Last active
December 31, 2015 19:39
-
-
Save creamidea/8035348 to your computer and use it in GitHub Desktop.
分析tinyos sdk中python解析的一段代码:https://github.com/tinyos/tinyos-main/blob/master/support/sdk/python/tinyos/message/MoteIF.py#L60 构造的字典
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def addListener(self, listener, msgClass): | |
if listener not in self.listeners: | |
self.listeners[listener] = {} | |
amTypes = self.listeners[listener] | |
amTypes[msgClass.get_amType()] = msgClass | |
def dispatchPacket(self, source, packet): | |
... | |
for l in self.listeners: | |
amTypes = self.listeners[l] | |
if amType in amTypes: | |
try: | |
msgClass = amTypes[amType] | |
msg = msgClass(data=data, | |
data_length = len(data), | |
addr=serial_pkt.get_header_src(), | |
gid=serial_pkt.get_header_group()) | |
l.receive(source, msg) | |
except Exception, x: | |
print >>sys.stderr, x | |
print >>sys.stderr, traceback.print_tb(sys.exc_info()[2]) | |
################################ | |
#数据格式 | |
listeners = { | |
listener : { | |
msgClass.get_amType(): msgClass | |
... | |
} | |
listener : { | |
msgClass.get_amType(): msgClass | |
... | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment