From 1c8700897016e740241cb26a930b37e2b0773f9a Mon Sep 17 00:00:00 2001 From: Ahmed Sheimy Date: Fri, 5 Aug 2022 18:32:45 +0400 Subject: [PATCH 1/5] Update canconfactory.cpp restore network connection was not working because it was detected as serial by this modification it is working --- connections/canconfactory.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/connections/canconfactory.cpp b/connections/canconfactory.cpp index 1fc461c..0adb9b8 100644 --- a/connections/canconfactory.cpp +++ b/connections/canconfactory.cpp @@ -13,6 +13,9 @@ CANConnection* CanConFactory::create(type pType, QString pPortName, QString pDri case SERIALBUS: return new SerialBusConnection(pPortName, pDriverName); case GVRET_SERIAL: + if(pPortName.contains(".")) + return new GVRetSerial(pPortName, true); + else return new GVRetSerial(pPortName, false); case REMOTE: return new GVRetSerial(pPortName, true); //it's a special case of GVRET connected over TCP/IP so it uses the same class From 7b966fe4a6b266c9f4da3f4ed50a7fd79414cb7d Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Fri, 16 Sep 2022 15:38:54 -0500 Subject: [PATCH 2/5] Fixed incorrect handling of partial frame tagged onto the end of a complete frame. Not sure if my method drops the partial or just sends the buffer back to continue filling. --- connections/socketcand.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/connections/socketcand.cpp b/connections/socketcand.cpp index 9bbddbb..cfac211 100644 --- a/connections/socketcand.cpp +++ b/connections/socketcand.cpp @@ -263,6 +263,12 @@ void SocketCANd::decodeFrames(QString data, int busNum) QString frameStr = frameStrConst; QStringList frameParsed = (frameStr.remove(QRegExp("^<")).remove(QRegExp(">$"))).simplified().split(' '); + if(frameParsed.length() < 2) + { + qDebug() << "Received datagramm is an incomplete frame: " << data; + return; + } + buildFrame.setFrameId(frameParsed[1].toUInt(nullptr, 16)); buildFrame.bus = busNum; @@ -271,6 +277,13 @@ void SocketCANd::decodeFrames(QString data, int busNum) buildFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, frameParsed[2].toDouble() * 1000000l)); //buildFrame.len = frameParsed[3].length() * 0.5; + + if(frameParsed.length() < 4) + { + qDebug() << "Received frame doesn't contain any data: " << data; + return; + } + int framelength = frameParsed[3].length() * 0.5; buildData.resize(framelength); From 47d07b8bf2381370b823c7f9fac97b6f975749f5 Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Sat, 17 Sep 2022 12:48:48 -0500 Subject: [PATCH 3/5] 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 4/5] 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); From 99640d7239437d6c3f0b8386abebe4258c33a1da Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Sat, 17 Sep 2022 13:16:02 -0500 Subject: [PATCH 5/5] Fixed data string parsing bug where an empty string created by a trailing space would be interpreted as a 0 and then added as a data byte This affected editing of the data in the table as well as loading data from a saved file --- framesenderwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framesenderwindow.cpp b/framesenderwindow.cpp index 8e796ef..7029fa0 100644 --- a/framesenderwindow.cpp +++ b/framesenderwindow.cpp @@ -898,7 +898,7 @@ void FrameSenderWindow::processCellChange(int line, int col) case 6: //Data bytes for (int i = 0; i < 8; i++) sendingData[line].payload().data()[i] = 0; - tokens = ui->tableSender->item(line, 6)->text().split(" "); + tokens = ui->tableSender->item(line, 6)->text().split(" ", QString::SkipEmptyParts); arr.clear(); arr.reserve(tokens.count()); for (int j = 0; j < tokens.count(); j++)