Skip to content

Commit d5b57eb

Browse files
fix: bugfixes
This is a bugfix commit
1 parent 781e855 commit d5b57eb

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

aprs_backend/aprs.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,20 @@ def send_message(self, msg: Message) -> None:
268268
msg_text = msg_text.strip("\n").strip("\r").strip("\t")
269269
if self._language_filter:
270270
msg_text = profanity.censor(msg_text)
271+
msgNo = None
272+
last_send_attempt = 0
273+
if "packet" in msg.extras:
274+
msgNo = getattr(msg.extras["packet"], "msgNo", None)
275+
last_send_attempt = getattr(msg.extras["packet"], "last_send_attempt", 0)
276+
if msgNo is None:
277+
msgNo = self._message_counter.get_value_sync()
271278
msg_packet = MessagePacket(
272279
from_call=self.from_call,
273280
to_call=msg.to.callsign,
274281
addresse=msg.to.callsign,
275282
message_text=msg_text,
276-
msgNo=msg.extras["packet"].msgNo,
277-
last_send_attempt=msg.extras["packet"].last_send_attempt
283+
msgNo=msgNo,
284+
last_send_attempt=last_send_attempt
278285
)
279286
msg_packet._build_raw()
280287
try:

aprs_backend/person.py

+11
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ def email(self) -> None:
3838
@property
3939
def callsign(self) -> str:
4040
return self._callsign
41+
42+
def __eq__(self, other: any) -> bool:
43+
if isinstance(other, APRSPerson):
44+
return self._callsign.lower() == other._callsign.lower()
45+
return False
46+
47+
def __hash__(self):
48+
return hash(self._callsign)
49+
50+
def __str__(self):
51+
return self._callsign

aprs_backend/utils/counter.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import asyncio
2+
from threading import RLock
23

34

45
class MessageCounter:
56
def __init__(self, initial_value: int = 1, max_message_count: int = 999):
67
self._lock = asyncio.Lock()
8+
self._sync_lock = RLock()
79
self._value = initial_value
810
self._max = max_message_count
911

@@ -19,3 +21,13 @@ async def get_value(self, increment: bool = True) -> int:
1921
async with self._lock:
2022
this_val = self._value
2123
return this_val
24+
25+
def get_value_sync(self, increment: bool = True) -> int:
26+
if increment:
27+
with self._sync_lock:
28+
self._value += 1
29+
if self._value > self._max:
30+
self._value = 1
31+
with self._sync_lock:
32+
this_val = self._value
33+
return this_val

0 commit comments

Comments
 (0)