[Tinyos-2-commits] CVS: tinyos-2.x/tools/tinyos/misc tos-deluge, 1.1, 1.2

Razvan Musaloiu-E. razvanm at users.sourceforge.net
Fri May 25 10:38:10 PDT 2007


Update of /cvsroot/tinyos/tinyos-2.x/tools/tinyos/misc
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv26812

Modified Files:
	tos-deluge 
Log Message:
Remove the TOSH_DATA_LENGTH=100 limitation.


Index: tos-deluge
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tools/tinyos/misc/tos-deluge,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** tos-deluge	22 May 2007 20:34:20 -0000	1.1
--- tos-deluge	25 May 2007 17:38:08 -0000	1.2
***************
*** 40,66 ****
  HEX_OUTPUT_LINE_SIZE = 16
  # Path to the python script that builds Deluge image from XML
! PY_PATH_BUILD_IMAGE  = os.path.join(os.path.dirname(sys.argv[0]), 'tos-build-deluge-image')
  
  # TinyOS serial communication parameters
! SERIAL_AMGROUP           = 0
! SERIAL_AMID              = 0xAB
! SERIAL_DATA_PAYLOAD_SIZE = 80
  
  # Serial message types
! MSG_ERASE    = 0
! MSG_WRITE    = 1
! MSG_READ     = 2
! MSG_REPROG   = 5
! MSG_DISS     = 6
  
! ERROR_SUCCESS = 0
! ERROR_FAIL    = 1
  
  # Deluge-specific parameters
! DELUGE_PKTS_PER_PAGE    = 48
! DELUGE_PKT_PAYLOAD_SIZE = 23
! DELUGE_MAX_PAGES        = 128
! DELUGE_METADATA_SIZE    = 16 + 16 + 16 + 16 + 4 + 4 + 4 + 4   # Metadata size in binary 
!                                                               # image
  
  class SerialReqPacket(tinyos.GenericPacket):
--- 40,67 ----
  HEX_OUTPUT_LINE_SIZE = 16
  # Path to the python script that builds Deluge image from XML
! PATH_PY_BUILD_IMAGE  = os.path.join(os.path.dirname(sys.argv[0]), 'tos-build-deluge-image')
  
  # TinyOS serial communication parameters
! SERIAL_AMGROUP     = 0
! SERIAL_AMID        = 0xAB
! SERIAL_DATA_LENGTH = 28 - 1 - 1 - 2 - 2
  
  # Serial message types
! MSG_ERASE  = 0
! MSG_WRITE  = 1
! MSG_READ   = 2
! MSG_REPROG = 5
! MSG_DISS   = 6
  
! ERROR_SUCCESS = 0   # T2-compatible
! ERROR_FAIL    = 1   # T2-compatible
  
  # Deluge-specific parameters
! DELUGE_MAX_PAGES       = 128
! DELUGE_METADATA_OFFSET = 0
! DELUGE_METADATA_SIZE   = 16
! DELUGE_IDENT_OFFSET    = 16 + (2 * DELUGE_MAX_PAGES)
! DELUGE_IDENT_SIZE      = 16 + 16 + 16 + 16 + 4 + 4 + 4 + 4   # Metadata size in binary 
!                                                              # image
  
  class SerialReqPacket(tinyos.GenericPacket):
***************
*** 155,188 ****
      return r
  
! # Returns the metadata (first 16 bytes of the image) plus the "ident" 
! # (DELUGE_METADATA_SIZE bytes after CRC)
! def getMetaData(s, img_num):
      r = []
      # Gets the metadata (first 16 bytes of the image)
!     sreqpkt = SerialReqPacket((MSG_READ, img_num, 0, 16, []))
!   
!     if s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload()):
!         packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
!         sreplypkt = SerialReplyPacket(packet[1])
!         if sreplypkt.error == ERROR_SUCCESS:
!             r.extend(sreplypkt.data)
!       
!             # Gets the "ident" portion of the image
!             sreqpkt["offset"] = 16 + (2 * DELUGE_MAX_PAGES)
!             sreqpkt["len"] = DELUGE_METADATA_SIZE
!             if s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload()):
!                 packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
!                 sreplypkt = SerialReplyPacket(packet[1])
!                 if sreplypkt.error == ERROR_SUCCESS:
!                     r.extend(sreplypkt.data)
!                     
!                     # Checks for valid CRC and timestamp
!                     if crc16(r[6:8]) == toInt(r[8:10]) and r[84:88] != [0xFF, 0xFF, 0xFF, 0xFF]:
!                         return r
!                 else:
!                     print "ERROR: Unable to retrieve image information"
          else:
!             print "ERROR: Unable to retrieve image information"
  
      return None
  
--- 156,208 ----
      return r
  
! # Reads a portion from the image in the external flash
! def op_read(s, img_num, offset, length):
      r = []
+     
      # Gets the metadata (first 16 bytes of the image)
!     sreqpkt = SerialReqPacket((MSG_READ, img_num, offset, length, []))
!     while True:
!         if sreqpkt['len'] > SERIAL_DATA_LENGTH:
!             sreqpkt['len'] = SERIAL_DATA_LENGTH
!         
!         if s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload()):
!             packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
!             sreplypkt = SerialReplyPacket(packet[1])
!             if sreplypkt.error == ERROR_SUCCESS:
!                 r.extend(sreplypkt.data)
!             else:
!                 r = None
!                 break
          else:
!             r = None
!             break
!         
!         sreqpkt['offset'] = sreqpkt['offset'] + sreqpkt['len']
!         if sreqpkt['offset'] >= (offset + length):
!             break
!         sreqpkt['len'] = (offset + length) - sreqpkt['offset']
!         
!     return r
!     
! # Returns the metadata (first 16 bytes of the image) plus the "ident" 
! # (DELUGE_IDENT_SIZE bytes after CRC)
! def getMetaData(s, img_num):
!     # Gets the metadata (first 16 bytes of the image)
!     r = op_read(s, img_num, DELUGE_METADATA_OFFSET, DELUGE_METADATA_SIZE)
  
+     # Gets the "ident" portion of the image
+     if r != None:
+         temp = op_read(s, img_num, DELUGE_IDENT_OFFSET, DELUGE_IDENT_SIZE)
+         if temp != None:
+             r.extend(temp)
+         else:
+             r = None
+         
+     # Checks for valid CRC and image timestamp
+     if r != None:
+         if crc16(r[6:8]) == toInt(r[8:10]) and r[84:88] != [0xFF, 0xFF, 0xFF, 0xFF]:
+             return r
+         
+     print "ERROR: Unable to retrieve image information"
      return None
  
***************
*** 227,232 ****
      while length > 0:
          # Calculates the payload size for the current packet
!         if length >= SERIAL_DATA_PAYLOAD_SIZE:
!             sreqpkt.len = SERIAL_DATA_PAYLOAD_SIZE
          else:
              sreqpkt.len = length
--- 247,252 ----
      while length > 0:
          # Calculates the payload size for the current packet
!         if length >= SERIAL_DATA_LENGTH:
!             sreqpkt.len = SERIAL_DATA_LENGTH
          else:
              sreqpkt.len = length
***************
*** 257,260 ****
--- 277,292 ----
  # Injects an image (specified by tos_image_xml) to an image volume
  def op_inject(s, img_num, tos_image_xml):
+     # Checks for valid file path
+     try:
+         os.stat(tos_image_xml)         # Checks whether tos_image_xml is a valid file
+     except:
+         print "ERROR: Unable to find the TOS image XML, \"%s\"" % tos_image_xml
+         return False
+     try:
+         os.stat(PATH_PY_BUILD_IMAGE)   # Checks whether PATH_PY_BUILD_IMAGE is a valid file
+     except:
+         print "ERROR: Unable to find the image building utility, \"%s\"" % PATH_PY_BUILD_IMAGE
+         return False
+   
      # Gets status information of stored image
      metadata = getMetaData(s, img_num)
***************
*** 271,281 ****
      
      # Creates binary image from the TOS image XML
!     try:
!         os.stat(tos_image_xml)         # Checks whether tos_image_xml is a valid file
!         os.stat(PY_PATH_BUILD_IMAGE)   # Checks whether PY_PATH_BUILD_IMAGE is a valid file
!     except:
!         print "ERROR: Unable to create a binary image from the TOS image XML, \"%s\"" % tos_image_xml
!         return False
!     p = subprocess.Popen([PY_PATH_BUILD_IMAGE, "-v", str(version), "-i", str(img_num), tos_image_xml], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      print p.stderr.read(),
      print "--------------------------------------------------"
--- 303,307 ----
      
      # Creates binary image from the TOS image XML
!     p = subprocess.Popen([PATH_PY_BUILD_IMAGE, "-v", str(version), "-i", str(img_num), tos_image_xml], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      print p.stderr.read(),
      print "--------------------------------------------------"



More information about the Tinyos-2-commits mailing list