From aad7b2cba6b02a505b505ce6eba888769551e07c Mon Sep 17 00:00:00 2001 From: ric355 <41516664+ric355@users.noreply.github.com> Date: Tue, 11 Feb 2020 22:26:04 +0000 Subject: [PATCH] Secondary serial requests are sometimes ignored (#321) * Fix to secondary serial requests to ensure the whole request is received before we attempt to process it. This avoids the situation where serial requests would sometimes be ignored when they are a multi-byte requests (e.g. the 'r' command). * Minor formatting change. --- speeduino/cancomms.h | 1 + speeduino/cancomms.ino | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/speeduino/cancomms.h b/speeduino/cancomms.h index d1f72281..7e83dd7f 100644 --- a/speeduino/cancomms.h +++ b/speeduino/cancomms.h @@ -20,6 +20,7 @@ uint8_t canlisten = 0; uint8_t Lbuffer[8]; //8 byte buffer to store incomng can data uint8_t Gdata[9]; uint8_t Glow, Ghigh; +bool canCmdPending = false; #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) HardwareSerial &CANSerial = Serial3; diff --git a/speeduino/cancomms.ino b/speeduino/cancomms.ino index e3fe5e50..d2afb10c 100644 --- a/speeduino/cancomms.ino +++ b/speeduino/cancomms.ino @@ -18,7 +18,7 @@ sendcancommand is called when a command is to be sent via serial3 to the Can int void canCommand() { - currentcanCommand = CANSerial.read(); + if (! canCmdPending) { currentcanCommand = CANSerial.read(); } switch (currentcanCommand) { @@ -30,6 +30,7 @@ void canCommand() byte destcaninchannel; if (CANSerial.available() >= 9) { + canCmdPending = false; cancmdfail = CANSerial.read(); //0 == fail, 1 == good. destcaninchannel = CANSerial.read(); // the input channel that requested the data value if (cancmdfail != 0) @@ -58,6 +59,11 @@ void canCommand() else{} //continue as command request failed and/or data/device was not available } + else + { + canCmdPending = true; + } + break; case 'k': //placeholder for new can interface (toucan etc) commands @@ -106,6 +112,7 @@ void canCommand() tmp = CANSerial.read(); length = word(CANSerial.read(), tmp); sendcanValues(offset, length,Cmd, 1); + canCmdPending = false; //Serial.print(Cmd); } else @@ -113,6 +120,11 @@ void canCommand() //No other r/ commands should be called } } + else + { + canCmdPending = true; + } + break; case 's': // send the "a" stream code version