Merge branch 'master' into FIR

This commit is contained in:
Jonathan Naylor
2024-10-31 15:39:45 +00:00
20 changed files with 1330 additions and 359 deletions

View File

@@ -104,10 +104,12 @@ bool CFMNetwork::open()
}
}
#if !defined(HAS_SRC)
if ((m_protocol == FMNP_RAW) && (m_sampleRate != MMDVM_SAMPLERATE)) {
LogError("The resampler needed for non-native sample rates has not been included");
return false;
}
#endif
return m_socket.open(m_addr);
}
@@ -544,7 +546,7 @@ bool CFMNetwork::writeUSRPStart()
buffer[length++] = 0x08U;
// TLV Length
buffer[length++] = 3U + 4U + 3U + 1U + 1U + m_callsign.size() + 1U;
buffer[length++] = 3U + 4U + 3U + 1U + 1U + (unsigned char)m_callsign.size() + 1U;
// DMR Id
buffer[length++] = 0x00U;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 2020,2021,2024 by Jonathan Naylor G4KLX
*
* 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
@@ -43,26 +43,30 @@ void CM17Utils::encodeCallsign(const std::string& callsign, unsigned char* encod
return;
}
unsigned int len = callsign.size();
unsigned int len = (unsigned int)callsign.size();
if (len > 9U)
len = 9U;
uint64_t enc = 0ULL;
for (int i = len - 1; i >= 0; i--) {
size_t pos = M17_CHARS.find(callsign[i]);
if (pos == std::string::npos)
pos = 0ULL;
if ((i == 0) && (callsign[i] == '#')) {
enc += 262144000000000ULL;
} else {
size_t pos = M17_CHARS.find(callsign[i]);
if (pos == std::string::npos)
pos = 0ULL;
enc *= 40ULL;
enc += pos;
enc *= 40ULL;
enc += pos;
}
}
encoded[0U] = (enc >> 40) & 0xFFU;
encoded[1U] = (enc >> 32) & 0xFFU;
encoded[2U] = (enc >> 24) & 0xFFU;
encoded[3U] = (enc >> 16) & 0xFFU;
encoded[4U] = (enc >> 8) & 0xFFU;
encoded[5U] = (enc >> 0) & 0xFFU;
encoded[4U] = (enc >> 8) & 0xFFU;
encoded[5U] = (enc >> 0) & 0xFFU;
}
void CM17Utils::decodeCallsign(const unsigned char* encoded, std::string& callsign)
@@ -71,22 +75,27 @@ void CM17Utils::decodeCallsign(const unsigned char* encoded, std::string& callsi
callsign.clear();
if (encoded[0U] == 0xFFU && encoded[1U] == 0xFFU && encoded[2U] == 0xFFU &&
encoded[3U] == 0xFFU && encoded[4U] == 0xFFU && encoded[5U] == 0xFFU) {
uint64_t enc = (uint64_t(encoded[0U]) << 40) +
(uint64_t(encoded[1U]) << 32) +
(uint64_t(encoded[2U]) << 24) +
(uint64_t(encoded[3U]) << 16) +
(uint64_t(encoded[4U]) << 8) +
(uint64_t(encoded[5U]) << 0);
if (enc == 281474976710655ULL) {
callsign = "ALL";
return;
}
uint64_t enc =
(uint64_t(encoded[0U]) << 40) +
(uint64_t(encoded[1U]) << 32) +
(uint64_t(encoded[2U]) << 24) +
(uint64_t(encoded[3U]) << 16) +
(uint64_t(encoded[4U]) << 8) +
(uint64_t(encoded[5U]) << 0);
if (enc >= 262144000000000ULL) // 40^9
if (enc >= 268697600000000ULL) {
callsign = "Invalid";
return;
}
if (enc >= 262144000000000ULL) {
callsign = "#";
enc -= 262144000000000ULL;
}
while (enc > 0ULL) {
callsign += " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/."[enc % 40ULL];

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2021,2023 by Jonathan Naylor G4KLX
* Copyright (C) 2015-2021,2023,2024 by Jonathan Naylor G4KLX
*
* 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
@@ -60,16 +60,11 @@ static int m_signal = 0;
static bool m_reload = false;
#if !defined(_WIN32) && !defined(_WIN64)
static void sigHandler1(int signum)
static void sigHandler(int signum)
{
m_killed = true;
m_signal = signum;
}
static void sigHandler2(int signum)
{
m_reload = true;
}
#endif
const char* HEADER1 = "This software is for use on amateur radio networks only,";
@@ -96,16 +91,16 @@ int main(int argc, char** argv)
}
#if !defined(_WIN32) && !defined(_WIN64)
::signal(SIGINT, sigHandler1);
::signal(SIGTERM, sigHandler1);
::signal(SIGHUP, sigHandler1);
::signal(SIGUSR1, sigHandler2);
::signal(SIGINT, sigHandler);
::signal(SIGTERM, sigHandler);
::signal(SIGHUP, sigHandler);
#endif
int ret = 0;
do {
m_signal = 0;
m_killed = false;
CMMDVMHost* host = new CMMDVMHost(std::string(iniFile));
ret = host->run();
@@ -113,6 +108,8 @@ int main(int argc, char** argv)
delete host;
switch (m_signal) {
case 0:
break;
case 2:
::LogInfo("MMDVMHost-%s exited on receipt of SIGINT", VERSION);
break;
@@ -120,16 +117,14 @@ int main(int argc, char** argv)
::LogInfo("MMDVMHost-%s exited on receipt of SIGTERM", VERSION);
break;
case 1:
::LogInfo("MMDVMHost-%s exited on receipt of SIGHUP", VERSION);
break;
case 10:
::LogInfo("MMDVMHost-%s is restarting on receipt of SIGUSR1", VERSION);
::LogInfo("MMDVMHost-%s is restarting on receipt of SIGHUP", VERSION);
m_reload = true;
break;
default:
::LogInfo("MMDVMHost-%s exited on receipt of an unknown signal", VERSION);
break;
}
} while (m_signal == 10);
} while (m_reload || (m_signal == 1));
::LogFinalise();

View File

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

View File

@@ -191,9 +191,6 @@
<ClInclude Include="BCH.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RS241213.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SerialPort.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -353,6 +350,12 @@
<ClInclude Include="FIR.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RS634717.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RS.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="BPTC19696.cpp">
@@ -514,9 +517,6 @@
<ClCompile Include="BCH.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RS241213.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SerialPort.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -664,5 +664,8 @@
<ClCompile Include="FIR.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RS634717.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -16,7 +16,7 @@ OBJECTS = \
MMDVMHost.o Modem.o ModemPort.o ModemSerialPort.o Mutex.o NetworkInfo.o Nextion.o NullController.o NullDisplay.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 \
NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o PseudoTTYController.o POCSAGControl.o \
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o TFTSurenoo.o Thread.o \
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS634717.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o TFTSurenoo.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
all: MMDVMHost RemoteCommand

View File

@@ -17,7 +17,7 @@ OBJECTS = \
M17Utils.o MMDVMHost.o Modem.o ModemPort.o ModemSerialPort.o Mutex.o NetworkInfo.o Nextion.o NullController.o NullDisplay.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 NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o PseudoTTYController.o \
POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o \
POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS634717.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o \
TFTSurenoo.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

View File

@@ -16,7 +16,7 @@ OBJECTS = \
M17Utils.o MMDVMHost.o Modem.o ModemPort.o ModemSerialPort.o Mutex.o NetworkInfo.o Nextion.o NullController.o NullDisplay.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 NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o PseudoTTYController.o \
POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o \
POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS634717.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o \
TFTSurenoo.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

View File

@@ -16,7 +16,7 @@ OBJECTS = \
M17Utils.o MMDVMHost.o Modem.o ModemPort.o ModemSerialPort.o Mutex.o NetworkInfo.o Nextion.o NullController.o NullDisplay.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 \
NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o PseudoTTYController.o POCSAGControl.o \
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o TFTSurenoo.o Thread.o \
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS634717.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o TFTSurenoo.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
all: MMDVMHost RemoteCommand

View File

@@ -20,7 +20,7 @@ OBJECTS = \
MMDVMHost.o Modem.o ModemPort.o ModemSerialPort.o Mutex.o NetworkInfo.o Nextion.o NullController.o NullDisplay.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 \
NXDNUDCH.o OLED.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o PseudoTTYController.o \
POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o \
POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS634717.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o \
TFTSurenoo.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

View File

@@ -17,7 +17,7 @@ OBJECTS = \
M17Utils.o MMDVMHost.o Modem.o ModemPort.o ModemSerialPort.o Mutex.o NetworkInfo.o Nextion.o NullController.o NullDisplay.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 NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o PseudoTTYController.o \
POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o \
POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS634717.o RSSIInterpolator.o SerialPort.o SMeter.o StopWatch.o Sync.o SHA256.o \
TFTSurenoo.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

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
*
* This program is free software; you can redistribute it and/or modify
@@ -44,7 +44,7 @@ m_lcf(0x00U),
m_emergency(false),
m_srcId(0U),
m_dstId(0U),
m_rs241213(),
m_rs(),
m_trellis()
{
m_mi = new unsigned char[P25_MI_LENGTH_BYTES];
@@ -89,7 +89,7 @@ bool CP25Data::decodeHeader(const unsigned char* data)
// decode RS (36,20,17) FEC
try {
bool ret = m_rs241213.decode362017(rs);
bool ret = m_rs.decode362017(rs);
if (!ret)
return false;
} catch (...) {
@@ -133,7 +133,7 @@ void CP25Data::encodeHeader(unsigned char* data)
rs[14U] = (m_dstId >> 0) & 0xFFU; // Talkgroup Address LSB
// encode RS (36,20,17) FEC
m_rs241213.encode362017(rs);
m_rs.encode362017(rs);
unsigned char raw[81U];
::memset(raw, 0x00U, 81U);
@@ -171,7 +171,7 @@ bool CP25Data::decodeLDU1(const unsigned char* data)
decodeLDUHamming(raw, rs + 15U);
try {
bool ret = m_rs241213.decode(rs);
bool ret = m_rs.decode241213(rs);
if (!ret)
return false;
} catch (...) {
@@ -234,7 +234,7 @@ void CP25Data::encodeLDU1(unsigned char* data)
break;
}
m_rs241213.encode(rs);
m_rs.encode241213(rs);
unsigned char raw[5U];
encodeLDUHamming(raw, rs + 0U);
@@ -284,7 +284,7 @@ bool CP25Data::decodeLDU2(const unsigned char* data)
// decode RS (24,16,9) FEC
try {
bool ret = m_rs241213.decode24169(rs);
bool ret = m_rs.decode24169(rs);
if (!ret)
return false;
} catch (...) {
@@ -324,7 +324,7 @@ void CP25Data::encodeLDU2(unsigned char* data)
rs[11U] = (m_kId >> 0) & 0xFFU; // Key ID LSB
// 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
unsigned char raw[5U];

View File

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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016,2018 by Jonathan Naylor, G4KLX
* Copyright (C) 2016,2018,2024 by Jonathan Naylor, G4KLX
*
* 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
@@ -475,7 +475,7 @@ bool CP25Trellis::fixCode12(unsigned char* points, unsigned int failPos, unsigne
unsigned int bestPos = 0U;
unsigned int bestVal = 0U;
for (unsigned int i = 0U; i < 4U; i++) {
for (unsigned int i = 0U; i < 16U; i++) {
points[failPos] = i;
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 by Jonathan Naylor G4KLX
* Copyright (C) 2018 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL
* Copyright (C) 2016,2024 by Jonathan Naylor G4KLX
* Copyright (C) 2018,2023 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL
*
* 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
@@ -17,13 +17,16 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "RS241213.h"
#include "RS634717.h"
#include "RS.h"
#include <vector>
#include <cstdio>
#include <cassert>
#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},
{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},
@@ -118,20 +121,69 @@ static void hex2Bin(unsigned char input, unsigned char* output, unsigned int off
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);
@@ -143,7 +195,7 @@ void CRS241213::encode(unsigned char* data)
unsigned int offset = 0U;
for (unsigned int j = 0U; j < 12U; j++, offset += 6U) {
unsigned char hexbit = bin2Hex(data, offset);
codeword[i] ^= gf6Mult(hexbit, ENCODE_MATRIX[j][i]);
codeword[i] ^= gf6Mult(hexbit, ENCODE_MATRIX_241213[j][i]);
}
}
@@ -152,12 +204,29 @@ void CRS241213::encode(unsigned char* data)
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);
@@ -178,12 +247,29 @@ void CRS241213::encode24169(unsigned char* data)
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);
@@ -205,7 +291,7 @@ void CRS241213::encode362017(unsigned char* data)
}
// 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;
@@ -223,262 +309,3 @@ unsigned char CRS241213::gf6Mult(unsigned char a, unsigned char b) const
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;
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2016 by Jonathan Naylor G4KLX
* Copyright (C) 2018 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL
* Copyright (C) 2016,2024 by Jonathan Naylor G4KLX
* Copyright (C) 2018,2023 by Bryan Biedenkapp <gatekeep@gmail.com> N2PLL
*
* 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
@@ -17,26 +17,25 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if !defined(RS241213_H)
#define RS241213_H
#if !defined(RS634717_H)
#define RS634717_H
class CRS241213
class CRS634717
{
public:
CRS241213();
~CRS241213();
CRS634717();
~CRS634717();
bool decode(unsigned char* data);
bool decode241213(unsigned char* data);
bool decode24169(unsigned char* data);
bool decode362017(unsigned char* data);
void encode(unsigned char* data);
void encode241213(unsigned char* data);
void encode24169(unsigned char* data);
void encode362017(unsigned char* data);
private:
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

View File

@@ -192,7 +192,7 @@ REMOTE_COMMAND CRemoteControl::getCommand()
#endif
}
m_socket.write((unsigned char*)replyStr.c_str(), replyStr.length(), address, addrlen);
m_socket.write((unsigned char*)replyStr.c_str(), (unsigned int)replyStr.length(), address, addrlen);
}
return m_command;
@@ -209,14 +209,14 @@ unsigned int CRemoteControl::getArgCount() const
case RCD_MODE_P25:
case RCD_MODE_NXDN:
case RCD_MODE_M17:
return m_args.size() - SET_MODE_ARGS;
return (unsigned int)m_args.size() - SET_MODE_ARGS;
case RCD_PAGE:
case RCD_PAGE_BCD:
case RCD_PAGE_A1:
case RCD_PAGE_A2:
return m_args.size() - 1U;
return (unsigned int)m_args.size() - 1U;
case RCD_CW:
return m_args.size() - 1U;
return (unsigned int)m_args.size() - 1U;
default:
return 0U;
}

View File

@@ -36,7 +36,11 @@
CUDPSocket::CUDPSocket(const std::string& address, unsigned short port) :
m_localAddress(address),
m_localPort(port),
#if defined(_WIN32) || defined(_WIN64)
m_fd(INVALID_SOCKET),
#else
m_fd(-1),
#endif
m_af(AF_UNSPEC)
{
}
@@ -44,7 +48,11 @@ m_af(AF_UNSPEC)
CUDPSocket::CUDPSocket(unsigned short port) :
m_localAddress(),
m_localPort(port),
#if defined(_WIN32) || defined(_WIN64)
m_fd(INVALID_SOCKET),
#else
m_fd(-1),
#endif
m_af(AF_UNSPEC)
{
}
@@ -97,7 +105,9 @@ int CUDPSocket::lookup(const std::string& hostname, unsigned short port, sockadd
return err;
}
::memcpy(&addr, res->ai_addr, address_length = res->ai_addrlen);
address_length = (unsigned int)res->ai_addrlen;
::memcpy(&addr, res->ai_addr, address_length);
::freeaddrinfo(res);
@@ -160,7 +170,11 @@ bool CUDPSocket::open(const sockaddr_storage& address)
bool CUDPSocket::open()
{
#if defined(_WIN32) || defined(_WIN64)
assert(m_fd == INVALID_SOCKET);
#else
assert(m_fd == -1);
#endif
sockaddr_storage addr;
unsigned int addrlen;
@@ -221,7 +235,14 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storag
{
assert(buffer != NULL);
assert(length > 0U);
assert(m_fd >= 0);
#if defined(_WIN32) || defined(_WIN64)
if (m_fd == INVALID_SOCKET)
return 0;
#else
if (m_fd == -1)
return 0;
#endif
// Check that the readfrom() won't block
struct pollfd pfd;
@@ -282,7 +303,11 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s
{
assert(buffer != NULL);
assert(length > 0U);
#if defined(_WIN32) || defined(_WIN64)
assert(m_fd != INVALID_SOCKET);
#else
assert(m_fd >= 0);
#endif
bool result = false;
@@ -313,13 +338,16 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s
void CUDPSocket::close()
{
if (m_fd >= 0) {
#if defined(_WIN32) || defined(_WIN64)
if (m_fd != INVALID_SOCKET) {
::closesocket(m_fd);
m_fd = INVALID_SOCKET;
}
#else
if (m_fd >= 0) {
::close(m_fd);
#endif
m_fd = -1;
}
#endif
}

View File

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