From ccab50a7df42dcd9b937c17cdd8cf602a9d22dea Mon Sep 17 00:00:00 2001 From: torque Date: Tue, 22 Aug 2023 17:23:19 -0700 Subject: [PATCH] spid: account for another type of debug message When the settings are saved via the front panel on the MD-01, the following debug messages are printed on COM 0: thread_motionController: settings changed!\r\n thread_protocols: settings changed!\r\n Notably, because these aren't timestamped the way the other debug messages are, they were missing the our debug message sieve and causing protocol errors. Address this by treating anything that doesn't start with the ROT2PROG start byte ('W') as a log frame. --- rotators/spid/spid.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/rotators/spid/spid.c b/rotators/spid/spid.c index fe46b5af1..7c4100bd7 100644 --- a/rotators/spid/spid.c +++ b/rotators/spid/spid.c @@ -94,12 +94,16 @@ static int read_r2p_frame(hamlib_port_t *port, unsigned char *rxbuffer, // strict numerical bounds that could be used to sanity check the contents // of the reply frame). - int res = 0; unsigned char peek = 0; enum r2p_frame_parser_state pstate = ROT2PROG_PARSER_EXPECT_FRAME_START; - while (1) { + // This will loop infinitely in the case of a badly-behaved serial device + // that is producing log-like frames faster than we can consume them. + // However, this is not expected to be a practical possibility, and there's + // no concrete loop bounds we can use. + while (1) + { switch (pstate) { case ROT2PROG_PARSER_EXPECT_FRAME_START: @@ -108,27 +112,14 @@ static int read_r2p_frame(hamlib_port_t *port, unsigned char *rxbuffer, switch (peek) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': { - pstate = ROT2PROG_PARSER_EXPECT_CR; - break; - } - - case ROT2PROG_FRAME_START_BYTE: { + case ROT2PROG_FRAME_START_BYTE: rxbuffer[0] = peek; pstate = ROT2PROG_PARSER_EXPECT_FRAME_END; break; - } - default: return -RIG_EPROTO; + default: + pstate = ROT2PROG_PARSER_EXPECT_CR; + break; } break; @@ -168,10 +159,11 @@ static int read_r2p_frame(hamlib_port_t *port, unsigned char *rxbuffer, return -RIG_EPROTO; } - // lie about the number of bytes read + // account for the already-read start byte here return res + 1; - default: return -RIG_EINTERNAL; + default: + return -RIG_EINTERNAL; } } }