code cleanup; fix memory corruption issue when handling the LC MI in LC::copy(); add compiler-directive level debugging helpers;

pull/12/head
Bryan Biedenkapp 4 years ago
parent acd3f60955
commit ebf1cde7ad

@ -87,7 +87,7 @@ void Utils::dump(int level, const std::string& title, const uint8_t* data, uint3
uint32_t bytes = (length > 16U) ? 16U : length;
for (unsigned i = 0U; i < bytes; i++) {
for (uint32_t i = 0U; i < bytes; i++) {
char temp[10U];
::sprintf(temp, "%02X ", data[offset + i]);
output += temp;
@ -98,7 +98,7 @@ void Utils::dump(int level, const std::string& title, const uint8_t* data, uint3
output += " *";
for (unsigned i = 0U; i < bytes; i++) {
for (uint32_t i = 0U; i < bytes; i++) {
uint8_t c = data[offset + i];
if (::isprint(c))
@ -177,7 +177,7 @@ void Utils::symbols(const std::string& title, const uint8_t* data, uint32_t leng
microslotHeader += temp;
}
::Log(2U, "SYMBOLS", "MCR: %s", microslotHeader.c_str());
::Log(2U, "SYMBOLS", "MCR: %s", microslotHeader.c_str());
uint32_t bufLen = length;
while (bufLen > 0U) {

@ -167,7 +167,9 @@ bool DataHeader::decode(const uint8_t* bytes)
switch (m_DPF) {
case DPF_UDT:
// Utils::dump(1U, "DMR, Unified Data Transport Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Unified Data Transport Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
m_sap = ((m_data[1U] & 0xF0U) >> 4); // Service Access Point
m_dataFormat = (m_data[1U] & 0x0FU); // UDT Format
m_blocks = (m_data[8U] & 0x03U) + 1U; // Blocks To Follow
@ -178,7 +180,9 @@ bool DataHeader::decode(const uint8_t* bytes)
break;
case DPF_UNCONFIRMED_DATA:
// Utils::dump(1U, "DMR, Unconfirmed Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Unconfirmed Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
m_sap = ((m_data[1U] & 0xF0U) >> 4); // Service Access Point
m_padCount = (m_data[0U] & 0x10U) + (m_data[1U] & 0x0FU); // Octet Pad Count
m_F = (m_data[8U] & 0x80U) == 0x80U; // Full Message Flag
@ -187,7 +191,9 @@ bool DataHeader::decode(const uint8_t* bytes)
break;
case DPF_CONFIRMED_DATA:
// Utils::dump(1U, "DMR, Confirmed Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Confirmed Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
m_sap = ((m_data[1U] & 0xF0U) >> 4); // Service Access Point
m_padCount = (m_data[0U] & 0x10U) + (m_data[1U] & 0x0FU); // Octet Pad Count
m_F = (m_data[8U] & 0x80U) == 0x80U; // Full Message Flag
@ -198,7 +204,9 @@ bool DataHeader::decode(const uint8_t* bytes)
break;
case DPF_RESPONSE:
// Utils::dump(1U, "DMR, Response Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Response Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
m_sap = ((m_data[1U] & 0xF0U) >> 4); // Service Access Point
m_blocks = m_data[8U] & 0x7FU; // Blocks To Follow
m_rspClass = (m_data[9U] >> 6) & 0x03U; // Response Class
@ -207,7 +215,9 @@ bool DataHeader::decode(const uint8_t* bytes)
break;
case DPF_DEFINED_SHORT:
// Utils::dump(1U, "DMR, Defined Short Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Defined Short Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
m_sap = ((m_data[1U] & 0xF0U) >> 4); // Service Access Point
m_blocks = (m_data[0U] & 0x30U) + (m_data[1U] & 0x0FU); // Blocks To Follow
m_F = (m_data[8U] & 0x01U) == 0x01U; // Full Message Flag
@ -217,7 +227,9 @@ bool DataHeader::decode(const uint8_t* bytes)
break;
case DPF_DEFINED_RAW:
// Utils::dump(1U, "DMR, Raw Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Raw Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
m_sap = ((m_data[1U] & 0xF0U) >> 4); // Service Access Point
m_blocks = (m_data[0U] & 0x30U) + (m_data[1U] & 0x0FU); // Blocks To Follow
m_F = (m_data[8U] & 0x01U) == 0x01U; // Full Message Flag
@ -285,7 +297,9 @@ void DataHeader::encode(uint8_t* bytes) const
m_data[9U] = (m_SF ? 0x80U : 0x00U) + // Supplemental Flag
(m_PF ? 0x40U : 0x00U) + // Protect Flag
(m_UDTO & 0x3F); // UDT Opcode
// Utils::dump(1U, "DMR, Unified Data Transport Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Unified Data Transport Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
break;
case DPF_UNCONFIRMED_DATA:
@ -295,7 +309,9 @@ void DataHeader::encode(uint8_t* bytes) const
m_data[8U] = (m_F ? 0x80U : 0x00U) + // Full Message Flag
(m_blocks & 0x7FU); // Blocks To Follow
m_data[9U] = m_fsn; // Fragment Sequence Number
// Utils::dump(1U, "DMR, Unconfirmed Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Unconfirmed Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
break;
case DPF_CONFIRMED_DATA:
@ -307,7 +323,9 @@ void DataHeader::encode(uint8_t* bytes) const
m_data[9U] = (m_S ? 0x80U : 0x00U) + // Synchronize Flag
((m_Ns & 0x07U) << 4) + // Send Sequence Number
(m_fsn & 0x0FU); // Fragment Sequence Number
// Utils::dump(1U, "DMR, Confirmed Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Confirmed Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
break;
case DPF_RESPONSE:
@ -316,7 +334,9 @@ void DataHeader::encode(uint8_t* bytes) const
m_data[9U] = ((m_rspClass & 0x03U) << 6) + // Response Class
((m_rspType & 0x07U) << 3) + // Response Type
((m_rspStatus & 0x07U)); // Response Status
// Utils::dump(1U, "DMR, Response Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Response Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
break;
case DPF_DEFINED_SHORT:
@ -327,7 +347,9 @@ void DataHeader::encode(uint8_t* bytes) const
(m_S ? 0x02U : 0x00U) + // Synchronize Flag
((m_dataFormat & 0xFCU) << 2); // Defined Data Format
m_data[9U] = m_padCount; // Bit Padding
// Utils::dump(1U, "DMR, Defined Short Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Defined Short Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
break;
case DPF_DEFINED_RAW:
@ -338,7 +360,9 @@ void DataHeader::encode(uint8_t* bytes) const
(m_S ? 0x02U : 0x00U) + // Synchronize Flag
((m_dstPort & 0x07U) << 2) + // Destination Port
((m_srcPort & 0x07U) << 5); // Source Port
// Utils::dump(1U, "DMR, Raw Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#if DEBUG_DMR_PDU_DATA
Utils::dump(1U, "DMR, DataHeader::decode(), Raw Data Header", m_data, DMR_LC_HEADER_LENGTH_BYTES);
#endif
break;
default:

@ -286,9 +286,9 @@ void Modem::setRXLevel(float rxLevel)
buffer[2U] = CMD_SET_RXLEVEL;
buffer[3U] = (uint8_t)(m_rxLevel * 2.55F + 0.5F);
// Utils::dump(1U, "Written", buffer, 16U);
#if DEBUG_MODEM
Utils::dump(1U, "Modem::setRXLevel(), Written", buffer, 16U);
#endif
int ret = write(buffer, 16U);
if (ret != 16)
return;
@ -307,9 +307,9 @@ void Modem::setRXLevel(float rxLevel)
}
}
} while (resp == RTM_OK && m_buffer[2U] != CMD_ACK && m_buffer[2U] != CMD_NAK);
// Utils::dump(1U, "Response", m_buffer, m_length);
#if DEBUG_MODEM
Utils::dump(1U, "Modem::setRXLevel(), Response", m_buffer, m_length);
#endif
if (resp == RTM_OK && m_buffer[2U] == CMD_NAK) {
LogError(LOG_MODEM, "NAK to the SET_RXLEVEL command from the modem");
}
@ -955,9 +955,9 @@ void Modem::clearP25Data()
buffer[0U] = DVM_FRAME_START;
buffer[1U] = 3U;
buffer[2U] = CMD_P25_CLEAR;
// Utils::dump(1U, "Written", buffer, 3U);
#if DEBUG_MODEM
Utils::dump(1U, "Modem::clearP25Data(), Written", buffer, 3U);
#endif
write(buffer, 3U);
}
}
@ -1139,9 +1139,9 @@ bool Modem::writeDMRStart(bool tx)
buffer[1U] = 4U;
buffer[2U] = CMD_DMR_START;
buffer[3U] = tx ? 0x01U : 0x00U;
// Utils::dump(1U, "Written", buffer, 4U);
#if DEBUG_MODEM
Utils::dump(1U, "Modem::writeDMRStart(), Written", buffer, 4U);
#endif
return write(buffer, 4U) == 4;
}
@ -1168,9 +1168,9 @@ bool Modem::writeDMRShortLC(const uint8_t* lc)
buffer[9U] = lc[6U];
buffer[10U] = lc[7U];
buffer[11U] = lc[8U];
// Utils::dump(1U, "Written", buffer, 12U);
#if DEBUG_MODEM
Utils::dump(1U, "Modem::writeDMRShortLC(), Written", buffer, 12U);
#endif
return write(buffer, 12U) == 12;
}
@ -1192,9 +1192,9 @@ bool Modem::writeDMRAbort(uint32_t slotNo)
buffer[1U] = 4U;
buffer[2U] = CMD_DMR_ABORT;
buffer[3U] = slotNo;
// Utils::dump(1U, "Written", buffer, 4U);
#if DEBUG_MODEM
Utils::dump(1U, "Modem::writeDMRAbort(), Written", buffer, 4U);
#endif
return write(buffer, 4U) == 4;
}
@ -1231,9 +1231,9 @@ bool Modem::setState(DVM_STATE state)
buffer[1U] = 4U;
buffer[2U] = CMD_SET_MODE;
buffer[3U] = state;
// Utils::dump(1U, "Written", buffer, 4U);
#if DEBUG_MODEM
Utils::dump(1U, "Modem::setState(), Written", buffer, 4U);
#endif
return write(buffer, 4U) == 4;
}
@ -1283,10 +1283,7 @@ bool Modem::getFirmwareVersion()
buffer[1U] = 3U;
buffer[2U] = CMD_GET_VERSION;
// Utils::dump(1U, "F/W Ver Written", buffer, 3U);
int ret = write(buffer, 3U);
// LogMessage(LOG_MODEM, "Asking for F/W");
if (ret != 3)
return false;
@ -1346,8 +1343,6 @@ bool Modem::getStatus()
buffer[1U] = 3U;
buffer[2U] = CMD_GET_STATUS;
// Utils::dump(1U, "Written", buffer, 3U);
return write(buffer, 3U) == 3;
}
@ -1413,9 +1408,9 @@ bool Modem::writeConfig()
buffer[17U] = (uint8_t)(m_rxDCOffset + 128);
buffer[14U] = m_p25CorrCount;
// Utils::dump(1U, "Written", buffer, 17U);
#if DEBUG_MODEM
Utils::dump(1U, "Modem::writeConfig(), Written", buffer, 17U);
#endif
int ret = write(buffer, 17U);
if (ret != 17)
return false;
@ -1434,9 +1429,9 @@ bool Modem::writeConfig()
}
}
} while (resp == RTM_OK && m_buffer[2U] != CMD_ACK && m_buffer[2U] != CMD_NAK);
// Utils::dump(1U, "Response", m_buffer, m_length);
#if DEBUG_MODEM
Utils::dump(1U, "Modem::writeConfig(), Response", m_buffer, m_length);
#endif
if (resp == RTM_OK && m_buffer[2U] == CMD_NAK) {
LogError(LOG_MODEM, "NAK to the SET_CONFIG command from the modem, reason = %u", resp);
return false;
@ -1484,8 +1479,6 @@ bool Modem::writeSymbolAdjust()
}
} while (resp == RTM_OK && m_buffer[2U] != CMD_ACK && m_buffer[2U] != CMD_NAK);
// Utils::dump(1U, "Response", m_buffer, m_length);
if (resp == RTM_OK && m_buffer[2U] == CMD_NAK) {
LogError(LOG_MODEM, "NAK to the SET_SYMLVLADJ command from the modem");
return false;

@ -828,6 +828,10 @@ void Control::writeRF_Nulls()
data[0U] = TAG_EOT;
data[1U] = 0x00U;
if (m_debug) {
LogDebug(LOG_P25, "writeRF_Nulls()");
}
writeQueueRF(data, NULLS_LENGTH_BYTES + 2U);
}

@ -1559,6 +1559,10 @@ void TrunkPacket::writeRF_TSDU_SBF(bool noNetwork, bool clearBeforeWrite, bool f
m_rfTSBK.encode(data + 2U);
if (m_debug) {
LogDebug(LOG_RF, P25_TSDU_STR ", lco = $%02X, mfId = $%02X, lastBlock = %u, AIV = %u, EX = %u, srcId = %u, dstId = %u, sysId = $%03X, netId = $%05X",
m_rfTSBK.getLCO(), m_rfTSBK.getMFId(), m_rfTSBK.getLastBlock(), m_rfTSBK.getAIV(), m_rfTSBK.getEX(), m_rfTSBK.getSrcId(), m_rfTSBK.getDstId(),
m_rfTSBK.getSysId(), m_rfTSBK.getNetId());
Utils::dump(1U, "!!! *TSDU (SBF) TSBK Block Data", data + P25_PREAMBLE_LENGTH_BYTES + 2U, P25_TSBK_FEC_LENGTH_BYTES);
}
@ -1631,6 +1635,10 @@ void TrunkPacket::writeRF_TSDU_MBF(bool clearBeforeWrite)
m_rfTSBK.encode(tsbk, true);
if (m_debug) {
LogDebug(LOG_RF, P25_TSDU_STR " (MBF), lco = $%02X, mfId = $%02X, lastBlock = %u, AIV = %u, EX = %u, srcId = %u, dstId = %u, sysId = $%03X, netId = $%05X",
m_rfTSBK.getLCO(), m_rfTSBK.getMFId(), m_rfTSBK.getLastBlock(), m_rfTSBK.getAIV(), m_rfTSBK.getEX(), m_rfTSBK.getSrcId(), m_rfTSBK.getDstId(),
m_rfTSBK.getSysId(), m_rfTSBK.getNetId());
Utils::dump(1U, "!!! *TSDU MBF Last TSBK Block", tsbk, P25_TSBK_FEC_LENGTH_BYTES);
}
@ -1646,6 +1654,10 @@ void TrunkPacket::writeRF_TSDU_MBF(bool clearBeforeWrite)
Utils::getBitRange(m_rfMBF, tsbk, offset, P25_TSBK_FEC_LENGTH_BITS);
if (m_debug) {
LogDebug(LOG_RF, P25_TSDU_STR " (MBF), lco = $%02X, mfId = $%02X, lastBlock = %u, AIV = %u, EX = %u, srcId = %u, dstId = %u, sysId = $%03X, netId = $%05X",
m_rfTSBK.getLCO(), m_rfTSBK.getMFId(), m_rfTSBK.getLastBlock(), m_rfTSBK.getAIV(), m_rfTSBK.getEX(), m_rfTSBK.getSrcId(), m_rfTSBK.getDstId(),
m_rfTSBK.getSysId(), m_rfTSBK.getNetId());
Utils::dump(1U, "!!! *TSDU (MBF) TSBK Block", tsbk, P25_TSBK_FEC_LENGTH_BYTES);
}
@ -1695,6 +1707,10 @@ void TrunkPacket::writeRF_TSDU_MBF(bool clearBeforeWrite)
m_rfTSBK.encode(tsbk, true);
if (m_debug) {
LogDebug(LOG_RF, P25_TSDU_STR " (MBF), lco = $%02X, mfId = $%02X, lastBlock = %u, AIV = %u, EX = %u, srcId = %u, dstId = %u, sysId = $%03X, netId = $%05X",
m_rfTSBK.getLCO(), m_rfTSBK.getMFId(), m_rfTSBK.getLastBlock(), m_rfTSBK.getAIV(), m_rfTSBK.getEX(), m_rfTSBK.getSrcId(), m_rfTSBK.getDstId(),
m_rfTSBK.getSysId(), m_rfTSBK.getNetId());
Utils::dump(1U, "!!! *TSDU MBF Block Data", tsbk, P25_TSBK_FEC_LENGTH_BYTES);
}

@ -122,15 +122,19 @@ void LC::encodeNID(uint8_t* data)
{
assert(data != NULL);
uint8_t rawFrame[P25_DFSI_SS_FRAME_LENGTH_BYTES];
::memset(rawFrame, 0x00U, P25_DFSI_SS_FRAME_LENGTH_BYTES);
uint8_t dfsiFrame[P25_DFSI_SS_FRAME_LENGTH_BYTES];
::memset(dfsiFrame, 0x00U, P25_DFSI_SS_FRAME_LENGTH_BYTES);
rawFrame[0U] = m_frameType; // Frame Type
dfsiFrame[0U] = m_frameType; // Frame Type
// encode start record
encodeStart(rawFrame + 1U);
encodeStart(dfsiFrame + 1U);
#if DEBUG_P25_DFSI
Utils::dump(2U, "LC::encodeNID(), DFSI Start/Stop Frame", dfsiFrame, P25_DFSI_SS_FRAME_LENGTH_BYTES);
#endif
::memcpy(data, rawFrame, P25_DFSI_SS_FRAME_LENGTH_BYTES);
::memcpy(data, dfsiFrame, P25_DFSI_SS_FRAME_LENGTH_BYTES);
}
/// <summary>
@ -167,18 +171,22 @@ void LC::encodeVHDR1(uint8_t* data)
{
assert(data != NULL);
uint8_t rawFrame[P25_DFSI_VHDR1_FRAME_LENGTH_BYTES];
::memset(rawFrame, 0x00U, P25_DFSI_VHDR1_FRAME_LENGTH_BYTES);
uint8_t dfsiFrame[P25_DFSI_VHDR1_FRAME_LENGTH_BYTES];
::memset(dfsiFrame, 0x00U, P25_DFSI_VHDR1_FRAME_LENGTH_BYTES);
rawFrame[0U] = P25_DFSI_VHDR1; // Frame Type
dfsiFrame[0U] = P25_DFSI_VHDR1; // Frame Type
// encode start record
encodeStart(rawFrame + 1U);
encodeStart(dfsiFrame + 1U);
dfsiFrame[5U] = m_icwFlag; // ICW Flag
dfsiFrame[6U] = m_rssi; // RSSI
rawFrame[5U] = m_icwFlag; // ICW Flag
rawFrame[6U] = m_rssi; // RSSI
#if DEBUG_P25_DFSI
Utils::dump(2U, "LC::encodeVHDR1(), DFSI Voice Header 1 Frame", dfsiFrame, P25_DFSI_VHDR1_FRAME_LENGTH_BYTES);
#endif
::memcpy(data, rawFrame, P25_DFSI_VHDR1_FRAME_LENGTH_BYTES);
::memcpy(data, dfsiFrame, P25_DFSI_VHDR1_FRAME_LENGTH_BYTES);
}
/// <summary>
@ -221,6 +229,10 @@ void LC::encodeVHDR2(uint8_t* data)
dfsiFrame[2U] = (dstId >> 8) & 0xFFU;
dfsiFrame[3U] = (dstId >> 0) & 0xFFU;
#if DEBUG_P25_DFSI
Utils::dump(2U, "LC::encodeVHDR2(), DFSI Voice Header 2 Frame", dfsiFrame, P25_DFSI_VHDR2_FRAME_LENGTH_BYTES);
#endif
::memcpy(data, dfsiFrame, P25_DFSI_VHDR2_FRAME_LENGTH_BYTES);
}
@ -451,6 +463,11 @@ void LC::encodeLDU1(uint8_t* data, const uint8_t* imbe)
break;
}
#if DEBUG_P25_DFSI
LogDebug(LOG_P25, "LC::encodeLDU1(), frameType = $%02X", m_frameType);
Utils::dump(2U, "LC::encodeLDU1(), DFSI LDU1 Frame", dfsiFrame, frameLength);
#endif
::memcpy(data, dfsiFrame, frameLength);
}
@ -560,6 +577,7 @@ void LC::encodeLDU2(uint8_t* data, const uint8_t* imbe)
// generate MI data
uint8_t mi[P25_MI_LENGTH_BYTES];
::memset(mi, 0x00U, P25_MI_LENGTH_BYTES);
m_control.getMI(mi);
// determine the LDU2 DFSI frame length, its variable
@ -684,6 +702,11 @@ void LC::encodeLDU2(uint8_t* data, const uint8_t* imbe)
break;
}
#if DEBUG_P25_DFSI
LogDebug(LOG_P25, "LC::encodeLDU2(), frameType = $%02X", m_frameType);
Utils::dump(2U, "LC::encodeLDU2(), DFSI LDU2 Frame", dfsiFrame, frameLength);
#endif
::memcpy(data, dfsiFrame, frameLength);
}
@ -716,6 +739,8 @@ bool LC::decodeTSBK(const uint8_t* data)
/// <param name="data"></param>
void LC::encodeTSBK(uint8_t* data)
{
assert(data != NULL);
uint8_t tsbk[P25_TSBK_LENGTH_BYTES];
m_tsbk.encode(tsbk, true, true);
@ -725,6 +750,12 @@ void LC::encodeTSBK(uint8_t* data)
dfsiFrame[0U] = P25_DFSI_TSBK; // Frame Type
encodeStart(dfsiFrame + 1U); // Start Record
::memcpy(dfsiFrame + 9U, tsbk, P25_TSBK_LENGTH_BYTES); // Raw TSBK + CRC
#if DEBUG_P25_DFSI
Utils::dump(2U, "LC::encodeTSBK(), DFSI TSBK Frame", dfsiFrame, P25_TSBK_LENGTH_BYTES);
#endif
::memcpy(data, dfsiFrame, P25_DFSI_TSBK_FRAME_LENGTH_BYTES);
}
// ---------------------------------------------------------------------------

@ -137,7 +137,9 @@ bool LC::decodeHDU(const uint8_t* data)
// decode Golay (18,6,8) FEC
decodeHDUGolay(raw, rs);
// Utils::dump(2U, "HDU RS", rs, P25_HDU_LENGTH_BYTES);
#if DEBUG_P25_HDU
Utils::dump(2U, "LC::decodeHDU(), HDU RS", rs, P25_HDU_LENGTH_BYTES);
#endif
// decode RS (36,20,17) FEC
try {
@ -152,7 +154,9 @@ bool LC::decodeHDU(const uint8_t* data)
return false;
}
// Utils::dump(2U, "HDU", rs, P25_HDU_LENGTH_BYTES);
#if DEBUG_P25_HDU
Utils::dump(2U, "LC::decodeHDU(), HDU", rs, P25_HDU_LENGTH_BYTES);
#endif
m_mfId = rs[9U]; // Mfg Id.
m_algId = rs[10U]; // Algorithm ID
@ -212,12 +216,16 @@ void LC::encodeHDU(uint8_t * data)
rs[13U] = (m_dstId >> 8) & 0xFFU; // Talkgroup Address
rs[14U] = (m_dstId >> 0) & 0xFFU; // ...
// Utils::dump(2U, "HDU", rs, P25_HDU_LENGTH_BYTES);
#if DEBUG_P25_HDU
Utils::dump(2U, "LC::encodeHDU(), HDU", rs, P25_HDU_LENGTH_BYTES);
#endif
// encode RS (36,20,17) FEC
m_rs.encode362017(rs);
// Utils::dump(2U, "HDU RS", rs, P25_HDU_LENGTH_BYTES);
#if DEBUG_P25_HDU
Utils::dump(2U, "LC::encodeHDU(), HDU RS", rs, P25_HDU_LENGTH_BYTES);
#endif
uint8_t raw[P25_HDU_LENGTH_BYTES + 1U];
::memset(raw, 0x00U, P25_HDU_LENGTH_BYTES + 1U);
@ -228,7 +236,9 @@ void LC::encodeHDU(uint8_t * data)
// interleave
P25Utils::encode(raw, data, 114U, 780U);
// Utils::dump(2U, "HDU Interleave", data, P25_HDU_FRAME_LENGTH_BYTES + P25_PREAMBLE_LENGTH_BYTES);
#if DEBUG_P25_HDU
Utils::dump(2U, "LC::encodeHDU(), HDU Interleave", data, P25_HDU_FRAME_LENGTH_BYTES + P25_PREAMBLE_LENGTH_BYTES);
#endif
}
/// <summary>
@ -262,7 +272,9 @@ bool LC::decodeLDU1(const uint8_t * data)
P25Utils::decode(data, raw, 1356U, 1398U);
decodeLDUHamming(raw, rs + 15U);
// Utils::dump(2U, "LDU1 RS", rs, P25_LDU_LC_LENGTH_BYTES);
#if DEBUG_P25_LDU1
Utils::dump(2U, "LC::decodeLDU1(), LDU1 RS", rs, P25_LDU_LC_LENGTH_BYTES);
#endif
// decode RS (24,12,13) FEC
try {
@ -277,7 +289,9 @@ bool LC::decodeLDU1(const uint8_t * data)
return false;
}
// Utils::dump(2U, "LDU1 LC", rs, P25_LDU_LC_LENGTH_BYTES);
#if DEBUG_P25_LDU1
Utils::dump(2U, "LC::decodeLDU1(), LDU1 LC", rs, P25_LDU_LC_LENGTH_BYTES);
#endif
return decodeLC(rs);
}
@ -295,12 +309,16 @@ void LC::encodeLDU1(uint8_t * data)
encodeLC(rs);
// Utils::dump(2U, "LDU1 LC", rs, P25_LDU_LC_LENGTH_BYTES);
#if DEBUG_P25_LDU1
Utils::dump(2U, "LC::encodeLDU1(), LDU1 LC", rs, P25_LDU_LC_LENGTH_BYTES);
#endif
// encode RS (24,12,13) FEC
m_rs.encode241213(rs);
// Utils::dump(2U, "LDU1 RS", rs, P25_LDU_LC_LENGTH_BYTES);
#if DEBUG_P25_LDU1
Utils::dump(2U, "LC::encodeLDU1(), LDU1 RS", rs, P25_LDU_LC_LENGTH_BYTES);
#endif
// encode Hamming (10,6,3) FEC and interleave for LC data
uint8_t raw[5U];
@ -322,7 +340,9 @@ void LC::encodeLDU1(uint8_t * data)
encodeLDUHamming(raw, rs + 15U);
P25Utils::encode(raw, data, 1356U, 1398U);
// Utils::dump(2U, "LDU1 Interleave", data, P25_LDU_FRAME_LENGTH_BYTES + P25_PREAMBLE_LENGTH_BYTES);
#if DEBUG_P25_LDU1
Utils::dump(2U, "LC::encodeLDU1(), LDU1 Interleave", data, P25_LDU_FRAME_LENGTH_BYTES + P25_PREAMBLE_LENGTH_BYTES);
#endif
}
/// <summary>
@ -356,7 +376,9 @@ bool LC::decodeLDU2(const uint8_t * data)
P25Utils::decode(data, raw, 1356U, 1398U);
decodeLDUHamming(raw, rs + 15U);
// Utils::dump(2U, "LDU2 RS", rs, P25_LDU_LC_LENGTH_BYTES);
#if DEBUG_P25_LDU2
Utils::dump(2U, "LC::decodeLDU2(), LDU2 RS", rs, P25_LDU_LC_LENGTH_BYTES);
#endif
// decode RS (24,16,9) FEC
try {
@ -371,7 +393,9 @@ bool LC::decodeLDU2(const uint8_t * data)
return false;
}
// Utils::dump(2U, "LDU2 LC", rs, P25_LDU_LC_LENGTH_BYTES);
#if DEBUG_P25_LDU2
Utils::dump(2U, "LC::decodeLDU2(), LDU2 LC", rs, P25_LDU_LC_LENGTH_BYTES);
#endif
m_algId = rs[9U]; // Algorithm ID
if (m_algId != P25_ALGO_UNENCRYPT) {
@ -418,12 +442,16 @@ void LC::encodeLDU2(uint8_t * data)
rs[10U] = (m_kId >> 8) & 0xFFU; // Key ID
rs[11U] = (m_kId >> 0) & 0xFFU; // ...
// Utils::dump(2U, "LDU2 LC", rs, P25_LDU_LC_LENGTH_BYTES);
#if DEBUG_P25_LDU2
Utils::dump(2U, "LC::encodeLDU2(), LDU2 LC", rs, P25_LDU_LC_LENGTH_BYTES);
#endif
// encode RS (24,16,9) FEC
m_rs.encode24169(rs);
// Utils::dump(2U, "LDU2 RS", rs, P25_LDU_LC_LENGTH_BYTES);
#if DEBUG_P25_LDU2
Utils::dump(2U, "LC::encodeLDU2(), LDU2 RS", rs, P25_LDU_LC_LENGTH_BYTES);
#endif
// encode Hamming (10,6,3) FEC and interleave for LC data
uint8_t raw[5U];
@ -445,7 +473,9 @@ void LC::encodeLDU2(uint8_t * data)
encodeLDUHamming(raw, rs + 15U);
P25Utils::encode(raw, data, 1356U, 1398U);
// Utils::dump(2U, "LDU2 Interleave", data, P25_LDU_FRAME_LENGTH_BYTES + P25_PREAMBLE_LENGTH_BYTES);
#if DEBUG_P25_LDU2
Utils::dump(2U, "LC::encodeLDU2(), LDU2 Interleave", data, P25_LDU_FRAME_LENGTH_BYTES + P25_PREAMBLE_LENGTH_BYTES);
#endif
}
/** Encryption data */
@ -496,10 +526,8 @@ void LC::copy(const LC& data)
if (m_algId != P25_ALGO_UNENCRYPT) {
delete[] m_mi;
uint8_t* mi = new uint8_t[P25_MI_LENGTH_BYTES];
::memcpy(mi, data.m_mi, P25_MI_LENGTH_BYTES);
m_mi = mi;
m_mi = new uint8_t[P25_MI_LENGTH_BYTES];
::memcpy(m_mi, data.m_mi, P25_MI_LENGTH_BYTES);
m_kId = data.m_kId;
if (!m_encrypted) {
@ -510,11 +538,9 @@ void LC::copy(const LC& data)
else {
delete[] m_mi;
uint8_t* mi = new uint8_t[P25_MI_LENGTH_BYTES];
m_mi = new uint8_t[P25_MI_LENGTH_BYTES];
::memset(m_mi, 0x00U, P25_MI_LENGTH_BYTES);
m_mi = mi;
m_kId = 0x0000U;
if (m_encrypted) {
m_encryptOverride = true;

@ -138,7 +138,9 @@ bool TDULC::decode(const uint8_t* data)
// decode Golay (24,12,8) FEC
edac::Golay24128::decode24128(rs, raw, P25_TDULC_LENGTH_BYTES);
// Utils::dump(2U, "TDULC RS", rs, P25_TDULC_LENGTH_BYTES);
#if DEBUG_P25_TDULC
Utils::dump(2U, "TDULC::decode(), TDULC RS", rs, P25_TDULC_LENGTH_BYTES);
#endif
// decode RS (24,12,13) FEC
try {
@ -181,7 +183,9 @@ void TDULC::encode(uint8_t * data)
// encode RS (24,12,13) FEC
m_rs.encode241213(rs);
// Utils::dump(2U, "TDULC RS", rs, P25_TDULC_LENGTH_BYTES);
#if DEBUG_P25_TDULC
Utils::dump(2U, "TDULC::encode(), TDULC RS", rs, P25_TDULC_LENGTH_BYTES);
#endif
uint8_t raw[P25_TDULC_FEC_LENGTH_BYTES + 1U];
::memset(raw, 0x00U, P25_TDULC_FEC_LENGTH_BYTES + 1U);
@ -192,7 +196,9 @@ void TDULC::encode(uint8_t * data)
// interleave
P25Utils::encode(raw, data, 114U, 410U);
// Utils::dump(2U, "TDULC Interleave", data, P25_TDULC_FRAME_LENGTH_BYTES + P25_PREAMBLE_LENGTH_BYTES);
#if DEBUG_P25_TDULC
Utils::dump(2U, "TDULC::encode(), TDULC Interleave", data, P25_TDULC_FRAME_LENGTH_BYTES + P25_PREAMBLE_LENGTH_BYTES);
#endif
}
// ---------------------------------------------------------------------------

@ -1023,7 +1023,9 @@ void TSBK::encode(uint8_t * data, bool rawTSBK, bool noTrellis)
// interleave
P25Utils::encode(raw, data, 114U, 318U);
// Utils::dump(2U, "TSBK Interleave", data, P25_TSBK_FEC_LENGTH_BYTES + P25_PREAMBLE_LENGTH_BYTES);
#if DEBUG_P25_TSBK
Utils::dump(2U, "TSBK::encode(), TSBK Interleave", data, P25_TSBK_FEC_LENGTH_BYTES + P25_PREAMBLE_LENGTH_BYTES);
#endif
}
}

Loading…
Cancel
Save

Powered by TurnKey Linux.