can timeout

This commit is contained in:
Lubos Petrovic
2020-12-21 07:49:00 +01:00
parent 8e30ed99d8
commit cc54de8501
2 changed files with 14 additions and 2 deletions

View File

@@ -77,6 +77,11 @@ void CommObd2Can::mainLoop() {
delay(10);
}
}
if (liveData->params.currentTime + 500 > lastDataSent) {
Serial.print("CAN execution timeout. Continue with next command.");
liveData->canSendNextAtCommand = true;
return;
}
}
/**
@@ -87,6 +92,7 @@ void CommObd2Can::executeCommand(String cmd) {
Serial.print("executeCommand ");
Serial.println(cmd);
if (cmd == "" || cmd.startsWith("AT")) { // skip AT commands as not used by direct CAN connection
liveData->canSendNextAtCommand = true;
return;
@@ -135,6 +141,7 @@ void CommObd2Can::sendPID(const uint16_t pid, const String& cmd) {
Serial.print(msgString);
}
Serial.println("");
lastDataSent = liveData->params.currentTime;
}
/**
@@ -210,11 +217,11 @@ bool CommObd2Can::processFrame() {
switch (frameType) {
// Single frame
case 0:
rxRemaining = (rxBuf[1] & 0x0f);
rxRemaining = (rxBuf[1] & 0x0f)+1;
break;
// First frame
case 1:
rxRemaining = ((rxBuf[0] & 0x0f) << 8) + rxBuf[1];
rxRemaining = ((rxBuf[0] & 0x0f) << 8) + rxBuf[1]+1;
liveData->responseRow = "0:";
start = 2;
break;
@@ -238,6 +245,10 @@ bool CommObd2Can::processFrame() {
rxRemaining--;
}
Serial.print(", r: ");
Serial.print(rxRemaining);
Serial.println(" ");
parseResponse();
// Send command to board module (obd2 simulation)