Change the LinkMode state machine.

This commit is contained in:
Jonathan Naylor 2021-09-06 22:50:40 +01:00
parent ed6bd66fab
commit 6a4dad4c44
2 changed files with 82 additions and 68 deletions

148
FM.cpp
View File

@ -66,7 +66,9 @@ m_extEnabled(false),
m_rxLevel(1), m_rxLevel(1),
m_inputRFRB(2401U), // 100ms of audio + 1 sample m_inputRFRB(2401U), // 100ms of audio + 1 sample
m_outputRFRB(2400U), // 100ms of audio m_outputRFRB(2400U), // 100ms of audio
m_inputExtRB() m_inputExtRB(),
m_rfSignal(false),
m_extSignal(false)
{ {
m_statusTimer.setTimeout(1U, 0U); m_statusTimer.setTimeout(1U, 0U);
m_reverseTimer.setTimeout(0U, 150U); m_reverseTimer.setTimeout(0U, 150U);
@ -158,28 +160,42 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length)
if (m_modemState != STATE_FM) if (m_modemState != STATE_FM)
continue; continue;
if (m_state == FS_LISTENING && !m_rfAck.isWanted() && !m_extAck.isWanted() && !m_callsign.isWanted() && !m_reverseTimer.isRunning()) q15_t currentSample;
continue;
q15_t currentSample = currentRFSample; if (m_linkMode) {
q15_t currentBoost = m_rfAudioBoost; if (m_rfSignal && m_extEnabled) {
if (m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) { q15_t currentSample = m_blanking.process(currentRFSample);
currentSample = currentExtSample; m_downSampler.addSample(currentSample);
currentBoost = m_extAudioBoost;
}
// Only let RF audio through when relaying RF audio
if (m_duplex) {
if (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF || m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) {
currentSample = m_blanking.process(currentSample);
if (m_extEnabled && (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF))
m_downSampler.addSample(currentSample);
currentSample *= currentBoost;
} else {
currentSample = 0;
} }
if (m_extSignal)
currentSample = currentExtSample * m_extAudioBoost;
if (!m_extSignal)
continue;
} else { } else {
if (m_state == FS_LISTENING && !m_rfAck.isWanted() && !m_extAck.isWanted() && !m_callsign.isWanted() && !m_reverseTimer.isRunning())
continue;
q15_t currentSample = currentRFSample;
q15_t currentBoost = m_rfAudioBoost;
if (m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) {
currentSample = currentExtSample;
currentBoost = m_extAudioBoost;
}
// Only let RF audio through when relaying RF audio
if (m_duplex) {
if (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF || m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) {
currentSample = m_blanking.process(currentSample);
if (m_extEnabled && (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF))
m_downSampler.addSample(currentSample);
currentSample *= currentBoost;
} else {
currentSample = 0;
}
} else {
if (m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) { if (m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) {
currentSample *= currentBoost; currentSample *= currentBoost;
} else { } else {
@ -187,6 +203,7 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length)
m_downSampler.addSample(currentSample); m_downSampler.addSample(currentSample);
continue; continue;
} }
}
} }
if (!m_callsign.isRunning() && !m_extAck.isRunning()) if (!m_callsign.isRunning() && !m_extAck.isRunning())
@ -281,6 +298,8 @@ void CFM::reset()
m_squelch.reset(); m_squelch.reset();
m_needReverse = false; m_needReverse = false;
m_rfSignal = false;
m_extSignal = false;
} }
uint8_t CFM::setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd, bool callsignAtLatch) uint8_t CFM::setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd, bool callsignAtLatch)
@ -1010,65 +1029,58 @@ void CFM::timeoutExtWaitStateSimplex(bool validSignal)
void CFM::linkStateMachine(bool validRFSignal, bool validExtSignal) void CFM::linkStateMachine(bool validRFSignal, bool validExtSignal)
{ {
switch (m_state) { if (validRFSignal && !m_rfSignal) {
case FS_LISTENING: io.setDecode(true);
if (validRFSignal) { io.setADCDetection(true);
io.setDecode(true);
io.setADCDetection(true);
if (m_duplex) if (!m_extSignal) {
insertSilence(50U); DEBUG1("State to RELAYING_RF");
m_state = FS_RELAYING_RF;
m_statusTimer.start();
serial.writeFMStatus(m_state);
}
DEBUG1("State to RELAYING_RF"); m_rfSignal = true;
m_state = FS_RELAYING_RF; }
m_statusTimer.start(); if (validExtSignal && !m_extSignal) {
serial.writeFMStatus(m_state); if (!m_rfSignal) {
} else if (validExtSignal) { DEBUG1("State to RELAYING_EXT");
io.setDecode(true); m_state = FS_RELAYING_EXT;
io.setADCDetection(true); m_statusTimer.start();
serial.writeFMStatus(m_state);
}
insertSilence(50U); insertSilence(50U);
DEBUG1("State to RELAYING_EXT"); m_extSignal = true;
m_state = FS_RELAYING_EXT; }
m_statusTimer.start(); if (!validRFSignal && m_rfSignal) {
serial.writeFMStatus(m_state); io.setDecode(false);
} io.setADCDetection(false);
break;
case FS_RELAYING_RF: if (!m_extSignal) {
if (!validRFSignal) { DEBUG1("State to LISTENING");
io.setDecode(false); m_state = FS_LISTENING;
io.setADCDetection(false); m_statusTimer.stop();
}
DEBUG1("State to LISTENING"); m_rfSignal = false;
m_state = FS_LISTENING;
if (m_extEnabled) if (m_extEnabled)
serial.writeFMEOT(); serial.writeFMEOT();
}
if (m_duplex) if (!validExtSignal && m_extSignal) {
m_needReverse = true; if (!m_rfSignal) {
DEBUG1("State to LISTENING");
m_state = FS_LISTENING;
m_statusTimer.stop();
}
m_statusTimer.stop(); m_needReverse = true;
} m_extSignal = false;
break;
case FS_RELAYING_EXT:
if (!validExtSignal) {
io.setDecode(false);
io.setADCDetection(false);
DEBUG1("State to LISTENING");
m_state = FS_LISTENING;
m_needReverse = true;
m_statusTimer.stop();
}
break;
} }
} }

2
FM.h
View File

@ -108,6 +108,8 @@ private:
CRingBuffer<q15_t> m_inputRFRB; CRingBuffer<q15_t> m_inputRFRB;
CRingBuffer<q15_t> m_outputRFRB; CRingBuffer<q15_t> m_outputRFRB;
CFMUpSampler m_inputExtRB; CFMUpSampler m_inputExtRB;
bool m_rfSignal;
bool m_extSignal;
void stateMachine(bool validRFSignal, bool validExtSignal); void stateMachine(bool validRFSignal, bool validExtSignal);