diff --git a/CalFM.cpp b/CalFM.cpp index a654b48..3f847cc 100644 --- a/CalFM.cpp +++ b/CalFM.cpp @@ -38,13 +38,13 @@ const struct TONE_TABLE { const uint8_t TONE_TABLE_DATA_LEN = 6U; CCalFM::CCalFM() : -m_tone(NULL), m_frequency(0), m_length(0), +m_tone(NULL), m_level(128*32), m_transmit(false), -m_lastState(STATE_IDLE), -m_audioSeq(0) +m_audioSeq(0), +m_lastState(STATE_IDLE) { } diff --git a/FM.cpp b/FM.cpp index 1aaf0be..e843996 100644 --- a/FM.cpp +++ b/FM.cpp @@ -57,7 +57,7 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length) for (; i < length; i++) { q15_t currentSample = samples[i];//save to a local variable to avoid indirection on every access - CTCSSState ctcssState = m_ctcssRX.process(currentSample); + uint8_t ctcssState = m_ctcssRX.process(currentSample); if (CTCSS_NOT_READY(ctcssState) && m_modemState != STATE_FM) { //Not enough samples to determine if you have CTCSS, just carry on @@ -123,7 +123,19 @@ void CFM::process() void CFM::reset() { + m_state = FS_LISTENING; + + m_callsignTimer.stop(); + m_timeoutTimer.stop(); + m_kerchunkTimer.stop(); + m_ackMinTimer.stop(); + m_ackDelayTimer.stop(); + m_hangTimer.stop(); + m_ctcssRX.reset(); + m_rfAck.stop(); + m_callsign.stop(); + m_timeoutTone.stop(); } 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) diff --git a/FMCTCSSRX.cpp b/FMCTCSSRX.cpp index f3f9047..ba0c03f 100644 --- a/FMCTCSSRX.cpp +++ b/FMCTCSSRX.cpp @@ -112,11 +112,11 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold, uint8_t leve return 0U; } -CTCSSState CFMCTCSSRX::process(q15_t sample) +uint8_t CFMCTCSSRX::process(q15_t sample) { q31_t sample31 = q31_t(sample) * m_rxLevelInverse; - m_result = m_result & (~CTS_READY); + m_result &= ~CTS_READY; q31_t q2 = m_q1; m_q1 = m_q0; @@ -150,13 +150,13 @@ CTCSSState CFMCTCSSRX::process(q15_t sample) q31_t value = t2 + t4 - t9; bool previousCTCSSValid = CTCSS_VALID(m_result); - m_result = m_result | CTS_READY; + m_result |= CTS_READY; if (value >= m_threshold) - m_result = m_result | CTS_VALID; + m_result |= CTS_VALID; else - m_result = m_result & ~CTS_VALID; + m_result &= ~CTS_VALID; - if(previousCTCSSValid != CTCSS_VALID(m_result)) + if (previousCTCSSValid != CTCSS_VALID(m_result)) DEBUG4("CTCSS Value / Threshold / Valid", value, m_threshold, CTCSS_VALID(m_result)); m_count = 0U; @@ -167,11 +167,6 @@ CTCSSState CFMCTCSSRX::process(q15_t sample) return m_result; } -CTCSSState CFMCTCSSRX::getState() -{ - return m_result; -} - void CFMCTCSSRX::reset() { m_q0 = 0; @@ -192,4 +187,3 @@ q15_t CFMCTCSSRX::q15Division(q15_t a, q15_t divisor) return a31 / divisor; } - diff --git a/FMCTCSSRX.h b/FMCTCSSRX.h index b5fea60..2caa9e6 100644 --- a/FMCTCSSRX.h +++ b/FMCTCSSRX.h @@ -21,28 +21,9 @@ #include "Config.h" -enum CTCSSState -{ - CTS_NONE = 0, - CTS_READY = 1, - CTS_VALID = 2, - CTS_READY_VALID = CTS_READY | CTS_VALID -}; - -inline CTCSSState operator|(CTCSSState a, CTCSSState b) -{ - return static_cast(static_cast(a) | static_cast(b)); -} - -inline CTCSSState operator&(CTCSSState a, CTCSSState b) -{ - return static_cast(static_cast(a) & static_cast(b)); -} - -inline CTCSSState operator~(CTCSSState a) -{ - return static_cast(~(static_cast(a))); -} +const uint8_t CTS_NONE = 0U; +const uint8_t CTS_READY = 1U; +const uint8_t CTS_VALID = 2U; #define CTCSS_READY(a) ((a & CTS_READY) != 0) #define CTCSS_NOT_READY(a) ((a & CTS_READY) == 0) @@ -55,22 +36,20 @@ public: uint8_t setParams(uint8_t frequency, uint8_t threshold, uint8_t level); - CTCSSState process(q15_t sample); - - CTCSSState getState(); + uint8_t process(q15_t sample); void reset(); private: - q15_t q15Division(q15_t a, q15_t divisor); + q63_t m_coeffDivTwo; + q31_t m_threshold; + uint16_t m_count; + q31_t m_q0; + q31_t m_q1; + uint8_t m_result; + q15_t m_rxLevelInverse; - q63_t m_coeffDivTwo; - q31_t m_threshold; - uint16_t m_count; - q31_t m_q0; - q31_t m_q1; - CTCSSState m_result; - q15_t m_rxLevelInverse; + q15_t q15Division(q15_t a, q15_t divisor); }; #endif diff --git a/SerialPort.cpp b/SerialPort.cpp index 3baa55b..3323d01 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -101,7 +101,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U; #define HW_TYPE "MMDVM" #endif -#define DESCRIPTION "20200501 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" +#define DESCRIPTION "20200502 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" #if defined(GITVERSION) #define concat(h, a, b, c) h " " a " " b " GitID #" c ""