diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 0f16c68..fffe23c 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -21,6 +21,7 @@ DemodulatorInstance::DemodulatorInstance() : demodulatorThread->setAudioOutputQueue(audioInputQueue); currentDemodType = demodulatorThread->getDemodulatorType(); + currentDemodLock = demodulatorThread->getDemodulatorLock(); } DemodulatorInstance::~DemodulatorInstance() { @@ -50,6 +51,7 @@ void DemodulatorInstance::run() { currentFrequency = demodulatorPreThread->getParams().frequency; currentDemodType = demodulatorThread->getDemodulatorType(); + currentDemodLock = demodulatorThread->getDemodulatorLock(); currentAudioSampleRate = AudioThread::deviceSampleRate[getOutputDevice()]; demodulatorPreThread->getParams().audioSampleRate = currentAudioSampleRate; @@ -264,6 +266,19 @@ int DemodulatorInstance::getDemodulatorType() { return currentDemodType; } +void DemodulatorInstance::setDemodulatorLock(bool demod_lock_in) { + if(demod_lock_in) { + currentDemodLock = true; + } + else { + currentDemodLock = false; + } +} + +int DemodulatorInstance::getDemodulatorLock() { + return currentDemodLock; +} + void DemodulatorInstance::setBandwidth(int bw) { if (!active) { currentBandwidth = bw; diff --git a/src/demod/DemodulatorInstance.h b/src/demod/DemodulatorInstance.h index bbb4841..88042ab 100644 --- a/src/demod/DemodulatorInstance.h +++ b/src/demod/DemodulatorInstance.h @@ -64,6 +64,9 @@ public: void setDemodulatorType(int demod_type_in); int getDemodulatorType(); + + void setDemodulatorLock(bool demod_lock_in); + int getDemodulatorLock(); void setBandwidth(int bw); int getBandwidth(); @@ -98,6 +101,7 @@ private: long long currentFrequency; int currentBandwidth; int currentDemodType; + bool currentDemodLock = false; int currentOutputDevice; int currentAudioSampleRate; bool follow, tracking; diff --git a/src/demod/DemodulatorMgr.cpp b/src/demod/DemodulatorMgr.cpp index 7604d92..ac584e7 100644 --- a/src/demod/DemodulatorMgr.cpp +++ b/src/demod/DemodulatorMgr.cpp @@ -162,6 +162,7 @@ void DemodulatorMgr::updateLastState() { if (lastActiveDemodulator) { lastBandwidth = lastActiveDemodulator->getBandwidth(); lastDemodType = lastActiveDemodulator->getDemodulatorType(); + lastDemodLock = lastActiveDemodulator->getDemodulatorLock(); lastSquelchEnabled = lastActiveDemodulator->isSquelchEnabled(); lastSquelch = lastActiveDemodulator->getSquelchLevel(); lastGain = lastActiveDemodulator->getGain(); @@ -191,6 +192,14 @@ void DemodulatorMgr::setLastDemodulatorType(int lastDemodType) { this->lastDemodType = lastDemodType; } +bool DemodulatorMgr::getLastDemodulatorLock() const { + return lastDemodLock; +} + +void DemodulatorMgr::setLastDemodulatorLock(bool lastDemodLock) { + this->lastDemodLock = lastDemodLock; +} + float DemodulatorMgr::getLastGain() const { return lastGain; } diff --git a/src/demod/DemodulatorMgr.h b/src/demod/DemodulatorMgr.h index 24baeb1..01a8273 100644 --- a/src/demod/DemodulatorMgr.h +++ b/src/demod/DemodulatorMgr.h @@ -27,6 +27,9 @@ public: int getLastDemodulatorType() const; void setLastDemodulatorType(int lastDemodType); + + bool getLastDemodulatorLock() const; + void setLastDemodulatorLock(bool lastDemodLock); float getLastGain() const; void setLastGain(float lastGain); @@ -52,6 +55,7 @@ private: int lastBandwidth; int lastDemodType; + bool lastDemodLock; bool lastSquelchEnabled; float lastSquelch; float lastGain; diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index cd69707..e79700d 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -178,7 +178,6 @@ void DemodulatorThread::threadMain() { } else { float p; unsigned int bitstream; - int temp; switch (demodulatorType.load()) { case DEMOD_TYPE_LSB: for (int i = 0; i < bufSize; i++) { // Reject upper band @@ -203,57 +202,62 @@ void DemodulatorThread::threadMain() { modem_demodulate(demodASK, inp->data[i], &bitstream); std::cout << bitstream << std::endl; } + updateDemodulatorLock(demodASK); break; case DEMOD_TYPE_BPSK: for (int i = 0; i < bufSize; i++) { modem_demodulate(demodBPSK, inp->data[i], &bitstream); std::cout << bitstream << std::endl; } + updateDemodulatorLock(demodBPSK); break; case DEMOD_TYPE_DPSK: for (int i = 0; i < bufSize; i++) { modem_demodulate(demodDPSK, inp->data[i], &bitstream); std::cout << bitstream << std::endl; } + updateDemodulatorLock(demodDPSK); break; case DEMOD_TYPE_PSK: for (int i = 0; i < bufSize; i++) { modem_demodulate(demodPSK, inp->data[i], &bitstream); std::cout << bitstream << std::endl; } + updateDemodulatorLock(demodPSK); break; case DEMOD_TYPE_OOK: for (int i = 0; i < bufSize; i++) { modem_demodulate(demodOOK, inp->data[i], &bitstream); std::cout << bitstream << std::endl; } + updateDemodulatorLock(demodOOK); break; case DEMOD_TYPE_SQAM: for (int i = 0; i < bufSize; i++) { modem_demodulate(demodSQAM, inp->data[i], &bitstream); std::cout << bitstream << std::endl; } + updateDemodulatorLock(demodSQAM); break; case DEMOD_TYPE_ST: for (int i = 0; i < bufSize; i++) { modem_demodulate(demodST, inp->data[i], &bitstream); std::cout << bitstream << std::endl; } + updateDemodulatorLock(demodST); break; case DEMOD_TYPE_QAM: for (int i = 0; i < bufSize; i++) { modem_demodulate(demodQAM, inp->data[i], &bitstream); std::cout << bitstream << std::endl; } + updateDemodulatorLock(demodQAM); break; case DEMOD_TYPE_QPSK: for (int i = 0; i < bufSize; i++) { modem_demodulate(demodQPSK, inp->data[i], &bitstream); - // std::cout << bitstream << std::endl; } - if(modem_get_demodulator_evm(demodQPSK) <= 0.8f) { - std::cout << "Lock!" << std::endl; - } + updateDemodulatorLock(demodQPSK); break; } @@ -458,6 +462,10 @@ void DemodulatorThread::threadMain() { demodAM = demodAM_DSB_CSP; ampmodem_reset(demodAM); break; + case DEMOD_TYPE_QPSK: + std::cout << "reset modem qpsk" << std::endl; + modem_reset(demodQPSK); + break; } demodulatorType = newDemodType; } @@ -553,3 +561,20 @@ int DemodulatorThread::getDemodulatorType() { return demodulatorType; } +void DemodulatorThread::setDemodulatorLock(bool demod_lock_in) { + if(demod_lock_in) { + currentDemodLock = true; + } + else { + currentDemodLock = false; + } +} + +int DemodulatorThread::getDemodulatorLock() { + return currentDemodLock; +} + +void DemodulatorThread::updateDemodulatorLock(modem demod) { + modem_get_demodulator_evm(demod) <= 0.8f ? setDemodulatorLock(true) : setDemodulatorLock(false); +} + diff --git a/src/demod/DemodulatorThread.h b/src/demod/DemodulatorThread.h index 0f113a5..33055d9 100644 --- a/src/demod/DemodulatorThread.h +++ b/src/demod/DemodulatorThread.h @@ -37,6 +37,9 @@ public: void setDemodulatorType(int demod_type_in); int getDemodulatorType(); + + void setDemodulatorLock(bool demod_lock_in); + int getDemodulatorLock(); #ifdef __APPLE__ static void *pthread_helper(void *context) { @@ -92,4 +95,7 @@ protected: std::atomic squelchLevel; std::atomic signalLevel; bool squelchEnabled; + + bool currentDemodLock = false; + void updateDemodulatorLock(modem demod); }; diff --git a/src/visual/PrimaryGLContext.cpp b/src/visual/PrimaryGLContext.cpp index f50cfdd..0557768 100644 --- a/src/visual/PrimaryGLContext.cpp +++ b/src/visual/PrimaryGLContext.cpp @@ -305,6 +305,12 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, RGBColor color, lon demodAlign = GLFont::GLFONT_ALIGN_CENTER; break; } + + + // add lock to string if we have an lock + if(demod->getDemodulatorLock()) { + demodStr = demodStr + " Lock"; + } glColor3f(0, 0, 0); getFont(PrimaryGLContext::GLFONT_SIZE16).drawString(demodStr, 2.0 * (uxPos - 0.5) + xOfs, -1.0 + hPos - yOfs, 16, demodAlign,