Bug fixes for ISOTP and UDS interpretation.

This commit is contained in:
Collin Kidder
2020-03-17 21:26:17 -04:00
parent f4a455b1b8
commit 27b5d156b7
4 changed files with 27 additions and 36 deletions
+15 -24
View File
@@ -210,6 +210,7 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame)
} }
} }
qDebug() << "Emitting single frame ISOTP message"; qDebug() << "Emitting single frame ISOTP message";
msg.setPayload(dataBytes);
emit newISOMessage(msg); emit newISOMessage(msg);
break; break;
case 1: //first frame of a multi-frame message case 1: //first frame of a multi-frame message
@@ -239,7 +240,7 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame)
} }
msg.lastSequence = -1; msg.lastSequence = -1;
msg.setPayload(dataBytes); msg.setPayload(dataBytes);
messageBuffer.append(msg); messageBuffer.insert(msg.frameId(), msg);
//The sending ID is set to the last ID we used to send from this class which is //The sending ID is set to the last ID we used to send from this class which is
//very likely to be correct. But, caution, there is a chance that it isn't. Beware. //very likely to be correct. But, caution, there is a chance that it isn't. Beware.
if (issueFlowMsgs && lastSenderID > 0) if (issueFlowMsgs && lastSenderID > 0)
@@ -258,13 +259,9 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame)
break; break;
case 2: //subsequent frames for multi-frame messages case 2: //subsequent frames for multi-frame messages
pMsg = nullptr; pMsg = nullptr;
for (int i = 0; i < messageBuffer.length(); i++) if (messageBuffer.contains(ID))
{ {
if (messageBuffer[i].frameId() == ID) pMsg = &messageBuffer[ID];
{
pMsg = &messageBuffer[i];
break;
}
} }
if (!pMsg) return; if (!pMsg) return;
if (!pMsg->isMultiframe) return; //if we didn't get a frame type 1 (start of multiframe) first then ignore this frame. if (!pMsg->isMultiframe) return; //if we didn't get a frame type 1 (start of multiframe) first then ignore this frame.
@@ -319,26 +316,20 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame)
void ISOTP_HANDLER::checkNeedFlush(uint64_t ID) void ISOTP_HANDLER::checkNeedFlush(uint64_t ID)
{ {
for (int i = 0; i < messageBuffer.length(); i++) ISOTP_MESSAGE *msg;
if (messageBuffer.contains(ID))
{ {
if (messageBuffer[i].frameId() == ID) msg = &messageBuffer[ID];
if (msg->reportedLength <= msg->payload().count())
{ {
//used to pass by reference but now newISOMessage should pass by value which makes it easier to use cross thread qDebug() << "Flushing full frame" << QString::number(msg->frameId(), 16) << " " << msg->reportedLength << " " << msg->payload().count();
if (messageBuffer[i].frameId() > 0x600 && messageBuffer[i].frameId() < 0x630)
{
if (messageBuffer[i].reportedLength <= messageBuffer[i].payload().count())
{
qDebug() << "Flushing full frame" << QString::number(messageBuffer[i].frameId(), 16) << " " << messageBuffer[i].reportedLength << " " << messageBuffer[i].payload().count();
}
else
{
qDebug() << "Flushing a partial frame " << QString::number(messageBuffer[i].frameId(), 16) << " " << messageBuffer[i].reportedLength << " " << messageBuffer[i].payload().count();
}
}
if (messageBuffer[i].reportedLength > 0) emit newISOMessage(messageBuffer[i]);
messageBuffer.removeAt(i);
return;
} }
else
{
qDebug() << "Flushing a partial frame " << QString::number(msg->frameId(), 16) << " " << msg->reportedLength << " " << msg->payload().count();
}
if (msg->reportedLength > 0) emit newISOMessage(*msg);
messageBuffer.remove(ID);
} }
} }
+1 -1
View File
@@ -35,7 +35,7 @@ signals:
void newISOMessage(ISOTP_MESSAGE msg); void newISOMessage(ISOTP_MESSAGE msg);
private: private:
QList<ISOTP_MESSAGE> messageBuffer; QHash<uint32_t, ISOTP_MESSAGE> messageBuffer;
QList<CANFrame> sendingFrames; QList<CANFrame> sendingFrames;
QList<CANFilter> filters; QList<CANFilter> filters;
const QVector<CANFrame> *modelFrames; const QVector<CANFrame> *modelFrames;
+10 -10
View File
@@ -409,7 +409,7 @@ QString UDS_HANDLER::getDetailedMessageAnalysis(const UDS_MESSAGE &msg)
if (dataLen > 1) if (dataLen > 1)
{ {
buildString.append("Data payload: "); buildString.append("Data payload: ");
for (int j = 1; j < dataLen; j++) buildString.append(Utility::formatHexNum(data[j]) + " "); for (int j = 2; j < dataLen; j++) buildString.append(Utility::formatHexNum(data[j]) + " ");
} }
} }
else else
@@ -417,8 +417,8 @@ QString UDS_HANDLER::getDetailedMessageAnalysis(const UDS_MESSAGE &msg)
buildString.append("Key sending for security level: " + QString::number(msg.subFunc - 1)); buildString.append("Key sending for security level: " + QString::number(msg.subFunc - 1));
if (dataLen > 1) //and it sure as hell should be! if (dataLen > 1) //and it sure as hell should be!
{ {
buildString.append("KEY: "); buildString.append(" KEY: ");
for (int j = 1; j < dataLen; j++) buildString.append(Utility::formatHexNum(data[j]) + " "); for (int j = 2; j < dataLen; j++) buildString.append(Utility::formatHexNum(data[j]) + " ");
} }
} }
break; break;
@@ -429,7 +429,7 @@ QString UDS_HANDLER::getDetailedMessageAnalysis(const UDS_MESSAGE &msg)
if (dataLen > 1) //be kinda pointless if it weren't if (dataLen > 1) //be kinda pointless if it weren't
{ {
buildString.append("SEED: "); buildString.append("SEED: ");
for (int j = 1; j < dataLen; j++) buildString.append(Utility::formatHexNum(data[j]) + " "); for (int j = 2; j < dataLen; j++) buildString.append(Utility::formatHexNum(data[j]) + " ");
} }
} }
else else
@@ -484,13 +484,13 @@ QString UDS_HANDLER::getDetailedMessageAnalysis(const UDS_MESSAGE &msg)
break; break;
case UDS_SERVICES::ROUTINE_CTRL: case UDS_SERVICES::ROUTINE_CTRL:
buildString.append("Routine Control: " + getLongDesc(UDS_ROUTINE_SUB, msg.subFunc)); buildString.append("Routine Control: " + getLongDesc(UDS_ROUTINE_SUB, msg.subFunc));
if (dataLen > 2) if (dataLen > 3)
{ {
int routineID; int routineID;
routineID = (data[1] * 256 + data[2]); routineID = (data[2] * 256 + data[3]);
buildString.append("\nRoutine ID: " + Utility::formatHexNum(routineID)); buildString.append("\nRoutine ID: " + Utility::formatHexNum(routineID));
} }
if (dataLen > 3) if (dataLen > 4)
{ {
buildString.append("\nParameter bytes to routine: "); buildString.append("\nParameter bytes to routine: ");
for (int i = 4; i < dataLen; i++) for (int i = 4; i < dataLen; i++)
@@ -501,13 +501,13 @@ QString UDS_HANDLER::getDetailedMessageAnalysis(const UDS_MESSAGE &msg)
break; break;
case UDS_SERVICES::ROUTINE_CTRL + 0x40: case UDS_SERVICES::ROUTINE_CTRL + 0x40:
buildString.append("Routine Control: " + getLongDesc(UDS_ROUTINE_SUB, msg.subFunc)); buildString.append("Routine Control: " + getLongDesc(UDS_ROUTINE_SUB, msg.subFunc));
if (dataLen > 2) if (dataLen > 3)
{ {
int routineID; int routineID;
routineID = (data[1] * 256 + data[2]); routineID = (data[2] * 256 + data[3]);
buildString.append("\nRoutine ID: " + Utility::formatHexNum(routineID)); buildString.append("\nRoutine ID: " + Utility::formatHexNum(routineID));
} }
if (dataLen > 3) if (dataLen > 4)
{ {
buildString.append("\nBytes returned by routine: "); buildString.append("\nBytes returned by routine: ");
for (int i = 4; i < dataLen; i++) for (int i = 4; i < dataLen; i++)
+1 -1
View File
@@ -73,7 +73,7 @@ void ISOTP_InterpreterWindow::showEvent(QShowEvent* event)
qApp->processEvents(); qApp->processEvents();
decoder->updatedFrames(-2); decoder->rapidFrames(nullptr, *modelFrames);
progress.cancel(); progress.cancel();