Skip to content

Commit

Permalink
Include the fragment LICH in the network data.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Aug 22, 2021
1 parent e966d35 commit ef6ce0e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
37 changes: 14 additions & 23 deletions M17Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ m_rfBits(1U),
m_rfLSF(),
m_rfLSFn(0U),
m_netLSF(),
m_netLSFn(0U),
m_rssiMapper(rssiMapper),
m_rssi(0U),
m_maxRSSI(0U),
Expand Down Expand Up @@ -309,8 +308,15 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
writeQueueRF(rfData);
}

if (m_network != NULL && m_rfTimeoutTimer.isRunning() && !m_rfTimeoutTimer.hasExpired())
m_network->writeData(m_rfLSF.getSource(), m_rfLSF.getDest(), frame);
if (m_network != NULL && m_rfTimeoutTimer.isRunning() && !m_rfTimeoutTimer.hasExpired()) {
unsigned char lich[M17_LICH_FRAGMENT_LENGTH_BYTES];
m_rfLSF.getFragment(lich, m_rfLSFn);

// Add the fragment number
lich[5U] = (m_rfLSFn & 0x07U) << 5;

m_network->writeData(m_rfLSF.getSource(), m_rfLSF.getDest(), lich, frame);
}

m_rfFrames++;

Expand Down Expand Up @@ -404,7 +410,7 @@ void CM17Control::writeNetwork()
m_networkWatchdog.start();

if (netData[0U] == TAG_HEADER) {
m_netLSF.setNetwork(netData + 25U);
m_netLSF.setNetwork(netData + 19U);
m_netLSF.setCAN(m_can);

if (!m_allowEncryption) {
Expand Down Expand Up @@ -433,6 +439,7 @@ void CM17Control::writeNetwork()
m_netState = RS_NET_DATA_AUDIO;
break;
default:
LogMessage("M17, received unknown network transmission from %s to %s", source.c_str(), dest.c_str());
m_network->reset();
break;
}
Expand All @@ -442,7 +449,6 @@ void CM17Control::writeNetwork()
m_netTimeoutTimer.start();
m_elapsed.start();
m_netFrames = 0U;
m_netLSFn = 0U;

// Create a dummy start message
unsigned char start[M17_FRAME_LENGTH_BYTES + 2U];
Expand Down Expand Up @@ -478,15 +484,8 @@ void CM17Control::writeNetwork()

m_netFrames++;

// Add the fragment LICH
unsigned char lich[M17_LICH_FRAGMENT_LENGTH_BYTES];
m_netLSF.getFragment(lich, m_netLSFn);

// Add the fragment number
lich[5U] = (m_netLSFn & 0x07U) << 5;

unsigned int frag1, frag2, frag3, frag4;
CM17Utils::splitFragmentLICH(lich, frag1, frag2, frag3, frag4);
CM17Utils::splitFragmentLICH(netData + 19U, frag1, frag2, frag3, frag4);

// Add Golay to the LICH fragment here
unsigned int lich1 = CGolay24128::encode24128(frag1);
Expand All @@ -496,26 +495,18 @@ void CM17Control::writeNetwork()

CM17Utils::combineFragmentLICHFEC(lich1, lich2, lich3, lich4, data + 2U + M17_SYNC_LENGTH_BYTES);

// Add the FN and the data/audio
unsigned char payload[M17_FN_LENGTH_BYTES + M17_PAYLOAD_LENGTH_BYTES];
::memcpy(payload, netData + 24U, M17_FN_LENGTH_BYTES + M17_PAYLOAD_LENGTH_BYTES);

// Add the Convolution FEC
CM17Convolution conv;
conv.encodeData(payload, data + 2U + M17_SYNC_LENGTH_BYTES + M17_LICH_FRAGMENT_FEC_LENGTH_BYTES);
conv.encodeData(netData + 25U, data + 2U + M17_SYNC_LENGTH_BYTES + M17_LICH_FRAGMENT_FEC_LENGTH_BYTES);

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

writeQueueNet(data);

m_netLSFn++;
if (m_netLSFn >= 6U)
m_netLSFn = 0U;

// EOT handling
uint16_t fn = (netData[24U] << 8) + (netData[25U] << 0);
uint16_t fn = (netData[25U] << 8) + (netData[26U] << 0);
if ((fn & 0x8000U) == 0x8000U) {
std::string source = m_netLSF.getSource();
std::string dest = m_netLSF.getDest();
Expand Down
1 change: 0 additions & 1 deletion M17Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class CM17Control {
CM17LSF m_rfLSF;
unsigned int m_rfLSFn;
CM17LSF m_netLSF;
unsigned int m_netLSFn;
CRSSIInterpolator* m_rssiMapper;
unsigned char m_rssi;
unsigned char m_maxRSSI;
Expand Down
17 changes: 10 additions & 7 deletions M17Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ bool CM17Network::open()
}
}

bool CM17Network::writeHeader(const std::string& source, const std::string& dest, const unsigned char* data)
bool CM17Network::writeHeader(const std::string& source, const std::string& dest, const unsigned char* lsf)
{
if (m_addrLen == 0U)
return false;

assert(data != NULL);
assert(lsf != NULL);

unsigned char buffer[60U];

Expand All @@ -103,20 +103,21 @@ bool CM17Network::writeHeader(const std::string& source, const std::string& dest
::memset(buffer + 15U, ' ', 9U);
::memcpy(buffer + 15U, dest.c_str(), dest.size());

::memcpy(buffer + 24U, data, 28U);
::memcpy(buffer + 24U, lsf, 28U);

if (m_debug)
CUtils::dump(1U, "M17 header transmitted", buffer, 52U);

return m_socket.write(buffer, 52U, m_addr, m_addrLen);
}

bool CM17Network::writeData(const std::string& source, const std::string& dest, const unsigned char* data)
bool CM17Network::writeData(const std::string& source, const std::string& dest,const unsigned char* lsf, const unsigned char* data)
{
if (m_addrLen == 0U)
return false;

assert(data != NULL);
assert(lsf != NULL);

unsigned char buffer[50U];

Expand All @@ -134,12 +135,14 @@ bool CM17Network::writeData(const std::string& source, const std::string& dest,
::memset(buffer + 15U, ' ', 9U);
::memcpy(buffer + 15U, dest.c_str(), dest.size());

::memcpy(buffer + 24U, data, 18U);
::memcpy(buffer + 24U, lsf, 6U);

::memcpy(buffer + 30U, data, 18U);

if (m_debug)
CUtils::dump(1U, "M17 data transmitted", buffer, 42U);
CUtils::dump(1U, "M17 data transmitted", buffer, 48U);

return m_socket.write(buffer, 42U, m_addr, m_addrLen);
return m_socket.write(buffer, 48U, m_addr, m_addrLen);
}

void CM17Network::clock(unsigned int ms)
Expand Down
4 changes: 2 additions & 2 deletions M17Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class CM17Network {

void enable(bool enabled);

bool writeHeader(const std::string& source, const std::string& dest, const unsigned char* data);
bool writeHeader(const std::string& source, const std::string& dest, const unsigned char* lsf);

bool writeData(const std::string& source, const std::string& dest, const unsigned char* data);
bool writeData(const std::string& source, const std::string& dest, const unsigned char* lsf, const unsigned char* data);

bool read(unsigned char* data);

Expand Down

0 comments on commit ef6ce0e

Please sign in to comment.