Merge remote-tracking branch 'upstream/FM' into FM

This commit is contained in:
m0vse 2020-04-27 14:19:12 +01:00
commit 980c529107
7 changed files with 25 additions and 41 deletions

20
FM.cpp
View File

@ -54,7 +54,7 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length)
for (; i < length; i++) { for (; i < length; i++) {
q15_t currentSample = samples[i];//save to a local variable to avoid indirection on every access q15_t currentSample = samples[i];//save to a local variable to avoid indirection on every access
CTCSSState ctcssState = m_ctcssRX.process(getUnscaledSample(currentSample)); CTCSSState ctcssState = m_ctcssRX.process(currentSample);
if (CTCSS_NOT_READY(ctcssState) && m_modemState != STATE_FM) { if (CTCSS_NOT_READY(ctcssState) && m_modemState != STATE_FM) {
//Not enough samples to determine if you have CTCSS, just carry on //Not enough samples to determine if you have CTCSS, just carry on
@ -144,7 +144,7 @@ uint8_t CFM::setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_
return m_rfAck.setParams(rfAck, speed, frequency, level, level); 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_useCOS = useCOS;
m_rxBoost = q15_t(rxBoost); m_rxBoost = q15_t(rxBoost);
@ -156,7 +156,7 @@ uint8_t CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFreque
m_timeoutTone.setParams(timeoutLevel); m_timeoutTone.setParams(timeoutLevel);
m_blanking.setParams(maxDev, timeoutLevel); m_blanking.setParams(maxDev, timeoutLevel);
uint8_t ret = m_ctcssRX.setParams(ctcssFrequency, ctcssThreshold); uint8_t ret = m_ctcssRX.setParams(ctcssFrequency, ctcssThreshold, rxLevel);
if (ret != 0U) if (ret != 0U)
return ret; return ret;
@ -397,17 +397,3 @@ void CFM::beginRelaying()
m_timeoutTimer.start(); m_timeoutTimer.start();
m_ackMinTimer.start(); m_ackMinTimer.start();
} }
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;
else
sample31 -= rxLevel >> 1;
sample31 /= rxLevel;
return q15_t(sample31);
}

4
FM.h
View File

@ -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 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 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: private:
CFMKeyer m_callsign; CFMKeyer m_callsign;
@ -90,8 +90,6 @@ private:
void sendCallsign(); void sendCallsign();
void beginRelaying(); void beginRelaying();
q15_t getUnscaledSample(q15_t sample);
}; };
#endif #endif

View File

@ -86,12 +86,15 @@ m_threshold(0),
m_count(0U), m_count(0U),
m_q0(0), m_q0(0),
m_q1(0), m_q1(0),
m_result(CTS_NONE) m_result(CTS_NONE),
m_rxLevelInverse(1)
{ {
} }
uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold) uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold, uint8_t level)
{ {
m_rxLevelInverse = 511 / q15_t(level);
m_coeffDivTwo = 0; m_coeffDivTwo = 0;
for (uint8_t i = 0U; i < CTCSS_TABLE_DATA_LEN; i++) { for (uint8_t i = 0U; i < CTCSS_TABLE_DATA_LEN; i++) {
@ -111,6 +114,8 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold)
CTCSSState CFMCTCSSRX::process(q15_t sample) CTCSSState CFMCTCSSRX::process(q15_t sample)
{ {
q31_t sample31 = q31_t(sample) * m_rxLevelInverse;
m_result = m_result & (~CTS_READY); m_result = m_result & (~CTS_READY);
q31_t q2 = m_q1; q31_t q2 = m_q1;
@ -122,7 +127,7 @@ CTCSSState CFMCTCSSRX::process(q15_t sample)
q31_t t3 = t2 * 2; q31_t t3 = t2 * 2;
// m_q0 = m_coeffDivTwo * m_q1 * 2 - q2 + sample // m_q0 = m_coeffDivTwo * m_q1 * 2 - q2 + sample
m_q0 = t3 - q2 + q31_t(sample); m_q0 = t3 - q2 + sample31;
m_count++; m_count++;
if (m_count == N) { if (m_count == N) {

View File

@ -53,7 +53,7 @@ class CFMCTCSSRX {
public: public:
CFMCTCSSRX(); CFMCTCSSRX();
uint8_t setParams(uint8_t frequency, uint8_t threshold); uint8_t setParams(uint8_t frequency, uint8_t threshold, uint8_t level);
CTCSSState process(q15_t sample); CTCSSState process(q15_t sample);
@ -68,6 +68,7 @@ private:
q31_t m_q0; q31_t m_q0;
q31_t m_q1; q31_t m_q1;
CTCSSState m_result; CTCSSState m_result;
q15_t m_rxLevelInverse;
}; };
#endif #endif

5
IO.cpp
View File

@ -592,8 +592,3 @@ bool CIO::hasLockout() const
{ {
return m_lockout; return m_lockout;
} }
q15_t CIO::getRxLevel() const
{
return m_rxLevel;
}

4
IO.h
View File

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -56,8 +56,6 @@ public:
void selfTest(); void selfTest();
q15_t getRxLevel() const;
private: private:
bool m_started; bool m_started;

View File

@ -101,7 +101,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U;
#define HW_TYPE "MMDVM" #define HW_TYPE "MMDVM"
#endif #endif
#define DESCRIPTION "20200426 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" #define DESCRIPTION "20200427 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)"
#if defined(GITVERSION) #if defined(GITVERSION)
#define concat(h, a, b, c) h " " a " " b " GitID #" c "" #define concat(h, a, b, c) h " " a " " b " GitID #" c ""
@ -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) uint8_t CSerialPort::setFMParams3(const uint8_t* data, uint8_t length)
{ {
if (length < 10U) if (length < 11U)
return 4U; return 4U;
uint16_t timeout = data[0U] * 5U; 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 rxBoost = data[8U];
uint8_t maxDev = data[9U]; 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) uint8_t CSerialPort::setMode(const uint8_t* data, uint8_t length)