From 1ee4274c48dd2048662409088bdc1b878ce3a8a6 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sat, 5 Dec 2020 14:06:45 +0200 Subject: [PATCH] wip : info about Rx protocol --- include/ggwave/ggwave.h | 7 ++++--- src/ggwave.cpp | 12 +++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/ggwave/ggwave.h b/include/ggwave/ggwave.h index a5443a5..3f5282e 100644 --- a/include/ggwave/ggwave.h +++ b/include/ggwave/ggwave.h @@ -77,6 +77,7 @@ public: const TxProtocols & getTxProtocols() const { return kTxProtocols; } const TxRxData & getRxData() const { return m_rxData; } + const TxProtocol & getRxProtocol() const { return m_rxProtocol; } int takeRxData(TxRxData & dst); private: @@ -106,14 +107,11 @@ private: const int m_encodedDataOffset; // Rx - bool m_hasNewRxData; bool m_receivingData; bool m_analyzingData; int m_markerFreqStart; - int m_recvDuration_frames; - int m_lastRxDataLength; int m_framesLeftToAnalyze; int m_framesLeftToRecord; @@ -126,7 +124,10 @@ private: AmplitudeData m_sampleAmplitude; SpectrumData m_sampleSpectrum; + bool m_hasNewRxData; + int m_lastRxDataLength; TxRxData m_rxData; + TxProtocol m_rxProtocol; int m_historyId = 0; AmplitudeData m_sampleAmplitudeAverage; diff --git a/src/ggwave.cpp b/src/ggwave.cpp index feae05c..5aa8d6d 100644 --- a/src/ggwave.cpp +++ b/src/ggwave.cpp @@ -423,6 +423,7 @@ void GGWave::receive(const CBDequeueAudio & CBDequeueAudio) { const int stepsPerFrame = 16; const int step = m_samplesPerFrame/stepsPerFrame; + int lastRSLength = -1; std::unique_ptr rsData; bool isValid = false; @@ -468,7 +469,7 @@ void GGWave::receive(const CBDequeueAudio & CBDequeueAudio) { uint8_t curByte = 0; for (int i = 0; i < 2*rxProtocol.bytesPerTx; ++i) { double freq = m_hzPerSample*rxProtocol.freqStart; - int bin = std::round(freq*m_ihzPerSample) + i*16; + int bin = std::round(freq*m_ihzPerSample) + 16*i; int kmax = 0; double amax = 0.0; @@ -498,9 +499,13 @@ void GGWave::receive(const CBDequeueAudio & CBDequeueAudio) { } if (knownLength) { - rsData.reset(new RS::ReedSolomon(m_rxData[0], ::getECCBytesForLength(m_rxData[0]))); - int decodedLength = m_rxData[0]; + + if (decodedLength != lastRSLength) { + rsData.reset(new RS::ReedSolomon(decodedLength, ::getECCBytesForLength(decodedLength))); + lastRSLength = decodedLength; + } + if (rsData->Decode(m_txDataEncoded.data() + m_encodedDataOffset, m_rxData.data()) == 0) { if (m_rxData[0] != 0) { std::string s((char *) m_rxData.data(), decodedLength); @@ -511,6 +516,7 @@ void GGWave::receive(const CBDequeueAudio & CBDequeueAudio) { isValid = true; m_hasNewRxData = true; m_lastRxDataLength = decodedLength; + m_rxProtocol = rxProtocol; } } }