-
Notifications
You must be signed in to change notification settings - Fork 1
/
icom7300.py
executable file
·4628 lines (4072 loc) · 199 KB
/
icom7300.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
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
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env python3
""" icom7300.py control an icom ic-7300 radio via serial port """
# pylint: disable=C0302
#
# Author: Tom N4LSJ -- EXPERIMENTAL CODE ONLY FOR TINKERING
# -- USE AT YOUR OWN RISK ONLY
# -- AUTHOR ASSUMES NO LIABILITY
#
# INSTRUCTIONS:
#
# By using this program, you agree it is at your own risk.
# What works great on my computer may work horribly on yours.
#
# Back up your radio to SD card in radio's slot before proceeding.
#
# This program needs python 3 to run. It will not work with
# python 2. You may have to install some python modules to
# get it to work. The most likely module you'll need to
# install is pyserial, with pip3 install pyserial
#
# EVERYTHING IN THE COMMENTS BELOW THIS LINE IS EXPERIMENTAL
#
# DEFAULT TCP/IP PORT NUMBERS FOR PYCOM SUITE
#
# WEB BROWSER MAP 7521
# WEB BROWSER AUD 7522
# WEB MAP QSY 7523
# LOGGER READ CI-V 7524
#
# WHY ALL THE PORTS? This is in case you're running all programs on the same machine.
#
# NETWORK CHAIN W/PyCOM-7300 and WEB BROWSER
#
# WEB BROWSER -> (HTTP) 7521 -> PYSKIMMER -> (QSY) 7523 -> PyCOM-7300
# PYSKIMMER may run on a separate machine
# PyCOM-7300 may run on a separate or third as well
# PyCOM-7300 must be the one connected to the radio via its serial/usb port
# You may run all these on the same machine if the CPU will allow it.
#
# N3FJP or SKCC LOGGER can read the radio's frequency via CI-V by emulating the serial port.
# set up n3fjp 115200 COM4 Icom2 FE FE 94 E0 03 FD and FE FE 94 E0 04 FD
# or skcc logger 115200 etc...
#
# In WINDOWS LAND
# LOGGER -> com0com/COM4->com0com/cncb0 -> com2tcp --ignore-dsr --baud 115200 \\.\cncb0 IPADDR-PyC-7300 7524
# (may or may not also need --telnet option)
# (talks in CI-V language directly)
#
# In LINUX LAND
# LOGGER -> /usr/bin/socat -W /tmp/logger_socket -d -d pty,link=/dev/ttyS0,b115200,cfmakeraw,mode=666,group-late=dialout TCP:(PyCOM-7300 IP):7523
#
#
import sys
import math
import textwrap
import collections
import time
import multiprocessing
# import queue
import tkinter
import tkinter.ttk
import tkinter.messagebox
import tkinter.simpledialog
import os
import shutil
import serial.tools.list_ports
if os.name == 'posix':
import termios
import fcntl
import struct
import socket
import select
class Socky:
def __init__(self,host,port,listen_instead):
if listen_instead:
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
self.s.bind((host,port))
self.s.listen()
else:
self.s = socket.create_connection((host,port))
self.s.setblocking(0)
self.conn=None
self.data=None
self.addr=None
self.rx_until = b''
def accept(self):
try:
#print("a",end='',flush=True)
self.conn, self.addr = self.s.accept()
except:
pass
def non_blocking_rx_until(self,expected):
bb=self.rxdata()
if bb is not b'' and bb is not None:
self.rx_until += bb
if bb == expected:
retval = self.rx_until
self.rx_until = b''
return retval
return None
def rxdata(self):
if self.conn is None:
self.accept()
if self.conn is not None:
try:
self.ready_to_read, self.ready_to_send, self.in_error = \
select.select([self.conn,], [self.conn,], [], .1)
except select.error:
try:
self.conn.shutdown(2)
self.conn.close()
print("conn: select error in rxdata...")
except:
print("Disconnected from other end")
self.conn=None
if len(self.in_error) > 0:
print("conn: socket error in rxdata...")
if len(self.ready_to_read) > 0:
#print(str(self.ready_to_read)+"R ", flush=True)
try:
recv = self.conn.recv(1)
except:
recv = b''
if recv == b'':
try:
self.shut()
except:
print("Disconnected from other end")
self.conn=None
return None
else:
return recv
else:
return None
else:
return None
def sxdata(self,data):
if self.conn is None:
self.accept()
if self.conn is not None:
try:
self.ready_to_read, self.ready_to_send, self.in_error = \
select.select([self.conn,], [self.conn,], [], .1)
except select.error:
self.shut()
print("conn: select error in sxdata...")
if len(self.in_error) > 0:
print("conn: socket error in sxdata...")
if len(self.ready_to_send) > 0 and data is not None:
try:
self.conn.send(data)
except:
self.shut()
return None
else:
return None
def shut(self):
try:
self.conn.shutdown(2)
self.conn.close()
self.conn=None
except:
print("Could not shut down socket, already closed?")
def _gdp_can(cc):
ICOM.digiprog.set('')
def _gdp_go(cc):
ICOM.digiprog.set(cc.get())
def get_digi_prog():
digiprogs=list()
digiprog=tkinter.StringVar()
for z in ('wsjtx','jtdx','fldigi','flrig','js8call'):
x=shutil.which(z)
if x is not None:
digiprogs.append(x)
if len(digiprogs) > 0:
digi_win = tkinter.Toplevel(root)
#cc = tkinter.ttk.Combobox(digi_win, values=digiprogs, height=1)
cc = tkinter.Listbox(digi_win, height=len(digiprogs), width=50)
cc['selectmode']=tkinter.SINGLE
for x in digiprogs:
cc.insert(tkinter.END,x)
cc.grid(row=1,column=1,columnspan=2)
b_b=tkinter.Button(digi_win,text="Go")
b_b.grid(row=2,column=1)
c_b=tkinter.Button(digi_win,text="Cancel")
c_b.grid(row=2,column=2)
digi_win.bind('<Escape>',lambda x=0: digiprog.set("0"))
c_b.bind('<ButtonRelease-1>',lambda x=0: digiprog.set("0"))
b_b.bind('<ButtonRelease-1>',lambda x=1: digiprog.set("1"))
digi_win.grab_set()
digi_win.wait_variable(digiprog)
#print("digiprog is "+str(digiprog.get()))
if digiprog.get() == "1":
print(cc.curselection())
if len(cc.curselection()) == 0:
digi_win.destroy()
return None
tmp=digiprogs[cc.curselection()[0]]
digi_win.destroy()
if tmp == "":
return None
else:
return tmp
elif digiprog.get() == "0":
digi_win.destroy()
return None
else:
print("HUH?")
return None
else:
tkinter.messagebox.showerror(
title="D'oh!",
message="I can not find any programs.")
return None
def erase_status_line():
ICOM.status_line.set("")
def setting_get(command):
CO.send_direct(ICOM.send_preamble_bin + ICOM.binary_send_item[command] + ICOM.suffix_bin)
retval = CO.no_buf_direct_receive()
print("command was "+command)
return((command,retval))
def setting_get_and_set(command,val):
CO.send_direct(ICOM.send_preamble_bin + ICOM.binary_send_item[command] + ICOM.suffix_bin)
retval = CO.no_buf_direct_receive()
CO.send_direct(ICOM.send_preamble_bin + ICOM.binary_send_item[command] + val + ICOM.suffix_bin)
garbage = CO.no_buf_direct_receive()
CO.send_direct(ICOM.send_preamble_bin + ICOM.binary_send_item[command] + ICOM.suffix_bin)
newval = CO.no_buf_direct_receive()
#print(" ")
print("command was "+command)
if retval is not None:
print("retval was "+retval.hex())
#print("garbage was "+garbage.hex())
if newval is not None:
print("newval was "+newval.hex())
return((command,retval))
def stuff_startup_cmds():
CO.send_direct(ICOM.send_preamble_bin + b'\x27\x11\x00' + ICOM.suffix_bin)
rx_initial_bytes=CO.no_buf_direct_receive()
#print ("RX initial bytes:")
#print(rx_initial_bytes)
if (rx_initial_bytes is None):
xcmd = ICOM.powerpfx_bin + \
ICOM.send_preamble_bin + \
ICOM.widget_object['set_power_on'].command + \
ICOM.suffix_bin
CO.send_direct(xcmd)
time.sleep(4)
# FIRST we stuff mandatory commands into the queue to put it into VFO mode,
# select "A", turn off Echo, and turn off Transceive
# turn off scope sending
CO.send_direct(ICOM.send_preamble_bin + b'\x27\x11\x00' + ICOM.suffix_bin)
# switch to vfo mode
CO.send_direct(ICOM.send_preamble_bin + b'\x07' + ICOM.suffix_bin)
# switch to vfo A
## CO.send_direct(ICOM.send_preamble_bin + b'\x07\x00' + ICOM.suffix_bin)
# turn off echo back
CO.send_direct(ICOM.send_preamble_bin + b'\x1a\x05\x00\x75\x00' + ICOM.suffix_bin)
# turn off ci-v transceive
CO.send_direct(ICOM.send_preamble_bin + b'\x1a\x05\x00\x71\x00' + ICOM.suffix_bin)
def start_scope_send():
if ICOM.scopewin.winfo_ismapped():
CO.send_direct(ICOM.send_preamble_bin + b'\x27\x10\x01' + ICOM.suffix_bin) # be sure scope in radio is on
CO.send_direct(ICOM.send_preamble_bin + b'\x27\x11\x01' + ICOM.suffix_bin) # tell radio to stream scope to window
def stop_scope_send():
if ICOM.scopewin.winfo_ismapped():
CO.send_direct(ICOM.send_preamble_bin + b'\x27\x11\x00' + ICOM.suffix_bin) # tell radio to stream scope to window
# repeat to make sure
CO.send_direct(ICOM.send_preamble_bin + b'\x27\x11\x00' + ICOM.suffix_bin) # tell radio to stream scope to window
### ask yes no
def _askyesno(title= "", message= "" , *args):
CO.pauseq.put('pause', True)
stop_scope_send()
qq=_replfunc_askyesno(title=title, message=message, *args)
dummy=CO.pauseq.get()
start_scope_send()
return qq
_replfunc_askyesno = tkinter.messagebox.askyesno
tkinter.messagebox.askyesno = _askyesno
## showerror
def _showerror(title= "", message= "" , *args):
CO.pauseq.put('pause', True)
stop_scope_send()
qq=_replfunc_showerror(title=title, message=message, *args)
dummy=CO.pauseq.get()
start_scope_send()
return qq
_replfunc_showerror = tkinter.messagebox.showerror
tkinter.messagebox.showerror = _showerror
## showwarning
def _showwarning(title= "", message= "" , *args):
CO.pauseq.put('pause', True)
stop_scope_send()
qq=_replfunc_showwarning(title=title, message=message, *args)
dummy=CO.pauseq.get()
start_scope_send()
return qq
_replfunc_showwarning = tkinter.messagebox.showwarning
tkinter.messagebox.showwarning = _showwarning
def get_meter_255(meter_name,mtr):
if meter_name == 'swr_meter':
xxtbl = ICOM.swrtbl
if meter_name == 'po_meter':
xxtbl = ICOM.pwrtbl
for i in range(0,len(xxtbl)):
try:
if (mtr >= xxtbl[i][0] and mtr < xxtbl[i+1][0]):
break
except:
i = i - 1
break
mtr = int(math.ceil( xxtbl[i][1] + (xxtbl[i+1][1] - xxtbl[i][1])*(mtr - xxtbl[i][0]) / (xxtbl[i+1][0] - xxtbl[i][0])))
if mtr > 100:
mtr = 100
if mtr < 0:
mtr = 0
return mtr
def hide_scope(*args):
CO.send_direct(ICOM.send_preamble_bin + b'\x27\x11\x00' + ICOM.suffix_bin) # tell radio to stop streaming scope
CO.send_direct(ICOM.send_preamble_bin + b'\x27\x11\x00' + ICOM.suffix_bin) # tell radio to stop streaming scope
ICOM.scopewin.update()
ICOM.scopewin.withdraw()
def show_scope(*args):
ICOM.scopewin.deiconify()
ICOM.scopewin.update()
CO.send_direct(ICOM.send_preamble_bin + b'\x27\x10\x01' + ICOM.suffix_bin) # be sure scope in radio is on
CO.send_direct(ICOM.send_preamble_bin + b'\x27\x11\x01' + ICOM.suffix_bin) # tell radio to stream scope to window
def timesync(*args):
""" sets var to true upon pressing something """
# pylint: disable=W0613
if time.timezone == 0.0:
tfunc = time.localtime
else:
t_z = tkinter.messagebox.askyesno(
title="Time Zone!",
message="Answer YES to set radio to computer clock, " \
+"or NO to set to UTC based on computer clock. " \
+"It is assumed your PC clock is local.")
if t_z:
tfunc = time.localtime
else:
tfunc = time.gmtime
t_l = tfunc()
while t_l.tm_sec > 0:
t_l = tfunc()
ICOM.widget_object['timesync'].config(text=str(t_l.tm_sec))
if CO.quitq.empty():
# keep this receivecycle
receivecycle()
else:
return
ICOM.widget_object['timesync'].config(text='Time Sync')
datestr = ('0000'+str(t_l.tm_year))[-4:] \
+('00'+str(t_l.tm_mon))[-2:] \
+('00'+str(t_l.tm_mday))[-2:]
timestr = ('00'+str(t_l.tm_hour))[-2:]+('00'+str(t_l.tm_min))[-2:]
g_o = t_l.tm_gmtoff
gmtdigs = ('0000'+str(abs(int(g_o/3600*100))))[-4:]
if g_o < 0:
gmtdigs += '01'
else:
gmtdigs += '00'
datestr_b = CO.send_preamble_bin+bytes.fromhex('1a050094'+datestr)+CO.suffix_bin
timestr_b = CO.send_preamble_bin+bytes.fromhex('1a050095'+timestr)+CO.suffix_bin
gmtdigs_b = CO.send_preamble_bin+bytes.fromhex('1a050096'+gmtdigs)+CO.suffix_bin
CO.send_direct(datestr_b)
CO.send_direct(timestr_b)
CO.send_direct(gmtdigs_b)
#def pressed(*args):
# """ sets var to true upon pressing something """
# # pylint: disable=W0613
# ICOM.gui_touched = time.time()
# ICOM.button_pressed = True
#def pressed_time(event,tt,*args):
# """ sets var to true upon pressing something with a time limit """
# # pylint: disable=W0613
# ICOM.gui_touched = time.time()
# ICOM.button_pressed = True
# root.after(tt, released)
#def released(*args):
# """ sets var to false upon releasing """
# # pylint: disable=W0613
# ICOM.gui_touched = time.time()
# ICOM.button_pressed = False
def _process_logger(cmd_dict, received_data):
ICOM.status_line.set(cmd_dict['name'])
root.update()
root.after(500,erase_status_line)
def _process_keyer_send(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
slot = returnval[0:1]
aslot = str(slot)
# THIS fromhex is OK to keep
asciimsg = returnval[1:].decode()
ICOM.cw_keyer[slot] = asciimsg
if slot not in ICOM.cw_keyer_edit:
ICOM.cw_keyer_edit[slot] = tkinter.StringVar()
ICOM.cw_keyer_edit[slot].set(asciimsg.rstrip())
ICOM.widget_object[cmd_dict['name']+aslot].configure(text=asciimsg[0:5])
if slot not in ICOM.cw_keyer_tip:
ICOM.cw_keyer_tip[slot]=CreateToolTip(ICOM.widget_object[cmd_dict['name']+aslot], asciimsg)
else:
if ICOM.cw_keyer_tip[slot].text is not None:
ICOM.cw_keyer_tip[slot].text=asciimsg
def _process_scale0255_progressbar(cmd_dict, received_data):
""" process specific thing """
widg = ICOM.widget_object[cmd_dict['name']]
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
vals = list(widg.values)
if cmd_dict['name'] in ('swr_meter','po_meter'):
w_val = get_meter_255(cmd_dict['name'], int(returnval.hex()))
else:
w_val = int((((int(returnval.hex()) + widg.bias) \
/ (254 - widg.bias)) * (vals[-1] - vals[0])) + vals[0])
#if widg.type == 'Progressbar':
ICOM.widget_variable[cmd_dict['name']].set(w_val)
ICOM.last_polled_value[cmd_dict['name']].set(w_val)
ICOM.widget_object[cmd_dict['name']].update()
def _process_scaleff(cmd_dict, received_data):
""" process specific thing """
widg = ICOM.widget_object[cmd_dict['name']]
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
w_val = int(returnval.hex())+widg.bias
ICOM.widget_variable[cmd_dict['name']].set(w_val)
ICOM.last_polled_value[cmd_dict['name']].set(w_val)
ICOM.widget_object[cmd_dict['name']].update()
def _process_mdfset(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
if returnval.hex() == "fffd":
return
#print("MDFSET: "+returnval.hex())
# pylint: disable=W0632
[mode, data, fil] = textwrap.wrap(returnval.hex(), 2)
#if not ICOM.button_pressed:
ICOM.widget_variable[cmd_dict['name']+'m'].set(mode)
ICOM.widget_variable[cmd_dict['name']+'d'].set(data)
ICOM.widget_variable[cmd_dict['name']+'f'].set(fil)
ICOM.last_polled_value[cmd_dict['name']+'m'].set(mode)
ICOM.last_polled_value[cmd_dict['name']+'d'].set(data)
ICOM.last_polled_value[cmd_dict['name']+'f'].set(fil)
for m in ICOM.modes:
ICOM.widget_object[cmd_dict['name']+'m'+ICOM.modes[m]].update()
ICOM.widget_object[cmd_dict['name']+'d'].update()
for f in '123':
ICOM.widget_object[cmd_dict['name']+'f'+f].update()
def _process_scope_edge(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
ICOM.widget_object['scope_edge'].set(returnval.hex()[-2:])
#print("scope edge returnval is "+str(returnval))
ICOM.widget_object['scope_edge'].update()
def _process_scope_width(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
print("scope width returnval is "+str(returnval))
def _process_scope_c_or_f(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
ICOM.widget_object['scope_c_or_f'].set(ICOM.scopetypes[int.from_bytes(ICOM.scope_c_or_f,'big')]);
def _process_vfoset(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
if root.IN_ENTRY or returnval.hex() == "fffd":
return
w_v = "{:010,}".format(int(returnval[::-1].hex())).replace(',', '.')
ICOM.last_polled_value[cmd_dict['name']].set(w_v)
if time.time() - ICOM.vfo_touched > 10:
ICOM.widget_variable[cmd_dict['name']].set(w_v)
ICOM.widget_object[cmd_dict['name']].update()
def _process_ovf(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
ICOM.widget_object['ovfb'].config(fg={'00':'black','01':'red'}[returnval.hex()])
ICOM.widget_object['ovfb'].update()
def _process_radio_date(cmd_dict, received_data):
""" process specific thing """
rvh = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])].hex()
ICOM.radio_date.set( rvh[0:4]+'/'+rvh[4:6]+'/'+rvh[6:8])
ICOM.widget_object['datedisp'].update()
def _process_radio_time(cmd_dict, received_data):
""" process specific thing """
rvh = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])].hex()
ICOM.radio_time.set(
rvh[0:2]+':'+ rvh[2:4]+'/'+ ICOM.radio_tz.get())
ICOM.widget_object['timedisp'].update()
def _process_radio_tz(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
tzs={'00':'+','01':'-','00':'+'}[returnval.hex()[4:6]]
ICOM.radio_tz.set(tzs+returnval.hex()[0:4])
ICOM.widget_object['timedisp'].update()
def _process_my_call(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
mycall = returnval.decode().strip()
root.title('PyC-7300: '+mycall)
ICOM.my_call_sign.set(mycall)
ICOM.widget_object['callbrag'].update()
def _process_contest_num(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
cnum = int(returnval[0:2].hex())
fmt={True:"{:04d}",False:"{:03d}"}[cnum>999].format(cnum)
ICOM.widget_variable[cmd_dict['name']].set(fmt)
ICOM.last_polled_value[cmd_dict['name']].set(fmt)
ICOM.widget_object[cmd_dict['name']].update()
def _process_rit_freq(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
w_v = float(int(returnval[1:2].hex()+returnval[0:1].hex())/1000)
if returnval[2:3] == b'\x01':
w_v = w_v*-1
w_v = "{:+0.3f}".format(w_v)
ICOM.widget_variable[cmd_dict['name']].set(w_v)
ICOM.last_polled_value[cmd_dict['name']].set(w_v)
ICOM.widget_object[cmd_dict['name']].update()
def _process_mem_ch(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
populate_memch(ICOM.widget_object['set_mem_modebox'], returnval)
def _process_contestnums(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
if returnval != '':
ICOM.widget_object[cmd_dict['name']].current(int(returnval.hex()))
ICOM.widget_object[cmd_dict['name']].update()
def _process_cur_rx_bw(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
mode = ICOM.widget_variable['this_vfo_mdfm'].get()
if mode != '':
ICOM.widget_object[cmd_dict['name']]['values'] = ICOM.bandwidths[mode]
ICOM.widget_object[cmd_dict['name']].current(int(returnval.hex()))
ICOM.widget_object[cmd_dict['name']].update()
def _process_agc_time(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
mode = ICOM.widget_variable['this_vfo_mdfm'].get()
if mode != '':
ICOM.widget_object[cmd_dict['name']]['values'] = ICOM.agc[mode]
ICOM.widget_object[cmd_dict['name']].current(int(returnval.hex()))
ICOM.widget_object[cmd_dict['name']].update()
def scopewheelms(evt):
if evt.delta < 0:
vinc = 236.1
if evt.delta > 0:
vinc = 239
q=evt
q.x=vinc
scopeclick(q)
def scopewheel(evt,a):
""" do stuff when scrolling on the scope """
#print(evt)
#print(a)
q=evt
q.x=a
scopeclick(q)
def clear_peaks():
for xaxis in range(0,475):
#ICOM.scope_canvas.coords( ICOM.scope_peak_line[xaxis], (xaxis, 160, xaxis, 0))
for y in range(0,20):
try:
ICOM.peaks[xaxis].pop()
except:
pass
def scopeclickround(evt):
""" do stuff when clicking on the scope """
newhz = ICOM.scope_bottom + (ICOM.scope_hzper * evt.x)
mode = ICOM.widget_variable['this_vfo_mdfm'].get()
if mode == '03': # cw # round to 500 hz if cw
roundhz = int(round(newhz*2,-3))/2
else: # round to 1000 hz if not cw
roundhz = int(round(newhz,-3))
qsy = "{:010d}".format(int(roundhz))
bqsy = ICOM.send_preamble_bin + \
ICOM.widget_object['this_vfo_freq'].command + \
bytes.fromhex(qsy)[::-1] + \
ICOM.suffix_bin
ICOM.vfo_touched = -99999
CO.send_direct(bqsy)
clear_peaks()
pollvfo()
def scopeclick(evt):
""" do stuff when clicking on the scope """
newhz = ICOM.scope_bottom + (ICOM.scope_hzper * evt.x)
qsy = "{:010d}".format(int(newhz))
bqsy = ICOM.send_preamble_bin + \
ICOM.widget_object['this_vfo_freq'].command + \
bytes.fromhex(qsy)[::-1] + \
ICOM.suffix_bin
ICOM.vfo_touched = -99999
CO.send_direct(bqsy)
clear_peaks()
pollvfo()
def _process_color(cmd_dict, received_data):
rvh = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])].hex()
name = cmd_dict['name']
ICOM.scope_color[name] = '#'+hex((int(rvh[0:4])*256*256)+(int(rvh[4:8])*256)+int(rvh[8:12])).replace('0x','').zfill(6)
linearr={'scope_line_color':ICOM.scope_spectrum_line,'scope_fill_color':ICOM.scope_fill_line,'scope_peak_color':ICOM.scope_peak_line}[name]
for xaxis in range(0,475):
ICOM.scope_canvas.itemconfig( linearr[xaxis], fill=ICOM.scope_color[name])
def _process_scope(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
div=returnval[1:2]
if div == b'\x01':
if returnval[14:15] != b'\x00': # scope oob
ICOM.scope_canvas.coords(ICOM.scope_oob_msg,(233,100))
return
else:
ICOM.scope_canvas.coords(ICOM.scope_oob_msg,(0,-20))
ICOM.scope_c_or_f = returnval[3:4]
ICOM.scope_one_freq = int(reverse_hex_to_bcd(returnval[4:9].hex()))
ICOM.scope_two_freq = int(reverse_hex_to_bcd(returnval[9:14].hex()))
# move all down
ICOM.waterfall_canvas.move(tkinter.ALL,0,1)
# get the tag for the top
ICOM.wafa_top_tag = ICOM.waterfall_canvas.gettags(ICOM.waterfall_canvas.find_overlapping(0,ICOM.wafa_bot,0,ICOM.wafa_bot))
# move all the ones on the bottom line up
ICOM.waterfall_canvas.move(ICOM.wafa_top_tag,0,(ICOM.wafa_bot )*-1)
# THIS WORKS BUT TRYING MOVE TAG
#for xx in ICOM.wafa_pix[ICOM.wafa_top_tag]:
# ICOM.waterfall_canvas.move(ICOM.wafa_pix[ICOM.wafa_top_tag][xx],0,-101)
ICOM.scope_bot_lbl.set("Bot: "+"{:10,}".format(ICOM.scope_bottom).replace(',','.'))
ICOM.widget_object['scope_width'].set(ICOM.scope_two_freq)
if ICOM.scope_c_or_f == b'\x00':
ICOM.scope_bottom = ICOM.scope_one_freq - ICOM.scope_two_freq
ICOM.scope_hzper = ( ICOM.scope_two_freq * 2 / 475 )
ICOM.widget_object['scope_width'].grid()
ICOM.widget_object['scope_edge'].grid_remove()
ICOM.scope_top_lbl.set("Top: "+"{:10,}".format(ICOM.scope_one_freq + ICOM.scope_two_freq).replace(',','.'))
ICOM.widget_object['scope_c_or_f'].config(text='')
else:
ICOM.scope_bottom = ICOM.scope_one_freq
ICOM.scope_hzper = ((ICOM.scope_two_freq - ICOM.scope_bottom) / 475)
ICOM.widget_object['scope_width'].grid_remove()
ICOM.widget_object['scope_edge'].grid()
ICOM.scope_top_lbl.set("Top: "+"{:10,}".format(ICOM.scope_two_freq).replace(',','.'))
ICOM.widget_object['scope_c_or_f'].config(text='')
sm=ICOM.widget_object['scope_mult'].get()
#if sm == "":
# ICOM.widget_object['scope_mult'].set("x1")
#ICOM.widget_object['scope_c_or_f'].set(ICOM.scopetypes[int.from_bytes(ICOM.scope_c_or_f,'big')]);
ICOM.scope_mult = {"":1, "x1":1, "x2":2, "x4":4, "x8":8}[sm]
this=ICOM.widget_variable['this_vfo_freq'].get().replace('.','')
that=ICOM.widget_variable['that_vfo_freq'].get().replace('.','')
if not (this == '' or that == ''):
split=ICOM.widget_variable['split_on_off'].get()
rx_x = int((int(this) - int(ICOM.scope_bottom)) / ICOM.scope_hzper)
if split == str(b'\x01'):
tx_x = int((int(that) - int(ICOM.scope_bottom)) / ICOM.scope_hzper)
else:
tx_x = rx_x
# have to test separately here, sorry
ICOM.scope_canvas.coords( ICOM.scope_receive_freq, (rx_x, {True:80,False:0}[rx_x==tx_x], rx_x, 160))
ICOM.scope_canvas.coords( ICOM.scope_transmit_freq, (tx_x, 0, tx_x, 160))
ICOM.scopewin.update()
if div != b'\x01':
# we don't "get" all the way to x11 when scope is outta band so we don't worry about it!
# this is the "starting position"
xaxis=(int(div.hex()) - 2)*50
#ftn = ICOM.waterfall_canvas.gettags(ICOM.waterfall_canvas.find_closest(0,0,0))[0].replace('t','')
for py in returnval[3:-1]:
#print("py is "+str(py))
amplitude = 160 - min(py * ICOM.scope_mult,159)
#amplitude=160-yaxis
ICOM.peaks[xaxis].append(amplitude)
# set peak lengths
if len(ICOM.peaks[xaxis]) > 10:
ICOM.peaks[xaxis].pop(0)
mp=min(ICOM.peaks[xaxis])
if ICOM.prevpeak[xaxis] != mp:
ICOM.scope_canvas.coords(ICOM.scope_peak_line[xaxis],(xaxis,160,xaxis,mp))
ICOM.prevpeak[xaxis]=mp
# set position of main line
if xaxis > 0:
if ICOM.prevline[xaxis] != (ICOM.prevyaxis[xaxis-1],amplitude):
ICOM.scope_canvas.coords(ICOM.scope_spectrum_line[xaxis], (xaxis-1, ICOM.prevyaxis[xaxis-1], xaxis, amplitude))
ICOM.prevline[xaxis]=(ICOM.prevyaxis[xaxis-1],amplitude)
# set length of fill line
if ICOM.prevyaxis[xaxis] != amplitude:
ICOM.scope_canvas.coords(ICOM.scope_fill_line[xaxis], (xaxis, 160, xaxis, amplitude))
ICOM.prevyaxis[xaxis]=amplitude
# set the color for that one pixel on the waterfall
#ICOM.waterfall_canvas.itemconfigure(ICOM.wafa_pix[ftn][xaxis],fill=ICOM.yaxcolor[amplitude])
ICOM.waterfall_canvas.itemconfigure(ICOM.wafa_pix[ICOM.wafa_top_tag[0].replace('t','')][xaxis],
fill=ICOM.yaxcolor[amplitude])
xaxis+=1
if os.name == 'nt':
ICOM.scopewin.update()
def _process_other(cmd_dict, received_data):
""" process specific thing """
returnval = received_data[ICOM.irpl+len(cmd_dict['command']) \
:ICOM.irpl +len(cmd_dict['command'])+(cmd_dict['num_of_bytes_returned'])]
if cmd_dict['name'] not in ICOM.widget_variable.keys():
print("No " + cmd_dict['name'] + " for widget_variable")
print("received data is "+received_data.hex())
pass
else:
ICOM.widget_variable[cmd_dict['name']].set(returnval)
ICOM.last_polled_value[cmd_dict['name']].set(returnval)
def _process_nothing(cmd_dict, received_data):
""" process specific thing """
# pylint: disable=W0613
print("Processing Nothing for "+cmd_dict['name'])
return None
class images():
""" images for the program in base64 """
def __init__(self):
self.swr_base64="""
iVBORw0KGgoAAAANSUhEUgAAAPsAAAATCAYAAABWZXtJAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9
kT1Iw0AcxV9bRZEWByOIOGSoThZERR21CkWoEGqFVh1MLv2CJg1Jiouj4Fpw8GOx6uDirKuDqyAI
foA4OTopukiJ/0sKLWI8OO7Hu3uPu3dAsF5mmtUxBmi6baYScTGTXRW7XhGCgAim0S8zy5iTpCR8
x9c9Any9i/Es/3N/joiasxgQEIlnmWHaxBvEU5u2wXmfWGBFWSU+Jx416YLEj1xXPH7jXHA5yDMF
M52aJxaIxUIbK23MiqZGPEkcVTWd8oMZj1XOW5y1cpU178lfGM7pK8tcpzmEBBaxBAkiFFRRQhk2
YrTqpFhI0X7cxz/o+iVyKeQqgZFjARVokF0/+B/87tbKT4x7SeE40PniOB/DQNcu0Kg5zvex4zRO
gNAzcKW3/JU6MPNJeq2lRY+A3m3g4rqlKXvA5Q4w8GTIpuxKIZrBfB54P6NvygJ9t0DPmtdbcx+n
D0CaukreAAeHwEiBstd93t3d3tu/Z5r9/QCCAXKtRPfxFgAAAAZiS0dEAP8A/wD/oL2nkwAAAAlw
SFlzAAAOxAAADsQBlSsOGwAAAAd0SU1FB+QDFA4ZG8IhBNIAAAAZdEVYdENvbW1lbnQAQ3JlYXRl
ZCB3aXRoIEdJTVBXgQ4XAAABWElEQVR42u2a0W3EIAyGfVEX6ggdofP04TgpnacjdISORF+KlCKc
0kjYFnyfdBLHy28wfzAkt7SnLCJyf7vL88uriIh8fX7Qpk17svYmALAEmB0AswMAZgcAzA4AmB0A
HLkdX7158Xh/iGcM6Pvqg7HZAWBys+ecMTvAAjzV5ZxVKadplZLyy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OwqCOl5+EIPUKXwJqD
DCtHxnWcOCJ+Q/w+qZLjVp1Xx/PntBMRMYSQw2P9YDgP0+Tp7fTrQ8N5uJnbm5yeGjZr2kbZRa1z
jq/7p2n88P2xOF9bm0ZNq9dKRMSNTkLCaze6m/f3Jqenpl0UqN+L/v2fd4/J67n52tpCu1o0rV1D
EZE+FS18hEdkdC0ZBgVqzdFZHJkdc5pSGV2Dri2arHeuVDmH3HSo8lJbWUtIacuz2LOHG1tDdkHo
QZ9V1LYXB3nEJk31nIhsOqcJndVzaxX36Us6LeNj28RBtQZ+U85tUISD5TTFDldT29JaldDXvMlb
SukW7KKqKW33XUt/HDubf2k5V9hK55+z89Eb3i6iddJ0RpE6HAszW0l/WiMQoTWVPqbs+KcaQtqg
Xxv9ESUf7R7b7trslcr41FSuy+59k/33o9oA2iWkILMTQv4/nRsde3YyVQUay1PyR87OAzpC2sCG
vd7zy6sxxpjr5Z1jjjk+2Jg9OyGNQGcnhM5OCDkSP4I0uagCuGCcAAAAAElFTkSuQmCC
"""
class CreateToolTip():
"""
create a tooltip for a given widget
"""
def __init__(self, widget, text='widget info'):
self.waittime = 1000 #miliseconds
self.wraplength = 180 #pixels
self.widget = widget
self.text = text
self.widget.bind("<Enter>", self.enter)
self.widget.bind("<Leave>", self.leave)
self.widget.bind("<ButtonPress>", self.leave)
self.af_id = None
self.top_widg = None
self.popup_list = []
def __del__(self):
print("Pop up deleted")
def enter(self, event=None):
""" executed when mouse enters widget """
# pylint: disable=W0613
self.schedule()
def leave(self, event=None):
""" executed when mouse leaves widget """
# pylint: disable=W0613
self.unschedule()
self.hidetip()
def schedule(self):
""" called by routine that is triggered when mouse enters widget"""
self.unschedule()
self.af_id = self.widget.after(self.waittime, self.showtip)
def unschedule(self):
""" cancels the "after" task """
af_id = self.af_id
self.af_id = None
if af_id:
self.widget.after_cancel(af_id)
def showtip(self, event=None):
""" shows the tool tip """
# pylint: disable=W0613
poi_x = self.widget.winfo_pointerx() + 10
poi_y = self.widget.winfo_pointery() + 10
# creates a toplevel window
self.top_widg = tkinter.Toplevel(self.widget)
self.popup_list.append(self.top_widg)
# Leaves only the label and removes the app window
self.top_widg.wm_overrideredirect(True)
self.top_widg.wm_geometry("+%d+%d" % (poi_x, poi_y))
label = tkinter.Label(self.top_widg, text=self.text, justify='left', \
background="#ffffff", relief='solid', borderwidth=1, \
wraplength=self.wraplength)
label.pack(ipadx=1)
def hidetip(self):
""" hides the tooltip and destroys the window when done with it """
while len(self.popup_list) > 0:
tw = self.popup_list.pop()
if tw:
tw.destroy()
self.top_widge=None
#top_widg = self.top_widg
#self.top_widg = None