-
Notifications
You must be signed in to change notification settings - Fork 70
/
dudestar.cpp
3797 lines (3635 loc) · 109 KB
/
dudestar.cpp
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
/*
Copyright (C) 2019 Doug McLain
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "dudestar.h"
#include "ui_dudestar.h"
#include "SHA256.h"
#include "crs129.h"
#include "cbptc19696.h"
#include "cgolay2087.h"
#include <iostream>
#include <QMessageBox>
#include <QFileDialog>
#include <QSerialPortInfo>
#define LOBYTE(w) ((uint8_t)(uint16_t)(w & 0x00FF))
#define HIBYTE(w) ((uint8_t)((((uint16_t)(w)) >> 8) & 0xFF))
#define LOWORD(dw) ((uint16_t)(uint32_t)(dw & 0x0000FFFF))
#define HIWORD(dw) ((uint16_t)((((uint32_t)(dw)) >> 16) & 0xFFFF))
#define DEBUG
//#define DEBUG_YSF
#define CHANNEL_FRAME_TX 0x1001
#define CODEC_FRAME_TX 0x1002
#define CHANNEL_FRAME_RX 0x2001
#define CODEC_FRAME_RX 0x2002
const unsigned char REC62[] = {0x62U, 0x02U, 0x02U, 0x0CU, 0x0BU, 0x12U, 0x64U, 0x00U, 0x00U, 0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
const unsigned char REC63[] = {0x63U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC64[] = {0x64U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC65[] = {0x65U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC66[] = {0x66U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC67[] = {0x67U, 0xF0U, 0x9DU, 0x6AU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC68[] = {0x68U, 0x19U, 0xD4U, 0x26U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC69[] = {0x69U, 0xE0U, 0xEBU, 0x7BU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC6A[] = {0x6AU, 0x00U, 0x00U, 0x02U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
const unsigned char REC6B[] = {0x6BU, 0x02U, 0x02U, 0x0CU, 0x0BU, 0x12U, 0x64U, 0x00U, 0x00U, 0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
const unsigned char REC6C[] = {0x6CU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC6D[] = {0x6DU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC6E[] = {0x6EU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC6F[] = {0x6FU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC70[] = {0x70U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC71[] = {0x71U, 0xACU, 0xB8U, 0xA4U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC72[] = {0x72U, 0x9BU, 0xDCU, 0x75U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC73[] = {0x73U, 0x00U, 0x00U, 0x02U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
const unsigned char REC80[] = {0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
const uint8_t AMBEP251_4400_2800[17] = {0x61, 0x00, 0x0d, 0x00, 0x0a, 0x05U, 0x58U, 0x08U, 0x6BU, 0x10U, 0x30U, 0x00U, 0x00U, 0x00U, 0x00U, 0x01U, 0x90U};//DVSI P25 USB Dongle FEC
const uint8_t AMBEP251_4400_0000[17] = {0x61, 0x00, 0x0d, 0x00, 0x0a, 0x05U, 0x58U, 0x08U, 0x6BU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x01U, 0x58U};//DVSI P25 USB Dongle No-FEC
const uint8_t AMBE1000_4400_2800[17] = {0x61, 0x00, 0x0d, 0x00, 0x0a, 0x00U, 0x58U, 0x08U, 0x87U, 0x30U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x44U, 0x90U};
const uint8_t AMBE2000_4400_2800[17] = {0x61, 0x00, 0x0d, 0x00, 0x0a, 0x02U, 0x58U, 0x07U, 0x65U, 0x00U, 0x09U, 0x1eU, 0x0cU, 0x41U, 0x27U, 0x73U, 0x90U};
const uint8_t AMBE3000_4400_2800[17] = {0x61, 0x00, 0x0d, 0x00, 0x0a, 0x04U, 0x58U, 0x09U, 0x86U, 0x80U, 0x20U, 0x00U, 0x00U, 0x00U, 0x00U, 0x73U, 0x90U};
const uint8_t AMBE2000_2400_1200[17] = {0x61, 0x00, 0x0d, 0x00, 0x0a, 0x01U, 0x30U, 0x07U, 0x63U, 0x40U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x48U};
const uint8_t AMBE3000_2450_1150[17] = {0x61, 0x00, 0x0d, 0x00, 0x0a, 0x04U, 0x31U, 0x07U, 0x54U, 0x24U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x6fU, 0x48U};
const uint8_t AMBE3000_2450_0000[17] = {0x61, 0x00, 0x0d, 0x00, 0x0a, 0x04U, 0x31U, 0x07U, 0x54U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x70U, 0x31U};
#ifdef USE_FLITE
extern "C" {
extern cst_voice * register_cmu_us_slt(const char *);
extern cst_voice * register_cmu_us_kal16(const char *);
extern cst_voice * register_cmu_us_awb(const char *);
extern cst_voice * register_cmu_us_rms(const char *);
}
#endif
DudeStar::DudeStar(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::DudeStar)
{
dmrslot = 2;
dmrcc = 1;
dmrcalltype = 0;
mbe = nullptr;
ysf = nullptr;
ping_cnt = 0;
hwtx = false;
hwrx = true;
muted = false;
enable_swtx = false;
ui->setupUi(this);
init_gui();
udp = new QUdpSocket(this);
config_path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
config_path += "/dudestar";
connect(&qnam, SIGNAL(finished(QNetworkReply*)), this, SLOT(http_finished(QNetworkReply*)));
QAudioFormat format;
format.setSampleRate(8000);
format.setChannelCount(1);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
qDebug() << "Version == " << VERSION_NUMBER;
if(devices.size() == 0){
qDebug() << "No audio hardware found";
}
else{
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
QList<int> srs = info.supportedSampleRates();
for(int i = 0; i < srs.size(); ++i){
qDebug() << "Sample rate " << srs[i] << " supported";
}
QList<int> ss = info.supportedSampleSizes();
for(int i = 0; i < ss.size(); ++i){
qDebug() << "Sample size " << ss[i] << " supported";
}
QList<QAudioFormat::SampleType> st = info.supportedSampleTypes();
for(int i = 0; i < st.size(); ++i){
qDebug() << "Sample type " << st[i] << " supported";
}
QStringList sc = info.supportedCodecs();
for(int i = 0; i < sc.size(); ++i){
qDebug() << "Sample codec " << sc[i] << " supported";
}
QList<QAudioFormat::Endian> bo = info.supportedByteOrders();
for(int i = 0; i < bo.size(); ++i){
qDebug() << "Sample byte order " << bo[i] << " supported";
}
QList<int> cc = info.supportedChannelCounts();
for(int i = 0; i < cc.size(); ++i){
qDebug() << "Sample channel count " << cc[i] << " supported";
}
if (!info.isFormatSupported(format)) {
qWarning() << "Raw audio format not supported by backend, trying nearest format.";
format = info.nearestFormat(format);
qWarning() << "Format now set to " << format.sampleRate() << ":" << format.sampleSize();
}
}
#ifdef USE_FLITE
flite_init();
voice_slt = register_cmu_us_slt(nullptr);
voice_kal = register_cmu_us_kal16(nullptr);
voice_awb = register_cmu_us_awb(nullptr);
voice_rms = register_cmu_us_rms(nullptr);
#endif
audio = new QAudioOutput(format, this);
audio->setBufferSize(8192);
//format.setByteOrder(QAudioFormat::BigEndian);
audioin = new QAudioInput(format, this);
audiotimer = new QTimer();
ping_timer = new QTimer();
ysftimer = new QTimer();
connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));
connect_status = DISCONNECTED;
tx = false;
txtimer = new QTimer();
user_data.resize(21);
connect(txtimer, SIGNAL(timeout()), this, SLOT(tx_timer()));
connect(udp, SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(audiotimer, SIGNAL(timeout()), this, SLOT(process_audio()));
connect(ping_timer, SIGNAL(timeout()), this, SLOT(process_ping()));
connect(ysftimer, SIGNAL(timeout()), this, SLOT(process_ysf_data()));
//audiotimer->start(19);
//ysftimer->start(90);
process_dmr_ids();
process_nxdn_ids();
//process_settings();
}
DudeStar::~DudeStar()
{
QFile f(config_path + "/settings.conf");
f.open(QIODevice::WriteOnly);
QTextStream stream(&f);
stream << "MODE:" << ui->modeCombo->currentText() << endl;
stream << "REFHOST:" << saved_refhost << endl;
stream << "DCSHOST:" << saved_dcshost << endl;
stream << "XRFHOST:" << saved_xrfhost << endl;
stream << "YSFHOST:" << saved_ysfhost << endl;
stream << "DMRHOST:" << saved_dmrhost << endl;
stream << "P25HOST:" << saved_p25host << endl;
stream << "NXDNHOST:" << saved_nxdnhost << endl;
stream << "MODULE:" << ui->comboMod->currentText() << endl;
stream << "CALLSIGN:" << ui->callsignEdit->text() << endl;
stream << "DMRTGID:" << ui->dmrtgEdit->text() << endl;
//stream << "DMRCC:" << ui->dmrccEdit->text() << endl;
//stream << "DMRSLOT:" << ui->dmrslotEdit->text() << endl;
stream << "MYCALL:" << ui->mycallEdit->text().simplified() << endl;
stream << "URCALL:" << ui->urcallEdit->text().simplified() << endl;
stream << "RPTR1:" << ui->rptr1Edit->text().simplified() << endl;
stream << "RPTR2:" << ui->rptr2Edit->text().simplified() << endl;
stream << "USRTXT:" << ui->usertxtEdit->text() << endl;
f.close();
delete ui;
}
void DudeStar::about()
{
QMessageBox::about(this, tr("About DUDE-Star"),
tr("DUDE-Star git build %1\nCopyright (C) 2019 Doug McLain AD8DP\n\n"
"This program is free software; you can redistribute it"
"and/or modify it under the terms of the GNU General Public "
"License as published by the Free Software Foundation; "
"version 2.\n\nThis program is distributed in the hope that it "
"will be useful, but WITHOUT ANY WARRANTY; without even "
"the implied warranty of MERCHANTABILITY or FITNESS FOR A "
"PARTICULAR PURPOSE. See the GNU General Public License for "
"more details.\n\nYou should have received a copy of the GNU "
"General Public License along with this program. "
"If not, see <http://www.gnu.org/licenses/>").arg(VERSION_NUMBER));
}
void DudeStar::init_gui()
{
status_txt = new QLabel("Not connected");
#ifdef USE_FLITE
tts_voices = new QButtonGroup();
tts_voices->addButton(ui->checkBoxTTSOff, 0);
tts_voices->addButton(ui->checkBoxKal, 1);
tts_voices->addButton(ui->checkBoxRms, 2);
tts_voices->addButton(ui->checkBoxAwb, 3);
tts_voices->addButton(ui->checkBoxSlt, 4);
#endif
#ifndef USE_FLITE
ui->checkBoxTTSOff->hide();
ui->checkBoxKal->hide();
ui->checkBoxRms->hide();
ui->checkBoxAwb->hide();
ui->checkBoxSlt->hide();
ui->TTSEdit->hide();
#endif
ui->checkBoxTTSOff->setCheckState(Qt::Checked);
ui->volumeSlider->setRange(0, 100);
ui->volumeSlider->setValue(100);
ui->txButton->setDisabled(true);
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close()));
connect(ui->actionUpdate_DMR_IDs, SIGNAL(triggered()), this, SLOT(update_dmr_ids()));
connect(ui->actionUpdate_host_files, SIGNAL(triggered()), this, SLOT(delete_host_files()));
connect(ui->connectButton, SIGNAL(clicked()), this, SLOT(process_connect()));
connect(ui->txButton, SIGNAL(pressed()), this, SLOT(press_tx()));
connect(ui->txButton, SIGNAL(released()), this, SLOT(release_tx()));
connect(ui->muteButton, SIGNAL(clicked()), this, SLOT(process_mute_button()));
connect(ui->volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(process_volume_changed(int)));
ui->statusBar->insertPermanentWidget(0, status_txt, 1);
connect(ui->checkBoxSWRX, SIGNAL(stateChanged(int)), this, SLOT(swrx_state_changed(int)));
connect(ui->checkBoxSWTX, SIGNAL(stateChanged(int)), this, SLOT(swtx_state_changed(int)));
ui->rptr1->setTextInteractionFlags(Qt::TextSelectableByMouse);
ui->rptr2->setTextInteractionFlags(Qt::TextSelectableByMouse);
ui->mycall->setTextInteractionFlags(Qt::TextSelectableByMouse);
ui->urcall->setTextInteractionFlags(Qt::TextSelectableByMouse);
ui->streamid->setTextInteractionFlags(Qt::TextSelectableByMouse);
ui->usertxt->setTextInteractionFlags(Qt::TextSelectableByMouse);
ui->modeCombo->addItem("REF");
ui->modeCombo->addItem("DCS");
ui->modeCombo->addItem("XRF");
ui->modeCombo->addItem("YSF");
ui->modeCombo->addItem("DMR");
ui->modeCombo->addItem("P25");
ui->modeCombo->addItem("NXDN");
ui->dmrccEdit->setText(QString::number(dmrcc));
ui->dmrslotEdit->setText(QString::number(dmrslot));
connect(ui->modeCombo, SIGNAL(currentTextChanged(const QString &)), this, SLOT(process_mode_change(const QString &)));
connect(ui->hostCombo, SIGNAL(currentTextChanged(const QString &)), this, SLOT(process_host_change(const QString &)));
for(char m = 0x41; m < 0x5b; ++m){
ui->comboMod->addItem(QString(m));
}
ui->hostCombo->setEditable(true);
ui->dmrtgEdit->setEnabled(false);
if(!enable_swtx){
ui->checkBoxSWTX->hide();
}
}
void DudeStar::start_request(QString f)
{
hosts_filename = f;
qnam.get(QNetworkRequest(QUrl("http://www.dudetronics.com/ar-dns" + f)));
status_txt->setText(tr("Downloading http://www.dudetronics.com/ar-dns" + f.toLocal8Bit()));
}
void DudeStar::http_finished(QNetworkReply *reply)
{
if (reply->error()) {
status_txt->setText(tr("Download failed:\n%1.").arg(reply->errorString()));
reply->deleteLater();
reply = nullptr;
return;
}
else{
QFile *hosts_file = new QFile(config_path + hosts_filename);
hosts_file->open(QIODevice::WriteOnly);
QFileInfo fileInfo(hosts_file->fileName());
QString filename(fileInfo.fileName());
hosts_file->write(reply->readAll());
hosts_file->flush();
hosts_file->close();
delete hosts_file;
status_txt->setText(tr("Downloaded " + filename.toLocal8Bit()));
qDebug() << "Downloaded " << filename;
if(filename == "dplus.txt"){
process_ref_hosts();
}
else if(filename == "dextra.txt"){
process_xrf_hosts();
}
else if(filename == "dcs.txt"){
process_dcs_hosts();
}
else if(filename == "YSFHosts.txt"){
process_ysf_hosts();
}
else if(filename == "P25Hosts.txt"){
process_p25_hosts();
}
else if(filename == "DMRHosts.txt"){
process_dmr_hosts();
}
else if(filename == "NXDNHosts.txt"){
process_nxdn_hosts();
}
else if(filename == "DMRIDs.dat"){
process_dmr_ids();
}
}
}
void DudeStar::process_host_change(const QString &h)
{
if(ui->modeCombo->currentText().simplified() == "REF"){
saved_refhost = h.simplified();
}
if(ui->modeCombo->currentText().simplified() == "DCS"){
saved_dcshost = h.simplified();
}
if(ui->modeCombo->currentText().simplified() == "XRF"){
saved_xrfhost = h.simplified();
}
if(ui->modeCombo->currentText().simplified() == "YSF"){
saved_ysfhost = h.simplified();
}
if(ui->modeCombo->currentText().simplified() == "DMR"){
saved_dmrhost = h.simplified();
}
if(ui->modeCombo->currentText().simplified() == "P25"){
saved_p25host = h.simplified();
}
if(ui->modeCombo->currentText().simplified() == "NXDN"){
saved_nxdnhost = h.simplified();
}
}
void DudeStar::process_mode_change(const QString &m)
{
if(m == "REF"){
process_ref_hosts();
ui->comboMod->setEnabled(true);
ui->dmrtgEdit->setEnabled(false);
ui->dmrccEdit->setEnabled(false);
ui->dmrslotEdit->setEnabled(false);
ui->checkBoxDMRPC->setEnabled(false);
ui->mycallEdit->setEnabled(true);
ui->urcallEdit->setEnabled(true);
ui->rptr1Edit->setEnabled(true);
ui->rptr2Edit->setEnabled(true);
ui->usertxtEdit->setEnabled(true);
ui->label_1->setText("MYCALL");
ui->label_2->setText("URCALL");
ui->label_3->setText("RPTR1");
ui->label_4->setText("RPTR2");
ui->label_5->setText("Stream ID");
ui->label_6->setText("User txt");
}
if(m == "DCS"){
process_dcs_hosts();
ui->comboMod->setEnabled(true);
ui->dmrtgEdit->setEnabled(false);
ui->dmrccEdit->setEnabled(false);
ui->dmrslotEdit->setEnabled(false);
ui->checkBoxDMRPC->setEnabled(false);
ui->mycallEdit->setEnabled(true);
ui->urcallEdit->setEnabled(true);
ui->rptr1Edit->setEnabled(true);
ui->rptr2Edit->setEnabled(true);
ui->usertxtEdit->setEnabled(true);
ui->label_1->setText("MYCALL");
ui->label_2->setText("URCALL");
ui->label_3->setText("RPTR1");
ui->label_4->setText("RPTR2");
ui->label_5->setText("Stream ID");
ui->label_6->setText("User txt");
}
if(m == "XRF"){
process_xrf_hosts();
ui->comboMod->setEnabled(true);
ui->dmrtgEdit->setEnabled(false);
ui->dmrccEdit->setEnabled(false);
ui->dmrslotEdit->setEnabled(false);
ui->checkBoxDMRPC->setEnabled(false);
ui->mycallEdit->setEnabled(true);
ui->urcallEdit->setEnabled(true);
ui->rptr1Edit->setEnabled(true);
ui->rptr2Edit->setEnabled(true);
ui->usertxtEdit->setEnabled(true);
ui->label_1->setText("MYCALL");
ui->label_2->setText("URCALL");
ui->label_3->setText("RPTR1");
ui->label_4->setText("RPTR2");
ui->label_5->setText("Stream ID");
ui->label_6->setText("User txt");
}
else if(m == "YSF"){
process_ysf_hosts();
ui->comboMod->setEnabled(false);
ui->dmrtgEdit->setEnabled(false);
ui->dmrccEdit->setEnabled(false);
ui->dmrslotEdit->setEnabled(false);
ui->checkBoxDMRPC->setEnabled(false);
ui->mycallEdit->setEnabled(false);
ui->urcallEdit->setEnabled(false);
ui->rptr1Edit->setEnabled(false);
ui->rptr2Edit->setEnabled(false);
ui->usertxtEdit->setEnabled(false);
ui->label_1->setText("Gateway");
ui->label_2->setText("Callsign");
ui->label_3->setText("Dest");
ui->label_4->setText("Type");
ui->label_5->setText("Path");
ui->label_6->setText("Frame#");
}
else if(m == "DMR"){
process_dmr_hosts();
ui->comboMod->setEnabled(false);
ui->dmrtgEdit->setEnabled(true);
ui->dmrccEdit->setEnabled(true);
ui->dmrslotEdit->setEnabled(true);
ui->checkBoxDMRPC->setEnabled(true);
ui->mycallEdit->setEnabled(false);
ui->urcallEdit->setEnabled(false);
ui->rptr1Edit->setEnabled(false);
ui->rptr2Edit->setEnabled(false);
ui->usertxtEdit->setEnabled(false);
ui->label_1->setText("Callsign");
ui->label_2->setText("SrcID");
ui->label_3->setText("DestID");
ui->label_4->setText("GWID");
ui->label_5->setText("Seq#");
ui->label_6->setText("");
}
else if(m == "P25"){
process_p25_hosts();
ui->comboMod->setEnabled(false);
ui->dmrtgEdit->setEnabled(false);
ui->dmrccEdit->setEnabled(false);
ui->dmrslotEdit->setEnabled(false);
ui->checkBoxDMRPC->setEnabled(false);
ui->mycallEdit->setEnabled(false);
ui->urcallEdit->setEnabled(false);
ui->rptr1Edit->setEnabled(false);
ui->rptr2Edit->setEnabled(false);
ui->usertxtEdit->setEnabled(false);
ui->label_1->setText("Callsign");
ui->label_2->setText("SrcID");
ui->label_3->setText("DestID");
ui->label_4->setText("GWID");
ui->label_5->setText("Seq#");
ui->label_6->setText("");
}
else if(m == "NXDN"){
process_nxdn_hosts();
ui->comboMod->setEnabled(false);
ui->dmrtgEdit->setEnabled(false);
ui->dmrccEdit->setEnabled(false);
ui->dmrslotEdit->setEnabled(false);
ui->checkBoxDMRPC->setEnabled(false);
ui->mycallEdit->setEnabled(false);
ui->urcallEdit->setEnabled(false);
ui->rptr1Edit->setEnabled(false);
ui->rptr2Edit->setEnabled(false);
ui->usertxtEdit->setEnabled(false);
ui->label_1->setText("Callsign");
ui->label_2->setText("SrcID");
ui->label_3->setText("DestID");
ui->label_4->setText("");
ui->label_5->setText("Seq#");
ui->label_6->setText("");
}
}
void DudeStar::swrx_state_changed(int s)
{
if(s == Qt::Unchecked){
hwrx = true;
}
else{
hwrx = false;
}
if(ysfdec){
//ysfdec->m_mbeDecoder->set_hwrx(hwrx);
}
}
void DudeStar::swtx_state_changed(int s)
{
if(s == Qt::Unchecked){
hwtx = true;
}
else{
hwtx = false;
}
}
void DudeStar::process_ref_hosts()
{
if(!QDir(config_path).exists()){
QDir().mkdir(config_path);
}
QFileInfo check_file(config_path + "/dplus.txt");
if(check_file.exists() && check_file.isFile()){
ui->hostCombo->blockSignals(true);
QFile f(config_path + "/dplus.txt");
if(f.open(QIODevice::ReadOnly)){
ui->hostCombo->clear();
while(!f.atEnd()){
QString l = f.readLine();
if(l.at(0) == '#'){
continue;
}
QStringList ll = l.split('\t');
if(ll.size() > 1){
ui->hostCombo->addItem(ll.at(0).simplified(), ll.at(1) + ":20001");
}
}
}
f.close();
int i = ui->hostCombo->findText(saved_refhost);
ui->hostCombo->setCurrentIndex(i);
ui->hostCombo->blockSignals(false);
}
else{
start_request("/dplus.txt");
}
}
void DudeStar::process_dcs_hosts()
{
if(!QDir(config_path).exists()){
QDir().mkdir(config_path);
}
QFileInfo check_file(config_path + "/dcs.txt");
if(check_file.exists() && check_file.isFile()){
ui->hostCombo->blockSignals(true);
QFile f(config_path + "/dcs.txt");
if(f.open(QIODevice::ReadOnly)){
ui->hostCombo->clear();
while(!f.atEnd()){
QString l = f.readLine();
if(l.at(0) == '#'){
continue;
}
QStringList ll = l.split('\t');
if(ll.size() > 1){
ui->hostCombo->addItem(ll.at(0).simplified(), ll.at(1) + ":30051");
}
}
}
f.close();
int i = ui->hostCombo->findText(saved_dcshost);
ui->hostCombo->setCurrentIndex(i);
ui->hostCombo->blockSignals(false);
}
else{
//QMessageBox::StandardButton reply;
//reply = QMessageBox::question(this, "No DExtra file", "No DExtra file found, download?", QMessageBox::Yes|QMessageBox::No);
//if (reply == QMessageBox::Yes) {
start_request("/dcs.txt");
//}
}
}
void DudeStar::process_xrf_hosts()
{
if(!QDir(config_path).exists()){
QDir().mkdir(config_path);
}
QFileInfo check_file(config_path + "/dextra.txt");
if(check_file.exists() && check_file.isFile()){
ui->hostCombo->blockSignals(true);
QFile f(config_path + "/dextra.txt");
if(f.open(QIODevice::ReadOnly)){
ui->hostCombo->clear();
while(!f.atEnd()){
QString l = f.readLine();
if(l.at(0) == '#'){
continue;
}
QStringList ll = l.split('\t');
if(ll.size() > 1){
ui->hostCombo->addItem(ll.at(0).simplified(), ll.at(1) + ":30001");
}
}
}
f.close();
int i = ui->hostCombo->findText(saved_xrfhost);
ui->hostCombo->setCurrentIndex(i);
ui->hostCombo->blockSignals(false);
}
else{
start_request("/dextra.txt");
}
}
void DudeStar::process_ysf_hosts()
{
if(!QDir(config_path).exists()){
QDir().mkdir(config_path);
}
QFileInfo check_file(config_path + "/YSFHosts.txt");
if(check_file.exists() && check_file.isFile()){
ui->hostCombo->blockSignals(true);
QFile f(config_path + "/YSFHosts.txt");
if(f.open(QIODevice::ReadOnly)){
ui->hostCombo->clear();
while(!f.atEnd()){
QString l = f.readLine();
if(l.at(0) == '#'){
continue;
}
QStringList ll = l.split(';');
if(ll.size() > 4){
ui->hostCombo->addItem(ll.at(1).simplified() + " - " + ll.at(2).simplified(), ll.at(3) + ":" + ll.at(4));
}
}
}
f.close();
int i = ui->hostCombo->findText(saved_ysfhost);
ui->hostCombo->setCurrentIndex(i);
ui->hostCombo->blockSignals(false);
}
else{
start_request("/YSFHosts.txt");
}
}
void DudeStar::process_dmr_hosts()
{
if(!QDir(config_path).exists()){
QDir().mkdir(config_path);
}
QFileInfo check_file(config_path + "/DMRHosts.txt");
if(check_file.exists() && check_file.isFile()){
ui->hostCombo->blockSignals(true);
QFile f(config_path + "/DMRHosts.txt");
if(f.open(QIODevice::ReadOnly)){
ui->hostCombo->clear();
while(!f.atEnd()){
QString l = f.readLine();
if(l.at(0) == '#'){
continue;
}
QStringList ll = l.simplified().split(' ');
if(ll.size() > 4){
//qDebug() << ll.at(0).simplified() << " " << ll.at(2) + ":" + ll.at(4);
ui->hostCombo->addItem(ll.at(0).simplified(), ll.at(2) + ":" + ll.at(4) + ":" + ll.at(3));
}
}
}
f.close();
//qDebug() << "saved_dmrhost == " << saved_dmrhost;
int i = ui->hostCombo->findText(saved_dmrhost);
ui->hostCombo->setCurrentIndex(i);
ui->hostCombo->blockSignals(false);
}
else{
start_request("/DMRHosts.txt");
}
}
void DudeStar::process_p25_hosts()
{
if(!QDir(config_path).exists()){
QDir().mkdir(config_path);
}
QFileInfo check_file(config_path + "/P25Hosts.txt");
if(check_file.exists() && check_file.isFile()){
ui->hostCombo->blockSignals(true);
QFile f(config_path + "/P25Hosts.txt");
if(f.open(QIODevice::ReadOnly)){
ui->hostCombo->clear();
while(!f.atEnd()){
QString l = f.readLine();
if(l.at(0) == '#'){
continue;
}
QStringList ll = l.simplified().split(' ');
if(ll.size() > 2){
//qDebug() << ll.at(0).simplified() << " " << ll.at(2) + ":" + ll.at(4);
ui->hostCombo->addItem(ll.at(0).simplified(), ll.at(1) + ":" + ll.at(2));
}
}
}
f.close();
//qDebug() << "saved_p25Host == " << saved_p25host;
int i = ui->hostCombo->findText(saved_p25host);
ui->hostCombo->setCurrentIndex(i);
ui->hostCombo->blockSignals(false);
}
else{
start_request("/P25Hosts.txt");
}
}
void DudeStar::process_nxdn_hosts()
{
if(!QDir(config_path).exists()){
QDir().mkdir(config_path);
}
QFileInfo check_file(config_path + "/NXDNHosts.txt");
if(check_file.exists() && check_file.isFile()){
ui->hostCombo->blockSignals(true);
QFile f(config_path + "/NXDNHosts.txt");
if(f.open(QIODevice::ReadOnly)){
ui->hostCombo->clear();
while(!f.atEnd()){
QString l = f.readLine();
if(l.at(0) == '#'){
continue;
}
QStringList ll = l.simplified().split(' ');
if(ll.size() > 2){
//qDebug() << ll.at(0).simplified() << " " << ll.at(2) + ":" + ll.at(4);
ui->hostCombo->addItem(ll.at(0).simplified(), ll.at(1) + ":" + ll.at(2));
}
}
}
f.close();
int i = ui->hostCombo->findText(saved_nxdnhost);
ui->hostCombo->setCurrentIndex(i);
ui->hostCombo->blockSignals(false);
}
else{
start_request("/NXDNHosts.txt");
}
}
void DudeStar::delete_host_files()
{
QFileInfo check_file(config_path + "/dplus.txt");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/dplus.txt");
f.remove();
}
check_file.setFile(config_path + "/dextra.txt");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/dextra.txt");
f.remove();
}
check_file.setFile(config_path + "/dcs.txt");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/dcs.txt");
f.remove();
}
check_file.setFile(config_path + "/YSFHosts.txt");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/YSFHosts.txt");
f.remove();
}
check_file.setFile(config_path + "/DMRHosts.txt");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/DMRHosts.txt");
f.remove();
}
check_file.setFile(config_path + "/P25Hosts.txt");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/P25Hosts.txt");
f.remove();
}
check_file.setFile(config_path + "/NXDNHosts.txt");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/NXDNHosts.txt");
f.remove();
}
process_mode_change(ui->modeCombo->currentText().simplified());
}
void DudeStar::process_dmr_ids()
{
if(!QDir(config_path).exists()){
QDir().mkdir(config_path);
}
QFileInfo check_file(config_path + "/DMRIDs.dat");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/DMRIDs.dat");
if(f.open(QIODevice::ReadOnly)){
while(!f.atEnd()){
QString l = f.readLine();
if(l.at(0) == '#'){
continue;
}
QStringList ll = l.simplified().split(' ');
//qDebug() << ll.at(0).simplified() << " " << ll.at(2) + ":" + ll.at(4);
dmrids[ll.at(0).toUInt()] = ll.at(1);
}
}
f.close();
process_settings();
}
else{
start_request("/DMRIDs.dat");
}
}
void DudeStar::update_dmr_ids()
{
QFileInfo check_file(config_path + "/DMRIDs.dat");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/DMRIDs.dat");
f.remove();
}
process_dmr_ids();
}
void DudeStar::process_nxdn_ids()
{
if(!QDir(config_path).exists()){
QDir().mkdir(config_path);
}
QFileInfo check_file(config_path + "/NXDN.csv");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/NXDN.csv");
if(f.open(QIODevice::ReadOnly)){
while(!f.atEnd()){
QString l = f.readLine();
if(l.at(0) == '#'){
continue;
}
QStringList ll = l.simplified().split(',');
if(ll.size() > 1){
//qDebug() << ll.at(0).simplified() << " " << ll.at(1) + ":" + ll.at(2);
nxdnids[ll.at(0).toUInt()] = ll.at(1);
}
}
}
f.close();
}
else{
start_request("/NXDN.csv");
}
}
void DudeStar::update_nxdn_ids()
{
QFileInfo check_file(config_path + "/NXDN.csv");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/NXDN.csv");
f.remove();
}
process_dmr_ids();
}
void DudeStar::process_settings()
{
QFileInfo check_file(config_path + "/settings.conf");
if(check_file.exists() && check_file.isFile()){
QFile f(config_path + "/settings.conf");
if(f.open(QIODevice::ReadOnly)){
while(!f.atEnd()){
QString s = f.readLine();
QStringList sl = s.split(':');
if(sl.at(0) == "MODE"){
ui->modeCombo->blockSignals(true);
int i = ui->modeCombo->findText(sl.at(1).simplified());
ui->modeCombo->setCurrentIndex(i);
process_mode_change(sl.at(1).simplified());
if(i == 0){
process_ref_hosts();
}
else if(i == 1){
process_dcs_hosts();
}
else if(i == 2){
process_xrf_hosts();
}
else if(i == 3){
process_ysf_hosts();
}
else if(i == 4){
process_dmr_hosts();
}
else if(i == 5){
process_p25_hosts();
}
else if(i == 6){
process_nxdn_hosts();
}
}
ui->modeCombo->blockSignals(false);
ui->hostCombo->blockSignals(true);
if(sl.at(0) == "REFHOST"){
saved_refhost = sl.at(1).simplified();
if(ui->modeCombo->currentText().simplified() == "REF"){
int i = ui->hostCombo->findText(saved_refhost);
ui->hostCombo->setCurrentIndex(i);
}
}
if(sl.at(0) == "DCSHOST"){
saved_dcshost = sl.at(1).simplified();
if(ui->modeCombo->currentText().simplified() == "DCS"){
int i = ui->hostCombo->findText(saved_dcshost);
ui->hostCombo->setCurrentIndex(i);
}
}
if(sl.at(0) == "XRFHOST"){
saved_xrfhost = sl.at(1).simplified();
if(ui->modeCombo->currentText().simplified() == "XRF"){
int i = ui->hostCombo->findText(saved_xrfhost);
ui->hostCombo->setCurrentIndex(i);
}
}
if(sl.at(0) == "YSFHOST"){
saved_ysfhost = sl.at(1).simplified();
if(ui->modeCombo->currentText().simplified() == "YSF"){
int i = ui->hostCombo->findText(saved_ysfhost);
ui->hostCombo->setCurrentIndex(i);
}
}
if(sl.at(0) == "DMRHOST"){
saved_dmrhost = sl.at(1).simplified();
if(ui->modeCombo->currentText().simplified() == "DMR"){
int i = ui->hostCombo->findText(saved_dmrhost);
ui->hostCombo->setCurrentIndex(i);
}
}
if(sl.at(0) == "P25HOST"){
saved_p25host = sl.at(1).simplified();
if(ui->modeCombo->currentText().simplified() == "P25"){
int i = ui->hostCombo->findText(saved_p25host);
ui->hostCombo->setCurrentIndex(i);
}
}
if(sl.at(0) == "NXDNHOST"){
saved_nxdnhost = sl.at(1).simplified();
if(ui->modeCombo->currentText().simplified() == "NXDN"){
int i = ui->hostCombo->findText(saved_nxdnhost);
ui->hostCombo->setCurrentIndex(i);
}
}
if(sl.at(0) == "MODULE"){
ui->comboMod->setCurrentText(sl.at(1).simplified());
}
if(sl.at(0) == "CALLSIGN"){
ui->callsignEdit->setText(sl.at(1).simplified());
}
if(sl.at(0) == "DMRTGID"){
ui->dmrtgEdit->setText(sl.at(1).simplified());
}
if(sl.at(0) == "MYCALL"){
ui->mycallEdit->setText(sl.at(1).simplified());
}
if(sl.at(0) == "URCALL"){
ui->urcallEdit->setText(sl.at(1).simplified());
}
if(sl.at(0) == "RPTR1"){
ui->rptr1Edit->setText(sl.at(1).simplified());
}
if(sl.at(0) == "RPTR2"){
ui->rptr2Edit->setText(sl.at(1).simplified());
}
if(sl.at(0) == "USRTXT"){
ui->usertxtEdit->setText(sl.at(1).simplified());
}
if(sl.at(0) == "SWTX"){
if(sl.at(1).simplified() == "enabled"){
enable_swtx = true;
ui->checkBoxSWTX->show();
}
}
ui->hostCombo->blockSignals(false);
}
}
}
else{ //No settings.conf file, first time launch