Fixes to hopefully parse CANalyzer files more accurately.
This commit is contained in:
+68
-59
@@ -1599,12 +1599,13 @@ bool FrameFileIO::isCanalyzerASC(QString filename)
|
|||||||
//47.971842 2 248 Rx d 8 FF FF FF FF FF FF FF FF
|
//47.971842 2 248 Rx d 8 FF FF FF FF FF FF FF FF
|
||||||
//version 8.1
|
//version 8.1
|
||||||
//47244640.194244 CANFD 1 Rx 122 0 0 6 6 00 00 18 12 D2 00 0 0 200000 0 0 0 0 0
|
//47244640.194244 CANFD 1 Rx 122 0 0 6 6 00 00 18 12 D2 00 0 0 200000 0 0 0 0 0
|
||||||
//That can be simplified to look like this:
|
//Version 16.0.0
|
||||||
//47.971842 2 248 Rx d 8 FF FF FF FF FF FF FF FF
|
//0.008600 1 358 Rx d 8 04 03 50 01 F0 40 54 2C Length = 233910 BitCount = 121 ID = 856
|
||||||
//47244640.194244 CANFD 1 Rx 122 0 0 6 6 00 00 18 12 D2 00 0 0 200000 0 0 0 0 0
|
|
||||||
//Which is then easy to parse by splitting on the spaces
|
|
||||||
//Time bus id dir ? len databytes (Ver 8.0)
|
//Time bus id dir ? len databytes (Ver 8.0)
|
||||||
//Time type bus dir ID ? ? length length bytes then many values of unknown type (ver 8.1)
|
//Time type bus dir ID ? ? length length bytes then many values of unknown type (ver 8.1)
|
||||||
|
//Time bus id dir ? len databytes additional crap (ver 16.0)
|
||||||
|
//So it seems the file format is not entirely different based on version but rather on some other
|
||||||
|
//settings... Fun!
|
||||||
bool FrameFileIO::loadCanalyzerASC(QString filename, QVector<CANFrame>* frames)
|
bool FrameFileIO::loadCanalyzerASC(QString filename, QVector<CANFrame>* frames)
|
||||||
{
|
{
|
||||||
QFile *inFile = new QFile(filename);
|
QFile *inFile = new QFile(filename);
|
||||||
@@ -1638,7 +1639,6 @@ bool FrameFileIO::loadCanalyzerASC(QString filename, QVector<CANFrame>* frames)
|
|||||||
{
|
{
|
||||||
if (line.startsWith("//"))
|
if (line.startsWith("//"))
|
||||||
{
|
{
|
||||||
// version 8.1.0
|
|
||||||
line = line.right(line.length() - 11);
|
line = line.right(line.length() - 11);
|
||||||
QList<QByteArray> versionTokens = line.split('.');
|
QList<QByteArray> versionTokens = line.split('.');
|
||||||
if (versionTokens.length() > 2)
|
if (versionTokens.length() > 2)
|
||||||
@@ -1646,6 +1646,7 @@ bool FrameFileIO::loadCanalyzerASC(QString filename, QVector<CANFrame>* frames)
|
|||||||
verMajor = versionTokens[0].toInt();
|
verMajor = versionTokens[0].toInt();
|
||||||
verMinor = versionTokens[1].toInt();
|
verMinor = versionTokens[1].toInt();
|
||||||
verRevision = versionTokens[2].toInt();
|
verRevision = versionTokens[2].toInt();
|
||||||
|
qDebug() << "Major: " << verMajor << " Minor:" << verMinor << " Rev:" << verRevision;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (line.startsWith("//") || lineCounter > 4)
|
if (line.startsWith("//") || lineCounter > 4)
|
||||||
@@ -1658,65 +1659,21 @@ bool FrameFileIO::loadCanalyzerASC(QString filename, QVector<CANFrame>* frames)
|
|||||||
if (line.length() > 2)
|
if (line.length() > 2)
|
||||||
{
|
{
|
||||||
tokens = line.simplified().split(' ');
|
tokens = line.simplified().split(' ');
|
||||||
if (verMajor == 8 && verMinor == 0)
|
|
||||||
{
|
//try to do some investigating to see if this line is a CAN frame or not. The file format has many other potential line types it seems...
|
||||||
if (tokens.length() > 5)
|
if (tokens.length() > 5)
|
||||||
{
|
{
|
||||||
thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, static_cast<uint64_t>(tokens[0].toDouble() * 1000000.0)));
|
if (tokens[5].at(0) >= '0' && tokens[5].at(0) <= '9')
|
||||||
if (tokens[2].endsWith('x'))
|
|
||||||
{
|
{
|
||||||
QByteArray copied_id = tokens[2];
|
if (tokens[3].toUpper().startsWith("RX") || tokens[3].toUpper().startsWith("TX"))
|
||||||
copied_id.chop(1);
|
|
||||||
thisFrame.setFrameId(copied_id.toUInt(nullptr, 16));
|
|
||||||
thisFrame.setExtendedFrameFormat(true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
thisFrame.setFrameId(tokens[2].toUInt(nullptr, 16));
|
|
||||||
thisFrame.setExtendedFrameFormat(thisFrame.frameId() > 0x7FF); //some .asc files have extended IDs without 'x'
|
|
||||||
}
|
|
||||||
|
|
||||||
int payloadLen = tokens[5].toInt();
|
int payloadLen = tokens[5].toInt();
|
||||||
QByteArray bytes(payloadLen, 0);
|
thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, static_cast<uint64_t>(tokens[0].toDouble() * 1000000.0)));
|
||||||
|
|
||||||
if (payloadLen > 8)
|
//Time bus id dir ? len databytes (Ver 8.0)
|
||||||
{
|
|
||||||
qDebug() << "Payload length too long. Original line: " << line;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (payloadLen < 0)
|
|
||||||
{
|
|
||||||
qDebug() << "Payload length negative! Original line: " << line;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
thisFrame.isReceived = tokens[3].toUpper().contains("RX");
|
|
||||||
thisFrame.bus = tokens[1].toInt();
|
|
||||||
if (tokens[4] == "r") thisFrame.setFrameType(QCanBusFrame::RemoteRequestFrame);
|
|
||||||
for (int d = 6; d < (6 + payloadLen); d++)
|
|
||||||
{
|
|
||||||
if (tokens.count() > d)
|
|
||||||
{
|
|
||||||
bytes[d - 6] = static_cast<char>(tokens[d].toInt(nullptr, 16));
|
|
||||||
}
|
|
||||||
else //expected byte wasn't there to read. Set it zero and set error flag
|
|
||||||
{
|
|
||||||
bytes[d - 6] = 0;
|
|
||||||
foundErrors = true;
|
|
||||||
qDebug() << "D:" << d << " Count:" << tokens.count();
|
|
||||||
qDebug() << "Expected byte missing! Original line: " << line;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
thisFrame.setPayload(bytes);
|
|
||||||
}
|
|
||||||
frames->append(thisFrame);
|
|
||||||
}
|
|
||||||
if (verMajor == 8 && verMinor == 1)
|
|
||||||
{
|
|
||||||
if (tokens.length() > 5)
|
|
||||||
{
|
|
||||||
//47244640.194244 CANFD 1 Rx 122 0 0 6 6 00 00 18 12 D2 00 0 0 200000 0 0 0 0 0
|
|
||||||
//Time type bus dir ID ? ? length length bytes then many values of unknown type (ver 8.1)
|
//Time type bus dir ID ? ? length length bytes then many values of unknown type (ver 8.1)
|
||||||
// 0 1 2 3 4 5 6 7 8 9-
|
if (tokens[1].contains("CAN")) //the different format I haven't seen a whole lot of, seems to support CANFD in this format
|
||||||
|
{
|
||||||
thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, static_cast<uint64_t>(tokens[0].toDouble() * 1000000.0)));
|
thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, static_cast<uint64_t>(tokens[0].toDouble() * 1000000.0)));
|
||||||
if (tokens[4].endsWith('x'))
|
if (tokens[4].endsWith('x'))
|
||||||
{
|
{
|
||||||
@@ -1763,9 +1720,56 @@ bool FrameFileIO::loadCanalyzerASC(QString filename, QVector<CANFrame>* frames)
|
|||||||
}
|
}
|
||||||
thisFrame.setPayload(bytes);
|
thisFrame.setPayload(bytes);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (tokens[2].endsWith('x'))
|
||||||
|
{
|
||||||
|
QByteArray copied_id = tokens[2];
|
||||||
|
copied_id.chop(1);
|
||||||
|
thisFrame.setFrameId(copied_id.toUInt(nullptr, 16));
|
||||||
|
thisFrame.setExtendedFrameFormat(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
thisFrame.setFrameId(tokens[2].toUInt(nullptr, 16));
|
||||||
|
thisFrame.setExtendedFrameFormat(thisFrame.frameId() > 0x7FF); //some .asc files have extended IDs without 'x'
|
||||||
|
}
|
||||||
|
QByteArray bytes(payloadLen, 0);
|
||||||
|
|
||||||
|
if (payloadLen > 8)
|
||||||
|
{
|
||||||
|
qDebug() << "Payload length too long. Original line: " << line;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (payloadLen < 0)
|
||||||
|
{
|
||||||
|
qDebug() << "Payload length negative! Original line: " << line;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
thisFrame.isReceived = tokens[3].toUpper().contains("RX");
|
||||||
|
thisFrame.bus = tokens[1].toInt();
|
||||||
|
if (tokens[4] == "r") thisFrame.setFrameType(QCanBusFrame::RemoteRequestFrame);
|
||||||
|
for (int d = 6; d < (6 + payloadLen); d++)
|
||||||
|
{
|
||||||
|
if (tokens.count() > d)
|
||||||
|
{
|
||||||
|
bytes[d - 6] = static_cast<char>(tokens[d].toInt(nullptr, 16));
|
||||||
|
}
|
||||||
|
else //expected byte wasn't there to read. Set it zero and set error flag
|
||||||
|
{
|
||||||
|
bytes[d - 6] = 0;
|
||||||
|
foundErrors = true;
|
||||||
|
qDebug() << "D:" << d << " Count:" << tokens.count();
|
||||||
|
qDebug() << "Expected byte missing! Original line: " << line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
thisFrame.setPayload(bytes);
|
||||||
|
}
|
||||||
frames->append(thisFrame);
|
frames->append(thisFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
//else foundErrors = true;
|
//else foundErrors = true;
|
||||||
}
|
}
|
||||||
inFile->close();
|
inFile->close();
|
||||||
@@ -2294,12 +2298,17 @@ bool FrameFileIO::loadGenericCSVFile(QString filename, QVector<CANFrame>* frames
|
|||||||
else thisFrame.setExtendedFrameFormat(false);
|
else thisFrame.setExtendedFrameFormat(false);
|
||||||
thisFrame.bus = 0;
|
thisFrame.bus = 0;
|
||||||
thisFrame.setFrameType(QCanBusFrame::DataFrame);
|
thisFrame.setFrameType(QCanBusFrame::DataFrame);
|
||||||
|
if (tokens.length() > 1)
|
||||||
|
{
|
||||||
QList<QByteArray> dataTok = tokens[1].split(' ');
|
QList<QByteArray> dataTok = tokens[1].split(' ');
|
||||||
QByteArray bytes(dataTok.length(), 0);
|
int dLen = dataTok.length();
|
||||||
for (int d = 0; d < dataTok.length(); d++) bytes[d] = static_cast<char>(dataTok[d].toInt(nullptr, 16));
|
if (dLen > 8) dLen = 8;
|
||||||
|
QByteArray bytes(dLen, 0);
|
||||||
|
for (int d = 0; d < dLen; d++) bytes[d] = static_cast<char>(dataTok[d].toInt(nullptr, 16));
|
||||||
thisFrame.setPayload(bytes);
|
thisFrame.setPayload(bytes);
|
||||||
frames->append(thisFrame);
|
frames->append(thisFrame);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else foundErrors = true;
|
else foundErrors = true;
|
||||||
}
|
}
|
||||||
inFile->close();
|
inFile->close();
|
||||||
|
|||||||
Reference in New Issue
Block a user