Small refactoring of M17 modulator.

- made start() function return a boolean indicating the actual modulator status
- moved sending of preamble to a dedicated function
- renamed send() function to sendFrame()
This commit is contained in:
Silvano Seva 2024-04-13 19:40:46 +02:00
parent 3df8657b16
commit a6f01c3e55
3 changed files with 38 additions and 24 deletions

View File

@ -64,9 +64,16 @@ public:
void terminate(); 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 * 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 * @param isLast: flag signalling that current block is the last one being
* transmitted. * transmitted.
*/ */
void send(const frame_t& frame); void sendFrame(const frame_t& frame);
/** /**
* Terminate baseband transmission. * Terminate baseband transmission.

View File

@ -74,12 +74,33 @@ void M17Modulator::terminate()
baseband_buffer.reset(); 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; txRunning = true;
return true;
}
void M17Modulator::sendPreamble()
{
// Fill symbol buffer with preamble, made of alternated +3 and -3 symbols // Fill symbol buffer with preamble, made of alternated +3 and -3 symbols
for(size_t i = 0; i < symbols.size(); i += 2) for(size_t i = 0; i < symbols.size(); i += 2)
{ {
@ -89,21 +110,7 @@ void M17Modulator::start()
// Generate baseband signal and then start transmission // Generate baseband signal and then start transmission
symbolsToBaseband(); 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(); sendBaseband();
#endif
// Repeat baseband generation and transmission, this makes the preamble to // Repeat baseband generation and transmission, this makes the preamble to
// be long 80ms (two frames) // be long 80ms (two frames)
@ -111,8 +118,7 @@ void M17Modulator::start()
sendBaseband(); sendBaseband();
} }
void M17Modulator::sendFrame(const frame_t& frame)
void M17Modulator::send(const frame_t& frame)
{ {
auto it = symbols.begin(); auto it = symbols.begin();
for(size_t i = 0; i < frame.size(); i++) for(size_t i = 0; i < frame.size(); i++)

View File

@ -326,7 +326,8 @@ void OpMode_M17::txState(rtxStatus_t *const status)
modulator.invertPhase(invertTxPhase); modulator.invertPhase(invertTxPhase);
modulator.start(); modulator.start();
modulator.send(m17Frame); modulator.sendPreamble();
modulator.sendFrame(m17Frame);
} }
payload_t dataFrame; payload_t dataFrame;
@ -344,12 +345,12 @@ void OpMode_M17::txState(rtxStatus_t *const status)
} }
encoder.encodeStreamFrame(dataFrame, m17Frame, lastFrame); encoder.encodeStreamFrame(dataFrame, m17Frame, lastFrame);
modulator.send(m17Frame); modulator.sendFrame(m17Frame);
if(lastFrame) if(lastFrame)
{ {
encoder.encodeEotFrame(m17Frame); encoder.encodeEotFrame(m17Frame);
modulator.send(m17Frame); modulator.sendFrame(m17Frame);
modulator.stop(); modulator.stop();
} }
} }