[Tinyos-commits] CVS: tinyos-1.x/tools/python/pytos/util NescApp.py, 1.3, 1.4

Kamin Whitehouse kaminw at users.sourceforge.net
Thu Jan 12 14:50:47 PST 2006


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

Modified Files:
	NescApp.py 
Log Message:
This should help Pytos startup three times faster.  

It also allows poking and peeking of global ram symbols, like TOS_AM_GROUP, through the new app.ramSymbols.Globals object.

Most of this patch is from Henri Dubois-ferriere from switzerland



Index: NescApp.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/util/NescApp.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** NescApp.py	27 Oct 2005 02:23:37 -0000	1.3
--- NescApp.py	12 Jan 2006 22:50:45 -0000	1.4
***************
*** 35,39 ****
    var = myTypes.typeName
    """
!   def __init__( self, xmlFilename=None, applicationName="Unknown App" ) :
      self.applicationName = applicationName
      self._typeNames = []
--- 35,39 ----
    var = myTypes.typeName
    """
!   def __init__( self, xmlFilename, applicationName="Unknown App", xmlFileDOM=None ) :
      self.applicationName = applicationName
      self._typeNames = []
***************
*** 43,48 ****
      platformTypes = {}
      typeRE = re.compile('cname=\"([\w\s]+?)\" size=\"I:(\d+?)\"')
-     xmlFilename = findBuildFile(xmlFilename, "nescDecls.xml")
      infile = open(xmlFilename, 'r')
      for line in infile :
        match = typeRE.search(line)
--- 43,49 ----
      platformTypes = {}
      typeRE = re.compile('cname=\"([\w\s]+?)\" size=\"I:(\d+?)\"')
      infile = open(xmlFilename, 'r')
+     if xmlFileDOM == None :
+       xmlFileDOM = minidom.parse(xmlFilename)
      for line in infile :
        match = typeRE.search(line)
***************
*** 103,107 ****
      self.anonymousRefStructs = []
      self.undefinedTypes = []
!     self.createTypesFromXml(xmlFilename)
      self._typeNames.sort()
      #self.printSkippedTypes()
--- 104,108 ----
      self.anonymousRefStructs = []
      self.undefinedTypes = []
!     self.createTypesFromXml(xmlFileDOM)
      self._typeNames.sort()
      #self.printSkippedTypes()
***************
*** 137,146 ****
      return string
      
!   def createTypesFromXml(self, xmlFilename) :
      """Go through the struct and typedef elements in the nescDecls.xml file"""
!     
!     dom = minidom.parse(xmlFilename)
!     typeDefs = [node for node in dom.getElementsByTagName("struct")]
!     for node in dom.getElementsByTagName("typedef") :
        typeDefs.append(node)
      
--- 138,145 ----
      return string
      
!   def createTypesFromXml(self, xmlFileDOM) :
      """Go through the struct and typedef elements in the nescDecls.xml file"""
!     typeDefs = [node for node in xmlFileDOM.getElementsByTagName("struct")]
!     for node in xmlFileDOM.getElementsByTagName("typedef") :
        typeDefs.append(node)
      
***************
*** 278,292 ****
    usage:
    myEnums = NescEnums('/path/to/nescDecls.xml')
    print myEnums
    var = myEnums.enumName
    """
  
!   def __init__( self, xmlFilename=None, applicationName="Unknown App" ) :
      self.applicationName = applicationName
      self._enums = []
!     if type(xmlFilename) == str:
!       xmlFilename = findBuildFile(xmlFilename, "nescDecls.xml")
!       xmlFilename = minidom.parse(xmlFilename)
!     self.createEnumsFromXml(xmlFilename)
  
    def __getitem__(self, key) :
--- 277,293 ----
    usage:
    myEnums = NescEnums('/path/to/nescDecls.xml')
+   myEnums = NescEnums(nescDeclsDOM)
    print myEnums
    var = myEnums.enumName
    """
  
!   def __init__( self, xmlFilename=None, applicationName="Unknown App", xmlFileDOM=None ) :
      self.applicationName = applicationName
      self._enums = []
!     if xmlFileDOM == None and type(xmlFilename) != str :
!       raise Exception("NescEnums parameters: either xmlFilename must be a string or xmlFileDOM must be a DOM object")
!     elif xmlFileDOM == None :
!       xmlFileDOM = minidom.parse(xmlFilename)
!     self.createEnumsFromXml(xmlFileDOM)
  
    def __getitem__(self, key) :
***************
*** 296,303 ****
        raise AttributeError("No such enum defined")
        
!   def createEnumsFromXml(self, dom) :
  
      #now define all the struct types
!     enumDefs = [node for node in dom.getElementsByTagName("enum")]
      integer = re.compile('^I:(\d+)$')
      hexidecimal = re.compile('^(0x[\dabcdefABCDEF]+)$')
--- 297,304 ----
        raise AttributeError("No such enum defined")
        
!   def createEnumsFromXml(self, xmlFileDOM) :
  
      #now define all the struct types
!     enumDefs = [node for node in xmlFileDOM.getElementsByTagName("enum")]
      integer = re.compile('^I:(\d+)$')
      hexidecimal = re.compile('^(0x[\dabcdefABCDEF]+)$')
***************
*** 319,326 ****
        self._enums.append(name)
        
!     namedEnums = [node for node in dom.getElementsByTagName("namedEnum")]
      for namedEnum in namedEnums :
        name = namedEnum.getAttribute("name")
!       self.__dict__[name] = NescEnums(namedEnum,name)
        self._enums.append(name)
      
--- 320,327 ----
        self._enums.append(name)
        
!     namedEnums = [node for node in xmlFileDOM.getElementsByTagName("namedEnum")]
      for namedEnum in namedEnums :
        name = namedEnum.getAttribute("name")
!       self.__dict__[name] = NescEnums(xmlFileDOM=namedEnum)
        self._enums.append(name)
      
***************
*** 431,438 ****
    """
    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
--- 432,447 ----
    """
    def __init__( self, buildDir=None, motecom=None, tosbase=True,
!                 localCommOnly=False, applicationName="Unknown App", xmlFileDOM=None ) :
      """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.  Paramers:
! 
!     BUILDDIR is a string that indicates the location of the nescDecls.xml file (see nescDecls.findBuildFile)
!     MOTECOM is a motecom string that the app should connect to
!     TOSBASE is True or False and indicates if we are connected to a TOSBASE node (autodetect in future?)
!     LOCALCOMMONLY is True or False and indicates if we should run pytos over multi-hop routing
!     APPLICATIONNAME is just for fun
!     XMLFILEDOM is a Document Object Model of the parsed xml file nescDecls.xml
!     """
      
      #first, import all enums, types, msgs, rpc functions, and ram symbols
***************
*** 442,455 ****
      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)
  
--- 451,471 ----
      self.tosbase=tosbase
      self.localCommOnly=localCommOnly
!     if xmlFileDOM == None :
!       try:
!         xmlFilename = findBuildFile(buildDir, "nescDecls.xml")
!       except:
!         raise Exception("""\nERROR: cannot find file \"nescDecls.xml\".
  
! Your nesC app cannot be imported.
! 
! Be sure that you compiled with the \"nescDecls\" option.
! Be sure that you supplied the correct buildDir parameter \"%s\".
! 
! """ % buildDir)
!       xmlFileDOM = minidom.parse(xmlFilename)
  
      # Import enums, types, and msgs
!     self.enums = NescEnums(xmlFilename, applicationName, xmlFileDOM)
!     self.types = NescTypes(xmlFilename, applicationName, xmlFileDOM)
      self.msgs = NescMsgs(self.types, self.enums, applicationName)
  
***************
*** 471,475 ****
          raise
      try:
!       self.ramSymbols = RamSymbols.RamSymbols(self)
      except Exception, e:
        if re.search("The RamSymbolsM module was not compiled in", e.args[0]) > 0 :
--- 487,491 ----
          raise
      try:
!       self.ramSymbols = RamSymbols.RamSymbols(self, xmlFileDOM=xmlFileDOM)
      except Exception, e:
        if re.search("The RamSymbolsM module was not compiled in", e.args[0]) > 0 :



More information about the Tinyos-commits mailing list