From 7b873740dc014c6fa64c680a859c0ac5be6aa1b2 Mon Sep 17 00:00:00 2001 From: jontio Date: Mon, 26 Jul 2021 22:47:15 +1200 Subject: [PATCH] added zmq_audiosender class and removed the code that was doing the same thing in mainwindow (untested). tidy --- JAERO/JAERO.pro | 10 +- JAERO/audioburstmskdemodulator.cpp | 13 +- JAERO/audioburstoqpskdemodulator.cpp | 13 +- JAERO/audiomskdemodulator.cpp | 13 +- JAERO/audiooqpskdemodulator.cpp | 13 +- JAERO/burstmskdemodulator.cpp | 210 +++++++++--------- JAERO/burstmskdemodulator.h | 1 - JAERO/burstoqpskdemodulator.cpp | 13 -- JAERO/burstoqpskdemodulator.h | 5 +- JAERO/jaero.qrc | 2 +- JAERO/mainwindow.cpp | 82 ++----- JAERO/mainwindow.h | 23 +- ...udioreceiver.cpp => zmq_audioreceiver.cpp} | 19 +- .../{audioreceiver.h => zmq_audioreceiver.h} | 23 +- JAERO/zmq_audiosender.cpp | 55 +++++ JAERO/zmq_audiosender.h | 24 ++ 16 files changed, 257 insertions(+), 262 deletions(-) rename JAERO/{audioreceiver.cpp => zmq_audioreceiver.cpp} (83%) rename JAERO/{audioreceiver.h => zmq_audioreceiver.h} (58%) create mode 100644 JAERO/zmq_audiosender.cpp create mode 100644 JAERO/zmq_audiosender.h diff --git a/JAERO/JAERO.pro b/JAERO/JAERO.pro index 4432b56..2364c64 100644 --- a/JAERO/JAERO.pro +++ b/JAERO/JAERO.pro @@ -85,8 +85,9 @@ SOURCES += mainwindow.cpp \ $$JFFT_PATH/jfft.cpp \ util/stdio_utils.cpp \ util/file_utils.cpp \ - util/RuntimeError.cpp\ - audioreceiver.cpp + util/RuntimeError.cpp \ + zmq_audiosender.cpp \ + zmq_audioreceiver.cpp HEADERS += mainwindow.h \ @@ -121,8 +122,9 @@ HEADERS += mainwindow.h \ $$JFFT_PATH/jfft.h \ util/stdio_utils.h \ util/file_utils.h \ - util/RuntimeError.h\ - audioreceiver.h + util/RuntimeError.h \ + zmq_audioreceiver.h \ + zmq_audiosender.h # Tell the qcustomplot header that it will be used as library: diff --git a/JAERO/audioburstmskdemodulator.cpp b/JAERO/audioburstmskdemodulator.cpp index eecd4a5..ce2189c 100644 --- a/JAERO/audioburstmskdemodulator.cpp +++ b/JAERO/audioburstmskdemodulator.cpp @@ -3,10 +3,10 @@ #include AudioBurstMskDemodulator::AudioBurstMskDemodulator(QObject *parent) -: BurstMskDemodulator(parent), - m_audioInput(NULL) + : BurstMskDemodulator(parent), + m_audioInput(NULL) { -// + // } void AudioBurstMskDemodulator::start() @@ -14,16 +14,15 @@ void AudioBurstMskDemodulator::start() BurstMskDemodulator::start(); if(!settings.zmqAudio) { - if(m_audioInput)m_audioInput->start(this); -} + if(m_audioInput)m_audioInput->start(this); + } } void AudioBurstMskDemodulator::stop() { if(!settings.zmqAudio) { - if(m_audioInput)m_audioInput->stop(); - + if(m_audioInput)m_audioInput->stop(); } BurstMskDemodulator::stop(); } diff --git a/JAERO/audioburstoqpskdemodulator.cpp b/JAERO/audioburstoqpskdemodulator.cpp index 11b1614..39246ae 100644 --- a/JAERO/audioburstoqpskdemodulator.cpp +++ b/JAERO/audioburstoqpskdemodulator.cpp @@ -2,8 +2,8 @@ #include AudioBurstOqpskDemodulator::AudioBurstOqpskDemodulator(QObject *parent) -: BurstOqpskDemodulator(parent), - m_audioInput(NULL) + : BurstOqpskDemodulator(parent), + m_audioInput(NULL) { demod2=new BurstOqpskDemodulator(this); demod2->channel_select_other=true; @@ -17,8 +17,8 @@ void AudioBurstOqpskDemodulator::start() demod2->start(); if(!settings.zmqAudio) { - if(m_audioInput)m_audioInput->start(this); -} + if(m_audioInput)m_audioInput->start(this); + } } void AudioBurstOqpskDemodulator::stop() @@ -26,8 +26,7 @@ void AudioBurstOqpskDemodulator::stop() if(m_audioInput)m_audioInput->stop(); if(!settings.zmqAudio) { - - BurstOqpskDemodulator::stop(); + BurstOqpskDemodulator::stop(); } demod2->stop(); } @@ -47,7 +46,7 @@ void AudioBurstOqpskDemodulator::setSettings(Settings _settings) //set the format m_format.setSampleRate(settings.Fs); if(settings.channel_stereo)m_format.setChannelCount(2); - else m_format.setChannelCount(1); + else m_format.setChannelCount(1); m_format.setSampleSize(16); m_format.setCodec("audio/pcm"); m_format.setByteOrder(QAudioFormat::LittleEndian); diff --git a/JAERO/audiomskdemodulator.cpp b/JAERO/audiomskdemodulator.cpp index 46bb98f..d368841 100644 --- a/JAERO/audiomskdemodulator.cpp +++ b/JAERO/audiomskdemodulator.cpp @@ -3,10 +3,10 @@ #include AudioMskDemodulator::AudioMskDemodulator(QObject *parent) -: MskDemodulator(parent), - m_audioInput(NULL) + : MskDemodulator(parent), + m_audioInput(NULL) { -// + // } void AudioMskDemodulator::start() @@ -14,16 +14,15 @@ void AudioMskDemodulator::start() MskDemodulator::start(); if(!settings.zmqAudio) { - if(m_audioInput)m_audioInput->start(this); -} + if(m_audioInput)m_audioInput->start(this); + } } void AudioMskDemodulator::stop() { if(!settings.zmqAudio) { - if(m_audioInput)m_audioInput->stop(); - + if(m_audioInput)m_audioInput->stop(); } MskDemodulator::stop(); } diff --git a/JAERO/audiooqpskdemodulator.cpp b/JAERO/audiooqpskdemodulator.cpp index eb06ef7..ee05bdb 100644 --- a/JAERO/audiooqpskdemodulator.cpp +++ b/JAERO/audiooqpskdemodulator.cpp @@ -3,10 +3,10 @@ #include AudioOqpskDemodulator::AudioOqpskDemodulator(QObject *parent) -: OqpskDemodulator(parent), - m_audioInput(NULL) + : OqpskDemodulator(parent), + m_audioInput(NULL) { -// + // } void AudioOqpskDemodulator::start() @@ -15,8 +15,8 @@ void AudioOqpskDemodulator::start() if(!settings.zmqAudio) { - if(m_audioInput)m_audioInput->start(this); -} + if(m_audioInput)m_audioInput->start(this); + } } @@ -24,8 +24,7 @@ void AudioOqpskDemodulator::stop() { if(!settings.zmqAudio) { - if(m_audioInput)m_audioInput->stop(); - + if(m_audioInput)m_audioInput->stop(); } OqpskDemodulator::stop(); } diff --git a/JAERO/burstmskdemodulator.cpp b/JAERO/burstmskdemodulator.cpp index 48841a8..26efcca 100644 --- a/JAERO/burstmskdemodulator.cpp +++ b/JAERO/burstmskdemodulator.cpp @@ -599,154 +599,154 @@ qint64 BurstMskDemodulator::writeData(const char *data, qint64 len) if(startstop > 0 || mse < signalthreshold) { - cval= mixer2.WTCISValue()*(val_to_demod)*vol_gain; + cval= mixer2.WTCISValue()*(val_to_demod)*vol_gain; - cpx_type sig2 = cpx_type(matchedfilter_re->FIRUpdateAndProcess(cval.real()),matchedfilter_im->FIRUpdateAndProcess(cval.imag())); + cpx_type sig2 = cpx_type(matchedfilter_re->FIRUpdateAndProcess(cval.real()),matchedfilter_im->FIRUpdateAndProcess(cval.imag())); - if(cntr>(startProcessing*SamplesPerSymbol) && cntr(startProcessing*SamplesPerSymbol) && cntrUpdate(std::abs(sig2)); + //Measure ebno + ebnomeasure->Update(std::abs(sig2)); - //send ebno when right time - if(cntr== endRotation + (200*SamplesPerSymbol)) - { - emit EbNoMeasurmentSignal(ebnomeasure->EbNo); - } + //send ebno when right time + if(cntr== endRotation + (200*SamplesPerSymbol)) + { + emit EbNoMeasurmentSignal(ebnomeasure->EbNo); + } - //AGC - sig2*=agc2->Update(std::abs(sig2)); + //AGC + sig2*=agc2->Update(std::abs(sig2)); - //clipping - double abval=std::abs(sig2); - if(abval>2.84)sig2=(2.84/abval)*sig2; + //clipping + double abval=std::abs(sig2); + if(abval>2.84)sig2=(2.84/abval)*sig2; - //normal symbol timer - cpx_type pt_d = delayedsmpl.update_dont_touch(sig2); - cpx_type pt_msk=cpx_type(sig2.real(), pt_d.imag()); + //normal symbol timer + cpx_type pt_d = delayedsmpl.update_dont_touch(sig2); + cpx_type pt_msk=cpx_type(sig2.real(), pt_d.imag()); - double st_eta = std::abs(pt_msk); - st_eta=st_iir_resonator.update(st_eta); + double st_eta = std::abs(pt_msk); + st_eta=st_iir_resonator.update(st_eta); - cpx_type st_m1=cpx_type(st_eta,-delayt8.update(st_eta)); - cpx_type st_out=st_osc.WTCISValue()*st_m1; + cpx_type st_m1=cpx_type(st_eta,-delayt8.update(st_eta)); + cpx_type st_out=st_osc.WTCISValue()*st_m1; - double st_angle_error=std::arg(st_out); - //acquire the symbol oscillation - if(cntr>endRotation) - { - st_osc.AdvanceFractionOfWave(-st_angle_error*0.002/360.0); - } + double st_angle_error=std::arg(st_out); + //acquire the symbol oscillation + if(cntr>endRotation) + { + st_osc.AdvanceFractionOfWave(-st_angle_error*0.002/360.0); + } - //sample times - if(st_osc.IfHavePassedPoint(ee)) - { + //sample times + if(st_osc.IfHavePassedPoint(ee)) + { - //carrier tracking - double ct_xt=tanh(sig2.imag())*sig2.real(); - double ct_xt_d=tanh(pt_d.real())*pt_d.imag(); + //carrier tracking + double ct_xt=tanh(sig2.imag())*sig2.real(); + double ct_xt_d=tanh(pt_d.real())*pt_d.imag(); - double ct_ec=ct_xt_d-ct_xt; - if(ct_ec>M_PI)ct_ec=M_PI; - if(ct_ec<-M_PI)ct_ec=-M_PI; - if(ct_ec>M_PI_2)ct_ec=M_PI_2; - if(ct_ec<-M_PI_2)ct_ec=-M_PI_2; - if(cntr>(startProcessing*SamplesPerSymbol)) - { - rotator=rotator*std::exp(imag*ct_ec*0.25);//correct carrier phase - if(cntr>endRotation) + double ct_ec=ct_xt_d-ct_xt; + if(ct_ec>M_PI)ct_ec=M_PI; + if(ct_ec<-M_PI)ct_ec=-M_PI; + if(ct_ec>M_PI_2)ct_ec=M_PI_2; + if(ct_ec<-M_PI_2)ct_ec=-M_PI_2; + if(cntr>(startProcessing*SamplesPerSymbol)) { - rotator_freq=rotator_freq+ct_ec*0.0001;//correct carrier frequency + rotator=rotator*std::exp(imag*ct_ec*0.25);//correct carrier phase + if(cntr>endRotation) + { + rotator_freq=rotator_freq+ct_ec*0.0001;//correct carrier frequency + } } - } - //gui feedback - if(cntr >= (endRotation + 100*SamplesPerSymbol) && pointbuff_ptr= (endRotation + 100*SamplesPerSymbol) && pointbuff_ptr(startProcessing*SamplesPerSymbol)) { - pointbuff_ptr++; - emit ScatterPoints(pointbuff); + double tda=(fabs((pt_msk*0.75).real())-1.0); + double tdb=(fabs((pt_msk*0.75).imag())-1.0); + mse=msema->Update((tda*tda)+(tdb*tdb)); } - } - //calc MSE of the points - if(cntr>(startProcessing*SamplesPerSymbol)) - { - double tda=(fabs((pt_msk*0.75).real())-1.0); - double tdb=(fabs((pt_msk*0.75).imag())-1.0); - mse=msema->Update((tda*tda)+(tdb*tdb)); - } + //soft bits + double imagin = diffdecode.UpdateSoft(pt_msk.imag()); - //soft bits - double imagin = diffdecode.UpdateSoft(pt_msk.imag()); + int ibit=qRound((imagin)*127.0+128.0); + if(ibit>255)ibit=255; + if(ibit<0)ibit=0; - int ibit=qRound((imagin)*127.0+128.0); - if(ibit>255)ibit=255; - if(ibit<0)ibit=0; + RxDataBits.push_back((uchar)ibit); - RxDataBits.push_back((uchar)ibit); + double real = diffdecode.UpdateSoft(pt_msk.real()); - double real = diffdecode.UpdateSoft(pt_msk.real()); + real =- real; - real =- real; + ibit=qRound((real)*127.0+128.0); - ibit=qRound((real)*127.0+128.0); + if(ibit>255)ibit=255; + if(ibit<0)ibit=0; - if(ibit>255)ibit=255; - if(ibit<0)ibit=0; + RxDataBits.push_back((uchar)ibit); - RxDataBits.push_back((uchar)ibit); + // push them out to decode + if(RxDataBits.size() >= 12) + { + emit processDemodulatedSoftBits(RxDataBits); + RxDataBits.clear(); + } - // push them out to decode - if(RxDataBits.size() >= 12) - { - emit processDemodulatedSoftBits(RxDataBits); - RxDataBits.clear(); } - } - - st_osc.WTnextFrame(); - st_osc_half.WTnextFrame(); + st_osc.WTnextFrame(); + st_osc_half.WTnextFrame(); - mixer2.WTnextFrame(); - mixer_center.WTnextFrame(); + mixer2.WTnextFrame(); + mixer_center.WTnextFrame(); - } + } } return len; diff --git a/JAERO/burstmskdemodulator.h b/JAERO/burstmskdemodulator.h index 51aa633..bf3f6c2 100644 --- a/JAERO/burstmskdemodulator.h +++ b/JAERO/burstmskdemodulator.h @@ -143,7 +143,6 @@ class BurstMskDemodulator : public QIODevice //delay for trident detection DelayThing d2; - //trident shape thing QVector tridentbuffer; int tridentbuffer_ptr; diff --git a/JAERO/burstoqpskdemodulator.cpp b/JAERO/burstoqpskdemodulator.cpp index 6c9a388..88fa6f7 100644 --- a/JAERO/burstoqpskdemodulator.cpp +++ b/JAERO/burstoqpskdemodulator.cpp @@ -389,7 +389,6 @@ void BurstOqpskDemodulator::writeDataSlot(const char *data, qint64 len) if(pdet.update(bt_sig)) { tridentbuffer_ptr=0; - } if(tridentbuffer_ptrZero(); - } - }//end of trident check //mix @@ -528,14 +521,11 @@ void BurstOqpskDemodulator::writeDataSlot(const char *data, qint64 len) startstop=startstopstart; } - - } if(startstop==0) { startstop--; emit SignalStatus(false); - } if((cntr>((256-10)*SamplesPerSymbol))&&insertpreamble) @@ -569,7 +559,6 @@ void BurstOqpskDemodulator::writeDataSlot(const char *data, qint64 len) //correct carrier phase - sig2*=symboltone_averotator; rotator=rotator*std::exp(imag*rotator_freq); @@ -590,8 +579,6 @@ void BurstOqpskDemodulator::writeDataSlot(const char *data, qint64 len) double abval=std::abs(sig2); if(abval>2.84)sig2=(2.84/abval)*sig2; - - //normal symbol timer double st_diff=delays.update(abval*abval)-(abval*abval); double st_d1out=delayt41.update(st_diff); diff --git a/JAERO/burstoqpskdemodulator.h b/JAERO/burstoqpskdemodulator.h index 384f4ac..db73e5c 100644 --- a/JAERO/burstoqpskdemodulator.h +++ b/JAERO/burstoqpskdemodulator.h @@ -60,10 +60,7 @@ class BurstOqpskDemodulator : public QIODevice void setScatterPointType(ScatterPointType type); //--L/R channel selection - bool channel_select_other; - - static int sample; - // + bool channel_select_other; signals: void ScatterPoints(const QVector &buffer); diff --git a/JAERO/jaero.qrc b/JAERO/jaero.qrc index de6a130..980f79c 100644 --- a/JAERO/jaero.qrc +++ b/JAERO/jaero.qrc @@ -28,4 +28,4 @@ images/cpu.png images/green_cpu.png - \ No newline at end of file + diff --git a/JAERO/mainwindow.cpp b/JAERO/mainwindow.cpp index 0d8064e..9f6d811 100644 --- a/JAERO/mainwindow.cpp +++ b/JAERO/mainwindow.cpp @@ -13,8 +13,6 @@ #endif #include "databasetext.h" -#include "zmq.h" - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -32,7 +30,9 @@ MainWindow::MainWindow(QWidget *parent) : planelog = new PlaneLog; //create zmq audio receiver - zmq_audio_receiver = new AudioReceiver(this); + zmq_audio_receiver = new ZMQAudioReceiver(this); + //create zmq audio sender + zmq_audio_sender = new ZMQAudioSender(this); //create areo decoder aerol = new AeroL(this); //Create Aero sink @@ -101,7 +101,6 @@ MainWindow::MainWindow(QWidget *parent) : //connect(&arincparser,SIGNAL(DownlinkBasicReportGroupSignal(DownlinkBasicReportGroup&)),sbs1,SLOT(DownlinkBasicReportGroupSlot(DownlinkBasicReportGroup&))); //connect(&arincparser,SIGNAL(DownlinkEarthReferenceGroupSignal(DownlinkEarthReferenceGroup&)),sbs1,SLOT(DownlinkEarthReferenceGroupSlot(DownlinkEarthReferenceGroup&))); - //default sink is the aerol device audiomskdemodulator->ConnectSinkDevice(aerol); audiooqpskdemodulator->ConnectSinkDevice(aerol); @@ -128,7 +127,6 @@ MainWindow::MainWindow(QWidget *parent) : connect(ambe,SIGNAL(decoded_signal(QByteArray)),compresseddiskwriter,SLOT(audioin(QByteArray))); connect(ambe,SIGNAL(decoded_signal(QByteArray)),audioout,SLOT(audioin(QByteArray))); - //statusbar setup freqlabel = new QLabel(); ebnolabel = new QLabel(); @@ -232,22 +230,6 @@ MainWindow::MainWindow(QWidget *parent) : ui->actionTXRX->setVisible(false);//there is a hidden audio modulator icon. - //for zmq stuff - - zmqStatus = -1; - context = zmq_ctx_new(); - publisher = zmq_socket(context, ZMQ_PUB); - - int keepalive = 1; - int keepalivecnt = 10; - int keepaliveidle = 1; - int keepaliveintrv = 1; - - zmq_setsockopt(publisher, ZMQ_TCP_KEEPALIVE,(void*)&keepalive, sizeof(ZMQ_TCP_KEEPALIVE)); - zmq_setsockopt(publisher, ZMQ_TCP_KEEPALIVE_CNT,(void*)&keepalivecnt,sizeof(ZMQ_TCP_KEEPALIVE_CNT)); - zmq_setsockopt(publisher, ZMQ_TCP_KEEPALIVE_IDLE,(void*)&keepaliveidle,sizeof(ZMQ_TCP_KEEPALIVE_IDLE)); - zmq_setsockopt(publisher, ZMQ_TCP_KEEPALIVE_INTVL,(void*)&keepaliveintrv,sizeof(ZMQ_TCP_KEEPALIVE_INTVL)); - //set pop and accept settings settingsdialog->populatesettings(); acceptsettings(); @@ -580,28 +562,6 @@ void MainWindow::selectdemodulatorconnections(DemodType demodtype) } } -void MainWindow::connectZMQ() -{ - // bind socket - - if(zmqStatus == 0) - { - zmq_disconnect(publisher, connected_url.c_str()); - } - - if(settingsdialog->zmqAudioOutEnabled) - { - QSettings settings("Jontisoft", settings_name); - QString url = settings.value("remoteAudioOutBindAddress", "tcp://*:5551").toString(); - connected_url = url.toUtf8().constData(); - zmqStatus= zmq_bind(publisher, connected_url.c_str() ); - } - - if(settingsdialog->zmqAudioInputEnabled)zmq_audio_receiver->ZMQaudioStart(settingsdialog->zmqAudioInputAddress, settingsdialog->zmqAudioInputTopic); - else zmq_audio_receiver->ZMQaudioStop(); - -} - void MainWindow::closeEvent(QCloseEvent *event) { @@ -1005,8 +965,6 @@ void MainWindow::acceptsettings() if(settingsdialog->tcp_for_ads_messages_enabled)sbs1->starttcpconnection(settingsdialog->tcp_for_ads_messages_address,settingsdialog->tcp_for_ads_messages_port,settingsdialog->tcp_as_client_enabled); else sbs1->stoptcpconnection(); - connectZMQ(); - //if soundcard rate changed if(typeofdemodtouse==MSK) { @@ -1127,11 +1085,25 @@ void MainWindow::acceptsettings() if(settingsdialog->loggingenable)compresseddiskwriter->setLogDir(settingsdialog->loggingdirectory); else compresseddiskwriter->setLogDir(""); + //zmq audio in from remote sdr + if(settingsdialog->zmqAudioInputEnabled)zmq_audio_receiver->Start(settingsdialog->zmqAudioInputAddress, settingsdialog->zmqAudioInputTopic); + else zmq_audio_receiver->Stop(); + + //local audio decode if(settingsdialog->localAudioOutEnabled)connect(aerol,SIGNAL(Voicesignal(QByteArray)),ambe,SLOT(to_decode_slot(QByteArray)),Qt::UniqueConnection); else disconnect(aerol,SIGNAL(Voicesignal(QByteArray)),ambe,SLOT(to_decode_slot(QByteArray))); - if(settingsdialog->zmqAudioOutEnabled)connect(aerol,SIGNAL(Voicesignal(QByteArray&, QString&)),this,SLOT(Voiceslot(QByteArray&, QString&)),Qt::UniqueConnection); - else disconnect(aerol,SIGNAL(Voicesignal(QByteArray&, QString&)),this,SLOT(Voiceslot(QByteArray&, QString&))); + //zmq compressed audio output + if(settingsdialog->zmqAudioOutEnabled) + { + zmq_audio_sender->Start(settingsdialog->zmqAudioOutBind,settingsdialog->zmqAudioOutTopic); + connect(aerol,SIGNAL(Voicesignal(QByteArray&, QString&)),zmq_audio_sender,SLOT(Voiceslot(QByteArray&, QString&)),Qt::UniqueConnection); + } + else + { + zmq_audio_sender->Stop(); + disconnect(aerol,SIGNAL(Voicesignal(QByteArray&, QString&)),zmq_audio_sender,SLOT(Voiceslot(QByteArray&, QString&))); + } } @@ -1168,22 +1140,6 @@ void MainWindow::CChannelAssignmentSlot(CChannelAssignmentItem &item) ui->plainTextEdit_cchan_assignment->appendPlainText(message); } -void MainWindow::Voiceslot(QByteArray &data, QString &hex) -{ - - std::string topic_text = settingsdialog->zmqAudioOutTopic.toUtf8().constData(); - zmq_setsockopt(publisher, ZMQ_IDENTITY, topic_text.c_str(), topic_text.length()); - - if(data.length()!=0) - { - zmq_send(publisher, topic_text.c_str(), topic_text.length(), ZMQ_SNDMORE); - zmq_send(publisher, data.data(), data.length(), 0 ); - } - zmq_send(publisher, topic_text.c_str(), 5, ZMQ_SNDMORE); - zmq_send(publisher, hex.toStdString().c_str(), 6, 0 ); - -} - //--new method of mainwindow getting second channel from aerol void MainWindow::ACARSslot(ACARSItem &acarsitem) diff --git a/JAERO/mainwindow.h b/JAERO/mainwindow.h index f7f5476..0e96b09 100644 --- a/JAERO/mainwindow.h +++ b/JAERO/mainwindow.h @@ -5,10 +5,6 @@ #include #include -#ifdef _WIN32 -#include "winsock2.h" -#endif - #include "audiooqpskdemodulator.h" #include "audiomskdemodulator.h" #include "audioburstoqpskdemodulator.h" @@ -23,11 +19,11 @@ #include "databasetext.h" #include "arincparse.h" -#include "zmq.h" #include "audiooutdevice.h" #include "compressedaudiodiskwriter.h" -#include "audioreceiver.h" +#include "zmq_audioreceiver.h" +#include "zmq_audiosender.h" namespace Ui { @@ -44,8 +40,6 @@ class MainWindow : public QMainWindow signals: - void ZMQaudioStop(); - private: enum DemodType{NoDemodType,MSK,OQPSK,BURSTOQPSK,BURSTMSK}; Ui::MainWindow *ui; @@ -69,7 +63,6 @@ class MainWindow : public QMainWindow AudioBurstMskDemodulator *audioburstmskdemodulator; AudioBurstMskDemodulator::Settings audioburstmskdemodulatorsettings; - //bottom textedit output QList > udpsockets_bottom_textedit; @@ -101,16 +94,9 @@ class MainWindow : public QMainWindow QSound *beep; - // zeromq for AMBE - void* context; - void* publisher; - - void connectZMQ(); - int zmqStatus; - std::string connected_url; - //ZeroMQ Audio Receiver - AudioReceiver *zmq_audio_receiver; + ZMQAudioReceiver *zmq_audio_receiver; + ZMQAudioSender *zmq_audio_sender; protected: void closeEvent(QCloseEvent *event); @@ -134,7 +120,6 @@ private slots: void on_action_Settings_triggered(); void on_action_PlaneLog_triggered(); void ACARSslot(ACARSItem &acarsitem); - void Voiceslot(QByteArray &data, QString &hex); void CChannelAssignmentSlot(CChannelAssignmentItem &item); void ERRorslot(QString &error); diff --git a/JAERO/audioreceiver.cpp b/JAERO/zmq_audioreceiver.cpp similarity index 83% rename from JAERO/audioreceiver.cpp rename to JAERO/zmq_audioreceiver.cpp index 2cffb7d..595c062 100644 --- a/JAERO/audioreceiver.cpp +++ b/JAERO/zmq_audioreceiver.cpp @@ -1,11 +1,12 @@ -#include "audioreceiver.h" +#include "zmq_audioreceiver.h" #include "QDebug" #include +#include -void AudioReceiver::ZMQaudioStart(QString address, QString topic) +void ZMQAudioReceiver::Start(QString address, QString topic) { //stop set prams and start thread - ZMQaudioStop(); + Stop(); setParameters(address,topic); future = QtConcurrent::run([=]() { process(); @@ -20,7 +21,7 @@ void AudioReceiver::ZMQaudioStart(QString address, QString topic) } } -void AudioReceiver::process() +void ZMQAudioReceiver::process() { // allocate enough for 96Khz sampling with 1 buffer per second int recsize = 192000; @@ -60,7 +61,7 @@ void AudioReceiver::process() } -AudioReceiver::AudioReceiver(QObject *parent): +ZMQAudioReceiver::ZMQAudioReceiver(QObject *parent): QObject(parent), running(false), context(nullptr), @@ -69,18 +70,18 @@ AudioReceiver::AudioReceiver(QObject *parent): } -AudioReceiver::~AudioReceiver() +ZMQAudioReceiver::~ZMQAudioReceiver() { - ZMQaudioStop(); + Stop(); } -void AudioReceiver::setParameters(QString address, QString topic) +void ZMQAudioReceiver::setParameters(QString address, QString topic) { _address = address; _topic = topic; } -void AudioReceiver::ZMQaudioStop() +void ZMQAudioReceiver::Stop() { running = false; diff --git a/JAERO/audioreceiver.h b/JAERO/zmq_audioreceiver.h similarity index 58% rename from JAERO/audioreceiver.h rename to JAERO/zmq_audioreceiver.h index 9ff13b7..ffa958c 100644 --- a/JAERO/audioreceiver.h +++ b/JAERO/zmq_audioreceiver.h @@ -1,35 +1,28 @@ -#ifndef AUDIORECEIVER_H -#define AUDIORECEIVER_H - - -#include "audioreceiver.h" +#ifndef ZMQ_AUDIORECEIVER_H +#define ZMQ_AUDIORECEIVER_H #include -#include -#include -#include +#include #include - -class AudioReceiver : public QObject +class ZMQAudioReceiver : public QObject { Q_OBJECT public: - explicit AudioReceiver(QObject *parent = 0);//QString address, QString topic); - ~AudioReceiver(); + explicit ZMQAudioReceiver(QObject *parent = 0); + ~ZMQAudioReceiver(); public slots: - void ZMQaudioStop(); - void ZMQaudioStart(QString address, QString topic); + void Stop(); + void Start(QString address, QString topic); signals: void finished(); - private: void setParameters(QString address, QString topic); diff --git a/JAERO/zmq_audiosender.cpp b/JAERO/zmq_audiosender.cpp new file mode 100644 index 0000000..729e025 --- /dev/null +++ b/JAERO/zmq_audiosender.cpp @@ -0,0 +1,55 @@ +#include "zmq_audiosender.h" +#include "zmq.h" +#include + +ZMQAudioSender::ZMQAudioSender(QObject *parent) : QObject(parent) +{ + zmqStatus = -1; + context = zmq_ctx_new(); + publisher = zmq_socket(context, ZMQ_PUB); + + int keepalive = 1; + int keepalivecnt = 10; + int keepaliveidle = 1; + int keepaliveintrv = 1; + + zmq_setsockopt(publisher, ZMQ_TCP_KEEPALIVE,(void*)&keepalive, sizeof(ZMQ_TCP_KEEPALIVE)); + zmq_setsockopt(publisher, ZMQ_TCP_KEEPALIVE_CNT,(void*)&keepalivecnt,sizeof(ZMQ_TCP_KEEPALIVE_CNT)); + zmq_setsockopt(publisher, ZMQ_TCP_KEEPALIVE_IDLE,(void*)&keepaliveidle,sizeof(ZMQ_TCP_KEEPALIVE_IDLE)); + zmq_setsockopt(publisher, ZMQ_TCP_KEEPALIVE_INTVL,(void*)&keepaliveintrv,sizeof(ZMQ_TCP_KEEPALIVE_INTVL)); +} + +void ZMQAudioSender::Start(QString &address, QString &topic) +{ + Stop(); + // bind socket + this->topic=topic; + connected_url=address.toUtf8().constData(); + zmqStatus=zmq_bind(publisher, connected_url.c_str() ); + qDebug()<<"ZMQAudioSender::Start"; +} + +void ZMQAudioSender::Stop() +{ + qDebug()<<"ZMQAudioSender::Stop"; + if(zmqStatus == 0) + { + zmqStatus = zmq_disconnect(publisher, connected_url.c_str()); + } +} + +void ZMQAudioSender::Voiceslot(QByteArray &data, QString &hex) +{ + qDebug()<<"ZMQAudioSender::Voiceslot"; + std::string topic_text = topic.toUtf8().constData(); + zmq_setsockopt(publisher, ZMQ_IDENTITY, topic_text.c_str(), topic_text.length()); + + if(data.length()!=0) + { + zmq_send(publisher, topic_text.c_str(), topic_text.length(), ZMQ_SNDMORE); + zmq_send(publisher, data.data(), data.length(), 0 ); + } + zmq_send(publisher, topic_text.c_str(), 5, ZMQ_SNDMORE); + zmq_send(publisher, hex.toStdString().c_str(), 6, 0 ); +} + diff --git a/JAERO/zmq_audiosender.h b/JAERO/zmq_audiosender.h new file mode 100644 index 0000000..f95eea3 --- /dev/null +++ b/JAERO/zmq_audiosender.h @@ -0,0 +1,24 @@ +#ifndef ZMQ_AUDIOSENDER_H +#define ZMQ_AUDIOSENDER_H + +#include + +class ZMQAudioSender : public QObject +{ + Q_OBJECT +public: + explicit ZMQAudioSender(QObject *parent = 0); + void Start(QString &address,QString &topic); + void Stop(); +signals: +public slots: + void Voiceslot(QByteArray &data, QString &hex); +private: + void* context; + void* publisher; + int zmqStatus; + std::string connected_url; + QString topic; +}; + +#endif // ZMQ_AUDIOSENDER_H