From fa33f15417bcb5837c32fe6e0a62a3d9b314ec0e Mon Sep 17 00:00:00 2001 From: Jacob McSwain Date: Sat, 16 Jul 2022 04:53:43 -0500 Subject: [PATCH] Implemented M17 EOT marker --- .../include/protocols/M17/M17Constants.hpp | 1 + .../include/protocols/M17/M17Modulator.hpp | 6 +- openrtx/src/protocols/M17/M17Modulator.cpp | 56 ++++++++++++------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/openrtx/include/protocols/M17/M17Constants.hpp b/openrtx/include/protocols/M17/M17Constants.hpp index f631fffe..c75952ab 100644 --- a/openrtx/include/protocols/M17/M17Constants.hpp +++ b/openrtx/include/protocols/M17/M17Constants.hpp @@ -41,6 +41,7 @@ static constexpr syncw_t LSF_SYNC_WORD = {0x55, 0xF7}; // LSF sync word static constexpr syncw_t BERT_SYNC_WORD = {0xDF, 0x55}; // BERT data sync word static constexpr syncw_t STREAM_SYNC_WORD = {0xFF, 0x5D}; // Stream data sync word static constexpr syncw_t PACKET_SYNC_WORD = {0x75, 0xFF}; // Packet data sync word +static constexpr syncw_t EOT_SYNC_WORD = {0x55, 0x5D}; // End of transmission sync word } // namespace M17 diff --git a/openrtx/include/protocols/M17/M17Modulator.hpp b/openrtx/include/protocols/M17/M17Modulator.hpp index 209d217e..8d2233c7 100644 --- a/openrtx/include/protocols/M17/M17Modulator.hpp +++ b/openrtx/include/protocols/M17/M17Modulator.hpp @@ -58,7 +58,7 @@ public: void init(); /** - * Shutdown modulator and deallocate data buffers. + * Forcefully shutdown modulator and deallocate data buffers. */ void terminate(); @@ -89,6 +89,9 @@ private: */ void sendBaseband(); + /** Gracefully end the transmission **/ + void stop(); + static constexpr size_t M17_TX_SAMPLE_RATE = 48000; static constexpr size_t M17_SAMPLES_PER_SYMBOL = M17_TX_SAMPLE_RATE / M17_SYMBOL_RATE; static constexpr size_t M17_FRAME_SAMPLES = M17_FRAME_SYMBOLS * M17_SAMPLES_PER_SYMBOL; @@ -106,7 +109,6 @@ private: stream_sample_t *idleBuffer; ///< Half baseband buffer, free for processing. streamId outStream; ///< Baseband output stream ID. bool txRunning; ///< Transmission running. - bool stopTx; ///< Stop transmission request. #if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0) filter_state_t pwmFilterState; diff --git a/openrtx/src/protocols/M17/M17Modulator.cpp b/openrtx/src/protocols/M17/M17Modulator.cpp index 80190965..c5b41e86 100644 --- a/openrtx/src/protocols/M17/M17Modulator.cpp +++ b/openrtx/src/protocols/M17/M17Modulator.cpp @@ -76,7 +76,6 @@ void M17::M17Modulator::start() if(txRunning) return; txRunning = true; - stopTx = false; // Fill symbol buffer with preamble, made of alternated +3 and -3 symbols for(size_t i = 0; i < symbols.size(); i += 2) @@ -112,11 +111,45 @@ void M17Modulator::send(const frame_t& frame, const bool isLast) it = std::copy(sym.begin(), sym.end(), it); } + symbolsToBaseband(); + sendBaseband(); + // If last frame, signal stop of transmission - if(isLast) stopTx = true; + if(isLast) stop(); +} + +void M17Modulator::stop() +{ + if(txRunning == false) + return; + + frame_t eotFrame; + // Fill EOT frame with 0x55, 0x5D as per M17 spec. + for(size_t i = 0; i < eotFrame.size(); i += 2) + { + eotFrame[i] = 0x55; + eotFrame[i + 1] = 0x5D; + } + + // Convert to symbols + auto it = symbols.begin(); + for(size_t i = 0; i < eotFrame.size(); i++) + { + auto sym = byteToSymbols(eotFrame[i]); + it = std::copy(sym.begin(), sym.end(), it); + } symbolsToBaseband(); sendBaseband(); + + outputStream_stop(outStream); + outputStream_sync(outStream, false); + txRunning = false; + idleBuffer = baseband_buffer.get(); + + #if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0) + dsp_resetFilterState(&pwmFilterState); + #endif } void M17Modulator::symbolsToBaseband() @@ -148,24 +181,7 @@ void M17Modulator::sendBaseband() // Transmission is ongoing, syncronise with stream end before proceeding outputStream_sync(outStream, true); - - // Check if transmission stop is requested, if so stop the output stream - // and wait until its effective termination. - if(stopTx == true) - { - outputStream_stop(outStream); - outputStream_sync(outStream, false); - stopTx = false; - txRunning = false; - idleBuffer = baseband_buffer.get(); - #if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0) - dsp_resetFilterState(&pwmFilterState); - #endif - } - else - { - idleBuffer = outputStream_getIdleBuffer(outStream); - } + idleBuffer = outputStream_getIdleBuffer(outStream); } #else void M17Modulator::sendBaseband()