-
Notifications
You must be signed in to change notification settings - Fork 56
/
md380.c
2326 lines (2017 loc) · 63.3 KB
/
md380.c
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
/*
* Interface to TYT MD-380.
*
* Copyright (C) 2018 Serge Vakulenko, KK6ABQ
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/stat.h>
#include "radio.h"
#include "util.h"
#define NCHAN 1000
#define NCONTACTS 1000
#define NZONES 250
#define NGLISTS 250
#define NSCANL 250
#define NMESSAGES 50
#define MEMSZ 0x40000
#define OFFSET_TIMESTMP 0x02001
#define OFFSET_SETTINGS 0x02040
#define OFFSET_MSG 0x02180
#define OFFSET_CONTACTS 0x05f80
#define OFFSET_GLISTS 0x0ec20
#define OFFSET_ZONES 0x149e0
#define OFFSET_SCANL 0x18860
#define OFFSET_CHANNELS 0x1ee00
#define GET_TIMESTAMP() (&radio_mem[OFFSET_TIMESTMP])
#define GET_SETTINGS() ((general_settings_t*) &radio_mem[OFFSET_SETTINGS])
#define GET_CHANNEL(i) ((channel_t*) &radio_mem[OFFSET_CHANNELS + (i)*64])
#define GET_ZONE(i) ((zone_t*) &radio_mem[OFFSET_ZONES + (i)*64])
#define GET_ZONEXT(i) ((zone_ext_t*) &radio_mem[OFFSET_ZONEXT + (i)*224])
#define GET_SCANLIST(i) ((scanlist_t*) &radio_mem[OFFSET_SCANL + (i)*104])
#define GET_CONTACT(i) ((contact_t*) &radio_mem[OFFSET_CONTACTS + (i)*36])
#define GET_GROUPLIST(i) ((grouplist_t*) &radio_mem[OFFSET_GLISTS + (i)*96])
#define GET_MESSAGE(i) ((uint16_t*) &radio_mem[OFFSET_MSG + (i)*288])
#define VALID_TEXT(txt) (*(txt) != 0 && *(txt) != 0xffff)
#define VALID_CHANNEL(ch) VALID_TEXT((ch)->name)
#define VALID_ZONE(z) VALID_TEXT((z)->name)
#define VALID_SCANLIST(sl) VALID_TEXT((sl)->name)
#define VALID_GROUPLIST(gl) VALID_TEXT((gl)->name)
#define VALID_CONTACT(ct) ((ct)->type != 0 && VALID_TEXT((ct)->name))
//
// Channel data.
//
typedef struct {
// Byte 0
uint8_t channel_mode : 2, // Mode: Analog or Digital
#define MODE_ANALOG 1
#define MODE_DIGITAL 2
bandwidth : 2, // Bandwidth: 12.5 or 20 or 25 kHz
#define BW_12_5_KHZ 0
#define BW_20_KHZ 1
#define BW_25_KHZ 2
autoscan : 1, // Autoscan Enable
squelch : 1, // Squelch
#define SQ_TIGHT 0
#define SQ_NORMAL 1
_unused1 : 1, // 1
lone_worker : 1; // Lone Worker
// Byte 1
uint8_t talkaround : 1, // Allow Talkaround
rx_only : 1, // RX Only Enable
repeater_slot : 2, // Repeater Slot: 1 or 2
colorcode : 4; // Color Code: 0...15
// Byte 2
uint8_t privacy_no : 4, // Privacy No. (+1): 1...16
privacy : 2, // Privacy: None, Basic or Enhanced
#define PRIV_NONE 0
#define PRIV_BASIC 1
#define PRIV_ENHANCED 2
private_call_conf : 1, // Private Call Confirmed
data_call_conf : 1; // Data Call Confirmed
// Byte 3
uint8_t rx_ref_frequency : 2, // RX Ref Frequency: Low, Medium or High
#define REF_LOW 0
#define REF_MEDIUM 1
#define REF_HIGH 2
_unused2 : 1, // 0
emergency_alarm_ack : 1, // Emergency Alarm Ack
_unused3 : 2, // 0b10
uncompressed_udp : 1, // Compressed UDP Data header (0) Enable, (1) Disable
display_pttid_dis : 1; // Display PTT ID (inverted)
// Byte 4
uint8_t tx_ref_frequency : 2, // RX Ref Frequency: Low, Medium or High
_unused4 : 2, // 0b01
vox : 1, // VOX Enable
power : 1, // Power: Low, High
#define POWER_HIGH 1
#define POWER_LOW 0
admit_criteria : 2; // Admit Criteria: Always, Channel Free or Correct CTS/DCS
#define ADMIT_ALWAYS 0
#define ADMIT_CH_FREE 1
#define ADMIT_TONE 2
#define ADMIT_COLOR 3
// Byte 5
uint8_t _unused5 : 4, // 0
in_call_criteria : 2, // In Call Criteria: Always, Follow Admit Criteria or TX Interrupt
#define INCALL_ALWAYS 0
#define INCALL_ADMIT 1
_unused6 : 2; // 0b11
// Bytes 6-7
uint16_t contact_name_index; // Contact Name: Contact1...
// Bytes 8-9
uint8_t tot : 6, // TOT x 15sec: 0-Infinite, 1=15s... 37=555s
_unused13 : 2; // 0
uint8_t tot_rekey_delay; // TOT Rekey Delay: 0s...255s
// Bytes 10-11
uint8_t emergency_system_index; // Emergency System: None, System1...32
uint8_t scan_list_index; // Scan List: None, ScanList1...250
// Bytes 12-13
uint8_t group_list_index; // Group List: None, GroupList1...250
uint8_t _unused7; // 0
// Bytes 14-15
uint8_t _unused8; // 0
uint8_t _unused9; // 0xff
// Bytes 16-23
uint32_t rx_frequency; // RX Frequency: 8 digits BCD
uint32_t tx_frequency; // TX Frequency: 8 digits BCD
// Bytes 24-27
uint16_t ctcss_dcs_receive; // CTCSS/DCS Dec: 4 digits BCD
uint16_t ctcss_dcs_transmit; // CTCSS/DCS Enc: 4 digits BCD
// Bytes 28-29
uint8_t rx_signaling_syst; // Rx Signaling System: Off, DTMF-1...4
uint8_t tx_signaling_syst; // Tx Signaling System: Off, DTMF-1...4
// Bytes 30-31
uint8_t _unused10; // 0xff
uint8_t _unused11; // 0xff
// Bytes 32-63
uint16_t name[16]; // Channel Name (Unicode)
} channel_t;
//
// Contact data.
//
typedef struct {
// Bytes 0-2
uint8_t id[3]; // Call ID: 1...16777215
#define CONTACT_ID(ct) ((ct)->id[0] | ((ct)->id[1] << 8) | ((ct)->id[2] << 16))
// Byte 3
uint8_t type : 5, // Call Type: Group Call, Private Call or All Call
#define CALL_GROUP 1
#define CALL_PRIVATE 2
#define CALL_ALL 3
receive_tone : 1, // Call Receive Tone: No or yes
_unused2 : 2; // 0b11
// Bytes 4-19
uint16_t name[16]; // Contact Name (Unicode)
} contact_t;
//
// Zone data.
//
typedef struct {
// Bytes 0-31
uint16_t name[16]; // Zone Name (Unicode)
// Bytes 32-63
uint16_t member[16]; // Member: channels 1...16
} zone_t;
//
// Group list data.
//
typedef struct {
// Bytes 0-31
uint16_t name[16]; // Group List Name (Unicode)
// Bytes 32-95
uint16_t member[32]; // Contacts
} grouplist_t;
//
// Scan list data.
//
typedef struct {
// Bytes 0-31
uint16_t name[16]; // Scan List Name (Unicode)
// Bytes 32-37
uint16_t priority_ch1; // Priority Channel 1 or ffff
uint16_t priority_ch2; // Priority Channel 2 or ffff
uint16_t tx_designated_ch; // Tx Designated Channel or ffff
// Bytes 38-41
uint8_t _unused1; // 0xf1
uint8_t sign_hold_time; // Signaling Hold Time (x25 = msec)
uint8_t prio_sample_time; // Priority Sample Time (x250 = msec)
uint8_t _unused2; // 0xff
// Bytes 42-103
uint16_t member[31]; // Channels
} scanlist_t;
//
// General settings.
// TODO: verify the general settings with official CPS
//
typedef struct {
// Bytes 0-19
uint16_t intro_line1[10];
// Bytes 20-39
uint16_t intro_line2[10];
// Bytes 40-63
uint8_t _unused40[24];
// Byte 64
uint8_t _unused64_0 : 3,
monitor_type : 1,
_unused64_4 : 1,
disable_all_leds : 1,
_unused64_6 : 2;
// Byte 65
uint8_t talk_permit_tone : 2,
pw_and_lock_enable : 1,
ch_free_indication_tone : 1,
_unused65_4 : 1,
disable_all_tones : 1,
save_mode_receive : 1,
save_preamble : 1;
// Byte 66
uint8_t _unused66_0 : 2,
keypad_tones : 1,
intro_picture : 1,
_unused66_4 : 4;
// Byte 67
uint8_t _unused67;
// Bytes 68-71
uint8_t radio_id[3];
uint8_t _unused71;
// Bytes 72-84
uint8_t tx_preamble_duration;
uint8_t group_call_hang_time;
uint8_t private_call_hang_time;
uint8_t vox_sensitivity;
uint8_t _unused76[2];
uint8_t rx_low_battery_interval;
uint8_t call_alert_tone_duration;
uint8_t lone_worker_response_time;
uint8_t lone_worker_reminder_time;
uint8_t _unused82;
uint8_t scan_digital_hang_time;
uint8_t scan_analog_hang_time;
// Byte 85
uint8_t _unused85_0 : 6,
backlight_time : 2;
// Bytes 86-87
uint8_t set_keypad_lock_time;
uint8_t mode;
// Bytes 88-95
uint32_t power_on_password;
uint32_t radio_prog_password;
// Bytes 96-103
uint8_t pc_prog_password[8];
// Bytes 104-111
uint8_t _unused104[8];
// Bytes 112-143
uint16_t radio_name[16];
} general_settings_t;
static const char *POWER_NAME[] = { "Low", "High" };
static const char *SQUELCH_NAME[] = { "Tight", "Normal" };
static const char *BANDWIDTH[] = { "12.5", "20", "25", "25" };
static const char *CONTACT_TYPE[] = { "-", "Group", "Private", "All" };
static const char *ADMIT_NAME[] = { "-", "Free", "Tone", "Color" };
#ifdef PRINT_RARE_PARAMS
static const char *INCALL_NAME[] = { "-", "Admit", "-", "Admit" };
static const char *REF_FREQUENCY[] = { "Low", "Med", "High" };
static const char *PRIVACY_NAME[] = { "-", "Basic", "Enhanced" };
static const char *SIGNALING_SYSTEM[] = { "-", "DTMF-1", "DTMF-2", "DTMF-3", "DTMF-4" };
#endif
//
// Print a generic information about the device.
//
static void md380_print_version(radio_device_t *radio, FILE *out)
{
unsigned char *timestamp = GET_TIMESTAMP();
static const char charmap[16] = "0123456789:;<=>?";
if (*timestamp != 0xff) {
fprintf(out, "Last Programmed Date: %d%d%d%d-%d%d-%d%d",
timestamp[0] >> 4, timestamp[0] & 15, timestamp[1] >> 4, timestamp[1] & 15,
timestamp[2] >> 4, timestamp[2] & 15, timestamp[3] >> 4, timestamp[3] & 15);
fprintf(out, " %d%d:%d%d:%d%d\n",
timestamp[4] >> 4, timestamp[4] & 15, timestamp[5] >> 4, timestamp[5] & 15,
timestamp[6] >> 4, timestamp[6] & 15);
fprintf(out, "CPS Software Version: V%c%c.%c%c\n",
charmap[timestamp[7] & 15], charmap[timestamp[8] & 15],
charmap[timestamp[9] & 15], charmap[timestamp[10] & 15]);
}
}
//
// Read memory image from the device.
//
static void md380_download(radio_device_t *radio)
{
int bno;
for (bno=0; bno<MEMSZ/1024; bno++) {
dfu_read_block(bno, &radio_mem[bno*1024], 1024);
++radio_progress;
if (radio_progress % 32 == 0) {
fprintf(stderr, "#");
fflush(stderr);
}
}
}
//
// Write memory image to the device.
//
static void md380_upload(radio_device_t *radio, int cont_flag)
{
int bno;
dfu_erase(0, MEMSZ);
for (bno=0; bno<MEMSZ/1024; bno++) {
dfu_write_block(bno, &radio_mem[bno*1024], 1024);
++radio_progress;
if (radio_progress % 32 == 0) {
fprintf(stderr, "#");
fflush(stderr);
}
}
}
//
// Check whether the memory image is compatible with this device.
//
static int md380_is_compatible(radio_device_t *radio)
{
return 1;
}
//
// Set name for a given zone.
//
static void setup_zone(int index, const char *name)
{
zone_t *z = GET_ZONE(index);
utf8_decode(z->name, name, 16);
}
//
// Add channel to a zone.
// Return 0 on failure.
//
static int zone_append(int index, int cnum)
{
zone_t *z = GET_ZONE(index);
int i;
for (i=0; i<16; i++) {
if (z->member[i] == cnum)
return 1;
if (z->member[i] == 0) {
z->member[i] = cnum;
return 1;
}
}
return 0;
}
static void erase_zone(int index)
{
zone_t *z = GET_ZONE(index);
memset(z, 0, 64);
}
//
// Set parameters for a given scan list.
//
static void setup_scanlist(int index, const char *name,
int prio1, int prio2, int txchan)
{
scanlist_t *sl = GET_SCANLIST(index);
// Bytes 0-31
utf8_decode(sl->name, name, 16);
// Bytes 32-37
sl->priority_ch1 = prio1;
sl->priority_ch2 = prio2;
sl->tx_designated_ch = txchan;
}
static void erase_scanlist(int index)
{
scanlist_t *sl = GET_SCANLIST(index);
memset(sl, 0, 104);
// Bytes 32-37
sl->priority_ch1 = 0xffff;
sl->priority_ch2 = 0xffff;
sl->tx_designated_ch = 0xffff;
// Bytes 38-41
sl->_unused1 = 0xf1;
sl->sign_hold_time = 500 / 25; // 500 msec
sl->prio_sample_time = 2000 / 250; // 2 sec
sl->_unused2 = 0xff;
}
//
// Add channel to a zone.
// Return 0 on failure.
//
static int scanlist_append(int index, int cnum)
{
scanlist_t *sl = GET_SCANLIST(index);
int i;
for (i=0; i<31; i++) {
if (sl->member[i] == cnum)
return 1;
if (sl->member[i] == 0) {
sl->member[i] = cnum;
return 1;
}
}
return 0;
}
static void erase_contact(int index)
{
contact_t *ct = GET_CONTACT(index);
memset(ct, 0, 36);
*(uint32_t*)ct = 0xffffffff;
}
static void setup_contact(int index, const char *name, int type, int id, int rxtone)
{
contact_t *ct = GET_CONTACT(index);
ct->id[0] = id;
ct->id[1] = id >> 8;
ct->id[2] = id >> 16;
ct->type = type;
ct->receive_tone = rxtone;
utf8_decode(ct->name, name, 16);
}
static void setup_grouplist(int index, const char *name)
{
grouplist_t *gl = GET_GROUPLIST(index);
utf8_decode(gl->name, name, 16);
}
//
// Add contact to a grouplist.
// Return 0 on failure.
//
static int grouplist_append(int index, int cnum)
{
grouplist_t *gl = GET_GROUPLIST(index);
int i;
for (i=0; i<32; i++) {
if (gl->member[i] == cnum)
return 1;
if (gl->member[i] == 0) {
gl->member[i] = cnum;
return 1;
}
}
return 0;
}
//
// Set text for a given message.
//
static void setup_message(int index, const char *text)
{
uint16_t *msg = GET_MESSAGE(index);
// Skip spaces and tabs.
while (*text == ' ' || *text == '\t')
text++;
utf8_decode(msg, text, 144);
}
//
// Check that the radio does support this frequency.
//
static int is_valid_frequency(int mhz)
{
if (mhz >= 136 && mhz <= 174)
return 1;
if (mhz >= 400 && mhz <= 480)
return 1;
return 0;
}
//
// Set the parameters for a given memory channel.
//
static void setup_channel(int i, int mode, char *name, double rx_mhz, double tx_mhz,
int power, int scanlist, int squelch, int tot, int rxonly,
int admit, int colorcode, int timeslot, int grouplist, int contact,
int rxtone, int txtone, int width)
{
channel_t *ch = GET_CHANNEL(i);
ch->channel_mode = mode;
ch->bandwidth = width;
ch->squelch = squelch;
ch->rx_only = rxonly;
ch->repeater_slot = timeslot;
ch->colorcode = colorcode;
ch->power = power;
ch->admit_criteria = admit;
ch->contact_name_index = contact;
ch->tot = tot;
ch->scan_list_index = scanlist;
ch->group_list_index = grouplist;
ch->rx_frequency = mhz_to_abcdefgh(rx_mhz);
ch->tx_frequency = mhz_to_abcdefgh(tx_mhz);
ch->ctcss_dcs_receive = rxtone;
ch->ctcss_dcs_transmit = txtone;
utf8_decode(ch->name, name, 16);
}
//
// Erase the channel record.
//
static void erase_channel(int i)
{
channel_t *ch = GET_CHANNEL(i);
// Byte 0
ch->channel_mode = MODE_ANALOG;
ch->bandwidth = BW_12_5_KHZ;
ch->autoscan = 0;
ch->squelch = SQ_NORMAL;
ch->_unused1 = 1;
ch->lone_worker = 0;
// Byte 1
ch->talkaround = 0;
ch->rx_only = 0;
ch->repeater_slot = 1;
ch->colorcode = 1;
// Byte 2
ch->privacy_no = 0;
ch->privacy = PRIV_NONE;
ch->private_call_conf = 0;
ch->data_call_conf = 0;
// Byte 3
ch->rx_ref_frequency = REF_LOW;
ch->_unused2 = 0;
ch->emergency_alarm_ack = 0;
ch->_unused3 = 2;
ch->uncompressed_udp = 1;
ch->display_pttid_dis = 1;
// Byte 4
ch->tx_ref_frequency = REF_LOW;
ch->_unused4 = 1;
ch->vox = 0;
ch->power = POWER_HIGH;
ch->admit_criteria = ADMIT_ALWAYS;
// Byte 5
ch->_unused5 = 0;
ch->in_call_criteria = INCALL_ALWAYS;
ch->_unused6 = 3;
// Bytes 6-7
ch->contact_name_index = 0;
// Bytes 8-9
ch->tot = 60/15;
ch->_unused13 = 0;
ch->tot_rekey_delay = 0;
// Bytes 10-11
ch->emergency_system_index = 0;
ch->scan_list_index = 0;
// Bytes 12-13
ch->group_list_index = 0;
ch->_unused7 = 0;
// Bytes 14-15
ch->_unused8 = 0;
ch->_unused9 = 0xff;
// Bytes 16-23
ch->rx_frequency = 0x40000000;
ch->tx_frequency = 0x40000000;
// Bytes 24-27
ch->ctcss_dcs_receive = 0xffff;
ch->ctcss_dcs_transmit = 0xffff;
// Bytes 28-29
ch->rx_signaling_syst = 0;
ch->tx_signaling_syst = 0;
// Bytes 30-31
ch->_unused10 = 0xff;
ch->_unused11 = 0xff;
// Bytes 32-63
utf8_decode(ch->name, "", 16);
}
static void print_chanlist(FILE *out, uint16_t *unsorted, int nchan)
{
int last = -1;
int range = 0;
int n;
uint16_t data[nchan];
// Sort the list before printing.
memcpy(data, unsorted, nchan * sizeof(uint16_t));
qsort(data, nchan, sizeof(uint16_t), compare_index);
for (n=0; n<nchan; n++) {
int cnum = data[n];
if (cnum == 0)
break;
if (cnum == last+1) {
range = 1;
} else {
if (range) {
fprintf(out, "-%d", last);
range = 0;
}
if (n > 0)
fprintf(out, ",");
fprintf(out, "%d", cnum);
}
last = cnum;
}
if (range)
fprintf(out, "-%d", last);
}
static void print_id(FILE *out, int verbose)
{
general_settings_t *gs = GET_SETTINGS();
unsigned id = gs->radio_id[0] | (gs->radio_id[1] << 8) | (gs->radio_id[2] << 16);
if (verbose)
fprintf(out, "\n# Unique DMR ID and name of this radio.");
fprintf(out, "\nID: %u\nName: ", id);
if (VALID_TEXT(gs->radio_name)) {
print_unicode(out, gs->radio_name, 16, 0);
} else {
fprintf(out, "-");
}
fprintf(out, "\n");
}
static void print_intro(FILE *out, int verbose)
{
general_settings_t *gs = GET_SETTINGS();
if (verbose)
fprintf(out, "\n# Text displayed when the radio powers up.\n");
fprintf(out, "Intro Line 1: ");
if (VALID_TEXT(gs->intro_line1)) {
print_unicode(out, gs->intro_line1, 10, 0);
} else {
fprintf(out, "-");
}
fprintf(out, "\nIntro Line 2: ");
if (VALID_TEXT(gs->intro_line2)) {
print_unicode(out, gs->intro_line2, 10, 0);
} else {
fprintf(out, "-");
}
fprintf(out, "\n");
}
//
// Do we have any channels of given mode?
//
static int have_channels(int mode)
{
int i;
for (i=0; i<NCHAN; i++) {
channel_t *ch = GET_CHANNEL(i);
if (VALID_CHANNEL(ch) && ch->channel_mode == mode)
return 1;
}
return 0;
}
//
// Print base parameters of the channel:
// Name
// RX Frequency
// TX Frequency
// Power
// Scan List
// TOT
// RX Only
// Admit Criteria
//
static void print_chan_base(FILE *out, channel_t *ch, int cnum)
{
fprintf(out, "%5d ", cnum);
print_unicode(out, ch->name, 16, 1);
fprintf(out, " ");
print_freq(out, ch->rx_frequency);
fprintf(out, " ");
print_offset(out, ch->rx_frequency, ch->tx_frequency);
fprintf(out, "%-4s ", POWER_NAME[ch->power]);
if (ch->scan_list_index == 0)
fprintf(out, "- ");
else
fprintf(out, "%-4d ", ch->scan_list_index);
if (ch->tot == 0)
fprintf(out, "- ");
else
fprintf(out, "%-3d ", ch->tot * 15);
fprintf(out, "%c ", "-+"[ch->rx_only]);
fprintf(out, "%-6s ", ADMIT_NAME[ch->admit_criteria]);
}
#ifdef PRINT_RARE_PARAMS
//
// Print extended parameters of the channel:
// Autoscan
// TOT Rekey Delay
// RX Ref Frequency
// RX Ref Frequency
// Lone Worker
// VOX
//
static void print_chan_ext(FILE *out, channel_t *ch)
{
fprintf(out, "%c ", "-+"[ch->autoscan]);
fprintf(out, "%-6s ", INCALL_NAME[ch->in_call_criteria]);
fprintf(out, "%-3d ", ch->tot_rekey_delay);
fprintf(out, "%-5s ", REF_FREQUENCY[ch->rx_ref_frequency]);
fprintf(out, "%-5s ", REF_FREQUENCY[ch->tx_ref_frequency]);
fprintf(out, "%c ", "-+"[ch->lone_worker]);
fprintf(out, "%c ", "-+"[ch->vox]);
fprintf(out, "%c ", "-+"[ch->talkaround]);
}
#endif
static void print_digital_channels(FILE *out, int verbose)
{
int i;
if (verbose) {
fprintf(out, "# Table of digital channels.\n");
fprintf(out, "# 1) Channel number: 1-%d\n", NCHAN);
fprintf(out, "# 2) Name: up to 16 characters, use '_' instead of space\n");
fprintf(out, "# 3) Receive frequency in MHz\n");
fprintf(out, "# 4) Transmit frequency or +/- offset in MHz\n");
fprintf(out, "# 5) Transmit power: High, Low\n");
fprintf(out, "# 6) Scan list: - or index in Scanlist table\n");
fprintf(out, "# 7) Transmit timeout timer in seconds: 0, 15, 30, 45... 555\n");
fprintf(out, "# 8) Receive only: -, +\n");
fprintf(out, "# 9) Admit criteria: -, Free, Color\n");
fprintf(out, "# 10) Color code: 0, 1, 2, 3... 15\n");
fprintf(out, "# 11) Time slot: 1 or 2\n");
fprintf(out, "# 12) Receive group list: - or index in Grouplist table\n");
fprintf(out, "# 13) Contact for transmit: - or index in Contacts table\n");
fprintf(out, "#\n");
}
fprintf(out, "Digital Name Receive Transmit Power Scan TOT RO Admit Color Slot RxGL TxContact");
#ifdef PRINT_RARE_PARAMS
fprintf(out, " AS InCall Dly RxRef TxRef LW VOX TA EmSys Privacy PN PCC EAA DCC CU");
#endif
fprintf(out, "\n");
for (i=0; i<NCHAN; i++) {
channel_t *ch = GET_CHANNEL(i);
if (!VALID_CHANNEL(ch) || ch->channel_mode != MODE_DIGITAL) {
// Select digital channels
continue;
}
print_chan_base(out, ch, i+1);
// Print digital parameters of the channel:
// Color Code
// Repeater Slot
// Group List
// Contact Name
fprintf(out, "%-5d %-3d ", ch->colorcode, ch->repeater_slot);
if (ch->group_list_index == 0)
fprintf(out, "- ");
else
fprintf(out, "%-4d ", ch->group_list_index);
if (ch->contact_name_index == 0)
fprintf(out, "-");
else
fprintf(out, "%-4d", ch->contact_name_index);
#ifdef PRINT_RARE_PARAMS
fprintf(out, " ");
print_chan_ext(out, ch);
// Extended digital parameters of the channel:
// In Call Criteria
// Emergency System
// Privacy
// Privacy No. (+1)
// Private Call Confirmed
// Emergency Alarm Ack
// Data Call Confirmed
// DCDM switch (inverted)
// Leader/MS
if (ch->emergency_system_index == 0)
fprintf(out, "- ");
else
fprintf(out, "%-5d ", ch->emergency_system_index);
fprintf(out, "%-8s ", PRIVACY_NAME[ch->privacy]);
if (ch->privacy == PRIV_NONE)
fprintf(out, "- ");
else
fprintf(out, "%-2d ", ch->privacy_no + 1);
fprintf(out, "%c ", "-+"[ch->private_call_conf]);
fprintf(out, "%c ", "-+"[ch->emergency_alarm_ack]);
fprintf(out, "%c ", "-+"[ch->data_call_conf]);
fprintf(out, "%c ", "+-"[ch->uncompressed_udp]);
#endif
// Print contact name as a comment.
if (ch->contact_name_index > 0) {
contact_t *ct = GET_CONTACT(ch->contact_name_index - 1);
if (VALID_CONTACT(ct)) {
fprintf(out, " # ");
print_unicode(out, ct->name, 16, 0);
}
}
fprintf(out, "\n");
}
}
static void print_analog_channels(FILE *out, int verbose)
{
int i;
if (verbose) {
fprintf(out, "# Table of analog channels.\n");
fprintf(out, "# 1) Channel number: 1-%d\n", NCHAN);
fprintf(out, "# 2) Name: up to 16 characters, use '_' instead of space\n");
fprintf(out, "# 3) Receive frequency in MHz\n");
fprintf(out, "# 4) Transmit frequency or +/- offset in MHz\n");
fprintf(out, "# 5) Transmit power: High, Low\n");
fprintf(out, "# 6) Scan list: - or index\n");
fprintf(out, "# 7) Transmit timeout timer in seconds: 0, 15, 30, 45... 555\n");
fprintf(out, "# 8) Receive only: -, +\n");
fprintf(out, "# 9) Admit criteria: -, Free, Tone\n");
fprintf(out, "# 10) Squelch level: Normal, Tight\n");
fprintf(out, "# 11) Guard tone for receive, or '-' to disable\n");
fprintf(out, "# 12) Guard tone for transmit, or '-' to disable\n");
fprintf(out, "# 13) Bandwidth in kHz: 12.5, 20, 25\n");
fprintf(out, "#\n");
}
fprintf(out, "Analog Name Receive Transmit Power Scan TOT RO Admit Squelch RxTone TxTone Width");
#ifdef PRINT_RARE_PARAMS
fprintf(out, " AS Dly RxRef TxRef LW VOX TA RxSign TxSign ID");
#endif
fprintf(out, "\n");
for (i=0; i<NCHAN; i++) {
channel_t *ch = GET_CHANNEL(i);
if (!VALID_CHANNEL(ch) || ch->channel_mode != MODE_ANALOG) {
// Select analog channels
continue;
}
print_chan_base(out, ch, i+1);
// Print analog parameters of the channel:
// Squelch
// CTCSS/DCS Dec
// CTCSS/DCS Enc
// Bandwidth
fprintf(out, "%-7s ", SQUELCH_NAME[ch->squelch]);
print_tone(out, ch->ctcss_dcs_receive);
fprintf(out, " ");
print_tone(out, ch->ctcss_dcs_transmit);
fprintf(out, " %s", BANDWIDTH[ch->bandwidth]);
#ifdef PRINT_RARE_PARAMS
print_chan_ext(out, ch);
fprintf(out, " ");
// Extended analog parameters of the channel:
// Rx Signaling System
// Tx Signaling System
// Display PTT ID (inverted)
// Non-QT/DQT Turn-off Freq.
fprintf(out, "%-6s ", SIGNALING_SYSTEM[ch->rx_signaling_syst]);
fprintf(out, "%-6s ", SIGNALING_SYSTEM[ch->tx_signaling_syst]);
fprintf(out, "%c ", "+-"[ch->display_pttid_dis]);
#endif
fprintf(out, "\n");
}
}
static int have_zones()
{
int i;
for (i=0; i<NZONES; i++) {
zone_t *z = GET_ZONE(i);
if (VALID_ZONE(z))