Esempio n. 1
0
    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
Esempio n. 3
0
    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()
Esempio n. 4
0
    def __init__(self, snooper):

        self.usage = """
    h   : help
    p   : pause
    q   : quit
    1-9 : verbosity
    f   : manage filters
    l   : draw line now
    c   : toggle colors
    """

        print "\nType \"h\" for help\n"
        msgQueue = Comm.MessageQueue(10)
        self.keyPress = KeyPress.KeyPress()
        self.filter = MessageFilter.MessageFilter(app, snooper)
        self.filter.register(msgQueue)
        self.running = True
        self.pausing = False
        self.verbosity = '4'
        self.numLostPackets = 0
        self.numPrintedChars = 0

        #start a thread to process the messages (make daemon so it dies when main thread stops)
        self.msgThread = threading.Thread(target=self.processMessages,
                                          args=(msgQueue, ))
        self.msgThread.setDaemon(True)
        self.msgThread.start()
        self.readKeys()
Esempio n. 5
0
 def __init__( self , app, spAddr, moteIF ) :
     if type(moteIF) == str :
         moteIF = Comm.openMoteIF(moteIF, app)
     drainObj = drain.Drain(spAddr, moteIF)
     drainConnectorObj = drain.DrainConnector(spAddr, moteIF)
     self.app = app #save for later use
     JavaInheritor.__init__(self, (drainObj, drainConnectorObj) )
Esempio n. 6
0
File: Drain.py Progetto: iplusu/sarp
 def __init__( self , app, spAddr, moteIF ) :
     if type(moteIF) == str :
         moteIF = Comm.openMoteIF(moteIF, app)
     drainObj = drain.Drain(spAddr, moteIF)
     drainConnectorObj = drain.DrainConnector(spAddr, moteIF)
     self.app = app #save for later use
     JavaInheritor.__init__(self, (drainObj, drainConnectorObj) )
Esempio n. 7
0
 def getCommObject(self, motecom) :
   """This function returns the comm object stored in app.  If there
   is none, it creates one"""
   for conn in self.app.connections :
       if isinstance(conn, Comm.Comm) :
           if motecom not in conn._connected :
               conn.connect(motecom)
           return conn
   comm = Comm.Comm()
   comm.connect(self.motecom)
   self.app.connections.append(comm)
   return comm
Esempio n. 8
0
  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()
Esempio n. 9
0
    def __init__(self, app, snooper):

        self.app = app
        self.snooper = snooper
        self.listeners = []
        self.filters = []

        msgQueue = Comm.MessageQueue(10)
        self.running = True
        self.snooper.register(msgQueue)
        msgThread = threading.Thread(target=self.processMessages,
                                     args=(msgQueue, ))
        msgThread.setDaemon(True)
        msgThread.start()
Esempio n. 10
0
    def __call__(self, *posArgs, **nameArgs):
        if not self.parent.app.__dict__.has_key("RpcM"):
            raise Exception(
                "You must include the marionette goal in your nesc application in order to use rpc commands"
            )
        commArgs = ()
        callParams = self.parseCallParams(nameArgs)
        self.rpcHeader.transactionID = (self.rpcHeader.transactionID + 1) % 256
        thisCall = deepcopy(self)
        thisCall.rpcHeader.address = callParams["address"]
        thisCall.rpcHeader.returnAddress = callParams["returnAddress"]
        thisCall.rpcHeader.responseDesired = callParams["responseDesired"]

        #If this is a blocking call, get ready to process response msgs for timeout time
        processMsgs = False
        if callParams["blocking"] ==True \
               and callParams["timeout"] > 0 \
               and callParams["responseDesired"]==True:
            responseQueue = Comm.MessageQueue(self.msgQueueSize)
            self.register(responseQueue)
            processMsgs = True

        thisCall._send(callParams["address"], *posArgs, **nameArgs)

        if processMsgs:
            startTime = time.time()
            responses = []
            while time.time() - startTime <= callParams["timeout"]:
                try:
                    (addr, msg) = responseQueue.get(True, 0.1)  #why 0.1?
                    if msg.nescType == "RpcResponseMsg":
                        rxdTransactionID = msg.transactionID
                    else:
                        rxdTransactionID = msg.parentMsg.transactionID
                    if rxdTransactionID == thisCall.rpcHeader.transactionID:
                        responses.append(msg)
                except Exception, e:
                    if len(e.args) > 0:
                        print "rpc error: %s" % str(e)
            self.unregister(responseQueue)
            return responses
Esempio n. 11
0
                     %(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)
Esempio n. 12
0
File: Drain.py Progetto: iplusu/sarp
 def _wrapCallbackAndTosMsg(self, msg, callback) :
     callback = DrainMsgPeeler(self.app, msg, callback)
     callback = Comm.createJavaMessageListener(callback)
     num = msg.amType
     return (num, callback)
Esempio n. 13
0
 def __init__( self , app, channel, moteIF ) :
     self.app = app
     if type(moteIF) == str :
         moteIF = Comm.openMoteIF(moteIF, app)
     dripObj = drip.Drip(channel, moteIF)
     JavaInheritor.__init__(self, (dripObj,) )
Esempio n. 14
0
 def _wrapCallbackAndTosMsg(self, msg, callback) :
     callback = DrainMsgPeeler(self.app, msg, callback)
     callback = Comm.createJavaMessageListener(callback)
     num = msg.amType
     return (num, callback)
Esempio n. 15
0
 def unregister( self , msg , callback , *comm ) :
     comm = Comm.getCommObject(self.app)
     comm.unregister(self.app.msgs.DripMsg, DripMsgPeeler(self.app, msg, callback))
Esempio n. 16
0
File: Drip.py Progetto: iplusu/sarp
 def __init__( self , app, channel, moteIF ) :
     self.app = app
     if type(moteIF) == str :
         moteIF = Comm.openMoteIF(moteIF, app)
     dripObj = drip.Drip(channel, moteIF)
     JavaInheritor.__init__(self, (dripObj,) )
Esempio n. 17
0
File: Drip.py Progetto: iplusu/sarp
 def unregister( self , msg , callback , *comm ) :
     comm = Comm.getCommObject(self.app)
     comm.unregister(self.app.msgs.DripMsg, DripMsgPeeler(self.app, msg, callback))