# HG changeset patch # User darius@Inchoate # Date 1232165390 -37800 # Node ID 729f2393f29672a846e3546cc7ebf789a95e3139 # Parent a3ec3f2988ac8b59b7d9004c25d19b34c5a06273 Auto increment frame ID when creating a TX packet. diff -r a3ec3f2988ac -r 729f2393f296 zb.py --- 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)):