From 2aabdb61ab4fbfb31471de1d9a4f606bcda9a9cd Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 8 Aug 2021 18:55:09 +0100 Subject: [PATCH] Remove the last traces of M17 packet mode and fix a buffer overrun bug. --- M17Defines.h | 15 ++------------- M17RX.cpp | 51 ++++++++------------------------------------------ M17RX.h | 4 +--- SerialPort.cpp | 37 ------------------------------------ SerialPort.h | 1 - Version.h | 2 +- 6 files changed, 12 insertions(+), 98 deletions(-) diff --git a/M17Defines.h b/M17Defines.h index de8ed31..0459b69 100644 --- a/M17Defines.h +++ b/M17Defines.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2018,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2018,2020,2021 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 @@ -27,18 +27,15 @@ const unsigned int M17_FRAME_LENGTH_SYMBOLS = M17_FRAME_LENGTH_BITS / 2U; const unsigned int M17_FRAME_LENGTH_SAMPLES = M17_FRAME_LENGTH_SYMBOLS * M17_RADIO_SYMBOL_LENGTH; const unsigned int M17_SYNC_LENGTH_BITS = 16U; +const unsigned int M17_SYNC_LENGTH_BYTES = M17_SYNC_LENGTH_BITS / 8U; const unsigned int M17_SYNC_LENGTH_SYMBOLS = M17_SYNC_LENGTH_BITS / 2U; const unsigned int M17_SYNC_LENGTH_SAMPLES = M17_SYNC_LENGTH_SYMBOLS * M17_RADIO_SYMBOL_LENGTH; const uint8_t M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U}; const uint8_t M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU}; -const uint8_t M17_PACKET_SYNC_BYTES[] = {0x75U, 0xFFU}; - -const uint8_t M17_SYNC_BYTES_LENGTH = 2U; const uint16_t M17_LINK_SETUP_SYNC_BITS = 0x55F7U; const uint16_t M17_STREAM_SYNC_BITS = 0xFF5DU; -const uint16_t M17_PACKET_SYNC_BITS = 0x75FFU; // 5 5 F 7 // 01 01 01 01 11 11 01 11 @@ -56,13 +53,5 @@ const int8_t M17_STREAM_SYNC_SYMBOLS_VALUES[] = {-3, -3, -3, -3, +3, +3, -3, +3} const uint8_t M17_STREAM_SYNC_SYMBOLS = 0x0DU; -// 7 5 F F -// 01 11 01 01 11 11 11 11 -// +3 -3 +3 +3 -3 -3 -3 -3 - -const int8_t M17_PACKET_SYNC_SYMBOLS_VALUES[] = {+3, -3, +3, +3, -3, -3, -3, -3}; - -const uint8_t M17_PACKET_SYNC_SYMBOLS = 0xB0U; - #endif diff --git a/M17RX.cpp b/M17RX.cpp index 6e10e35..15fc643 100644 --- a/M17RX.cpp +++ b/M17RX.cpp @@ -105,7 +105,6 @@ void CM17RX::samples(const q15_t* samples, uint16_t* rssi, uint8_t length) switch (m_state) { case M17RXS_LINK_SETUP: case M17RXS_STREAM: - case M17RXS_PACKET: processData(sample); break; default: @@ -127,9 +126,8 @@ void CM17RX::processNone(q15_t sample) { bool ret1 = correlateSync(M17_LINK_SETUP_SYNC_SYMBOLS, M17_LINK_SETUP_SYNC_SYMBOLS_VALUES, M17_LINK_SETUP_SYNC_BYTES, MAX_SYNC_SYMBOL_START_ERRS, MAX_SYNC_BIT_START_ERRS); bool ret2 = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_START_ERRS, MAX_SYNC_BIT_START_ERRS); - // bool ret3 = correlateSync(M17_PACKET_SYNC_SYMBOLS, M17_PACKET_SYNC_SYMBOLS_VALUES, M17_PACKET_SYNC_BYTES, MAX_SYNC_SYMBOL_START_ERRS, MAX_SYNC_BIT_START_ERRS); - if (ret1 || ret2 /* || ret3 */ ) { + if (ret1 || ret2) { // On the first sync, start the countdown to the state change if (m_countdown == 0U) { m_rssiAccum = 0U; @@ -144,7 +142,6 @@ void CM17RX::processNone(q15_t sample) if (ret1) m_nextState = M17RXS_LINK_SETUP; if (ret2) m_nextState = M17RXS_STREAM; - // if (ret3) m_nextState = M17RXS_PACKET; } } @@ -172,21 +169,17 @@ void CM17RX::processData(q15_t sample) if (m_dataPtr >= m_minSyncPtr && m_dataPtr <= m_maxSyncPtr) { bool ret1 = correlateSync(M17_LINK_SETUP_SYNC_SYMBOLS, M17_LINK_SETUP_SYNC_SYMBOLS_VALUES, M17_LINK_SETUP_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); bool ret2 = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); - // bool ret3 = correlateSync(M17_PACKET_SYNC_SYMBOLS, M17_PACKET_SYNC_SYMBOLS_VALUES, M17_PACKET_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); if (ret1) m_state = M17RXS_LINK_SETUP; if (ret2) m_state = M17RXS_STREAM; - // if (ret3) m_state = M17RXS_PACKET; } } else { if (m_dataPtr >= m_minSyncPtr || m_dataPtr <= m_maxSyncPtr) { bool ret1 = correlateSync(M17_LINK_SETUP_SYNC_SYMBOLS, M17_LINK_SETUP_SYNC_SYMBOLS_VALUES, M17_LINK_SETUP_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); bool ret2 = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); - // bool ret3 = correlateSync(M17_PACKET_SYNC_SYMBOLS, M17_PACKET_SYNC_SYMBOLS_VALUES, M17_PACKET_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); if (ret1) m_state = M17RXS_LINK_SETUP; if (ret2) m_state = M17RXS_STREAM; - // if (ret3) m_state = M17RXS_PACKET; } } @@ -211,9 +204,6 @@ void CM17RX::processData(q15_t sample) case M17RXS_STREAM: DEBUG4("M17RX: stream sync found pos/centre/threshold", m_syncPtr, m_centreVal, m_thresholdVal); break; - case M17RXS_PACKET: - DEBUG4("M17RX: packet sync found pos/centre/threshold", m_syncPtr, m_centreVal, m_thresholdVal); - break; default: break; } @@ -238,8 +228,7 @@ void CM17RX::processData(q15_t sample) m_nextState = M17RXS_NONE; m_maxCorr = 0; } else { - frame[0U] = 0x00U; - frame[0U] |= m_lostCount == (MAX_SYNC_FRAMES - 1U) ? 0x01U : 0x00U; + frame[0U] = m_lostCount == (MAX_SYNC_FRAMES - 1U) ? 0x01U : 0x00U; switch (m_state) { case M17RXS_LINK_SETUP: @@ -248,9 +237,6 @@ void CM17RX::processData(q15_t sample) case M17RXS_STREAM: writeRSSIStream(frame); break; - case M17RXS_PACKET: - writeRSSIPacket(frame); - break; default: break; } @@ -312,11 +298,11 @@ bool CM17RX::correlateSync(uint8_t syncSymbols, const int8_t* syncSymbolValues, if (startPtr >= M17_FRAME_LENGTH_SAMPLES) startPtr -= M17_FRAME_LENGTH_SAMPLES; - uint8_t sync[M17_SYNC_BYTES_LENGTH]; + uint8_t sync[M17_SYNC_LENGTH_BYTES]; samplesToBits(startPtr, M17_SYNC_LENGTH_SYMBOLS, sync, 0U, m_centreVal, m_thresholdVal); uint8_t errs = 0U; - for (uint8_t i = 0U; i < M17_SYNC_BYTES_LENGTH; i++) + for (uint8_t i = 0U; i < M17_SYNC_LENGTH_BYTES; i++) errs += countBits8(sync[i] ^ syncBytes[i]); if (errs <= maxBitErrs) { @@ -441,8 +427,8 @@ void CM17RX::writeRSSILinkSetup(uint8_t* data) if (m_rssiCount > 0U) { uint16_t rssi = m_rssiAccum / m_rssiCount; - data[121U] = (rssi >> 8) & 0xFFU; - data[122U] = (rssi >> 0) & 0xFFU; + data[49U] = (rssi >> 8) & 0xFFU; + data[50U] = (rssi >> 0) & 0xFFU; serial.writeM17LinkSetup(data, M17_FRAME_LENGTH_BYTES + 3U); } else { @@ -462,8 +448,8 @@ void CM17RX::writeRSSIStream(uint8_t* data) if (m_rssiCount > 0U) { uint16_t rssi = m_rssiAccum / m_rssiCount; - data[121U] = (rssi >> 8) & 0xFFU; - data[122U] = (rssi >> 0) & 0xFFU; + data[49U] = (rssi >> 8) & 0xFFU; + data[50U] = (rssi >> 0) & 0xFFU; serial.writeM17Stream(data, M17_FRAME_LENGTH_BYTES + 3U); } else { @@ -477,26 +463,5 @@ void CM17RX::writeRSSIStream(uint8_t* data) m_rssiCount = 0U; } -void CM17RX::writeRSSIPacket(uint8_t* data) -{ -#if defined(SEND_RSSI_DATA) - if (m_rssiCount > 0U) { - uint16_t rssi = m_rssiAccum / m_rssiCount; - - data[121U] = (rssi >> 8) & 0xFFU; - data[122U] = (rssi >> 0) & 0xFFU; - - serial.writeM17Packet(data, M17_FRAME_LENGTH_BYTES + 3U); - } else { - serial.writeM17Packet(data, M17_FRAME_LENGTH_BYTES + 1U); - } -#else - serial.writeM17Packet(data, M17_FRAME_LENGTH_BYTES + 1U); -#endif - - m_rssiAccum = 0U; - m_rssiCount = 0U; -} - #endif diff --git a/M17RX.h b/M17RX.h index 7506551..de6ed6d 100644 --- a/M17RX.h +++ b/M17RX.h @@ -28,8 +28,7 @@ enum M17RX_STATE { M17RXS_NONE, M17RXS_LINK_SETUP, - M17RXS_STREAM, - M17RXS_PACKET + M17RXS_STREAM }; class CM17RX { @@ -70,7 +69,6 @@ private: void samplesToBits(uint16_t start, uint16_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold); void writeRSSILinkSetup(uint8_t* data); void writeRSSIStream(uint8_t* data); - void writeRSSIPacket(uint8_t* data); }; #endif diff --git a/SerialPort.cpp b/SerialPort.cpp index 3a51798..6eb6043 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -1329,20 +1329,6 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l sendNAK(type, err); } break; - - case MMDVM_M17_PACKET: - if (m_m17Enable) { - if (m_modemState == STATE_IDLE || m_modemState == STATE_M17) - err = m17TX.writeData(buffer, length); - } - if (err == 0U) { - if (m_modemState == STATE_IDLE) - setMode(STATE_M17); - } else { - DEBUG2("Received invalid M17 packet data", err); - sendNAK(type, err); - } - break; #endif #if defined(MODE_POCSAG) @@ -1740,29 +1726,6 @@ void CSerialPort::writeM17Stream(const uint8_t* data, uint8_t length) writeInt(1U, reply, count); } -void CSerialPort::writeM17Packet(const uint8_t* data, uint8_t length) -{ - if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE) - return; - - if (!m_m17Enable) - return; - - uint8_t reply[130U]; - - reply[0U] = MMDVM_FRAME_START; - reply[1U] = 0U; - reply[2U] = MMDVM_M17_PACKET; - - uint8_t count = 3U; - for (uint8_t i = 0U; i < length; i++, count++) - reply[count] = data[i]; - - reply[1U] = count; - - writeInt(1U, reply, count); -} - void CSerialPort::writeM17Lost() { if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE) diff --git a/SerialPort.h b/SerialPort.h index ccd2b6e..5a309e7 100644 --- a/SerialPort.h +++ b/SerialPort.h @@ -67,7 +67,6 @@ public: #if defined(MODE_M17) void writeM17LinkSetup(const uint8_t* data, uint8_t length); void writeM17Stream(const uint8_t* data, uint8_t length); - void writeM17Packet(const uint8_t* data, uint8_t length); void writeM17Lost(); #endif diff --git a/Version.h b/Version.h index 9841303..1afbd05 100644 --- a/Version.h +++ b/Version.h @@ -19,7 +19,7 @@ #if !defined(VERSION_H) #define VERSION_H -#define VERSION "20210719" +#define VERSION "20210808" #endif