Add support for the new EOF sync pattern.

This commit is contained in:
Jonathan Naylor 2021-08-26 18:14:05 +01:00
parent e3cadb7f32
commit 36f607250a
7 changed files with 70 additions and 14 deletions

View file

@ -25,14 +25,17 @@ const unsigned int M17_FRAME_LENGTH_BITS = 384U;
const unsigned int M17_FRAME_LENGTH_BYTES = M17_FRAME_LENGTH_BITS / 8U;
const unsigned int M17_SYNC_LENGTH_BITS = 16U;
const unsigned int M17_SYNC_LENGTH_BYTES = M17_SYNC_LENGTH_BITS / 8U;
const uint8_t M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U};
const uint8_t M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU};
const uint8_t M17_EOF_SYNC_BYTES[] = {0x55U, 0x5DU};
const uint8_t M17_SYNC_BYTES_LENGTH = 2U;
const uint16_t M17_LINK_SETUP_SYNC_BITS = 0x55F7U;
const uint16_t M17_STREAM_SYNC_BITS = 0xFF5DU;
const uint16_t M17_EOF_SYNC_BITS = 0x555DU;
#endif

View file

@ -108,7 +108,7 @@ void CM17RX::processData(bool bit)
if (m_bufferPtr > M17_FRAME_LENGTH_BITS)
reset();
// Only search for a link setup sync in the right place +-2 symbols
// Only search for the syncs in the right place +-2 symbols
if (m_bufferPtr >= (M17_SYNC_LENGTH_BITS - 2U) && m_bufferPtr <= (M17_SYNC_LENGTH_BITS + 2U)) {
// Fuzzy matching of the stream sync bit sequence
if (countBits16(m_bitBuffer ^ M17_LINK_SETUP_SYNC_BITS) <= MAX_SYNC_BIT_RUN_ERRS) {
@ -117,10 +117,7 @@ void CM17RX::processData(bool bit)
m_bufferPtr = M17_SYNC_LENGTH_BITS;
m_state = M17RXS_LINK_SETUP;
}
}
// Only search for a stream sync in the right place +-2 symbols
if (m_bufferPtr >= (M17_SYNC_LENGTH_BITS - 2U) && m_bufferPtr <= (M17_SYNC_LENGTH_BITS + 2U)) {
// Fuzzy matching of the stream sync bit sequence
if (countBits16(m_bitBuffer ^ M17_STREAM_SYNC_BITS) <= MAX_SYNC_BIT_RUN_ERRS) {
DEBUG2("M17RX: found stream sync, pos", m_bufferPtr - M17_SYNC_LENGTH_BITS);
@ -128,6 +125,14 @@ void CM17RX::processData(bool bit)
m_bufferPtr = M17_SYNC_LENGTH_BITS;
m_state = M17RXS_STREAM;
}
// Fuzzy matching of the eof sync bit sequence
if (countBits16(m_bitBuffer ^ M17_EOF_SYNC_BITS) <= MAX_SYNC_BIT_RUN_ERRS) {
DEBUG2("M17RX: found eof sync, pos", m_bufferPtr - M17_SYNC_LENGTH_BITS);
io.setDecode(false);
serial.writeM17EOT();
reset();
}
}
// Send a frame to the host if the required number of bits have been received

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2018,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2009-2018,2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 2017 by Andy Uribe CA6JAU
*
* This program is free software; you can redistribute it and/or modify
@ -82,7 +82,7 @@ void CM17TX::process()
}
}
uint8_t CM17TX::writeData(const uint8_t* data, uint8_t length)
uint8_t CM17TX::writeLinkSetup(const uint8_t* data, uint8_t length)
{
if (length != (M17_FRAME_LENGTH_BYTES + 1U))
return 4U;
@ -97,6 +97,33 @@ uint8_t CM17TX::writeData(const uint8_t* data, uint8_t length)
return 0U;
}
uint8_t CM17TX::writeStream(const uint8_t* data, uint8_t length)
{
if (length != (M17_FRAME_LENGTH_BYTES + 1U))
return 4U;
uint16_t space = m_buffer.getSpace();
if (space < M17_FRAME_LENGTH_BYTES)
return 5U;
for (uint8_t i = 0U; i < M17_FRAME_LENGTH_BYTES; i++)
m_buffer.put(data[i + 1U]);
return 0U;
}
uint8_t CM17TX::writeEOT()
{
uint16_t space = m_buffer.getSpace();
if (space < M17_SYNC_LENGTH_BYTES)
return 5U;
for (uint8_t i = 0U; i < M17_SYNC_LENGTH_BYTES; i++)
m_buffer.put(M17_EOF_SYNC_BYTES[i]);
return 0U;
}
void CM17TX::writeByte(uint8_t c)
{
uint8_t bit;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2017,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2017,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
@ -27,7 +27,9 @@ class CM17TX {
public:
CM17TX();
uint8_t writeData(const uint8_t* data, uint8_t length);
uint8_t writeLinkSetup(const uint8_t* data, uint8_t length);
uint8_t writeStream(const uint8_t* data, uint8_t length);
uint8_t writeEOT();
void process();

View file

@ -64,6 +64,7 @@ const uint8_t MMDVM_M17_LINK_SETUP = 0x45U;
const uint8_t MMDVM_M17_STREAM = 0x46U;
const uint8_t MMDVM_M17_PACKET = 0x47U;
const uint8_t MMDVM_M17_LOST = 0x48U;
const uint8_t MMDVM_M17_EOT = 0x49U;
const uint8_t MMDVM_POCSAG_DATA = 0x50U;
@ -869,7 +870,7 @@ void CSerialPort::process()
case MMDVM_M17_LINK_SETUP:
if (m_m17Enable) {
if (m_modemState == STATE_IDLE || m_modemState == STATE_M17)
err = m17TX.writeData(m_buffer + 3U, m_len - 3U);
err = m17TX.writeLinkSetup(m_buffer + 3U, m_len - 3U);
}
if (err == 0U) {
if (m_modemState == STATE_IDLE)
@ -883,7 +884,7 @@ void CSerialPort::process()
case MMDVM_M17_STREAM:
if (m_m17Enable) {
if (m_modemState == STATE_IDLE || m_modemState == STATE_M17)
err = m17TX.writeData(m_buffer + 3U, m_len - 3U);
err = m17TX.writeStream(m_buffer + 3U, m_len - 3U);
}
if (err == 0U) {
if (m_modemState == STATE_IDLE)
@ -894,16 +895,16 @@ void CSerialPort::process()
}
break;
case MMDVM_M17_PACKET:
case MMDVM_M17_EOT:
if (m_m17Enable) {
if (m_modemState == STATE_IDLE || m_modemState == STATE_M17)
err = m17TX.writeData(m_buffer + 3U, m_len - 3U);
err = m17TX.writeEOT();
}
if (err == 0U) {
if (m_modemState == STATE_IDLE)
setMode(STATE_M17);
} else {
DEBUG2("Received invalid M17 packet data", err);
DEBUG2("Received invalid M17 EOT", err);
sendNAK(err);
}
break;
@ -1309,6 +1310,23 @@ void CSerialPort::writeM17Stream(const uint8_t* data, uint8_t length)
writeInt(1U, reply, count);
}
void CSerialPort::writeM17EOT()
{
if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE)
return;
if (!m_m17Enable)
return;
uint8_t reply[3U];
reply[0U] = MMDVM_FRAME_START;
reply[1U] = 3U;
reply[2U] = MMDVM_M17_EOT;
writeInt(1U, reply, 3);
}
void CSerialPort::writeM17Lost()
{
if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE)

View file

@ -54,6 +54,7 @@ public:
void writeM17LinkSetup(const uint8_t* data, uint8_t length);
void writeM17Stream(const uint8_t* data, uint8_t length);
void writeM17EOT();
void writeM17Lost();
#if defined(SEND_RSSI_DATA)

View file

@ -26,7 +26,7 @@
#define VER_MAJOR "1"
#define VER_MINOR "5"
#define VER_REV "2"
#define VERSION_DATE "20210822"
#define VERSION_DATE "20210826"
#if defined(ZUMSPOT_ADF7021)
#define BOARD_INFO "ZUMspot"