Skip to content

Commit

Permalink
Add validation for M17 end bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Aug 18, 2021
1 parent 200986b commit 8e34cab
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 21 deletions.
15 changes: 6 additions & 9 deletions M17Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ m_rfErrs(0U),
m_rfBits(1U),
m_rfLSF(),
m_rfLSFn(0U),
m_rfFN(0U),
m_netLSF(),
m_netLSFn(0U),
m_rssiMapper(rssiMapper),
Expand Down Expand Up @@ -189,7 +188,6 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
m_aveRSSI = m_rssi;
m_rssiCount = 1U;
m_rfLSFn = 0U;
m_rfFN = 0U;

#if defined(DUMP_M17)
openFile();
Expand Down Expand Up @@ -238,7 +236,6 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
m_maxRSSI = m_rssi;
m_aveRSSI = m_rssi;
m_rssiCount = 1U;
m_rfFN = 0U;

#if defined(DUMP_M17)
openFile();
Expand All @@ -257,11 +254,9 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
unsigned char frame[M17_FN_LENGTH_BYTES + M17_PAYLOAD_LENGTH_BYTES];
unsigned int errors = conv.decodeData(data + 2U + M17_SYNC_LENGTH_BYTES + M17_LICH_FRAGMENT_FEC_LENGTH_BYTES, frame);

m_rfFN = (frame[0U] << 8) + (frame[1U] << 0);
uint16_t fn = (frame[0U] << 8) + (frame[1U] << 0);

LogDebug("M17, audio: FN: %u, errs: %u/272 (%.1f%%)", m_rfFN & 0x7FFFU, errors, float(errors) / 2.72F);

m_rfFN++;
LogDebug("M17, audio: FN: %u, errs: %u/272 (%.1f%%)", fn & 0x7FFFU, errors, float(errors) / 2.72F);

m_rfBits += 272U;
m_rfErrs += errors;
Expand Down Expand Up @@ -324,8 +319,10 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
if (m_rfLSFn >= 6U)
m_rfLSFn = 0U;

// Only check for the EOT marker if the frame has a reasonable BER
if ((m_rfFN & 0x8000U) == 0x8000U) {
bool bValid = (fn & 0x7FFFU) < (210U * 25U); // 210 seconds maximum
bool bEnd = (fn & 0x8000U) == 0x8000U;

if (bValid && bEnd) {
std::string source = m_rfLSF.getSource();
std::string dest = m_rfLSF.getDest();

Expand Down
1 change: 0 additions & 1 deletion M17Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class CM17Control {
unsigned int m_rfBits;
CM17LSF m_rfLSF;
unsigned int m_rfLSFn;
unsigned int m_rfFN;
CM17LSF m_netLSF;
unsigned int m_netLSFn;
CRSSIInterpolator* m_rssiMapper;
Expand Down
1 change: 0 additions & 1 deletion M17Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const unsigned int M17_FRAME_LENGTH_BYTES = M17_FRAME_LENGTH_BITS / 8U;

const unsigned char M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U};
const unsigned char M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU};
const unsigned char M17_PACKET_SYNC_BYTES[] = {0x75U, 0xFFU};

const unsigned int M17_SYNC_LENGTH_BITS = 16U;
const unsigned int M17_SYNC_LENGTH_BYTES = M17_SYNC_LENGTH_BITS / 8U;
Expand Down
8 changes: 1 addition & 7 deletions Sync.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2018,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2018,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 Down Expand Up @@ -99,9 +99,3 @@ void CSync::addM17StreamSync(unsigned char* data)
::memcpy(data, M17_STREAM_SYNC_BYTES, M17_SYNC_LENGTH_BYTES);
}

void CSync::addM17PacketSync(unsigned char* data)
{
assert(data != NULL);

::memcpy(data, M17_PACKET_SYNC_BYTES, M17_SYNC_LENGTH_BYTES);
}
3 changes: 1 addition & 2 deletions Sync.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2018,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2018,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 Down Expand Up @@ -35,7 +35,6 @@ class CSync

static void addM17LinkSetupSync(unsigned char* data);
static void addM17StreamSync(unsigned char* data);
static void addM17PacketSync(unsigned char* data);

private:
};
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 = "20210817";
const char* VERSION = "20210818";

#endif

0 comments on commit 8e34cab

Please sign in to comment.