Changes to hopefully handle error frames better over the socketcan

interface
This commit is contained in:
Collin Kidder
2020-10-13 20:09:46 -04:00
parent ee944a51e9
commit 5a3e5636f6
3 changed files with 37 additions and 49 deletions
+23 -2
View File
@@ -311,6 +311,8 @@ void CANFrameModel::recalcOverwrite()
uint64_t idAugmented; //id in lower 29 bits, bus number shifted up 29 bits uint64_t idAugmented; //id in lower 29 bits, bus number shifted up 29 bits
foreach(CANFrame frame, frames) foreach(CANFrame frame, frames)
{ {
if (frame.frameType() != frame.DataFrame) continue;
idAugmented = frame.frameId(); idAugmented = frame.frameId();
idAugmented = idAugmented + (frame.bus << 29ull); idAugmented = idAugmented + (frame.bus << 29ull);
if (!overWriteFrames.contains(idAugmented)) if (!overWriteFrames.contains(idAugmented))
@@ -445,7 +447,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
tempString.append(QString::number(thisFrame.frameId() & 0x7)); tempString.append(QString::number(thisFrame.frameId() & 0x7));
return tempString; return tempString;
} }
if (thisFrame.frameType() != QCanBusFrame::RemoteRequestFrame) { if (thisFrame.frameType() == QCanBusFrame::DataFrame) {
if (dataLen < 0) dataLen = 0; if (dataLen < 0) dataLen = 0;
//if (dLen > 8) dLen = 8; //if (dLen > 8) dLen = 8;
for (int i = 0; i < dataLen; i++) 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)); tempString.append(QString::fromUtf8(&byt, 1));
} }
} }
if (thisFrame.frameType() == QCanBusFrame::ErrorFrame)
{
tempString = "ERROR";
}
return tempString; return tempString;
case Column::Data: case Column::Data:
if (dataLen < 0) dataLen = 0; 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)); else tempString.append(QString::number(data[i], 10));
tempString.append(" "); 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 //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); DBC_MESSAGE *msg = dbcHandler->findMessage(thisFrame);
if (msg != nullptr) if (msg != nullptr)
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef CONFIG #ifndef CONFIG
#define CONFIG #define CONFIG
#define VERSION 200 #define VERSION 201
//try to keep this in sync. //try to keep this in sync.
//SavvyCAN will complain if you connect a GVRET board with a revision //SavvyCAN will complain if you connect a GVRET board with a revision
+13 -46
View File
@@ -183,55 +183,22 @@ void SerialBusConnection::framesReceived()
CANFrame* frame_p = getQueue().get(); CANFrame* frame_p = getQueue().get();
if(frame_p) { if(frame_p) {
frame_p->setPayload(recFrame.payload()); frame_p->setPayload(recFrame.payload());
frame_p->bus = 0; frame_p->bus = 0;
if (recFrame.frameType() == recFrame.ErrorFrame)
if (recFrame.frameType() == QCanBusFrame::ErrorFrame) { {
// Constants defined in include/uapi/linux/can/error.h frame_p->setExtendedFrameFormat(recFrame.hasExtendedFrameFormat());
//since the whole program uses QCanBusFrame now we can just grab errors directly out of the proper place from now on frame_p->setFrameId(recFrame.frameId() + 0x20000000ull);
/* }
switch (recFrame.error()) { else
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->setExtendedFrameFormat(recFrame.hasExtendedFrameFormat()); frame_p->setExtendedFrameFormat(recFrame.hasExtendedFrameFormat());
frame_p->setFrameId(recFrame.frameId()); 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->setTimeStamp(recFrame.timeStamp());
frame_p->isReceived = true; frame_p->setFrameType(recFrame.frameType());
frame_p->setError(recFrame.error());
frame_p->isReceived = true;
if (useSystemTime) { if (useSystemTime) {
frame_p->setTimeStamp(QCanBusFrame::TimeStamp(0, QDateTime::currentMSecsSinceEpoch() * 1000ul)); frame_p->setTimeStamp(QCanBusFrame::TimeStamp(0, QDateTime::currentMSecsSinceEpoch() * 1000ul));
} }