Added a bit of error handling to file loading routines. It will now most likely
tell you that you picked the wrong format instead of crashing. Updated version number to match new functionality.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#ifndef CONFIG
|
#ifndef CONFIG
|
||||||
#define CONFIG
|
#define CONFIG
|
||||||
|
|
||||||
#define VERSION 152
|
#define VERSION 154
|
||||||
|
|
||||||
//try to keep this in sync.
|
//try to keep this in sync.
|
||||||
//SavvyCAN will complain if you connect a GVRET board with a revision
|
//SavvyCAN will complain if you connect a GVRET board with a revision
|
||||||
|
|||||||
+216
-141
@@ -1,5 +1,6 @@
|
|||||||
#include "framefileio.h"
|
#include "framefileio.h"
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
|
|
||||||
FrameFileIO::FrameFileIO()
|
FrameFileIO::FrameFileIO()
|
||||||
@@ -159,7 +160,13 @@ bool FrameFileIO::loadFrameFile(QString &fileName, QVector<CANFrame>* frameCache
|
|||||||
fileName = fileList[fileList.length() - 1];
|
fileName = fileList[fileList.length() - 1];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else return false;
|
else
|
||||||
|
{
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setText("File load completed with errors.\r\nPerhaps you selected the wrong file type?");
|
||||||
|
msgBox.exec();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -175,6 +182,7 @@ bool FrameFileIO::loadVehicleSpyFile(QString filename, QVector<CANFrame> *frames
|
|||||||
QByteArray line;
|
QByteArray line;
|
||||||
int lineCounter = 0;
|
int lineCounter = 0;
|
||||||
bool pastHeader = false;
|
bool pastHeader = false;
|
||||||
|
bool foundErrors = false;
|
||||||
|
|
||||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
{
|
{
|
||||||
@@ -189,6 +197,8 @@ bool FrameFileIO::loadVehicleSpyFile(QString filename, QVector<CANFrame> *frames
|
|||||||
if (lineCounter == 2) pastHeader = true;
|
if (lineCounter == 2) pastHeader = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inFile->atEnd()) foundErrors = true;
|
||||||
|
|
||||||
while (!inFile->atEnd()) {
|
while (!inFile->atEnd()) {
|
||||||
lineCounter++;
|
lineCounter++;
|
||||||
if (lineCounter > 100)
|
if (lineCounter > 100)
|
||||||
@@ -199,30 +209,33 @@ bool FrameFileIO::loadVehicleSpyFile(QString filename, QVector<CANFrame> *frames
|
|||||||
line = inFile->readLine().simplified().toUpper();
|
line = inFile->readLine().simplified().toUpper();
|
||||||
|
|
||||||
QList<QByteArray> tokens = line.split(',');
|
QList<QByteArray> tokens = line.split(',');
|
||||||
thisFrame.bus = 0;
|
if (tokens.length() > 20)
|
||||||
thisFrame.timestamp = tokens[1].toDouble() * 1000000.0;
|
|
||||||
if (tokens[5].startsWith("T")) thisFrame.isReceived = false;
|
|
||||||
else thisFrame.isReceived = true;
|
|
||||||
thisFrame.ID = tokens[9].toInt(NULL, 16);
|
|
||||||
if (tokens[11].startsWith("T")) thisFrame.extended = true;
|
|
||||||
else thisFrame.extended = false;
|
|
||||||
|
|
||||||
thisFrame.len = 0;
|
|
||||||
for (int i = 0; i < 8; i++)
|
|
||||||
{
|
{
|
||||||
if (tokens[12 + i].length() > 0)
|
thisFrame.bus = 0;
|
||||||
{
|
thisFrame.timestamp = tokens[1].toDouble() * 1000000.0;
|
||||||
thisFrame.data[i] = tokens[12 + i].toInt(NULL, 16);
|
if (tokens[5].startsWith("T")) thisFrame.isReceived = false;
|
||||||
thisFrame.len++;
|
else thisFrame.isReceived = true;
|
||||||
}
|
thisFrame.ID = tokens[9].toInt(NULL, 16);
|
||||||
else break;
|
if (tokens[11].startsWith("T")) thisFrame.extended = true;
|
||||||
}
|
else thisFrame.extended = false;
|
||||||
|
|
||||||
frames->append(thisFrame);
|
thisFrame.len = 0;
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if (tokens[12 + i].length() > 0)
|
||||||
|
{
|
||||||
|
thisFrame.data[i] = tokens[12 + i].toInt(NULL, 16);
|
||||||
|
thisFrame.len++;
|
||||||
|
}
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
frames->append(thisFrame);
|
||||||
|
}
|
||||||
|
else foundErrors = true;
|
||||||
}
|
}
|
||||||
inFile->close();
|
inFile->close();
|
||||||
delete inFile;
|
delete inFile;
|
||||||
return true;
|
return !foundErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FrameFileIO::saveVehicleSpyFile(QString filename, const QVector<CANFrame> *frames)
|
bool FrameFileIO::saveVehicleSpyFile(QString filename, const QVector<CANFrame> *frames)
|
||||||
@@ -258,6 +271,7 @@ bool FrameFileIO::loadCRTDFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
CANFrame thisFrame;
|
CANFrame thisFrame;
|
||||||
QByteArray line;
|
QByteArray line;
|
||||||
int lineCounter = 0;
|
int lineCounter = 0;
|
||||||
|
bool foundErrors = false;
|
||||||
|
|
||||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
{
|
{
|
||||||
@@ -279,44 +293,48 @@ bool FrameFileIO::loadCRTDFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
{
|
{
|
||||||
QList<QByteArray> tokens = line.split(' ');
|
QList<QByteArray> tokens = line.split(' ');
|
||||||
int multiplier;
|
int multiplier;
|
||||||
int idxOfDecimal = tokens[0].indexOf('.');
|
if (tokens.length() > 3)
|
||||||
if (idxOfDecimal > -1) {
|
|
||||||
//int decimalPlaces = tokens[0].length() - tokens[0].indexOf('.') - 1;
|
|
||||||
//the result of the above is the # of digits after the decimal.
|
|
||||||
//This program deals in microsecond so turn the value into microseconds
|
|
||||||
multiplier = 1000000; //turn the decimal into full microseconds
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
multiplier = 1; //special case. Assume no decimal means microseconds
|
int idxOfDecimal = tokens[0].indexOf('.');
|
||||||
}
|
if (idxOfDecimal > -1) {
|
||||||
//qDebug() << "decimal places " << decimalPlaces;
|
//int decimalPlaces = tokens[0].length() - tokens[0].indexOf('.') - 1;
|
||||||
thisFrame.timestamp = (int64_t)(tokens[0].toDouble() * multiplier);
|
//the result of the above is the # of digits after the decimal.
|
||||||
char firstChar = tokens[1].left(1)[0];
|
//This program deals in microsecond so turn the value into microseconds
|
||||||
if (firstChar == 'R' || firstChar == 'T')
|
multiplier = 1000000; //turn the decimal into full microseconds
|
||||||
{
|
}
|
||||||
thisFrame.ID = tokens[2].toInt(NULL, 16);
|
else
|
||||||
if (tokens[1] == "R29" || tokens[1] == "T29") thisFrame.extended = true;
|
|
||||||
else thisFrame.extended = false;
|
|
||||||
if (firstChar == 'T') thisFrame.isReceived = false;
|
|
||||||
else thisFrame.isReceived = true;
|
|
||||||
thisFrame.bus = 0;
|
|
||||||
thisFrame.len = tokens.length() - 3;
|
|
||||||
for (int d = 0; d < thisFrame.len; d++)
|
|
||||||
{
|
{
|
||||||
if (tokens[d + 3] != "")
|
multiplier = 1; //special case. Assume no decimal means microseconds
|
||||||
|
}
|
||||||
|
//qDebug() << "decimal places " << decimalPlaces;
|
||||||
|
thisFrame.timestamp = (int64_t)(tokens[0].toDouble() * multiplier);
|
||||||
|
char firstChar = tokens[1].left(1)[0];
|
||||||
|
if (firstChar == 'R' || firstChar == 'T')
|
||||||
|
{
|
||||||
|
thisFrame.ID = tokens[2].toInt(NULL, 16);
|
||||||
|
if (tokens[1] == "R29" || tokens[1] == "T29") thisFrame.extended = true;
|
||||||
|
else thisFrame.extended = false;
|
||||||
|
if (firstChar == 'T') thisFrame.isReceived = false;
|
||||||
|
else thisFrame.isReceived = true;
|
||||||
|
thisFrame.bus = 0;
|
||||||
|
thisFrame.len = tokens.length() - 3;
|
||||||
|
for (int d = 0; d < thisFrame.len; d++)
|
||||||
{
|
{
|
||||||
thisFrame.data[d] = tokens[d + 3].toInt(NULL, 16);
|
if (tokens[d + 3] != "")
|
||||||
|
{
|
||||||
|
thisFrame.data[d] = tokens[d + 3].toInt(NULL, 16);
|
||||||
|
}
|
||||||
|
else thisFrame.data[d] = 0;
|
||||||
}
|
}
|
||||||
else thisFrame.data[d] = 0;
|
frames->append(thisFrame);
|
||||||
}
|
}
|
||||||
frames->append(thisFrame);
|
|
||||||
}
|
}
|
||||||
|
else foundErrors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inFile->close();
|
inFile->close();
|
||||||
delete inFile;
|
delete inFile;
|
||||||
return true;
|
return !foundErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FrameFileIO::saveCRTDFile(QString filename, const QVector<CANFrame>* frames)
|
bool FrameFileIO::saveCRTDFile(QString filename, const QVector<CANFrame>* frames)
|
||||||
@@ -380,6 +398,7 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
int fileVersion = 1;
|
int fileVersion = 1;
|
||||||
long long timeStamp = Utility::GetTimeMS();
|
long long timeStamp = Utility::GetTimeMS();
|
||||||
int lineCounter = 0;
|
int lineCounter = 0;
|
||||||
|
bool foundErrors = false;
|
||||||
|
|
||||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
{
|
{
|
||||||
@@ -402,47 +421,52 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
if (line.length() > 2)
|
if (line.length() > 2)
|
||||||
{
|
{
|
||||||
QList<QByteArray> tokens = line.split(',');
|
QList<QByteArray> tokens = line.split(',');
|
||||||
if (tokens[0].length() > 3)
|
if (tokens.length() >= 6)
|
||||||
{
|
{
|
||||||
long long temp = tokens[0].right(10).toLongLong();
|
if (tokens[0].length() > 3)
|
||||||
thisFrame.timestamp = temp;
|
{
|
||||||
}
|
long long temp = tokens[0].right(10).toLongLong();
|
||||||
else
|
thisFrame.timestamp = temp;
|
||||||
{
|
}
|
||||||
timeStamp += 5;
|
else
|
||||||
thisFrame.timestamp = timeStamp;
|
{
|
||||||
}
|
timeStamp += 5;
|
||||||
|
thisFrame.timestamp = timeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
thisFrame.ID = tokens[1].toInt(NULL, 16);
|
thisFrame.ID = tokens[1].toInt(NULL, 16);
|
||||||
if (tokens[2].toUpper().contains("TRUE")) thisFrame.extended = 1;
|
if (tokens[2].toUpper().contains("TRUE")) thisFrame.extended = 1;
|
||||||
else thisFrame.extended = 0;
|
else thisFrame.extended = 0;
|
||||||
|
|
||||||
if (fileVersion == 1)
|
if (fileVersion == 1)
|
||||||
{
|
{
|
||||||
thisFrame.isReceived = true;
|
thisFrame.isReceived = true;
|
||||||
thisFrame.bus = tokens[3].toInt();
|
thisFrame.bus = tokens[3].toInt();
|
||||||
thisFrame.len = tokens[4].toInt();
|
thisFrame.len = tokens[4].toInt();
|
||||||
for (int c = 0; c < 8; c++) thisFrame.data[c] = 0;
|
for (int c = 0; c < 8; c++) thisFrame.data[c] = 0;
|
||||||
for (int d = 0; d < thisFrame.len; d++)
|
for (int d = 0; d < thisFrame.len; d++)
|
||||||
thisFrame.data[d] = tokens[5 + d].toInt(NULL, 16);
|
thisFrame.data[d] = tokens[5 + d].toInt(NULL, 16);
|
||||||
}
|
}
|
||||||
else if (fileVersion == 2)
|
else if (fileVersion == 2)
|
||||||
{
|
{
|
||||||
if (tokens[3].at(0) == 'R') thisFrame.isReceived = true;
|
if (tokens[3].at(0) == 'R') thisFrame.isReceived = true;
|
||||||
else thisFrame.isReceived = false;
|
else thisFrame.isReceived = false;
|
||||||
thisFrame.bus = tokens[4].toInt();
|
thisFrame.bus = tokens[4].toInt();
|
||||||
thisFrame.len = tokens[5].toInt();
|
thisFrame.len = tokens[5].toInt();
|
||||||
for (int c = 0; c < 8; c++) thisFrame.data[c] = 0;
|
if (thisFrame.len + 6 > tokens.length()) thisFrame.len = tokens.length() - 6;
|
||||||
for (int d = 0; d < thisFrame.len; d++)
|
for (int c = 0; c < 8; c++) thisFrame.data[c] = 0;
|
||||||
thisFrame.data[d] = tokens[6 + d].toInt(NULL, 16);
|
for (int d = 0; d < thisFrame.len; d++)
|
||||||
}
|
thisFrame.data[d] = tokens[6 + d].toInt(NULL, 16);
|
||||||
|
}
|
||||||
|
|
||||||
frames->append(thisFrame);
|
frames->append(thisFrame);
|
||||||
|
}
|
||||||
|
else foundErrors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inFile->close();
|
inFile->close();
|
||||||
delete inFile;
|
delete inFile;
|
||||||
return true;
|
return !foundErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FrameFileIO::saveNativeCSVFile(QString filename, const QVector<CANFrame>* frames)
|
bool FrameFileIO::saveNativeCSVFile(QString filename, const QVector<CANFrame>* frames)
|
||||||
@@ -510,6 +534,7 @@ bool FrameFileIO::loadGenericCSVFile(QString filename, QVector<CANFrame>* frames
|
|||||||
QByteArray line;
|
QByteArray line;
|
||||||
long long timeStamp = Utility::GetTimeMS();
|
long long timeStamp = Utility::GetTimeMS();
|
||||||
int lineCounter = 0;
|
int lineCounter = 0;
|
||||||
|
bool foundErrors = false;
|
||||||
|
|
||||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
{
|
{
|
||||||
@@ -545,10 +570,11 @@ bool FrameFileIO::loadGenericCSVFile(QString filename, QVector<CANFrame>* frames
|
|||||||
|
|
||||||
frames->append(thisFrame);
|
frames->append(thisFrame);
|
||||||
}
|
}
|
||||||
|
else foundErrors = true;
|
||||||
}
|
}
|
||||||
inFile->close();
|
inFile->close();
|
||||||
delete inFile;
|
delete inFile;
|
||||||
return true;
|
return !foundErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
//4f5,ff 34 23 45 24 e4
|
//4f5,ff 34 23 45 24 e4
|
||||||
@@ -631,6 +657,7 @@ bool FrameFileIO::loadLogFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
QByteArray line;
|
QByteArray line;
|
||||||
uint64_t timeStamp = Utility::GetTimeMS();
|
uint64_t timeStamp = Utility::GetTimeMS();
|
||||||
int lineCounter = 0;
|
int lineCounter = 0;
|
||||||
|
bool foundErrors = false;
|
||||||
|
|
||||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
{
|
{
|
||||||
@@ -653,24 +680,30 @@ bool FrameFileIO::loadLogFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
if (line.length() > 1)
|
if (line.length() > 1)
|
||||||
{
|
{
|
||||||
QList<QByteArray> tokens = line.split(' ');
|
QList<QByteArray> tokens = line.split(' ');
|
||||||
QList<QByteArray> timeToks = tokens[0].split(':');
|
if (tokens.length() >= 6)
|
||||||
timeStamp = (timeToks[0].toInt() * (1000ul * 1000ul * 60ul * 60ul)) + (timeToks[1].toInt() * (1000ul * 1000ul * 60ul))
|
{
|
||||||
|
QList<QByteArray> timeToks = tokens[0].split(':');
|
||||||
|
timeStamp = (timeToks[0].toInt() * (1000ul * 1000ul * 60ul * 60ul)) + (timeToks[1].toInt() * (1000ul * 1000ul * 60ul))
|
||||||
+ (timeToks[2].toInt() * (1000ul * 1000ul)) + (timeToks[3].toInt() * 100ul);
|
+ (timeToks[2].toInt() * (1000ul * 1000ul)) + (timeToks[3].toInt() * 100ul);
|
||||||
thisFrame.timestamp = timeStamp;
|
thisFrame.timestamp = timeStamp;
|
||||||
if (tokens[1].at(0) == 'R') thisFrame.isReceived = true;
|
if (tokens[1].at(0) == 'R') thisFrame.isReceived = true;
|
||||||
else thisFrame.isReceived = false;
|
else thisFrame.isReceived = false;
|
||||||
thisFrame.ID = tokens[3].right(tokens[3].length() - 2).toInt(NULL, 16);
|
thisFrame.ID = tokens[3].right(tokens[3].length() - 2).toInt(NULL, 16);
|
||||||
if (tokens[4] == "s") thisFrame.extended = false;
|
if (tokens[4] == "s") thisFrame.extended = false;
|
||||||
else thisFrame.extended = true;
|
else thisFrame.extended = true;
|
||||||
thisFrame.bus = tokens[2].toInt() - 1;
|
thisFrame.bus = tokens[2].toInt() - 1;
|
||||||
thisFrame.len = tokens[5].toInt();
|
thisFrame.len = tokens[5].toInt();
|
||||||
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = tokens[d + 6].toInt(NULL, 16);
|
if (thisFrame.len > 8) thisFrame.len = 8;
|
||||||
|
if (thisFrame.len < 0) thisFrame.len = 0;
|
||||||
|
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = tokens[d + 6].toInt(NULL, 16);
|
||||||
|
frames->append(thisFrame);
|
||||||
|
}
|
||||||
|
else foundErrors = true;
|
||||||
}
|
}
|
||||||
frames->append(thisFrame);
|
|
||||||
}
|
}
|
||||||
inFile->close();
|
inFile->close();
|
||||||
delete inFile;
|
delete inFile;
|
||||||
return true;
|
return !foundErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FrameFileIO::saveLogFile(QString filename, const QVector<CANFrame>* frames)
|
bool FrameFileIO::saveLogFile(QString filename, const QVector<CANFrame>* frames)
|
||||||
@@ -744,6 +777,7 @@ bool FrameFileIO::loadIXXATFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
QByteArray line;
|
QByteArray line;
|
||||||
uint64_t timeStamp = Utility::GetTimeMS();
|
uint64_t timeStamp = Utility::GetTimeMS();
|
||||||
int lineCounter = 0;
|
int lineCounter = 0;
|
||||||
|
bool foundErrors = false;
|
||||||
|
|
||||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
{
|
{
|
||||||
@@ -765,27 +799,48 @@ bool FrameFileIO::loadIXXATFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
if (line.length() > 1)
|
if (line.length() > 1)
|
||||||
{
|
{
|
||||||
QList<QByteArray> tokens = line.split(',');
|
QList<QByteArray> tokens = line.split(',');
|
||||||
QString timePortion = unQuote(tokens[0]);
|
if (line.length() >= 5)
|
||||||
QStringList timeToks = timePortion.split(':');
|
{
|
||||||
timeStamp = (timeToks[0].toInt() * (1000ul * 1000ul * 60ul * 60ul)) + (timeToks[1].toInt() * (1000ul * 1000ul * 60ul))
|
QString timePortion = unQuote(tokens[0]);
|
||||||
|
QStringList timeToks = timePortion.split(':');
|
||||||
|
if (timeToks.length() >= 3)
|
||||||
|
{
|
||||||
|
timeStamp = (timeToks[0].toInt() * (1000ul * 1000ul * 60ul * 60ul)) + (timeToks[1].toInt() * (1000ul * 1000ul * 60ul))
|
||||||
+ (timeToks[2].toDouble() * (1000.0 * 1000.0));
|
+ (timeToks[2].toDouble() * (1000.0 * 1000.0));
|
||||||
thisFrame.timestamp = timeStamp;
|
}
|
||||||
thisFrame.ID = unQuote(tokens[1]).toInt(NULL, 16);
|
else
|
||||||
if (unQuote(tokens[2]).toUpper().at(0) == 'S') thisFrame.extended = false;
|
{
|
||||||
else thisFrame.extended = true;
|
timeStamp = 0;
|
||||||
|
foundErrors = true;
|
||||||
|
}
|
||||||
|
thisFrame.timestamp = timeStamp;
|
||||||
|
thisFrame.ID = unQuote(tokens[1]).toInt(NULL, 16);
|
||||||
|
QString tempStr = unQuote(tokens[2]).toUpper();
|
||||||
|
if (tempStr.length() > 0)
|
||||||
|
{
|
||||||
|
if (tempStr.at(0) == 'S') thisFrame.extended = false;
|
||||||
|
else thisFrame.extended = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
thisFrame.extended = false;
|
||||||
|
foundErrors = true;
|
||||||
|
}
|
||||||
|
|
||||||
thisFrame.isReceived = true;
|
thisFrame.isReceived = true;
|
||||||
thisFrame.bus = 0;
|
thisFrame.bus = 0;
|
||||||
|
|
||||||
QStringList dataToks = unQuote(tokens[4]).simplified().split(' ');
|
QStringList dataToks = unQuote(tokens[4]).simplified().split(' ');
|
||||||
thisFrame.len = dataToks.length();
|
thisFrame.len = dataToks.length();
|
||||||
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = dataToks[d].toInt(NULL, 16);
|
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = dataToks[d].toInt(NULL, 16);
|
||||||
|
frames->append(thisFrame);
|
||||||
|
}
|
||||||
|
else foundErrors = true;
|
||||||
}
|
}
|
||||||
frames->append(thisFrame);
|
|
||||||
}
|
}
|
||||||
inFile->close();
|
inFile->close();
|
||||||
delete inFile;
|
delete inFile;
|
||||||
return true;
|
return !foundErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FrameFileIO::saveIXXATFile(QString filename, const QVector<CANFrame>* frames)
|
bool FrameFileIO::saveIXXATFile(QString filename, const QVector<CANFrame>* frames)
|
||||||
@@ -852,6 +907,7 @@ bool FrameFileIO::loadCANDOFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
QByteArray data;
|
QByteArray data;
|
||||||
int timeOffset = 0;
|
int timeOffset = 0;
|
||||||
uint64_t lastTimeStamp = 0;
|
uint64_t lastTimeStamp = 0;
|
||||||
|
bool foundErrors = false;
|
||||||
|
|
||||||
if (!inFile->open(QIODevice::ReadOnly))
|
if (!inFile->open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
@@ -887,7 +943,7 @@ bool FrameFileIO::loadCANDOFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
timeOffset += 60000000ul;
|
timeOffset += 60000000ul;
|
||||||
}
|
}
|
||||||
lastTimeStamp = thisFrame.timestamp;
|
lastTimeStamp = thisFrame.timestamp;
|
||||||
thisFrame.ID = ((unsigned char)data[3] * 256 + (unsigned char)data[2]) & 0x7FF;
|
thisFrame.ID = (((unsigned char)data[3] & 0x0F) * 256 + (unsigned char)data[2]) & 0x7FF;
|
||||||
thisFrame.len = (unsigned char)data[3] >> 4;
|
thisFrame.len = (unsigned char)data[3] >> 4;
|
||||||
|
|
||||||
if (thisFrame.len <= 8 && thisFrame.ID <= 0x7FF)
|
if (thisFrame.len <= 8 && thisFrame.ID <= 0x7FF)
|
||||||
@@ -895,11 +951,12 @@ bool FrameFileIO::loadCANDOFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)data[4 + d];
|
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)data[4 + d];
|
||||||
frames->append(thisFrame);
|
frames->append(thisFrame);
|
||||||
}
|
}
|
||||||
|
else foundErrors = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inFile->close();
|
inFile->close();
|
||||||
delete inFile;
|
delete inFile;
|
||||||
return true;
|
return !foundErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FrameFileIO::saveCANDOFile(QString filename, const QVector<CANFrame>* frames)
|
bool FrameFileIO::saveCANDOFile(QString filename, const QVector<CANFrame>* frames)
|
||||||
@@ -973,6 +1030,7 @@ bool FrameFileIO::loadMicrochipFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
bool inComment = false;
|
bool inComment = false;
|
||||||
long long timeStamp;
|
long long timeStamp;
|
||||||
int lineCounter = 0;
|
int lineCounter = 0;
|
||||||
|
bool foundErrors = false;
|
||||||
|
|
||||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
{
|
{
|
||||||
@@ -1002,24 +1060,31 @@ bool FrameFileIO::loadMicrochipFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
if (!inComment)
|
if (!inComment)
|
||||||
{
|
{
|
||||||
QList<QByteArray> tokens = line.split(';');
|
QList<QByteArray> tokens = line.split(';');
|
||||||
timeStamp = tokens[0].toInt() * 1000;
|
if (tokens.length() >= 4)
|
||||||
thisFrame.timestamp = timeStamp;
|
{
|
||||||
if (tokens[1].at(0) == 'R') thisFrame.isReceived = true;
|
timeStamp = tokens[0].toInt() * 1000;
|
||||||
else thisFrame.isReceived = false;
|
thisFrame.timestamp = timeStamp;
|
||||||
thisFrame.ID = Utility::ParseStringToNum(tokens[2]);
|
if (tokens[1].at(0) == 'R') thisFrame.isReceived = true;
|
||||||
if (thisFrame.ID <= 0x7FF) thisFrame.extended = false;
|
else thisFrame.isReceived = false;
|
||||||
else thisFrame.extended = true;
|
thisFrame.ID = Utility::ParseStringToNum(tokens[2]);
|
||||||
thisFrame.bus = 0;
|
if (thisFrame.ID <= 0x7FF) thisFrame.extended = false;
|
||||||
thisFrame.len = tokens[3].toInt();
|
else thisFrame.extended = true;
|
||||||
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)Utility::ParseStringToNum(tokens[4 + d]);
|
thisFrame.bus = 0;
|
||||||
frames->append(thisFrame);
|
thisFrame.len = tokens[3].toInt();
|
||||||
|
if (thisFrame.len > 8) thisFrame.len = 8;
|
||||||
|
if (thisFrame.len < 0) thisFrame.len = 0;
|
||||||
|
if (thisFrame.len + 4 > tokens.length()) thisFrame.len = tokens.length() - 4;
|
||||||
|
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)Utility::ParseStringToNum(tokens[4 + d]);
|
||||||
|
frames->append(thisFrame);
|
||||||
|
}
|
||||||
|
else foundErrors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inFile->close();
|
inFile->close();
|
||||||
delete inFile;
|
delete inFile;
|
||||||
return true;
|
return !foundErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1122,6 +1187,7 @@ bool FrameFileIO::loadTraceFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
QByteArray line;
|
QByteArray line;
|
||||||
long long timeStamp = 0;
|
long long timeStamp = 0;
|
||||||
int lineCounter = 0;
|
int lineCounter = 0;
|
||||||
|
bool foundErrors = false;
|
||||||
|
|
||||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
{
|
{
|
||||||
@@ -1148,31 +1214,36 @@ bool FrameFileIO::loadTraceFile(QString filename, QVector<CANFrame>* frames)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
QList<QByteArray> tokens = line.split('\t');
|
QList<QByteArray> tokens = line.split('\t');
|
||||||
|
if (tokens.length() > 3)
|
||||||
|
{
|
||||||
|
QList<QByteArray> timestampToks = tokens[1].split(':');
|
||||||
|
|
||||||
QList<QByteArray> timestampToks = tokens[1].split(':');
|
timeStamp = timestampToks[0].toInt() * 1000000ul * 60 * 60;
|
||||||
|
timeStamp += timestampToks[1].toInt() * 1000000ul * 60;
|
||||||
|
timeStamp += timestampToks[2].toInt() * 1000000ul;
|
||||||
|
timeStamp += timestampToks[3].toInt() * 100;
|
||||||
|
|
||||||
timeStamp = timestampToks[0].toInt() * 1000000ul * 60 * 60;
|
thisFrame.timestamp = timeStamp;
|
||||||
timeStamp += timestampToks[1].toInt() * 1000000ul * 60;
|
|
||||||
timeStamp += timestampToks[2].toInt() * 1000000ul;
|
|
||||||
timeStamp += timestampToks[3].toInt() * 100;
|
|
||||||
|
|
||||||
thisFrame.timestamp = timeStamp;
|
thisFrame.ID = tokens[2].toLong(NULL, 16);
|
||||||
|
if (thisFrame.ID <= 0x7FF) thisFrame.extended = false;
|
||||||
thisFrame.ID = tokens[2].toLong(NULL, 16);
|
else thisFrame.extended = true;
|
||||||
if (thisFrame.ID <= 0x7FF) thisFrame.extended = false;
|
thisFrame.bus = 0;
|
||||||
else thisFrame.extended = true;
|
thisFrame.len = tokens[3].toInt();
|
||||||
thisFrame.bus = 0;
|
if (thisFrame.len < 0) thisFrame.len = 0;
|
||||||
thisFrame.len = tokens[3].toInt();
|
if (thisFrame.len > 8) thisFrame.len = 8;
|
||||||
|
QList<QByteArray> dataToks = tokens[4].split(' ');
|
||||||
QList<QByteArray> dataToks = tokens[4].split(' ');
|
if (thisFrame.len > dataToks.length()) thisFrame.len = dataToks.length();
|
||||||
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)dataToks[d].toInt(NULL, 16);
|
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)dataToks[d].toInt(NULL, 16);
|
||||||
frames->append(thisFrame);
|
frames->append(thisFrame);
|
||||||
|
}
|
||||||
|
else foundErrors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inFile->close();
|
inFile->close();
|
||||||
delete inFile;
|
delete inFile;
|
||||||
return true;
|
return !foundErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FrameFileIO::saveTraceFile(QString filename, const QVector<CANFrame> * frames)
|
bool FrameFileIO::saveTraceFile(QString filename, const QVector<CANFrame> * frames)
|
||||||
@@ -1266,5 +1337,9 @@ bool FrameFileIO::saveTraceFile(QString filename, const QVector<CANFrame> * fram
|
|||||||
|
|
||||||
QString FrameFileIO::unQuote(QString inStr)
|
QString FrameFileIO::unQuote(QString inStr)
|
||||||
{
|
{
|
||||||
return inStr.split('\"')[1];
|
QStringList temp;
|
||||||
|
temp = inStr.split('\"');
|
||||||
|
if (temp.length() >= 3)
|
||||||
|
return temp[1];
|
||||||
|
return QString("");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user