diff --git a/framefileio.cpp b/framefileio.cpp index 5dc82d4..e350671 100644 --- a/framefileio.cpp +++ b/framefileio.cpp @@ -1596,15 +1596,16 @@ bool FrameFileIO::isCanalyzerASC(QString filename) //There tends to be four lines of header first. The last of which starts with // so first burn off lines //until a line starting with // is seen, then the rest are formatted like this: //Version 8.0: -// 47.971842 2 248 Rx d 8 FF FF FF FF FF FF FF FF -//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 -//That can be simplified to look like this: //47.971842 2 248 Rx d 8 FF FF FF FF FF FF FF FF +//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 -//Which is then easy to parse by splitting on the spaces +//Version 16.0.0 +//0.008600 1 358 Rx d 8 04 03 50 01 F0 40 54 2C Length = 233910 BitCount = 121 ID = 856 //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 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* frames) { QFile *inFile = new QFile(filename); @@ -1638,7 +1639,6 @@ bool FrameFileIO::loadCanalyzerASC(QString filename, QVector* frames) { if (line.startsWith("//")) { - // version 8.1.0 line = line.right(line.length() - 11); QList versionTokens = line.split('.'); if (versionTokens.length() > 2) @@ -1646,6 +1646,7 @@ bool FrameFileIO::loadCanalyzerASC(QString filename, QVector* frames) verMajor = versionTokens[0].toInt(); verMinor = versionTokens[1].toInt(); verRevision = versionTokens[2].toInt(); + qDebug() << "Major: " << verMajor << " Minor:" << verMinor << " Rev:" << verRevision; } } if (line.startsWith("//") || lineCounter > 4) @@ -1658,112 +1659,115 @@ bool FrameFileIO::loadCanalyzerASC(QString filename, QVector* frames) if (line.length() > 2) { 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) + if (tokens[5].at(0) >= '0' && tokens[5].at(0) <= '9') { - thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, static_cast(tokens[0].toDouble() * 1000000.0))); - if (tokens[2].endsWith('x')) + if (tokens[3].toUpper().startsWith("RX") || tokens[3].toUpper().startsWith("TX")) { - 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' - } + int payloadLen = tokens[5].toInt(); + thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, static_cast(tokens[0].toDouble() * 1000000.0))); - int payloadLen = tokens[5].toInt(); - QByteArray bytes(payloadLen, 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) + 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(tokens[0].toDouble() * 1000000.0))); + if (tokens[4].endsWith('x')) + { + QByteArray copied_id = tokens[4]; + copied_id.chop(1); + thisFrame.setFrameId(copied_id.toUInt(nullptr, 16)); + thisFrame.setExtendedFrameFormat(true); + } + else + { + thisFrame.setFrameId(tokens[4].toUInt(nullptr, 16)); + thisFrame.setExtendedFrameFormat(thisFrame.frameId() > 0x7FF); //some .asc files have extended IDs without 'x' + } - 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(tokens[d].toInt(nullptr, 16)); + int payloadLen = tokens[8].toInt(); + 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[2].toInt(); + if (tokens[5] == "r") thisFrame.setFrameType(QCanBusFrame::RemoteRequestFrame); + for (int d = 9; d < (9 + payloadLen); d++) + { + if (tokens.count() > d) + { + bytes[d - 9] = static_cast(tokens[d].toInt(nullptr, 16)); + } + else //expected byte wasn't there to read. Set it zero and set error flag + { + bytes[d - 9] = 0; + foundErrors = true; + qDebug() << "D:" << d << " Count:" << tokens.count(); + qDebug() << "Expected byte missing! Original line: " << line; + } + } + thisFrame.setPayload(bytes); } - else //expected byte wasn't there to read. Set it zero and set error flag + else { - bytes[d - 6] = 0; - foundErrors = true; - qDebug() << "D:" << d << " Count:" << tokens.count(); - qDebug() << "Expected byte missing! Original line: " << line; + 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(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); } - 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) - // 0 1 2 3 4 5 6 7 8 9- - thisFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, static_cast(tokens[0].toDouble() * 1000000.0))); - if (tokens[4].endsWith('x')) - { - QByteArray copied_id = tokens[4]; - copied_id.chop(1); - thisFrame.setFrameId(copied_id.toUInt(nullptr, 16)); - thisFrame.setExtendedFrameFormat(true); - } - else - { - thisFrame.setFrameId(tokens[4].toUInt(nullptr, 16)); - thisFrame.setExtendedFrameFormat(thisFrame.frameId() > 0x7FF); //some .asc files have extended IDs without 'x' - } - - int payloadLen = tokens[8].toInt(); - 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[2].toInt(); - if (tokens[5] == "r") thisFrame.setFrameType(QCanBusFrame::RemoteRequestFrame); - for (int d = 9; d < (9 + payloadLen); d++) - { - if (tokens.count() > d) - { - bytes[d - 9] = static_cast(tokens[d].toInt(nullptr, 16)); - } - else //expected byte wasn't there to read. Set it zero and set error flag - { - bytes[d - 9] = 0; - foundErrors = true; - qDebug() << "D:" << d << " Count:" << tokens.count(); - qDebug() << "Expected byte missing! Original line: " << line; - } - } - thisFrame.setPayload(bytes); - } - frames->append(thisFrame); } } //else foundErrors = true; @@ -2294,11 +2298,16 @@ bool FrameFileIO::loadGenericCSVFile(QString filename, QVector* frames else thisFrame.setExtendedFrameFormat(false); thisFrame.bus = 0; thisFrame.setFrameType(QCanBusFrame::DataFrame); - QList dataTok = tokens[1].split(' '); - QByteArray bytes(dataTok.length(), 0); - for (int d = 0; d < dataTok.length(); d++) bytes[d] = static_cast(dataTok[d].toInt(nullptr, 16)); - thisFrame.setPayload(bytes); - frames->append(thisFrame); + if (tokens.length() > 1) + { + QList dataTok = tokens[1].split(' '); + int dLen = dataTok.length(); + if (dLen > 8) dLen = 8; + QByteArray bytes(dLen, 0); + for (int d = 0; d < dLen; d++) bytes[d] = static_cast(dataTok[d].toInt(nullptr, 16)); + thisFrame.setPayload(bytes); + frames->append(thisFrame); + } } else foundErrors = true; }