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

Kamin Whitehouse kaminw at users.sourceforge.net
Tue Sep 27 23:59:13 PDT 2005


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

Modified Files:
	NescApp.py RoutingMessages.py 
Log Message:
NescApp now has an attribute called "connections" which holds all connections to the network for that particular app.  This makes it easier for other applications to snoop on network traffic.  The error messages have also been improved, if the user did not compile with nescDecls, rpc, or ram symbols.  RoutingMessages now uses the connections field in NescApp, and has the new ability to connect to only local comm (ie. not use drip/drain) and to not bonk when a connection is not available.

Index: NescApp.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/util/NescApp.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NescApp.py	23 Sep 2005 10:20:33 -0000	1.1
--- NescApp.py	28 Sep 2005 06:59:11 -0000	1.2
***************
*** 22,25 ****
--- 22,26 ----
  
  from nescDecls import *
+ import pytos.Comm as Comm
  import pytos.tools.Rpc as Rpc
  import pytos.tools.RamSymbols as RamSymbols
***************
*** 420,424 ****
  
  class NescApp( object ) :
!   """A class that holds all types and enums defined in a specific nesc application.
  
    usage:
--- 421,426 ----
  
  class NescApp( object ) :
!   """A class that holds all types, enums, msgs, rpc commands and ram
!   symbol definitions as defined for a specific nesc application.
  
    usage:
***************
*** 428,464 ****
    var = myApp.types.typeName
    """
!   def __init__( self, buildDir=None, port=None, tosbase=True, applicationName="Unknown App" ) :
      #first, import all enums, types, msgs, rpc functions, and ram symbols
      self.applicationName = applicationName
      try:
!       f = findBuildFile(buildDir, "nescDecls.xml")
      except Exception, e:
!       if len(e.args) > 0 and e.args[0].find("File ") == 0:
!         raise Exception("%s.  Perhaps you provided the wrong build directory, or perhaps you did not compile with the \"nescDecls\" build argument.  Your nesC app cannot be imported." % e.args[0])
        else :
          raise
-     self.enums = NescEnums(buildDir, applicationName)
-     self.types = NescTypes(buildDir, applicationName)
-     self.msgs = NescMsgs(self.types, self.enums, applicationName)
      try:
!       f = findBuildFile(buildDir, "rpcSchema.xml")
      except Exception, e:
!       if len(e.args) > 0 and e.args[0].find("File ") == 0:
!         print "Warning: %s.  You did not compile with the \"rpc\" make argument.  No rpc commands or ram symbols will be imported." % e.args[0]
!         return
        else :
          raise
  
!     self.rpc = Rpc.Rpc(self, buildDir, sendComm=port, tosbase=tosbase)
!     self.ramSymbols = RamSymbols.RamSymbols(self, buildDir,
!                                             sendComm=self.rpc.sendComm,
!                                             receiveComm=self.rpc.receiveComm,
!                                             tosbase=tosbase)
!     #now create shortcuts to all the application modules
      moduleNames = {}
      self._moduleNames = []
      moduleName = re.compile('^(\w+).')
      names = self.rpc._messages.keys()
!     names.extend(self.ramSymbols._messages.keys())
      names.sort()
      for name in names :
--- 430,489 ----
    var = myApp.types.typeName
    """
!   def __init__( self, buildDir=None, motecom=None, tosbase=True,
!                 localCommOnly=False, applicationName="Unknown App" ) :
!     """This function creates the NescEnums, NescTypes, NescMsgs, Rpc,
!     and RamSymbol objects for a particular application.  It also
!     connects to the network using the motecom value"""
!     
      #first, import all enums, types, msgs, rpc functions, and ram symbols
      self.applicationName = applicationName
+     self.buildDir = buildDir
+     self.motecom=motecom
+     self.tosbase=tosbase
+     self.localCommOnly=localCommOnly
+     
+     # Check for the nescDecls.xml file
+     if not os.path.isfile("%snescDecls.xml" % buildDir) :
+       raise Exception("""\nERROR: cannot find file \"%snescDecls.xml\".
+ 
+ Your nesC app cannot be imported.  Be sure that you compiled with the \"nescDecls\" option.\n\n""" % buildDir)
+ 
+     # Import enums, types, and msgs
+     self.enums = NescEnums(buildDir, applicationName)
+     self.types = NescTypes(buildDir, applicationName)
+     self.msgs = NescMsgs(self.types, self.enums, applicationName)
+ 
+     # Connect to the network
+     self.connections = []
+     if self.motecom != None:
+       comm = Comm.Comm()
+       comm.connect(self.motecom)
+       self.connections.append(comm)
+ 
+     # Import the rpc commands and ram symbols
      try:
!       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)
        else :
          raise
      try:
!       self.ramSymbols = RamSymbols.RamSymbols(self)
      except Exception, e:
!       if re.search("The RamSymbolsM module was not compiled in", e.args[0]) > 0 :
!         print e.args[0]
        else :
          raise
+       pass 
  
!     # Create shortcuts to all the application modules
      moduleNames = {}
      self._moduleNames = []
      moduleName = re.compile('^(\w+).')
      names = self.rpc._messages.keys()
!     if self.__dict__.has_key("ramSymbols"):
!       names.extend(self.ramSymbols._messages.keys())
      names.sort()
      for name in names :

Index: RoutingMessages.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/util/RoutingMessages.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RoutingMessages.py	23 Sep 2005 10:20:33 -0000	1.1
--- RoutingMessages.py	28 Sep 2005 06:59:11 -0000	1.2
***************
*** 140,170 ****
  class RoutingMessages(object) :
    
!   def __init__(self, app, sendComm=None, receiveComm=None, sendChannel=None, tosbase=True) :
      self.app = app
!     self.sendComm = sendComm
!     if sendComm == None :
!       raise Exception("You must pass something in sendComm")
!     elif type(sendComm) == str :
!       if sendChannel == None:
!         self.sendComm = Comm.Comm(app)
!         self.sendComm.connect(sendComm)
        else :
!         self.sendComm = Drip.Drip(app, sendChannel, sendComm)
!       self.address=app.enums.TOS_BCAST_ADDR
!     self.receiveComm = receiveComm
!     if receiveComm == None :
!       receiveComm = sendComm
!       self.receiveComm = receiveComm
!     if type(receiveComm) == str :
!       self.returnAddress = 0xfffe
!       self.receiveComm = Drain.Drain(app, self.returnAddress, receiveComm)
!       self.receiveComm.usingTosBase=tosbase 
!       self.receiveComm.delay=60            #rebuild the tree every 5 mins
!       self.receiveComm.forever=True
!       self.receiveComm.VERBOSE=False
!       self.receiveComm.maintainTree()
  
!     self._messages = {}
  
    def initializeCallParams(self, callParams) :
      for (callParam,defaultVal) in self.defaultCallParams :
--- 140,218 ----
  class RoutingMessages(object) :
    
!   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 = 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()
!       if app.tosbase==True:                                  #can we discover this like deluge?
!         self.returnAddress = treeID
        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
  
+     
    def initializeCallParams(self, callParams) :
      for (callParam,defaultVal) in self.defaultCallParams :



More information about the Tinyos-commits mailing list