Fix PCAN file loading to better handle irregularities
This commit is contained in:
+61
-34
@@ -1417,32 +1417,41 @@ bool FrameFileIO::loadPCANFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
if (line.startsWith(';')) continue;
|
if (line.startsWith(';')) continue;
|
||||||
if (line.length() > 41)
|
if (line.length() > 41)
|
||||||
{
|
{
|
||||||
|
line = line.simplified();
|
||||||
|
QList<QByteArray> tokens = line.split(' ');
|
||||||
if (fileVersion == 11)
|
if (fileVersion == 11)
|
||||||
{
|
{
|
||||||
thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, (uint64_t)(line.mid(10, 8).simplified().toDouble() * 1000.0)));
|
if (tokens.length() > 4)
|
||||||
thisFrame.setFrameId(line.mid(28, 8).simplified().toUInt(nullptr, 16));
|
{
|
||||||
|
thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, (uint64_t)(tokens[1].toDouble() * 1000.0)));
|
||||||
|
thisFrame.setFrameId(tokens[3].toUInt(nullptr, 16));
|
||||||
if (thisFrame.frameId() < 0x1FFFFFFF)
|
if (thisFrame.frameId() < 0x1FFFFFFF)
|
||||||
{
|
{
|
||||||
int numBytes = line.mid(38,1).toInt();
|
int numBytes = tokens[4].toInt();
|
||||||
QByteArray bytes(numBytes, 0);
|
QByteArray bytes(numBytes, 0);
|
||||||
thisFrame.isReceived = true;
|
thisFrame.isReceived = true;
|
||||||
thisFrame.bus = 0;
|
thisFrame.bus = 0;
|
||||||
if (line.at(28) == ' ') {
|
if (thisFrame.frameId() > 0x10000000)
|
||||||
thisFrame.setExtendedFrameFormat(false);
|
{
|
||||||
} else {
|
|
||||||
thisFrame.setExtendedFrameFormat(true);
|
thisFrame.setExtendedFrameFormat(true);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
thisFrame.setExtendedFrameFormat(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (line.at(41) == 'R') {
|
if (tokens[5] == "R")
|
||||||
|
{
|
||||||
thisFrame.setFrameType(QCanBusFrame::RemoteRequestFrame);
|
thisFrame.setFrameType(QCanBusFrame::RemoteRequestFrame);
|
||||||
} else {
|
}
|
||||||
QList<QByteArray> tokens = line.mid(41, numBytes * 3).split(' ');
|
else
|
||||||
|
{
|
||||||
thisFrame.setFrameType(QCanBusFrame::DataFrame);
|
thisFrame.setFrameType(QCanBusFrame::DataFrame);
|
||||||
for (int d = 0; d < numBytes; d++)
|
for (int d = 0; d < numBytes; d++)
|
||||||
{
|
{
|
||||||
if (tokens[d] != "")
|
if (tokens[d + 5] != "")
|
||||||
{
|
{
|
||||||
bytes[d] = static_cast<char>(tokens[d].toInt(nullptr, 16));
|
bytes[d] = static_cast<char>(tokens[d + 5].toInt(nullptr, 16));
|
||||||
}
|
}
|
||||||
else bytes[d] = 0;
|
else bytes[d] = 0;
|
||||||
}
|
}
|
||||||
@@ -1451,6 +1460,7 @@ bool FrameFileIO::loadPCANFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
frames->append(thisFrame);
|
frames->append(thisFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Version 1.3
|
// Version 1.3
|
||||||
//; Message Time Bus Type ID Reserved
|
//; Message Time Bus Type ID Reserved
|
||||||
//; Number Offset | | [hex] | Data Length Code
|
//; Number Offset | | [hex] | Data Length Code
|
||||||
@@ -1459,32 +1469,40 @@ bool FrameFileIO::loadPCANFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
//;---+-- ------+------ +- --+-- ---+---- +- -+-- -+ -- -- -- -- -- -- --
|
//;---+-- ------+------ +- --+-- ---+---- +- -+-- -+ -- -- -- -- -- -- --
|
||||||
// 0-6 8-20 22 25-26 38 41-? two chars each + space
|
// 0-6 8-20 22 25-26 38 41-? two chars each + space
|
||||||
// 1) 1004.898 1 Tx 1fff079B - 8 02 21 04 00 00 00 00 00
|
// 1) 1004.898 1 Tx 1fff079B - 8 02 21 04 00 00 00 00 00
|
||||||
|
// 0 1 2 3 4 5 6 7-?
|
||||||
else if (fileVersion == 13)
|
else if (fileVersion == 13)
|
||||||
{
|
{
|
||||||
thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, static_cast<uint64_t>(line.mid(8, 13).simplified().toDouble() * 1000.0)));
|
if (tokens.length() > 6)
|
||||||
thisFrame.setFrameId(line.mid(31, 8).simplified().toUInt(nullptr, 16));
|
{
|
||||||
|
thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, static_cast<uint64_t>(tokens[1].toDouble() * 1000.0)));
|
||||||
|
thisFrame.setFrameId(tokens[3].toUInt(nullptr, 16));
|
||||||
if (thisFrame.frameId() < 0x1FFFFFFF)
|
if (thisFrame.frameId() < 0x1FFFFFFF)
|
||||||
{
|
{
|
||||||
int numBytes = line.mid(43,2).trimmed().toInt();
|
int numBytes = tokens[6].toInt();
|
||||||
QByteArray bytes(numBytes, 0);
|
QByteArray bytes(numBytes, 0);
|
||||||
//qDebug() << thisFrame.payload().length();
|
//qDebug() << thisFrame.payload().length();
|
||||||
thisFrame.isReceived = true;
|
thisFrame.isReceived = true;
|
||||||
thisFrame.bus = line.mid(22,1).trimmed().toInt();
|
thisFrame.bus = tokens[2].toInt();
|
||||||
if (line.at(30) == ' ') {
|
if (thisFrame.frameId() > 0x10000000)
|
||||||
thisFrame.setExtendedFrameFormat(false);
|
{
|
||||||
} else {
|
|
||||||
thisFrame.setExtendedFrameFormat(true);
|
thisFrame.setExtendedFrameFormat(true);
|
||||||
}
|
}
|
||||||
if (line.at(48) == 'R') {
|
else
|
||||||
|
{
|
||||||
|
thisFrame.setExtendedFrameFormat(false);
|
||||||
|
}
|
||||||
|
if (tokens[7] == "R")
|
||||||
|
{
|
||||||
thisFrame.setFrameType(QCanBusFrame::RemoteRequestFrame);
|
thisFrame.setFrameType(QCanBusFrame::RemoteRequestFrame);
|
||||||
} else {
|
}
|
||||||
QList<QByteArray> tokens = line.mid(48, numBytes * 3).split(' ');
|
else
|
||||||
|
{
|
||||||
thisFrame.setFrameType(QCanBusFrame::DataFrame);
|
thisFrame.setFrameType(QCanBusFrame::DataFrame);
|
||||||
for (int d = 0; d < numBytes; d++)
|
for (int d = 0; d < numBytes; d++)
|
||||||
{
|
{
|
||||||
if (tokens[d] != "")
|
if (tokens[d + 7] != "")
|
||||||
{
|
{
|
||||||
bytes[d] = static_cast<char>(tokens[d].toInt(nullptr, 16));
|
bytes[d] = static_cast<char>(tokens[d + 7].toInt(nullptr, 16));
|
||||||
}
|
}
|
||||||
else bytes[d] = 0;
|
else bytes[d] = 0;
|
||||||
}
|
}
|
||||||
@@ -1493,32 +1511,40 @@ bool FrameFileIO::loadPCANFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
frames->append(thisFrame);
|
frames->append(thisFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (fileVersion == 20)
|
else if (fileVersion == 20)
|
||||||
{
|
{
|
||||||
thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, static_cast<uint64_t>(line.mid(8, 13).simplified().toDouble() * 1000.0)));
|
if (tokens.length() > 5)
|
||||||
thisFrame.setFrameId(line.mid(25, 8).simplified().toUInt(nullptr, 16));
|
{
|
||||||
|
thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, static_cast<uint64_t>(tokens[1].toDouble() * 1000.0)));
|
||||||
|
thisFrame.setFrameId(tokens[3].toUInt(nullptr, 16));
|
||||||
if (thisFrame.frameId() < 0x1FFFFFFF)
|
if (thisFrame.frameId() < 0x1FFFFFFF)
|
||||||
{
|
{
|
||||||
int numBytes = line.mid(37,2).trimmed().toInt();
|
int numBytes = tokens[5].toInt();
|
||||||
QByteArray bytes(numBytes, 0);
|
QByteArray bytes(numBytes, 0);
|
||||||
//qDebug() << thisFrame.payload().length();
|
//qDebug() << thisFrame.payload().length();
|
||||||
thisFrame.isReceived = true;
|
thisFrame.isReceived = true;
|
||||||
thisFrame.bus = 0;
|
thisFrame.bus = 0;
|
||||||
if (line.at(25) == ' ') {
|
if (thisFrame.frameId() > 0x10000000)
|
||||||
thisFrame.setExtendedFrameFormat(false);
|
{
|
||||||
} else {
|
|
||||||
thisFrame.setExtendedFrameFormat(true);
|
thisFrame.setExtendedFrameFormat(true);
|
||||||
}
|
}
|
||||||
if (line.at(40) == 'R') {
|
else
|
||||||
|
{
|
||||||
|
thisFrame.setExtendedFrameFormat(false);
|
||||||
|
}
|
||||||
|
if (tokens[6] == "R")
|
||||||
|
{
|
||||||
thisFrame.setFrameType(QCanBusFrame::RemoteRequestFrame);
|
thisFrame.setFrameType(QCanBusFrame::RemoteRequestFrame);
|
||||||
} else {
|
}
|
||||||
QList<QByteArray> tokens = line.mid(40, numBytes * 3).split(' ');
|
else
|
||||||
|
{
|
||||||
thisFrame.setFrameType(QCanBusFrame::DataFrame);
|
thisFrame.setFrameType(QCanBusFrame::DataFrame);
|
||||||
for (int d = 0; d < numBytes; d++)
|
for (int d = 0; d < numBytes; d++)
|
||||||
{
|
{
|
||||||
if (tokens[d] != "")
|
if (tokens[d + 6] != "")
|
||||||
{
|
{
|
||||||
bytes[d] = static_cast<char>(tokens[d].toInt(nullptr, 16));
|
bytes[d] = static_cast<char>(tokens[d + 6].toInt(nullptr, 16));
|
||||||
}
|
}
|
||||||
else bytes[d] = 0;
|
else bytes[d] = 0;
|
||||||
}
|
}
|
||||||
@@ -1528,6 +1554,7 @@ bool FrameFileIO::loadPCANFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//else foundErrors = true;
|
//else foundErrors = true;
|
||||||
}
|
}
|
||||||
inFile->close();
|
inFile->close();
|
||||||
|
|||||||
Reference in New Issue
Block a user