From 873fc066080cb588658e56574100dd5200e1edbc Mon Sep 17 00:00:00 2001 From: Hemna Date: Sat, 23 Mar 2024 17:53:01 -0400 Subject: [PATCH] added packet counter random int The packet counter now starts at a random number between 1 and 9999 instead of always at 1. --- aprsd/packets/core.py | 2 +- aprsd/utils/counter.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/aprsd/packets/core.py b/aprsd/packets/core.py index 9372000..861cabf 100644 --- a/aprsd/packets/core.py +++ b/aprsd/packets/core.py @@ -167,7 +167,7 @@ class Packet: # 67 displays 64 on the ftm400. (+3 {01 suffix) # feature req: break long ones into two msgs if not msg: - raise ValueError("No message text to send. call prepare() first.") + return "" message = msg[:67] # We all miss George Carlin diff --git a/aprsd/utils/counter.py b/aprsd/utils/counter.py index 5f569f4..30b6b75 100644 --- a/aprsd/utils/counter.py +++ b/aprsd/utils/counter.py @@ -1,9 +1,13 @@ from multiprocessing import RawValue +import random import threading import wrapt +MAX_PACKET_ID = 9999 + + class PacketCounter: """ Global Packet id counter class. @@ -17,19 +21,18 @@ class PacketCounter: """ _instance = None - max_count = 9999 lock = threading.Lock() def __new__(cls, *args, **kwargs): """Make this a singleton class.""" if cls._instance is None: cls._instance = super().__new__(cls, *args, **kwargs) - cls._instance.val = RawValue("i", 1) + cls._instance.val = RawValue("i", random.randint(1, MAX_PACKET_ID)) return cls._instance @wrapt.synchronized(lock) def increment(self): - if self.val.value == self.max_count: + if self.val.value == MAX_PACKET_ID: self.val.value = 1 else: self.val.value += 1