@@ -23,9 +23,10 @@ static void appendRxByte(uart_parser_t *uartState, uint8_t byte) {
2323 uartState -> rxCrcBuffer [uartState -> rxPosition ++ ] = byte ;
2424 } else if (uartState -> rxPosition - CRC_LEN < uartState -> rxLength ) {
2525 uartState -> rxBuffer [uartState -> rxPosition ++ - CRC_LEN ] = byte ;
26- } else {
27- LogU ("Uart error: too long message [%i, %i, ... %i]\n" , uartState -> rxPosition , uartState -> rxBuffer [0 ], uartState -> rxBuffer [1 ], byte );
28- uartState -> receiveMessage (uartState , UartControl_Unexpected , NULL , 0 );
26+ } else if (!uartState -> rxTooLong ) {
27+ uartState -> rxTooLong = true;
28+ LogU ("Uart error: too long message, discarding [len %i: src %i, dst %i, msgId %i, propId %i]\n" ,
29+ uartState -> rxLength , uartState -> rxBuffer [0 ], uartState -> rxBuffer [1 ], uartState -> rxBuffer [3 ], uartState -> rxBuffer [4 ]);
2930 }
3031}
3132
@@ -95,6 +96,11 @@ static void processIncomingByte(uart_parser_t *uartState, uint8_t byte) {
9596
9697 uartState -> receivingMessage = false;
9798
99+ if (uartState -> rxTooLong ) {
100+ uartState -> rxTooLong = false;
101+ break ;
102+ }
103+
98104 uint16_t len = uartState -> rxPosition ;
99105 uint8_t * data = uartState -> rxBuffer ;
100106
@@ -117,6 +123,7 @@ static void processIncomingByte(uart_parser_t *uartState, uint8_t byte) {
117123 }
118124 uartState -> receivingMessage = true;
119125 uartState -> rxPosition = 0 ;
126+ uartState -> rxTooLong = false;
120127 break ;
121128msg_byte :
122129 default :
@@ -209,6 +216,7 @@ void UartParser_InitParser(
209216 uartState -> txPosition = 0 ;
210217 uartState -> receivingMessage = false;
211218 uartState -> escaping = false;
219+ uartState -> rxTooLong = false;
212220 uartState -> receiveMessage = receiveMessage ;
213221 uartState -> userArg = userArg ;
214222}
@@ -219,6 +227,7 @@ void UartParser_SetRxBuffer(uart_parser_t *uartState, uint8_t* buffer, uint16_t
219227 uartState -> rxLength = length ;
220228 uartState -> escaping = false;
221229 uartState -> receivingMessage = false;
230+ uartState -> rxTooLong = false;
222231}
223232
224233void UartParser_SetTxBuffer (uart_parser_t * uartState , uint8_t * buffer , uint16_t length ) {
0 commit comments