Fix timeout after CAN send.

Signed-off-by: Martin Kolací <martin.kolaci@lmc.eu>
This commit is contained in:
Martin Kolací
2020-12-21 14:01:20 +01:00
parent 0bd5fd0f74
commit 5721a8aaef
2 changed files with 3 additions and 3 deletions

View File

@@ -78,7 +78,7 @@ void CommObd2Can::mainLoop() {
} }
} }
Serial.println(liveData->params.currentTime ); Serial.println(liveData->params.currentTime );
if (lastDataSent != 0 && liveData->params.currentTime + 2 > lastDataSent) { if (lastDataSent != 0 && (unsigned long)(millis() - lastDataSent) > 500) {
Serial.print("CAN execution timeout. Continue with next command."); Serial.print("CAN execution timeout. Continue with next command.");
liveData->canSendNextAtCommand = true; liveData->canSendNextAtCommand = true;
return; return;
@@ -92,7 +92,6 @@ void CommObd2Can::executeCommand(String cmd) {
Serial.print("executeCommand "); Serial.print("executeCommand ");
Serial.println(cmd); Serial.println(cmd);
lastDataSent = 0;
if (cmd.equals("") || cmd.startsWith("AT")) { // skip AT commands as not used by direct CAN connection if (cmd.equals("") || cmd.startsWith("AT")) { // skip AT commands as not used by direct CAN connection
liveData->canSendNextAtCommand = true; liveData->canSendNextAtCommand = true;
@@ -140,7 +139,7 @@ void CommObd2Can::sendPID(const uint16_t pid, const String& cmd) {
Serial.print(msgString); Serial.print(msgString);
} }
Serial.println(""); Serial.println("");
lastDataSent = liveData->params.currentTime; lastDataSent = millis();
} }
/** /**

View File

@@ -18,6 +18,7 @@ class CommObd2Can : public CommInterface {
int16_t rxRemaining; // Remaining bytes to complete message int16_t rxRemaining; // Remaining bytes to complete message
char msgString[128]; // Array to store serial string char msgString[128]; // Array to store serial string
uint16_t lastPid; uint16_t lastPid;
unsigned long lastDataSent = 0;
public: public:
void connectDevice() override; void connectDevice() override;
void disconnectDevice() override; void disconnectDevice() override;