comparison zb.py @ 13:729f2393f296

Auto increment frame ID when creating a TX packet.
author darius@Inchoate
date Sat, 17 Jan 2009 14:39:50 +1030
parents 75f785a09e2e
children c6ee9eae9e49
comparison
equal deleted inserted replaced
12:a3ec3f2988ac 13:729f2393f296
82 (i, ord(list[i]), min, max)) 82 (i, ord(list[i]), min, max))
83 83
84 class TXPkts(PktBase): 84 class TXPkts(PktBase):
85 """Base class for all packets that go to the module""" 85 """Base class for all packets that go to the module"""
86 86
87 frameidcounter = 0
88
87 def __init__(self): 89 def __init__(self):
88 # Frame ID of 0 will prevent TX status pakets being sent 90 self._frameid = self.getNextFrameId()
89 self._frameid = 1 91
90 92 @classmethod
93 def getNextFrameId(clss):
94 """Generate the next frame ID, skip 0 as it will cause the module to not send a response back"""
95 clss.frameidcounter = (clss.frameidcounter + 1) % 255
96
97 if clss.frameidcounter == 0:
98 clss.frameidcounter = 1
99
100 return clss.frameidcounter
101
91 def setframeid(self, value): 102 def setframeid(self, value):
92 if (value < 0 or value > 255): 103 if (value < 0 or value > 255):
93 raise ValueError("FrameID must be 0-255") 104 raise ValueError("FrameID must be 0-255")
94 self._frameid = value 105 self._frameid = value
95 frameid = property(lambda s: s._frameid, setframeid) 106 frameid = property(lambda s: s._frameid, setframeid)
267 self.payload = args[1] 278 self.payload = args[1]
268 else: 279 else:
269 raise TypeError("incorrect number of arguments"); 280 raise TypeError("incorrect number of arguments");
270 281
271 def __str__(self): 282 def __str__(self):
272 return "TX_%d_Bit 0x%0*x <- %s" % (self.ADDR_SIZE * 8, self.ADDR_SIZE * 2, self.recipient, 283 return "TX_%d_Bit ID: %d 0x%0*x <- %s" % (self.ADDR_SIZE * 8, self._frameid, self.ADDR_SIZE * 2,
273 self.payload) 284 self.recipient, self.payload)
274 285
275 def setrecipient(self, value): 286 def setrecipient(self, value):
276 if (value < 0 or value > 2 ** (self.ADDR_SIZE * 8)): 287 if (value < 0 or value > 2 ** (self.ADDR_SIZE * 8)):
277 raise ValueError("value out of range must be between 0 and %d" % (2 ** self.ADDR_SIZE)) 288 raise ValueError("value out of range must be between 0 and %d" % (2 ** self.ADDR_SIZE))
278 289