def __init__(self, app=""): self.app = app self.listeners = [] msgQueue = Comm.MessageQueue(10) #register the msgQueue for all message types with localComm comm = Comm.getCommObject(self.app, self.app.motecom) registerAllMsgs(self.app.msgs, msgQueue, comm) #register the msgQueue for all message types with drain and unregister DrainMsg with localComm if "AM_DRAINMSG" in self.app.enums._enums: drains = Drain.getDrainObject(self.app) for drain in drains: registerAllMsgs(self.app.msgs, msgQueue, drain) comm.unregister(self.app.msgs.DrainMsg, msgQueue) #if rpc is imported if self.app.__dict__.has_key("rpc"): #make sure a drip object exists for snooping on cmds drips = Drip.getDripObject(self.app, self.app.motecom, self.app.enums.AM_RPCCOMMANDMSG) #register the msgQueue for all rpc response messages for command in self.app.rpc._messages.values(): command.register(msgQueue) #and unregister RpcResponseMsg from drain drains = Drain.getDrainObject(self.app, self.app.motecom, 0xfffe) #ugh... hard coded number for drain in drains: drain.unregister(app.msgs.RpcResponseMsg, msgQueue) #if ram symbols is imported if self.app.__dict__.has_key("ramSymbols"): #register the msgQueue for all ram symbol response messages for symbol in self.app.ramSymbols._messages.values(): symbol.registerPeek(msgQueue) symbol.registerPoke(msgQueue) #and unregister from peek/poke rpc commands self.app.RamSymbolsM.peek.unregister(msgQueue) self.app.RamSymbolsM.poke.unregister(msgQueue) #register the msgQueue for all message types with drip and unregister DripMsg with localComm if "AM_DRIPMSG" in self.app.enums._enums: drips = Drip.getDripObject(self.app) for drip in drips: print "actually dtrying to register dripmsgs\n" registerAllMsgs(self.app.msgs, msgQueue, drip) comm.unregister(self.app.msgs.DripMsg, msgQueue) self.running = True msgThread = threading.Thread(target=self.processMessages, args=(msgQueue, )) msgThread.setDaemon(True) msgThread.start()
def __init__( self , app="" ) : self.app = app self.listeners = [] msgQueue = Comm.MessageQueue(10) #register the msgQueue for all message types with localComm comm = Comm.getCommObject(self.app, self.app.motecom) registerAllMsgs(self.app.msgs, msgQueue, comm) #register the msgQueue for all message types with drain and unregister DrainMsg with localComm if "AM_DRAINMSG" in self.app.enums._enums : drains = Drain.getDrainObject(self.app) for drain in drains: registerAllMsgs(self.app.msgs, msgQueue, drain) comm.unregister(self.app.msgs.DrainMsg, msgQueue) #if rpc is imported if self.app.__dict__.has_key("rpc") : #make sure a drip object exists for snooping on cmds drips = Drip.getDripObject(self.app, self.app.motecom, self.app.enums.AM_RPCCOMMANDMSG) #register the msgQueue for all rpc response messages for command in self.app.rpc._messages.values() : command.register(msgQueue) #and unregister RpcResponseMsg from drain drains = Drain.getDrainObject(self.app, self.app.motecom, 0xfffe) #ugh... hard coded number for drain in drains: drain.unregister(app.msgs.RpcResponseMsg, msgQueue) #if ram symbols is imported if self.app.__dict__.has_key("ramSymbols") : #register the msgQueue for all ram symbol response messages for symbol in self.app.ramSymbols._messages.values() : symbol.registerPeek(msgQueue) symbol.registerPoke(msgQueue) #and unregister from peek/poke rpc commands self.app.RamSymbolsM.peek.unregister(msgQueue) self.app.RamSymbolsM.poke.unregister(msgQueue) #register the msgQueue for all message types with drip and unregister DripMsg with localComm if "AM_DRIPMSG" in self.app.enums._enums : drips = Drip.getDripObject(self.app) for drip in drips: print "actually dtrying to register dripmsgs\n" registerAllMsgs(self.app.msgs, msgQueue, drip) comm.unregister(self.app.msgs.DripMsg, msgQueue) self.running = True msgThread = threading.Thread(target=self.processMessages, args=(msgQueue,)) msgThread.setDaemon(True) msgThread.start()
def __init__(self, app) : self.app = app self._messages = {} ## In this constructor, we connect to the routing layer as best as ## we can. This may mean creating new drip/drain instances, ## reusing old ones, reusing old Comm objects, or not connecting ## at all, depending... if app.motecom == None: return #connect to sendComm: use localComm if user requested or if drip not compiled in. self.address=app.enums.TOS_BCAST_ADDR if app.localCommOnly==True or "AM_DRIPMSG" not in app.enums._enums: self.sendComm = Comm.getCommObject(app, app.motecom) else : self.sendComm = Drip.getDripObject(app, app.motecom, app.enums.AM_RPCCOMMANDMSG)[0] #connect to receiveComm: always use Drain unless not compiled in if "AM_DRAINMSG" not in app.enums._enums: self.receiveComm = Comm.getCommObject(app, app.motecom) self.returnAddress = app.enums.TOS_BCAST_ADDR else : treeID = 0xfffe #can we set this automatically? self.receiveComm = Drain.getDrainObject(app, app.motecom, treeID)[0] if app.localCommOnly == False : self.receiveComm.maintainTree() if app.tosbase==True: #can we discover this like deluge? self.returnAddress = treeID else : self.returnAddress = app.enums.TOS_UART_ADDR
def read(self, nodeID, strawID, start, size): data=[] #store the data in here response=None while response==None: print "pinging node %d" % nodeID response = self.app.StrawM.msgDataSize.peek(address=nodeID, timeout=3) #find num bytes/msg dataSize = response[0].value['value'].value numHops = self.app.enums.DRAIN_MAX_TTL - response[0].getParentMsg(self.app.enums.AM_DRAINMSG).ttl self.app.StrawM.sendPeriod.poke(self.linkLatency * numHops * 1000, address=nodeID, responseDesired=False) msgs = [0 for i in range(int(math.ceil(size/float(dataSize))))] #keep track of straw msgs in here msgQueue = Comm.MessageQueue(10) Drain.getDrainObject(self.app)[0].register(self.app.msgs.StrawMsg, msgQueue) print "Sucking %d bytes from node %d through Straw %d:" % (size, nodeID, strawID) while msgs.count(1) < len(msgs): subStart = msgs.index(0) * dataSize try: subSize = min(size, (msgs.index(1, subStart)*dataSize - subStart) ) except: subSize = size - subStart response = [] #while response == []: self.app.StrawM.read(strawID, subStart, subSize, address=nodeID) sys.stdout.write("%d-%d: " % (subStart, subStart+subSize)) numPrintedChars=0 while True : try: (addr, msg) = msgQueue.get(block=True, timeout=self.linkLatency * numHops * 4) if msg.parentMsg.source == nodeID :#and msgs[msg.startIndex//dataSize] == 0: msgs[msg.startIndex//dataSize] = 1 data[msg.startIndex:msg.startIndex+dataSize-1] = msg.data[:] strg = "" for i in range(numPrintedChars) : strg += "\b" strg += "%s/%s" % (msgs.count(1),len(msgs)) sys.stdout.write(strg) sys.stdout.flush() numPrintedChars = len(strg)-numPrintedChars except Queue.Empty: print "" break #now, pack the data so that it can be easily unpacked for i in range(len(data)): data[i] = pack('B',data[i]) return ''.join(data[0:size])