can timeout
This commit is contained in:
@@ -12,6 +12,7 @@ class CommInterface {
|
|||||||
BoardInterface* board;
|
BoardInterface* board;
|
||||||
char ch;
|
char ch;
|
||||||
String response;
|
String response;
|
||||||
|
time_t lastDataSent;
|
||||||
public:
|
public:
|
||||||
void initComm(LiveData* pLiveData, BoardInterface* pBoard);
|
void initComm(LiveData* pLiveData, BoardInterface* pBoard);
|
||||||
virtual void connectDevice() = 0;
|
virtual void connectDevice() = 0;
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ void CommObd2Can::mainLoop() {
|
|||||||
delay(10);
|
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.print("executeCommand ");
|
||||||
Serial.println(cmd);
|
Serial.println(cmd);
|
||||||
|
|
||||||
|
|
||||||
if (cmd == "" || cmd.startsWith("AT")) { // skip AT commands as not used by direct CAN connection
|
if (cmd == "" || cmd.startsWith("AT")) { // skip AT commands as not used by direct CAN connection
|
||||||
liveData->canSendNextAtCommand = true;
|
liveData->canSendNextAtCommand = true;
|
||||||
return;
|
return;
|
||||||
@@ -135,6 +141,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -210,11 +217,11 @@ bool CommObd2Can::processFrame() {
|
|||||||
switch (frameType) {
|
switch (frameType) {
|
||||||
// Single frame
|
// Single frame
|
||||||
case 0:
|
case 0:
|
||||||
rxRemaining = (rxBuf[1] & 0x0f);
|
rxRemaining = (rxBuf[1] & 0x0f)+1;
|
||||||
break;
|
break;
|
||||||
// First frame
|
// First frame
|
||||||
case 1:
|
case 1:
|
||||||
rxRemaining = ((rxBuf[0] & 0x0f) << 8) + rxBuf[1];
|
rxRemaining = ((rxBuf[0] & 0x0f) << 8) + rxBuf[1]+1;
|
||||||
liveData->responseRow = "0:";
|
liveData->responseRow = "0:";
|
||||||
start = 2;
|
start = 2;
|
||||||
break;
|
break;
|
||||||
@@ -238,6 +245,10 @@ bool CommObd2Can::processFrame() {
|
|||||||
rxRemaining--;
|
rxRemaining--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Serial.print(", r: ");
|
||||||
|
Serial.print(rxRemaining);
|
||||||
|
Serial.println(" ");
|
||||||
|
|
||||||
parseResponse();
|
parseResponse();
|
||||||
|
|
||||||
// Send command to board module (obd2 simulation)
|
// Send command to board module (obd2 simulation)
|
||||||
|
|||||||
Reference in New Issue
Block a user