@@ -291,23 +291,24 @@ static RS485_Response_e WaitForResponse(int32_t timeoutMs, uint8_t fromAddr, Mcu
291291 CMD_ParserState_e state = CMD_PARSER_INIT ;
292292
293293 for (;;) { /* returns */
294- /* read response text and write into buffer or to console */
295- static unsigned char lineBuffer [512 ]; /* enough for a line of text coming back from the bus */
296-
297- lineBuffer [0 ] = '\0' ; /* initialize buffer */
298- do {
299- rsIO -> stdIn (& ch );
300- if (ch != '\0' ) {
301- McuUtility_chcat (lineBuffer , sizeof (lineBuffer ), ch );
302- if (ch == '\n' ) {
303- if (lineBuffer [0 ]!= '@' ) { /* do not send things like OK or NOK messages from bus */
304- SHELL_SendStringToIO (lineBuffer , shellIO );
294+ if (rsIO != NULL && shellIO != NULL ) { /* only do it if we have valid handles */
295+ /* read response text and write into buffer or to console */
296+ static unsigned char lineBuffer [512 ]; /* enough for a line of text coming back from the bus */
297+
298+ lineBuffer [0 ] = '\0' ; /* initialize buffer */
299+ do {
300+ rsIO -> stdIn (& ch );
301+ if (ch != '\0' ) {
302+ McuUtility_chcat (lineBuffer , sizeof (lineBuffer ), ch );
303+ if (ch == '\n' ) {
304+ if (lineBuffer [0 ]!= '@' ) { /* do not send things like OK or NOK messages from bus */
305+ SHELL_SendStringToIO (lineBuffer , shellIO );
306+ }
307+ lineBuffer [0 ] = '\0' ; /* reset buffer */
305308 }
306- lineBuffer [0 ] = '\0' ; /* reset buffer */
307309 }
308- }
309- } while (ch != '\0' );
310-
310+ } while (ch != '\0' );
311+ }
311312 ch = McuUart485_GetResponseQueueChar ();
312313 if (ch != '\0' ) {
313314 resp = Scan (& state , ch , buf , sizeof (buf ), fromAddr );
@@ -513,6 +514,7 @@ static uint8_t CheckHeader(unsigned char *msg, const unsigned char **startCmd, u
513514 }
514515 expected_crc = CalcMsgCrc (msg );
515516 if (crc != expected_crc ) {
517+ McuLog_error ("CRC error, msg `%s`, expected 0x%x" , msg , expected_crc );
516518 if (dstAddr != RS485_BROADCAST_ADDRESS ) { /* only send back error if it was not a broadcast */
517519 McuUtility_strcpy (buf , sizeof (buf ), (uint8_t * )"CRC_ERR 0x" );
518520 McuUtility_strcatNum8Hex (buf , sizeof (buf ), RS485_GetAddress ());
0 commit comments