diff --git a/edac/CRC.cpp b/edac/CRC.cpp index dcf4012d..e0acf7ff 100644 --- a/edac/CRC.cpp +++ b/edac/CRC.cpp @@ -513,8 +513,8 @@ bool CRC::checkCRC6(const uint8_t* in, uint32_t bitLength) /// /// Input byte array. /// Length of byte array in bits. -/// True, if CRC is valid, otherwise false. -void CRC::addCRC6(uint8_t* in, uint32_t bitLength) +/// 6-bit CRC. +uint8_t CRC::addCRC6(uint8_t* in, uint32_t bitLength) { assert(in != nullptr); @@ -530,6 +530,7 @@ void CRC::addCRC6(uint8_t* in, uint32_t bitLength) #if DEBUG_CRC LogDebug(LOG_HOST, "CRC::addCRC6(), crc = $%04X, bitlen = %u", crc[0U], bitLength); #endif + return crc[0U]; } /// @@ -569,8 +570,8 @@ bool CRC::checkCRC12(const uint8_t* in, uint32_t bitLength) /// /// Input byte array. /// Length of byte array in bits. -/// True, if CRC is valid, otherwise false. -void CRC::addCRC12(uint8_t* in, uint32_t bitLength) +/// 12-bit CRC. +uint16_t CRC::addCRC12(uint8_t* in, uint32_t bitLength) { assert(in != nullptr); @@ -589,6 +590,7 @@ void CRC::addCRC12(uint8_t* in, uint32_t bitLength) #if DEBUG_CRC LogDebug(LOG_HOST, "CRC::addCRC12(), crc = $%04X, bitlen = %u", crc, bitLength); #endif + return crc; } /// @@ -628,8 +630,8 @@ bool CRC::checkCRC15(const uint8_t* in, uint32_t bitLength) /// /// Input byte array. /// Length of byte array in bits. -/// True, if CRC is valid, otherwise false. -void CRC::addCRC15(uint8_t* in, uint32_t bitLength) +/// 15-bit CRC. +uint16_t CRC::addCRC15(uint8_t* in, uint32_t bitLength) { assert(in != nullptr); @@ -648,6 +650,7 @@ void CRC::addCRC15(uint8_t* in, uint32_t bitLength) #if DEBUG_CRC LogDebug(LOG_HOST, "CRC::addCRC15(), crc = $%04X, bitlen = %u", crc, bitLength); #endif + return crc; } /// @@ -687,8 +690,8 @@ bool CRC::checkCRC16(const uint8_t* in, uint32_t bitLength) /// /// Input byte array. /// Length of byte array in bits. -/// True, if CRC is valid, otherwise false. -void CRC::addCRC16(uint8_t* in, uint32_t bitLength) +/// 16-bit CRC. +uint16_t CRC::addCRC16(uint8_t* in, uint32_t bitLength) { assert(in != nullptr); @@ -707,6 +710,7 @@ void CRC::addCRC16(uint8_t* in, uint32_t bitLength) #if DEBUG_CRC LogDebug(LOG_HOST, "CRC::addCRC16(), crc = $%04X, bitlen = %u", crc, bitLength); #endif + return crc; } // --------------------------------------------------------------------------- diff --git a/edac/CRC.h b/edac/CRC.h index cd74577f..a15a0d75 100644 --- a/edac/CRC.h +++ b/edac/CRC.h @@ -71,22 +71,22 @@ namespace edac /// Check 6-bit CRC. static bool checkCRC6(const uint8_t* in, uint32_t bitLength); /// Encode 6-bit CRC. - static void addCRC6(uint8_t* in, uint32_t bitLength); + static uint8_t addCRC6(uint8_t* in, uint32_t bitLength); /// Check 12-bit CRC. static bool checkCRC12(const uint8_t* in, uint32_t bitLength); /// Encode 12-bit CRC. - static void addCRC12(uint8_t* in, uint32_t bitLength); + static uint16_t addCRC12(uint8_t* in, uint32_t bitLength); /// Check 15-bit CRC. static bool checkCRC15(const uint8_t* in, uint32_t bitLength); /// Encode 15-bit CRC. - static void addCRC15(uint8_t* in, uint32_t bitLength); + static uint16_t addCRC15(uint8_t* in, uint32_t bitLength); /// Check 16-bit CRC-CCITT. static bool checkCRC16(const uint8_t* in, uint32_t bitLength); /// Encode 15-bit CRC. - static void addCRC16(uint8_t* in, uint32_t bitLength); + static uint16_t addCRC16(uint8_t* in, uint32_t bitLength); private: /// diff --git a/nxdn/channel/CAC.cpp b/nxdn/channel/CAC.cpp index d2014c8c..807d27eb 100644 --- a/nxdn/channel/CAC.cpp +++ b/nxdn/channel/CAC.cpp @@ -275,7 +275,7 @@ void CAC::encode(uint8_t* data) const WRITE_BIT(buffer, i, b); } - CRC::addCRC16(buffer, NXDN_CAC_LENGTH_BITS); + uint16_t crc = CRC::addCRC16(buffer, NXDN_CAC_LENGTH_BITS); #if DEBUG_NXDN_CAC Utils::dump(2U, "Encoded CAC", buffer, NXDN_CAC_FEC_LENGTH_BYTES); @@ -324,8 +324,8 @@ void CAC::encode(uint8_t* data) const control[0U] = ((m_idleBusy ? 0x03U : 0x01U) << 6) + ((m_txContinuous ? 0x03U : 0x01U) << 4) + (parity << 2) + ((m_receive ? 0x03U : 0x01U)); - control[1U] = (m_rxCRC >> 8U) & 0xFFU; - control[2U] = (m_rxCRC >> 0U) & 0xFFU; + control[1U] = (crc >> 8U) & 0xFFU; + control[2U] = (crc >> 0U) & 0xFFU; for (uint32_t i = 0U; i < NXDN_CAC_E_POST_FIELD_BITS; i++) { uint32_t n = i + NXDN_FSW_LENGTH_BITS + NXDN_LICH_LENGTH_BITS + NXDN_CAC_FEC_LENGTH_BITS;