-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrigcommander.cpp
5733 lines (5134 loc) · 172 KB
/
rigcommander.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
#include "rigcommander.h"
#include <QDebug>
#include "rigidentities.h"
#include "logcategories.h"
#include "printhex.h"
// Copyright 2017-2020 Elliott H. Liggett
// This file parses data from the radio and also forms commands to the radio.
// The radio physical interface is handled by the commHandler() instance "comm"
//
// See here for a wonderful CI-V overview:
// http://www.plicht.de/ekki/civ/civ-p0a.html
//
// The IC-7300 "full" manual also contains a command reference.
// How to make spectrum display stop using rigctl:
// echo "w \0xFE\0xFE\0x94\0xE0\0x27\0x11\0x00\0xFD" | rigctl -m 3073 -r /dev/ttyUSB0 -s 115200 -vvvvv
// Note: When sending \x00, must use QByteArray.setRawData()
rigCommander::rigCommander(QObject* parent) : QObject(parent)
{
qInfo(logRig()) << "creating instance of rigCommander()";
state.set(SCOPEFUNC, true, false);
}
rigCommander::rigCommander(quint8 guid[GUIDLEN], QObject* parent) : QObject(parent)
{
qInfo(logRig()) << "creating instance of rigCommander()";
state.set(SCOPEFUNC, true, false);
memcpy(this->guid, guid, GUIDLEN);
}
rigCommander::~rigCommander()
{
qInfo(logRig()) << "closing instance of rigCommander()";
closeComm();
}
void rigCommander::commSetup(unsigned char rigCivAddr, QString rigSerialPort, quint32 rigBaudRate, QString vsp,quint16 tcpPort, quint8 wf)
{
// construct
// TODO: Bring this parameter and the comm port from the UI.
// Keep in hex in the UI as is done with other CIV apps.
// civAddr = 0x94; // address of the radio. Decimal is 148.
civAddr = rigCivAddr; // address of the radio. Decimal is 148.
usingNativeLAN = false;
//qInfo(logRig()) << "Opening connection to Rig:" << QString("0x%1").arg((unsigned char)rigCivAddr,0,16) << "on serial port" << rigSerialPort << "at baud rate" << rigBaudRate;
// ---
setup();
// ---
this->rigSerialPort = rigSerialPort;
this->rigBaudRate = rigBaudRate;
rigCaps.baudRate = rigBaudRate;
comm = new commHandler(rigSerialPort, rigBaudRate,wf,this);
ptty = new pttyHandler(vsp,this);
if (tcpPort > 0) {
tcp = new tcpServer(this);
tcp->startServer(tcpPort);
}
// data from the comm port to the program:
connect(comm, SIGNAL(haveDataFromPort(QByteArray)), this, SLOT(handleNewData(QByteArray)));
// data from the ptty to the rig:
connect(ptty, SIGNAL(haveDataFromPort(QByteArray)), comm, SLOT(receiveDataFromUserToRig(QByteArray)));
// data from the program to the comm port:
connect(this, SIGNAL(dataForComm(QByteArray)), comm, SLOT(receiveDataFromUserToRig(QByteArray)));
if (tcpPort > 0) {
// data from the tcp port to the rig:
connect(tcp, SIGNAL(receiveData(QByteArray)), comm, SLOT(receiveDataFromUserToRig(QByteArray)));
connect(comm, SIGNAL(haveDataFromPort(QByteArray)), tcp, SLOT(sendData(QByteArray)));
}
connect(this, SIGNAL(toggleRTS(bool)), comm, SLOT(setRTS(bool)));
// data from the rig to the ptty:
connect(comm, SIGNAL(haveDataFromPort(QByteArray)), ptty, SLOT(receiveDataFromRigToPtty(QByteArray)));
connect(comm, SIGNAL(havePortError(errorType)), this, SLOT(handlePortError(errorType)));
connect(ptty, SIGNAL(havePortError(errorType)), this, SLOT(handlePortError(errorType)));
connect(this, SIGNAL(getMoreDebug()), comm, SLOT(debugThis()));
connect(this, SIGNAL(getMoreDebug()), ptty, SLOT(debugThis()));
connect(this, SIGNAL(discoveredRigID(rigCapabilities)), ptty, SLOT(receiveFoundRigID(rigCapabilities)));
emit commReady();
sendState(); // Send current rig state to rigctld
}
void rigCommander::commSetup(unsigned char rigCivAddr, udpPreferences prefs, audioSetup rxSetup, audioSetup txSetup, QString vsp, quint16 tcpPort)
{
// construct
// TODO: Bring this parameter and the comm port from the UI.
// Keep in hex in the UI as is done with other CIV apps.
// civAddr = 0x94; // address of the radio. Decimal is 148.
civAddr = rigCivAddr; // address of the radio. Decimal is 148.
usingNativeLAN = true;
// --
setup();
// ---
if (udp == Q_NULLPTR) {
udp = new udpHandler(prefs,rxSetup,txSetup);
udpHandlerThread = new QThread(this);
udpHandlerThread->setObjectName("udpHandler()");
udp->moveToThread(udpHandlerThread);
connect(this, SIGNAL(initUdpHandler()), udp, SLOT(init()));
connect(udpHandlerThread, SIGNAL(finished()), udp, SLOT(deleteLater()));
udpHandlerThread->start();
emit initUdpHandler();
//this->rigSerialPort = rigSerialPort;
//this->rigBaudRate = rigBaudRate;
ptty = new pttyHandler(vsp,this);
if (tcpPort > 0) {
tcp = new tcpServer(this);
tcp->startServer(tcpPort);
}
// Data from UDP to the program
connect(udp, SIGNAL(haveDataFromPort(QByteArray)), this, SLOT(handleNewData(QByteArray)));
// data from the rig to the ptty:
connect(udp, SIGNAL(haveDataFromPort(QByteArray)), ptty, SLOT(receiveDataFromRigToPtty(QByteArray)));
// Audio from UDP
connect(udp, SIGNAL(haveAudioData(audioPacket)), this, SLOT(receiveAudioData(audioPacket)));
// data from the program to the rig:
connect(this, SIGNAL(dataForComm(QByteArray)), udp, SLOT(receiveDataFromUserToRig(QByteArray)));
// data from the ptty to the rig:
connect(ptty, SIGNAL(haveDataFromPort(QByteArray)), udp, SLOT(receiveDataFromUserToRig(QByteArray)));
if (tcpPort > 0) {
// data from the tcp port to the rig:
connect(tcp, SIGNAL(receiveData(QByteArray)), udp, SLOT(receiveDataFromUserToRig(QByteArray)));
connect(udp, SIGNAL(haveDataFromPort(QByteArray)), tcp, SLOT(sendData(QByteArray)));
}
connect(this, SIGNAL(haveChangeLatency(quint16)), udp, SLOT(changeLatency(quint16)));
connect(this, SIGNAL(haveSetVolume(unsigned char)), udp, SLOT(setVolume(unsigned char)));
connect(udp, SIGNAL(haveBaudRate(quint32)), this, SLOT(receiveBaudRate(quint32)));
// Connect for errors/alerts
connect(udp, SIGNAL(haveNetworkError(errorType)), this, SLOT(handlePortError(errorType)));
connect(udp, SIGNAL(haveNetworkStatus(networkStatus)), this, SLOT(handleStatusUpdate(networkStatus)));
connect(udp, SIGNAL(haveNetworkAudioLevels(networkAudioLevels)), this, SLOT(handleNetworkAudioLevels(networkAudioLevels)));
connect(ptty, SIGNAL(havePortError(errorType)), this, SLOT(handlePortError(errorType)));
connect(this, SIGNAL(getMoreDebug()), ptty, SLOT(debugThis()));
connect(this, SIGNAL(discoveredRigID(rigCapabilities)), ptty, SLOT(receiveFoundRigID(rigCapabilities)));
connect(udp, SIGNAL(requestRadioSelection(QList<radio_cap_packet>)), this, SLOT(radioSelection(QList<radio_cap_packet>)));
connect(udp, SIGNAL(setRadioUsage(quint8, quint8, QString, QString)), this, SLOT(radioUsage(quint8, quint8, QString, QString)));
connect(this, SIGNAL(selectedRadio(quint8)), udp, SLOT(setCurrentRadio(quint8)));
emit haveAfGain(rxSetup.localAFgain);
localVolume = rxSetup.localAFgain;
}
// data from the comm port to the program:
emit commReady();
sendState(); // Send current rig state to rigctld
pttAllowed = true; // This is for developing, set to false for "safe" debugging. Set to true for deployment.
}
void rigCommander::closeComm()
{
qDebug(logRig()) << "Closing rig comms";
if (comm != Q_NULLPTR) {
delete comm;
}
comm = Q_NULLPTR;
if (udpHandlerThread != Q_NULLPTR) {
udpHandlerThread->quit();
udpHandlerThread->wait();
}
udp = Q_NULLPTR;
if (ptty != Q_NULLPTR) {
delete ptty;
}
ptty = Q_NULLPTR;
}
void rigCommander::setup()
{
// common elements between the two constructors go here:
setCIVAddr(civAddr);
spectSeqMax = 0; // this is now set after rig ID determined
payloadSuffix = QByteArray("\xFD");
lookingForRig = false;
foundRig = false;
oldScopeMode = spectModeUnknown;
pttAllowed = true; // This is for developing, set to false for "safe" debugging. Set to true for deployment.
}
void rigCommander::process()
{
// new thread enters here. Do nothing but do check for errors.
if(comm!=Q_NULLPTR && comm->serialError)
{
emit havePortError(errorType(rigSerialPort, QString("Error from commhandler. Check serial port.")));
}
}
void rigCommander::handlePortError(errorType err)
{
qInfo(logRig()) << "Error using port " << err.device << " message: " << err.message;
emit havePortError(err);
}
void rigCommander::handleStatusUpdate(const networkStatus status)
{
emit haveStatusUpdate(status);
}
void rigCommander::handleNetworkAudioLevels(networkAudioLevels l)
{
emit haveNetworkAudioLevels(l);
}
bool rigCommander::usingLAN()
{
return usingNativeLAN;
}
void rigCommander::receiveBaudRate(quint32 baudrate) {
rigCaps.baudRate = baudrate;
emit haveBaudRate(baudrate);
}
void rigCommander::setRTSforPTT(bool enabled)
{
if(!usingNativeLAN)
{
useRTSforPTT_isSet = true;
useRTSforPTT_manual = enabled;
if(comm != NULL)
{
rigCaps.useRTSforPTT=enabled;
comm->setUseRTSforPTT(enabled);
}
}
}
void rigCommander::findRigs()
{
// This function sends data to 0x00 ("broadcast") to look for any connected rig.
lookingForRig = true;
foundRig = false;
QByteArray data;
QByteArray data2;
//data.setRawData("\xFE\xFE\xa2", 3);
data.setRawData("\xFE\xFE\x00", 3);
data.append((char)compCivAddr); // wfview's address, 0xE1
data2.setRawData("\x19\x00", 2); // get rig ID
data.append(data2);
data.append(payloadSuffix);
emit dataForComm(data);
// HACK for testing radios that do not respond to rig ID queries:
//this->model = model736;
//this->determineRigCaps();
return;
}
void rigCommander::prepDataAndSend(QByteArray data)
{
data.prepend(payloadPrefix);
//printHex(data, false, true);
data.append(payloadSuffix);
if(data[4] != '\x15')
{
// We don't print out requests for meter levels
qDebug(logRigTraffic()) << "Final payload in rig commander to be sent to rig: ";
//printHex(data);
//printHex(data, logRigTraffic());
printHexNow(data, logRigTraffic());
}
emit dataForComm(data);
}
void rigCommander::powerOn()
{
QByteArray payload;
int numFE=150;
switch (this->rigBaudRate) {
case 57600:
numFE = 75;
break;
case 38400:
numFE = 50;
break;
case 19200:
numFE = 25;
break;
case 9600:
numFE = 13;
break;
case 4800:
numFE = 7;
break;
}
for(int i=0; i < numFE; i++)
{
payload.append("\xFE");
}
payload.append(payloadPrefix); // FE FE 94 E1
payload.append("\x18\x01");
payload.append(payloadSuffix); // FD
qDebug(logRig()) << "Power ON command in rigcommander to be sent to rig: ";
printHex(payload);
emit dataForComm(payload);
}
void rigCommander::powerOff()
{
QByteArray payload;
payload.setRawData("\x18\x00", 2);
prepDataAndSend(payload);
}
void rigCommander::enableSpectOutput()
{
QByteArray payload("\x27\x11\x01");
prepDataAndSend(payload);
}
void rigCommander::disableSpectOutput()
{
QByteArray payload;
payload.setRawData("\x27\x11\x00", 3);
prepDataAndSend(payload);
}
void rigCommander::enableSpectrumDisplay()
{
// 27 10 01
QByteArray payload("\x27\x10\x01");
prepDataAndSend(payload);
}
void rigCommander::disableSpectrumDisplay()
{
// 27 10 00
QByteArray payload;
payload.setRawData("\x27\x10\x00", 3);
prepDataAndSend(payload);
}
void rigCommander::setSpectrumBounds(double startFreq, double endFreq, unsigned char edgeNumber)
{
if((edgeNumber > 4) || (!edgeNumber))
{
return;
}
unsigned char freqRange = 1; // 1 = VHF, 2 = UHF, 3 = L-Band
switch(rigCaps.model)
{
case model9700:
if(startFreq > 148)
{
freqRange++;
if(startFreq > 450)
{
freqRange++;
}
}
break;
case model705:
case model7300:
case model7610:
case model7850:
// Some rigs do not go past 60 MHz, but we will not encounter
// requests for those ranges since they are derived from the rig's existing scope range.
// start value of freqRange is 1.
if(startFreq > 1.6)
freqRange++;
if(startFreq > 2.0)
freqRange++;
if(startFreq > 6.0)
freqRange++;
if(startFreq > 8.0)
freqRange++;
if(startFreq > 11.0)
freqRange++;
if(startFreq > 15.0)
freqRange++;
if(startFreq > 20.0)
freqRange++;
if(startFreq > 22.0)
freqRange++;
if(startFreq > 26.0)
freqRange++;
if(startFreq > 30.0)
freqRange++;
if(startFreq > 45.0)
freqRange++;
if(startFreq > 60.0)
freqRange++;
if(startFreq > 74.8)
freqRange++;
if(startFreq > 108.0)
freqRange++;
if(startFreq > 137.0)
freqRange++;
if(startFreq > 400.0)
freqRange++;
break;
case modelR8600:
freqRange = 1;
edgeNumber = 1;
break;
default:
return;
break;
}
QByteArray lowerEdge = makeFreqPayload(startFreq);
QByteArray higherEdge = makeFreqPayload(endFreq);
QByteArray payload;
payload.setRawData("\x27\x1E", 2);
payload.append(freqRange);
payload.append(edgeNumber);
payload.append(lowerEdge);
payload.append(higherEdge);
prepDataAndSend(payload);
}
void rigCommander::getScopeMode()
{
// center or fixed
QByteArray payload;
payload.setRawData("\x27\x14\x00", 3);
prepDataAndSend(payload);
}
void rigCommander::getScopeEdge()
{
QByteArray payload;
payload.setRawData("\x27\x16", 2);
prepDataAndSend(payload);
}
void rigCommander::setScopeEdge(char edge)
{
// 1 2 or 3
// 27 16 00 0X
if((edge <1) || (edge >4))
return;
QByteArray payload;
payload.setRawData("\x27\x16\x00", 3);
payload.append(edge);
prepDataAndSend(payload);
}
void rigCommander::getScopeSpan()
{
getScopeSpan(false);
}
void rigCommander::getScopeSpan(bool isSub)
{
QByteArray payload;
payload.setRawData("\x27\x15", 2);
payload.append(static_cast<unsigned char>(isSub));
prepDataAndSend(payload);
}
void rigCommander::setScopeSpan(char span)
{
// See ICD, page 165, "19-12".
// 2.5k = 0
// 5k = 2, etc.
if((span <0 ) || (span >9))
return;
QByteArray payload;
double freq; // MHz
payload.setRawData("\x27\x15\x00", 3);
// next 6 bytes are the frequency
switch(span)
{
case 0:
// 2.5k
freq = 2.5E-3;
break;
case 1:
// 5k
freq = 5.0E-3;
break;
case 2:
freq = 10.0E-3;
break;
case 3:
freq = 25.0E-3;
break;
case 4:
freq = 50.0E-3;
break;
case 5:
freq = 100.0E-3;
break;
case 6:
freq = 250.0E-3;
break;
case 7:
freq = 500.0E-3;
break;
case 8:
freq = 1000.0E-3;
break;
case 9:
freq = 2500.0E-3;
break;
default:
return;
break;
}
payload.append( makeFreqPayload(freq));
payload.append("\x00");
// printHex(payload, false, true);
prepDataAndSend(payload);
}
void rigCommander::setSpectrumMode(spectrumMode spectMode)
{
QByteArray specModePayload;
specModePayload.setRawData("\x27\x14\x00", 3);
specModePayload.append( static_cast<unsigned char>(spectMode) );
prepDataAndSend(specModePayload);
}
void rigCommander::getSpectrumRefLevel()
{
QByteArray payload;
payload.setRawData("\x27\x19\x00", 3);
prepDataAndSend(payload);
}
void rigCommander::getSpectrumRefLevel(unsigned char mainSub)
{
QByteArray payload;
payload.setRawData("\x27\x19", 2);
payload.append(mainSub);
prepDataAndSend(payload);
}
void rigCommander::setSpectrumRefLevel(int level)
{
//qInfo(logRig()) << __func__ << ": Setting scope to level " << level;
QByteArray setting;
QByteArray number;
QByteArray pn;
setting.setRawData("\x27\x19\x00", 3);
if(level >= 0)
{
pn.setRawData("\x00", 1);
number = bcdEncodeInt(level*10);
} else {
pn.setRawData("\x01", 1);
number = bcdEncodeInt( (-level)*10 );
}
setting.append(number);
setting.append(pn);
//qInfo(logRig()) << __func__ << ": scope reference number: " << number << ", PN to: " << pn;
//printHex(setting, false, true);
prepDataAndSend(setting);
}
void rigCommander::getSpectrumCenterMode()
{
QByteArray specModePayload;
specModePayload.setRawData("\x27\x14", 2);
prepDataAndSend(specModePayload);
}
void rigCommander::getSpectrumMode()
{
QByteArray specModePayload;
specModePayload.setRawData("\x27\x14", 2);
prepDataAndSend(specModePayload);
}
void rigCommander::setFrequency(unsigned char vfo, freqt freq)
{
QByteArray freqPayload = makeFreqPayload(freq);
QByteArray cmdPayload;
cmdPayload.append(freqPayload);
if (vfo == 0) {
cmdPayload.prepend('\x00');
}
else
{
cmdPayload.prepend(vfo);
cmdPayload.prepend('\x25');
}
//printHex(cmdPayload, false, true);
prepDataAndSend(cmdPayload);
}
void rigCommander::selectVFO(vfo_t vfo)
{
// Note, some radios use main/sub,
// some use A/B,
// and some appear to use both...
QByteArray payload;
char vfoBytes[1];
vfoBytes[0] = (unsigned char)vfo;
payload.setRawData("\x07", 1);
payload.append(vfoBytes, 1);
prepDataAndSend(payload);
}
void rigCommander::equalizeVFOsAB()
{
QByteArray payload;
payload.setRawData("\x07\xA0", 2);
prepDataAndSend(payload);
}
void rigCommander::equalizeVFOsMS()
{
QByteArray payload;
payload.setRawData("\x07\xB1", 2);
prepDataAndSend(payload);
}
void rigCommander::exchangeVFOs()
{
// NB: This command exchanges A-B or M-S
// depending upon the radio.
QByteArray payload;
payload.setRawData("\x07\xB0", 2);
prepDataAndSend(payload);
}
QByteArray rigCommander::makeFreqPayload(freqt freq)
{
QByteArray result;
quint64 freqInt = freq.Hz;
unsigned char a;
int numchars = 5;
for (int i = 0; i < numchars; i++) {
a = 0;
a |= (freqInt) % 10;
freqInt /= 10;
a |= ((freqInt) % 10)<<4;
freqInt /= 10;
result.append(a);
//printHex(result, false, true);
}
return result;
}
QByteArray rigCommander::makeFreqPayload(double freq)
{
quint64 freqInt = (quint64) (freq * 1E6);
QByteArray result;
unsigned char a;
int numchars = 5;
for (int i = 0; i < numchars; i++) {
a = 0;
a |= (freqInt) % 10;
freqInt /= 10;
a |= ((freqInt) % 10)<<4;
freqInt /= 10;
result.append(a);
//printHex(result, false, true);
}
//qInfo(logRig()) << "encoded frequency for " << freq << " as int " << freqInt;
//printHex(result, false, true);
return result;
}
void rigCommander::setRitEnable(bool ritEnabled)
{
QByteArray payload;
if(ritEnabled)
{
payload.setRawData("\x21\x01\x01", 3);
} else {
payload.setRawData("\x21\x01\x00", 3);
}
prepDataAndSend(payload);
}
void rigCommander::getRitEnabled()
{
QByteArray payload;
payload.setRawData("\x21\x01", 2);
prepDataAndSend(payload);
}
void rigCommander::getRitValue()
{
QByteArray payload;
payload.setRawData("\x21\x00", 2);
prepDataAndSend(payload);
}
void rigCommander::setRitValue(int ritValue)
{
QByteArray payload;
QByteArray freqBytes;
freqt f;
bool isNegative = false;
payload.setRawData("\x21\x00", 2);
if(ritValue < 0)
{
isNegative = true;
ritValue *= -1;
}
if(ritValue > 9999)
return;
f.Hz = ritValue;
freqBytes = makeFreqPayload(f);
freqBytes.truncate(2);
payload.append(freqBytes);
payload.append(QByteArray(1,(char)isNegative));
prepDataAndSend(payload);
}
void rigCommander::setMode(mode_info m)
{
QByteArray payload;
if (rigCaps.model == model706)
{
m.filter = '\x01';
}
if (m.mk == modeWFM)
{
m.filter = '\x01';
}
if(m.VFO==inactiveVFO)
{
payload.setRawData("\x26\x01", 2);
} else {
payload.setRawData("\x06", 1);
}
payload.append(m.reg);
if(m.VFO==inactiveVFO)
payload.append("\x00", 1);
payload.append(m.filter);
prepDataAndSend(payload);
}
void rigCommander::setMode(unsigned char mode, unsigned char modeFilter)
{
QByteArray payload;
if(mode < 0x22 + 1)
{
// mode command | filter
// 0x01 | Filter 01 automatically
// 0x04 | user-specififed 01, 02, 03 | note, is "read the current mode" on older rigs
// 0x06 | "default" filter is auto
payload.setRawData("\x06", 1); // cmd 06 needs filter specified
//payload.setRawData("\x04", 1); // cmd 04 will apply the default filter, but it seems to always pick FIL 02
payload.append(mode);
if(rigCaps.model==model706)
{
payload.append("\x01"); // "normal" on IC-706
} else {
if(mode == 0x06)
{
payload.append(0x01);
} else {
payload.append(modeFilter);
}
}
prepDataAndSend(payload);
}
}
void rigCommander::setDataMode(bool dataOn, unsigned char filter)
{
QByteArray payload;
payload.setRawData("\x1A\x06", 2);
if(dataOn)
{
payload.append("\x01", 1); // data mode on
payload.append(filter);
} else {
payload.append("\x00\x00", 2); // data mode off, bandwidth not defined per ICD.
}
prepDataAndSend(payload);
}
void rigCommander::getFrequency(unsigned char vfo)
{
if (rigCaps.hasVFOAB || rigCaps.hasVFOMS)
{
QByteArray payload("\x25");
payload.append(vfo);
prepDataAndSend(payload);
} else {
getFrequency();
}
}
void rigCommander::getFrequency()
{
// figure out frequency and then respond with haveFrequency();
// send request to radio
// 1. make the data
QByteArray payload("\x03");
prepDataAndSend(payload);
}
void rigCommander::getMode()
{
QByteArray payload("\x04");
prepDataAndSend(payload);
}
void rigCommander::getDataMode()
{
QByteArray payload("\x1A\x06");
prepDataAndSend(payload);
}
void rigCommander::getSplit()
{
QByteArray payload("\x0F");
prepDataAndSend(payload);
}
void rigCommander::setSplit(bool splitEnabled)
{
QByteArray payload("\x0F");
payload.append((unsigned char)splitEnabled);
prepDataAndSend(payload);
}
void rigCommander::setDuplexMode(duplexMode dm)
{
QByteArray payload;
if(dm==dmDupAutoOff)
{
payload.setRawData("\x1A\x05\x00\x46\x00", 5);
} else if (dm==dmDupAutoOn)
{
payload.setRawData("\x1A\x05\x00\x46\x01", 5);
} else {
payload.setRawData("\x0F", 1);
payload.append((unsigned char) dm);
}
prepDataAndSend(payload);
}
void rigCommander::getDuplexMode()
{
QByteArray payload;
// Duplex mode:
payload.setRawData("\x0F", 1);
prepDataAndSend(payload);
// Auto Repeater Mode:
payload.setRawData("\x1A\x05\x00\x46", 4);
prepDataAndSend(payload);
}
void rigCommander::setQuickSplit(bool qsOn)
{
if(rigCaps.hasQuickSplitCommand)
{
QByteArray payload = rigCaps.quickSplitCommand;
payload.append((unsigned char)qsOn);
prepDataAndSend(payload);
}
}
void rigCommander::setPassband(quint16 pass)
{
QByteArray payload;
payload.setRawData("\x1A\x03", 2);
/*
* Passband is calculated as follows, if a higher than legal value is provided,
* It will set passband to the maximum allowed for the particular mode.
*
* Mode Data Steps
* SSB/CW/RTTY/PSK 0 to 9 50 ~ 500 Hz (50 Hz)
* SSB/CW/PSK 10 to 40 600 Hz ~ 3.6 kHz (100 Hz)
* RTTY 10 to 31 600 ~ 2.7 kHz (100 Hz)
* AM 0 to 49 200 Hz ~ 10.0 kHz (200 Hz)
*/
unsigned char calc;
if (state.getChar(MODE) == modeAM) { // AM 0-49
calc = quint16((pass / 200) - 1);
if (calc > 49)
calc = 49;
}
else if (pass >= 600) // SSB/CW/PSK 10-40 (10-31 for RTTY)
{
calc = quint16((pass / 100) + 4);
if (((calc > 31) && (state.getChar(MODE) == modeRTTY || state.getChar(MODE) == modeRTTY_R)))
{
calc = 31;
}
else if (calc > 40) {
calc = 40;
}
}
else { // SSB etc 0-9
calc = quint16((pass / 50) - 1);
}
char tens = (calc / 10);
char units = (calc - (10 * tens));