From 10d4a940fd95556b43785fb7d37da184c5b42b6e Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Sat, 29 Oct 2022 23:32:31 -0400 Subject: [PATCH] move addBusyBits and setBusyBits to P25 utilities class; --- p25/Control.cpp | 43 +---------------------------------- p25/Control.h | 5 ---- p25/P25Utils.cpp | 41 +++++++++++++++++++++++++++++++++ p25/P25Utils.h | 5 ++++ p25/dfsi/packet/DFSITrunk.cpp | 4 ++-- p25/dfsi/packet/DFSIVoice.cpp | 8 +++---- p25/packet/Data.cpp | 2 +- p25/packet/Trunk.cpp | 18 +++++++-------- p25/packet/Voice.cpp | 14 ++++++------ 9 files changed, 70 insertions(+), 70 deletions(-) diff --git a/p25/Control.cpp b/p25/Control.cpp index 13e0775d..0a6b0d18 100644 --- a/p25/Control.cpp +++ b/p25/Control.cpp @@ -1175,7 +1175,7 @@ void Control::writeRF_TDU(bool noNetwork) m_nid.encode(data + 2U, P25_DUID_TDU); // Add busy bits - addBusyBits(data + 2U, P25_TDU_FRAME_LENGTH_BITS, true, true); + P25Utils::addBusyBits(data + 2U, P25_TDU_FRAME_LENGTH_BITS, true, true); if (!noNetwork) m_voice->writeNetwork(data + 2U, P25_DUID_TDU); @@ -1187,44 +1187,3 @@ void Control::writeRF_TDU(bool noNetwork) addFrame(data, P25_TDU_FRAME_LENGTH_BYTES + 2U); } } - -/// -/// Helper to set the busy status bits on P25 frame data. -/// -/// -/// -/// -/// -void Control::setBusyBits(uint8_t* data, uint32_t ssOffset, bool b1, bool b2) -{ - assert(data != nullptr); - - WRITE_BIT(data, ssOffset, b1); - WRITE_BIT(data, ssOffset + 1U, b2); -} - -/// -/// Helper to add the busy status bits on P25 frame data. -/// -/// -/// -/// -/// -void Control::addBusyBits(uint8_t* data, uint32_t length, bool b1, bool b2) -{ - assert(data != nullptr); - - // insert the "10" (Unknown, use for inbound or outbound) status bits - for (uint32_t ss0Pos = P25_SS0_START; ss0Pos < length; ss0Pos += P25_SS_INCREMENT) { - uint32_t ss1Pos = ss0Pos + 1U; - WRITE_BIT(data, ss0Pos, true); // 1 - WRITE_BIT(data, ss1Pos, false); // 0 - } - - // interleave the requested status bits (every other) - for (uint32_t ss0Pos = P25_SS0_START; ss0Pos < length; ss0Pos += (P25_SS_INCREMENT * 2)) { - uint32_t ss1Pos = ss0Pos + 1U; - WRITE_BIT(data, ss0Pos, b1); - WRITE_BIT(data, ss1Pos, b2); - } -} diff --git a/p25/Control.h b/p25/Control.h index 6ac2412c..b891b514 100644 --- a/p25/Control.h +++ b/p25/Control.h @@ -232,11 +232,6 @@ namespace p25 void writeRF_Preamble(uint32_t preambleCount = 0, bool force = false); /// Helper to write a P25 TDU packet. void writeRF_TDU(bool noNetwork); - - /// Helper to set the busy status bits on P25 frame data. - void setBusyBits(uint8_t* data, uint32_t ssOffset, bool b1, bool b2); - /// Helper to add the busy status bits on P25 frame data. - void addBusyBits(uint8_t* data, uint32_t length, bool b1, bool b2); }; } // namespace p25 diff --git a/p25/P25Utils.cpp b/p25/P25Utils.cpp index e7467763..82c54a8f 100644 --- a/p25/P25Utils.cpp +++ b/p25/P25Utils.cpp @@ -40,6 +40,47 @@ using namespace p25; // Static Class Members // --------------------------------------------------------------------------- +/// +/// Helper to set the busy status bits on P25 frame data. +/// +/// +/// +/// +/// +void P25Utils::setBusyBits(uint8_t* data, uint32_t ssOffset, bool b1, bool b2) +{ + assert(data != nullptr); + + WRITE_BIT(data, ssOffset, b1); + WRITE_BIT(data, ssOffset + 1U, b2); +} + +/// +/// Helper to add the busy status bits on P25 frame data. +/// +/// +/// +/// +/// +void P25Utils::addBusyBits(uint8_t* data, uint32_t length, bool b1, bool b2) +{ + assert(data != nullptr); + + // insert the "10" (Unknown, use for inbound or outbound) status bits + for (uint32_t ss0Pos = P25_SS0_START; ss0Pos < length; ss0Pos += P25_SS_INCREMENT) { + uint32_t ss1Pos = ss0Pos + 1U; + WRITE_BIT(data, ss0Pos, true); // 1 + WRITE_BIT(data, ss1Pos, false); // 0 + } + + // interleave the requested status bits (every other) + for (uint32_t ss0Pos = P25_SS0_START; ss0Pos < length; ss0Pos += (P25_SS_INCREMENT * 2)) { + uint32_t ss1Pos = ss0Pos + 1U; + WRITE_BIT(data, ss0Pos, b1); + WRITE_BIT(data, ss1Pos, b2); + } +} + /// /// Decode bit interleaving. /// diff --git a/p25/P25Utils.h b/p25/P25Utils.h index d93a1319..e20d221b 100644 --- a/p25/P25Utils.h +++ b/p25/P25Utils.h @@ -108,6 +108,11 @@ namespace p25 return id; } + /// Helper to set the busy status bits on P25 frame data. + static void setBusyBits(uint8_t* data, uint32_t ssOffset, bool b1, bool b2); + /// Helper to add the busy status bits on P25 frame data. + static void addBusyBits(uint8_t* data, uint32_t length, bool b1, bool b2); + /// Decode bit interleaving. static uint32_t decode(const uint8_t* in, uint8_t* out, uint32_t start, uint32_t stop); /// Encode bit interleaving. diff --git a/p25/dfsi/packet/DFSITrunk.cpp b/p25/dfsi/packet/DFSITrunk.cpp index ddc5c12e..a0a3b555 100644 --- a/p25/dfsi/packet/DFSITrunk.cpp +++ b/p25/dfsi/packet/DFSITrunk.cpp @@ -149,10 +149,10 @@ void DFSITrunk::writeRF_TSDU_SBF(lc::TSBK* tsbk, bool noNetwork, bool clearBefor } // Add busy bits - m_p25->addBusyBits(data + 2U, P25_TSDU_FRAME_LENGTH_BITS, true, false); + P25Utils::addBusyBits(data + 2U, P25_TSDU_FRAME_LENGTH_BITS, true, false); // Set first busy bits to 1,1 - m_p25->setBusyBits(data + 2U, P25_SS0_START, true, true); + P25Utils::setBusyBits(data + 2U, P25_SS0_START, true, true); if (!noNetwork) writeNetworkRF(tsbk, data + 2U, true); diff --git a/p25/dfsi/packet/DFSIVoice.cpp b/p25/dfsi/packet/DFSIVoice.cpp index bc5137d6..8d6ce82f 100644 --- a/p25/dfsi/packet/DFSIVoice.cpp +++ b/p25/dfsi/packet/DFSIVoice.cpp @@ -387,7 +387,7 @@ bool DFSIVoice::process(uint8_t* data, uint32_t len) m_rfLC.encodeHDU(buffer + 2U); // Add busy bits - m_p25->addBusyBits(buffer + 2U, P25_HDU_FRAME_LENGTH_BITS, false, true); + P25Utils::addBusyBits(buffer + 2U, P25_HDU_FRAME_LENGTH_BITS, false, true); writeNetwork(buffer, P25_DUID_HDU); @@ -462,7 +462,7 @@ bool DFSIVoice::process(uint8_t* data, uint32_t len) m_rfFrames++; // Add busy bits - m_p25->addBusyBits(buffer + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); + P25Utils::addBusyBits(buffer + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); writeNetwork(buffer + 2U, P25_DUID_LDU1); @@ -554,7 +554,7 @@ bool DFSIVoice::process(uint8_t* data, uint32_t len) m_rfFrames++; // Add busy bits - m_p25->addBusyBits(buffer + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); + P25Utils::addBusyBits(buffer + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); writeNetwork(buffer + 2U, P25_DUID_LDU2); @@ -585,7 +585,7 @@ bool DFSIVoice::process(uint8_t* data, uint32_t len) m_p25->m_nid.encode(data + 2U, P25_DUID_TDU); // Add busy bits - m_p25->addBusyBits(data + 2U, P25_TDU_FRAME_LENGTH_BITS, true, true); + P25Utils::addBusyBits(data + 2U, P25_TDU_FRAME_LENGTH_BITS, true, true); writeNetwork(data + 2U, P25_DUID_TDU); diff --git a/p25/packet/Data.cpp b/p25/packet/Data.cpp index 45c78f22..9c30b991 100644 --- a/p25/packet/Data.cpp +++ b/p25/packet/Data.cpp @@ -717,7 +717,7 @@ void Data::writeRF_PDU(const uint8_t* pdu, uint32_t bitLength, bool noNulls) m_p25->m_nid.encode(data + 2U, P25_DUID_PDU); // Add busy bits - m_p25->addBusyBits(data + 2U, newBitLength, false, true); + P25Utils::addBusyBits(data + 2U, newBitLength, false, true); if (m_p25->m_duplex) { data[0U] = modem::TAG_DATA; diff --git a/p25/packet/Trunk.cpp b/p25/packet/Trunk.cpp index d98cc8cd..718984b0 100644 --- a/p25/packet/Trunk.cpp +++ b/p25/packet/Trunk.cpp @@ -1435,7 +1435,7 @@ void Trunk::writeRF_TDULC(lc::TDULC* lc, bool noNetwork) lc->encode(data + 2U); // Add busy bits - m_p25->addBusyBits(data + 2U, P25_TDULC_FRAME_LENGTH_BITS, true, true); + P25Utils::addBusyBits(data + 2U, P25_TDULC_FRAME_LENGTH_BITS, true, true); m_p25->m_rfTimeout.stop(); @@ -1476,7 +1476,7 @@ void Trunk::writeNet_TDULC(lc::TDULC* lc) lc->encode(buffer + 2U); // Add busy bits - m_p25->addBusyBits(buffer + 2U, P25_TDULC_FRAME_LENGTH_BITS, true, true); + P25Utils::addBusyBits(buffer + 2U, P25_TDULC_FRAME_LENGTH_BITS, true, true); m_p25->addFrame(buffer, P25_TDULC_FRAME_LENGTH_BYTES + 2U, true); @@ -1587,10 +1587,10 @@ void Trunk::writeRF_TSDU_SBF(lc::TSBK* tsbk, bool noNetwork, bool clearBeforeWri } // Add busy bits - m_p25->addBusyBits(data + 2U, P25_TSDU_FRAME_LENGTH_BITS, true, false); + P25Utils::addBusyBits(data + 2U, P25_TSDU_FRAME_LENGTH_BITS, true, false); // Set first busy bits to 1,1 - m_p25->setBusyBits(data + 2U, P25_SS0_START, true, true); + P25Utils::setBusyBits(data + 2U, P25_SS0_START, true, true); if (!noNetwork) writeNetworkRF(tsbk, data + 2U, true); @@ -1646,10 +1646,10 @@ void Trunk::writeNet_TSDU(lc::TSBK* tsbk) tsbk->encode(buffer + 2U); // Add busy bits - m_p25->addBusyBits(buffer + 2U, P25_TSDU_FRAME_LENGTH_BYTES, true, false); + P25Utils::addBusyBits(buffer + 2U, P25_TSDU_FRAME_LENGTH_BYTES, true, false); // Set first busy bits to 1,1 - m_p25->setBusyBits(buffer + 2U, P25_SS0_START, true, true); + P25Utils::setBusyBits(buffer + 2U, P25_SS0_START, true, true); m_p25->addFrame(buffer, P25_TSDU_FRAME_LENGTH_BYTES + 2U, true); @@ -1742,7 +1742,7 @@ void Trunk::writeRF_TSDU_MBF(lc::TSBK* tsbk, bool clearBeforeWrite) P25Utils::encode(tsdu, data + 2U, 114U, 720U); // Add busy bits - m_p25->addBusyBits(data + 2U, P25_TSDU_TRIPLE_FRAME_LENGTH_BITS, true, false); + P25Utils::addBusyBits(data + 2U, P25_TSDU_TRIPLE_FRAME_LENGTH_BITS, true, false); // Add idle bits addIdleBits(data + 2U, P25_TSDU_TRIPLE_FRAME_LENGTH_BITS, true, true); @@ -2633,10 +2633,10 @@ void Trunk::writeNet_TSDU_From_RF(lc::TSBK* tsbk, uint8_t* data) tsbk->encode(data); // Add busy bits - m_p25->addBusyBits(data, P25_TSDU_FRAME_LENGTH_BYTES, true, false); + P25Utils::addBusyBits(data, P25_TSDU_FRAME_LENGTH_BYTES, true, false); // Set first busy bits to 1,1 - m_p25->setBusyBits(data, P25_SS0_START, true, true); + P25Utils::setBusyBits(data, P25_SS0_START, true, true); } /// diff --git a/p25/packet/Voice.cpp b/p25/packet/Voice.cpp index 4d1c5f73..6c72a404 100644 --- a/p25/packet/Voice.cpp +++ b/p25/packet/Voice.cpp @@ -404,7 +404,7 @@ bool Voice::process(uint8_t* data, uint32_t len) m_rfLC.encodeHDU(buffer + 2U); // Add busy bits - m_p25->addBusyBits(buffer + 2U, P25_HDU_FRAME_LENGTH_BITS, false, true); + P25Utils::addBusyBits(buffer + 2U, P25_HDU_FRAME_LENGTH_BITS, false, true); writeNetwork(buffer, P25_DUID_HDU); @@ -530,7 +530,7 @@ bool Voice::process(uint8_t* data, uint32_t len) m_rfFrames++; // Add busy bits - m_p25->addBusyBits(data + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); + P25Utils::addBusyBits(data + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); writeNetwork(data + 2U, P25_DUID_LDU1); @@ -609,7 +609,7 @@ bool Voice::process(uint8_t* data, uint32_t len) m_rfFrames++; // Add busy bits - m_p25->addBusyBits(data + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); + P25Utils::addBusyBits(data + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); writeNetwork(data + 2U, P25_DUID_LDU2); @@ -982,7 +982,7 @@ void Voice::writeNet_TDU() m_p25->m_nid.encode(buffer + 2U, P25_DUID_TDU); // Add busy bits - m_p25->addBusyBits(buffer + 2U, P25_TDU_FRAME_LENGTH_BITS, true, true); + P25Utils::addBusyBits(buffer + 2U, P25_TDU_FRAME_LENGTH_BITS, true, true); m_p25->addFrame(buffer, P25_TDU_FRAME_LENGTH_BYTES + 2U, true); @@ -1215,7 +1215,7 @@ void Voice::writeNet_LDU1() m_netLC.encodeHDU(buffer + 2U); // Add busy bits - m_p25->addBusyBits(buffer + 2U, P25_HDU_FRAME_LENGTH_BITS, false, true); + P25Utils::addBusyBits(buffer + 2U, P25_HDU_FRAME_LENGTH_BITS, false, true); buffer[0U] = modem::TAG_DATA; buffer[1U] = 0x00U; @@ -1274,7 +1274,7 @@ void Voice::writeNet_LDU1() m_netLSD.encode(buffer + 2U); // Add busy bits - m_p25->addBusyBits(buffer + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); + P25Utils::addBusyBits(buffer + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); buffer[0U] = modem::TAG_DATA; buffer[1U] = 0x00U; @@ -1379,7 +1379,7 @@ void Voice::writeNet_LDU2() m_netLSD.encode(buffer + 2U); // Add busy bits - m_p25->addBusyBits(buffer + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); + P25Utils::addBusyBits(buffer + 2U, P25_LDU_FRAME_LENGTH_BITS, false, true); buffer[0U] = modem::TAG_DATA; buffer[1U] = 0x00U;