From 0661427b445cd00d8924022a5ffb9e8a33ba286d Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Tue, 13 Sep 2016 19:58:08 -0400 Subject: [PATCH] Added PCAN files for loading (but not saving) --- framefileio.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ framefileio.h | 1 + 2 files changed, 67 insertions(+) diff --git a/framefileio.cpp b/framefileio.cpp index 2e96149..c279685 100644 --- a/framefileio.cpp +++ b/framefileio.cpp @@ -126,6 +126,7 @@ bool FrameFileIO::loadFrameFile(QString &fileName, QVector* frameCache filters.append(QString(tr("CAN-DO Log (*.avc *.can *.evc *.qcc *.AVC *.CAN *.EVC *.QCC)"))); filters.append(QString(tr("Vehicle Spy (*.csv *.CSV)"))); filters.append(QString(tr("Candump/Kayak (*.log *.LOG)"))); + filters.append(QString(tr("PCAN Viewer (*.txt *.TXT)"))); dialog.setFileMode(QFileDialog::ExistingFile); dialog.setNameFilters(filters); @@ -155,6 +156,7 @@ bool FrameFileIO::loadFrameFile(QString &fileName, QVector* frameCache if (dialog.selectedNameFilter() == filters[7]) result = loadCANDOFile(filename, frameCache); if (dialog.selectedNameFilter() == filters[8]) result = loadVehicleSpyFile(filename, frameCache); if (dialog.selectedNameFilter() == filters[9]) result = loadCanDumpFile(filename, frameCache); + if (dialog.selectedNameFilter() == filters[10]) result = loadPCANFile(filename, frameCache); progress.cancel(); @@ -393,6 +395,70 @@ bool FrameFileIO::saveCRTDFile(QString filename, const QVector* frames return true; } + +//; Message Number +//; | Time Offset (ms) +//; | | Type +//; | | | ID (hex) +//; | | | | Data Length Code +//; | | | | | Data Bytes (hex) ... +//; | | | | | | +//;---+-- ----+---- --+-- ----+--- + -+ -- -- -- -- -- -- -- +// 0-6 10-18 21-25 28-35 38 41-? +//Fixed length lines +bool FrameFileIO::loadPCANFile(QString filename, QVector* frames) +{ + QFile *inFile = new QFile(filename); + CANFrame thisFrame; + QByteArray line; + int lineCounter = 0; + bool foundErrors = false; + + if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text)) + { + delete inFile; + return false; + } + + while (!inFile->atEnd()) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } + line = inFile->readLine(); + if (line.startsWith(';')) continue; + if (line.length() > 2) + { + thisFrame.timestamp = line.mid(10, 8).simplified().toFloat() * 1000ull; + thisFrame.ID = line.mid(28, 8).simplified().toUInt(NULL, 16); + if (thisFrame.ID < 0x1FFFFFFF) + { + thisFrame.len = line.mid(38,1).toInt(); + thisFrame.isReceived = true; + thisFrame.bus = 0; + thisFrame.extended = false; + QList tokens = line.mid(41, thisFrame.len * 3).split(' '); + for (int d = 0; d < thisFrame.len; d++) + { + if (tokens[d] != "") + { + thisFrame.data[d] = tokens[d].toInt(NULL, 16); + } + else thisFrame.data[d] = 0; + } + frames->append(thisFrame); + } + } + //else foundErrors = true; + } + inFile->close(); + delete inFile; + return !foundErrors; +} + + //The "native" file format for this program bool FrameFileIO::loadNativeCSVFile(QString filename, QVector* frames) { diff --git a/framefileio.h b/framefileio.h index 44a648f..13f6e59 100644 --- a/framefileio.h +++ b/framefileio.h @@ -43,6 +43,7 @@ public: static bool loadFrameFile(QString &, QVector*); static bool saveFrameFile(QString &, const QVector*); static bool loadCanDumpFile(QString, QVector*); + static bool loadPCANFile(QString, QVector*); private: static QString unQuote(QString);