-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.py
79 lines (62 loc) · 6.58 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import socket
import string
from datetime import datetime
from ysf import ysfpayload, ysffich
from ysf.ysffich import DT
def now():
dt = datetime.now()
return datetime.timestamp(dt)
def pad(data: bytes, length: int) -> bytes:
padding_length = length - len(data)
return data + b'\x20' * padding_length
def validate_dg_id_map(dgid_to_tg_map: dict) -> bool:
# checks that a TG appears only one
return len(set(dgid_to_tg_map.values())) == len(dgid_to_tg_map)
def close_socket(sock):
try:
sock.shutdown(socket.SHUT_RD)
except OSError as e:
pass
sock.close()
def consume_tail(sock):
sock.settimeout(0.11)
for i in range(5):
try:
sock.recvfrom(1024)
except TimeoutError:
pass
except socket.timeout:
pass
sock.setblocking(True)
def send_tg_change_tx(callsign, tg: int, sock, client_addr):
payloads = [
b'\x00\xd4q\xc9cM\x11m8\xdc\xec"\x01\xff0\x0e\xd0r\x82x\xec`3\x00\x86q}\\ \xa6o\xf3\xed\xc3\x08\x10S\x1b\xdd \xfb#S\x08\x1c\xa3_= \xbf\xa5\xf5\x83\xd2\x99&\xe1|\xb6.\xfa\xb3\xd2\x9b6D\xbc\xdd\xae,\xff\xf3\xfd\x14\x9c\x8b\xdd\xa8\xfd\xdf\xb3\xfd\x19\xddvY\xaf\x07>[\x8dI\x93\x8f\x19\xaf\x0b\x15%\rI\x96(\x04]\x165W\xf7\xed\x01\x8f\x13]\x16\x0e@U\xad\x01\xaf',
b"\x02\xd4q\xc9cM!\x9d85\x93\xe1\x91\xffG\xf0\x91\x82\x81|v,\xf3\x02\x18Z\xf7\x9c S'\xe7{\xe2\x91\x02{\xbb\x04\xe9\xb6\xf4\xb29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\x14\x9c\x8b\xdd\xa8\xfd\xdf\xb3\xfd\x19\xddvY\xaf\x07>[\x8dI\x93\x8f\x19\xaf\x0b\x15%\rI\x96(\x04]\x165W\xf7\xed\x01\x8f\x13]\x16\x0e@U\xad\x01\xaf'
]
encoded_call = pad(callsign.encode(), 10)
messages = ["YSFD".encode() + encoded_call + encoded_call + pad("ALL".encode(), 10) + d for d in payloads]
src = f"TG{tg}".ljust(10).encode()
for i in range(0, len(messages)):
data = messages[i]
ysffich.decode(data[40:])
fn = ysffich.getFN()
dt = ysffich.getDT()
if fn == 1 and dt == DT.VD2:
payload = bytearray(data[35:])
ysfpayload.writeVDMmode2Data(payload, src)
messages[i] = data[:35] + payload
sock.sendto(messages[i], client_addr)