From 5a3e5636f66aea079e87f46c45d95f88bbbb12a5 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Tue, 13 Oct 2020 20:09:46 -0400 Subject: [PATCH] Changes to hopefully handle error frames better over the socketcan interface --- canframemodel.cpp | 25 +++++++++++- config.h | 2 +- connections/serialbusconnection.cpp | 59 +++++++---------------------- 3 files changed, 37 insertions(+), 49 deletions(-) diff --git a/canframemodel.cpp b/canframemodel.cpp index 39dd246..de09091 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -311,6 +311,8 @@ void CANFrameModel::recalcOverwrite() uint64_t idAugmented; //id in lower 29 bits, bus number shifted up 29 bits foreach(CANFrame frame, frames) { + if (frame.frameType() != frame.DataFrame) continue; + idAugmented = frame.frameId(); idAugmented = idAugmented + (frame.bus << 29ull); if (!overWriteFrames.contains(idAugmented)) @@ -445,7 +447,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const tempString.append(QString::number(thisFrame.frameId() & 0x7)); return tempString; } - if (thisFrame.frameType() != QCanBusFrame::RemoteRequestFrame) { + if (thisFrame.frameType() == QCanBusFrame::DataFrame) { if (dataLen < 0) dataLen = 0; //if (dLen > 8) dLen = 8; for (int i = 0; i < dataLen; i++) @@ -457,6 +459,10 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const tempString.append(QString::fromUtf8(&byt, 1)); } } + if (thisFrame.frameType() == QCanBusFrame::ErrorFrame) + { + tempString = "ERROR"; + } return tempString; case Column::Data: if (dataLen < 0) dataLen = 0; @@ -470,8 +476,23 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const else tempString.append(QString::number(data[i], 10)); tempString.append(" "); } + if (thisFrame.frameType() == thisFrame.ErrorFrame) + { + if (thisFrame.error() & thisFrame.TransmissionTimeoutError) tempString.append("\nTX Timeout"); + if (thisFrame.error() & thisFrame.LostArbitrationError) tempString.append("\nLost Arbitration"); + if (thisFrame.error() & thisFrame.ControllerError) tempString.append("\nController Error"); + if (thisFrame.error() & thisFrame.ProtocolViolationError) tempString.append("\nProtocol Violation"); + if (thisFrame.error() & thisFrame.TransceiverError) tempString.append("\nTransceiver Error"); + if (thisFrame.error() & thisFrame.MissingAcknowledgmentError) tempString.append("\nMissing ACK"); + if (thisFrame.error() & thisFrame.BusOffError) tempString.append("\nBus OFF"); + if (thisFrame.error() & thisFrame.BusError) tempString.append("\nBus ERR"); + if (thisFrame.error() & thisFrame.ControllerRestartError) tempString.append("\nController restart err"); + if (thisFrame.error() & thisFrame.UnknownError) tempString.append("\nUnknown error type"); + } + //TODO: technically the actual returned bytes for an error frame encode some more info. Not interpreting it yet. + //now, if we're supposed to interpret the data and the DBC handler is loaded then use it - if (dbcHandler != nullptr && interpretFrames) + if ( (dbcHandler != nullptr) && interpretFrames && (thisFrame.frameType() == thisFrame.DataFrame) ) { DBC_MESSAGE *msg = dbcHandler->findMessage(thisFrame); if (msg != nullptr) diff --git a/config.h b/config.h index 3bbbd8a..0e8517d 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #ifndef CONFIG #define CONFIG -#define VERSION 200 +#define VERSION 201 //try to keep this in sync. //SavvyCAN will complain if you connect a GVRET board with a revision diff --git a/connections/serialbusconnection.cpp b/connections/serialbusconnection.cpp index f628cb6..c544a85 100644 --- a/connections/serialbusconnection.cpp +++ b/connections/serialbusconnection.cpp @@ -183,55 +183,22 @@ void SerialBusConnection::framesReceived() CANFrame* frame_p = getQueue().get(); if(frame_p) { frame_p->setPayload(recFrame.payload()); - frame_p->bus = 0; - - if (recFrame.frameType() == QCanBusFrame::ErrorFrame) { - // Constants defined in include/uapi/linux/can/error.h - //since the whole program uses QCanBusFrame now we can just grab errors directly out of the proper place from now on - /* - switch (recFrame.error()) { - case QCanBusFrame::TransmissionTimeoutError: - frame_p->setFrameId(0x20000001); - break; - case QCanBusFrame::LostArbitrationError: - frame_p->ID = 0x20000002; - break; - case QCanBusFrame::ControllerError: - frame_p->ID = 0x20000004; - break; - case QCanBusFrame::ProtocolViolationError: - frame_p->ID = 0x20000008; - break; - case QCanBusFrame::TransceiverError: - frame_p->ID = 0x20000010; - break; - case QCanBusFrame::MissingAcknowledgmentError: - frame_p->ID = 0x20000020; - break; - case QCanBusFrame::BusOffError: - frame_p->ID = 0x20000040; - break; - case QCanBusFrame::BusError: - frame_p->ID = 0x20000080; - break; - case QCanBusFrame::ControllerRestartError: - frame_p->ID = 0x20000100; - break; - default: - break; - } - frame_p->extended = true; - */ - } else { + frame_p->bus = 0; + if (recFrame.frameType() == recFrame.ErrorFrame) + { + frame_p->setExtendedFrameFormat(recFrame.hasExtendedFrameFormat()); + frame_p->setFrameId(recFrame.frameId() + 0x20000000ull); + } + else + { frame_p->setExtendedFrameFormat(recFrame.hasExtendedFrameFormat()); frame_p->setFrameId(recFrame.frameId()); - frame_p->setTimeStamp(recFrame.timeStamp()); - frame_p->setFrameType(recFrame.frameType()); - frame_p->setError(recFrame.error()); - frame_p->isReceived = true; } - - frame_p->isReceived = true; + frame_p->setTimeStamp(recFrame.timeStamp()); + frame_p->setFrameType(recFrame.frameType()); + frame_p->setError(recFrame.error()); + frame_p->isReceived = true; + if (useSystemTime) { frame_p->setTimeStamp(QCanBusFrame::TimeStamp(0, QDateTime::currentMSecsSinceEpoch() * 1000ul)); }