From 996db45b45aad3d8ce6fd07ba862791bfd86395b Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 6 Sep 2016 08:06:19 +0100 Subject: [PATCH] Clean up the DMR sync generation code. --- DMRSlot.cpp | 105 +++++++++++----------------------------------------- Sync.cpp | 38 ++++++++----------- Sync.h | 7 +--- 3 files changed, 39 insertions(+), 111 deletions(-) diff --git a/DMRSlot.cpp b/DMRSlot.cpp index b857316..2115198 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -168,10 +168,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); data[0U] = TAG_DATA; data[1U] = 0x00U; @@ -213,10 +210,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); // Regenerate the payload CBPTC19696 bptc; @@ -243,10 +237,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); data[0U] = TAG_EOT; data[1U] = 0x00U; @@ -292,10 +283,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); data[0U] = m_rfFrames == 0U ? TAG_EOT : TAG_DATA; data[1U] = 0x00U; @@ -342,10 +330,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); m_rfSeqNo = 0U; @@ -403,10 +388,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); m_rfFrames--; @@ -424,10 +406,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len) } else if (audioSync) { if (m_rfState == RS_RF_AUDIO) { // Convert the Audio Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSAudioSync(data + 2U); - else - CSync::addDMRMSAudioSync(data + 2U); + CSync::addDMRAudioSync(data + 2U, m_duplex); unsigned int errors = 0U; unsigned char fid = m_rfLC->getFID(); @@ -511,10 +490,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len) // Create a dummy start frame to replace the received frame unsigned char start[DMR_FRAME_LENGTH_BYTES + 2U]; - if (m_duplex) - CSync::addDMRBSDataSync(start + 2U); - else - CSync::addDMRMSDataSync(start + 2U); + CSync::addDMRDataSync(start + 2U, m_duplex); CDMRFullLC fullLC; fullLC.encode(*m_rfLC, start + 2U, DT_VOICE_LC_HEADER); @@ -613,10 +589,7 @@ void CDMRSlot::endOfRFData() if (m_duplex) { unsigned char bytes[DMR_FRAME_LENGTH_BYTES + 2U]; - if (m_duplex) - CSync::addDMRBSDataSync(bytes + 2U); - else - CSync::addDMRMSDataSync(bytes + 2U); + CSync::addDMRDataSync(bytes + 2U, m_duplex); CDMRSlotType slotType; slotType.setDataType(DT_TERMINATOR_WITH_LC); @@ -656,10 +629,7 @@ void CDMRSlot::writeEndRF(bool writeEnd) // Create a dummy start end frame unsigned char data[DMR_FRAME_LENGTH_BYTES + 2U]; - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); CDMRFullLC fullLC; fullLC.encode(*m_rfLC, data + 2U, DT_TERMINATOR_WITH_LC); @@ -688,10 +658,7 @@ void CDMRSlot::endOfNetData() if (m_duplex) { unsigned char bytes[DMR_FRAME_LENGTH_BYTES + 2U]; - if (m_duplex) - CSync::addDMRBSDataSync(bytes + 2U); - else - CSync::addDMRMSDataSync(bytes + 2U); + CSync::addDMRDataSync(bytes + 2U, m_duplex); CDMRSlotType slotType; slotType.setDataType(DT_TERMINATOR_WITH_LC); @@ -735,10 +702,7 @@ void CDMRSlot::writeEndNet(bool writeEnd) // Create a dummy start end frame unsigned char data[DMR_FRAME_LENGTH_BYTES + 2U]; - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); CDMRFullLC fullLC; fullLC.encode(*m_netLC, data + 2U, DT_TERMINATOR_WITH_LC); @@ -809,10 +773,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); data[0U] = TAG_DATA; data[1U] = 0x00U; @@ -871,10 +832,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); // Regenerate the payload CBPTC19696 bptc; @@ -910,10 +868,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); data[0U] = TAG_EOT; data[1U] = 0x00U; @@ -966,10 +921,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); data[0U] = m_netFrames == 0U ? TAG_EOT : TAG_DATA; data[1U] = 0x00U; @@ -1019,10 +971,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) // Create a dummy start frame unsigned char start[DMR_FRAME_LENGTH_BYTES + 2U]; - if (m_duplex) - CSync::addDMRBSDataSync(start + 2U); - else - CSync::addDMRMSDataSync(start + 2U); + CSync::addDMRDataSync(start + 2U, m_duplex); CDMRFullLC fullLC; fullLC.encode(*m_netLC, start + 2U, DT_VOICE_LC_HEADER); @@ -1069,10 +1018,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) data[1U] = 0x00U; // Convert the Audio Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSAudioSync(data + 2U); - else - CSync::addDMRMSAudioSync(data + 2U); + CSync::addDMRAudioSync(data + 2U, m_duplex); // Initialise the lost packet data if (m_netFrames == 0U) { @@ -1179,10 +1125,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); data[0U] = TAG_DATA; data[1U] = 0x00U; @@ -1240,10 +1183,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) slotType.getData(data + 2U); // Convert the Data Sync to be from the BS or MS as needed - if (m_duplex) - CSync::addDMRBSDataSync(data + 2U); - else - CSync::addDMRMSDataSync(data + 2U); + CSync::addDMRDataSync(data + 2U, m_duplex); m_netFrames--; @@ -1622,10 +1562,7 @@ void CDMRSlot::insertSilence(unsigned int count) } if (n == 0U) { - if (m_duplex) - CSync::addDMRBSAudioSync(data + 2U); - else - CSync::addDMRMSAudioSync(data + 2U); + CSync::addDMRAudioSync(data + 2U, m_duplex); } else { unsigned char lcss = m_netEmbeddedLC.getData(data + 2U, n); diff --git a/Sync.cpp b/Sync.cpp index 810103b..88faad1 100644 --- a/Sync.cpp +++ b/Sync.cpp @@ -34,36 +34,30 @@ void CSync::addDStarSync(unsigned char* data) ::memcpy(data + DSTAR_VOICE_FRAME_LENGTH_BYTES, DSTAR_SYNC_BYTES, DSTAR_DATA_FRAME_LENGTH_BYTES); } -void CSync::addDMRBSDataSync(unsigned char* data) +void CSync::addDMRDataSync(unsigned char* data, bool duplex) { assert(data != NULL); - for (unsigned int i = 0U; i < 7U; i++) - data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | BS_SOURCED_DATA_SYNC[i]; + if (duplex) { + for (unsigned int i = 0U; i < 7U; i++) + data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | BS_SOURCED_DATA_SYNC[i]; + } else { + for (unsigned int i = 0U; i < 7U; i++) + data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | MS_SOURCED_DATA_SYNC[i]; + } } -void CSync::addDMRBSAudioSync(unsigned char* data) +void CSync::addDMRAudioSync(unsigned char* data, bool duplex) { assert(data != NULL); - for (unsigned int i = 0U; i < 7U; i++) - data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | BS_SOURCED_AUDIO_SYNC[i]; -} - -void CSync::addDMRMSDataSync(unsigned char* data) -{ - assert(data != NULL); - - for (unsigned int i = 0U; i < 7U; i++) - data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | MS_SOURCED_DATA_SYNC[i]; -} - -void CSync::addDMRMSAudioSync(unsigned char* data) -{ - assert(data != NULL); - - for (unsigned int i = 0U; i < 7U; i++) - data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | MS_SOURCED_AUDIO_SYNC[i]; + if (duplex) { + for (unsigned int i = 0U; i < 7U; i++) + data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | BS_SOURCED_AUDIO_SYNC[i]; + } else { + for (unsigned int i = 0U; i < 7U; i++) + data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | MS_SOURCED_AUDIO_SYNC[i]; + } } void CSync::addYSFSync(unsigned char* data) diff --git a/Sync.h b/Sync.h index dae7bc1..92df8c0 100644 --- a/Sync.h +++ b/Sync.h @@ -24,11 +24,8 @@ class CSync public: static void addDStarSync(unsigned char* data); - static void addDMRBSDataSync(unsigned char* data); - static void addDMRBSAudioSync(unsigned char* data); - - static void addDMRMSDataSync(unsigned char* data); - static void addDMRMSAudioSync(unsigned char* data); + static void addDMRDataSync(unsigned char* data, bool duplex); + static void addDMRAudioSync(unsigned char* data, bool duplex); static void addYSFSync(unsigned char* data);