Merge branch 'master' into mqtt

This commit is contained in:
Jonathan Naylor
2024-09-30 18:53:33 +01:00
12 changed files with 1249 additions and 313 deletions

View File

@@ -168,7 +168,7 @@ bool CDStarNetwork::writePoll(const char* text)
buffer[4] = 0x0AU; // Poll with text buffer[4] = 0x0AU; // Poll with text
unsigned int length = ::strlen(text); unsigned int length = (unsigned int)::strlen(text);
// Include the nul at the end also // Include the nul at the end also
::memcpy(buffer + 5U, text, length + 1U); ::memcpy(buffer + 5U, text, length + 1U);

View File

@@ -238,8 +238,9 @@
<ClInclude Include="QR1676.h" /> <ClInclude Include="QR1676.h" />
<ClInclude Include="RemoteControl.h" /> <ClInclude Include="RemoteControl.h" />
<ClInclude Include="RingBuffer.h" /> <ClInclude Include="RingBuffer.h" />
<ClInclude Include="RS.h" />
<ClInclude Include="RS129.h" /> <ClInclude Include="RS129.h" />
<ClInclude Include="RS241213.h" /> <ClInclude Include="RS634717.h" />
<ClInclude Include="RSSIInterpolator.h" /> <ClInclude Include="RSSIInterpolator.h" />
<ClInclude Include="NXDNSACCH.h" /> <ClInclude Include="NXDNSACCH.h" />
<ClInclude Include="UARTController.h" /> <ClInclude Include="UARTController.h" />
@@ -334,7 +335,7 @@
<ClCompile Include="QR1676.cpp" /> <ClCompile Include="QR1676.cpp" />
<ClCompile Include="RemoteControl.cpp" /> <ClCompile Include="RemoteControl.cpp" />
<ClCompile Include="RS129.cpp" /> <ClCompile Include="RS129.cpp" />
<ClCompile Include="RS241213.cpp" /> <ClCompile Include="RS634717.cpp" />
<ClCompile Include="RSSIInterpolator.cpp" /> <ClCompile Include="RSSIInterpolator.cpp" />
<ClCompile Include="UARTController.cpp" /> <ClCompile Include="UARTController.cpp" />
<ClCompile Include="Modem.cpp" /> <ClCompile Include="Modem.cpp" />

View File

@@ -182,9 +182,6 @@
<ClInclude Include="BCH.h"> <ClInclude Include="BCH.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="RS241213.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SerialPort.h"> <ClInclude Include="SerialPort.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
@@ -314,6 +311,12 @@
<ClInclude Include="MQTTConnection.h"> <ClInclude Include="MQTTConnection.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="RS634717.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RS.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="BPTC19696.cpp"> <ClCompile Include="BPTC19696.cpp">
@@ -466,9 +469,6 @@
<ClCompile Include="BCH.cpp"> <ClCompile Include="BCH.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="RS241213.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SerialPort.cpp"> <ClCompile Include="SerialPort.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
@@ -586,5 +586,8 @@
<ClCompile Include="MQTTConnection.cpp"> <ClCompile Include="MQTTConnection.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="RS634717.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -84,14 +84,14 @@ bool CMQTTConnection::publish(const char* topic, const char* text)
assert(topic != NULL); assert(topic != NULL);
assert(text != NULL); assert(text != NULL);
return publish(topic, (unsigned char*)text, ::strlen(text)); return publish(topic, (unsigned char*)text, (unsigned int)::strlen(text));
} }
bool CMQTTConnection::publish(const char* topic, const std::string& text) bool CMQTTConnection::publish(const char* topic, const std::string& text)
{ {
assert(topic != NULL); assert(topic != NULL);
return publish(topic, (unsigned char*)text.c_str(), text.size()); return publish(topic, (unsigned char*)text.c_str(), (unsigned int)text.size());
} }
bool CMQTTConnection::publish(const char* topic, const unsigned char* data, unsigned int len) bool CMQTTConnection::publish(const char* topic, const unsigned char* data, unsigned int len)

View File

@@ -14,7 +14,7 @@ OBJECTS = \
MQTTConnection.o Modem.o ModemPort.o Mutex.o NullController.o NXDNAudio.o NXDNControl.o \ MQTTConnection.o Modem.o ModemPort.o Mutex.o NullController.o NXDNAudio.o NXDNControl.o \
NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o \ NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o \
NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o \ NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o \
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialPort.o StopWatch.o Sync.o Thread.o \ POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS634717.o RSSIInterpolator.o SerialPort.o StopWatch.o Sync.o Thread.o \
Timer.o UARTController.o UDPController.o UDPSocket.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o Timer.o UARTController.o UDPController.o UDPSocket.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
all: MMDVMHost all: MMDVMHost

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016,2017,2023 by Jonathan Naylor G4KLX * Copyright (C) 2016,2017,2023,2024 by Jonathan Naylor G4KLX
* Copyright (C) 2018 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL * Copyright (C) 2018 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@@ -46,7 +46,7 @@ m_lcf(0x00U),
m_emergency(false), m_emergency(false),
m_srcId(0U), m_srcId(0U),
m_dstId(0U), m_dstId(0U),
m_rs241213(), m_rs(),
m_trellis() m_trellis()
{ {
m_mi = new unsigned char[P25_MI_LENGTH_BYTES]; m_mi = new unsigned char[P25_MI_LENGTH_BYTES];
@@ -91,7 +91,7 @@ bool CP25Data::decodeHeader(const unsigned char* data)
// decode RS (36,20,17) FEC // decode RS (36,20,17) FEC
try { try {
bool ret = m_rs241213.decode362017(rs); bool ret = m_rs.decode362017(rs);
if (!ret) if (!ret)
return false; return false;
} catch (...) { } catch (...) {
@@ -135,7 +135,7 @@ void CP25Data::encodeHeader(unsigned char* data)
rs[14U] = (m_dstId >> 0) & 0xFFU; // Talkgroup Address LSB rs[14U] = (m_dstId >> 0) & 0xFFU; // Talkgroup Address LSB
// encode RS (36,20,17) FEC // encode RS (36,20,17) FEC
m_rs241213.encode362017(rs); m_rs.encode362017(rs);
unsigned char raw[81U]; unsigned char raw[81U];
::memset(raw, 0x00U, 81U); ::memset(raw, 0x00U, 81U);
@@ -173,7 +173,7 @@ bool CP25Data::decodeLDU1(const unsigned char* data)
decodeLDUHamming(raw, rs + 15U); decodeLDUHamming(raw, rs + 15U);
try { try {
bool ret = m_rs241213.decode(rs); bool ret = m_rs.decode241213(rs);
if (!ret) if (!ret)
return false; return false;
} catch (...) { } catch (...) {
@@ -236,7 +236,7 @@ void CP25Data::encodeLDU1(unsigned char* data)
break; break;
} }
m_rs241213.encode(rs); m_rs.encode241213(rs);
unsigned char raw[5U]; unsigned char raw[5U];
encodeLDUHamming(raw, rs + 0U); encodeLDUHamming(raw, rs + 0U);
@@ -286,7 +286,7 @@ bool CP25Data::decodeLDU2(const unsigned char* data)
// decode RS (24,16,9) FEC // decode RS (24,16,9) FEC
try { try {
bool ret = m_rs241213.decode24169(rs); bool ret = m_rs.decode24169(rs);
if (!ret) if (!ret)
return false; return false;
} catch (...) { } catch (...) {
@@ -326,7 +326,7 @@ void CP25Data::encodeLDU2(unsigned char* data)
rs[11U] = (m_kId >> 0) & 0xFFU; // Key ID LSB rs[11U] = (m_kId >> 0) & 0xFFU; // Key ID LSB
// encode RS (24,16,9) FEC // encode RS (24,16,9) FEC
m_rs241213.encode24169(rs); m_rs.encode24169(rs);
// encode Hamming (10,6,3) FEC and interleave for LC data // encode Hamming (10,6,3) FEC and interleave for LC data
unsigned char raw[5U]; unsigned char raw[5U];

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016,2017,2023 by Jonathan Naylor G4KLX * Copyright (C) 2016,2017,2023,2024 by Jonathan Naylor G4KLX
* Copyright (C) 2018 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL * Copyright (C) 2018 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@@ -20,7 +20,7 @@
#if !defined(P25Data_H) #if !defined(P25Data_H)
#define P25Data_H #define P25Data_H
#include "RS241213.h" #include "RS634717.h"
#include "P25Trellis.h" #include "P25Trellis.h"
#include "Defines.h" #include "Defines.h"
@@ -84,7 +84,7 @@ private:
unsigned int m_srcId; unsigned int m_srcId;
unsigned int m_dstId; unsigned int m_dstId;
unsigned char m_serviceType; unsigned char m_serviceType;
CRS241213 m_rs241213; CRS634717 m_rs;
CP25Trellis m_trellis; CP25Trellis m_trellis;
void decodeLDUHamming(const unsigned char* raw, unsigned char* data); void decodeLDUHamming(const unsigned char* raw, unsigned char* data);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016,2018,2023 by Jonathan Naylor, G4KLX * Copyright (C) 2016,2018,2023,2024 by Jonathan Naylor, G4KLX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -477,7 +477,7 @@ bool CP25Trellis::fixCode12(unsigned char* points, unsigned int failPos, unsigne
unsigned int bestPos = 0U; unsigned int bestPos = 0U;
unsigned int bestVal = 0U; unsigned int bestVal = 0U;
for (unsigned int i = 0U; i < 4U; i++) { for (unsigned int i = 0U; i < 16U; i++) {
points[failPos] = i; points[failPos] = i;
unsigned char dibits[49U]; unsigned char dibits[49U];

1107
RS.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2016,2023 by Jonathan Naylor G4KLX * Copyright (C) 2016,2023,2024 by Jonathan Naylor G4KLX
* Copyright (C) 2018 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL * Copyright (C) 2018,2023 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -17,7 +17,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include "RS241213.h" #include "RS634717.h"
#include "RS.h"
#include <vector>
#if defined(USE_P25) #if defined(USE_P25)
@@ -25,7 +28,7 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
const unsigned char ENCODE_MATRIX[12U][24U] = { const unsigned char ENCODE_MATRIX_241213[12U][24U] = {
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 062, 044, 003, 025, 014, 016, 027, 003, 053, 004, 036, 047}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 062, 044, 003, 025, 014, 016, 027, 003, 053, 004, 036, 047},
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 011, 012, 011, 011, 016, 064, 067, 055, 001, 076, 026, 073}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 011, 012, 011, 011, 016, 064, 067, 055, 001, 076, 026, 073},
{0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 003, 001, 005, 075, 014, 006, 020, 044, 066, 006, 070, 066}, {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 003, 001, 005, 075, 014, 006, 020, 044, 066, 006, 070, 066},
@@ -120,20 +123,69 @@ static void hex2Bin(unsigned char input, unsigned char* output, unsigned int off
WRITE_BIT(output, offset + 5U, input & 0x01U); WRITE_BIT(output, offset + 5U, input & 0x01U);
} }
CRS241213::CRS241213() #define __RS(TYPE, SYMBOLS, PAYLOAD, POLY, FCR, PRIM) \
rs::reed_solomon<TYPE, \
rs::log_<(SYMBOLS) + 1>::value, \
(SYMBOLS) - (PAYLOAD), FCR, PRIM, \
rs::gfpoly<rs::log_<(SYMBOLS) + 1>::value, POLY>>
#define __RS_63(PAYLOAD) __RS(unsigned char, 63, PAYLOAD, 0x43, 1, 1)
class RS6347 : public __RS_63(47) {
public:
RS6347() : __RS_63(47)() { /* stub */ }
};
RS6347 rs634717; // 16 bit / 8 bit corrections max / 5 bytes total
/**
* @brief Implements Reed-Solomon (24,12,13)
*/
class RS6351 : public __RS_63(51) {
public:
RS6351() : __RS_63(51)() { /* stub */ }
};
RS6351 rs241213; // 12 bit / 6 bit corrections max / 3 bytes total
/**
* @brief Implements Reed-Solomon (24,16,9)
*/
class RS6355 : public __RS_63(55) {
public:
RS6355() : __RS_63(55)() { /* stub */ }
};
RS6355 rs24169; // 8 bit / 4 bit corrections max / 2 bytes total
CRS634717::CRS634717()
{ {
} }
CRS241213::~CRS241213() CRS634717::~CRS634717()
{ {
} }
bool CRS241213::decode(unsigned char* data) bool CRS634717::decode241213(unsigned char* data)
{ {
return decode(data, 24U, 39, 12); assert(data != NULL);
std::vector<unsigned char> codeword(63, 0);
unsigned int offset = 0U;
for (unsigned int i = 0U; i < 24U; i++, offset += 6U)
codeword[39U + i] = bin2Hex(data, offset);
int ec = rs241213.decode(codeword);
offset = 0U;
for (unsigned int i = 0U; i < 12U; i++, offset += 6U)
hex2Bin(codeword[39U + i], data, offset);
if (ec == -1 || ec >= 6)
return false;
return true;
} }
void CRS241213::encode(unsigned char* data) void CRS634717::encode241213(unsigned char* data)
{ {
assert(data != NULL); assert(data != NULL);
@@ -145,7 +197,7 @@ void CRS241213::encode(unsigned char* data)
unsigned int offset = 0U; unsigned int offset = 0U;
for (unsigned int j = 0U; j < 12U; j++, offset += 6U) { for (unsigned int j = 0U; j < 12U; j++, offset += 6U) {
unsigned char hexbit = bin2Hex(data, offset); unsigned char hexbit = bin2Hex(data, offset);
codeword[i] ^= gf6Mult(hexbit, ENCODE_MATRIX[j][i]); codeword[i] ^= gf6Mult(hexbit, ENCODE_MATRIX_241213[j][i]);
} }
} }
@@ -154,12 +206,29 @@ void CRS241213::encode(unsigned char* data)
hex2Bin(codeword[i], data, offset); hex2Bin(codeword[i], data, offset);
} }
bool CRS241213::decode24169(unsigned char* data) bool CRS634717::decode24169(unsigned char* data)
{ {
return decode(data, 24U, 39, 8); assert(data != NULL);
std::vector<unsigned char> codeword(63, 0);
unsigned int offset = 0U;
for (unsigned int i = 0U; i < 24U; i++, offset += 6U)
codeword[39U + i] = bin2Hex(data, offset);
int ec = rs24169.decode(codeword);
offset = 0U;
for (unsigned int i = 0U; i < 16U; i++, offset += 6U)
hex2Bin(codeword[39U + i], data, offset);
if (ec == -1 || ec >= 4)
return false;
return true;
} }
void CRS241213::encode24169(unsigned char* data) void CRS634717::encode24169(unsigned char* data)
{ {
assert(data != NULL); assert(data != NULL);
@@ -180,12 +249,29 @@ void CRS241213::encode24169(unsigned char* data)
hex2Bin(codeword[i], data, offset); hex2Bin(codeword[i], data, offset);
} }
bool CRS241213::decode362017(unsigned char* data) bool CRS634717::decode362017(unsigned char* data)
{ {
return decode(data, 36U, 27, 16); assert(data != NULL);
std::vector<unsigned char> codeword(63, 0);
unsigned int offset = 0U;
for (unsigned int i = 0U; i < 36U; i++, offset += 6U)
codeword[27U + i] = bin2Hex(data, offset);
int ec = rs634717.decode(codeword);
offset = 0U;
for (unsigned int i = 0U; i < 20U; i++, offset += 6U)
hex2Bin(codeword[27U + i], data, offset);
if (ec == -1 || ec >= 8)
return false;
return true;
} }
void CRS241213::encode362017(unsigned char* data) void CRS634717::encode362017(unsigned char* data)
{ {
assert(data != NULL); assert(data != NULL);
@@ -207,7 +293,7 @@ void CRS241213::encode362017(unsigned char* data)
} }
// GF(2 ^ 6) multiply(for Reed - Solomon encoder) // GF(2 ^ 6) multiply(for Reed - Solomon encoder)
unsigned char CRS241213::gf6Mult(unsigned char a, unsigned char b) const unsigned char CRS634717::gf6Mult(unsigned char a, unsigned char b) const
{ {
unsigned char p = 0x00U; unsigned char p = 0x00U;
@@ -226,264 +312,4 @@ unsigned char CRS241213::gf6Mult(unsigned char a, unsigned char b) const
return p; return p;
} }
bool CRS241213::decode(unsigned char* data, const unsigned int bitLength, const int firstData, const int roots)
{
assert(data != NULL);
//unsigned char HB[24U];
unsigned char HB[63U];
::memset(HB, 0x00U, 63U);
unsigned int offset = 0U;
for (unsigned int i = 0U; i < bitLength; i++, offset += 6)
HB[i] = bin2Hex(data, offset);
//RS (63,63-nroots,nroots+1) decoder where nroots = number of parity bits
// rsDec(8, 39) rsDec(16, 27) rsDec(12, 39)
const int nroots = roots;
int lambda[18]; // Err+Eras Locator poly
int S[17]; // syndrome poly
int b[18];
int t[18];
int omega[18];
int root[17];
int reg[18];
int locn[17];
int i, j, count, r, el, SynError, DiscrR, q, DegOmega, tmp, num1, num2, den, DegLambda;
// form the syndromes; i.e., evaluate HB(x) at roots of g(x)
for (i = 0; i <= nroots - 1; i++) {
S[i] = HB[0];
}
//for (j = 1; j <= 24; j++) { // XXX was 62
//for (j = 1; j <= (int)(bitLength - 1); j++) {
for (j = 1; j <= 62; j++) {
for (i = 0; i <= nroots - 1; i++) {
if (S[i] == 0) {
S[i] = HB[j];
}
else {
S[i] = HB[j] ^ rsGFexp[(rsGFlog[S[i]] + i + 1) % 63];
}
}
}
// convert syndromes to index form, checking for nonzero condition
SynError = 0;
for (i = 0; i <= nroots - 1; i++) {
SynError = SynError | S[i];
S[i] = rsGFlog[S[i]];
}
if (SynError == 0) {
// if syndrome is zero, rsData[] is a codeword and there are
// no errors to correct. So return rsData[] unmodified
count = 0;
return true;
}
for (i = 1; i <= nroots; i++) {
lambda[i] = 0;
}
lambda[0] = 1;
for (i = 0; i <= nroots; i++) {
b[i] = rsGFlog[lambda[i]];
}
// begin Berlekamp-Massey algorithm to determine error+erasure
// locator polynomial
r = 0;
el = 0;
while (++r <= nroots) {
// r is the step number
//r = r + 1;
// compute discrepancy at the r-th step in poly-form
DiscrR = 0;
for (i = 0; i <= r - 1; i++) {
if ((lambda[i] != 0) && (S[r - i - 1] != 63)) {
DiscrR = DiscrR ^ rsGFexp[(rsGFlog[lambda[i]] + S[r - i - 1]) % 63];
}
}
DiscrR = rsGFlog[DiscrR]; // index form
if (DiscrR == 63) {
// shift elements upward one step
for (i = nroots; i >= 1; i += -1) {
b[i] = b[i - 1];
}
b[0] = 63;
}
else {
// t(x) <-- lambda(x) - DiscrR*x*b(x)
t[0] = lambda[0];
for (i = 0; i <= nroots - 1; i++) {
if (b[i] != 63) {
t[i + 1] = lambda[i + 1] ^ rsGFexp[(DiscrR + b[i]) % 63];
}
else {
t[i + 1] = lambda[i + 1];
}
}
if (2 * el <= r - 1) {
el = r - el;
// b(x) <-- inv(DiscrR) * lambda(x)
for (i = 0; i <= nroots; i++) {
if (lambda[i]) {
b[i] = (rsGFlog[lambda[i]] - DiscrR + 63) % 63;
}
else {
b[i] = 63;
}
}
}
else {
// shift elements upward one step
for (i = nroots; i >= 1; i += -1) {
b[i] = b[i - 1];
}
b[0] = 63;
}
for (i = 0; i <= nroots; i++) {
lambda[i] = t[i];
}
}
} /* end while() */
// convert lambda to index form and compute deg(lambda(x))
DegLambda = 0;
for (i = 0; i <= nroots; i++) {
lambda[i] = rsGFlog[lambda[i]];
if (lambda[i] != 63) {
DegLambda = i;
}
}
// Find roots of the error+erasure locator polynomial by Chien search
for (i = 1; i <= nroots; i++) {
reg[i] = lambda[i];
}
count = 0;// number of roots of lambda(x)
for (i = 1; i <= 63; i++) {
q = 1;// lambda[0] is always 0
for (j = DegLambda; j >= 1; j += -1) {
if (reg[j] != 63) {
reg[j] = (reg[j] + j) % 63;
q = q ^ rsGFexp[reg[j]];
}
}
// it is a root
if (q == 0) {
// store root (index-form) and error location number
root[count] = i;
locn[count] = i - 40;
// if we have max possible roots, abort search to save time
count = count + 1;
if (count == DegLambda) {
break;
}
}
}
if (DegLambda != count) {
// deg(lambda) unequal to number of roots => uncorrectable error detected
return false;
}
// compute err+eras evaluator poly omega(x)
// = s(x)*lambda(x) (modulo x**nroots). in index form. Also find deg(omega).
DegOmega = 0;
for (i = 0; i <= nroots - 1; i++) {
tmp = 0;
if (DegLambda < i) {
j = DegLambda;
}
else {
j = i;
}
for ( /* j = j */; j >= 0; j += -1) {
if ((S[i - j] != 63) && (lambda[j] != 63)) {
tmp = tmp ^ rsGFexp[(S[i - j] + lambda[j]) % 63];
}
}
if (tmp) {
DegOmega = i;
}
omega[i] = rsGFlog[tmp];
}
omega[nroots] = 63;
//compute error values in poly-form:
// num1 = omega(inv(X(l)))
// num2 = inv(X(l))**(FCR - 1)
// den = lambda_pr(inv(X(l)))
for (j = count - 1; j >= 0; j += -1) {
num1 = 0;
for (i = DegOmega; i >= 0; i += -1) {
if (omega[i] != 63) {
num1 = num1 ^ rsGFexp[(omega[i] + i * root[j]) % 63];
}
}
num2 = rsGFexp[0];
den = 0;
// lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i]
if (DegLambda < nroots) {
i = DegLambda;
}
else {
i = nroots;
}
for (i = i & ~1; i >= 0; i += -2) {
if (lambda[i + 1] != 63) {
den = den ^ rsGFexp[(lambda[i + 1] + i * root[j]) % 63];
}
}
if (den == 0) {
return false;
}
// apply error to data
if (num1 != 0) {
if (locn[j] < firstData)
return false;
HB[locn[j]] = HB[locn[j]] ^ (rsGFexp[(rsGFlog[num1] + rsGFlog[num2] + 63 - rsGFlog[den]) % 63]);
}
}
offset = 0U;
for (unsigned int i = 0U; i < (unsigned int)nroots; i++, offset += 6)
hex2Bin(HB[i], data, offset);
return true;
}
#endif #endif

View File

@@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2016,2023 by Jonathan Naylor G4KLX * Copyright (C) 2016,2023,2024 by Jonathan Naylor G4KLX
* Copyright (C) 2018 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL * Copyright (C) 2018,2023 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -17,30 +17,29 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#if !defined(RS241213_H) #if !defined(RS634717_H)
#define RS241213_H #define RS634717_H
#include "Defines.h" #include "Defines.h"
#if defined(USE_P25) #if defined(USE_P25)
class CRS241213 class CRS634717
{ {
public: public:
CRS241213(); CRS634717();
~CRS241213(); ~CRS634717();
bool decode(unsigned char* data); bool decode241213(unsigned char* data);
bool decode24169(unsigned char* data); bool decode24169(unsigned char* data);
bool decode362017(unsigned char* data); bool decode362017(unsigned char* data);
void encode(unsigned char* data); void encode241213(unsigned char* data);
void encode24169(unsigned char* data); void encode24169(unsigned char* data);
void encode362017(unsigned char* data); void encode362017(unsigned char* data);
private: private:
unsigned char gf6Mult(unsigned char a, unsigned char b) const; unsigned char gf6Mult(unsigned char a, unsigned char b) const;
bool decode(unsigned char* data, const unsigned int bitLength, const int firstData, const int roots);
}; };
#endif #endif

View File

@@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
const char* VERSION = "20240923"; const char* VERSION = "20240930";
#endif #endif