Skip to content

Commit ef6ce0e

Browse files
committed
Include the fragment LICH in the network data.
1 parent e966d35 commit ef6ce0e

File tree

4 files changed

+26
-33
lines changed

4 files changed

+26
-33
lines changed

M17Control.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ m_rfBits(1U),
7979
m_rfLSF(),
8080
m_rfLSFn(0U),
8181
m_netLSF(),
82-
m_netLSFn(0U),
8382
m_rssiMapper(rssiMapper),
8483
m_rssi(0U),
8584
m_maxRSSI(0U),
@@ -309,8 +308,15 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
309308
writeQueueRF(rfData);
310309
}
311310

312-
if (m_network != NULL && m_rfTimeoutTimer.isRunning() && !m_rfTimeoutTimer.hasExpired())
313-
m_network->writeData(m_rfLSF.getSource(), m_rfLSF.getDest(), frame);
311+
if (m_network != NULL && m_rfTimeoutTimer.isRunning() && !m_rfTimeoutTimer.hasExpired()) {
312+
unsigned char lich[M17_LICH_FRAGMENT_LENGTH_BYTES];
313+
m_rfLSF.getFragment(lich, m_rfLSFn);
314+
315+
// Add the fragment number
316+
lich[5U] = (m_rfLSFn & 0x07U) << 5;
317+
318+
m_network->writeData(m_rfLSF.getSource(), m_rfLSF.getDest(), lich, frame);
319+
}
314320

315321
m_rfFrames++;
316322

@@ -404,7 +410,7 @@ void CM17Control::writeNetwork()
404410
m_networkWatchdog.start();
405411

406412
if (netData[0U] == TAG_HEADER) {
407-
m_netLSF.setNetwork(netData + 25U);
413+
m_netLSF.setNetwork(netData + 19U);
408414
m_netLSF.setCAN(m_can);
409415

410416
if (!m_allowEncryption) {
@@ -433,6 +439,7 @@ void CM17Control::writeNetwork()
433439
m_netState = RS_NET_DATA_AUDIO;
434440
break;
435441
default:
442+
LogMessage("M17, received unknown network transmission from %s to %s", source.c_str(), dest.c_str());
436443
m_network->reset();
437444
break;
438445
}
@@ -442,7 +449,6 @@ void CM17Control::writeNetwork()
442449
m_netTimeoutTimer.start();
443450
m_elapsed.start();
444451
m_netFrames = 0U;
445-
m_netLSFn = 0U;
446452

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

479485
m_netFrames++;
480486

481-
// Add the fragment LICH
482-
unsigned char lich[M17_LICH_FRAGMENT_LENGTH_BYTES];
483-
m_netLSF.getFragment(lich, m_netLSFn);
484-
485-
// Add the fragment number
486-
lich[5U] = (m_netLSFn & 0x07U) << 5;
487-
488487
unsigned int frag1, frag2, frag3, frag4;
489-
CM17Utils::splitFragmentLICH(lich, frag1, frag2, frag3, frag4);
488+
CM17Utils::splitFragmentLICH(netData + 19U, frag1, frag2, frag3, frag4);
490489

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

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

499-
// Add the FN and the data/audio
500-
unsigned char payload[M17_FN_LENGTH_BYTES + M17_PAYLOAD_LENGTH_BYTES];
501-
::memcpy(payload, netData + 24U, M17_FN_LENGTH_BYTES + M17_PAYLOAD_LENGTH_BYTES);
502-
503498
// Add the Convolution FEC
504499
CM17Convolution conv;
505-
conv.encodeData(payload, data + 2U + M17_SYNC_LENGTH_BYTES + M17_LICH_FRAGMENT_FEC_LENGTH_BYTES);
500+
conv.encodeData(netData + 25U, data + 2U + M17_SYNC_LENGTH_BYTES + M17_LICH_FRAGMENT_FEC_LENGTH_BYTES);
506501

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

511506
writeQueueNet(data);
512507

513-
m_netLSFn++;
514-
if (m_netLSFn >= 6U)
515-
m_netLSFn = 0U;
516-
517508
// EOT handling
518-
uint16_t fn = (netData[24U] << 8) + (netData[25U] << 0);
509+
uint16_t fn = (netData[25U] << 8) + (netData[26U] << 0);
519510
if ((fn & 0x8000U) == 0x8000U) {
520511
std::string source = m_netLSF.getSource();
521512
std::string dest = m_netLSF.getDest();

M17Control.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class CM17Control {
6969
CM17LSF m_rfLSF;
7070
unsigned int m_rfLSFn;
7171
CM17LSF m_netLSF;
72-
unsigned int m_netLSFn;
7372
CRSSIInterpolator* m_rssiMapper;
7473
unsigned char m_rssi;
7574
unsigned char m_maxRSSI;

M17Network.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ bool CM17Network::open()
7474
}
7575
}
7676

77-
bool CM17Network::writeHeader(const std::string& source, const std::string& dest, const unsigned char* data)
77+
bool CM17Network::writeHeader(const std::string& source, const std::string& dest, const unsigned char* lsf)
7878
{
7979
if (m_addrLen == 0U)
8080
return false;
8181

82-
assert(data != NULL);
82+
assert(lsf != NULL);
8383

8484
unsigned char buffer[60U];
8585

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

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

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

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

114-
bool CM17Network::writeData(const std::string& source, const std::string& dest, const unsigned char* data)
114+
bool CM17Network::writeData(const std::string& source, const std::string& dest,const unsigned char* lsf, const unsigned char* data)
115115
{
116116
if (m_addrLen == 0U)
117117
return false;
118118

119119
assert(data != NULL);
120+
assert(lsf != NULL);
120121

121122
unsigned char buffer[50U];
122123

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

137-
::memcpy(buffer + 24U, data, 18U);
138+
::memcpy(buffer + 24U, lsf, 6U);
139+
140+
::memcpy(buffer + 30U, data, 18U);
138141

139142
if (m_debug)
140-
CUtils::dump(1U, "M17 data transmitted", buffer, 42U);
143+
CUtils::dump(1U, "M17 data transmitted", buffer, 48U);
141144

142-
return m_socket.write(buffer, 42U, m_addr, m_addrLen);
145+
return m_socket.write(buffer, 48U, m_addr, m_addrLen);
143146
}
144147

145148
void CM17Network::clock(unsigned int ms)

M17Network.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class CM17Network {
3636

3737
void enable(bool enabled);
3838

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

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

4343
bool read(unsigned char* data);
4444

0 commit comments

Comments
 (0)