[Tinyos-commits] CVS: tinyos-1.x/tools/python/pytos/util MessageFilter.py, 1.1, 1.2 MessageSnooper.py, 1.1, 1.2 NescApp.py, 1.2, 1.3 RoutingMessages.py, 1.2, 1.3

Kamin Whitehouse kaminw at users.sourceforge.net
Wed Oct 26 19:23:39 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv871/util

Modified Files:
	MessageFilter.py MessageSnooper.py NescApp.py 
	RoutingMessages.py 
Log Message:
Added register/unregister functions to Drip and RamSymbols and updated the messageSnooper to know how to snoop on these messages.  Added "get" functions to comm, drip and drain, so that only a single instance of each needs to be instantiated.  Added a logically "negative" message filter.  


Index: MessageFilter.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/util/MessageFilter.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MessageFilter.py	29 Sep 2005 02:16:16 -0000	1.1
--- MessageFilter.py	27 Oct 2005 02:23:37 -0000	1.2
***************
*** 182,194 ****
      return strg
    
  logicalMenu = ( """
!   All filters are AND-ed together by default,
!   but you can also create an OR-filter.
    
      'd': default filter
      'o': OR-filter
      'x': to cancel
      """, { 
    'o': ORFilter.menu,
    'd': lambda : userMenu(recursionMenu),
    'x': lambda : None
--- 182,219 ----
      return strg
    
+ class NotFilter( object ):
+   """A wrapper filter that NOTs another filter"""
+   def __init__( self, filtr ) :
+     self._filter = filtr
+ 
+   def filter( self, addr, msg) :
+     if self._filter.filter(addr, msg) :
+         return  False
+     return True
+ 
+   @staticmethod
+   def menu() :
+     filtr = userMenu( recursionMenu )
+     if filtr != None :
+       return NotFilter(filtr)
+     else :
+       return None
+   
+   def __str__(self) :
+     return "NOT %s\n" % str(filtr)
+   
+ 
  logicalMenu = ( """
!   Only messages that match ALL filters can pass through, by default.
!   You can negate a filter with the NOT-filter, or create a group of
!   filters than are OR-ed together with the OR-filter.
    
      'd': default filter
      'o': OR-filter
+     'n': NOT-filter
      'x': to cancel
      """, { 
    'o': ORFilter.menu,
+   'n': NotFilter.menu,
    'd': lambda : userMenu(recursionMenu),
    'x': lambda : None

Index: MessageSnooper.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/util/MessageSnooper.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MessageSnooper.py	28 Sep 2005 07:01:21 -0000	1.1
--- MessageSnooper.py	27 Oct 2005 02:23:37 -0000	1.2
***************
*** 27,30 ****
--- 27,31 ----
  import pytos.Comm as Comm         
  import pytos.tools.Drain as Drain         
+ import pytos.tools.Drip as Drip         
  import threading
  
***************
*** 58,74 ****
          
      #register the msgQueue for all message types with localComm
!     for conn in self.app.connections :
!       if isinstance(conn, Comm.Comm) :
!         registerAllMsgs(self.app.msgs, msgQueue, conn)
  
!     #register the msgQueue for all message types with drain
      if "AM_DRAINMSG" in self.app.enums._enums :
!       for conn in self.app.connections :
!         if isinstance(conn, Drain.Drain) :
!           registerAllMsgs(self.app.msgs, msgQueue, conn)
!       #unregister DrainMsg with localComm
!       for conn in self.app.connections :
!         if isinstance(conn, Comm.Comm) :
!           conn.unregister(self.app.msgs.DrainMsg, msgQueue)
  
      self.running = True
--- 59,100 ----
          
      #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

Index: NescApp.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/util/NescApp.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** NescApp.py	28 Sep 2005 06:59:11 -0000	1.2
--- NescApp.py	27 Oct 2005 02:23:37 -0000	1.3
***************
*** 465,469 ****
        self.rpc = Rpc.Rpc(self)
      except Exception, e:
!       if re.search("WARNING: cannot find file", e.args[0]) > 0 :
          print  e.args[0]
          return # (if there are no rpc commands, we have nothing left to do)
--- 465,469 ----
        self.rpc = Rpc.Rpc(self)
      except Exception, e:
!       if len(e.args)>0 and re.search("WARNING: cannot find file", e.args[0]) > 0 :
          print  e.args[0]
          return # (if there are no rpc commands, we have nothing left to do)

Index: RoutingMessages.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/util/RoutingMessages.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RoutingMessages.py	28 Sep 2005 06:59:11 -0000	1.2
--- RoutingMessages.py	27 Oct 2005 02:23:37 -0000	1.3
***************
*** 156,170 ****
      self.address=app.enums.TOS_BCAST_ADDR
      if app.localCommOnly==True or "AM_DRIPMSG" not in app.enums._enums:
!       self.sendComm = self.getCommObject(app.motecom)
      else :
!       self.sendComm = self.getDripObject(app.motecom, app.enums.AM_RPCCOMMANDMSG)
  
      #connect to receiveComm: always use Drain unless not compiled in
      if "AM_DRAINMSG" not in app.enums._enums:
!       self.receiveComm = self.getCommObject(app.motecom)
        self.returnAddress = app.enums.TOS_BCAST_ADDR
      else :
        treeID = 0xfffe                                        #can we set this automatically?
!       self.receiveComm = self.getDrainObject(app.motecom, treeID)
        if app.localCommOnly == False :
          self.receiveComm.maintainTree()
--- 156,170 ----
      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()
***************
*** 173,216 ****
        else :
          self.returnAddress = app.enums.TOS_UART_ADDR
- 
-   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.connections.append(comm)
-     return comm
    
-   def getDripObject(self, motecom, channel) :
-     """This function returns the drip object stored in app.  If there
-     is none, it creates one"""
-     for conn in self.app.connections :
-       if isinstance(conn, Drip.Drip) :
- #        if conn.motecom == motecom :                       #we need this funtion in java
- #          if drip.channel == app.enums.AM_RPCCOMMANDMSG :  #we need this funtion in java
-             return conn
-     drip = Drip.Drip(self.app, self.app.enums.AM_RPCCOMMANDMSG, self.app.motecom)
-     self.app.connections.append(drip)
-     return drip
-   
-   def getDrainObject(self, motecom, treeID) :
-     """This function returns the drain object stored in app.  If there
-     is none, it creates one"""
-     for conn in self.app.connections :
-       if isinstance(conn, Drain.Drain) :
- #        if conn.motecom == motecom :                       #we need this funtion in java
- #          if drip.channel == app.enums.AM_RPCCOMMANDMSG :  #we need this funtion in java
-             return conn
-     drain = Drain.Drain(self.app, treeID, self.app.motecom)
-     drain.delay=60            #rebuild every 5 mins          #can we make this a parameter?
-     drain.forever=True
-     drain.VERBOSE=False
-     self.app.connections.append(drain)
-     return drain
  
      
--- 173,177 ----



More information about the Tinyos-commits mailing list