-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcps-import-builder.py
executable file
·1789 lines (1483 loc) · 70.4 KB
/
cps-import-builder.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 python
# coding: utf-8
#
# This script reads generic, textual zone, talkgroup, and channel definition
# files (CVS format) and then generates files suitable for import into any
# or all of the supported CPS import formats.
#
# Input files are compatible with those used by K7ABD's Anytone Config Builder.
#
import pandas
import csv
import sys
import os
import time
import glob
import argparse
import re
#
# Our internal channel dictionary contains a set of channel
# attributes which are in stored in a dictionary for that
# channel. Here are the keys available in the attribute dict:
#
# Key Comments
# 'Ch Type' Analog or Digital
# 'RX Freq' Receive frequency of the channel
# 'TX Freq' Transmit frequency of the channel
# 'Power' Power level to operate at Low,Medium,High,Turbo
# (Turbo & High are equivalent when not supported)
# 'Bandwidth' Channel bandwidth 12.5 or 25
# 'CTCSS Decode' Rx tone decode value
# 'CTCSS Encode' Tx tone encode value
# 'RX Only' Make channel receive only if set to "On"
#
# Additional attributes for a digital channel:
#
# Key
# 'Color Code' Integer val 1-14
# 'Talk Group' Contact/TG Name
# 'Time Slot' "1" or "2"
# 'Call Type' "Group Call" or "Private Call"
# 'TX Permit' "Same Color Code" or "Always"
# global lists of all CTCSS values
ctcss_list = ['67','67.0','69.4','71.9','74.4','77','77.0','79.7','82.5','85.4',
'88.5','91.5','94.8','97.4','100','100.0','103.5','107.2',
'110.9','114.8','118.8','123','123.0','127.3','131.8','136.5',
'141.3','146.2','150','150.0','151.4','156.7','159.8',
'162.2','165.5','167.9','171.3','173.8','177.3','179.9',
'183.5','186.2','189.9','192.8','196.6','199.5','203.5',
'206.5','210.7','218.1','225.7','229.1','233.6','241.8',
'250.3','254.1']
cdcss_list = ['D023N','D025N','D026N','D031N','D032N','D043N','D047N','D051N',
'D054N','D065N','D071N','D072N','D073N','D074N','D114N','D115N',
'D116N','D125N','D131N','D132N','D134N','D143N','D152N','D155N',
'D156N','D162N','D165N','D172N','D174N','D205N','D223N','D226N',
'D243N','D244N','D245N','D251N','D261N','D263N','D265N','D271N',
'D306N','D311N','D315N','D331N','D343N','D346N','D351N','D364N',
'D365N','D371N','D411N','D412N','D413N','D423N','D431N','D432N',
'D445N','D464N','D465N','D466N','D503N','D506N','D516N','D532N',
'D546N','D565N','D606N','D612N','D624N','D627N','D631N','D632N',
'D654N','D662N','D664N','D703N','D712N','D723N','D731N','D732N',
'D734N','D743N','D754N']
def anytone_write_zones_export(zones_dict, zones_order_list,
zones_export_file, channels_dict, model, debug=False):
"""This function writes out an Anytone zones import/export file"""
if debug:
print("Preparing Zones Export File...")
# Create a dataframe from the zones dict
header_row_868 = ['No.','Zone Name','Zone Channel Member',
'A Channel','B Channel']
header_row_878 = ['No.','Zone Name','Zone Channel Member',
'Zone Channel Member RX Frequency',
'Zone Channel Member TX Frequency',
'A Channel','A Channel RX Frequency',
'A Channel TX Frequency',
'B Channel','B Channel RX Frequency',
'B Channel TX Frequency']
zones_out_dict = {}
zones_not_ordered_list = []
cnt = 1
for zone_name in zones_dict.keys():
if debug:
print(" Adding zone {} with following members:".format(zone_name))
print(" ", zones_dict[zone_name])
row_list = []
row_list.append(str(cnt))
cnt = cnt + 1
row_list.append(zone_name)
# build Zone Channel Member string from list
zone_member_list = sorted(zones_dict[zone_name])
member_str = '|'.join(zone_member_list)
if debug:
print(" Member string: '{}'".format(member_str))
row_list.append(member_str)
if model != "868":
# build Zone Channel Rx Freq string
rx_freq_list = []
for member in zone_member_list:
channel_rx_freq = str(channels_dict[member]['RX Freq'])
rx_freq_list.append(channel_rx_freq)
rx_freq_str = '|'.join(rx_freq_list)
row_list.append(rx_freq_str)
# build Zone Channel Tx Freq string
tx_freq_list = []
for member in zone_member_list:
channel_tx_freq = str(channels_dict[member]['TX Freq'])
tx_freq_list.append(channel_tx_freq)
tx_freq_str = '|'.join(tx_freq_list)
row_list.append(tx_freq_str)
# now use first member channel info as the "A" & "B" VFO default
first_member_name = zones_dict[zone_name][0]
attr_dict = channels_dict[first_member_name]
row_list.append(first_member_name)
if model != "868":
row_list.append(attr_dict['RX Freq'])
row_list.append(attr_dict['TX Freq'])
row_list.append(first_member_name)
if model != "868":
row_list.append(attr_dict['RX Freq'])
row_list.append(attr_dict['TX Freq'])
zones_out_dict.update({zone_name:row_list})
if zone_name not in zones_order_list:
zones_not_ordered_list.append(row_list)
# Build zones_out_list to match zones_order_list; all the rest of the zones
# go to bottom of list in the order they were processed
zones_out_list = []
for zone_name in zones_order_list:
if zone_name in zones_out_dict.keys():
if debug:
print(" Adding zone to zones_out_list: {}".format(zone_name))
zones_out_list.append(zones_out_dict[zone_name])
else:
print("Warning: Zone '{}' specified in Zones_Order.csv file not used!".format(zone_name))
for i in range(len(zones_not_ordered_list)):
if debug:
print(" Adding zone to zones_out_list: {}".format(zones_not_ordered_list[i][1]))
zones_out_list.append(zones_not_ordered_list[i])
# Output our Zones dataframe
if model == "868":
zones_out_df = pandas.DataFrame(zones_out_list, columns=header_row_868)
else:
# 578 and 878 zone files are the same
zones_out_df = pandas.DataFrame(zones_out_list, columns=header_row_878)
# renumber the "No." column to match new order
for i in range(len(zones_out_df.index)):
zones_out_df.at[i, 'No.'] = i+1
if debug:
print("Writing output to: ", zones_export_file)
zones_out_df.to_csv(zones_export_file, index=False, header=True, quoting=csv.QUOTE_ALL,
line_terminator='\r\n')
# clean up...
del zones_out_list
del zones_out_df
return
def anytone_write_talk_groups_export(talk_groups_dict,
talk_groups_export_file, debug=False):
"""This function writes out an Anytone D878 talk groups file"""
# Create a dataframe from the talk groups dict and output it...
header_row = ['No.','Radio ID','Name','Call Type','Call Alert']
talk_groups_out_list = []
cnt = 1
for tg_id in sorted(talk_groups_dict.keys()):
row_list = []
row_list.append(str(cnt))
cnt = cnt + 1
row_list.append(tg_id)
tg_name = talk_groups_dict[tg_id][0]
if len(tg_name) > 16:
print("WARNING: TG Name '{}' > 16, truncating to '{}'".format(
tg_name,tg_name[:16]))
row_list.append(tg_name[:16])
tg_call_type = talk_groups_dict[tg_id][1]
row_list.append(tg_call_type)
tg_call_alert = talk_groups_dict[tg_id][2]
row_list.append(tg_call_alert)
talk_groups_out_list.append(row_list)
talk_groups_out_df = pandas.DataFrame(talk_groups_out_list,
columns=header_row)
if debug:
print("Writing output to: ", talk_groups_export_file)
talk_groups_out_df.to_csv(talk_groups_export_file, index=False,
header=True, quoting=csv.QUOTE_ALL, line_terminator='\r\n')
# clean up...
del talk_groups_out_list
del talk_groups_out_df
return
def anytone_write_channels_export(channels_dict, channels_export_file,
model, debug=False):
"""This function writes out an Anytone D878 channels import/export file"""
# Header for Anytone 868
header_row_868 = ['No.','Channel Name','Receive Frequency',
'Transmit Frequency','Channel Type','Transmit Power',
'Band Width','CTCSS/DCS Decode','CTCSS/DCS Encode',
'Contact','Contact Call Type','Radio ID',
'Busy Lock/TX Permit','Squelch Mode','Optional Signal',
"DTMF ID",'2Tone ID','5Tone ID','PTT ID','Color Code',
'Slot','CH Scan List','Receive Group List','TX Prohibit',
'Reverse','Simplex TDMA','TDMA Adaptive',
'Encryption Type','Digital Encryption',
'Call Confirmation','Talk Around','Work Alone',
'Custom CTCSS','2TONE Decode','Ranging','Through Mode',
'APRS Report','APRS Report Channel']
# Header for Anytone 578
header_row_578 = ['No.','Channel Name','Receive Frequency',
'Transmit Frequency','Channel Type','Transmit Power',
'Band Width','CTCSS/DCS Decode','CTCSS/DCS Encode',
'Contact','Contact Call Type','Contact TG/DMR ID','Radio ID',
'Busy Lock/TX Permit','Squelch Mode','Optional Signal',
"DTMF ID",'2Tone ID','5Tone ID','PTT ID','Color Code',
'Slot','Scan List','Receive Group List','PTT Prohibit',
'Reverse','TDMA','TDMA Adaptive',
'AES Digital Encryption','Digital Encryption',
'Call Confirmation','Talk Around(Simplex)','Work Alone',
'Custom CTCSS','2TONE Decode','Ranging','Simplex',
'Digi APRS RX','Analog APRS PTT Mode',
'Digital APRS PTT Mode','APRS Report Type',
'Digital APRS Report Channel','Correct Frequency[Hz]',
'SMS Confirmation','Exclude channel from roaming',
'DMR MODE','DataACK Disable','R5toneBot','R5ToneEot']
# Header for Anytone 878
header_row_878 = ['No.','Channel Name','Receive Frequency',
'Transmit Frequency','Channel Type','Transmit Power',
'Band Width','CTCSS/DCS Decode','CTCSS/DCS Encode',
'Contact','Contact Call Type','Contact TG/DMR ID','Radio ID',
'Busy Lock/TX Permit','Squelch Mode','Optional Signal',
"DTMF ID",'2Tone ID','5Tone ID','PTT ID','Color Code',
'Slot','Scan List','Receive Group List','PTT Prohibit',
'Reverse','Simplex TDMA','Slot Suit',
'AES Digital Encryption','Digital Encryption',
'Call Confirmation','Talk Around(Simplex)','Work Alone',
'Custom CTCSS','2TONE Decode','Ranging','Through Mode',
'Digi APRS RX','Analog APRS PTT Mode',
'Digital APRS PTT Mode','APRS Report Type',
'Digital APRS Report Channel','Correct Frequency[Hz]',
'SMS Confirmation','Exclude channel from roaming',
'DMR MODE','DataACK Disable','R5toneBot','R5ToneEot']
# Create a dataframe from the channels dict and output it...
channels_out_list = []
cnt = 1
for ch_name in channels_dict.keys():
# get channel attributes dictionary
attr_dict = channels_dict[ch_name]
# now fill out this row in correct order for Anytone 878
row_list = []
row_list.append(str(cnt))
cnt = cnt + 1
row_list.append(ch_name)
row_list.append(attr_dict['RX Freq']) # Receive Frequency
row_list.append(attr_dict['TX Freq']) # Transmit Frequency
ch_type = attr_dict['Ch Type']
if ch_type == "Analog":
row_list.append("A-Analog")
else:
row_list.append("D-Digital") # Channel Type
# get power and translate "High" to "Turbo"
rf_power = attr_dict['Power']
if rf_power == "High":
rf_power = "Turbo"
row_list.append(rf_power) # Transmit Power
row_list.append(attr_dict['Bandwidth']) # Bandwidth
row_list.append(attr_dict['CTCSS Decode']) # CTCSS/DCS Decode
row_list.append(attr_dict['CTCSS Encode']) # CTCSS/DCS Encode
if ch_type == "Analog":
# use fixed items
row_list.append("0_Analog") # Talk Group
row_list.append("Group Call") # Contact Call Type
if model != "868":
row_list.append("0") # Contact TG/DMR ID
row_list.append("none") # Radio ID
row_list.append("0") # Busy Lock/TX Permit
else:
# use digital channel attributes
row_list.append(attr_dict['Talk Group'])# Talk Group
row_list.append(attr_dict['Call Type']) # Contact Call Type
if model != "868":
row_list.append(attr_dict['TG Number']) # Contact TG/DMR ID
row_list.append("My_DMR_ID") # Radio ID
row_list.append(attr_dict['TX Permit']) # Busy Lock/TX Permit
row_list.append("Carrier") # Squelch Mode
row_list.append("Off") # Optional Signal
row_list.append("1") # DTMF ID
row_list.append("1") # 2Tone ID
row_list.append("1") # 5Tone ID
row_list.append("Off") # PTT ID
if ch_type == "Analog":
# use fixed items
row_list.append("1") # Color Code
row_list.append("1") # Time Slot
else:
# use digital channel attributes
row_list.append(attr_dict['Color Code'])# Color Code
row_list.append(attr_dict['Time Slot']) # Time Slot
row_list.append("None") # Scan List
row_list.append("None") # Receive Group List
row_list.append(attr_dict['RX Only']) # PTT Prohibit
row_list.append("Off") # Reverse
row_list.append("Off") # Simplex TDMA
row_list.append("Off") # TDMA Adaptive
row_list.append("Normal Encryption") # AES Digital Encryption
row_list.append("Off") # Digital Encryption
row_list.append("Off") # Call Confirmation
row_list.append("Off") # Talk Around
row_list.append("Off") # Work Alone
row_list.append("251.1") # Custom CTCSS
row_list.append("1") # 2TONE Decode
row_list.append("Off") # Ranging
row_list.append("Off") # Through Mode
if model == "868":
row_list.append("Off") # APRS Report
row_list.append("1") # APRS Channel
else:
row_list.append("Off") # Digi APRS RX
row_list.append("Off") # Analog APRS PTT Mode
row_list.append("Off") # Digital APRS PTT Mode
row_list.append("Off") # APRS Report Type
row_list.append("1") # Digtial APRS Report Channel
row_list.append("0") # Correct Frequency[Hz]
row_list.append("Off") # SMS Confirmation
row_list.append("0") # Exclude channel from roaming
# calculate DMR Mode
if (attr_dict['RX Freq'] == attr_dict['TX Freq']):
# assume simplex mode
row_list.append(0)
else:
row_list.append(1)
row_list.append("0") # DataACK Disable
row_list.append("0") # R5toneBot
row_list.append("0") # R5ToneEot
# now add this row to the channels list
channels_out_list.append(row_list)
if model == "868":
channels_out_df = pandas.DataFrame(channels_out_list,
columns=header_row_868)
elif model == "578":
channels_out_df = pandas.DataFrame(channels_out_list,
columns=header_row_578)
else:
channels_out_df = pandas.DataFrame(channels_out_list,
columns=header_row_878)
# Group channels by Channel Type (analog then digital)
channels_out_df.sort_values(by=['Channel Type','Channel Name'],
inplace=True)
channels_out_df.reset_index(drop=True, inplace=True)
# renumber the "No." column to match new order
for i in range(len(channels_out_df.index)):
channels_out_df.at[i, 'No.'] = i+1
if debug:
print("Writing output to: ", channels_export_file)
channels_out_df.to_csv(channels_export_file, index=False,
header=True, quoting=csv.QUOTE_ALL, line_terminator='\r\n')
return
def cs800d_write_channels_export(channels_dict, channels_export_file,
debug=False):
"""This function writes out a CS800D CPS formatted channels file"""
analog_header_row = ['No','Channel Alias','Squelch Level',
'Channel Band[KHz]','Personality List','Scan List',
'Auto Scan Start','Rx Only','Talk Around',
'Lone Worker','VOX','Scrambler','Emp De-emp',
'Receive Frequency',
'RX CTCSS/CDCSS Type','CTCSS/CDCSS',
'RX Ref Frequency','Rx Squelch Mode',
'Monitor Squelch Mode',
'Channel Switch Squelch Mode',
'Transmit Frequency',
'TX CTCSS/CDCSS Type','CTCSS/CDCSS',
'TX Ref Frequency','Power Level','Tx Admit',
'Reverse Burst/Turn off code',
'TX Time-out Time[s]','TOT Re-key Time[s]',
'TOT Pre-Alert Time[s]',
'CTCSS Tail Revert Option']
digital_header_row = ['No','Channel Alias','Digital Id', 'Color Code',
'Time Slot','Scan List','Auto Scan Start','Rx Only',
'Talk Around', 'Lone Worker', 'VOX',
'Receive Frequency',
'RX Ref Frequency', 'RX Group List',
'Emergency Alarm Indication',
'Emergency Alarm Ack','Emergency Call Indication',
'Transmit Frequency',
'TX Ref Frequency','TX Contact',
'Emergency System', 'Power Level','Tx Admit',
'TX Time-out Time[s]','TOT Re-key Time[s]',
'TOT Pre-Alert Time[s]','Private Call Confirmed',
'Data Call Confirmed','Encrypt']
# setup analog channels dataframe
analog_channels_out_list = []
cnt = 1
total_channel_cnt = 0
for ch_name in sorted(channels_dict.keys()):
ch_type = channels_dict[ch_name]['Ch Type']
# skip non-analog channels
if ch_type != 'Analog':
continue
# get channel attributes dictionary
attr_dict = channels_dict[ch_name]
# now fill out this row in correct order for cs800d
row_list = []
row_list.append(str(cnt))
cnt = cnt + 1
row_list.append(ch_name) # Channel Alias
row_list.append("Normal") # Squelch level
row_list.append(attr_dict['Bandwidth']) # Channel Bandwidth
row_list.append("Personality 1") # Personality
row_list.append("None") # scan list
row_list.append("Off") # auto scan start
row_list.append(attr_dict['RX Only']) # Rx Only
row_list.append("Off") # Talk around
row_list.append("Off") # Lone Worker
row_list.append("Off") # VOX
row_list.append("Off") # Scrambler
row_list.append("Off") # Emp De-emp
row_list.append(attr_dict['RX Freq']) # Receive Frequency
# RX CTCSS/CDCSS Type & set rx_squelch_mode
ctcss_dcs_decode_val = str(attr_dict['CTCSS Decode'])
if ctcss_dcs_decode_val == "Off":
row_list.append("NONE")
row_list.append("NONE")
rx_squelch_mode = "CTCSS/DCS and Audio"
elif ctcss_dcs_decode_val in ctcss_list:
row_list.append("CTCSS")
row_list.append(float(ctcss_dcs_decode_val))
rx_squelch_mode = "CTCSS/DCS and Audio"
elif ctcss_dcs_decode_val in cdcss_list:
row_list.append("CDCSS")
row_list.append(ctcss_dcs_decode_val[1:4])
rx_squelch_mode = "CTCSS/DCS and Audio"
else:
# we should never get here!
print("ERROR: Invalid ctcss_dcs_decode_val '{}'".format(
ctcss_dcs_decode_val))
sys.exit(-1)
# Compute RX Ref Frequency
if float(attr_dict['RX Freq']) > 180.0:
row_list.append("Low") # RX Ref Frequency (VHF/2 meters)
else:
row_list.append("Low") # RX Ref Frequency (UHF/70cm )
row_list.append(rx_squelch_mode) # Rx squelch mode
row_list.append("Carrier") # Monitor squelch mode
row_list.append("RX Squelch Mode") # Channel switch squelch mode
row_list.append(attr_dict['TX Freq']) # Transmit Frequency
# TX CTCSS/CDCSS Type
ctcss_dcs_encode_val = str(attr_dict['CTCSS Encode'])
if ctcss_dcs_encode_val == "Off":
row_list.append("NONE")
row_list.append("NONE")
elif ctcss_dcs_encode_val in ctcss_list:
row_list.append("CTCSS")
row_list.append(float(ctcss_dcs_encode_val))
elif ctcss_dcs_encode_val in cdcss_list:
row_list.append("CDCSS")
row_list.append(ctcss_dcs_encode_val[1:4])
else:
# we should never get here!
print("ERROR: Invalid ctcss_dcs_encode_val '{}'".format(
ctcss_dcs_encode_val))
sys.exit(-1)
# Compute TX Ref Frequency
if float(attr_dict['TX Freq']) > 180.0:
row_list.append("Middle") # TX Ref Frequency (VHF/2 meters)
else:
row_list.append("Low") # TX Ref Frequency (UHF/70cm )
# Power level
power_level = attr_dict['Power']
if power_level in ['Turbo','High']:
row_list.append("High")
else:
row_list.append("Low")
row_list.append("Always Allow") # TX Admit
row_list.append("Off") # Reverse Burst/Turn off code
row_list.append("180") # TX Time-out Time[s]
row_list.append("0") # TOT Re-key Time[s]
row_list.append("10") # TOT Pre-Alert Time[s]
row_list.append("120") # CTCSS Tail Revert Option
# now add the row for this channel to our analog channels list
analog_channels_out_list.append(row_list)
# Need to ensure max channel count isn't reached
total_channel_cnt += 1
if total_channel_cnt > 2000:
print(" ERROR: Maximum channel count (2000) exceeded.")
print("Aborting...")
sys.exit(-1)
# create the analog channels data frame
analog_channels_out_df = pandas.DataFrame(analog_channels_out_list,
columns=analog_header_row)
# setup digital channels dataframe
digital_channels_out_list = []
cnt = 1
for ch_name in sorted(channels_dict.keys()):
ch_type = channels_dict[ch_name]['Ch Type']
# skip analog channels
if ch_type != 'Digital':
continue
# get channel attributes dictionary
attr_dict = channels_dict[ch_name]
# now fill out this row in correct order for cs800d
row_list = []
row_list.append(str(cnt))
cnt = cnt + 1
row_list.append(ch_name) # Channel Alias
row_list.append("0") # Digital ID
row_list.append(attr_dict['Color Code']) # Color Code
if str(attr_dict['Time Slot']) == '1': # Time Slot
row_list.append("Slot 1")
else:
row_list.append("Slot 2")
row_list.append("None") # Scan List
row_list.append("Off") # Auto Scan Start
row_list.append(attr_dict['RX Only']) # Rx Only
row_list.append("Off") # Talk around
row_list.append("Off") # Lone Worker
row_list.append("Off") # VOX
row_list.append(attr_dict['RX Freq']) # Receive Frequency
# compute RX Ref Frequency
if float(attr_dict['RX Freq']) > 180.0:
row_list.append("Middle") # RX Ref Frequency (VHF/2 meters)
else:
row_list.append("Middle") # RX Ref Frequency (UHF/70cm )
row_list.append("None") # RX Receive Group
row_list.append("Off") # Emergency Alarm Indication
row_list.append("Off") # Emergency Alarm Ack
row_list.append("Off") # Emergency Call Indication
row_list.append(attr_dict['TX Freq']) # Transmit Frequency
# compute TX Ref Frequency
if float(attr_dict['TX Freq']) > 180.0:
row_list.append("Middle") # TX Ref Frequency (VHF/2 meters)
else:
row_list.append("Middle") # TX Ref Frequency (UHF/70cm )
# Need to translate non-alphanumeric characters to spaces
talk_group_str = re.sub('[^0-9a-zA-Z~ ]+', ' ', attr_dict['Talk Group'])
row_list.append(talk_group_str) # TX Contact
row_list.append("None") # Emergency System
# Power level
power_level = attr_dict['Power']
if power_level in ['Turbo','High']:
row_list.append("High")
else:
row_list.append(power_level)
# TX Admit (admit criteria)
dict_admit_criteria = attr_dict['TX Permit']
admit_criteria = "ERROR!" # just in case...
if dict_admit_criteria == "Always":
admit_criteria = "Always"
elif dict_admit_criteria in ['ChannelFree','Different Color Code']:
admit_criteria = "Channel Idle"
elif dict_admit_criteria == "Same Color Code":
admit_criteria = "Color Code Free"
row_list.append(admit_criteria) # TX Admit
row_list.append("180") # TX Time-out Time[s]
row_list.append("0") # TOT Re-key Time[s]
row_list.append("10") # TOT Pre-Alert Time[s]
row_list.append("Off") # Private Call Confirmed
row_list.append("Off") # Data Call Confirmed
row_list.append("Off") # Encrypt
# now add the row for this channel to our digital channels list
digital_channels_out_list.append(row_list)
# Need to ensure max channel count isn't reached
total_channel_cnt += 1
if total_channel_cnt > 2000:
print(" ERROR: Maximum channel count (2000) exceeded.")
print("Aborting...")
sys.exit(-1)
# create the digital channels data frame
digital_channels_out_df = pandas.DataFrame(digital_channels_out_list,
columns=digital_header_row)
# Create a Pandas Excel writer using XlsxWriter as the engine.
if debug:
print("Writing output to: ", channels_export_file)
writer = pandas.ExcelWriter(channels_export_file, engine='xlsxwriter')
analog_channels_out_df.to_excel(writer,
sheet_name="Analog Channel", index=False)
digital_channels_out_df.to_excel(writer,
sheet_name="Digital Channel", index=False)
writer.save()
return
def cs800d_write_talk_groups_export(talk_groups_dict,talk_groups_export_file, debug=False):
"""This function writes out a Connect Systems CS800D formatted talk groups import file."""
# Create a dataframe from the talk groups dict and output it...
header_row = ['No','Call Alias','Call Type','Call ID','Receive Tone']
talk_groups_out_list = []
cnt = 1
for tg_id in sorted(talk_groups_dict.keys()):
row_list = []
#row_list.append(str(cnt))
row_list.append(cnt)
cnt = cnt + 1
tg_name = talk_groups_dict[tg_id][0]
# Need to translate non-alphanumeric characters to spaces
tg_name = re.sub('[^0-9a-zA-Z~ ]+', ' ', tg_name)
tg_name.strip()
if len(tg_name) > 16:
print("WARNING: TG Name '{}' > 16, truncating to '{}'".format(tg_name,tg_name[:16]))
row_list.append(tg_name[:16])
tg_call_type = talk_groups_dict[tg_id][1]
row_list.append(tg_call_type)
row_list.append(tg_id)
tg_call_alert = talk_groups_dict[tg_id][2]
if tg_call_alert == "None":
tg_call_alert = "No"
else:
tg_call_alert = "Yes"
row_list.append(tg_call_alert)
talk_groups_out_list.append(row_list)
talk_groups_out_df = pandas.DataFrame(talk_groups_out_list, columns=header_row)
if debug:
print("Writing output to: ", talk_groups_export_file)
# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pandas.ExcelWriter(talk_groups_export_file, engine='xlsxwriter')
talk_groups_out_df.to_excel(writer, sheet_name="DMR_Contacts", index=False)
writer.save()
return
def opengd77_write_talk_groups_export(talk_groups_dict,talk_groups_export_file,
debug=False):
"""This function writes out an Open GD77 formatted talk groups import file."""
return
def opengd77_write_channels_export(channels_dict, channels_export_file,
debug=False):
"""This function writes out an Open GD77 CPS formatted channels file"""
return
def uv380_write_talk_groups_export(talk_groups_dict,talk_groups_export_file,
tytera_tg_index_dict, debug=False):
"""This function writes out a Tytera uv380 CPS formatted talk groups import file."""
# Prepare a dataframe from the talk groups dict
header_row = ['Contact Name','Call Type','Call ID','Call Receive Tone']
talk_groups_out_list = []
cnt = 1
for tg_id in sorted(talk_groups_dict.keys()):
row_list = []
# Contact Name
tg_name = talk_groups_dict[tg_id][0]
if len(tg_name) > 16:
print("WARNING: TG Name '{}' > 16, truncating to '{}'".format(
tg_name,tg_name[:16]))
row_list.append(tg_name[:16])
# Call Type
tytera_call_type_dict = {'Group Call':'1','Private Call':'2'}
tg_call_type = talk_groups_dict[tg_id][1]
if tg_call_type not in tytera_call_type_dict.keys():
print("ERROR: Can't convert '{}' to Tytera call type!".format(
tg_call_type))
print(" Aborting.")
sys.exit(-1)
row_list.append(tytera_call_type_dict[tg_call_type])
# Call ID
row_list.append(tg_id)
# Call Receive Tone
tytera_call_alert_dict = {'None':'0','Yes':'1'}
tg_call_alert = talk_groups_dict[tg_id][2]
if tg_call_alert not in tytera_call_alert_dict.keys():
print("ERROR: Can't convert '{}' to Tytera call alert!".format(
tg_call_alert))
print(" Aborting.")
sys.exit(-1)
row_list.append(tytera_call_alert_dict[tg_call_alert])
# append the row to our list
talk_groups_out_list.append(row_list)
# Update tytera_tg_index_dict so we can translate in channels file
tytera_tg_index_dict.update({tg_name[:16]:cnt})
cnt = cnt + 1
# Create the data frame
talk_groups_out_df = pandas.DataFrame(talk_groups_out_list,
columns=header_row)
# Output the data frame as CSV file
if debug:
print("Writing output to: ", talk_groups_export_file)
talk_groups_out_df.to_csv(talk_groups_export_file, index=False,
header=True, quoting=csv.QUOTE_NONE, line_terminator='\r\n')
# clean up...
del talk_groups_out_list
del talk_groups_out_df
return
def uv380_write_channels_export(channels_dict, channels_export_file,
tytera_tg_index_dict, debug=False):
"""This function writes out a Tytera uv380 CPS formatted channels file"""
header_row = ['Channel Mode','Channel Name','RX Frequency(MHz)',
'TX Frequency(MHz)','Band Width','Scan List','Squelch',
'RX Ref Frequency','TX Ref Frequency','TOT[s]',
'TOT Rekey Delay[s]','Power','Admit Criteria',
'Auto Scan','Rx Only','Lone Worker','VOX',
'Allow Talkaround','Send GPS Info','Receive GPS Info',
'Private Call Confirmed','Emergency Alarm Ack',
'Data Call Confirmed','Allow Interrupt','DCDM Switch',
'Leader/MS','Emergency System','Contact Name',
'Group List','Color Code','Repeater Slot',
'In Call Criteria','Privacy','Privacy No.',
'GPS System','CTCSS/DCS Dec','CTCSS/DCS Enc',
'Rx Signaling System','Tx Signaling System',
'QT Reverse','Non-QT/DQT Turn-off Freq',
'Display PTT ID','Reverse Burst/Turn-off Code',
'Decode 1','Decode 2','Decode 3','Decode 4',
'Decode 5','Decode 6','Decode 7','Decode 8'
]
# Create a dataframe from the channels dict and output it...
channels_out_list = []
cnt = 1
for ch_name in channels_dict.keys():
# get channel attributes dictionary
attr_dict = channels_dict[ch_name]
# now fill out this row in correct order for Tytera uv380
row_list = []
ch_type = attr_dict['Ch Type']
if ch_type == "Analog":
row_list.append('1') # Channel Mode
else:
row_list.append('2') # Channel Mode
row_list.append(ch_name) # Channel Name
row_list.append(attr_dict['RX Freq']) # Receive Frequency(MHz)
row_list.append(attr_dict['TX Freq']) # Transmit Frequency(MHz)
# translate bandwidth to Tytera 0 (12.5K), 1 (20), or 2 (25K)
if ch_type == "Analog":
tytera_bandwidth_dict = {'12.5K':'0', '20K':'1', '25K':'2'}
bandwidth = attr_dict['Bandwidth']
if bandwidth not in tytera_bandwidth_dict.keys():
print("ERROR: Can't convert '{}' to Tytera bandwidth!".format(
bandwidth))
print(" Aborting.")
sys.exit(-1)
row_list.append(tytera_bandwidth_dict[bandwidth])
else:
row_list.append('0')
row_list.append('0') # Scan List
row_list.append('1') # Squelch
row_list.append('0') # RX Ref Frequency
row_list.append('0') # TX Ref Frequency
row_list.append('8') # TOT[s] (index 8 = 120s)
row_list.append('0') # TOT Rekey Delay[s]
# translate power to Tytera 0 (Low), 1 (Middle), or 2 (High)
tytera_power_dict = {'Low':'0', 'Medium':'1',
'High':'2', 'Turbo':'2' }
power = attr_dict['Power']
if power not in tytera_power_dict.keys():
print("ERROR: Can't convert '{}' to Tytera power!".format(
power))
print(" Aborting.")
sys.exit(-1)
row_list.append(tytera_power_dict[power]) # Power
# Admit Criteria
if ch_type == 'Analog':
row_list.append('0')
else:
# translate Admit Criteria to Tytera 0 (Always), 3 (Color Code)
tytera_admit_criteria_dict = {'Always':'0', 'Same Color Code':'3'}
admit_criteria = attr_dict['TX Permit']
if admit_criteria not in tytera_admit_criteria_dict.keys():
print("ERROR: Can't convert '{}' to Tytera admit criteria!".format(
admit_criteria))
print(" Aborting.")
sys.exit(-1)
row_list.append(tytera_admit_criteria_dict[admit_criteria])
row_list.append('0') # Auto Scan
if attr_dict['RX Only'] == "On":
row_list.append('1') # Rx Only
else:
row_list.append('0') # Rx Only
row_list.append('0') # Lone Worker
row_list.append('0') # VOX
row_list.append('0') # Allow Talkaround
row_list.append('0') # Send GPS
row_list.append('0') # Receive GPS Info
row_list.append('0') # Private Call Confirmed
row_list.append('0') # Emergency Alarm Ack
row_list.append('0') # Data Call Confirmed
row_list.append('0') # Allow Interrupt
row_list.append('0') # DCDM Switch
row_list.append('1') # Leader/MS
row_list.append('0') # Emergency System
# Contact Name
if ch_type == 'Analog':
row_list.append('0')
else:
talk_group_str = attr_dict['Talk Group']
if talk_group_str not in tytera_tg_index_dict.keys():
print("ERROR: Can't convert '{}' to Tytera TG Index!".format(
talk_group_str))
print(" Aborting.")
sys.exit(-1)
row_list.append(tytera_tg_index_dict[talk_group_str])
row_list.append('0') # Group List
# Color Code
if ch_type == 'Analog':
row_list.append('1')
else:
row_list.append(attr_dict['Color Code'])
# Repeater Slot
if ch_type == 'Analog':
row_list.append('0')
else:
# translate Repeater Slot to Tytera 0 (Slot 1), 1 (Slot 2)
tytera_time_slot_dict = {'1':'0', '2':'1'}
time_slot = str(attr_dict['Time Slot'])
if time_slot not in tytera_time_slot_dict.keys():
print("ERROR: Can't convert '{}' to Tytera time slot!".format(
time_slot))
print(" Channel name = {}".format(ch_name))
print(" Aborting.")
sys.exit(-1)
row_list.append(tytera_time_slot_dict[time_slot])
# In Call Criteria
if ch_type == 'Analog':
row_list.append('0')
else:
row_list.append('1') # force "Follow Admit Criteria"
row_list.append('0') # Privacy
row_list.append('0') # Privacy No.
row_list.append('0') # GPS System
row_list.append(attr_dict['CTCSS Decode']) # CTCSS/DCS Dec
row_list.append(attr_dict['CTCSS Encode']) # CTCSS/DCS Enc
row_list.append('0') # Rx Signaling System
row_list.append('0') # Tx Signaling System
row_list.append('0') # QT Reverse
row_list.append('2') # Non-QT/DQT Turn-off Freq
row_list.append('1') # Display PTT ID
row_list.append('1') # Reverse Burst/Turn-off Code
row_list.append('0') # Decode 1
row_list.append('0') # Decode 2
row_list.append('0') # Decode 3
row_list.append('0') # Decode 4
row_list.append('0') # Decode 5
row_list.append('0') # Decode 6
row_list.append('0') # Decode 7
row_list.append('0') # Decode 8
# now add this row to the channels list
channels_out_list.append(row_list)
# Create data frame
channels_out_df = pandas.DataFrame(channels_out_list, columns=header_row)
# Group channels by Channel Type (analog then digital)
channels_out_df.sort_values(by=['Channel Mode','Channel Name'],
inplace=True)
channels_out_df.reset_index(drop=True, inplace=True)
# Write CSV file
if debug:
print("Writing output to: {}".format(channels_export_file))
channels_out_df.to_csv(channels_export_file, index=False,
header=True, quoting=csv.QUOTE_NONE, line_terminator='\r\n')
return
def read_zone_order_file(file_path, debug=False):
"""This function reads the Zone_Order.csv file and builds the zones_order_list."""
# read in the Zone_Order.csv file
if debug:
print("Processing: {}".format(file_path))
zones_order_df = pandas.read_csv(file_path)
# loop through k7abd file rows
zones_order_list = []
for i,row in zones_order_df.iterrows():
# get zone
zone_name = row['Zone Name']
zones_order_list.append(zone_name)
if debug:
print(" Returning zones_order_list: {}".format(zones_order_list))
return zones_order_list
def read_tg_filter_file(file_path, debug=False):