Mercurial > ~darius > hgwebdir.cgi > ZigBee
changeset 13:729f2393f296
Auto increment frame ID when creating a TX packet.
author | darius@Inchoate |
---|---|
date | Sat, 17 Jan 2009 14:39:50 +1030 |
parents | a3ec3f2988ac |
children | ac60a9244bdf |
files | zb.py |
diffstat | 1 files changed, 16 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/zb.py Tue Jan 13 12:17:02 2009 +1030 +++ b/zb.py Sat Jan 17 14:39:50 2009 +1030 @@ -84,10 +84,21 @@ class TXPkts(PktBase): """Base class for all packets that go to the module""" + frameidcounter = 0 + def __init__(self): - # Frame ID of 0 will prevent TX status pakets being sent - self._frameid = 1 - + self._frameid = self.getNextFrameId() + + @classmethod + def getNextFrameId(clss): + """Generate the next frame ID, skip 0 as it will cause the module to not send a response back""" + clss.frameidcounter = (clss.frameidcounter + 1) % 255 + + if clss.frameidcounter == 0: + clss.frameidcounter = 1 + + return clss.frameidcounter + def setframeid(self, value): if (value < 0 or value > 255): raise ValueError("FrameID must be 0-255") @@ -269,8 +280,8 @@ raise TypeError("incorrect number of arguments"); def __str__(self): - return "TX_%d_Bit 0x%0*x <- %s" % (self.ADDR_SIZE * 8, self.ADDR_SIZE * 2, self.recipient, - self.payload) + return "TX_%d_Bit ID: %d 0x%0*x <- %s" % (self.ADDR_SIZE * 8, self._frameid, self.ADDR_SIZE * 2, + self.recipient, self.payload) def setrecipient(self, value): if (value < 0 or value > 2 ** (self.ADDR_SIZE * 8)):