From 50a3afd66fcc7b278e775ba3317e066471bf3e40 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 19 Sep 2021 15:15:37 +0100 Subject: [PATCH] Change to the new method of M17 EOT transmission. --- M17Control.cpp | 66 +++++++++++++++++--------------------------------- M17Control.h | 2 -- M17Defines.h | 1 + Modem.cpp | 1 + Sync.cpp | 7 ++++++ Sync.h | 1 + Version.h | 2 +- 7 files changed, 33 insertions(+), 47 deletions(-) diff --git a/M17Control.cpp b/M17Control.cpp index 50664a7..6834e94 100644 --- a/M17Control.cpp +++ b/M17Control.cpp @@ -329,8 +329,18 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len) #if defined(DUMP_M17) writeFile(data + 2U); #endif - if (m_duplex) - writeQueueEOTRF(); + if (m_duplex) { + unsigned char rfData[M17_FRAME_LENGTH_BYTES + 2U]; + + rfData[0U] = TAG_EOT; + rfData[1U] = 0x00U; + + // Generate the sync + for (unsigned int i = 0U; i < M17_FRAME_LENGTH_BYTES; i += M17_SYNC_LENGTH_BYTES) + CSync::addM17EOTSync(rfData + 2U + i); + + writeQueueRF(rfData); + } if (m_network != NULL && m_rfTimeoutTimer.isRunning() && !m_rfTimeoutTimer.hasExpired()) { unsigned char netData[M17_LSF_LENGTH_BYTES + M17_FN_LENGTH_BYTES + M17_PAYLOAD_LENGTH_BYTES + M17_CRC_LENGTH_BYTES]; @@ -560,7 +570,16 @@ void CM17Control::writeNetwork() LogMessage("M17, received network end of transmission from %s to %s, %.1f seconds", source.c_str(), dest.c_str(), float(m_netFrames) / 25.0F); - writeQueueEOTNet(); + unsigned char data[M17_FRAME_LENGTH_BYTES + 2U]; + + data[0U] = TAG_EOT; + data[1U] = 0x00U; + + // Generate the sync + for (unsigned int i = 0U; i < M17_FRAME_LENGTH_BYTES; i += M17_SYNC_LENGTH_BYTES) + CSync::addM17EOTSync(data + 2U + i); + + writeQueueNet(data); writeEndNet(); } @@ -686,28 +705,6 @@ void CM17Control::writeQueueRF(const unsigned char *data) m_queue.addData(data, len); } -void CM17Control::writeQueueEOTRF() -{ - if (m_netState != RS_NET_IDLE) - return; - - if (m_rfTimeoutTimer.isRunning() && m_rfTimeoutTimer.hasExpired()) - return; - - const unsigned char len = 1U; - - unsigned int space = m_queue.freeSpace(); - if (space < (len + 1U)) { - LogError("M17, overflow in the M17 RF queue"); - return; - } - - m_queue.addData(&len, 1U); - - const unsigned char data = TAG_EOT; - m_queue.addData(&data, len); -} - void CM17Control::writeQueueNet(const unsigned char *data) { assert(data != NULL); @@ -728,25 +725,6 @@ void CM17Control::writeQueueNet(const unsigned char *data) m_queue.addData(data, len); } -void CM17Control::writeQueueEOTNet() -{ - if (m_netTimeoutTimer.isRunning() && m_netTimeoutTimer.hasExpired()) - return; - - const unsigned char len = 1U; - - unsigned int space = m_queue.freeSpace(); - if (space < (len + 1U)) { - LogError("M17, overflow in the M17 RF queue"); - return; - } - - m_queue.addData(&len, 1U); - - const unsigned char data = TAG_EOT; - m_queue.addData(&data, len); -} - void CM17Control::interleaver(const unsigned char* in, unsigned char* out) const { assert(in != NULL); diff --git a/M17Control.h b/M17Control.h index f7cc775..ad9ef4c 100644 --- a/M17Control.h +++ b/M17Control.h @@ -82,10 +82,8 @@ private: bool processRFHeader(bool lateEntry); void writeQueueRF(const unsigned char* data); - void writeQueueEOTRF(); void writeQueueNet(const unsigned char* data); - void writeQueueEOTNet(); void writeNetwork(); diff --git a/M17Defines.h b/M17Defines.h index ab69859..35fdc6b 100644 --- a/M17Defines.h +++ b/M17Defines.h @@ -26,6 +26,7 @@ const unsigned int M17_FRAME_LENGTH_BYTES = M17_FRAME_LENGTH_BITS / 8U; const unsigned char M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U}; const unsigned char M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU}; +const unsigned char M17_EOT_SYNC_BYTES[] = {0x55U, 0x5DU}; const unsigned int M17_SYNC_LENGTH_BITS = 16U; const unsigned int M17_SYNC_LENGTH_BYTES = M17_SYNC_LENGTH_BITS / 8U; diff --git a/Modem.cpp b/Modem.cpp index 4b1b535..348d690 100644 --- a/Modem.cpp +++ b/Modem.cpp @@ -1534,6 +1534,7 @@ bool CModem::writeM17Data(const unsigned char* data, unsigned int length) break; case TAG_EOT: buffer[2U] = MMDVM_M17_EOT; + ::memcpy(buffer + 3U, data + 1U, length - 1U); break; default: return false; diff --git a/Sync.cpp b/Sync.cpp index 6d38bbd..1fcb2c4 100644 --- a/Sync.cpp +++ b/Sync.cpp @@ -99,3 +99,10 @@ void CSync::addM17StreamSync(unsigned char* data) ::memcpy(data, M17_STREAM_SYNC_BYTES, M17_SYNC_LENGTH_BYTES); } +void CSync::addM17EOTSync(unsigned char* data) +{ + assert(data != NULL); + + ::memcpy(data, M17_EOT_SYNC_BYTES, M17_SYNC_LENGTH_BYTES); +} + diff --git a/Sync.h b/Sync.h index 6190ae1..7f75711 100644 --- a/Sync.h +++ b/Sync.h @@ -35,6 +35,7 @@ public: static void addM17LinkSetupSync(unsigned char* data); static void addM17StreamSync(unsigned char* data); + static void addM17EOTSync(unsigned char* data); private: }; diff --git a/Version.h b/Version.h index 44c1823..aba5baa 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20210906"; +const char* VERSION = "20210919"; #endif