Update to the latest M17 specification.

This commit is contained in:
Jonathan Naylor 2020-11-26 10:22:03 +00:00
parent d732807ee3
commit c9bd700100
6 changed files with 130 additions and 15 deletions

View file

@ -26,10 +26,13 @@ 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_BITS = 16U;
const uint8_t M17_SYNC_BYTES[] = {0x32U, 0x43U}; const uint8_t M17_HEADER_SYNC_BYTES[] = {0x5DU, 0xDDU};
const uint8_t M17_DATA_SYNC_BYTES[] = {0xDDU, 0xDDU};
const uint8_t M17_SYNC_BYTES_LENGTH = 2U; const uint8_t M17_SYNC_BYTES_LENGTH = 2U;
const uint16_t M17_SYNC_BITS = 0x3243U; const uint16_t M17_HEADER_SYNC_BITS = 0x5DDDU;
const uint16_t M17_DATA_SYNC_BITS = 0xDDDDU;
#endif #endif

View file

@ -52,10 +52,17 @@ void CM17RX::reset()
void CM17RX::databit(bool bit) void CM17RX::databit(bool bit)
{ {
if (m_state == M17RXS_NONE) switch (m_state) {
case M17RXS_NONE:
processNone(bit); processNone(bit);
else break;
case M17RXS_HEADER:
processHeader(bit);
break;
default:
processData(bit); processData(bit);
break;
}
} }
void CM17RX::processNone(bool bit) void CM17RX::processNone(bool bit)
@ -64,11 +71,24 @@ void CM17RX::processNone(bool bit)
if (bit) if (bit)
m_bitBuffer |= 0x01U; m_bitBuffer |= 0x01U;
// Fuzzy matching of the data sync bit sequence // Fuzzy matching of the header sync bit sequence
if (countBits16(m_bitBuffer ^ M17_SYNC_BITS) <= MAX_SYNC_BIT_START_ERRS) { if (countBits16(m_bitBuffer ^ M17_HEADER_SYNC_BITS) <= MAX_SYNC_BIT_START_ERRS) {
DEBUG1("M17RX: sync found in None"); DEBUG1("M17RX: header sync found in None");
for (uint8_t i = 0U; i < M17_SYNC_BYTES_LENGTH; i++) for (uint8_t i = 0U; i < M17_SYNC_BYTES_LENGTH; i++)
m_buffer[i] = M17_SYNC_BYTES[i]; m_buffer[i] = M17_HEADER_SYNC_BYTES[i];
m_lostCount = MAX_SYNC_FRAMES;
m_bufferPtr = M17_SYNC_LENGTH_BITS;
m_state = M17RXS_HEADER;
io.setDecode(true);
}
// Fuzzy matching of the data sync bit sequence
if (countBits16(m_bitBuffer ^ M17_DATA_SYNC_BITS) <= MAX_SYNC_BIT_START_ERRS) {
DEBUG1("M17RX: data sync found in None");
for (uint8_t i = 0U; i < M17_SYNC_BYTES_LENGTH; i++)
m_buffer[i] = M17_DATA_SYNC_BYTES[i];
m_lostCount = MAX_SYNC_FRAMES; m_lostCount = MAX_SYNC_FRAMES;
m_bufferPtr = M17_SYNC_LENGTH_BITS; m_bufferPtr = M17_SYNC_LENGTH_BITS;
@ -76,7 +96,43 @@ void CM17RX::processNone(bool bit)
io.setDecode(true); io.setDecode(true);
} }
}
void CM17RX::processHeader(bool bit)
{
m_bitBuffer <<= 1;
if (bit)
m_bitBuffer |= 0x01U;
WRITE_BIT1(m_buffer, m_bufferPtr, bit);
m_bufferPtr++;
if (m_bufferPtr > M17_FRAME_LENGTH_BITS)
reset();
// Only search for a 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 data sync bit sequence
if (countBits16(m_bitBuffer ^ M17_HEADER_SYNC_BITS) <= MAX_SYNC_BIT_RUN_ERRS) {
DEBUG2("M17RX: found header sync in Data, pos", m_bufferPtr - M17_SYNC_LENGTH_BITS);
m_lostCount = MAX_SYNC_FRAMES;
m_bufferPtr = M17_SYNC_LENGTH_BITS;
}
}
// Send a data frame to the host if the required number of bits have been received
if (m_bufferPtr == M17_FRAME_LENGTH_BITS) {
m_lostCount--;
// Write data to host
m_outBuffer[0U] = 0x01U;
writeRSSIHeader(m_outBuffer);
// Start the next frame
::memset(m_outBuffer, 0x00U, M17_FRAME_LENGTH_BYTES + 3U);
m_state = M17RXS_DATA;
m_bufferPtr = 0U;
}
} }
void CM17RX::processData(bool bit) void CM17RX::processData(bool bit)
@ -94,8 +150,8 @@ void CM17RX::processData(bool bit)
// Only search for a sync in the right place +-2 symbols // Only search for a sync in the right place +-2 symbols
if (m_bufferPtr >= (M17_SYNC_LENGTH_BITS - 2U) && m_bufferPtr <= (M17_SYNC_LENGTH_BITS + 2U)) { if (m_bufferPtr >= (M17_SYNC_LENGTH_BITS - 2U) && m_bufferPtr <= (M17_SYNC_LENGTH_BITS + 2U)) {
// Fuzzy matching of the data sync bit sequence // Fuzzy matching of the data sync bit sequence
if (countBits16(m_bitBuffer ^ M17_SYNC_BITS) <= MAX_SYNC_BIT_RUN_ERRS) { if (countBits16(m_bitBuffer ^ M17_DATA_SYNC_BITS) <= MAX_SYNC_BIT_RUN_ERRS) {
DEBUG2("M17RX: found sync in Data, pos", m_bufferPtr - M17_SYNC_LENGTH_BITS); DEBUG2("M17RX: found data sync in Data, pos", m_bufferPtr - M17_SYNC_LENGTH_BITS);
m_lostCount = MAX_SYNC_FRAMES; m_lostCount = MAX_SYNC_FRAMES;
m_bufferPtr = M17_SYNC_LENGTH_BITS; m_bufferPtr = M17_SYNC_LENGTH_BITS;
} }
@ -122,6 +178,20 @@ void CM17RX::processData(bool bit)
} }
} }
void CM17RX::writeRSSIHeader(uint8_t* data)
{
#if defined(SEND_RSSI_DATA)
uint16_t rssi = io.readRSSI();
data[49U] = (rssi >> 8) & 0xFFU;
data[50U] = (rssi >> 0) & 0xFFU;
serial.writeM17Header(data, M17_FRAME_LENGTH_BYTES + 3U);
#else
serial.writeM17Header(data, M17_FRAME_LENGTH_BYTES + 1U);
#endif
}
void CM17RX::writeRSSIData(uint8_t* data) void CM17RX::writeRSSIData(uint8_t* data)
{ {
#if defined(SEND_RSSI_DATA) #if defined(SEND_RSSI_DATA)

View file

@ -24,6 +24,7 @@
enum M17RX_STATE { enum M17RX_STATE {
M17RXS_NONE, M17RXS_NONE,
M17RXS_HEADER,
M17RXS_DATA M17RXS_DATA
}; };
@ -44,7 +45,9 @@ private:
uint16_t m_lostCount; uint16_t m_lostCount;
void processNone(bool bit); void processNone(bool bit);
void processHeader(bool bit);
void processData(bool bit); void processData(bool bit);
void writeRSSIHeader(uint8_t* data);
void writeRSSIData(uint8_t* data); void writeRSSIData(uint8_t* data);
}; };

View file

@ -60,8 +60,9 @@ const uint8_t MMDVM_P25_LOST = 0x32U;
const uint8_t MMDVM_NXDN_DATA = 0x40U; const uint8_t MMDVM_NXDN_DATA = 0x40U;
const uint8_t MMDVM_NXDN_LOST = 0x41U; const uint8_t MMDVM_NXDN_LOST = 0x41U;
const uint8_t MMDVM_M17_DATA = 0x45U; const uint8_t MMDVM_M17_HEADER = 0x45U;
const uint8_t MMDVM_M17_LOST = 0x46U; const uint8_t MMDVM_M17_DATA = 0x46U;
const uint8_t MMDVM_M17_LOST = 0x47U;
const uint8_t MMDVM_POCSAG_DATA = 0x50U; const uint8_t MMDVM_POCSAG_DATA = 0x50U;
@ -864,6 +865,20 @@ void CSerialPort::process()
} }
break; break;
case MMDVM_M17_HEADER:
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 header", err);
sendNAK(err);
}
break;
case MMDVM_M17_DATA: case MMDVM_M17_DATA:
if (m_m17Enable) { if (m_m17Enable) {
if (m_modemState == STATE_IDLE || m_modemState == STATE_M17) if (m_modemState == STATE_IDLE || m_modemState == STATE_M17)
@ -1233,6 +1248,29 @@ void CSerialPort::writeNXDNLost()
writeInt(1U, reply, 3); writeInt(1U, reply, 3);
} }
void CSerialPort::writeM17Header(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_HEADER;
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::writeM17Data(const uint8_t* data, uint8_t length) void CSerialPort::writeM17Data(const uint8_t* data, uint8_t length)
{ {
if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE) if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE)

View file

@ -52,6 +52,7 @@ public:
void writeNXDNData(const uint8_t* data, uint8_t length); void writeNXDNData(const uint8_t* data, uint8_t length);
void writeNXDNLost(); void writeNXDNLost();
void writeM17Header(const uint8_t* data, uint8_t length);
void writeM17Data(const uint8_t* data, uint8_t length); void writeM17Data(const uint8_t* data, uint8_t length);
void writeM17Lost(); void writeM17Lost();

View file

@ -25,7 +25,7 @@
#define VER_MAJOR "1" #define VER_MAJOR "1"
#define VER_MINOR "5" #define VER_MINOR "5"
#define VER_REV "2" #define VER_REV "2"
#define VERSION_DATE "20201111" #define VERSION_DATE "20201126"
#if defined(ZUMSPOT_ADF7021) #if defined(ZUMSPOT_ADF7021)
#define BOARD_INFO "ZUMspot" #define BOARD_INFO "ZUMspot"