diff --git a/DMRIdleRX.cpp b/DMRIdleRX.cpp index 2121a47..28b716f 100644 --- a/DMRIdleRX.cpp +++ b/DMRIdleRX.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG +#define WANT_DEBUG #include "Config.h" #include "Globals.h" @@ -47,7 +47,8 @@ m_endPtr(NOENDPTR), m_maxCorr(0), m_centre(0), m_threshold(0), -m_colorCode(0U) +m_colorCode(0U), +m_scale(SCALING_FACTOR) { } @@ -103,7 +104,7 @@ void CDMRIdleRX::processSample(q15_t sample) if (corr > m_maxCorr) { q15_t centre = (max + min) >> 1; - q31_t v1 = (max - centre) * SCALING_FACTOR; + q31_t v1 = (max - centre) * m_scale; q15_t threshold = q15_t(v1 >> 15); uint8_t sync[DMR_SYNC_BYTES_LENGTH]; @@ -200,3 +201,20 @@ void CDMRIdleRX::setColorCode(uint8_t colorCode) m_colorCode = colorCode; } +void CDMRIdleRX::setThreshold(int8_t percent) +{ + q31_t res = SCALING_FACTOR * 1000; + + if (percent > 0) { + for (int8_t i = 0; i < percent; i++) + res += SCALING_FACTOR; + } else if (percent < 0) { + for (int8_t i = 0; i < -percent; i++) + res -= SCALING_FACTOR; + } + + m_scale = res / 1000; + + DEBUG2("DMR, Scale", m_scale); +} + diff --git a/DMRIdleRX.h b/DMRIdleRX.h index fbb82fa..72b251f 100644 --- a/DMRIdleRX.h +++ b/DMRIdleRX.h @@ -28,6 +28,7 @@ public: void samples(const q15_t* samples, uint8_t length); + void setThreshold(int8_t threshold); void setColorCode(uint8_t colorCode); void reset(); @@ -42,6 +43,7 @@ private: q15_t m_centre; q15_t m_threshold; uint8_t m_colorCode; + q15_t m_scale; void processSample(q15_t sample); void samplesToBits(uint16_t start, uint8_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold); diff --git a/DMRRX.cpp b/DMRRX.cpp index 9137b94..3c93b3c 100644 --- a/DMRRX.cpp +++ b/DMRRX.cpp @@ -56,6 +56,12 @@ void CDMRRX::setColorCode(uint8_t colorCode) m_slot2RX.setColorCode(colorCode); } +void CDMRRX::setThreshold(int8_t threshold) +{ + m_slot1RX.setThreshold(threshold); + m_slot2RX.setThreshold(threshold); +} + void CDMRRX::setDelay(uint8_t delay) { m_slot1RX.setDelay(delay); diff --git a/DMRRX.h b/DMRRX.h index 2f8810d..b3584de 100644 --- a/DMRRX.h +++ b/DMRRX.h @@ -29,6 +29,7 @@ public: void samples(const q15_t* samples, const uint8_t* control, uint8_t length); void setColorCode(uint8_t colorCode); + void setThreshold(int8_t threshold); void setDelay(uint8_t delay); void reset(); diff --git a/DMRSlotRX.cpp b/DMRSlotRX.cpp index be2ec48..fc67529 100644 --- a/DMRSlotRX.cpp +++ b/DMRSlotRX.cpp @@ -61,7 +61,8 @@ m_colorCode(0U), m_delay(0U), m_state(DMRRXS_NONE), m_n(0U), -m_type(0U) +m_type(0U), +m_scale(SCALING_FACTOR) { } @@ -270,7 +271,7 @@ void CDMRSlotRX::correlateSync(bool first) if (corr > m_maxCorr) { q15_t centre = (max + min) >> 1; - q31_t v1 = (max - centre) * SCALING_FACTOR; + q31_t v1 = (max - centre) * m_scale; q15_t threshold = q15_t(v1 >> 15); uint8_t sync[DMR_SYNC_BYTES_LENGTH]; @@ -371,3 +372,20 @@ void CDMRSlotRX::setDelay(uint8_t delay) m_delay = delay; } +void CDMRSlotRX::setThreshold(int8_t percent) +{ + q31_t res = SCALING_FACTOR * 1000; + + if (percent > 0) { + for (int8_t i = 0; i < percent; i++) + res += SCALING_FACTOR; + } else if (percent < 0) { + for (int8_t i = 0; i < -percent; i++) + res -= SCALING_FACTOR; + } + + m_scale = res / 1000; + + DEBUG2("DMR, Scale", m_scale); +} + diff --git a/DMRSlotRX.h b/DMRSlotRX.h index 994839f..023b97c 100644 --- a/DMRSlotRX.h +++ b/DMRSlotRX.h @@ -37,6 +37,7 @@ public: bool processSample(q15_t sample); void setColorCode(uint8_t colorCode); + void setThreshold(int8_t threshold); void setDelay(uint8_t delay); void reset(); @@ -62,6 +63,7 @@ private: DMRRX_STATE m_state; uint8_t m_n; uint8_t m_type; + q15_t m_scale; void correlateSync(bool first); void samplesToBits(uint16_t start, uint8_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold); diff --git a/SerialPort.cpp b/SerialPort.cpp index e688b00..b9a6e57 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -185,7 +185,7 @@ void CSerialPort::getVersion() uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) { - if (length < 14U) + if (length < 16U) return 4U; bool rxInvert = (data[0U] & 0x01U) == 0x01U; @@ -240,6 +240,9 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) int8_t ysfLevel1 = int8_t(data[12U]) - 128; int8_t ysfLevel3 = int8_t(data[13U]) - 128; + int8_t dmrThreshold = int8_t(data[14U]) - 128; + int8_t ysfThreshold = int8_t(data[15U]) - 128; + m_modemState = modemState; m_dstarEnable = dstarEnable; @@ -258,6 +261,10 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) dmrTX.setLevels(dmrLevel1, dmrLevel3); ysfTX.setLevels(ysfLevel1, ysfLevel3); + dmrIdleRX.setThreshold(dmrThreshold); + dmrRX.setThreshold(dmrThreshold); + ysfRX.setThreshold(ysfThreshold); + io.setParameters(rxInvert, txInvert, pttInvert, rxLevel, txLevel); io.start(); diff --git a/YSFRX.cpp b/YSFRX.cpp index 37826af..477c3b2 100644 --- a/YSFRX.cpp +++ b/YSFRX.cpp @@ -55,7 +55,8 @@ m_bufferPtr(0U), m_symbolPtr(0U), m_lostCount(0U), m_centre(0), -m_threshold(0) +m_threshold(0), +m_scale(SCALING_FACTOR) { m_buffer = m_outBuffer + 1U; } @@ -123,7 +124,7 @@ void CYSFRX::processNone(q15_t sample) q15_t centre = (max + min) >> 1; - q31_t v1 = (max - centre) * SCALING_FACTOR; + q31_t v1 = (max - centre) * m_scale; q15_t threshold = q15_t(v1 >> 15); uint16_t ptr = m_symbolPtr + 1U; @@ -242,3 +243,20 @@ void CYSFRX::processData(q15_t sample) } } +void CYSFRX::setThreshold(int8_t percent) +{ + q31_t res = SCALING_FACTOR * 1000; + + if (percent > 0) { + for (int8_t i = 0; i < percent; i++) + res += SCALING_FACTOR; + } else if (percent < 0) { + for (int8_t i = 0; i < -percent; i++) + res -= SCALING_FACTOR; + } + + m_scale = res / 1000; + + DEBUG2("YSF, Scale", m_scale); +} + diff --git a/YSFRX.h b/YSFRX.h index 22228ce..32a8c9e 100644 --- a/YSFRX.h +++ b/YSFRX.h @@ -35,6 +35,8 @@ public: void reset(); + void setThreshold(int8_t threshold); + private: uint32_t m_pll; bool m_prev; @@ -49,6 +51,7 @@ private: uint16_t m_lostCount; q15_t m_centre; q15_t m_threshold; + q15_t m_scale; void processNone(q15_t sample); void processData(q15_t sample);