From a9b339c02e8086cfc1878168c1343ffd656031ce Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sat, 9 Jan 2021 13:24:19 +0200 Subject: [PATCH] ggwave : getTxProtocols is now static method --- include/ggwave/ggwave.h | 23 +++++++++++++---------- src/ggwave.cpp | 14 +++++++------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/include/ggwave/ggwave.h b/include/ggwave/ggwave.h index a8a9fdf..fbb9010 100644 --- a/include/ggwave/ggwave.h +++ b/include/ggwave/ggwave.h @@ -26,14 +26,18 @@ public: using TxProtocols = std::vector; - const TxProtocols kTxProtocols { - { "Normal", 40, 9, 3, }, - { "Fast", 40, 6, 3, }, - { "Fastest", 40, 3, 3, }, - { "[U] Normal", 320, 9, 3, }, - { "[U] Fast", 320, 6, 3, }, - { "[U] Fastest", 320, 3, 3, }, - }; + static const TxProtocols & getTxProtocols() { + static TxProtocols kTxProtocols { + { "Normal", 40, 9, 3, }, + { "Fast", 40, 6, 3, }, + { "Fastest", 40, 3, 3, }, + { "[U] Normal", 320, 9, 3, }, + { "[U] Fast", 320, 6, 3, }, + { "[U] Fastest", 320, 3, 3, }, + }; + + return kTxProtocols; + } using AmplitudeData = std::vector; using AmplitudeData16 = std::vector; @@ -71,8 +75,7 @@ public: const float & getSampleRateIn() const { return m_sampleRateIn; } const float & getSampleRateOut() const { return m_sampleRateOut; } - const TxProtocol & getDefultTxProtocol() const { return kTxProtocols[1]; } - const TxProtocols & getTxProtocols() const { return kTxProtocols; } + const TxProtocol & getDefultTxProtocol() const { return getTxProtocols()[1]; } const TxRxData & getRxData() const { return m_rxData; } const TxProtocol & getRxProtocol() const { return m_rxProtocol; } diff --git a/src/ggwave.cpp b/src/ggwave.cpp index 5c7f90c..19b555a 100644 --- a/src/ggwave.cpp +++ b/src/ggwave.cpp @@ -444,8 +444,8 @@ void GGWave::receive(const CBDequeueAudio & CBDequeueAudio) { const int step = m_samplesPerFrame/stepsPerFrame; bool isValid = false; - for (int rxProtocolId = 0; rxProtocolId < (int) kTxProtocols.size(); ++rxProtocolId) { - const auto & rxProtocol = kTxProtocols[rxProtocolId]; + for (int rxProtocolId = 0; rxProtocolId < (int) getTxProtocols().size(); ++rxProtocolId) { + const auto & rxProtocol = getTxProtocols()[rxProtocolId]; // skip Rx protocol if start frequency is different from detected one if (rxProtocol.freqStart != m_markerFreqStart) { @@ -576,7 +576,7 @@ void GGWave::receive(const CBDequeueAudio & CBDequeueAudio) { if (m_receivingData == false) { bool isReceiving = false; - for (const auto & rxProtocol : kTxProtocols) { + for (const auto & rxProtocol : getTxProtocols()) { int nDetectedMarkerBits = m_nBitsInMarker; for (int i = 0; i < m_nBitsInMarker; ++i) { @@ -615,7 +615,7 @@ void GGWave::receive(const CBDequeueAudio & CBDequeueAudio) { } else { bool isEnded = false; - for (const auto & rxProtocol : kTxProtocols) { + for (const auto & rxProtocol : getTxProtocols()) { int nDetectedMarkerBits = m_nBitsInMarker; for (int i = 0; i < m_nBitsInMarker; ++i) { @@ -681,15 +681,15 @@ bool GGWave::takeSpectrum(SpectrumData & dst) { int GGWave::maxFramesPerTx() const { int res = 0; - for (const auto & protocol : kTxProtocols) { + for (const auto & protocol : getTxProtocols()) { res = std::max(res, protocol.framesPerTx); } return res; } int GGWave::minBytesPerTx() const { - int res = kTxProtocols.front().framesPerTx; - for (const auto & protocol : kTxProtocols) { + int res = getTxProtocols().front().framesPerTx; + for (const auto & protocol : getTxProtocols()) { res = std::min(res, protocol.bytesPerTx); } return res;