diff --git a/src/common/Utils.cpp b/src/common/Utils.cpp
index a48c7160..346c71ba 100644
--- a/src/common/Utils.cpp
+++ b/src/common/Utils.cpp
@@ -351,6 +351,43 @@ uint32_t Utils::setBitRange(const uint8_t* in, uint8_t* out, uint32_t start, uin
return setBits(in, out, start, start + length);
}
+///
+///
+///
+///
+///
+///
+uint8_t Utils::bin2Hex(const uint8_t* input, uint32_t offset)
+{
+ uint8_t output = 0x00U;
+
+ output |= READ_BIT(input, offset + 0U) ? 0x20U : 0x00U;
+ output |= READ_BIT(input, offset + 1U) ? 0x10U : 0x00U;
+ output |= READ_BIT(input, offset + 2U) ? 0x08U : 0x00U;
+ output |= READ_BIT(input, offset + 3U) ? 0x04U : 0x00U;
+ output |= READ_BIT(input, offset + 4U) ? 0x02U : 0x00U;
+ output |= READ_BIT(input, offset + 5U) ? 0x01U : 0x00U;
+
+ return output;
+}
+
+///
+///
+///
+///
+///
+///
+///
+void Utils::hex2Bin(const uint8_t input, uint8_t* output, uint32_t offset)
+{
+ WRITE_BIT(output, offset + 0U, input & 0x20U);
+ WRITE_BIT(output, offset + 1U, input & 0x10U);
+ WRITE_BIT(output, offset + 2U, input & 0x08U);
+ WRITE_BIT(output, offset + 3U, input & 0x04U);
+ WRITE_BIT(output, offset + 4U, input & 0x02U);
+ WRITE_BIT(output, offset + 5U, input & 0x01U);
+}
+
///
/// Returns the count of bits in the passed 8 byte value.
///
diff --git a/src/common/Utils.h b/src/common/Utils.h
index e9428694..e65c10ef 100644
--- a/src/common/Utils.h
+++ b/src/common/Utils.h
@@ -69,6 +69,11 @@ public:
///
static uint32_t setBitRange(const uint8_t* in, uint8_t* out, uint32_t start, uint32_t length);
+ ///
+ static uint8_t bin2Hex(const uint8_t* input, uint32_t offset);
+ ///
+ static void hex2Bin(const uint8_t input, uint8_t* output, uint32_t offset);
+
/// Returns the count of bits in the passed 8 byte value.
static uint8_t countBits8(uint8_t bits);
/// Returns the count of bits in the passed 32 byte value.
diff --git a/src/common/edac/RS634717.cpp b/src/common/edac/RS634717.cpp
index bec30fb6..91361ec2 100755
--- a/src/common/edac/RS634717.cpp
+++ b/src/common/edac/RS634717.cpp
@@ -32,6 +32,7 @@
#include "edac/RS634717.h"
#include "edac/rs/RS.h"
#include "Log.h"
+#include "Utils.h"
using namespace edac;
@@ -170,7 +171,7 @@ bool RS634717::decode241213(uint8_t* data)
uint32_t offset = 0U;
for (uint32_t i = 0U; i < 24U; i++, offset += 6)
- codeword[39 + i] = bin2Hex(data, offset);
+ codeword[39 + i] = Utils::bin2Hex(data, offset);
int ec = rs241213.decode(codeword);
#if DEBUG_RS
@@ -178,7 +179,7 @@ bool RS634717::decode241213(uint8_t* data)
#endif
offset = 0U;
for (uint32_t i = 0U; i < 12U; i++, offset += 6)
- hex2Bin(codeword[39 + i], data, offset);
+ Utils::hex2Bin(codeword[39 + i], data, offset);
if ((ec == -1) || (ec >= 6)) {
return false;
@@ -202,14 +203,14 @@ void RS634717::encode241213(uint8_t* data)
uint32_t offset = 0U;
for (uint32_t j = 0U; j < 12U; j++, offset += 6U) {
- uint8_t hexbit = bin2Hex(data, offset);
+ uint8_t hexbit = Utils::bin2Hex(data, offset);
codeword[i] ^= gf6Mult(hexbit, ENCODE_MATRIX[j][i]);
}
}
uint32_t offset = 0U;
for (uint32_t i = 0U; i < 24U; i++, offset += 6U)
- hex2Bin(codeword[i], data, offset);
+ Utils::hex2Bin(codeword[i], data, offset);
}
///
@@ -225,7 +226,7 @@ bool RS634717::decode24169(uint8_t* data)
uint32_t offset = 0U;
for (uint32_t i = 0U; i < 24U; i++, offset += 6)
- codeword[39 + i] = bin2Hex(data, offset);
+ codeword[39 + i] = Utils::bin2Hex(data, offset);
int ec = rs24169.decode(codeword);
#if DEBUG_RS
@@ -233,7 +234,7 @@ bool RS634717::decode24169(uint8_t* data)
#endif
offset = 0U;
for (uint32_t i = 0U; i < 16U; i++, offset += 6)
- hex2Bin(codeword[39 + i], data, offset);
+ Utils::hex2Bin(codeword[39 + i], data, offset);
if ((ec == -1) || (ec >= 4)) {
return false;
@@ -257,14 +258,14 @@ void RS634717::encode24169(uint8_t* data)
uint32_t offset = 0U;
for (uint32_t j = 0U; j < 16U; j++, offset += 6U) {
- uint8_t hexbit = bin2Hex(data, offset);
+ uint8_t hexbit = Utils::bin2Hex(data, offset);
codeword[i] ^= gf6Mult(hexbit, ENCODE_MATRIX_24169[j][i]);
}
}
uint32_t offset = 0U;
for (uint32_t i = 0U; i < 24U; i++, offset += 6U)
- hex2Bin(codeword[i], data, offset);
+ Utils::hex2Bin(codeword[i], data, offset);
}
///
@@ -280,7 +281,7 @@ bool RS634717::decode362017(uint8_t* data)
uint32_t offset = 0U;
for (uint32_t i = 0U; i < 36U; i++, offset += 6)
- codeword[27 + i] = bin2Hex(data, offset);
+ codeword[27 + i] = Utils::bin2Hex(data, offset);
int ec = rs634717.decode(codeword);
#if DEBUG_RS
@@ -288,7 +289,7 @@ bool RS634717::decode362017(uint8_t* data)
#endif
offset = 0U;
for (uint32_t i = 0U; i < 20U; i++, offset += 6)
- hex2Bin(codeword[27 + i], data, offset);
+ Utils::hex2Bin(codeword[27 + i], data, offset);
if ((ec == -1) || (ec >= 8)) {
return false;
@@ -312,57 +313,20 @@ void RS634717::encode362017(uint8_t* data)
uint32_t offset = 0U;
for (uint32_t j = 0U; j < 20U; j++, offset += 6U) {
- uint8_t hexbit = bin2Hex(data, offset);
+ uint8_t hexbit = Utils::bin2Hex(data, offset);
codeword[i] ^= gf6Mult(hexbit, ENCODE_MATRIX_362017[j][i]);
}
}
uint32_t offset = 0U;
for (uint32_t i = 0U; i < 36U; i++, offset += 6U)
- hex2Bin(codeword[i], data, offset);
+ Utils::hex2Bin(codeword[i], data, offset);
}
// ---------------------------------------------------------------------------
// Private Static Class Members
// ---------------------------------------------------------------------------
-///
-///
-///
-///
-///
-///
-uint8_t RS634717::bin2Hex(const uint8_t* input, uint32_t offset)
-{
- uint8_t output = 0x00U;
-
- output |= READ_BIT(input, offset + 0U) ? 0x20U : 0x00U;
- output |= READ_BIT(input, offset + 1U) ? 0x10U : 0x00U;
- output |= READ_BIT(input, offset + 2U) ? 0x08U : 0x00U;
- output |= READ_BIT(input, offset + 3U) ? 0x04U : 0x00U;
- output |= READ_BIT(input, offset + 4U) ? 0x02U : 0x00U;
- output |= READ_BIT(input, offset + 5U) ? 0x01U : 0x00U;
-
- return output;
-}
-
-///
-///
-///
-///
-///
-///
-///
-void RS634717::hex2Bin(const uint8_t input, uint8_t* output, uint32_t offset)
-{
- WRITE_BIT(output, offset + 0U, input & 0x20U);
- WRITE_BIT(output, offset + 1U, input & 0x10U);
- WRITE_BIT(output, offset + 2U, input & 0x08U);
- WRITE_BIT(output, offset + 3U, input & 0x04U);
- WRITE_BIT(output, offset + 4U, input & 0x02U);
- WRITE_BIT(output, offset + 5U, input & 0x01U);
-}
-
// ---------------------------------------------------------------------------
// Private Class Members
// ---------------------------------------------------------------------------
diff --git a/src/common/edac/RS634717.h b/src/common/edac/RS634717.h
index 43c0bfb3..a5cad7ff 100755
--- a/src/common/edac/RS634717.h
+++ b/src/common/edac/RS634717.h
@@ -65,11 +65,6 @@ namespace edac
void encode362017(uint8_t* data);
private:
- ///
- static uint8_t bin2Hex(const uint8_t* input, uint32_t offset);
- ///
- static void hex2Bin(const uint8_t input, uint8_t* output, uint32_t offset);
-
///
uint8_t gf6Mult(uint8_t a, uint8_t b) const;
};