diff --git a/M17Control.cpp b/M17Control.cpp index a5d5b34..fa9a9c6 100644 --- a/M17Control.cpp +++ b/M17Control.cpp @@ -257,7 +257,7 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len) #endif CM17Convolution conv; unsigned char frame[M17_FN_LENGTH_BYTES + M17_PAYLOAD_LENGTH_BYTES]; - conv.decodeData(data + 2U + M17_SYNC_LENGTH_BYTES + M17_LICH_FRAGMENT_FEC_LENGTH_BYTES, frame); + unsigned int convBER = conv.decodeData(data + 2U + M17_SYNC_LENGTH_BYTES + M17_LICH_FRAGMENT_FEC_LENGTH_BYTES, frame); unsigned int fn = ((frame[0U] << 8) + (frame[1U] << 0)) & 0x7FU; @@ -296,7 +296,7 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len) errors += CUtils::countBits(rfData[offset] ^ data[offset]); } - LogDebug("M17, FN: %u, errs: %u/144 (%.1f%%)", fn & 0x7FU, errors, float(errors) / 1.44F); + LogDebug("M17, FN: %u, errs: %u/%u/144 (%.1f%%)", fn & 0x7FU, errors, convBER, float(errors) / 1.44F); m_rfBits += M17_FN_LENGTH_BITS + M17_PAYLOAD_LENGTH_BITS; m_rfErrs += errors; diff --git a/M17Convolution.cpp b/M17Convolution.cpp index ae99c46..8ce22b8 100644 --- a/M17Convolution.cpp +++ b/M17Convolution.cpp @@ -118,7 +118,7 @@ void CM17Convolution::encodeData(const unsigned char* in, unsigned char* out) co } } -void CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned char* out) +unsigned int CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned char* out) { assert(in != NULL); assert(out != NULL); @@ -150,10 +150,10 @@ void CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned char* ou decode(s0, s1); } - chainback(out, 240U); + return chainback(out, 240U); } -void CM17Convolution::decodeData(const unsigned char* in, unsigned char* out) +unsigned int CM17Convolution::decodeData(const unsigned char* in, unsigned char* out) { assert(in != NULL); assert(out != NULL); @@ -185,7 +185,7 @@ void CM17Convolution::decodeData(const unsigned char* in, unsigned char* out) decode(s0, s1); } - chainback(out, 160U); + return chainback(out, 160U); } void CM17Convolution::start() @@ -229,7 +229,7 @@ void CM17Convolution::decode(uint8_t s0, uint8_t s1) m_newMetrics = tmp; } -void CM17Convolution::chainback(unsigned char* out, unsigned int nBits) +unsigned int CM17Convolution::chainback(unsigned char* out, unsigned int nBits) { assert(out != NULL); @@ -244,6 +244,15 @@ void CM17Convolution::chainback(unsigned char* out, unsigned int nBits) WRITE_BIT1(out, nBits, bit != 0U); } + + unsigned int minCost = m_oldMetrics[0]; + + for (unsigned int i = 0U; i < NUM_OF_STATES; i++) { + if (m_oldMetrics[i] < minCost) + minCost = m_oldMetrics[i]; + } + + return minCost / (M >> 1); } void CM17Convolution::encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const diff --git a/M17Convolution.h b/M17Convolution.h index 91843ba..0c5c7c3 100644 --- a/M17Convolution.h +++ b/M17Convolution.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 by Jonathan Naylor G4KLX + * Copyright (C) 2020,2021 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 @@ -26,8 +26,8 @@ public: CM17Convolution(); ~CM17Convolution(); - void decodeLinkSetup(const unsigned char* in, unsigned char* out); - void decodeData(const unsigned char* in, unsigned char* out); + unsigned int decodeLinkSetup(const unsigned char* in, unsigned char* out); + unsigned int decodeData(const unsigned char* in, unsigned char* out); void encodeLinkSetup(const unsigned char* in, unsigned char* out) const; void encodeData(const unsigned char* in, unsigned char* out) const; @@ -42,7 +42,8 @@ private: void start(); void decode(uint8_t s0, uint8_t s1); - void chainback(unsigned char* out, unsigned int nBits); + + unsigned int chainback(unsigned char* out, unsigned int nBits); void encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const; }; diff --git a/NXDNConvolution.cpp b/NXDNConvolution.cpp index 10c4504..875752e 100644 --- a/NXDNConvolution.cpp +++ b/NXDNConvolution.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2016,2018 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2016,2018,2021 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 @@ -97,7 +97,7 @@ void CNXDNConvolution::decode(uint8_t s0, uint8_t s1) m_newMetrics = tmp; } -void CNXDNConvolution::chainback(unsigned char* out, unsigned int nBits) +unsigned int CNXDNConvolution::chainback(unsigned char* out, unsigned int nBits) { assert(out != NULL); @@ -112,6 +112,15 @@ void CNXDNConvolution::chainback(unsigned char* out, unsigned int nBits) WRITE_BIT1(out, nBits, bit != 0U); } + + unsigned int minCost = m_oldMetrics[0]; + + for (unsigned int i = 0U; i < NUM_OF_STATES; i++) { + if (m_oldMetrics[i] < minCost) + minCost = m_oldMetrics[i]; + } + + return minCost / (M >> 1); } void CNXDNConvolution::encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const diff --git a/NXDNConvolution.h b/NXDNConvolution.h index d6171c9..805bc25 100644 --- a/NXDNConvolution.h +++ b/NXDNConvolution.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2018 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2018,2021 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 @@ -28,7 +28,8 @@ public: void start(); void decode(uint8_t s0, uint8_t s1); - void chainback(unsigned char* out, unsigned int nBits); + + unsigned int chainback(unsigned char* out, unsigned int nBits); void encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const; diff --git a/Version.h b/Version.h index 888ab6a..afa0ef1 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20210625"; +const char* VERSION = "20210627"; #endif diff --git a/YSFConvolution.cpp b/YSFConvolution.cpp index e1d705a..c79bf2a 100644 --- a/YSFConvolution.cpp +++ b/YSFConvolution.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2016 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2016,2021 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 @@ -96,7 +96,7 @@ void CYSFConvolution::decode(uint8_t s0, uint8_t s1) m_newMetrics = tmp; } -void CYSFConvolution::chainback(unsigned char* out, unsigned int nBits) +unsigned int CYSFConvolution::chainback(unsigned char* out, unsigned int nBits) { assert(out != NULL); @@ -111,6 +111,15 @@ void CYSFConvolution::chainback(unsigned char* out, unsigned int nBits) WRITE_BIT1(out, nBits, bit != 0U); } + + unsigned int minCost = m_oldMetrics[0]; + + for (unsigned int i = 0U; i < NUM_OF_STATES; i++) { + if (m_oldMetrics[i] < minCost) + minCost = m_oldMetrics[i]; + } + + return minCost / (M >> 1); } void CYSFConvolution::encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const diff --git a/YSFConvolution.h b/YSFConvolution.h index 23127e9..b49ddc5 100644 --- a/YSFConvolution.h +++ b/YSFConvolution.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016.2021 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 @@ -28,7 +28,8 @@ public: void start(); void decode(uint8_t s0, uint8_t s1); - void chainback(unsigned char* out, unsigned int nBits); + + unsigned int chainback(unsigned char* out, unsigned int nBits); void encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const;