From 47d07b8bf2381370b823c7f9fac97b6f975749f5 Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Sat, 17 Sep 2022 12:48:48 -0500 Subject: [PATCH 1/2] Fixed bug where switching to RAW mode would fail due to the "ok" response being received in the same message as the first data frame Sometimes when opening socketcand 1 or more busses won't start right and there's a ton of debug data saying "received datagramm: ...." It seems to happen because the switch to RAW mode is in progress and we receive the OK with a frame in the same datagramm and we don't parse the OK out of the string but rather expect the whole string to just be OK. Offending code is in socketcand.cpp SocketCANd::procRXData line 386 Fixed by looking to see if the < ok > message was at index 0 of the incoming message...could also look for it elsewhere (as in index != -1), but not sure if necessary --- canframemodel.cpp | 2 +- connections/socketcand.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/canframemodel.cpp b/canframemodel.cpp index 735236b..c7f5ce1 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -779,7 +779,7 @@ int CANFrameModel::sendBulkRefresh() if (lastUpdateNumFrames == 0 && !overwriteDups) return 0; if (filteredFrames.count() == 0) return 0; - qDebug() << "Bulk refresh of " << lastUpdateNumFrames; + //qDebug() << "Bulk refresh of " << lastUpdateNumFrames; beginResetModel(); endResetModel(); diff --git a/connections/socketcand.cpp b/connections/socketcand.cpp index cfac211..15db439 100644 --- a/connections/socketcand.cpp +++ b/connections/socketcand.cpp @@ -396,6 +396,12 @@ void SocketCANd::procRXData(QString data, int busNum) { rx_state[busNum] = RAWMODE; } + else if(data.indexOf("< ok >", 0, Qt::CaseSensitivity::CaseInsensitive) == 0) + { + qDebug() << "Ok found at start of compound message, switching to RAW and decoding immediately"; + rx_state[busNum] = RAWMODE; + decodeFrames(data, busNum); + } break; case RAWMODE: decodeFrames(data, busNum); From 60520b59395474e1ed585595325aee90bf0bd79d Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Sat, 17 Sep 2022 12:52:03 -0500 Subject: [PATCH 2/2] Added handing of ok message from RAW mode switch coming in out of order with other messages... For now I made it its own else statement so it can be detected --- connections/socketcand.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/connections/socketcand.cpp b/connections/socketcand.cpp index 15db439..20f2ae8 100644 --- a/connections/socketcand.cpp +++ b/connections/socketcand.cpp @@ -402,6 +402,12 @@ void SocketCANd::procRXData(QString data, int busNum) rx_state[busNum] = RAWMODE; decodeFrames(data, busNum); } + else if(data.indexOf("< ok >", 0, Qt::CaseSensitivity::CaseInsensitive) > 0) + { + qDebug() << "Ok found at in middle of compound message, switching to RAW and decoding immediately"; + rx_state[busNum] = RAWMODE; + decodeFrames(data, busNum); + } break; case RAWMODE: decodeFrames(data, busNum);