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