示例#1
0
文件: Listen.py 项目: sopier/WSNTools
    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()
示例#2
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()
示例#3
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()
示例#4
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