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.AM_BROADCAST_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.AM_BROADCAST_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 __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.AM_BROADCAST_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.AM_BROADCAST_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 __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()
%(msg.nodeID,msg.data)) elif (msg.msgType == app.enums.MetricsTypes.TRANS_RATE_REPLY): print("Constant transmission rate for node %d: %d\n" %(msg.nodeID,msg.data)) elif (msg.msgType == app.enums.MetricsTypes.RF_POWER_REPLY): print("RF power level for node %d: %d\n" %(msg.nodeID,msg.data)) elif (msg.amType == self.AM_DETECTIONEVENTMSG): pass else: print("MetricsTools.py: registered for a message you are not processing. AM Type: %d" %(msg.amType)) ##### Main Code ##### ## Instantiate your own Comm object and connection # import pytos.Comm as Comm # recvComm = Comm.Comm # recvComm.connect("sf@localhost:9001") ## Uses the comm object instantiated by app if (appType == 'TestDetectionEvent'): recvComm = app.rpc.receiveComm # drain comm sendComm = Comm.getCommObject(app) else: # assume 'MetricsMote' recvComm = Comm.getCommObject(app) # ex. app.connections[0] sendComm = recvComm metricsMsg = app.msgs.MetricsCmdMsg mTool = MetricsTools(sendComm,recvComm,appType)
def unregister( self , msg , callback , *comm ) : comm = Comm.getCommObject(self.app) comm.unregister(self.app.msgs.DripMsg, DripMsgPeeler(self.app, msg, callback))
def unregister( self , msg , callback , *comm ) : comm = Comm.getCommObject(self.app) comm.unregister(self.app.msgs.DripMsg, DripMsgPeeler(self.app, msg, callback))