File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -268,13 +268,20 @@ def send_message(self, msg: Message) -> None:
268
268
msg_text = msg_text .strip ("\n " ).strip ("\r " ).strip ("\t " )
269
269
if self ._language_filter :
270
270
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 ()
271
278
msg_packet = MessagePacket (
272
279
from_call = self .from_call ,
273
280
to_call = msg .to .callsign ,
274
281
addresse = msg .to .callsign ,
275
282
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
278
285
)
279
286
msg_packet ._build_raw ()
280
287
try :
Original file line number Diff line number Diff line change @@ -38,3 +38,14 @@ def email(self) -> None:
38
38
@property
39
39
def callsign (self ) -> str :
40
40
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
Original file line number Diff line number Diff line change 1
1
import asyncio
2
+ from threading import RLock
2
3
3
4
4
5
class MessageCounter :
5
6
def __init__ (self , initial_value : int = 1 , max_message_count : int = 999 ):
6
7
self ._lock = asyncio .Lock ()
8
+ self ._sync_lock = RLock ()
7
9
self ._value = initial_value
8
10
self ._max = max_message_count
9
11
@@ -19,3 +21,13 @@ async def get_value(self, increment: bool = True) -> int:
19
21
async with self ._lock :
20
22
this_val = self ._value
21
23
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
You can’t perform that action at this time.
0 commit comments