forked from jfrancis42/js8net-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs8net.py
More file actions
executable file
·748 lines (691 loc) · 26.6 KB
/
js8net.py
File metadata and controls
executable file
·748 lines (691 loc) · 26.6 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
#!/usr/bin/env python3
# coding: utf-8
import sys
import socket
import json
import time
import threading
import traceback
from threading import Thread
from queue import Queue
# Defaults within JS8Call.
global eom
global error
global timeout
eom="♢"
error="…"
timeout=1.0
# These are our global objects (and locks for them).
global tx_queue
global tx_lock
global rx_queue
global rx_lock
global spots_lock
global unique
global unique_lock
global s
s=False
tx_queue=Queue()
tx_lock=threading.Lock()
rx_queue=Queue()
rx_lock=threading.Lock()
spots_lock=threading.Lock()
unique_lock=threading.Lock()
# These globals represent the state of JS8Call.
global spots
global dial
global freq
global offset
global grid
global info
global call
global speed
global ptt
global tx_text
global rx_text
global last_rx
global mycall
global messages
global call_activity
global call_selected
global band_activity
spots={}
unique=0
# Note that this assumes US bandplan. TODO: Figure out how to make
# this "locale-friendly" for different countries with different
# bandplans.
def calc_band(freq):
if(freq>=1800000 and freq<=2000000):
return("160m")
elif(freq>=3500000 and freq<=4000000):
return("80m")
elif(freq>=5330000 and freq<=5410000):
return("60m")
elif(freq>=7000000 and freq<=7300000):
return("40m")
elif(freq>=10100000 and freq<=10150000):
return("30m")
elif(freq>=14000000 and freq<=14350000):
return("20m")
elif(freq>=18068000 and freq<=18168000):
return("17m")
elif(freq>=21000000 and freq<=21450000):
return("15m")
elif(freq>=24890000 and freq<=24990000):
return("12m")
elif(freq>=28000000 and freq<=29700000):
return("10m")
elif(freq>=50000000 and freq<=54000000):
return("6m")
elif(freq>=144000000 and freq<=148000000):
return("2m")
elif(freq>=219000000 and freq<=225000000):
return("1.25m")
elif(freq>=420000000 and freq<=450000000):
return("70cm")
else:
return(False)
# Process an incoming message, and record any useful stats about it
# (currently, time, band, grid, speed, snr).
# ToDo: Periodically fetch and parse RX.BAND_ACTIVITY
def process_message(msg):
global spots
global spots_lock
global mycall
global error
global messages
# Process INBOX messages.
if('MESSAGES' in msg['params']):
messages=msg['params']['MESSAGES']
# If it's a SPOT message, we get everything but speed.
if(msg['type']=="RX.SPOT"):
with spots_lock:
band=calc_band(msg['params']['FREQ'])
if(mycall not in spots):
spots[mycall]={}
if(msg['params']['CALL'] not in spots[mycall]):
spots[mycall][msg['params']['CALL']]=[]
grid=False
if(msg['params']['GRID']!=""):
grid=msg['params']['GRID']
spots[mycall][msg['params']['CALL']].append({'time':msg['time'],
'band':band,
'grid':grid,
'speed':False,
'snr':msg['params']['SNR']})
# If it's a DIRECTED message, we should get everything we hope
# for, plus maybe some extras, depending on what the CMD is.
if(msg['type']=="RX.DIRECTED"):
with spots_lock:
band=calc_band(msg['params']['FREQ'])
if(mycall not in spots):
spots[mycall]={}
if(msg['params']['FROM'] not in spots[mycall]):
spots[mycall][msg['params']['FROM']]=[]
grid=False
if(msg['params']['GRID']!=""):
grid=msg['params']['GRID']
spots[mycall][msg['params']['FROM']].append({'time':msg['time'],
'band':band,
'grid':grid,
'speed':msg['params']['SPEED'],
'snr':msg['params']['SNR']})
# If it's an SNR reply, we get to find out how one station
# hears another, not just how we hear them.
if(msg['params']['CMD']==" HEARTBEAT SNR" or
msg['params']['CMD']==" SNR"):
grid=False
if(msg['params']['GRID']!=""):
grid=msg['params']['GRID']
if(msg['params']['FROM'] not in spots):
spots[msg['params']['FROM']]={}
if(msg['params']['TO'] not in spots[msg['params']['FROM']]):
spots[msg['params']['FROM']][msg['params']['TO']]=[]
spots[msg['params']['FROM']][msg['params']['TO']].append({'time':msg['time'],
'band':band,
'grid':grid,
'speed':msg['params']['SPEED'],
'snr':int(msg['params']['EXTRA'])})
# If somebody replies to a GRID? request, capture and save
# the reply.
elif(msg['params']['CMD']==" GRID"):
grid=msg['params']['TEXT'].split()
band=calc_band(msg['params']['FREQ'])
if(len(grid)>=4):
grid=grid[3]
if(not(error in grid)):
if(msg['params']['FROM'] not in spots):
spots[msg['params']['FROM']]={}
if(msg['params']['TO'] not in spots[msg['params']['FROM']]):
spots[msg['params']['FROM']][msg['params']['TO']]=[]
spots[msg['params']['FROM']][msg['params']['TO']].append({'time':msg['time'],
'band':band,
'grid':grid,
'speed':msg['params']['SPEED'],
'snr':False})
# If somebody reports who they're hearing, save that.
elif(msg['params']['CMD']==" HEARING"):
grid=False
band=calc_band(msg['params']['FREQ'])
speed=msg['params']['SPEED']
if(msg['params']['GRID']!=""):
grid=msg['params']['GRID']
if('FROM' in msg['params']):
if(msg['params']['FROM'] not in spots):
spots[msg['params']['FROM']]={}
if(not(error in msg['params']['TEXT'])):
hearing=msg['params']['TEXT'].split()[3:-1]
for h in hearing:
if(h not in msg['params']['FROM']):
spots[msg['params']['FROM']][h]=[]
spots[msg['params']['FROM']][h].append({'time':msg['time'],
'band':band,
'grid':False,
'speed':speed,
'snr':False})
# elif(msg['params']['CMD']==" QUERY CALL"):
# n=True
# else:
# n=True
# Add a message to the outgoing message queue.
def queue_message(message):
global tx_queue
global tx_lock
with tx_lock:
tx_queue.put(message)
# This thread watches the transmit queue and sends data to JS8
# whenever something appears in the queue.
def tx_thread(name):
global tx_queue
global tx_lock
# Run forever. Delay 0.25 seconds between each send, because
# sending too quickly jacks up comms with JS8.
while(True):
thing=json.dumps(tx_queue.get())
with tx_lock:
s.sendall(bytes(thing+"\r\n",'utf-8'))
time.sleep(0.25)
# Station class for RX.CALL_ACTIVITY
class Callstation:
def __init__(self,call,stuff):
self.call=call
self.snr=stuff['SNR']
self.utc=stuff['UTC']/1000
if(stuff['GRID']==''):
self.grid=False
else:
self.grid=stuff['GRID'].strip()
def age(self):
return(round(time.time()-self.utc))
def string(self):
if(self.grid):
return('Call: '+self.call+'\tSNR: '+str(self.snr)+' \tAge: '+str(self.age())+
' \tGrid: '+str(self.grid))
else:
return('Call: '+self.call+'\tSNR: '+str(self.snr)+' \tAge: '+str(self.age()))
# Station class for RX.BAND_ACTIVITY
class Bandstation:
def __init__(self,stuff):
self.dial=stuff['DIAL']
self.freq=stuff['FREQ']
self.offset=stuff['OFFSET']
self.snr=stuff['SNR']
self.text=stuff['TEXT']
self.utc=stuff['UTC']/1000
def age(self):
return(round(time.time()-self.utc))
def string(self):
return('Freq: '+str(self.freq/1000)+' khz ('+str(self.dial/1000)+' khz + '+
str(self.offset)+' hz) \tSNR: '+str(self.snr)+' \tAge: '+
str(self.age())+' \t Text: '+str(self.text))
# Due to the way JS8Call sends data to an API client (ie, it just
# sends random JSON data whenever it pleases), we'll receive all
# messages in a thread so it'll all work in the background.
def rx_thread(name):
global spots
global dial
global freq
global offset
global grid
global info
global call
global speed
global ptt
global tx_text
global rx_text
global call_activity
global call_selected
global band_activity
n=0
left=False
empty=True
# Run forever.
while(True):
try:
# Get a chunk of text and process it. Each valid chunk of
# data ends in a \n. This is epically painful due to py3's
# multi-byte characters.
string=""
stuff=s.recv(65535)
if(not(empty)):
stuff=left+stuff
if(stuff[0:1]==b'{' and stuff[-2:-1]==b'}'):
string=stuff.decode("utf-8")
empty=True
else:
if(empty):
empty=False
left=stuff
if(string==""):
message={"type":"empty"}
else:
string=string.rstrip("\n")
for m in string.split("\n"):
message=json.loads(m)
now=time.time()
message['time']=now
last_rx=now
# If the message contains something we need to
# process (for example, the result of a frequency
# query), do it. If it's just incoming text, queue
# it for the user.
if('params' in list(message.keys())):
if('TEXT' in list(message['params'].keys())):
if(error in message['params']['TEXT']):
message['rxerror']=True
else:
message['rxerror']=False
processed=False
try:
process_message(message)
except Exception:
print("Message: ",message)
traceback.print_exc()
if(message['type']=="RIG.FREQ"):
processed=True
dial=message['params']['DIAL']
freq=message['params']['FREQ']
offset=message['params']['OFFSET']
elif(message['type']=="STATION.CALLSIGN"):
processed=True
call=message['value']
elif(message['type']=="STATION.GRID"):
processed=True
grid=message['value']
elif(message['type']=="STATION.INFO"):
processed=True
info=message['value']
elif(message['type']=="MODE.SPEED"):
processed=True
speed=str(message['params']['SPEED'])
elif(message['type']=="RIG.PTT"):
processed=True
if(message['value'])=="on":
ptt=True
else:
ptt=False
elif(message['type']=="RX.CALL_SELECTED"):
#RSJC
call_selected=message['value']
processed=True
elif(message['type']=="TX.FRAME"):
processed=True
elif(message['type']=="TX.TEXT"):
processed=True
tx_text=message['value']
elif(message['type']=="RX.TEXT"):
# Note that we don't mark this as 'processed'
# (even though it is), as the user may want to
# watch for incoming text to take his own
# action.
rx_text=message['value']
elif(message['type']=="RX.CALL_ACTIVITY"):
processed=True
tmp=message['params']
if('_ID' in tmp):
del(tmp['_ID'])
stations=list(map(lambda c: Callstation(c,tmp[c]),list(tmp.keys())))
call_activity=stations
elif(message['type']=="RX.BAND_ACTIVITY"):
processed=True
tmp=message['params']
if('_ID' in tmp):
del(tmp['_ID'])
stations=list(map(lambda c: Bandstation(tmp[c]),list(tmp.keys())))
band_activity=stations
elif(message['type']=="RX.SPOT"):
processed=True
# The following message types are delivered to the
# rx_queue for user processing (though some of
# them are also internally processed):
# RX.DIRECTED, RX.ACTIVITY, RX.SPOT,
# RX.BAND_ACTIVITY, RX.TEXT. If any other messages
# show up in the queue, it's a bug.
if(not(processed)):
with rx_lock:
rx_queue.put(message)
time.sleep(0.1)
except socket.timeout:
# Ignore for now. TODO: Be smarter here.
n=n+1
time.sleep(0.1)
# This thread makes sure the connection is alive by sending a
# heartbeat request (specifically, a request for callsign) every five
# minutes.
def hb_thread(name):
# Run forever. Sleep five minutes between runs.
global mycall
while(True):
mycall=get_callsign()
time.sleep(300)
def start_net(host,port):
global s
# Open a socket to JS8Call.
s=socket.socket()
s.connect((host,int(port)))
s.settimeout(1)
# Start the RX thread. We make this a daemon thread so that it
# will automatically die when the main thread dies. Kind of dirty,
# but there's no risk of data loss, and the OS will automatically
# take care of the socket clean-up when the process exits.
thread1=Thread(target=rx_thread,args=("RX Thread",),daemon=True)
thread1.start()
# Start the TX thread. Also a daemon thread.
thread2=Thread(target=tx_thread,args=("TX Thread",),daemon=True)
thread2.start()
# Start the heartbeat thread. Also a daemon thread.
thread3=Thread(target=hb_thread,args=("HB Thread",),daemon=True)
thread3.start()
time.sleep(1)
def get_freq():
# Ask JS8Call to get the radio's frequency. Returns the dial
# frequency (in hz), the offset in the audio passband (in hz), and
# the actual effective transmit frequency (basically the two
# values added together) as a JSON blob.
global dial
global freq
global offset
global timeout
dial=False
freq=False
offset=False
queue_message({"params":{},"type":"RIG.GET_FREQ","value":""})
now=time.time()
while(not(dial) or not(freq) or not(offset)):
if(time.time()>now+timeout):
return(False)
time.sleep(0.1)
return({"dial":dial,"freq":freq,"offset":offset})
def set_freq(dial,offset):
# Set the radio's dial freq (in hz) and the offset within the
# passband (also in hz).
queue_message({"params":{"DIAL":dial,"OFFSET":offset},"type":"RIG.SET_FREQ","value":""})
time.sleep(0.1)
return(get_freq())
def get_messages():
# Fetch all inbox messages.
queue_message({"params":{},"type":"INBOX.GET_MESSAGES","value":""})
global messages
global timeout
messages=False
now=time.time()
while(not(messages)):
if(time.time()>now+timeout):
return(False)
time.sleep(0.1)
return(messages)
def store_message(callsign,text):
# Store a message in the INBOX for later pickup by recipient.
queue_message({"params":{"CALLSIGN":callsign,"TEXT":text},"type":"INBOX.STORE_MESSAGE","value":""})
time.sleep(0.1)
return(get_messages())
def get_callsign():
# Ask JS8Call for the configured callsign.
global call
global timeout
call=False
queue_message({"params":{},"type":"STATION.GET_CALLSIGN","value":""})
now=time.time()
while(not(call)):
if(time.time()>now+timeout):
return(False)
time.sleep(0.1)
return(call)
def get_grid():
# Ask JS8Call for the configured grid square.
global grid
global timeout
grid=False
queue_message({'params':{},'type':'STATION.GET_GRID','value':''})
now=time.time()
while(not(grid)):
if(time.time()>now+timeout):
return(False)
time.sleep(0.1)
return(grid)
def set_grid(grid):
# Set the grid square.
queue_message({"params":{},"type":"STATION.SET_GRID","value":grid})
return(get_grid())
def send_aprs_grid(grid):
# Send the supplied grid info to APRS (use
# send_aprs_grid(get_grid()) to send your configured grid square).
send_message("@APRSIS GRID "+grid)
def send_heartbeat(grid=False):
# Send a heartbeat message.
if(not(grid)):
grid=get_grid()
if(len(grid)>=4):
grid=grid[0:4]
send_message(get_callsign()+": @HB HEARTBEAT "+grid)
def send_sms(phone,message):
# Send an SMS message via JS8.
global unique
global unique_lock
with unique_lock:
unique=unique+1
if(unique>99):
unique=1
send_message("@APRSIS CMD :SMSGTE :@"+phone+" "+message+"{%02d}" % unique)
def send_email(address,message):
# Send an email message via JS8.
global unique
global unique_lock
with unique_lock:
unique=unique+1
if(unique>99):
unique=1
send_message("@APRSIS CMD :EMAIL-2 :"+address+" "+message+"{%02d}" % unique)
def send_aprs(dest,message):
# Send an APRS message to the destination call. Your call is sent
# as configured in JS8Call. Be reasonable with the message
# length. I'm not certain what the length limit in APRS is, but
# there almost certainly is one.
global unique
global unique_lock
dest=dest[0:9]
while(len(dest)<9):
dest=dest+" "
with unique_lock:
unique=unique+1
if(unique>99):
unique=1
send_message("@APRSIS CMD :"+dest+":"+message+"{%02d}" % unique)
def send_sota(summit,freq,mode,comment=False):
# Send a SOTA spot. freq is an integer in khz (ie, 7200, 14300,
# 144200). Your call is sent as configured in JS8Call. Don't get
# too creative with the mode. Stick with the basics: USB, LSB,
# SSB, AM, FM, CW, etc, lest your message get dropped.. You must
# pre-register with the SOTA gateway for this to work:
# https://www.sotaspots.co.uk/Aprs2Sota_Info.php
global unique
global unique_lock
with unique_lock:
unique=unique+1
if(unique>99):
unique=1
if(comment):
send_message("@APRSIS CMD :APRS2SOTA:"+get_callsign()+";"+summit+";"+str(int(freq))+";"+mode+";"+comment+"{%02d}" % unique)
else:
send_message("@APRSIS CMD :APRS2SOTA:"+get_callsign()+";"+summit+";"+str(int(freq))+";"+mode+"{%02d}" % unique)
def send_pota(park,freq,mode,comment=False):
# Send a POTA spot. freq is an integer in khz (ie, 7200, 14300,
# 144200). Your call is sent as configured in JS8Call.
global unique
global unique_lock
with unique_lock:
unique=unique+1
if(unique>99):
unique=1
if(comment):
send_message("@APRSIS CMD :POTAGW :"+get_callsign()+" "+park+" "+str(int(freq))+" "+mode+" "+comment+"{%02d}" % unique)
else:
send_message("@APRSIS CMD :POTAGW :"+get_callsign()+" "+park+" "+str(int(freq))+" "+mode+"{%02d}" % unique)
def get_info():
# Ask JS8Call for the configured info field.
global info
global timeout
info=False
queue_message({"params":{},"type":"STATION.GET_INFO","value":""})
now=time.time()
while(not(info)):
if(time.time()>now+timeout):
return(False)
time.sleep(0.1)
return(info)
def set_info(info):
# Set the info field.
queue_message({"params":{},"type":"STATION.SET_INFO","value":info})
return(get_info())
def get_call_activity():
# Get the contents of the right white window.
global call_activity
call_activity=False
queue_message({"params":{},"type":"RX.GET_CALL_ACTIVITY","value":""})
now=time.time()
while(not(call_activity)):
if(time.time()>now+timeout):
return(False)
time.sleep(0.1)
return(call_activity)
def get_call_selected():
# Never quite figured out what this does. I assume based on the
# name that it returns the value of whichever callsign has been
# clicked on in the right window, but I haven't gotten 'round to
# testing this theory. ToDo: figure this out
# RSJC - Yes that is exactly what it does, need this functionality for my telegram bot
# Have added below to get the value
global call_selected
call_selected=False
queue_message({"params":{},"type":"RX.GET_CALL_SELECTED","value":""})
now=time.time()
while(not(call_selected)):
if(time.time()>now+timeout):
return(False)
time.sleep(0.1)
print(call_selected)
return(call_selected)
def get_band_activity():
# Get the contents of the left white window.
global band_activity
band_activity=False
queue_message({"params":{},"type":"RX.GET_BAND_ACTIVITY","value":""})
now=time.time()
while(not(band_activity)):
if(time.time()>now+timeout):
return(False)
time.sleep(0.1)
return(band_activity)
def get_rx_text():
# Get the contents of the yellow window.
global rx_text
global timeout
rx_text='-=-=-=-shibboleeth-=-=-=-'
queue_message({"params":{},"type":"RX.GET_TEXT","value":""})
now=time.time()
while(rx_text=='-=-=-=-shibboleeth-=-=-=-'):
if(time.time()>now+timeout):
return(False)
time.sleep(0.1)
return(rx_text)
def get_tx_text():
# Get the contents of the window below yellow window.
global tx_text
global timeout
tx_text='-=-=-=-shibboleeth-=-=-=-'
queue_message({"params":{},"type":"TX.GET_TEXT","value":""})
now=time.time()
while(tx_text=='-=-=-=-shibboleeth-=-=-=-'):
if(time.time()>now+timeout):
return(False)
time.sleep(0.1)
return(tx_text)
def set_tx_text(text):
# Set the contents of the window below yellow window.
global tx_text
queue_message({"params":{},"type":"TX.SET_TEXT","value":text})
return(get_tx_text())
def get_speed():
# Ask JS8Call what speed it's currently configured for.
# slow==4, normal==0, fast==1, turbo==2
global speed
global timeout
speed=False
queue_message({"params":{},"type":"MODE.GET_SPEED","value":""})
now=time.time()
while(not(speed)):
if(time.time()>now+timeout):
return(False)
time.sleep(0.1)
return(speed)
def speed_name(speed):
if(speed>=0 and speed<=4):
return(['Normal', 'Fast', 'Turbo', 'Invalid', 'Slow'][speed])
else:
return('Invalid')
def set_speed(speed):
# Set the JS8Call transmission speed.
# slow==4, normal==0, fast==1, turbo==2
queue_message({"params":{"SPEED":speed},"type":"MODE.SET_SPEED","value":""})
return(get_speed())
def raise_window():
# Raise the JS8Call window to the top.
queue_message({"params":{},"type":"WINDOW.RAISE","value":""})
def send_message(message):
# Send 'message' in the next transmit cycle.
queue_message({"params":{},"type":"TX.SEND_MESSAGE","value":message})
def send_directed_message(dest_call,message):
# Send directed 'message' (to a specific call sign) in the next
# transmit cycle.
queue_message({"params":{},"type":"TX.SEND_MESSAGE","value":dest_call+" "+message})
def send_inbox_message(dest_call,message):
# Send directed 'message' (to a specific call sign) in the next
# transmit cycle.
queue_message({"params":{},"type":"TX.SEND_MESSAGE","value":dest_call+" MSG "+message})
def alive():
# Return true if the TCP connection appears to still be alive (ie,
# a valid response was received in the last five minutes + wiggle
# room). Else return false. It's up to you to re-establish comms
# if the connection has failed.
global last_rx
if(time.time()-last_rx<=335):
return(true)
else:
return(false)
def query_snr(dest_call):
# Query a station for your SNR report.
queue_message({"params":{},"type":"TX.SEND_MESSAGE","value":dest_call+" SNR? "})
def query_grid(dest_call):
# Query a station for their grid square.
queue_message({"params":{},"type":"TX.SEND_MESSAGE","value":dest_call+" GRID? "})
def query_status(dest_call):
# Query a station for their status.
queue_message({"params":{},"type":"TX.SEND_MESSAGE","value":dest_call+" STATUS? "})
def query_info(dest_call):
# Query a station for their info.
queue_message({"params":{},"type":"TX.SEND_MESSAGE","value":dest_call+" INFO? "})
def query_hearing(dest_call):
# Query a station for top stations heard.
queue_message({"params":{},"type":"TX.SEND_MESSAGE","value":dest_call+" HEARING? "})
if __name__ == '__main__':
print("This is a library and is not intended for stand-alone execution.")