comparison zb.py @ 8:9f0808b13454

Use non-blocking serial access. Add __str__ method for RX packets.
author darius@inchoate.localdomain
date Sun, 04 Nov 2007 21:10:21 +1030
parents 579dedf5a1f1
children d147529ad2db
comparison
equal deleted inserted replaced
7:579dedf5a1f1 8:9f0808b13454
68 class RX_16_Bit(PktBase): 68 class RX_16_Bit(PktBase):
69 PKT_TYPE = 0x81 69 PKT_TYPE = 0x81
70 PKT_DESC = "RX Packet: 16 bit address" 70 PKT_DESC = "RX Packet: 16 bit address"
71 ADDR_SIZE = 2 71 ADDR_SIZE = 2
72 72
73 def __str__(self):
74 return "0x%0*x (%ddBm) -> %s" % (self.ADDR_SIZE * 2, self.sender,
75 self.rssi, str(self.payload))
76
73 def getsender(self): 77 def getsender(self):
74 value = 0 78 value = 0
75 for i, j in zip(reversed(range(self.ADDR_SIZE)), range(0, self.ADDR_SIZE * 8, 8)): 79 for i, j in zip(reversed(range(self.ADDR_SIZE)), range(0, self.ADDR_SIZE * 8, 8)):
76 value |= self.data[i] << j 80 value |= self.data[i] << j
77 return value 81 return value
290 # if (issubclass(c, PktBase)): 294 # if (issubclass(c, PktBase)):
291 # print .. 295 # print ..
292 296
293 s = serial.Serial(port='/dev/cuad0', baudrate=9600, bytesize=8, parity='N', \ 297 s = serial.Serial(port='/dev/cuad0', baudrate=9600, bytesize=8, parity='N', \
294 stopbits=1, rtscts=0) 298 stopbits=1, rtscts=0)
295 s.setTimeout(0.1) 299 # Non-blocking
300 s.timeout = 0
296 #s.write('+++') 301 #s.write('+++')
297 #s.readline(eol='\r') 302 #s.readline(eol='\r')
298 303
299 304
300 # 0x0001 (-36dBm) -> 1 samples, mask 0x000f, DIO - 0x00f 305 # 0x0001 (-36dBm) -> 1 samples, mask 0x000f, DIO - 0x00f