Add the CRC and callsign encoding.

This commit is contained in:
Jonathan Naylor
2020-10-18 14:51:52 +01:00
parent 48f95be982
commit 521da9b54d
8 changed files with 187 additions and 16 deletions

View File

@@ -20,6 +20,7 @@
#include "M17Defines.h"
#include "M17Utils.h"
#include "Defines.h"
#include "M17CRC.h"
#include "Utils.h"
#include "Log.h"
@@ -119,7 +120,10 @@ bool CM17Network::write(const unsigned char* data)
buffer[4U] = m_outId / 256U; // Unique session id
buffer[5U] = m_outId % 256U;
::memcpy(buffer + 6U, data, 48U);
::memcpy(buffer + 6U, data, 46U);
// Add the CRC
CM17CRC::encodeCRC(buffer + 6U, M17_LICH_LENGTH_BYTES + M17_FN_LENGTH_BYTES + M17_PAYLOAD_LENGTH_BYTES + M17_CRC_LENGTH_BYTES);
if (m_debug)
CUtils::dump(1U, "M17 data transmitted", buffer, 54U);
@@ -205,6 +209,13 @@ void CM17Network::clock(unsigned int ms)
return;
}
// Check the CRC
bool valid = CM17CRC::checkCRC(buffer + 6U, M17_LICH_LENGTH_BYTES + M17_FN_LENGTH_BYTES + M17_PAYLOAD_LENGTH_BYTES + M17_CRC_LENGTH_BYTES);
if (!valid) {
LogMessage("M17, network packet received with an invalid CRC");
return;
}
// EOT?
uint16_t fn = (buffer[38U] << 8) + (buffer[39U] << 0);
if ((fn & 0x8000U) == 0x8000U)