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:
parent
3df8657b16
commit
a6f01c3e55
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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++)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue