From 299f53b551cb90789df77f73e9acb87920c71e48 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Thu, 21 Jul 2016 18:09:29 +0100 Subject: [PATCH] Don't use someone elses infill audio! --- DMRSlot.cpp | 24 +++++++++++++++++++----- DMRSlot.h | 8 ++------ DStarControl.cpp | 9 ++++++++- DStarControl.h | 1 + YSFControl.cpp | 6 ++++++ YSFControl.h | 1 + 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/DMRSlot.cpp b/DMRSlot.cpp index 2093401..8c69109 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -82,6 +82,7 @@ m_netBits(1U), m_rfErrs(0U), m_netErrs(0U), m_lastFrame(NULL), +m_lastFrameValid(false), m_lastEMB(), m_fp(NULL) { @@ -667,6 +668,8 @@ void CDMRSlot::writeEndNet(bool writeEnd) m_display->clearDMR(m_slotNo); + m_lastFrameValid = false; + m_networkWatchdog.stop(); m_netTimeoutTimer.stop(); m_packetTimer.stop(); @@ -757,6 +760,8 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) data[0U] = TAG_DATA; data[1U] = 0x00U; + m_lastFrameValid = false; + m_netTimeoutTimer.start(); m_packetTimer.start(); @@ -937,6 +942,8 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) if (!DMRAccessControl::validateAccess(id, did, m_slotNo, true)) return; + m_lastFrameValid = false; + m_netTimeoutTimer.start(); m_packetTimer.start(); @@ -1472,6 +1479,7 @@ bool CDMRSlot::insertSilence(const unsigned char* data, unsigned char seqNo) if (seq == seqNo) { // Just copy the data, nothing else to do here ::memcpy(m_lastFrame, data, DMR_FRAME_LENGTH_BYTES + 2U); + m_lastFrameValid = true; return true; } @@ -1490,6 +1498,7 @@ bool CDMRSlot::insertSilence(const unsigned char* data, unsigned char seqNo) insertSilence(count); ::memcpy(m_lastFrame, data, DMR_FRAME_LENGTH_BYTES + 2U); + m_lastFrameValid = true; return true; } @@ -1498,11 +1507,16 @@ void CDMRSlot::insertSilence(unsigned int count) { unsigned char data[DMR_FRAME_LENGTH_BYTES + 2U]; - ::memcpy(data, m_lastFrame, 2U); // The control data - ::memcpy(data + 2U, m_lastFrame + 24U + 2U, 9U); // Copy the last audio block to the first - ::memcpy(data + 24U + 2U, data + 2U, 9U); // Copy the last audio block to the last - ::memcpy(data + 9U + 2U, data + 2U, 5U); // Copy the last audio block to the middle (1/2) - ::memcpy(data + 19U + 2U, data + 4U + 2U, 5U); // Copy the last audio block to the middle (2/2) + if (m_lastFrameValid) { + ::memcpy(data, m_lastFrame, 2U); // The control data + ::memcpy(data + 2U, m_lastFrame + 24U + 2U, 9U); // Copy the last audio block to the first + ::memcpy(data + 24U + 2U, data + 2U, 9U); // Copy the last audio block to the last + ::memcpy(data + 9U + 2U, data + 2U, 5U); // Copy the last audio block to the middle (1/2) + ::memcpy(data + 19U + 2U, data + 4U + 2U, 5U); // Copy the last audio block to the middle (2/2) + } else { + // Not sure what to do if this isn't AMBE audio + ::memcpy(data, DMR_SILENCE_DATA, DMR_FRAME_LENGTH_BYTES + 2U); + } unsigned char n = (m_netN + 1U) % 6U; unsigned char seqNo = m_netSeqNo + 1U; diff --git a/DMRSlot.h b/DMRSlot.h index 49fce04..74213b7 100644 --- a/DMRSlot.h +++ b/DMRSlot.h @@ -82,6 +82,7 @@ private: unsigned int m_rfErrs; unsigned int m_netErrs; unsigned char* m_lastFrame; + bool m_lastFrameValid; CDMREMB m_lastEMB; FILE* m_fp; @@ -90,12 +91,7 @@ private: static bool m_selfOnly; static std::vector m_prefixes; static std::vector m_blackList; -/* - static std::vector m_dstBlackListSlot1; - static std::vector m_dstBlackListSlot2; - static std::vector m_dstWhiteListSlot1; - static std::vector m_dstWhiteListSlot2; -*/ + static CModem* m_modem; static CDMRIPSC* m_network; static CDisplay* m_display; diff --git a/DStarControl.cpp b/DStarControl.cpp index 0ef9c5a..84c22de 100644 --- a/DStarControl.cpp +++ b/DStarControl.cpp @@ -69,6 +69,7 @@ m_netBits(1U), m_rfErrs(0U), m_netErrs(0U), m_lastFrame(NULL), +m_lastFrameValid(false), m_fp(NULL) { assert(display != NULL); @@ -418,6 +419,8 @@ void CDStarControl::writeEndNet() { m_netState = RS_NET_IDLE; + m_lastFrameValid = false; + m_display->clearDStar(); m_netTimeoutTimer.stop(); @@ -470,6 +473,8 @@ void CDStarControl::writeNetwork() m_elapsed.start(); m_ackTimer.stop(); + m_lastFrameValid = false; + m_netFrames = 0U; m_netLost = 0U; @@ -808,6 +813,7 @@ bool CDStarControl::insertSilence(const unsigned char* data, unsigned char seqNo if (oldSeqNo == seqNo) { // Just copy the data, nothing else to do here ::memcpy(m_lastFrame, data, DSTAR_FRAME_LENGTH_BYTES + 1U); + m_lastFrameValid = true; return true; } @@ -823,6 +829,7 @@ bool CDStarControl::insertSilence(const unsigned char* data, unsigned char seqNo insertSilence(count); ::memcpy(m_lastFrame, data, DSTAR_FRAME_LENGTH_BYTES + 1U); + m_lastFrameValid = true; return true; } @@ -832,7 +839,7 @@ void CDStarControl::insertSilence(unsigned int count) unsigned char n = (m_netN + 1U) % 21U; for (unsigned int i = 0U; i < count; i++) { - if (i < 3U) { + if (i < 3U && m_lastFrameValid) { if (n == 0U) { ::memcpy(m_lastFrame + DSTAR_VOICE_FRAME_LENGTH_BYTES + 1U, DSTAR_NULL_SLOW_SYNC_BYTES, DSTAR_DATA_FRAME_LENGTH_BYTES); writeQueueDataNet(m_lastFrame); diff --git a/DStarControl.h b/DStarControl.h index 18e5e1a..c7dcc1c 100644 --- a/DStarControl.h +++ b/DStarControl.h @@ -78,6 +78,7 @@ private: unsigned int m_rfErrs; unsigned int m_netErrs; unsigned char* m_lastFrame; + bool m_lastFrameValid; FILE* m_fp; void writeNetwork(); diff --git a/YSFControl.cpp b/YSFControl.cpp index 03cb387..46119cc 100644 --- a/YSFControl.cpp +++ b/YSFControl.cpp @@ -48,6 +48,7 @@ m_rfDest(NULL), m_netSource(NULL), m_netDest(NULL), m_lastFrame(NULL), +m_lastFrameValid(false), m_lastMode(YSF_DT_VOICE_FR_MODE), m_netN(0U), m_rfPayload(), @@ -355,6 +356,8 @@ void CYSFControl::writeEndNet() m_networkWatchdog.stop(); m_packetTimer.stop(); + m_lastFrameValid = false; + m_netPayload.reset(); m_display->clearFusion(); @@ -401,6 +404,7 @@ void CYSFControl::writeNetwork() m_netPayload.reset(); m_packetTimer.start(); m_elapsed.start(); + m_lastFrameValid = false; m_netState = RS_NET_AUDIO; m_netFrames = 0U; m_netLost = 0U; @@ -671,6 +675,7 @@ bool CYSFControl::insertSilence(const unsigned char* data, unsigned char n) if (newN == n) { // Just copy the data, nothing else to do here ::memcpy(m_lastFrame, data, YSF_FRAME_LENGTH_BYTES + 2U); + m_lastFrameValid = true; return true; } @@ -690,6 +695,7 @@ bool CYSFControl::insertSilence(const unsigned char* data, unsigned char n) insertSilence(count); ::memcpy(m_lastFrame, data, YSF_FRAME_LENGTH_BYTES + 2U); + m_lastFrameValid = true; return true; } diff --git a/YSFControl.h b/YSFControl.h index caf3e69..a52252a 100644 --- a/YSFControl.h +++ b/YSFControl.h @@ -66,6 +66,7 @@ private: unsigned char* m_netSource; unsigned char* m_netDest; unsigned char* m_lastFrame; + bool m_lastFrameValid; unsigned char m_lastMode; unsigned char m_netN; CYSFPayload m_rfPayload;