diff --git a/FM.cpp b/FM.cpp index ad8b5f5..074de3d 100644 --- a/FM.cpp +++ b/FM.cpp @@ -41,7 +41,8 @@ m_filterStage2(32768, 0,-32768, 32768, -50339, 19052), m_filterStage3(32768, -65536, 32768, 32768, -64075, 31460), m_blanking(), m_useCOS(true), -m_rxBoost(1U) +m_rxBoost(1U), +m_rxLevel(128 * 128) { } @@ -144,10 +145,11 @@ uint8_t CFM::setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_ return m_rfAck.setParams(rfAck, speed, frequency, level, level); } -uint8_t CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, bool useCOS, uint8_t rxBoost, uint8_t maxDev) +uint8_t CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, bool useCOS, uint8_t rxBoost, uint8_t maxDev, uint8_t rxLevel) { m_useCOS = useCOS; m_rxBoost = q15_t(rxBoost); + m_rxLevel = q15_t(rxLevel * 128); m_timeoutTimer.setTimeout(timeout, 0U); m_kerchunkTimer.setTimeout(kerchunkTime, 0U); @@ -401,13 +403,14 @@ void CFM::beginRelaying() q15_t CFM::getUnscaledSample(q15_t sample) { // sample / rxLevel - q15_t rxLevel = io.getRxLevel(); q31_t sample31 = q31_t(sample) << 16; - if (((sample31 >> 31) & 1) == ((rxLevel >> 15) & 1)) - sample31 += rxLevel >> 1; + + if (((sample31 >> 31) & 1) == ((m_rxLevel >> 15) & 1)) + sample31 += m_rxLevel >> 1; else - sample31 -= rxLevel >> 1; - sample31 /= rxLevel; + sample31 -= m_rxLevel >> 1; + + sample31 /= m_rxLevel; return q15_t(sample31); } diff --git a/FM.h b/FM.h index f2190d7..1a07eb8 100644 --- a/FM.h +++ b/FM.h @@ -54,7 +54,7 @@ public: uint8_t 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); uint8_t setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_t minTime, uint16_t delay, uint8_t level); - uint8_t setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, bool useCOS, uint8_t rxBoost, uint8_t maxDev); + uint8_t setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, bool useCOS, uint8_t rxBoost, uint8_t maxDev, uint8_t rxLevel); private: CFMKeyer m_callsign; @@ -78,6 +78,7 @@ private: CFMBlanking m_blanking; bool m_useCOS; q15_t m_rxBoost; + q15_t m_rxLevel; void stateMachine(bool validSignal, uint8_t length); void listeningState(bool validSignal); diff --git a/IO.cpp b/IO.cpp index afd56b0..a737693 100644 --- a/IO.cpp +++ b/IO.cpp @@ -592,8 +592,3 @@ bool CIO::hasLockout() const { return m_lockout; } - -q15_t CIO::getRxLevel() const -{ - return m_rxLevel; -} diff --git a/IO.h b/IO.h index f3ac4f9..07ed700 100644 --- a/IO.h +++ b/IO.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017,2018,2020 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,8 +56,6 @@ public: void selfTest(); - q15_t getRxLevel() const; - private: bool m_started; diff --git a/SerialPort.cpp b/SerialPort.cpp index f729cb3..7a6e609 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -408,7 +408,7 @@ uint8_t CSerialPort::setFMParams2(const uint8_t* data, uint8_t length) uint8_t CSerialPort::setFMParams3(const uint8_t* data, uint8_t length) { - if (length < 10U) + if (length < 11U) return 4U; uint16_t timeout = data[0U] * 5U; @@ -425,8 +425,9 @@ uint8_t CSerialPort::setFMParams3(const uint8_t* data, uint8_t length) uint8_t rxBoost = data[8U]; uint8_t maxDev = data[9U]; + uint8_t rxLevel = data[10U]; - return fm.setMisc(timeout, timeoutLevel, ctcssFrequency, ctcssThreshold, ctcssLevel, kerchunkTime, hangTime, useCOS, rxBoost, maxDev); + return fm.setMisc(timeout, timeoutLevel, ctcssFrequency, ctcssThreshold, ctcssLevel, kerchunkTime, hangTime, useCOS, rxBoost, maxDev, rxLevel); } uint8_t CSerialPort::setMode(const uint8_t* data, uint8_t length)