Fix and simplify the M17 receiver.

This commit is contained in:
Jonathan Naylor 2021-03-14 18:13:05 +00:00
parent 9a3e3704e2
commit df3a140173
5 changed files with 119 additions and 104 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2013,2015,2016,2018,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2013,2015,2016,2018,2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Colin Durbridge G4EML
* Copyright (C) 2016,2017,2018,2019 by Andy Uribe CA6JAU
* Copyright (C) 2019 by Florian Wolters DF2ET
@ -60,9 +60,10 @@ const uint8_t MMDVM_P25_LOST = 0x32U;
const uint8_t MMDVM_NXDN_DATA = 0x40U;
const uint8_t MMDVM_NXDN_LOST = 0x41U;
const uint8_t MMDVM_M17_HEADER = 0x45U;
const uint8_t MMDVM_M17_DATA = 0x46U;
const uint8_t MMDVM_M17_LOST = 0x47U;
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_POCSAG_DATA = 0x50U;
@ -865,7 +866,7 @@ void CSerialPort::process()
}
break;
case MMDVM_M17_HEADER:
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);
@ -874,12 +875,12 @@ void CSerialPort::process()
if (m_modemState == STATE_IDLE)
setMode(STATE_M17);
} else {
DEBUG2("Received invalid M17 header", err);
DEBUG2("Received invalid M17 link setup data", err);
sendNAK(err);
}
break;
case MMDVM_M17_DATA:
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);
@ -888,7 +889,21 @@ void CSerialPort::process()
if (m_modemState == STATE_IDLE)
setMode(STATE_M17);
} else {
DEBUG2("Received invalid M17 data", err);
DEBUG2("Received invalid M17 stream data", err);
sendNAK(err);
}
break;
case MMDVM_M17_PACKET:
if (m_m17Enable) {
if (m_modemState == STATE_IDLE || m_modemState == STATE_M17)
err = m17TX.writeData(m_buffer + 3U, m_len - 3U);
}
if (err == 0U) {
if (m_modemState == STATE_IDLE)
setMode(STATE_M17);
} else {
DEBUG2("Received invalid M17 packet data", err);
sendNAK(err);
}
break;
@ -1248,7 +1263,7 @@ void CSerialPort::writeNXDNLost()
writeInt(1U, reply, 3);
}
void CSerialPort::writeM17Header(const uint8_t* data, uint8_t length)
void CSerialPort::writeM17LinkSetup(const uint8_t* data, uint8_t length)
{
if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE)
return;
@ -1260,7 +1275,7 @@ void CSerialPort::writeM17Header(const uint8_t* data, uint8_t length)
reply[0U] = MMDVM_FRAME_START;
reply[1U] = 0U;
reply[2U] = MMDVM_M17_HEADER;
reply[2U] = MMDVM_M17_LINK_SETUP;
uint8_t count = 3U;
for (uint8_t i = 0U; i < length; i++, count++)
@ -1271,7 +1286,7 @@ void CSerialPort::writeM17Header(const uint8_t* data, uint8_t length)
writeInt(1U, reply, count);
}
void CSerialPort::writeM17Data(const uint8_t* data, uint8_t length)
void CSerialPort::writeM17Stream(const uint8_t* data, uint8_t length)
{
if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE)
return;
@ -1283,7 +1298,30 @@ void CSerialPort::writeM17Data(const uint8_t* data, uint8_t length)
reply[0U] = MMDVM_FRAME_START;
reply[1U] = 0U;
reply[2U] = MMDVM_M17_DATA;
reply[2U] = MMDVM_M17_STREAM;
uint8_t count = 3U;
for (uint8_t i = 0U; i < length; i++, count++)
reply[count] = data[i];
reply[1U] = count;
writeInt(1U, reply, count);
}
void CSerialPort::writeM17Packet(const uint8_t* data, uint8_t length)
{
if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE)
return;
if (!m_m17Enable)
return;
uint8_t reply[130U];
reply[0U] = MMDVM_FRAME_START;
reply[1U] = 0U;
reply[2U] = MMDVM_M17_PACKET;
uint8_t count = 3U;
for (uint8_t i = 0U; i < length; i++, count++)