Skip to content

Commit

Permalink
Convert to the new EOF marker.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Aug 25, 2021
1 parent 37c889c commit b779ea5
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 64 deletions.
98 changes: 47 additions & 51 deletions M17Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,35 +325,12 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
return true;
}

if ((m_rfState == RS_RF_AUDIO || m_rfState == RS_RF_DATA_AUDIO) && data[0U] == TAG_HEADER) {
if ((m_rfState == RS_RF_AUDIO || m_rfState == RS_RF_DATA_AUDIO) && data[0U] == TAG_EOT) {
#if defined(DUMP_M17)
writeFile(data + 2U);
#endif
if (m_duplex) {
unsigned char rfData[M17_FRAME_LENGTH_BYTES + 2U];

// Create a Link Setup frame
rfData[0U] = TAG_HEADER;
rfData[1U] = 0x00U;

// Generate the sync
CSync::addM17LinkSetupSync(rfData + 2U);

m_rfLSF.setDataType(M17_DATA_TYPE_END);

unsigned char setup[M17_LSF_LENGTH_BYTES];
m_rfLSF.getLinkSetup(setup);

// Add the convolution FEC
CM17Convolution conv;
conv.encodeLinkSetup(setup, rfData + 2U + M17_SYNC_LENGTH_BYTES);

unsigned char temp[M17_FRAME_LENGTH_BYTES];
interleaver(rfData + 2U, temp);
decorrelator(temp, rfData + 2U);

writeQueueRF(rfData);
}
if (m_duplex)
writeQueueEOTRF();

if (m_network != NULL && m_rfTimeoutTimer.isRunning() && !m_rfTimeoutTimer.hasExpired()) {
unsigned char netData[M17_LSF_LENGTH_BYTES + M17_FN_LENGTH_BYTES + M17_PAYLOAD_LENGTH_BYTES + M17_CRC_LENGTH_BYTES];
Expand Down Expand Up @@ -583,29 +560,7 @@ void CM17Control::writeNetwork()

LogMessage("M17, received network end of transmission from %s to %s, %.1f seconds", source.c_str(), dest.c_str(), float(m_netFrames) / 25.0F);

unsigned char rfData[M17_FRAME_LENGTH_BYTES + 2U];

// Create a Link Setup frame
rfData[0U] = TAG_HEADER;
rfData[1U] = 0x00U;

// Generate the sync
CSync::addM17LinkSetupSync(rfData + 2U);

m_netLSF.setDataType(M17_DATA_TYPE_END);

unsigned char setup[M17_LSF_LENGTH_BYTES];
m_netLSF.getLinkSetup(setup);

// Add the convolution FEC
CM17Convolution conv;
conv.encodeLinkSetup(setup, rfData + 2U + M17_SYNC_LENGTH_BYTES);

unsigned char temp[M17_FRAME_LENGTH_BYTES];
interleaver(rfData + 2U, temp);
decorrelator(temp, rfData + 2U);

writeQueueNet(rfData);
writeQueueEOTNet();

writeEndNet();
}
Expand Down Expand Up @@ -718,7 +673,7 @@ void CM17Control::writeQueueRF(const unsigned char *data)
if (m_rfTimeoutTimer.isRunning() && m_rfTimeoutTimer.hasExpired())
return;

unsigned char len = M17_FRAME_LENGTH_BYTES + 2U;
const unsigned char len = M17_FRAME_LENGTH_BYTES + 2U;

unsigned int space = m_queue.freeSpace();
if (space < (len + 1U)) {
Expand All @@ -731,14 +686,36 @@ void CM17Control::writeQueueRF(const unsigned char *data)
m_queue.addData(data, len);
}

void CM17Control::writeQueueEOTRF()
{
if (m_netState != RS_NET_IDLE)
return;

if (m_rfTimeoutTimer.isRunning() && m_rfTimeoutTimer.hasExpired())
return;

const unsigned char len = 1U;

unsigned int space = m_queue.freeSpace();
if (space < (len + 1U)) {
LogError("M17, overflow in the M17 RF queue");
return;
}

m_queue.addData(&len, 1U);

const unsigned char data = TAG_EOT;
m_queue.addData(&data, len);
}

void CM17Control::writeQueueNet(const unsigned char *data)
{
assert(data != NULL);

if (m_netTimeoutTimer.isRunning() && m_netTimeoutTimer.hasExpired())
return;

unsigned char len = M17_FRAME_LENGTH_BYTES + 2U;
const unsigned char len = M17_FRAME_LENGTH_BYTES + 2U;

unsigned int space = m_queue.freeSpace();
if (space < (len + 1U)) {
Expand All @@ -751,6 +728,25 @@ void CM17Control::writeQueueNet(const unsigned char *data)
m_queue.addData(data, len);
}

void CM17Control::writeQueueEOTNet()
{
if (m_netTimeoutTimer.isRunning() && m_netTimeoutTimer.hasExpired())
return;

const unsigned char len = 1U;

unsigned int space = m_queue.freeSpace();
if (space < (len + 1U)) {
LogError("M17, overflow in the M17 RF queue");
return;
}

m_queue.addData(&len, 1U);

const unsigned char data = TAG_EOT;
m_queue.addData(&data, len);
}

void CM17Control::interleaver(const unsigned char* in, unsigned char* out) const
{
assert(in != NULL);
Expand Down
4 changes: 4 additions & 0 deletions M17Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class CM17Control {
bool processRFHeader(bool lateEntry);

void writeQueueRF(const unsigned char* data);
void writeQueueEOTRF();

void writeQueueNet(const unsigned char* data);
void writeQueueEOTNet();

void writeNetwork();

void interleaver(const unsigned char* in, unsigned char* out) const;
Expand Down
1 change: 0 additions & 1 deletion M17Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const unsigned char M17_1600_SILENCE[] = {0x0CU, 0x41U, 0x09U, 0x03U, 0x0CU, 0x4
const unsigned char M17_PACKET_TYPE = 0U;
const unsigned char M17_STREAM_TYPE = 1U;

const unsigned char M17_DATA_TYPE_END = 0x00U;
const unsigned char M17_DATA_TYPE_DATA = 0x01U;
const unsigned char M17_DATA_TYPE_VOICE = 0x02U;
const unsigned char M17_DATA_TYPE_VOICE_DATA = 0x03U;
Expand Down
41 changes: 30 additions & 11 deletions Modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const unsigned char MMDVM_M17_LINK_SETUP = 0x45U;
const unsigned char MMDVM_M17_STREAM = 0x46U;
const unsigned char MMDVM_M17_PACKET = 0x47U;
const unsigned char MMDVM_M17_LOST = 0x48U;
const unsigned char MMDVM_M17_EOT = 0x49U;

const unsigned char MMDVM_POCSAG_DATA = 0x50U;

Expand Down Expand Up @@ -690,6 +691,18 @@ void CModem::clock(unsigned int ms)
}
break;

case MMDVM_M17_EOT: {
if (m_trace)
CUtils::dump(1U, "RX M17 EOT", m_buffer, m_length);

unsigned char data = 1U;
m_rxM17Data.addData(&data, 1U);

data = TAG_EOT;
m_rxM17Data.addData(&data, 1U);
}
break;

case MMDVM_M17_LOST: {
if (m_trace)
CUtils::dump(1U, "RX M17 Lost", m_buffer, m_length);
Expand Down Expand Up @@ -1041,8 +1054,8 @@ void CModem::clock(unsigned int ms)
case MMDVM_M17_STREAM:
CUtils::dump(1U, "TX M17 Stream Data", m_buffer, len);
break;
case MMDVM_M17_PACKET:
CUtils::dump(1U, "TX M17 Packet Data", m_buffer, len);
case MMDVM_M17_EOT:
CUtils::dump(1U, "TX M17 EOT", m_buffer, len);
break;
}
}
Expand Down Expand Up @@ -1504,20 +1517,26 @@ bool CModem::writeM17Data(const unsigned char* data, unsigned int length)
assert(data != NULL);
assert(length > 0U);

if (data[0U] != TAG_HEADER && data[0U] != TAG_DATA && data[0U] != TAG_EOT)
return false;

unsigned char buffer[130U];

buffer[0U] = MMDVM_FRAME_START;
buffer[1U] = length + 2U;

if (data[0U] == TAG_HEADER)
buffer[2U] = MMDVM_M17_LINK_SETUP;
else
buffer[2U] = MMDVM_M17_STREAM;

::memcpy(buffer + 3U, data + 1U, length - 1U);
switch (data[0U]) {
case TAG_HEADER:
buffer[2U] = MMDVM_M17_LINK_SETUP;
::memcpy(buffer + 3U, data + 1U, length - 1U);
break;
case TAG_DATA:
buffer[2U] = MMDVM_M17_STREAM;
::memcpy(buffer + 3U, data + 1U, length - 1U);
break;
case TAG_EOT:
buffer[2U] = MMDVM_M17_EOT;
break;
default:
return false;
}

unsigned char len = length + 2U;
m_txM17Data.addData(&len, 1U);
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 = "20210823";
const char* VERSION = "20210825";

#endif

0 comments on commit b779ea5

Please sign in to comment.