Skip to content

Commit f8358ed

Browse files
committed
handle serial buffer overflow condition (while the modem protocol *can* send frames >512 bytes the serial port handler can only handle frames up to 512 bytes); better handle transmitting double length (512 byte) P25 PDU frames;
1 parent ca0882a commit f8358ed

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

SerialPort.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,20 @@ void SerialPort::process()
7878
if (m_dblFrame) {
7979
m_buffer[m_ptr] = c;
8080
m_len = ((c & 0xFFU) << 8);
81+
// DEBUG3("long frame, len msb", m_len, c);
8182
} else {
8283
m_len = m_buffer[m_ptr] = c;
84+
// DEBUG2("short frame, len", m_len);
8385
}
8486
m_ptr = 2U;
8587
}
8688
else if (m_ptr == 2U && m_dblFrame) {
8789
// Handle the frame length
8890
m_buffer[m_ptr] = c;
8991
m_len = (m_len + (c & 0xFFU));
92+
if (m_len > SERIAL_FB_LEN)
93+
m_len = SERIAL_FB_LEN; // don't allow length to be longer then the buffer
94+
// DEBUG3("long frame, len lsb", m_len, c);
9095
m_ptr = 3U;
9196
}
9297
else {
@@ -318,8 +323,12 @@ void SerialPort::process()
318323
/** Project 25 */
319324
case CMD_P25_DATA:
320325
if (m_p25Enable) {
321-
if (m_modemState == STATE_IDLE || m_modemState == STATE_P25)
322-
err = p25TX.writeData(m_buffer + 3U, m_len - 3U);
326+
if (m_modemState == STATE_IDLE || m_modemState == STATE_P25) {
327+
if (m_dblFrame)
328+
err = p25TX.writeData(m_buffer + 4U, m_len - 4U);
329+
else
330+
err = p25TX.writeData(m_buffer + 3U, m_len - 3U);
331+
}
323332
}
324333
if (err == RSN_OK) {
325334
if (m_modemState == STATE_IDLE)

SerialPort.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ enum CMD_REASON_CODE {
152152
const uint8_t DVM_SHORT_FRAME_START = 0xFEU;
153153
const uint8_t DVM_LONG_FRAME_START = 0xFDU;
154154

155+
#define SERIAL_FB_LEN 518U
155156
#define SERIAL_SPEED 115200
156157
/** @} */
157158

@@ -284,9 +285,9 @@ class DSP_FW_API SerialPort {
284285
void writeDump(const uint8_t* data, uint16_t length);
285286

286287
private:
287-
uint8_t m_buffer[518U];
288-
uint8_t m_ptr;
289-
uint8_t m_len;
288+
uint8_t m_buffer[SERIAL_FB_LEN];
289+
uint16_t m_ptr;
290+
uint16_t m_len;
290291
bool m_dblFrame;
291292

292293
bool m_debug;

p25/P25TX.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void P25TX::process()
151151

152152
/* Write data to the local buffer. */
153153

154-
uint8_t P25TX::writeData(const uint8_t* data, uint8_t length)
154+
uint8_t P25TX::writeData(const uint8_t* data, uint16_t length)
155155
{
156156
if (length < (P25_TDU_FRAME_LENGTH_BYTES + 1U))
157157
return RSN_ILLEGAL_LENGTH;
@@ -164,7 +164,7 @@ uint8_t P25TX::writeData(const uint8_t* data, uint8_t length)
164164
}
165165

166166
m_fifo.put(length - 1U);
167-
for (uint8_t i = 0U; i < (length - 1U); i++)
167+
for (uint16_t i = 0U; i < (length - 1U); i++)
168168
m_fifo.put(data[i + 1U]);
169169

170170
return RSN_OK;
@@ -257,9 +257,9 @@ void P25TX::createData()
257257
m_poBuffer[m_poLen++] = P25_START_SYNC;
258258
}
259259
else {
260-
uint8_t length = m_fifo.get();
260+
uint16_t length = m_fifo.get();
261261
DEBUG3("P25TX::createData() dataLength/fifoSpace", length, m_fifo.getSpace());
262-
for (uint8_t i = 0U; i < length; i++) {
262+
for (uint16_t i = 0U; i < length; i++) {
263263
m_poBuffer[m_poLen++] = m_fifo.get();
264264
}
265265
}
@@ -273,7 +273,7 @@ void P25TX::createCal()
273273
{
274274
// 1.2 kHz sine wave generation
275275
if (m_modemState == STATE_P25_CAL) {
276-
for (unsigned int i = 0U; i < P25_LDU_FRAME_LENGTH_BYTES; i++) {
276+
for (uint8_t i = 0U; i < P25_LDU_FRAME_LENGTH_BYTES; i++) {
277277
m_poBuffer[i] = P25_START_SYNC;
278278
}
279279

p25/P25TX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace p25
6464
* @param length Length of buffer.
6565
* @returns uint8_t Reason code.
6666
*/
67-
uint8_t writeData(const uint8_t* data, uint8_t length);
67+
uint8_t writeData(const uint8_t* data, uint16_t length);
6868

6969
/**
7070
* @brief Clears the local buffer.

0 commit comments

Comments
 (0)