mirror of
https://github.com/meshtastic/python.git
synced 2026-01-09 00:07:56 -05:00
precalculate bit-shifts and don't generate too-large random numbers for packet ID generation
This commit is contained in:
@@ -803,9 +803,9 @@ class MeshInterface: # pylint: disable=R0902
|
||||
)
|
||||
else:
|
||||
nextPacketId = (self.currentPacketId + 1) & 0xFFFFFFFF
|
||||
nextPacketId = nextPacketId & (0xFFFFFFFF >> 22) # mask upper 22 bits
|
||||
randomPart = (random.randint(0, 0x7FFFFFFF) << 10) & 0xFFFFFFFF # generate number with 10 zeros at end
|
||||
self.currentPacketId = nextPacketId | randomPart # combine
|
||||
nextPacketId = nextPacketId & 0x3FF # == (0xFFFFFFFF >> 22), masks upper 22 bits
|
||||
randomPart = (random.randint(0, 0x3FFFFF) << 10) & 0xFFFFFFFF # generate number with 10 zeros at end
|
||||
self.currentPacketId = nextPacketId | randomPart # combine
|
||||
return self.currentPacketId
|
||||
|
||||
def _disconnected(self):
|
||||
|
||||
Reference in New Issue
Block a user