diff --git a/openrtx/include/protocols/M17/M17Modulator.hpp b/openrtx/include/protocols/M17/M17Modulator.hpp index 090f935c..73f04ebc 100644 --- a/openrtx/include/protocols/M17/M17Modulator.hpp +++ b/openrtx/include/protocols/M17/M17Modulator.hpp @@ -64,9 +64,16 @@ public: void terminate(); /** - * Start baseband transmission and send an 80ms preamble. + * Start the modulator. + * + * @return true if the modulator has been successfully started. */ - void start(); + bool start(); + + /** + * Send an 80ms long transmission preamble. + */ + void sendPreamble(); /** * Generate and transmit the baseband signal obtained by 4FSK modulation of @@ -76,7 +83,7 @@ public: * @param isLast: flag signalling that current block is the last one being * transmitted. */ - void send(const frame_t& frame); + void sendFrame(const frame_t& frame); /** * Terminate baseband transmission. diff --git a/openrtx/src/protocols/M17/M17Modulator.cpp b/openrtx/src/protocols/M17/M17Modulator.cpp index febc1ca6..c5bb546c 100644 --- a/openrtx/src/protocols/M17/M17Modulator.cpp +++ b/openrtx/src/protocols/M17/M17Modulator.cpp @@ -74,12 +74,33 @@ void M17Modulator::terminate() baseband_buffer.reset(); } -void M17Modulator::start() +bool M17Modulator::start() { - if(txRunning) return; + if(txRunning) + return true; + + #ifndef PLATFORM_LINUX + outPath = audioPath_request(SOURCE_MCU, SINK_RTX, PRIO_TX); + if(outPath < 0) + return false; + + outStream = audioStream_start(outPath, baseband_buffer.get(), + 2*M17_FRAME_SAMPLES, M17_TX_SAMPLE_RATE, + STREAM_OUTPUT | BUF_CIRC_DOUBLE); + + if(outStream < 0) + return false; + + idleBuffer = outputStream_getIdleBuffer(outStream); + #endif txRunning = true; + return true; +} + +void M17Modulator::sendPreamble() +{ // Fill symbol buffer with preamble, made of alternated +3 and -3 symbols for(size_t i = 0; i < symbols.size(); i += 2) { @@ -89,21 +110,7 @@ void M17Modulator::start() // Generate baseband signal and then start transmission symbolsToBaseband(); - #ifndef PLATFORM_LINUX - outPath = audioPath_request(SOURCE_MCU, SINK_RTX, PRIO_TX); - if(outPath < 0) - { - txRunning = false; - return; - } - - outStream = audioStream_start(outPath, baseband_buffer.get(), - 2*M17_FRAME_SAMPLES, M17_TX_SAMPLE_RATE, - STREAM_OUTPUT | BUF_CIRC_DOUBLE); - idleBuffer = outputStream_getIdleBuffer(outStream); - #else sendBaseband(); - #endif // Repeat baseband generation and transmission, this makes the preamble to // be long 80ms (two frames) @@ -111,8 +118,7 @@ void M17Modulator::start() sendBaseband(); } - -void M17Modulator::send(const frame_t& frame) +void M17Modulator::sendFrame(const frame_t& frame) { auto it = symbols.begin(); for(size_t i = 0; i < frame.size(); i++) diff --git a/openrtx/src/rtx/OpMode_M17.cpp b/openrtx/src/rtx/OpMode_M17.cpp index 891f0bbe..c9f7e3bc 100644 --- a/openrtx/src/rtx/OpMode_M17.cpp +++ b/openrtx/src/rtx/OpMode_M17.cpp @@ -326,7 +326,8 @@ void OpMode_M17::txState(rtxStatus_t *const status) modulator.invertPhase(invertTxPhase); modulator.start(); - modulator.send(m17Frame); + modulator.sendPreamble(); + modulator.sendFrame(m17Frame); } payload_t dataFrame; @@ -344,12 +345,12 @@ void OpMode_M17::txState(rtxStatus_t *const status) } encoder.encodeStreamFrame(dataFrame, m17Frame, lastFrame); - modulator.send(m17Frame); + modulator.sendFrame(m17Frame); if(lastFrame) { encoder.encodeEotFrame(m17Frame); - modulator.send(m17Frame); + modulator.sendFrame(m17Frame); modulator.stop(); } }