X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tools%2Ftinyos%2Fmisc%2Ftinyos.py;h=b2b25478f1530e16f5ed8035d548f03cce0a9081;hb=1275ad8c5c9368b541e7eeccfeb6bf20352e6330;hp=22c9c94e0edba6e6b4c78bcd5cacf65816fc7af5;hpb=ef7a1ceb50ed42a0b9ad53da885ef022c559e886;p=tinyos-2.x.git diff --git a/tools/tinyos/misc/tinyos.py b/tools/tinyos/misc/tinyos.py index 22c9c94e..b2b25478 100644 --- a/tools/tinyos/misc/tinyos.py +++ b/tools/tinyos/misc/tinyos.py @@ -23,6 +23,10 @@ import struct, time, serial, socket # @author Chieh-Jan Mike Liang # @author Razvan Musaloiu-E. +############################################################################### +# TinyOS 2 Python Serial Module +############################################################################### + class Serial: HDLC_FLAG_BYTE = 0x7e HDLC_CTLESC_BYTE = 0x7d @@ -36,12 +40,28 @@ class Serial: SERIAL_PROTO_PACKET_ACK = 68 SERIAL_PROTO_PACKET_NOACK = 69 SERIAL_PROTO_PACKET_UNKNOWN = 255 - - __s = None # An instance of serial.Serial object + + __s = None # An instance of serial.Serial object __debug = False # Debug mode + __baud_rate = {} + def __init__(self, port, baudrate): - self.__s = serial.Serial(port, baudrate, rtscts=0, timeout=0.5) + __baud_rate = {'telos': 115200, 'telosb': 115200, + 'tmote': 115200, 'micaz': 57600, + 'mica2': 57600, 'mica2dot': 19200, + 'eyes': 115200, 'intelmote2': 115200} + + # Converts baud rate from platform name to value, if necessary + try: + int(baudrate) + except: + baudrate = __baud_rate.get(baudrate) + + if not baudrate == None: + self.__s = serial.Serial(port, baudrate, rtscts=0, timeout=0.5) + else: + raise ValueError, 'Invalid baud rate' def __format_packet(self, packet): return " ".join(["%02x" % p for p in packet]) + " | " + \ @@ -186,9 +206,10 @@ class Serial: print "Failed to send the packet!" else: print "Timeout waiting for ACK... Retry" - + return False + # Sets whether debugging message will in this module will be printed def set_debug(self, debug): self.__debug = debug