-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsjtmess.py
221 lines (154 loc) · 5.54 KB
/
wsjtmess.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
def isloc(loc):
if len(loc) != 4 or loc == 'RR73':
return False
if loc[0].isalpha() and loc[1].isalpha() and loc[2].isdigit() and loc[3].isdigit():
return True
return False
def decode21(data):
data = data[12:]
strl = int.from_bytes(data[0:4], byteorder='big')
app_id = data[4:4+strl].decode("utf-8")
print("app-id", app_id)
data = data[4+strl:]
# Dial freq
dial_freq = int.from_bytes(data[0:8], byteorder='big')
print("dial", dial_freq, data[0:8])
data = data[8:]
# Mode
strl = int.from_bytes(data[0:4], byteorder='big')
mode = data[4:4+strl].decode("utf-8")
data = data[4+strl:]
print("mode:", strl, mode)
# DX call
strl = int.from_bytes(data[0:4], byteorder='big')
if strl == 4294967295:
strl = 0
dx_call = data[4:4+strl].decode("utf-8")
data = data[4+strl:]
print("DX", dx_call, strl)
# Report
strl = int.from_bytes(data[0:4], byteorder='big')
report = data[4:4+strl].decode("utf-8")
data = data[4+strl:]
print("report", report, strl)
# Tx-mode
strl = int.from_bytes(data[0:4], byteorder='big')
txmode = data[4:4+strl].decode("utf-8")
data = data[4+strl:]
print("txmode", txmode, strl)
# Status
txenabled = int(data[0])
transmitting = int(data[1])
decoding = int(data[2])
data = data[3:]
# TX & RX drift
rx_df = int.from_bytes(data[0:4], byteorder='big')
tx_df = int.from_bytes(data[4:8], byteorder='big')
data = data[8:]
# DE call
strl = int.from_bytes(data[0:4], byteorder='big')
if strl == 4294967295:
strl = 0
de_call = data[4:4+strl].decode("utf-8")
data = data[4+strl:]
# DE grid
strl = int.from_bytes(data[0:4], byteorder='big')
if strl == 4294967295:
strl = 0
de_grid = data[4:4+strl].decode("utf-8")
data = data[4+strl:]
print("de_grid", de_grid, strl, data)
# DX grid
strl = int.from_bytes(data[0:4], byteorder='big')
if strl == 4294967295:
strl = 0
dx_grid = data[4:4+strl].decode("utf-8")
print("dx-grid", dx_grid)
data = data[4+strl:]
# print("dog", data)
# # Tx Watchdog
# tx_watchdog = int(data[0])
# data = data[1:]
# print("subm", data)
# # Sub-Mode
# strl = int.from_bytes(data[0:4], byteorder='big')
# submode = data[4:4+strl].decode("utf-8")
# data = data[4+strl:]
# print("fast", data)
# # Fast mode
# fast_mode = int(data[0])
# data = data[1:]
# # Special operation mode
# spec_mode = int.from_bytes(data[0:0], byteorder='big')
# data = data[1:]
# 0 -> NONE
# 1 -> NA VHF
# 2 -> EU VHF
# 3 -> FIELD DAY
# 4 -> RTTY RU
# 5 -> FOX
# 6 -> HOUND
# print(data)
# Tx Watchdog bool
# Sub-mode utf8
# Fast mode bool
# Special operation mode quint8
statusstrnew = "Dial: %s Mode: %s DXcall: %s Report: %s TXmode: %s TXe: %s TX: %s Dec %s rxdf %s txdf %s DEcall: %s DEgrid: %s DXgrid: %s" % (dial_freq, mode, dx_call, report, txmode, txenabled, transmitting, decoding, rx_df, tx_df, de_call, de_grid, dx_grid)
print(statusstrnew)
# print("DEcall", de_call, "DEgrid:", de_grid, "DXgrid:", dx_grid)
#DEcall: %s DEgrid: %s DXgrid: %s
# print(
# print("watchdog:", tx_watchdog, "fastmode", fast_mode, "special mode", spec_mode)
# sys.exit(0)
def decode22(data):
if debug:
print("decode ")
data = data[12:]
strl = int.from_bytes(data[0:4], byteorder='big')
app_id = data[4:4+strl].decode("utf-8")
print("app-id", app_id)
data = data[4+strl:]
new = int(data[0])
print("new", new)
year = datetime.datetime.today().year
month = datetime.datetime.today().month
day = datetime.datetime.today().day
qtime = int.from_bytes(data[1:5], byteorder='big')
hour = int(qtime / (60 * 60 * 1000))
minute = int((qtime - (hour * 60 * 60 * 1000)) / (60 * 1000))
second = int((qtime % (60 * 1000)) / 1000)
time = datetime.datetime(year, month, day, hour, minute, second)
print(time)
snr = int.from_bytes(data[5:9], byteorder='big', signed=True)
data = data[9:]
print("snr", snr)
#for c in data:
# print(hex(c)[2:], end=',')
#print()
delta_time = round(struct.unpack('>d',data[0:8])[0], 5)
data = data[8:]
print("deltatime:", delta_time)
delta_fq = int.from_bytes(data[0:4], byteorder='big')
data = data[4:]
strl = int.from_bytes(data[0:4], byteorder='big')
mode = data[4:4+strl].decode("utf-8")
data = data[4+strl:]
print("mode", mode)
strl = int.from_bytes(data[0:4], byteorder='big')
message = data[4:4+strl].decode("utf-8")
data = data[4+strl:]
print("message", message)
low_conf = int(data[0])
off_air = int(data[1])
print("New: %s Time %s snr %4s dtime: %4s dfq: %4s mode: %s mess: %s" % (new, time, snr, delta_time, delta_fq, mode, message))
mess_lst = message.split()
if len(mess_lst) == 3 and mess_lst[0] == 'CQ' and isloc(mess_lst[2]):
# elif len(mess_lst) == 3 and isloc(mess_lst[2])
loc=message.split()[2]
# print("CQ3", loc, maidenhead.toLoc(loc), len(callpos))
elif len(mess_lst) == 4 and mess_lst[0] == 'CQ' and isloc(mess_lst[3]):
loc=message.split()[3]
# print("CQ4", loc, maidenhead.toLoc(loc))
elif len(mess_lst) == 3 and isloc(mess_lst[2]):
loc=message.split()[2]
# print(loc, maidenhead.toLoc(loc), len(callpos))