-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTCITransceiver.cpp
2018 lines (1927 loc) · 90 KB
/
TCITransceiver.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 "TCITransceiver.hpp"
#include <QRegularExpression>
#include <QLocale>
#include <QThread>
#include <qmath.h>
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#include <QRandomGenerator>
#endif
#include "commons.h"
#include "NetworkServerLookup.hpp"
#include "moc_TCITransceiver.cpp"
namespace
{
char const * const TCI_transceiver_1_name {"TCI Client RX1"};
char const * const TCI_transceiver_2_name {"TCI Client RX2"};
QString map_mode (Transceiver::MODE mode)
{
switch (mode)
{
case Transceiver::AM: return "am";
case Transceiver::CW: return "cw";
// case Transceiver::CW_R: return "CW-R";
case Transceiver::USB: return "usb";
case Transceiver::LSB: return "lsb";
// case Transceiver::FSK: return "RTTY";
// case Transceiver::FSK_R: return "RTTY-R";
case Transceiver::DIG_L: return "digl";
case Transceiver::DIG_U: return "digu";
case Transceiver::FM: return "wfm";
case Transceiver::DIG_FM:
return "nfm";
default: break;
}
return "";
}
static const QString SmTZ(";");
static const QString SmDP(":");
static const QString SmCM(",");
static const QString SmTrue("true");
static const QString SmFalse("false");
// Command maps
static const QString CmdDevice("device");
static const QString CmdReceiveOnly("receive_only");
static const QString CmdTrxCount("trx_count");
static const QString CmdChannelCount("channels_count");
static const QString CmdVfoLimits("vfo_limits");
static const QString CmdIfLimits("if_limits");
static const QString CmdModeList("modulations_list");
static const QString CmdMode("modulation");
static const QString CmdReady("ready");
static const QString CmdStop("stop");
static const QString CmdStart("start");
static const QString CmdPreamp("preamp");
static const QString CmdDds("dds");
static const QString CmdIf("if");
static const QString CmdTrx("trx");
static const QString CmdRxEnable("rx_enable");
static const QString CmdTxEnable("tx_enable");
static const QString CmdRxChannelEnable("rx_channel_enable");
static const QString CmdRitEnable("rit_enable");
static const QString CmdRitOffset("rit_offset");
static const QString CmdXitEnable("xit_enable");
static const QString CmdXitOffset("xit_offset");
static const QString CmdSplitEnable("split_enable");
static const QString CmdIqSR("iq_samplerate");
static const QString CmdIqStart("iq_start");
static const QString CmdIqStop("iq_stop");
static const QString CmdCWSpeed("cw_macros_speed");
static const QString CmdCWDelay("cw_macros_delay");
static const QString CmdSpot("spot");
static const QString CmdSpotDelete("spot_delete");
static const QString CmdFilterBand("rx_filter_band");
static const QString CmdVFO("vfo");
static const QString CmdVersion("protocol"); //protocol:esdr,1.2;
static const QString CmdTune("tune");
static const QString CmdRxMute("rx_mute");
static const QString CmdSmeter("rx_smeter");
static const QString CmdPower("tx_power");
static const QString CmdSWR("tx_swr");
static const QString CmdECoderRX("ecoder_switch_rx");
static const QString CmdECoderVFO("ecoder_switch_channel");
static const QString CmdAudioSR("audio_samplerate");
static const QString CmdAudioStart("audio_start");
static const QString CmdAudioStop("audio_stop");
static const QString CmdAppFocus("app_focus");
static const QString CmdVolume("volume");
static const QString CmdSqlEnable("sql_enable");
static const QString CmdSqlLevel("sql_level");
static const QString CmdDrive("drive");
static const QString CmdTuneDrive("tune_drive");
static const QString CmdMute("mute");
static const QString CmdRxSensorsEnable("rx_sensors_enable");
static const QString CmdTxSensorsEnable("tx_sensors_enable");
static const QString CmdRxSensors("rx_sensors");
static const QString CmdTxSensors("tx_sensors");
static const QString CmdAgcMode("agc_mode");
static const QString CmdAgcGain("agc_gain");
static const QString CmdLock("lock");
}
extern "C" {
void fil4_(qint16*, qint32*, qint16*, qint32*, float*);
}
extern dec_data dec_data;
extern float gran(); // Noise generator (for tests only)
#define RAMP_INCREMENT 64 // MUST be an integral factor of 2^16
#if defined (WSJT_SOFT_KEYING)
# define SOFT_KEYING WSJT_SOFT_KEYING
#else
# define SOFT_KEYING 1
#endif
double constexpr TCITransceiver::m_twoPi;
void TCITransceiver::register_transceivers (TransceiverFactory::Transceivers * registry, unsigned id1, unsigned id2)
{
(*registry)[TCI_transceiver_1_name] = TransceiverFactory::Capabilities {id1, TransceiverFactory::Capabilities::tci, true};
(*registry)[TCI_transceiver_2_name] = TransceiverFactory::Capabilities {id2, TransceiverFactory::Capabilities::tci, true};
}
static constexpr quint32 AudioHeaderSize = 16u*sizeof(quint32);
TCITransceiver::TCITransceiver (std::unique_ptr<TransceiverBase> wrapped,QString const& rignr,
QString const& address, bool use_for_ptt,
int poll_interval, QObject * parent)
: PollingTransceiver {poll_interval, parent}
, wrapped_ {std::move (wrapped)}
, rx_ {rignr}
, server_ {address}
, use_for_ptt_ {use_for_ptt}
, errortable {tr("ConnectionRefused"),
tr("RemoteHostClosed"),
tr("HostNotFound"),
tr("SocketAccess"),
tr("SocketResource"),
tr("SocketTimeout"),
tr("DatagramTooLarge"),
tr("Network"),
tr("AddressInUse"),
tr("SocketAddressNotAvailable"),
tr("UnsupportedSocketOperation"),
tr("UnfinishedSocketOperation"),
tr("ProxyAuthenticationRequired"),
tr("SslHandshakeFailed"),
tr("ProxyConnectionRefused"),
tr("ProxyConnectionClosed"),
tr("ProxyConnectionTimeout"),
tr("ProxyNotFound"),
tr("ProxyProtocol"),
tr("Operation"),
tr("SslInternal"),
tr("SslInvalidUserData"),
tr("Temporary"),
tr("UnknownSocket") }
, error_ {""}
, do_snr_ {(poll_interval & do__snr) == do__snr}
, do_pwr_ {(poll_interval & do__pwr) == do__pwr}
, rig_power_ {(poll_interval & rig__power) == rig__power}
, rig_power_off_ {(poll_interval & rig__power_off) == rig__power_off}
, tci_audio_ {(poll_interval & tci__audio) == tci__audio}
, commander_ {nullptr}
, tci_timer1_ {nullptr}
, tci_loop1_ {nullptr}
, tci_timer2_ {nullptr}
, tci_loop2_ {nullptr}
, tci_timer3_ {nullptr}
, tci_loop3_ {nullptr}
, wavptr_ {nullptr}
, m_jtdxtime {nullptr}
, m_downSampleFactor {4}
, m_buffer ((m_downSampleFactor > 1) ?
new short [max_buffer_size * m_downSampleFactor] : nullptr)
, m_quickClose {false}
, m_phi {0.0}
, m_toneSpacing {0.0}
, m_fSpread {0.0}
, m_state {Idle}
, m_tuning {false}
, m_cwLevel {false}
, m_j0 {-1}
, m_toneFrequency0 {1500.0}
, debug_file_ {QDir(QStandardPaths::writableLocation (QStandardPaths::DataLocation)).absoluteFilePath ("jtdx_debug.txt").toStdString()}
, wav_file_ {QDir(QStandardPaths::writableLocation (QStandardPaths::DataLocation)).absoluteFilePath ("tx.wav").toStdString()}
{
m_samplesPerFFT = 6912 / 2;
tci_Ready = false;
trxA = 0;
trxB = 0;
cntIQ = 0;
bIQ = false;
inConnected = false;
audioSampleRate = 48000u;
mapCmd_[CmdDevice] = Cmd_Device;
mapCmd_[CmdReceiveOnly] = Cmd_ReceiveOnly;
mapCmd_[CmdTrxCount] = Cmd_TrxCount;
mapCmd_[CmdChannelCount] = Cmd_ChannelCount;
mapCmd_[CmdVfoLimits] = Cmd_VfoLimits;
mapCmd_[CmdIfLimits] = Cmd_IfLimits;
mapCmd_[CmdModeList] = Cmd_ModeList;
mapCmd_[CmdMode] = Cmd_Mode;
mapCmd_[CmdReady] = Cmd_Ready;
mapCmd_[CmdStop] = Cmd_Stop;
mapCmd_[CmdStart] = Cmd_Start;
mapCmd_[CmdPreamp] = Cmd_Preamp;
mapCmd_[CmdDds] = Cmd_Dds;
mapCmd_[CmdIf] = Cmd_If;
mapCmd_[CmdTrx] = Cmd_Trx;
mapCmd_[CmdRxEnable] = Cmd_RxEnable;
mapCmd_[CmdTxEnable] = Cmd_TxEnable;
mapCmd_[CmdRxChannelEnable] = Cmd_RxChannelEnable;
mapCmd_[CmdRitEnable] = Cmd_RitEnable;
mapCmd_[CmdRitOffset] = Cmd_RitOffset;
mapCmd_[CmdXitEnable] = Cmd_XitEnable;
mapCmd_[CmdXitOffset] = Cmd_XitOffset;
mapCmd_[CmdSplitEnable] = Cmd_SplitEnable;
mapCmd_[CmdIqSR] = Cmd_IqSR;
mapCmd_[CmdIqStart] = Cmd_IqStart;
mapCmd_[CmdIqStop] = Cmd_IqStop;
mapCmd_[CmdCWSpeed] = Cmd_CWSpeed;
mapCmd_[CmdCWDelay] = Cmd_CWDelay;
mapCmd_[CmdFilterBand] = Cmd_FilterBand;
mapCmd_[CmdVFO] = Cmd_VFO;
mapCmd_[CmdVersion] = Cmd_Version;
mapCmd_[CmdTune] = Cmd_Tune;
mapCmd_[CmdRxMute] = Cmd_RxMute;
mapCmd_[CmdSmeter] = Cmd_Smeter;
mapCmd_[CmdPower] = Cmd_Power;
mapCmd_[CmdSWR] = Cmd_SWR;
mapCmd_[CmdECoderRX] = Cmd_ECoderRX;
mapCmd_[CmdECoderVFO] = Cmd_ECoderVFO;
mapCmd_[CmdAudioSR] = Cmd_AudioSR;
mapCmd_[CmdAudioStart] = Cmd_AudioStart;
mapCmd_[CmdAudioStop] = Cmd_AudioStop;
mapCmd_[CmdAppFocus] = Cmd_AppFocus;
mapCmd_[CmdVolume] = Cmd_Volume;
mapCmd_[CmdSqlEnable] = Cmd_SqlEnable;
mapCmd_[CmdSqlLevel] = Cmd_SqlLevel;
mapCmd_[CmdDrive] = Cmd_Drive;
mapCmd_[CmdTuneDrive] = Cmd_TuneDrive;
mapCmd_[CmdMute] = Cmd_Mute;
mapCmd_[CmdRxSensorsEnable] = Cmd_RxSensorsEnable;
mapCmd_[CmdTxSensorsEnable] = Cmd_TxSensorsEnable;
mapCmd_[CmdRxSensors] = Cmd_RxSensors;
mapCmd_[CmdTxSensors] = Cmd_TxSensors;
mapCmd_[CmdAgcMode] = Cmd_AgcMode;
mapCmd_[CmdAgcGain] = Cmd_AgcGain;
mapCmd_[CmdLock] = Cmd_Lock;
}
void TCITransceiver::onConnected()
{
inConnected = true;
// printf("%s(%0.1f) TCI connected\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset());
#if JTDX_DEBUG_TO_FILE
FILE * pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) TCI connected\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset());
fclose (pFile);
#endif
}
void TCITransceiver::onDisconnected()
{
inConnected = false;
// printf("%s(%0.1f) TCI disconnected\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset());
#if JTDX_DEBUG_TO_FILE
FILE * pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) TCI disconnected\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset());
fclose (pFile);
#endif
}
void TCITransceiver::onError(QAbstractSocket::SocketError err)
{
//qDebug() << "WebInThread::onError";
// printf("%s(%0.1f) TCI error:%d\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),err);
#if JTDX_DEBUG_TO_FILE
FILE * pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) TCI error:%d\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),err);
fclose (pFile);
#endif
error_ = tr ("TCI websocket error: %1").arg (errortable.at (err));
}
int TCITransceiver::do_start (JTDXDateTime * jtdxtime)
{
if (tci_audio_) QThread::currentThread()->setPriority(QThread::HighPriority);
// printf("do_start tci_Ready:%d\n",tci_Ready);
#if JTDX_DEBUG_TO_FILE
FILE * pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"do_start tci_Ready:%d\n",tci_Ready);
fclose (pFile);
#endif
TRACE_CAT ("TCITransceiver", "starting");
m_jtdxtime = jtdxtime;
if (wrapped_) wrapped_->start (0,m_jtdxtime);
url_.setUrl("ws://" + server_); //server_
if (url_.host() == "") url_.setHost("localhost");
if (url_.port() == -1) url_.setPort(40001);
if (!commander_)
{
commander_ = new QWebSocket {}; // QObject takes ownership
// printf ("commander created");
#if JTDX_DEBUG_TO_FILE
FILE * pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"commander created");
fclose (pFile);
#endif
connect(commander_,SIGNAL(connected()),this,SLOT(onConnected()));
connect(commander_,SIGNAL(disconnected()),this,SLOT(onDisconnected()));
connect(commander_,SIGNAL(binaryMessageReceived(QByteArray)),this,SLOT(onBinaryReceived(QByteArray)));
connect(commander_,SIGNAL(textMessageReceived(QString)),this,SLOT(onMessageReceived(QString)));
connect(commander_,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(onError(QAbstractSocket::SocketError)));
}
if (!tci_loop1_) {
tci_loop1_ = new QEventLoop {this};
}
if (!tci_timer1_) {
tci_timer1_ = new QTimer {this};
tci_timer1_ -> setSingleShot(true);
connect( tci_timer1_, &QTimer::timeout, tci_loop1_, &QEventLoop::quit);
connect( this, &TCITransceiver::tci_done1, tci_loop1_, &QEventLoop::quit);
}
if (!tci_loop2_) {
tci_loop2_ = new QEventLoop {this};
}
if (!tci_timer2_) {
tci_timer2_ = new QTimer {this};
tci_timer2_ -> setSingleShot(true);
connect( tci_timer2_, &QTimer::timeout, tci_loop2_, &QEventLoop::quit);
connect( this, &TCITransceiver::tci_done2, tci_loop2_, &QEventLoop::quit);
}
if (!tci_loop3_) {
tci_loop3_ = new QEventLoop {this};
}
if (!tci_timer3_) {
tci_timer3_ = new QTimer {this};
tci_timer3_ -> setSingleShot(true);
connect( tci_timer3_, &QTimer::timeout, tci_loop3_, &QEventLoop::quit);
connect( this, &TCITransceiver::tci_done3, tci_loop3_, &QEventLoop::quit);
}
tx_fifo = 0; tx_top_ = true;
tci_Ready = false;
ESDR3 = false;
HPSDR = false;
band_change = false;
trxA = 0;
trxB = 0;
busy_rx_frequency_ = false;
busy_mode_ = false;
busy_other_frequency_ = false;
busy_split_ = false;
busy_drive_ = false;
busy_PTT_ = false;
busy_rx2_ = false;
rx2_ = false;
requested_rx2_ = false;
started_rx2_ = false;
split_ = false;
requested_split_ = false;
started_split_ = false;
PTT_ = false;
requested_PTT_ = false;
mode_ = "";
requested_mode_ = "";
started_mode_ = "";
requested_rx_frequency_ = "";
rx_frequency_ = "";
requested_other_frequency_ = "";
other_frequency_ = "";
requested_drive_ = "";
drive_ = "";
level_ = -54;
power_ = 0;
swr_ = 0;
m_bufferPos = 0;
m_downSampleFactor =4;
m_ns = 999;
audio_ = false;
requested_stream_audio_ = false;
stream_audio_ = false;
_power_ = false;
// printf ("%s(%0.1f) TCI open %s rig_power:%d rig_power_off:%d tci_audio:%d do_snr:%d do_pwr:%d\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),url_.toString().toStdString().c_str(),rig_power_,rig_power_off_,tci_audio_,do_snr_,do_pwr_);
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) TCI open %s rig_power:%d rig_power_off:%d tci_audio:%d do_snr:%d do_pwr:%d\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),url_.toString().toStdString().c_str(),rig_power_,rig_power_off_,tci_audio_,do_snr_,do_pwr_);
fclose (pFile);
#endif
commander_->open (url_);
mysleep1 (1500);
// if (ESDR3) mysleep1 (500); else mysleep1 (100);
mysleep1 (210);
if (HPSDR) {
busy_split_ = true;
const QString cmd = CmdSplitEnable + SmDP + rx_ + SmTZ;
sendTextMessage(cmd);
mysleep2(500);
busy_split_ = false;
}
if (error_.isEmpty()) {
tci_Ready = true;
if (!_power_) {
if (rig_power_) {
rig_power(true);
mysleep1(1000);
if(!_power_) throw error {tr ("TCI SDR could not be switched on")};
} else {
tci_Ready = false;
throw error {tr ("TCI SDR is not switched on")};
}
}
if (rx_ == "1" && !rx2_) {
rx2_enable (true);
if (!rx2_) {
tci_Ready = false;
throw error {tr ("TCI RX2 could not be enabled")};
}
}
if (tci_audio_) {
stream_audio (true);
mysleep1(500);
if (!stream_audio_) {
tci_Ready = false;
throw error {tr ("TCI Audio could not be switched on")};
}
}
if (ESDR3) {
const QString cmd = CmdRxSensorsEnable + SmDP + (do_snr_ ? "true" : "false") + SmCM + "500" + SmTZ;
sendTextMessage(cmd);
} else if (do_snr_) {
const QString cmd = CmdSmeter + SmDP + rx_ + SmCM + "0" + SmTZ;
sendTextMessage(cmd);
}
if (!requested_rx_frequency_.isEmpty()) do_frequency(string_to_frequency (requested_rx_frequency_),get_mode(true),false);
if (!requested_other_frequency_.isEmpty()) do_tx_frequency(string_to_frequency (requested_other_frequency_),get_mode(true),false);
else if (requested_split_ != split_) {/*printf("splt from start %d\n",requested_split_);*/ rig_split();} // split_ = requested_split_; mysleep2(100);}
if (!requested_drive_.isEmpty() && requested_drive_ != drive_) {
busy_drive_ = true;
if (ESDR3) {
const QString cmd = CmdDrive + SmDP + rx_ + SmCM + requested_drive_ + SmTZ;
sendTextMessage(cmd);
} else {
const QString cmd = CmdDrive + SmDP + requested_drive_ + SmTZ;
sendTextMessage(cmd);
}
}
do_poll ();
if (ESDR3) {
const QString cmd = CmdTxSensorsEnable + SmDP + (do_pwr_ ? "true" : "false") + SmCM + "500" + SmTZ;
sendTextMessage(cmd);
}
if (stream_audio_) do_audio(true);
TRACE_CAT ("TCITransceiver", "started");
// printf("%s(%0.1f) TCI Transceiver started\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) TCI Transceiver started\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset());
fclose (pFile);
#endif
return 0;
} else {
// printf("%s(%0.1f) TCI Transceiver not started %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),error_.toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) TCI Transceiver not started %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),error_.toStdString().c_str());
fclose (pFile);
#endif
if (error_.isEmpty())
throw error {tr ("TCI could not be opened")};
else
throw error {error_};
}
}
void TCITransceiver::do_stop ()
{
// printf ("TCI close\n");
if (!commander_) return;
#if JTDX_DEBUG_TO_FILE
FILE * pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"TCI close\n");
#endif
if (stream_audio_ && tci_Ready && inConnected && _power_) {
stream_audio (false);
mysleep1(500);
// printf ("TCI audio closed\n");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile,"TCI audio closed\n");
#endif
}
if (tci_Ready && inConnected && _power_) {
requested_other_frequency_ = "";
if (started_split_ != split_) {requested_split_ = started_split_; rig_split();}
if (started_mode_ != mode_) sendTextMessage(mode_to_command(started_mode_));
if (!started_rx2_ && rx2_) {
rx2_enable (false);
}
}
if (_power_ && rig_power_off_ && tci_Ready && inConnected && _power_) {
rig_power(false);
mysleep1(500);
// printf ("TCI power down\n");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile,"TCI power down\n");
#endif
}
tci_Ready = false;
if (commander_)
{
if (inConnected) commander_->close(QWebSocketProtocol::CloseCodeNormal,"end");
delete commander_, commander_ = nullptr;
// printf ("commander ");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile,"commander ");
#endif
}
if (tci_timer1_)
{
if (tci_timer1_->isActive()) tci_timer1_->stop();
delete tci_timer1_, tci_timer1_ = nullptr;
// printf ("timer1 ");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile,"timer1 ");
#endif
}
if (tci_loop1_)
{
tci_loop1_->quit();
delete tci_loop1_, tci_loop1_ = nullptr;
// printf ("loop1 ");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile,"loop1 ");
#endif
}
if (tci_timer2_)
{
if (tci_timer2_->isActive()) tci_timer2_->stop();
delete tci_timer2_, tci_timer2_ = nullptr;
// printf ("timer2 ");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile,"timer2 ");
#endif
}
if (tci_loop2_)
{
tci_loop2_->quit();
delete tci_loop2_, tci_loop2_ = nullptr;
// printf ("loop2 ");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile,"loop2 ");
#endif
}
if (tci_timer3_)
{
if (tci_timer3_->isActive()) tci_timer3_->stop();
delete tci_timer3_, tci_timer3_ = nullptr;
// printf ("timer3 ");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile,"timer3 ");
#endif
}
if (tci_loop3_)
{
tci_loop3_->quit();
delete tci_loop3_, tci_loop3_ = nullptr;
// printf ("loop3 ");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile,"loop3 ");
#endif
}
if (wrapped_) wrapped_->stop ();
TRACE_CAT ("TCITransceiver", "stopped");
// printf ("deleted\nTCI closed\n");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile,"deleted\nTCI closed\n");
fclose (pFile);
#endif
}
void TCITransceiver::onMessageReceived(const QString &str)
{
//qDebug() << "From WEB" << str;
QStringList cmd_list = str.split(";", SkipEmptyParts);
#if JTDX_DEBUG_TO_FILE
FILE * pFile;
#endif
for (QString cmds : cmd_list){
QStringList cmd = cmds.split(":", SkipEmptyParts);
QStringList args = cmd.last().split(",", SkipEmptyParts);
Tci_Cmd idCmd = mapCmd_[cmd.first()];
// if (idCmd != Cmd_Power && idCmd != Cmd_SWR && idCmd != Cmd_Smeter && idCmd != Cmd_AppFocus && idCmd != Cmd_RxSensors && idCmd != Cmd_TxSensors) { printf ("%s(%0.1f) TCI message received:|%s| ",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),str.toStdString().c_str()); printf("idCmd : %d args : %s\n",idCmd,args.join("|").toStdString().c_str());}
#if JTDX_DEBUG_TO_FILE
if (idCmd != Cmd_Power && idCmd != Cmd_SWR && idCmd != Cmd_Smeter && idCmd != Cmd_AppFocus && idCmd != Cmd_RxSensors && idCmd != Cmd_TxSensors) {
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) TCI message received:|%s| ",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),str.toStdString().c_str());
fprintf (pFile,"idCmd : %d args : %s\n",idCmd,args.join("|").toStdString().c_str());
fclose (pFile);
}
#endif
//qDebug() << cmds << idCmd;
if (idCmd <=0) continue;
switch (idCmd) {
case Cmd_Smeter:
if(args.at(0)==rx_ && args.at(1) == "0") level_ = args.at(2).toInt() + 73;
break;
case Cmd_RxSensors:
if(args.at(0)==rx_) level_ = args.at(1).split(".")[0].toInt() + 73;
// printf("Smeter=%d\n",level_);
break;
case Cmd_TxSensors:
if(args.at(0)==rx_) {
power_ = 10 * args.at(3).split(".")[0].toInt() + args.at(3).split(".")[1].toInt();
swr_ = 10 * args.at(4).split(".")[0].toInt() + args.at(4).split(".")[1].toInt();
// printf("Power=%d SWR=%d\n",power_,swr_);
}
break;
case Cmd_SWR:
// printf("%s(%0.1f) Cmd_SWR : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
swr_ = 10 * args.at(0).split(".")[0].toInt() + args.at(0).split(".")[1].toInt();
break;
case Cmd_Power:
power_ = 10 * args.at(0).split(".")[0].toInt() + args.at(0).split(".")[1].toInt();
// printf("%s(%0.1f) Cmd_Power : %s %d\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str(),power_);
break;
case Cmd_VFO:
// printf("%s(%0.1f) Cmd_VFO : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
// printf("band_change:%d busy_other_frequency_:%d timer1_remaining:%d timer2_remaining:%d",band_change,busy_other_frequency_,tci_timer1_->remainingTime(),tci_timer2_->remainingTime());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) Cmd_VFO : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fprintf (pFile,"band_change:%d busy_other_frequency_:%d timer1_remaining:%d timer2_remaining:%d",band_change,busy_other_frequency_,tci_timer1_->remainingTime(),tci_timer2_->remainingTime());
#endif
if(args.at(0)==rx_ && args.at(1) == "0") {
if (args.at(2).left(1) != "-") rx_frequency_ = args.at(2);
if (!tci_Ready && requested_rx_frequency_.isEmpty()) {requested_rx_frequency_ = rx_frequency_; }
if (busy_rx_frequency_ && !band_change) {
// printf (" cmdvfo0 done1");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile," cmdvfo0 done1");
#endif
tci_done1();
} else if (!tci_timer2_->isActive() && split_) {
// printf (" cmdvfo0 timer2 start 210");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile," cmdvfo0 timer2 start 210");
#endif
tci_timer2_->start(210);
}
}
else if (args.at(0)==rx_ && args.at(1) == "1") {
if (args.at(2).left(1) != "-") other_frequency_ = args.at(2);
// if (!tci_Ready && requested_other_frequency_.isEmpty()) requested_other_frequency_ = other_frequency_;
if (band_change && tci_timer1_->isActive()) {
// printf (" cmdvfo1 done1");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile," cmdvfo1 done1");
#endif
band_change = false;
tci_timer2_->start(210);
tci_done1();
} else if (busy_other_frequency_) {
// printf (" cmdvfo1 done2");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile," cmdvfo1 done2");
#endif
tci_done2();
} else if (tci_timer2_->isActive()) {
// printf (" cmdvfo1 timer2 reset 210");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile," cmdvfo1 timer2 reset 210");
#endif
tci_timer2_->start(210);
} else if (other_frequency_ != requested_other_frequency_ && tci_Ready && split_ && !tci_timer2_->isActive()) {
// printf (" cmdvfo1 timer2 start 210");
#if JTDX_DEBUG_TO_FILE
fprintf (pFile," cmdvfo1 timer2 start 210");
#endif
tci_timer2_->start(210);
}
}
// printf("->%d\n",tci_timer2_->remainingTime());
#if JTDX_DEBUG_TO_FILE
fprintf(pFile,"->%d\n",tci_timer2_->remainingTime());
fclose (pFile);
#endif
break;
case Cmd_Mode:
// printf("%s(%0.1f) Cmd_Mode : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) Cmd_Mode : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
if(args.at(0)==rx_) {
if (ESDR3 || HPSDR) {
if (args.at(1) == "0" ) mode_ = args.at(2).toLower(); else mode_ = args.at(1).toLower();
} else mode_ = args.at(1);
if (started_mode_.isEmpty()) started_mode_ = mode_;
if (busy_mode_) tci_done1();
else if (!requested_mode_.isEmpty() && requested_mode_ != mode_ && !band_change) {
sendTextMessage(mode_to_command(requested_mode_));
}
}
break;
case Cmd_SplitEnable:
// printf("%s(%0.1f) Cmd_SplitEnable : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) Cmd_SplitEnable : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
if(args.at(0)==rx_) {
if (args.at(1) == "false") split_ = false;
else if (args.at(1) == "true") split_ = true;
if (!tci_Ready) {started_split_ = split_;}
else if (busy_split_) tci_done2();
else if (requested_split_ != split_ && !tci_timer2_->isActive()) {
tci_timer2_->start(210);
rig_split();
}
}
break;
case Cmd_Drive:
// printf("%s(%0.1f) Cmd_Drive : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) Cmd_Drive : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
if((!ESDR3 && !HPSDR) || args.at(0)==rx_) {
if (ESDR3 || HPSDR) drive_ = args.at(1); else drive_ = args.at(0);
if (requested_drive_.isEmpty()) requested_drive_ = drive_;
busy_drive_ = false;
}
break;
case Cmd_Trx:
// printf("%s(%0.1f) Cmd_Trx : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) Cmd_Trx : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
if(args.at(0)==rx_) {
if (args.at(1) == "false") PTT_ = false;
else if (args.at(1) == "true") PTT_ = true;
if (tci_Ready && requested_PTT_ == PTT_) tci_done3();
else if (tci_Ready && !PTT_) {
requested_PTT_ = PTT_;
update_PTT(PTT_);
power_ = 0; if (do_pwr_) update_power (0);
swr_ = 0; if (do_pwr_) update_swr (0);
}
}
break;
case Cmd_AudioStart:
// printf("%s(%0.1f) Cmd_AudioStart : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) Cmd_AudioStart : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
if(args.at(0)==rx_) {
stream_audio_ = true;
if (tci_Ready) { //printf ("cmdaudiostart done1\n");
tci_done1();}
}
break;
case Cmd_RxEnable:
// printf("%s(%0.1f) Cmd_RxEnable : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) Cmd_RxEnable : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
if(args.at(0)=="1") {
if (args.at(1) == "false") rx2_ = false;
else if (args.at(1) == "true") rx2_ = true;
if(!tci_Ready) {requested_rx2_ = rx2_; started_rx2_ = rx2_;}
else if (tci_Ready && busy_rx2_ && requested_rx2_ == rx2_) tci_done1();
}
break;
case Cmd_AudioStop:
// printf("%s(%0.1f) CmdAudioStop : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) CmdAudioStop : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
if(args.at(0)==rx_) {
stream_audio_ = false;
if (tci_Ready) { //printf ("cmdaudiostop done1\n");
tci_done1();}
}
break;
case Cmd_Start:
// printf("%s(%0.1f) CmdStart : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) CmdStart : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
_power_ = true;
// printf ("cmdstart done1\n");
if (tci_Ready) tci_done1();
break;
case Cmd_Stop:
// printf("%s(%0.1f) CmdStop : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) CmdStop : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
if (tci_Ready && PTT_) {
PTT_ = false;
requested_PTT_ = PTT_;
update_PTT(PTT_);
power_ = 0; if (do_pwr_) update_power (0);
swr_ = 0; if (do_pwr_) update_swr (0);
m_state = Idle;
Q_EMIT tci_mod_active(m_state != Idle);
}
_power_ = false;
if (tci_timer1_->isActive()) { /*printf ("cmdstop done1\n");*/ tci_done1();}
else {
tci_Ready = false;
}
break;
case Cmd_Version:
// printf("%s(%0.1f) CmdVersion : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) CmdVersion : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
if(args.at(0)=="ExpertSDR3") ESDR3 = true;
else if (args.at(0)=="Thetis") HPSDR = true;
break;
case Cmd_Device:
// printf("%s(%0.1f) CmdDevice : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) CmdDevice : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
if((args.at(0)=="SunSDR2DX" || args.at(0)=="SunSDR2PRO") && !ESDR3) tx_top_ = false;
// printf ("tx_top_:%d\n",tx_top_);
break;
case Cmd_Ready:
// printf("%s(%0.1f) CmdReady : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
#if JTDX_DEBUG_TO_FILE
pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) CmdReady : %s\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),args.join("|").toStdString().c_str());
fclose (pFile);
#endif
tci_done1();
break;
default:
break;
}
}
}
void TCITransceiver::sendTextMessage(const QString &message)
{
if (inConnected) commander_->sendTextMessage(message);
}
void TCITransceiver::onBinaryReceived(const QByteArray &data)
{
/* if (++cntIQ % 50 == 0){
bIQ = !bIQ;
nIqBytes+=data.size();
printf("receiveIQ\n");
emit receiveIQ(bIQ,nIqBytes);
nIqBytes = 0;
} else {
nIqBytes+=data.size();
} */
Data_Stream *pStream = (Data_Stream*)(data.data());
if (pStream->type != last_type) {
// printf ("%s(%0.1f) binary received type=%d last_type=%d %d samplerate %d stream_size %d frame_size %d\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),pStream->type,last_type,data.size(),pStream->sampleRate,pStream->length,data.size());
#if JTDX_DEBUG_TO_FILE
FILE * pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"%s(%0.1f) binary received type=%d last_type=%d %d samplerate %d stream_size %d frame_size %d\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset(),pStream->type,last_type,data.size(),pStream->sampleRate,pStream->length,data.size());
fclose (pFile);
#endif
last_type = pStream->type;
#if JTDX_DEBUG_TO_FILE
if (last_type == TxChrono) { // audio transmit starts
struct {
char ariff[4]; //ChunkID: "RIFF"
int nchunk; //ChunkSize: 36+SubChunk2Size
char awave[4]; //Format: "WAVE"
char afmt[4]; //Subchunk1ID: "fmt "
int lenfmt; //Subchunk1Size: 16
short int nfmt2; //AudioFormat: 1
short int nchan2; //NumChannels: 1
int nsamrate; //SampleRate: 12000
int nbytesec; //ByteRate: SampleRate*NumChannels*BitsPerSample/8
short int nbytesam2; //BlockAlign: NumChannels*BitsPerSample/8
short int nbitsam2; //BitsPerSample: 16
char adata[4]; //Subchunk2ID: "data"
int ndata; //Subchunk2Size: numSamples*NumChannels*BitsPerSample/8
} hdr;
int npts=static_cast<int>(m_period) * 48000;
wavptr_ = fopen(wav_file_.c_str(),"wb");
if (wavptr_ != NULL) {
// Write a WAV header
hdr.ariff[0]='R';
hdr.ariff[1]='I';
hdr.ariff[2]='F';
hdr.ariff[3]='F';
hdr.nchunk=36 + 2*npts;
hdr.awave[0]='W';
hdr.awave[1]='A';
hdr.awave[2]='V';
hdr.awave[3]='E';
hdr.afmt[0]='f';
hdr.afmt[1]='m';
hdr.afmt[2]='t';
hdr.afmt[3]=' ';
hdr.lenfmt=16;
hdr.nfmt2=1;
hdr.nchan2=1;
hdr.nsamrate=48000;
hdr.nbytesec=2*48000;
hdr.nbytesam2=2;
hdr.nbitsam2=16;
hdr.adata[0]='d';
hdr.adata[1]='a';
hdr.adata[2]='t';
hdr.adata[3]='a';
hdr.ndata=2*npts;
fwrite(&hdr,sizeof(hdr),1,wavptr_);
}
}
else if (last_type == RxAudioStream) { // audio switched back to resceive
if (wavptr_ != NULL) {
fclose(wavptr_);
wavptr_ = nullptr;
}
}
#endif
}
if (pStream->type == Iq_Stream){
bool tx = false;
if (pStream->receiver == 0){
tx = trxA == 0;
trxA = 1;
}
if (pStream->receiver == 1) {
tx = trxB == 0;
trxB = 1;
}
// printf("sendIqData\n");
#if JTDX_DEBUG_TO_FILE
FILE * pFile = fopen (debug_file_.c_str(),"a");
fprintf (pFile,"sendIqData\n");
fclose (pFile);
#endif
emit sendIqData(pStream->receiver,pStream->length,pStream->data,tx);
qDebug() << "IQ" << data.size() << pStream->length;
} else if (pStream->type == RxAudioStream && audio_ && pStream->receiver == rx_.toUInt()){
// printf("%s(%0.1f) writeAudioData\n",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset());
writeAudioData(pStream->data,pStream->length);
qDebug() << "Audio" << data.size() << pStream->length;
} else if (pStream->type == TxChrono && pStream->receiver == rx_.toUInt()){
mtx_.lock(); tx_fifo += 1; tx_fifo &= 7;
int ssize = AudioHeaderSize+pStream->length*sizeof(float)*2;
// printf("%s(%0.1f) TxChrono ",m_jtdxtime->currentDateTimeUtc2().toString("hh:mm:ss.zzz").toStdString().c_str(),m_jtdxtime->GetOffset());
quint16 tehtud;
if (m_tx1[tx_fifo].size() != ssize) {m_tx1[tx_fifo].resize(ssize);/* m_tx1[tx_fifo].fill('\0x00');*/}
Data_Stream * pOStream1 = (Data_Stream*)(m_tx1[tx_fifo].data());
pOStream1->receiver = pStream->receiver;
pOStream1->sampleRate = pStream->sampleRate;
pOStream1->format = pStream->format;
pOStream1->codec = 0;
pOStream1->crc = 0;
pOStream1->length = pStream->length;
pOStream1->type = TxAudioStream;
// for (size_t i = 0; i < pStream->length; i++) pOStream1->data[i] = 0;