From 11b10b72200885f9dfea3edfe589a66c467713c5 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Tue, 19 Mar 2019 19:56:48 -0400 Subject: [PATCH] Add CANOpen Magic file format for loading --- framefileio.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ framefileio.h | 1 + 2 files changed, 67 insertions(+) diff --git a/framefileio.cpp b/framefileio.cpp index edd32f5..1755c48 100644 --- a/framefileio.cpp +++ b/framefileio.cpp @@ -156,6 +156,7 @@ bool FrameFileIO::loadFrameFile(QString &fileName, QVector* frameCache filters.append(QString(tr("CANalyzer Binary Log Files (*.blf *.BLF)"))); filters.append(QString(tr("CANHacker Trace Files (*.trc *.TRC)"))); filters.append(QString(tr("Cabana Log (*.csv *.CSV)"))); + filters.append(QString(tr("CANOpen Magic (*.csv *.CSV)"))); dialog.setFileMode(QFileDialog::ExistingFile); dialog.setNameFilters(filters); @@ -192,6 +193,7 @@ bool FrameFileIO::loadFrameFile(QString &fileName, QVector* frameCache if (dialog.selectedNameFilter() == filters[14]) result = loadCanalyzerBLF(filename, frameCache); if (dialog.selectedNameFilter() == filters[15]) result = loadCANHackerFile(filename, frameCache); if (dialog.selectedNameFilter() == filters[16]) result = loadCabanaFile(filename, frameCache); + if (dialog.selectedNameFilter() == filters[17]) result = loadCANOpenFile(filename, frameCache); progress.cancel(); @@ -457,6 +459,70 @@ bool FrameFileIO::loadCANHackerFile(QString filename, QVector* frames) return !foundErrors; } + +//"Message Number","Time (ms)","Time","Excel Time","Count","ID","Flags","Message Type","Node","Details","Process Data","Data (Hex)","Data (Text)","Data (Decimal)","Length","Raw Message" +//"0","0.000","8:09:42:48.7953090'",43447.7100146116,"","0x2E1","","Default: PDO","","Default: TPDO 2 of Node 0x61 (97)","","10 21 04 00 00 00 00 00 ",". ! . . . . . . ","U:0 S:0","8","10 21 04 00 00 00 00 00" +bool FrameFileIO::loadCANOpenFile(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; + qDebug() << "Could not open the file!"; + return false; + } + + line = inFile->readLine(); //read out the header first and discard it. + line = inFile->readLine(); + line = inFile->readLine(); + line = inFile->readLine(); + line = inFile->readLine(); + + while (!inFile->atEnd()) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } + + line = inFile->readLine().replace('\"', ' ').simplified(); + if (line.length() > 2) + { + QList tokens = line.split(','); + if (tokens.length() > 11) + { + thisFrame.timestamp = (int64_t)(tokens[1].simplified().toDouble() * 1000.0); + thisFrame.ID = Utility::ParseStringToNum(tokens[5].simplified()); + thisFrame.extended = (thisFrame.ID > 0x7FF); + thisFrame.isReceived = true; + thisFrame.remote = false; + thisFrame.bus = 0; + QList dataTok = tokens[11].simplified().split(' '); + thisFrame.len = dataTok.length(); + for (unsigned int d = 0; d < thisFrame.len; d++) + { + if (dataTok[d] != "") + { + thisFrame.data[d] = dataTok[d].simplified().toInt(NULL, 16); + } + else thisFrame.data[d] = 0; + } + frames->append(thisFrame); + } + else foundErrors = true; + } + } + inFile->close(); + delete inFile; + return !foundErrors; +} + bool FrameFileIO::saveCRTDFile(QString filename, const QVector* frames) { QFile *outFile = new QFile(filename); diff --git a/framefileio.h b/framefileio.h index 2eea45b..820426c 100644 --- a/framefileio.h +++ b/framefileio.h @@ -46,6 +46,7 @@ public: static bool loadCanalyzerBLF(QString, QVector*); static bool loadCANHackerFile(QString filename, QVector* frames); static bool loadCabanaFile(QString filename, QVector* frames); + static bool loadCANOpenFile(QString filename, QVector* frames); static bool saveCRTDFile(QString, const QVector*); static bool saveNativeCSVFile(QString, const QVector*); static bool saveGenericCSVFile(QString, const QVector*);