From babba5bca9c0e840f7eb75b8afb823f13046bfd6 Mon Sep 17 00:00:00 2001 From: ole00 Date: Sat, 20 Apr 2024 16:01:18 +0100 Subject: [PATCH] PC app: jtag: better handling of new line characters Previously the new line characters were expected to be part of the feed request message. This is not so on ESP32 based Arduino library implementation. The new line characters arrive later on separately after a small pause This code change fixes 'corrupted feed request' warning messages on such Arduino platforms. --- src_pc/afterburner.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src_pc/afterburner.c b/src_pc/afterburner.c index e1a2228..f5e4b56 100644 --- a/src_pc/afterburner.c +++ b/src_pc/afterburner.c @@ -1253,13 +1253,23 @@ static int readJtagSerialLine(char* buf, int bufSize, int maxDelay, int* feedReq bufPos -= readSize; buf[0] = 0; //extra 5 bytes should be present: 3 bytes of size, 2 new line chars - readSize = serialDeviceRead(serialF, tmp, 5); - if (readSize == 5) { + readSize = serialDeviceRead(serialF, tmp, 3); + if (readSize == 3) { + int retry = 1000; tmp[3] = 0; *feedRequest = atoi(tmp); maxDelay = 0; //force exit + + //read the extra 2 characters (new line chars) + while (retry && readSize != 2) { + readSize = serialDeviceRead(serialF, tmp, 2); + retry--; + } + if (readSize != 2 || tmp[0] != '\r' || tmp[1] != '\n') { + printf("Warning: corrupted feed request ! %d \n", readSize); + } } else { - printf("Warning: corrupted feed request!\n"); + printf("Warning: corrupted feed request! %d \n", readSize); } //printf("***\n"); } else