Skip to content

Commit

Permalink
Get the convolution BER directly from the decoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Jun 27, 2021
1 parent 5033763 commit 8547a21
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 20 deletions.
4 changes: 2 additions & 2 deletions M17Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
19 changes: 14 additions & 5 deletions M17Convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions M17Convolution.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,8 +26,8 @@ class CM17Convolution {
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;
Expand All @@ -42,7 +42,8 @@ class CM17Convolution {

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;
};
Expand Down
13 changes: 11 additions & 2 deletions NXDNConvolution.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions NXDNConvolution.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,7 +28,8 @@ class CNXDNConvolution {

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;

Expand Down
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H

const char* VERSION = "20210625";
const char* VERSION = "20210627";

#endif
13 changes: 11 additions & 2 deletions YSFConvolution.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions YSFConvolution.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,7 +28,8 @@ class CYSFConvolution {

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;

Expand Down

0 comments on commit 8547a21

Please sign in to comment.