expand previous PR to cover all RS decode functions; implement fecErr returns for P2 LC handlers; update tests;

pull/128/head
Bryan Biedenkapp 3 months ago
parent a4f8829b45
commit b13f127036

@ -406,7 +406,7 @@ void RS634717::encode24169(uint8_t* data)
/* Decode RS (36,20,17) FEC. */
bool RS634717::decode362017(uint8_t* data)
bool RS634717::decode362017(uint8_t* data, int8_t* errs)
{
assert(data != nullptr);
@ -424,6 +424,9 @@ bool RS634717::decode362017(uint8_t* data)
for (uint32_t i = 0U; i < 20U; i++, offset += 6)
Utils::hex2Bin(codeword[27 + i], data, offset);
if (errs != nullptr)
*errs = (int8_t)ec;
if ((ec == -1) || (ec > 8)) {
return false;
}
@ -456,7 +459,7 @@ void RS634717::encode362017(uint8_t* data)
/* Decode RS (52,30,23) FEC. */
bool RS634717::decode523023(uint8_t* data)
bool RS634717::decode523023(uint8_t* data, int8_t* errs)
{
assert(data != nullptr);
@ -475,6 +478,9 @@ bool RS634717::decode523023(uint8_t* data)
for (uint32_t i = 0U; i < 30U; i++, offset += 6)
Utils::hex2Bin(codeword[11 + i], data, offset);
if (errs != nullptr)
*errs = (int8_t)ec;
if ((ec == -1) || (ec >= 11)) {
return false;
}
@ -507,7 +513,7 @@ void RS634717::encode523023(uint8_t* data)
/* Decode RS (46,26,21) FEC. */
bool RS634717::decode462621(uint8_t* data)
bool RS634717::decode462621(uint8_t* data, int8_t* errs)
{
assert(data != nullptr);
@ -529,6 +535,9 @@ bool RS634717::decode462621(uint8_t* data)
for (uint32_t i = 0U; i < 26U; i++, offset += 6)
Utils::hex2Bin(codeword[9 + i], data, offset);
if (errs != nullptr)
*errs = (int8_t)ec;
if ((ec == -1) || (ec > 10)) {
return false;
}
@ -561,7 +570,7 @@ void RS634717::encode462621(uint8_t* data)
/* Decode RS (45,26,20) FEC. */
bool RS634717::decode452620(uint8_t* data)
bool RS634717::decode452620(uint8_t* data, int8_t* errs)
{
assert(data != nullptr);
@ -583,6 +592,9 @@ bool RS634717::decode452620(uint8_t* data)
for (uint32_t i = 0U; i < 26U; i++, offset += 6)
Utils::hex2Bin(codeword[9 + i], data, offset);
if (errs != nullptr)
*errs = (int8_t)ec;
if ((ec == -1) || (ec > 9)) {
return false;
}
@ -615,7 +627,7 @@ void RS634717::encode452620(uint8_t* data)
/* Decode RS (44,16,29) FEC. */
bool RS634717::decode441629(uint8_t* data)
bool RS634717::decode441629(uint8_t* data, int8_t* errs)
{
assert(data != nullptr);
@ -637,6 +649,9 @@ bool RS634717::decode441629(uint8_t* data)
for (uint32_t i = 0U; i < 16U; i++, offset += 6)
Utils::hex2Bin(codeword[19 + i], data, offset);
if (errs != nullptr)
*errs = (int8_t)ec;
if ((ec == -1) || (ec > 14)) {
return false;
}

@ -5,7 +5,7 @@
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2016 Jonathan Naylor, G4KLX
* Copyright (C) 2017,2023,2025 Bryan Biedenkapp, N2PLL
* Copyright (C) 2017,2023,2025,2026 Bryan Biedenkapp, N2PLL
*
*/
/**
@ -73,9 +73,10 @@ namespace edac
/**
* @brief Decode RS (36,20,17) FEC.
* @param data Reed-Solomon FEC encoded data to decode.
* @param[out] errs Optional, number of symbol errors corrected (0-8), or -1 if uncorrectable.
* @returns bool True, if data was decoded, otherwise false.
*/
bool decode362017(uint8_t* data);
bool decode362017(uint8_t* data, int8_t* errs = nullptr);
/**
* @brief Encode RS (36,20,17) FEC.
* @param data Raw data to encode with Reed-Solomon FEC.
@ -87,9 +88,10 @@ namespace edac
/**
* @brief Decode RS (52,30,23) FEC.
* @param data Reed-Solomon FEC encoded data to decode.
* @param[out] errs Optional, number of symbol errors corrected (0-11), or -1 if uncorrectable.
* @returns bool True, if data was decoded, otherwise false.
*/
bool decode523023(uint8_t* data);
bool decode523023(uint8_t* data, int8_t* errs = nullptr);
/**
* @brief Encode RS (52,30,23) FEC.
* @param data Raw data to encode with Reed-Solomon FEC.
@ -99,9 +101,10 @@ namespace edac
/**
* @brief Decode RS (46,26,21) FEC.
* @param data Reed-Solomon FEC encoded data to decode.
* @param[out] errs Optional, number of symbol errors corrected (0-10), or -1 if uncorrectable.
* @returns bool True, if data was decoded, otherwise false.
*/
bool decode462621(uint8_t* data);
bool decode462621(uint8_t* data, int8_t* errs = nullptr);
/**
* @brief Encode RS (46,26,21) FEC.
* @param data Raw data to encode with Reed-Solomon FEC.
@ -111,9 +114,10 @@ namespace edac
/**
* @brief Decode RS (45,26,20) FEC.
* @param data Reed-Solomon FEC encoded data to decode.
* @param[out] errs Optional, number of symbol errors corrected (0-10), or -1 if uncorrectable.
* @returns bool True, if data was decoded, otherwise false.
*/
bool decode452620(uint8_t* data);
bool decode452620(uint8_t* data, int8_t* errs = nullptr);
/**
* @brief Encode RS (45,26,20) FEC.
* @param data Raw data to encode with Reed-Solomon FEC.
@ -123,9 +127,10 @@ namespace edac
/**
* @brief Decode RS (44,16,29) FEC.
* @param data Reed-Solomon FEC encoded data to decode.
* @param[out] errs Optional, number of symbol errors corrected (0-14), or -1 if uncorrectable.
* @returns bool True, if data was decoded, otherwise false.
*/
bool decode441629(uint8_t* data);
bool decode441629(uint8_t* data, int8_t* errs = nullptr);
/**
* @brief Encode RS (44,16,29) FEC.
* @param data Raw data to encode with Reed-Solomon FEC.

@ -265,7 +265,9 @@ bool LC::decodeHDU(const uint8_t* data, bool rawOnly)
// decode RS (36,20,17) FEC
try {
bool ret = m_rs.decode362017(rs);
int8_t errs = -1;
bool ret = m_rs.decode362017(rs, &errs);
m_fecErrs = errs;
if (!ret) {
LogError(LOG_P25, "LC::decodeHDU(), failed to decode RS (36,20,17) FEC");
return false;
@ -687,7 +689,9 @@ bool LC::decodeVCH_MACPDU_IEMI(const uint8_t* data, bool sync)
// decode RS (46,26,21) FEC
try {
bool ret = m_rs.decode462621(raw);
int8_t errs = -1;
bool ret = m_rs.decode462621(raw, &errs);
m_fecErrs = errs;
if (!ret) {
LogError(LOG_P25, "LC::decodeVCH_MACPDU_IEMI(), failed to decode RS (46,26,21) FEC");
return false;
@ -772,7 +776,9 @@ bool LC::decodeVCH_MACPDU_OEMI(const uint8_t* data, bool sync)
// decode RS (45,26,20) FEC
try {
bool ret = m_rs.decode452620(raw);
int8_t errs = -1;
bool ret = m_rs.decode452620(raw, &errs);
m_fecErrs = errs;
if (!ret) {
LogError(LOG_P25, "LC::decodeVCH_MACPDU_OEMI(), failed to decode RS (45,26,20) FEC");
return false;
@ -807,7 +813,9 @@ bool LC::decodeVCH_MACPDU_OEMI(const uint8_t* data, bool sync)
// decode RS (52,30,23) FEC
try {
bool ret = m_rs.decode523023(raw);
int8_t errs = -1;
bool ret = m_rs.decode523023(raw, &errs);
m_fecErrs = errs;
if (!ret) {
LogError(LOG_P25, "LC::decodeVCH_MACPDU_OEMI(), failed to decode RS (52,30,23) FEC");
return false;

@ -25,7 +25,9 @@ TEST_CASE("RS241213 preserves all-zero payload", "[edac][rs241213]") {
RS634717 rs;
rs.encode241213(data);
REQUIRE(rs.decode241213(data));
int8_t errs = -1;
REQUIRE(rs.decode241213(data, &errs));
REQUIRE(errs == 0);
for (size_t i = 0; i < 9U; i++) {
REQUIRE(data[i] == 0x00U);
@ -40,7 +42,9 @@ TEST_CASE("RS241213 preserves all-ones payload", "[edac][rs241213]") {
rs.encode241213(data);
Utils::dump(2U, "encode241213()", data, 24U);
REQUIRE(rs.decode241213(data));
int8_t errs = -1;
REQUIRE(rs.decode241213(data, &errs));
REQUIRE(errs == 0);
for (size_t i = 0; i < 9U; i++) {
REQUIRE(data[i] == 0xFFU);
@ -61,7 +65,9 @@ TEST_CASE("RS241213 preserves alternating pattern", "[edac][rs241213]") {
rs.encode241213(data);
Utils::dump(2U, "encode241213()", data, 24U);
REQUIRE(rs.decode241213(data));
int8_t errs = -1;
REQUIRE(rs.decode241213(data, &errs));
REQUIRE(errs == 0);
// Verify data portion matches original
REQUIRE(::memcmp(data, original, 9U) == 0);
@ -81,7 +87,9 @@ TEST_CASE("RS241213 preserves incrementing pattern", "[edac][rs241213]") {
rs.encode241213(data);
Utils::dump(2U, "encode241213()", data, 24U);
REQUIRE(rs.decode241213(data));
int8_t errs = -1;
REQUIRE(rs.decode241213(data, &errs));
REQUIRE(errs == 0);
REQUIRE(::memcmp(data, original, 9U) == 0);
}
@ -108,12 +116,13 @@ TEST_CASE("RS241213 corrects single-byte errors", "[edac][rs241213]") {
corrupted[pos] ^= 0xFFU; // Flip all bits in one byte
RS634717 rsDec;
bool decoded = rsDec.decode241213(corrupted);
int8_t errs = -1;
bool decoded = rsDec.decode241213(corrupted, &errs);
// RS(24,12,13) can correct up to 6 symbol errors
if (decoded) {
REQUIRE(::memcmp(corrupted, original, 9U) == 0);
}
REQUIRE(decoded);
REQUIRE(errs >= 0);
REQUIRE(::memcmp(corrupted, original, 9U) == 0);
}
}
@ -137,6 +146,8 @@ TEST_CASE("RS241213 detects uncorrectable errors", "[edac][rs241213]") {
}
// Should fail to decode
bool result = rs.decode241213(data);
REQUIRE(!result);
int8_t errs = -1;
bool result = rs.decode241213(data, &errs);
REQUIRE_FALSE(result);
REQUIRE(errs == -1);
}

@ -26,7 +26,9 @@ TEST_CASE("RS24169 preserves all-zero payload", "[edac][rs24169]") {
rs.encode24169(data);
Utils::dump(2U, "encode24169()", data, 24U);
REQUIRE(rs.decode24169(data));
int8_t errs = -1;
REQUIRE(rs.decode24169(data, &errs));
REQUIRE(errs == 0);
// First 16 bytes should be zero (data portion)
for (size_t i = 0; i < 12U; i++) {
@ -42,7 +44,9 @@ TEST_CASE("RS24169 preserves all-ones payload", "[edac][rs24169]") {
rs.encode24169(data);
Utils::dump(2U, "encode24169()", data, 24U);
REQUIRE(rs.decode24169(data));
int8_t errs = -1;
REQUIRE(rs.decode24169(data, &errs));
REQUIRE(errs == 0);
// First 16 bytes should be 0xFF
for (size_t i = 0; i < 12U; i++) {
@ -64,7 +68,9 @@ TEST_CASE("RS24169 preserves alternating pattern", "[edac][rs24169]") {
rs.encode24169(data);
Utils::dump(2U, "encode24169()", data, 24U);
REQUIRE(rs.decode24169(data));
int8_t errs = -1;
REQUIRE(rs.decode24169(data, &errs));
REQUIRE(errs == 0);
REQUIRE(::memcmp(data, original, 12U) == 0);
}
@ -83,7 +89,9 @@ TEST_CASE("RS24169 preserves incrementing pattern", "[edac][rs24169]") {
rs.encode24169(data);
Utils::dump(2U, "encode24169()", data, 24U);
REQUIRE(rs.decode24169(data));
int8_t errs = -1;
REQUIRE(rs.decode24169(data, &errs));
REQUIRE(errs == 0);
REQUIRE(::memcmp(data, original, 12U) == 0);
}
@ -110,12 +118,13 @@ TEST_CASE("RS24169 corrects single-byte errors", "[edac][rs24169]") {
corrupted[pos] ^= 0xFFU;
RS634717 rsDec;
bool decoded = rsDec.decode24169(corrupted);
int8_t errs = -1;
bool decoded = rsDec.decode24169(corrupted, &errs);
// RS(24,16,9) can correct up to 4 symbol errors
if (decoded) {
REQUIRE(::memcmp(corrupted, original, 12U) == 0);
}
REQUIRE(decoded);
REQUIRE(errs >= 0);
REQUIRE(::memcmp(corrupted, original, 12U) == 0);
}
}
@ -138,6 +147,8 @@ TEST_CASE("RS24169 detects uncorrectable errors", "[edac][rs24169]") {
data[i] ^= 0xFFU;
}
bool result = rs.decode24169(data);
REQUIRE(!result);
int8_t errs = -1;
bool result = rs.decode24169(data, &errs);
REQUIRE_FALSE(result);
REQUIRE(errs == -1);
}

@ -26,7 +26,9 @@ TEST_CASE("RS362017 preserves all-zero payload", "[edac][rs362017]") {
rs.encode362017(data);
Utils::dump(2U, "encode362017()", data, 27U);
REQUIRE(rs.decode362017(data));
int8_t errs = -1;
REQUIRE(rs.decode362017(data, &errs));
REQUIRE(errs == 0);
// First 15 bytes (20 symbols * 6 bits = 120 bits) should be zero
for (size_t i = 0; i < 15U; i++) {
@ -42,7 +44,9 @@ TEST_CASE("RS362017 preserves all-ones payload", "[edac][rs362017]") {
rs.encode362017(data);
Utils::dump(2U, "encode362017()", data, 27U);
REQUIRE(rs.decode362017(data));
int8_t errs = -1;
REQUIRE(rs.decode362017(data, &errs));
REQUIRE(errs == 0);
// First 15 bytes should be 0xFF
for (size_t i = 0; i < 15U; i++) {
@ -63,7 +67,9 @@ TEST_CASE("RS362017 preserves alternating pattern", "[edac][rs362017]") {
rs.encode362017(data);
Utils::dump(2U, "encode362017()", data, 27U);
REQUIRE(rs.decode362017(data));
int8_t errs = -1;
REQUIRE(rs.decode362017(data, &errs));
REQUIRE(errs == 0);
// Verify first 15 bytes (data portion) match
REQUIRE(::memcmp(data, original, 15U) == 0);
@ -82,7 +88,9 @@ TEST_CASE("RS362017 preserves incrementing pattern", "[edac][rs362017]") {
rs.encode362017(data);
Utils::dump(2U, "encode362017()", data, 27U);
REQUIRE(rs.decode362017(data));
int8_t errs = -1;
REQUIRE(rs.decode362017(data, &errs));
REQUIRE(errs == 0);
REQUIRE(::memcmp(data, original, 15U) == 0);
}
@ -112,12 +120,13 @@ TEST_CASE("RS362017 corrects symbol errors", "[edac][rs362017]") {
corrupted[pos] ^= 0x3FU; // Flip 6 bits (1 symbol)
RS634717 rsDec;
bool decoded = rsDec.decode362017(corrupted);
int8_t errs = -1;
bool decoded = rsDec.decode362017(corrupted, &errs);
// RS(36,20,17) can correct up to 8 symbol errors
if (decoded) {
REQUIRE(::memcmp(corrupted, original, 15U) == 0);
}
REQUIRE(decoded);
REQUIRE(errs >= 0);
REQUIRE(::memcmp(corrupted, original, 15U) == 0);
}
}
@ -139,6 +148,8 @@ TEST_CASE("RS362017 detects uncorrectable errors", "[edac][rs362017]") {
data[i] ^= 0xFFU;
}
bool result = rs.decode362017(data);
REQUIRE(!result);
int8_t errs = -1;
bool result = rs.decode362017(data, &errs);
REQUIRE_FALSE(result);
REQUIRE(errs == -1);
}

@ -26,7 +26,9 @@ TEST_CASE("RS441629 preserves all-zero payload", "[edac][rs441629]") {
rs.encode441629(data);
Utils::dump(2U, "encode441629()", data, 33U);
REQUIRE(rs.decode441629(data));
int8_t errs = -1;
REQUIRE(rs.decode441629(data, &errs));
REQUIRE(errs == 0);
// First 12 bytes (16 symbols * 6 bits = 96 bits) should be zero
for (size_t i = 0; i < 12U; i++) {
@ -42,7 +44,9 @@ TEST_CASE("RS441629 preserves all-ones payload", "[edac][rs441629]") {
rs.encode441629(data);
Utils::dump(2U, "encode441629()", data, 33U);
REQUIRE(rs.decode441629(data));
int8_t errs = -1;
REQUIRE(rs.decode441629(data, &errs));
REQUIRE(errs == 0);
// First 12 bytes should be 0xFF
for (size_t i = 0; i < 12U; i++) {
@ -63,7 +67,9 @@ TEST_CASE("RS441629 preserves alternating pattern", "[edac][rs441629]") {
rs.encode441629(data);
Utils::dump(2U, "encode441629()", data, 33U);
REQUIRE(rs.decode441629(data));
int8_t errs = -1;
REQUIRE(rs.decode441629(data, &errs));
REQUIRE(errs == 0);
// Verify first 12 bytes (data portion) match
REQUIRE(::memcmp(data, original, 12U) == 0);
@ -82,7 +88,9 @@ TEST_CASE("RS441629 preserves incrementing pattern", "[edac][rs441629]") {
rs.encode441629(data);
Utils::dump(2U, "encode441629()", data, 33U);
REQUIRE(rs.decode441629(data));
int8_t errs = -1;
REQUIRE(rs.decode441629(data, &errs));
REQUIRE(errs == 0);
REQUIRE(::memcmp(data, original, 12U) == 0);
}
@ -112,10 +120,12 @@ TEST_CASE("RS441629 corrects symbol errors", "[edac][rs441629]") {
corrupted[pos] ^= 0x3FU; // Flip 6 bits (1 symbol)
RS634717 rsDec;
bool decoded = rsDec.decode441629(corrupted);
int8_t errs = -1;
bool decoded = rsDec.decode441629(corrupted, &errs);
// RS(44,16,29) can correct up to 14 symbol errors (very strong code)
if (decoded) {
REQUIRE(errs == 2);
REQUIRE(::memcmp(corrupted, original, 12U) == 0);
}
}
@ -141,7 +151,9 @@ TEST_CASE("RS441629 corrects multiple symbol errors", "[edac][rs441629]") {
data[26] ^= 0x3FU; // Parity region
data[30] ^= 0x3FU; // Parity region
REQUIRE(rs.decode441629(data));
int8_t errs = -1;
REQUIRE(rs.decode441629(data, &errs));
REQUIRE(errs == 8);
REQUIRE(::memcmp(data, original, 12U) == 0);
}
@ -166,7 +178,9 @@ TEST_CASE("RS441629 corrects many symbol errors", "[edac][rs441629]") {
data[26] ^= 0x0FU;
data[30] ^= 0x0FU;
REQUIRE(rs.decode441629(data));
int8_t errs = -1;
REQUIRE(rs.decode441629(data, &errs));
REQUIRE(errs == 7);
REQUIRE(::memcmp(data, original, 12U) == 0);
}
@ -188,6 +202,8 @@ TEST_CASE("RS441629 detects uncorrectable errors", "[edac][rs441629]") {
data[i] ^= 0xFFU;
}
bool result = rs.decode441629(data);
REQUIRE(!result);
int8_t errs = -1;
bool result = rs.decode441629(data, &errs);
REQUIRE_FALSE(result);
REQUIRE(errs == -1);
}

@ -41,7 +41,9 @@ TEST_CASE("RS452620 preserves all-zero payload", "[edac][rs452620]") {
rs.encode452620(data);
Utils::dump(2U, "encode452620()", data, 34U);
REQUIRE(rs.decode452620(data));
int8_t errs = -1;
REQUIRE(rs.decode452620(data, &errs));
REQUIRE(errs == 0);
// First 19.5 bytes (26 symbols * 6 bits = 156 bits) should be zero
for (size_t i = 0; i < 19U; i++) {
@ -57,7 +59,9 @@ TEST_CASE("RS452620 preserves all-ones payload", "[edac][rs452620]") {
rs.encode452620(data);
Utils::dump(2U, "encode452620()", data, 34U);
REQUIRE(rs.decode452620(data));
int8_t errs = -1;
REQUIRE(rs.decode452620(data, &errs));
REQUIRE(errs == 9);
// First 19 bytes should be 0xFF
for (size_t i = 0; i < 19U; i++) {
@ -78,7 +82,9 @@ TEST_CASE("RS452620 preserves alternating pattern", "[edac][rs452620]") {
rs.encode452620(data);
Utils::dump(2U, "encode452620()", data, 34U);
REQUIRE(rs.decode452620(data));
int8_t errs = -1;
REQUIRE(rs.decode452620(data, &errs));
REQUIRE(errs == 9);
// Verify first 19 bytes (data portion) match
REQUIRE(::memcmp(data, original, 19U) == 0);
@ -97,7 +103,9 @@ TEST_CASE("RS452620 preserves incrementing pattern", "[edac][rs452620]") {
rs.encode452620(data);
Utils::dump(2U, "encode452620()", data, 34U);
REQUIRE(rs.decode452620(data));
int8_t errs = -1;
REQUIRE(rs.decode452620(data, &errs));
REQUIRE(errs == 9);
REQUIRE(::memcmp(data, original, 19U) == 0);
}
@ -127,10 +135,12 @@ TEST_CASE("RS452620 corrects symbol errors", "[edac][rs452620]") {
corrupted[pos] ^= 0x3FU; // Flip 6 bits (1 symbol)
RS634717 rsDec;
bool decoded = rsDec.decode452620(corrupted);
int8_t errs = -1;
bool decoded = rsDec.decode452620(corrupted, &errs);
// RS(45,26,20) can correct up to 9 symbol errors
if (decoded) {
REQUIRE(errs == 1);
REQUIRE(::memcmp(corrupted, original, 19U) == 0);
}
}
@ -157,7 +167,9 @@ TEST_CASE("RS452620 corrects multiple symbol errors", "[edac][rs452620]") {
injectSymbolError(data, 15, 0x01); // Corrupt data symbol 15 with single bit
injectSymbolError(data, 20, 0x01); // Corrupt data symbol 20 with single bit
REQUIRE(rs.decode452620(data));
int8_t errs = -1;
REQUIRE(rs.decode452620(data, &errs));
REQUIRE(errs == 3);
REQUIRE(::memcmp(data, original, 19U) == 0);
}
@ -179,6 +191,8 @@ TEST_CASE("RS452620 detects uncorrectable errors", "[edac][rs452620]") {
data[i] ^= 0xFFU;
}
bool result = rs.decode452620(data);
REQUIRE(!result);
int8_t errs = -1;
bool result = rs.decode452620(data, &errs);
REQUIRE_FALSE(result);
REQUIRE(errs == -1);
}

@ -41,7 +41,9 @@ TEST_CASE("RS462621 preserves all-zero payload", "[edac][rs462621]") {
rs.encode462621(data);
Utils::dump(2U, "encode462621()", data, 35U);
REQUIRE(rs.decode462621(data));
int8_t errs = -1;
REQUIRE(rs.decode462621(data, &errs));
REQUIRE(errs == 0);
// First 19.5 bytes (26 symbols * 6 bits = 156 bits) should be zero
for (size_t i = 0; i < 19U; i++) {
@ -57,7 +59,9 @@ TEST_CASE("RS462621 preserves all-ones payload", "[edac][rs462621]") {
rs.encode462621(data);
Utils::dump(2U, "encode462621()", data, 35U);
REQUIRE(rs.decode462621(data));
int8_t errs = -1;
REQUIRE(rs.decode462621(data, &errs));
REQUIRE(errs == 8);
// First 19 bytes should be 0xFF
for (size_t i = 0; i < 19U; i++) {
@ -78,7 +82,9 @@ TEST_CASE("RS462621 preserves alternating pattern", "[edac][rs462621]") {
rs.encode462621(data);
Utils::dump(2U, "encode462621()", data, 35U);
REQUIRE(rs.decode462621(data));
int8_t errs = -1;
REQUIRE(rs.decode462621(data, &errs));
REQUIRE(errs == 8);
// Verify first 19 bytes (data portion) match
REQUIRE(::memcmp(data, original, 19U) == 0);
@ -97,7 +103,9 @@ TEST_CASE("RS462621 preserves incrementing pattern", "[edac][rs462621]") {
rs.encode462621(data);
Utils::dump(2U, "encode462621()", data, 35U);
REQUIRE(rs.decode462621(data));
int8_t errs = -1;
REQUIRE(rs.decode462621(data, &errs));
REQUIRE(errs == 8);
REQUIRE(::memcmp(data, original, 19U) == 0);
}
@ -127,10 +135,12 @@ TEST_CASE("RS462621 corrects symbol errors", "[edac][rs462621]") {
corrupted[pos] ^= 0x3FU; // Flip 6 bits (1 symbol)
RS634717 rsDec;
bool decoded = rsDec.decode462621(corrupted);
int8_t errs = -1;
bool decoded = rsDec.decode462621(corrupted, &errs);
// RS(46,26,21) can correct up to 10 symbol errors
if (decoded) {
REQUIRE(errs >= 0);
REQUIRE(::memcmp(corrupted, original, 19U) == 0);
}
}
@ -157,7 +167,9 @@ TEST_CASE("RS462621 corrects multiple symbol errors", "[edac][rs462621]") {
injectSymbolError(data, 15, 0x01); // Corrupt data symbol 15 with single bit
injectSymbolError(data, 20, 0x01); // Corrupt data symbol 20 with single bit
REQUIRE(rs.decode462621(data));
int8_t errs = -1;
REQUIRE(rs.decode462621(data, &errs));
REQUIRE(errs == 3);
REQUIRE(::memcmp(data, original, 19U) == 0);
}
@ -179,6 +191,8 @@ TEST_CASE("RS462621 detects uncorrectable errors", "[edac][rs462621]") {
data[i] ^= 0xFFU;
}
bool result = rs.decode462621(data);
REQUIRE(!result);
int8_t errs = -1;
bool result = rs.decode462621(data, &errs);
REQUIRE_FALSE(result);
REQUIRE(errs == -1);
}

@ -26,7 +26,9 @@ TEST_CASE("RS523023 preserves all-zero payload", "[edac][rs523023]") {
rs.encode523023(data);
Utils::dump(2U, "encode523023()", data, 39U);
REQUIRE(rs.decode523023(data));
int8_t errs = -1;
REQUIRE(rs.decode523023(data, &errs));
REQUIRE(errs == 0);
// First 22.5 bytes (30 symbols * 6 bits = 180 bits) should be zero
for (size_t i = 0; i < 22U; i++) {
@ -42,7 +44,9 @@ TEST_CASE("RS523023 preserves all-ones payload", "[edac][rs523023]") {
rs.encode523023(data);
Utils::dump(2U, "encode523023()", data, 39U);
REQUIRE(rs.decode523023(data));
int8_t errs = -1;
REQUIRE(rs.decode523023(data, &errs));
REQUIRE(errs == 6);
// First 22 bytes should be 0xFF
for (size_t i = 0; i < 22U; i++) {
@ -63,7 +67,9 @@ TEST_CASE("RS523023 preserves alternating pattern", "[edac][rs523023]") {
rs.encode523023(data);
Utils::dump(2U, "encode523023()", data, 39U);
REQUIRE(rs.decode523023(data));
int8_t errs = -1;
REQUIRE(rs.decode523023(data, &errs));
REQUIRE(errs == 6);
// Verify first 22 bytes (data portion) match
REQUIRE(::memcmp(data, original, 22U) == 0);
@ -82,7 +88,9 @@ TEST_CASE("RS523023 preserves incrementing pattern", "[edac][rs523023]") {
rs.encode523023(data);
Utils::dump(2U, "encode523023()", data, 39U);
REQUIRE(rs.decode523023(data));
int8_t errs = -1;
REQUIRE(rs.decode523023(data, &errs));
REQUIRE(errs == 6);
REQUIRE(::memcmp(data, original, 22U) == 0);
}
@ -112,10 +120,12 @@ TEST_CASE("RS523023 corrects symbol errors", "[edac][rs523023]") {
corrupted[pos] ^= 0x3FU; // Flip 6 bits (1 symbol)
RS634717 rsDec;
bool decoded = rsDec.decode523023(corrupted);
int8_t errs = -1;
bool decoded = rsDec.decode523023(corrupted, &errs);
// RS(52,30,23) can correct up to 11 symbol errors
if (decoded) {
REQUIRE(errs >= 0);
REQUIRE(::memcmp(corrupted, original, 22U) == 0);
}
}
@ -139,7 +149,9 @@ TEST_CASE("RS523023 corrects multiple symbol errors", "[edac][rs523023]") {
data[30] ^= 0x01U; // Single bit error
data[36] ^= 0x01U; // Single bit error
REQUIRE(rs.decode523023(data));
int8_t errs = -1;
REQUIRE(rs.decode523023(data, &errs));
REQUIRE(errs == 9);
REQUIRE(::memcmp(data, original, 22U) == 0);
}
@ -161,6 +173,8 @@ TEST_CASE("RS523023 detects uncorrectable errors", "[edac][rs523023]") {
data[i] ^= 0xFFU;
}
bool result = rs.decode523023(data);
REQUIRE(!result);
int8_t errs = -1;
bool result = rs.decode523023(data, &errs);
REQUIRE_FALSE(result);
REQUIRE(errs == -1);
}

@ -61,12 +61,15 @@ TEST_CASE("P25 HDU Reed-Soloman 36,20,17 Test", "[p25][hdu_rs362017]") {
// decode RS (36,20,17) FEC
try {
bool ret = m_rs.decode362017(rs);
int8_t errs = -1;
bool ret = m_rs.decode362017(rs, &errs);
if (!ret) {
::LogError("T", "LC::decodeHDU(), failed to decode RS (36,20,17) FEC");
failed = true;
goto cleanup;
}
REQUIRE(errs > 0);
REQUIRE(errs <= 8);
}
catch (...) {
Utils::dump(2U, "P25, RS excepted with input data", rs, P25_HDU_LENGTH_BYTES);

@ -59,12 +59,15 @@ TEST_CASE("P25 LDU1 Reed-Soloman 24,12,13 Test", "[p25][ldu1_rs241213]") {
// decode RS (24,12,13) FEC
try {
bool ret = m_rs.decode241213(rs);
int8_t errs = -1;
bool ret = m_rs.decode241213(rs, &errs);
if (!ret) {
::LogError("T", "LC::decodeLDU1(), failed to decode RS (24,12,13) FEC");
failed = true;
goto cleanup;
}
REQUIRE(errs > 0);
REQUIRE(errs <= 6);
}
catch (...) {
Utils::dump(2U, "P25, RS excepted with input data", rs, P25_LDU_LC_FEC_LENGTH_BYTES);

@ -58,12 +58,15 @@ TEST_CASE("P25 LDU2 Reed-Soloman 24,16,9 Test", "[p25][ldu2_rs24169]") {
// decode RS (24,16,9) FEC
try {
bool ret = m_rs.decode24169(rs);
int8_t errs = -1;
bool ret = m_rs.decode24169(rs, &errs);
if (!ret) {
::LogError("T", "LC::decodeLDU2(), failed to decode RS (24,16,9) FEC");
failed = true;
goto cleanup;
}
REQUIRE(errs > 0);
REQUIRE(errs <= 4);
}
catch (...) {
Utils::dump(2U, "P25, RS excepted with input data", rs, P25_LDU_LC_FEC_LENGTH_BYTES);

Loading…
Cancel
Save

Powered by TurnKey Linux.