From 859425d6f27e961f373731224550b3cc154b2e29 Mon Sep 17 00:00:00 2001 From: Lubos Petrovic Date: Mon, 21 Dec 2020 18:45:20 +0100 Subject: [PATCH] can --- CommObd2Can.cpp | 26 +++++++++++++++++++++----- CommObd2Can.h | 1 + 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CommObd2Can.cpp b/CommObd2Can.cpp index af0dfa9..70ae1f6 100644 --- a/CommObd2Can.cpp +++ b/CommObd2Can.cpp @@ -75,6 +75,15 @@ void CommObd2Can::mainLoop() { if (rxRemaining <= 2) break; delay(1); + // apply timeout for next frames loop too + if (lastDataSent != 0 && (unsigned long)(millis() - lastDataSent) > 100) { + break; + } + } + // Process incomplette messages + if (liveData->responseRowMerged.length() > 7) { + processMergedResponse(); + return; } } if (lastDataSent != 0 && (unsigned long)(millis() - lastDataSent) > 100) { @@ -266,13 +275,20 @@ bool CommObd2Can::processFrame() { // Send response to board module if (rxRemaining <= 2) { - Serial.print("merged:"); - Serial.println(liveData->responseRowMerged); - board->parseRowMerged(); - liveData->responseRowMerged = ""; - liveData->canSendNextAtCommand = true; + processMergedResponse(); return false; } return true; } + +/** + processMergedResponse +*/ +void CommObd2Can::processMergedResponse() { + Serial.print("merged:"); + Serial.println(liveData->responseRowMerged); + board->parseRowMerged(); + liveData->responseRowMerged = ""; + liveData->canSendNextAtCommand = true; +} diff --git a/CommObd2Can.h b/CommObd2Can.h index 28dd2ec..c403497 100644 --- a/CommObd2Can.h +++ b/CommObd2Can.h @@ -30,4 +30,5 @@ class CommObd2Can : public CommInterface { void sendFlowControlFrame(); uint8_t receivePID(); bool processFrame(); + void processMergedResponse(); };