Skip to content

Commit

Permalink
Change to the new method of M17 EOT transmission.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Sep 19, 2021
1 parent cb89b34 commit 50a3afd
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 47 deletions.
66 changes: 22 additions & 44 deletions M17Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,18 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
#if defined(DUMP_M17)
writeFile(data + 2U);
#endif
if (m_duplex)
writeQueueEOTRF();
if (m_duplex) {
unsigned char rfData[M17_FRAME_LENGTH_BYTES + 2U];

rfData[0U] = TAG_EOT;
rfData[1U] = 0x00U;

// Generate the sync
for (unsigned int i = 0U; i < M17_FRAME_LENGTH_BYTES; i += M17_SYNC_LENGTH_BYTES)
CSync::addM17EOTSync(rfData + 2U + i);

writeQueueRF(rfData);
}

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 @@ -560,7 +570,16 @@ 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);

writeQueueEOTNet();
unsigned char data[M17_FRAME_LENGTH_BYTES + 2U];

data[0U] = TAG_EOT;
data[1U] = 0x00U;

// Generate the sync
for (unsigned int i = 0U; i < M17_FRAME_LENGTH_BYTES; i += M17_SYNC_LENGTH_BYTES)
CSync::addM17EOTSync(data + 2U + i);

writeQueueNet(data);

writeEndNet();
}
Expand Down Expand Up @@ -686,28 +705,6 @@ 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);
Expand All @@ -728,25 +725,6 @@ 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
2 changes: 0 additions & 2 deletions M17Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ class CM17Control {
bool processRFHeader(bool lateEntry);

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

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

void writeNetwork();

Expand Down
1 change: 1 addition & 0 deletions M17Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const unsigned int M17_FRAME_LENGTH_BYTES = M17_FRAME_LENGTH_BITS / 8U;

const unsigned char M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U};
const unsigned char M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU};
const unsigned char M17_EOT_SYNC_BYTES[] = {0x55U, 0x5DU};

const unsigned int M17_SYNC_LENGTH_BITS = 16U;
const unsigned int M17_SYNC_LENGTH_BYTES = M17_SYNC_LENGTH_BITS / 8U;
Expand Down
1 change: 1 addition & 0 deletions Modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,7 @@ bool CModem::writeM17Data(const unsigned char* data, unsigned int length)
break;
case TAG_EOT:
buffer[2U] = MMDVM_M17_EOT;
::memcpy(buffer + 3U, data + 1U, length - 1U);
break;
default:
return false;
Expand Down
7 changes: 7 additions & 0 deletions Sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,10 @@ void CSync::addM17StreamSync(unsigned char* data)
::memcpy(data, M17_STREAM_SYNC_BYTES, M17_SYNC_LENGTH_BYTES);
}

void CSync::addM17EOTSync(unsigned char* data)
{
assert(data != NULL);

::memcpy(data, M17_EOT_SYNC_BYTES, M17_SYNC_LENGTH_BYTES);
}

1 change: 1 addition & 0 deletions Sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CSync

static void addM17LinkSetupSync(unsigned char* data);
static void addM17StreamSync(unsigned char* data);
static void addM17EOTSync(unsigned char* data);

private:
};
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 = "20210906";
const char* VERSION = "20210919";

#endif

0 comments on commit 50a3afd

Please sign in to comment.