Skip to content

Commit 2ffd831

Browse files
committed
Fix the P25 PDU transmit length.
1 parent 082c2e1 commit 2ffd831

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

P25Control.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len)
414414
m_rfDataFrames = header[6U] & 0x7FU;
415415

416416
m_display->writeP25("DATA", false, llId, "R");
417+
m_display->writeP25RSSI(m_rssi);
418+
417419
LogMessage("P25, received RF data transmission to %u, %u blocks", llId, m_rfDataFrames);
418420
} else {
419421
m_rfPDUCount = 0U;
@@ -457,7 +459,10 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len)
457459
unsigned char pdu[1024U];
458460

459461
// Add the data
460-
CP25Utils::encode(m_rfPDU, pdu + 2U, 0U, bitLength);
462+
unsigned int newBitLength = CP25Utils::encode(m_rfPDU, pdu + 2U, bitLength);
463+
unsigned int newByteLength = newBitLength / 8U;
464+
if ((newBitLength % 8U) > 0U)
465+
newByteLength++;
461466

462467
// Regenerate Sync
463468
CSync::addP25Sync(pdu + 2U);
@@ -466,16 +471,12 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len)
466471
m_nid.encode(pdu + 2U, P25_DUID_PDU);
467472

468473
// Add busy bits
469-
addBusyBits(pdu + 2U, bitLength, false, true);
474+
addBusyBits(pdu + 2U, newBitLength, false, true);
470475

471476
if (m_duplex) {
472-
unsigned int byteLength = bitLength / 8U;
473-
if ((bitLength % 8U) > 0U)
474-
byteLength++;
475-
476477
pdu[0U] = TAG_DATA;
477478
pdu[1U] = 0x00U;
478-
writeQueueRF(pdu, byteLength + 2U);
479+
writeQueueRF(pdu, newByteLength + 2U);
479480
}
480481

481482
LogMessage("P25, ended RF data transmission");

P25Utils.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,33 @@ unsigned int CP25Utils::encode(const unsigned char* in, unsigned char* out, unsi
8787
return n;
8888
}
8989

90+
unsigned int CP25Utils::encode(const unsigned char* in, unsigned char* out, unsigned int length)
91+
{
92+
assert(in != NULL);
93+
assert(out != NULL);
94+
95+
// Move the SSx positions to the range needed
96+
unsigned int ss0Pos = P25_SS0_START;
97+
unsigned int ss1Pos = P25_SS1_START;
98+
99+
unsigned int n = 0U;
100+
unsigned int pos = 0U;
101+
while (n < length) {
102+
if (pos == ss0Pos) {
103+
ss0Pos += P25_SS_INCREMENT;
104+
} else if (pos == ss1Pos) {
105+
ss1Pos += P25_SS_INCREMENT;
106+
} else {
107+
bool b = READ_BIT(in, n);
108+
WRITE_BIT(out, pos, b);
109+
n++;
110+
}
111+
pos++;
112+
}
113+
114+
return pos;
115+
}
116+
90117
unsigned int CP25Utils::compare(const unsigned char* data1, const unsigned char* data2, unsigned int length)
91118
{
92119
assert(data1 != NULL);

P25Utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
class CP25Utils {
2323
public:
2424
static unsigned int encode(const unsigned char* in, unsigned char* out, unsigned int start, unsigned int stop);
25+
static unsigned int encode(const unsigned char* in, unsigned char* out, unsigned int length);
2526

2627
static unsigned int decode(const unsigned char* in, unsigned char* out, unsigned int start, unsigned int stop);
2728

0 commit comments

Comments
 (0)