-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCIV.py
More file actions
429 lines (398 loc) · 18.8 KB
/
CIV.py
File metadata and controls
429 lines (398 loc) · 18.8 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
# file: CIV.py
# For use with CIV_Serial.py
# K7MDL March 2025
from enum import Enum, auto
# Freq_table:
# These band edge frequency values are based on the radio message VFO
# values which have no offset applied
# We use this value then once we know the band we can add the
# fixed offset and then display the actual dial frequency
# The 10G band values in this table are just dummy values until
# the 10G transverter is hooked up to observe the actual values
# The band and ptt values are the mapping to the group of
# 6 pins for band and 6 pins for ptt
# Set the pin value(s) = 1 that you want activated when the band is active
# There is an inversion flag to corert for buffer inversions
# At startup all pins will be set to 0 then initialized once the band
# is first determined.
# For BCD output to the Remote BCD Decoder board, edit the band
# values = 0 through 5 so only using 3 io pins
# and ptt values will all be set to 1 using only 1 io pin
# Example values for BCD decoder
# 2M decimal 0 or in binary format 0b0000000
# 70cm decimal 1 or in binary format 0b0000001
# 23cm decimal 2 or in binary format 0b0000010
# 13cm decimal 3 or in binary format 0b0000011
# 6cm decimal 4 or in binary format 0b0000100
# 3cm decimal 5 or in binary format 0b0000101
# Set all bands ptt to decimal 1 or in binary format 0b0000001
Freq_table_905 = {
'0': {
'bandname':'2M',
'lower_edge':144000000,
'upper_edge':148000000,
'offset':0,
'band':0b00000000,
'ptt':0b00000001,
},
'1': {
'bandname':'70cm',
'lower_edge':430000000,
'upper_edge':450000000,
'offset':0,
'band':0b00000001,
'ptt':0b00000001,
},
'2': {
'bandname':'23cm',
'lower_edge':1240000000,
'upper_edge':1300000000,
'offset':0,
'band':0b00000010,
'ptt':0b00000001,
},
'3': {
'bandname':'13cm',
'lower_edge':2300000000,
'upper_edge':2550000000,
'offset':0,
'band':0b00000011,
'ptt':0b00000001,
},
'4': {
'bandname':'6cm',
'lower_edge':5600000000,
'upper_edge':5800000000,
'offset':0,
'band':0b00000100,
'ptt':0b00000001,
},
'5': {
'bandname':'3cm',
'lower_edge':10000000000, # 10000,000.000 = 1,389,000,000
'upper_edge':10500000000,
'offset':0, #10.0G - 1.389G = 8,611,000,000
'band':0b00000101,
'ptt':0b00000001,
}
}
Freq_table_705 = {
'0': {
'bandname':'LF',
'lower_edge':1,
'upper_edge':1800000,
'offset':0,
'band':0b00000000,
'ptt':0b00000001,
},
'1': {
'bandname':'HF',
'lower_edge':1800000,
'upper_edge':50000000,
'offset':0,
'band':0b00000001,
'ptt':0b00000001,
},
'2': {
'bandname':'6M',
'lower_edge':50000000,
'upper_edge':54000000,
'offset':0,
'band':0b00000010,
'ptt':0b00000001,
},
'3': {
'bandname':'FMAIR',
'lower_edge':54000000,
'upper_edge':144000000,
'offset':0,
'band':0b00000011,
'ptt':0b00000001,
},
'4': {
'bandname':'2M',
'lower_edge':144000000,
'upper_edge':200000000,
'offset':0,
'band':0b00000100,
'ptt':0b00000001,
},
'5': {
'bandname':'70cm',
'lower_edge':400000000,
'upper_edge':470000000,
'offset':0,
'band':0b00000101,
'ptt':0b00000001,
}
}
# IO-Table:
# These are the GPIO pin assignments of BAND and PTT outputs.
# 1 or more pins may be assigned to any band so they are not band specific.
# The band and ptt keys in the Freq_table map the bank of pins to a band
# We use up to 6 pins for band output and up to 6 for PTT
# BCD mode will use fewer pins and the extras will be ignored
# set the inversion this to match your hardware. Buffering usually inverts the logic
# The 3 relay HAT I have uses pin CH1=26 CH2=20 CH3=21 (25, , 28, 29 using Wiring Pi numbers on the board
# This is set up for 3-wire BCD Band and 1-wire PTT for the Remote BCD DEcdoer board
IO_table = {
0x01 : {
'band_pin':5, #4,
'band_invert':False,
'ptt_pin':0, #16, for 4 relay hat, #17, for 3 relay hat, 0 for antenna only and no PTT
'ptt_invert':False,
},
0x02 : {
'band_pin':6, #3,
'band_invert':False,
'ptt_pin':0,
'ptt_invert':True,
},
0x04 : {
'band_pin':13, #2,
'band_invert':False,
'ptt_pin':0,
'ptt_invert':True,
},
0x08 : {
'band_pin':0,
'band_invert':True,
'ptt_pin':0,
'ptt_invert':True,
},
0x10: {
'band_pin':0,
'band_invert':True,
'ptt_pin':0,
'ptt_invert':True,
},
0x20 : {
'band_pin':0,
'band_invert':True,
'ptt_pin':0,
'ptt_invert':True,
}
}
# __________________________________________________________________
#
# GPIO outputs for Band and PTT
# __________________________________________________________________
#
class cmds(Enum):
CIV_C_F_SEND = 0
CIV_C_F1_SEND = auto()
CIV_C_F_READ = auto()
CIV_C_F25A = auto()
CIV_C_F25B = auto()
CIV_C_F26 = auto()
CIV_C_F26A = auto()
CIV_C_F26B = auto()
CIV_C_F25A_SEND = auto()
CIV_C_F25B_SEND = auto()
CIV_C_MOD_READ = auto()
CIV_C_MOD_SET = auto()
CIV_C_MOD_SEND = auto()
CIV_C_MOD1_SEND = auto()
CIV_C_MOD_USB_F1_SEND = auto()
CIV_C_MOD_USB_SEND = auto()
CIV_C_USB_D0_F2_SEND = auto()
CIV_C_USB_D1_F2_SEND = auto()
CIV_C_LSB_D0_F2_SEND = auto()
CIV_C_LSB_D1_F2_SEND = auto()
CIV_C_FM_D1_F1_SEND = auto()
CIV_C_ATTN_READ = auto()
CIV_C_ATTN_OFF = auto()
CIV_C_ATTN_ON = auto()
CIV_C_SPLIT_READ = auto()
CIV_C_SPLIT_OFF_SEND = auto()
CIV_C_SPLIT_ON_SEND = auto()
CIV_C_RFGAIN = auto()
CIV_C_AFGAIN = auto()
CIV_C_RFPOWER = auto()
CIV_C_S_MTR_LVL = auto()
CIV_C_PREAMP_READ = auto()
CIV_C_PREAMP_OFF = auto()
CIV_C_PREAMP_ON = auto()
CIV_C_PREAMP_ON2 = auto()
CIV_C_AGC_READ = auto()
CIV_C_AGC_FAST = auto()
CIV_C_AGC_MID = auto()
CIV_C_AGC_SLOW = auto()
CIV_C_CW_MSGS = auto()
CIV_C_BSTACK = auto()
CIV_C_MY_POSIT_READ = auto()
CIV_C_MY_POSIT_DATA = auto()
CIV_C_RF_POW = auto()
CIV_C_TRX_ON_OFF = auto()
CIV_C_TRX_ID = auto()
CIV_C_TX = auto()
CIV_C_TX_FREQ = auto()
CIV_C_DATE = auto()
CIV_C_TIME = auto()
CIV_C_UTC_READ_905 = auto()
CIV_C_UTC_READ_705 = auto()
CIV_C_UTC_READ_9700 = auto()
CIV_C_DUPLEX_READ = auto()
CIV_C_DUPLEX_SEND = auto()
CIV_C_RIT_XIT = auto()
CIV_C_RIT_ON_OFF = auto()
CIV_C_XIT_ON_OFF = auto()
CIV_C_RADIO_OFF = auto()
CIV_C_RADIO_ON = auto()
CIV_C_SCOPE_ON = auto()
CIV_C_SCOPE_OFF = auto()
CIV_C_SCOPE_ALL = auto()
CIV_R_NO_GOOD = auto()
CIV_R_GOOD = auto()
CIV_R_MAINSUBBAND = auto()
CIV_R_MAIN_BANDVFO = auto()
CIV_R_SUB_BANDVFO = auto()
End_of_Cmd_List = auto()
cmd_List = [
[cmds.CIV_C_F_SEND, 1,0x00], # send operating frequency to all
[cmds.CIV_C_F1_SEND, 1,0x05], # send operating frequency to one
[cmds.CIV_C_F_READ, 1,0x03], # read operating frequency
[cmds.CIV_C_F25A, 2,0x25,0x00], # read selected VFO (00) operating frequency
[cmds.CIV_C_F25B, 2,0x25,0x01], # read unselected VFO (01)
[cmds.CIV_C_F26, 1,0x26], # read selected VFO m data, filt - 26 datafield template; selected VFO; mode, data on/off(0-1), filter (1-3);
[cmds.CIV_C_F26A, 2,0x26,0x00], # read/set selected VFO m data, filt
[cmds.CIV_C_F26B, 2,0x26,0x01], # read/set un- selected VFO m data, filt
[cmds.CIV_C_F25A_SEND, 2,0x25,0x00], # set selected VFO frequency
[cmds.CIV_C_F25B_SEND, 2,0x25,0x01], # set un-selected VFO frequency
[cmds.CIV_C_MOD_READ, 1,0x04], # read Modulation Mode in use
[cmds.CIV_C_MOD_SET, 3,0x06,0x23,0x02], # set mode to ATV and FIL2, same 2 byte filed for cmds 1, 4, and 6
[cmds.CIV_C_MOD_SEND , 1,0x01], # send Modulation Mode to all
[cmds.CIV_C_MOD1_SEND, 1,0x06], # send Modulation Mode to one
[cmds.CIV_C_MOD_USB_F1_SEND, 3,0x06,0x01,0x01], # send USB Filter 1
[cmds.CIV_C_MOD_USB_SEND, 2,0x06,0x01], # send USB Filter 1
[cmds.CIV_C_USB_D0_F2_SEND, 5,0x26,0x00,0x01,0x00,0x02], # selected VFO; mod USB; Data OFF; RX_filter F2;
[cmds.CIV_C_USB_D1_F2_SEND, 5,0x26,0x00,0x01,0x01,0x02], # selected VFO; mod USB; Data ON; RX_filter F2;
[cmds.CIV_C_LSB_D0_F2_SEND, 5,0x26,0x00,0x00,0x00,0x02], # selected VFO; mod USB; Data OFF; RX_filter F2;
[cmds.CIV_C_LSB_D1_F2_SEND, 5,0x26,0x00,0x00,0x01,0x02], # selected VFO; mod USB; Data ON; RX_filter F2;
[cmds.CIV_C_FM_D1_F1_SEND, 5,0x26,0x00,0x05,0x01,0x01], # selected VFO; mod USB; Data ON; RX_filter F2;
[cmds.CIV_C_ATTN_READ, 1,0x11], # Attn read state
[cmds.CIV_C_ATTN_OFF, 2,0x11,0x00], # Attn OFF
[cmds.CIV_C_ATTN_ON, 2,0x11,0x10], # Attn 10dB (144, 432, 1200 bands only)
[cmds.CIV_C_SPLIT_READ, 1,0x0F], # read Split OFF
[cmds.CIV_C_SPLIT_OFF_SEND, 2,0x0F,0x00], # set split OFF
[cmds.CIV_C_SPLIT_ON_SEND, 2,0x0F,0x01], # Set split ON
[cmds.CIV_C_RFGAIN, 2,0x14,0x02], # send/read RF Gain
[cmds.CIV_C_AFGAIN, 2,0x14,0x01], # send/read AF Gain
[cmds.CIV_C_RFPOWER, 2,0x14,0x0A], # send/read selected bands RF power
[cmds.CIV_C_S_MTR_LVL, 2,0x15,0x02], # send/read S-meter level (00 00 to 02 55) 00 00 = S0, 01 20 = S9, 02 41 = S9+60dB
[cmds.CIV_C_PREAMP_READ, 2,0x16,0x02], # read preamp state
[cmds.CIV_C_PREAMP_OFF, 3,0x16,0x02,0x00], # send/read preamp 3rd byte is on or of for sending - 00 = OFF, 01 = ON
[cmds.CIV_C_PREAMP_ON, 3,0x16,0x02,0x00], # send/read preamp 3rd byte is on or of for sending - 00 = OFF, 01 = ON
[cmds.CIV_C_PREAMP_ON2, 3,0x16,0x02,0x02], # send/read preamp 3rd byte is on or of for sending - 00 = OFF, 01 = ON - not on 905
[cmds.CIV_C_AGC_READ, 2,0x16,0x12], # send/read AGC 01 = FAST, 02 = MID, 03 = SLOW
[cmds.CIV_C_AGC_FAST, 3,0x16,0x12,0x01], # send/read AGC 01 = FAST, 02 = MID, 03 = SLOW
[cmds.CIV_C_AGC_MID, 3,0x16,0x12,0x02], # send/read AGC 01 = FAST, 02 = MID, 03 = SLOW
[cmds.CIV_C_AGC_SLOW, 3,0x16,0x12,0x03], # send/read AGC 01 = FAST, 02 = MID, 03 = SLOW
[cmds.CIV_C_CW_MSGS, 1,0x17], # Send CW messages see page 17 of prog manual for char table
[cmds.CIV_C_BSTACK, 2,0x1A,0x01], # send/read BandStack contents - see page 19 of prog manual.
# data byte 1 0xyy = Freq band code
# dat abyte 2 0xzz = register code 01, 02 or 03
# to read 432 band stack register 1 use 0x1A,0x01,0x02,0x01
[cmds.CIV_C_MY_POSIT_READ, 2,0x23,0x00], # read my GPS Position
[cmds.CIV_C_MY_POSIT_DATA, 1,0x23], # read my GPS Position
[cmds.CIV_C_RF_POW, 2,0x14,0x0A], # send / read max RF power setting (0..255 == 0 .. 100%)
[cmds.CIV_C_TRX_ON_OFF, 1,0x18], # switch radio ON/OFF
[cmds.CIV_C_TRX_ID, 2,0x19,0x00], # ID query
[cmds.CIV_C_TX, 2,0x1C,0x00], # query of TX-State 00=OFF, 01=ON
[cmds.CIV_C_TX_FREQ, 2,0x1C,0x03], # query of current TX frequency
# the following three commands don't fit for IC7100 !!!
[cmds.CIV_C_DATE, 4,0x1A,0x05,0x00,0x94], # + 0x20 0x20 0x04 0x27 for 27.4.2020
[cmds.CIV_C_TIME, 4,0x1A,0x05,0x00,0x95], # + 0x19 0x57 for 19:57
#[cmds.CIV_C_UTC, 4,0x1A,0x05,0x00,0x96], # + 0x01,0x00,0x00 = +1h delta of UTC to MEZ
[cmds.CIV_C_UTC_READ_905, 4,0x1A,0x05,0x01,0x81], # Get UTC Offset
#[cmds.CIV_C_UTC_SEND, 4,0x1A,0x05,0x00,0x96], # + 0x01,0x00,0x00 = +1h delta of UTC to MEZ
[cmds.CIV_C_UTC_READ_705, 4,0x1A,0x05,0x01,0x70], # + 0x01,0x00,0x00 = +1h delta of UTC to MEZ
[cmds.CIV_C_UTC_READ_9700, 4,0x1A,0x05,0x01,0x84], # + 0x01,0x00,0x00 = +1h delta of UTC to MEZ
[cmds.CIV_C_DUPLEX_READ, 1,0x0C], # read Duplex Offset - has 3 bytes frequency offset data
[cmds.CIV_C_DUPLEX_SEND, 1,0x0D], # send Duplex Offset
[cmds.CIV_C_RIT_XIT, 2,0x21,0x00], # read or send RIT/XIT Offset - has 3 bytes frequency offset data XIT and RIT share this Offset value
[cmds.CIV_C_RIT_ON_OFF, 2,0x21,0x01], # send or send RIT ON or Off status 00 = , 01 = t
[cmds.CIV_C_XIT_ON_OFF, 2,0x21,0x02], # send or send XIT Offset
[cmds.CIV_C_RADIO_OFF, 2,0x18,0x00], # Turn Off the radio
[cmds.CIV_C_RADIO_ON, 2,0x18,0x01], # Turn on the radio
[cmds.CIV_C_SCOPE_ON, 3,0x27,0x11,0x01], # send/read Scope wave data output ON
[cmds.CIV_C_SCOPE_OFF, 3,0x27,0x11,0x00], # send/read Scope wave data output OFF
[cmds.CIV_C_SCOPE_ALL, 1,0x27], # send/read Scope catch all to avoid no match found error outputs
[cmds.CIV_R_NO_GOOD, 1,0xFA], # Message received from radio was no good
[cmds.CIV_R_GOOD, 1,0xFB], # Message received from radio was good
[cmds.CIV_R_MAINSUBBAND, 2,0x07,0xD2], # IC-9700 Main band Active query
[cmds.CIV_R_MAIN_BANDVFO, 3,0x07,0xD2,0x00], # Set/Read IC-9700 Main band VFO selection
[cmds.CIV_R_SUB_BANDVFO, 3,0x07,0xD2,0x01] # Set/Read IC-9700 Sub band VFO selection
]
# For CIV commands
#define MODES_NUM 16
#define CW 3
#define CW_R 7
#define USB 1
#define LSB 0
#define RTTY 4
#define RTTY_R 8
#define AM 2
#define FM 5
#define DV 23
#define DD 34
#define ATV 35
#define AGC_SET_NUM 4
#define AGC_OFF 0 // Index to AGC Settings table
#define AGC_SLOW 3
#define AGC_MID 2
#define AGC_FAST 1
#define FILTER 4
#define FILT1 1
#define FILT2 2
#define FILT3 3
#define VFO_A 1
#define VFO_B 0
#define ATTN_OFF 0 // Bypass
#define ATTN_ON 1 // Turn relay on
#define PREAMP_OFF 0 // Bypass
#define PREAMP_ON 1 // Switch relay on
#
# Icom mode number, model Label, range of filt choices allowed (1, 2, or 3), and data mode allowed table (set for data capable modes only)
# per mode, can use filtX and datamode clumns to determine allowable value to write to the radio, or to allow for display.
# not all filters are avaiable for all odes. FOr example DD and WFM are FILT1 only.
# To use filt column, test desired or received value against highest value in the field.
# For datamode, simple check for 1 or 0. If o hen data mode must be off. If 1, data mode must be on.
# in a table search, that would change the displayed mode label from USB to USB-D for example, they are both the same base mode, 0x01.
#
#Modes_List = [
# uint8_t mode_num;
# char mode_label[8];
# uint8_t filtx; // bandwidth in HZ - look up matching width in Filter table when changing modes
# uint8_t data;
modeList = [
(0x00, "LSB ", 3, 0),
(0x01, "USB ", 3, 0),
(0x02, "AM ", 3, 0),
(0x03, "CW ", 3, 0),
(0x04, "RTTY ", 3, 0),
(0x05, "FM ", 3, 0),
(0x06, "W-FM ", 1, 0), # on 705, NA for IC-905
(0x07, "CW-R ", 3, 0),
(0x08, "RTTY-R", 3, 0),
(0x17, "DV ", 3, 0), # hex 17 is 23 dec
(0x00, "LSB-D ", 3, 1),
(0x01, "USB-D ", 3, 1),
(0x02, "AM-D ", 3, 1),
(0x05, "FM-D ", 3, 1),
(0x22, "DD ", 1, 0), # hex 22 is 34 dec // not on 705, on 905
(0x23, "ATV ", 1, 0) # hex 23 is 35 dec // not on 705, on 905
]
# clear text translation of the Filter setting
FilStr = [
"NDEF",
"FIL1", # 1 (1 .. 3 is according to ICOM's documentation)
"FIL2",
"FIL3"
]
# translation of the radio's general mode
ModeStr = [
"MODE_VOICE",
"MODE_DATA",
"MODE_NDEF"
]