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.
This commit is contained in:
parent
1054f1d290
commit
aad7b2cba6
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue