From a98b9b2b5262de9a56a1f75d4c507471a6d88947 Mon Sep 17 00:00:00 2001 From: Lubos Petrovic Date: Tue, 22 Dec 2020 10:04:27 +0100 Subject: [PATCH] can --- CommObd2Can.cpp | 5 ++++- CommObd2Can.h | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CommObd2Can.cpp b/CommObd2Can.cpp index 70ae1f6..c6bf9b1 100644 --- a/CommObd2Can.cpp +++ b/CommObd2Can.cpp @@ -77,6 +77,7 @@ void CommObd2Can::mainLoop() { delay(1); // apply timeout for next frames loop too if (lastDataSent != 0 && (unsigned long)(millis() - lastDataSent) > 100) { + Serial.print("CAN execution timeout (multiframe message)."); break; } } @@ -157,7 +158,7 @@ void CommObd2Can::sendPID(const uint16_t pid, const String& cmd) { */ void CommObd2Can::sendFlowControlFrame() { - uint8_t txBuf[8] = { 0x30, 0, 0, 0, 0, 0, 0, 0 }; + uint8_t txBuf[8] = { 0x30, requestFramesCount /*request count*/, 14 /*ms between frames*/ , 0, 0, 0, 0, 0 }; const uint8_t sndStat = CAN->sendMsgBuf(lastPid, 0, 8, txBuf); // 11 bit if (sndStat == CAN_OK) { Serial.print("Flow control frame sent "); @@ -225,10 +226,12 @@ bool CommObd2Can::processFrame() { // Single frame case 0: rxRemaining = (rxBuf[1] & 0x0f); + requestFramesCount = 0; break; // First frame case 1: rxRemaining = ((rxBuf[0] & 0x0f) << 8) + rxBuf[1]; + requestFramesCount = ceil((rxRemaining - 6) / 7.0); liveData->responseRowMerged = ""; for (uint16_t i = 0; i < rxRemaining - 1; i++) liveData->responseRowMerged += "00"; diff --git a/CommObd2Can.h b/CommObd2Can.h index c403497..cbb352a 100644 --- a/CommObd2Can.h +++ b/CommObd2Can.h @@ -15,7 +15,8 @@ class CommObd2Can : public CommInterface { long unsigned int rxId; unsigned char rxLen = 0; uint8_t rxBuf[32]; - int16_t rxRemaining; // Remaining bytes to complete message + int16_t rxRemaining; // Remaining bytes to complete message, signed is ok + uint8_t requestFramesCount; char msgString[128]; // Array to store serial string uint16_t lastPid; unsigned long lastDataSent = 0;