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
|
||||
#define CONFIG
|
||||
|
||||
#define VERSION 152
|
||||
#define VERSION 154
|
||||
|
||||
//try to keep this in sync.
|
||||
//SavvyCAN will complain if you connect a GVRET board with a revision
|
||||
|
||||
+93
-18
@@ -1,5 +1,6 @@
|
||||
#include "framefileio.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QProgressDialog>
|
||||
|
||||
FrameFileIO::FrameFileIO()
|
||||
@@ -159,7 +160,13 @@ bool FrameFileIO::loadFrameFile(QString &fileName, QVector<CANFrame>* frameCache
|
||||
fileName = fileList[fileList.length() - 1];
|
||||
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;
|
||||
}
|
||||
@@ -175,6 +182,7 @@ bool FrameFileIO::loadVehicleSpyFile(QString filename, QVector<CANFrame> *frames
|
||||
QByteArray line;
|
||||
int lineCounter = 0;
|
||||
bool pastHeader = false;
|
||||
bool foundErrors = false;
|
||||
|
||||
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 (inFile->atEnd()) foundErrors = true;
|
||||
|
||||
while (!inFile->atEnd()) {
|
||||
lineCounter++;
|
||||
if (lineCounter > 100)
|
||||
@@ -199,6 +209,8 @@ bool FrameFileIO::loadVehicleSpyFile(QString filename, QVector<CANFrame> *frames
|
||||
line = inFile->readLine().simplified().toUpper();
|
||||
|
||||
QList<QByteArray> tokens = line.split(',');
|
||||
if (tokens.length() > 20)
|
||||
{
|
||||
thisFrame.bus = 0;
|
||||
thisFrame.timestamp = tokens[1].toDouble() * 1000000.0;
|
||||
if (tokens[5].startsWith("T")) thisFrame.isReceived = false;
|
||||
@@ -217,12 +229,13 @@ bool FrameFileIO::loadVehicleSpyFile(QString filename, QVector<CANFrame> *frames
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
frames->append(thisFrame);
|
||||
}
|
||||
else foundErrors = true;
|
||||
}
|
||||
inFile->close();
|
||||
delete inFile;
|
||||
return true;
|
||||
return !foundErrors;
|
||||
}
|
||||
|
||||
bool FrameFileIO::saveVehicleSpyFile(QString filename, const QVector<CANFrame> *frames)
|
||||
@@ -258,6 +271,7 @@ bool FrameFileIO::loadCRTDFile(QString filename, QVector<CANFrame>* frames)
|
||||
CANFrame thisFrame;
|
||||
QByteArray line;
|
||||
int lineCounter = 0;
|
||||
bool foundErrors = false;
|
||||
|
||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
@@ -279,6 +293,8 @@ bool FrameFileIO::loadCRTDFile(QString filename, QVector<CANFrame>* frames)
|
||||
{
|
||||
QList<QByteArray> tokens = line.split(' ');
|
||||
int multiplier;
|
||||
if (tokens.length() > 3)
|
||||
{
|
||||
int idxOfDecimal = tokens[0].indexOf('.');
|
||||
if (idxOfDecimal > -1) {
|
||||
//int decimalPlaces = tokens[0].length() - tokens[0].indexOf('.') - 1;
|
||||
@@ -313,10 +329,12 @@ bool FrameFileIO::loadCRTDFile(QString filename, QVector<CANFrame>* frames)
|
||||
frames->append(thisFrame);
|
||||
}
|
||||
}
|
||||
else foundErrors = true;
|
||||
}
|
||||
}
|
||||
inFile->close();
|
||||
delete inFile;
|
||||
return true;
|
||||
return !foundErrors;
|
||||
}
|
||||
|
||||
bool FrameFileIO::saveCRTDFile(QString filename, const QVector<CANFrame>* frames)
|
||||
@@ -380,6 +398,7 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector<CANFrame>* frames)
|
||||
int fileVersion = 1;
|
||||
long long timeStamp = Utility::GetTimeMS();
|
||||
int lineCounter = 0;
|
||||
bool foundErrors = false;
|
||||
|
||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
@@ -402,6 +421,8 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector<CANFrame>* frames)
|
||||
if (line.length() > 2)
|
||||
{
|
||||
QList<QByteArray> tokens = line.split(',');
|
||||
if (tokens.length() >= 6)
|
||||
{
|
||||
if (tokens[0].length() > 3)
|
||||
{
|
||||
long long temp = tokens[0].right(10).toLongLong();
|
||||
@@ -432,6 +453,7 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector<CANFrame>* frames)
|
||||
else thisFrame.isReceived = false;
|
||||
thisFrame.bus = tokens[4].toInt();
|
||||
thisFrame.len = tokens[5].toInt();
|
||||
if (thisFrame.len + 6 > tokens.length()) thisFrame.len = tokens.length() - 6;
|
||||
for (int c = 0; c < 8; c++) thisFrame.data[c] = 0;
|
||||
for (int d = 0; d < thisFrame.len; d++)
|
||||
thisFrame.data[d] = tokens[6 + d].toInt(NULL, 16);
|
||||
@@ -439,10 +461,12 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector<CANFrame>* frames)
|
||||
|
||||
frames->append(thisFrame);
|
||||
}
|
||||
else foundErrors = true;
|
||||
}
|
||||
}
|
||||
inFile->close();
|
||||
delete inFile;
|
||||
return true;
|
||||
return !foundErrors;
|
||||
}
|
||||
|
||||
bool FrameFileIO::saveNativeCSVFile(QString filename, const QVector<CANFrame>* frames)
|
||||
@@ -510,6 +534,7 @@ bool FrameFileIO::loadGenericCSVFile(QString filename, QVector<CANFrame>* frames
|
||||
QByteArray line;
|
||||
long long timeStamp = Utility::GetTimeMS();
|
||||
int lineCounter = 0;
|
||||
bool foundErrors = false;
|
||||
|
||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
@@ -545,10 +570,11 @@ bool FrameFileIO::loadGenericCSVFile(QString filename, QVector<CANFrame>* frames
|
||||
|
||||
frames->append(thisFrame);
|
||||
}
|
||||
else foundErrors = true;
|
||||
}
|
||||
inFile->close();
|
||||
delete inFile;
|
||||
return true;
|
||||
return !foundErrors;
|
||||
}
|
||||
|
||||
//4f5,ff 34 23 45 24 e4
|
||||
@@ -631,6 +657,7 @@ bool FrameFileIO::loadLogFile(QString filename, QVector<CANFrame>* frames)
|
||||
QByteArray line;
|
||||
uint64_t timeStamp = Utility::GetTimeMS();
|
||||
int lineCounter = 0;
|
||||
bool foundErrors = false;
|
||||
|
||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
@@ -653,6 +680,8 @@ bool FrameFileIO::loadLogFile(QString filename, QVector<CANFrame>* frames)
|
||||
if (line.length() > 1)
|
||||
{
|
||||
QList<QByteArray> tokens = line.split(' ');
|
||||
if (tokens.length() >= 6)
|
||||
{
|
||||
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);
|
||||
@@ -664,13 +693,17 @@ bool FrameFileIO::loadLogFile(QString filename, QVector<CANFrame>* frames)
|
||||
else thisFrame.extended = true;
|
||||
thisFrame.bus = tokens[2].toInt() - 1;
|
||||
thisFrame.len = tokens[5].toInt();
|
||||
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;
|
||||
}
|
||||
}
|
||||
inFile->close();
|
||||
delete inFile;
|
||||
return true;
|
||||
return !foundErrors;
|
||||
}
|
||||
|
||||
bool FrameFileIO::saveLogFile(QString filename, const QVector<CANFrame>* frames)
|
||||
@@ -744,6 +777,7 @@ bool FrameFileIO::loadIXXATFile(QString filename, QVector<CANFrame>* frames)
|
||||
QByteArray line;
|
||||
uint64_t timeStamp = Utility::GetTimeMS();
|
||||
int lineCounter = 0;
|
||||
bool foundErrors = false;
|
||||
|
||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
@@ -765,14 +799,33 @@ bool FrameFileIO::loadIXXATFile(QString filename, QVector<CANFrame>* frames)
|
||||
if (line.length() > 1)
|
||||
{
|
||||
QList<QByteArray> tokens = line.split(',');
|
||||
if (line.length() >= 5)
|
||||
{
|
||||
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));
|
||||
}
|
||||
else
|
||||
{
|
||||
timeStamp = 0;
|
||||
foundErrors = true;
|
||||
}
|
||||
thisFrame.timestamp = timeStamp;
|
||||
thisFrame.ID = unQuote(tokens[1]).toInt(NULL, 16);
|
||||
if (unQuote(tokens[2]).toUpper().at(0) == 'S') thisFrame.extended = false;
|
||||
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.bus = 0;
|
||||
@@ -780,12 +833,14 @@ bool FrameFileIO::loadIXXATFile(QString filename, QVector<CANFrame>* frames)
|
||||
QStringList dataToks = unQuote(tokens[4]).simplified().split(' ');
|
||||
thisFrame.len = dataToks.length();
|
||||
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = dataToks[d].toInt(NULL, 16);
|
||||
}
|
||||
frames->append(thisFrame);
|
||||
}
|
||||
else foundErrors = true;
|
||||
}
|
||||
}
|
||||
inFile->close();
|
||||
delete inFile;
|
||||
return true;
|
||||
return !foundErrors;
|
||||
}
|
||||
|
||||
bool FrameFileIO::saveIXXATFile(QString filename, const QVector<CANFrame>* frames)
|
||||
@@ -852,6 +907,7 @@ bool FrameFileIO::loadCANDOFile(QString filename, QVector<CANFrame>* frames)
|
||||
QByteArray data;
|
||||
int timeOffset = 0;
|
||||
uint64_t lastTimeStamp = 0;
|
||||
bool foundErrors = false;
|
||||
|
||||
if (!inFile->open(QIODevice::ReadOnly))
|
||||
{
|
||||
@@ -887,7 +943,7 @@ bool FrameFileIO::loadCANDOFile(QString filename, QVector<CANFrame>* frames)
|
||||
timeOffset += 60000000ul;
|
||||
}
|
||||
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;
|
||||
|
||||
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];
|
||||
frames->append(thisFrame);
|
||||
}
|
||||
else foundErrors = true;
|
||||
}
|
||||
|
||||
inFile->close();
|
||||
delete inFile;
|
||||
return true;
|
||||
return !foundErrors;
|
||||
}
|
||||
|
||||
bool FrameFileIO::saveCANDOFile(QString filename, const QVector<CANFrame>* frames)
|
||||
@@ -973,6 +1030,7 @@ bool FrameFileIO::loadMicrochipFile(QString filename, QVector<CANFrame>* frames)
|
||||
bool inComment = false;
|
||||
long long timeStamp;
|
||||
int lineCounter = 0;
|
||||
bool foundErrors = false;
|
||||
|
||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
@@ -1002,6 +1060,8 @@ bool FrameFileIO::loadMicrochipFile(QString filename, QVector<CANFrame>* frames)
|
||||
if (!inComment)
|
||||
{
|
||||
QList<QByteArray> tokens = line.split(';');
|
||||
if (tokens.length() >= 4)
|
||||
{
|
||||
timeStamp = tokens[0].toInt() * 1000;
|
||||
thisFrame.timestamp = timeStamp;
|
||||
if (tokens[1].at(0) == 'R') thisFrame.isReceived = true;
|
||||
@@ -1011,15 +1071,20 @@ bool FrameFileIO::loadMicrochipFile(QString filename, QVector<CANFrame>* frames)
|
||||
else thisFrame.extended = true;
|
||||
thisFrame.bus = 0;
|
||||
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();
|
||||
delete inFile;
|
||||
return true;
|
||||
return !foundErrors;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1122,6 +1187,7 @@ bool FrameFileIO::loadTraceFile(QString filename, QVector<CANFrame>* frames)
|
||||
QByteArray line;
|
||||
long long timeStamp = 0;
|
||||
int lineCounter = 0;
|
||||
bool foundErrors = false;
|
||||
|
||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
@@ -1148,7 +1214,8 @@ bool FrameFileIO::loadTraceFile(QString filename, QVector<CANFrame>* frames)
|
||||
else
|
||||
{
|
||||
QList<QByteArray> tokens = line.split('\t');
|
||||
|
||||
if (tokens.length() > 3)
|
||||
{
|
||||
QList<QByteArray> timestampToks = tokens[1].split(':');
|
||||
|
||||
timeStamp = timestampToks[0].toInt() * 1000000ul * 60 * 60;
|
||||
@@ -1163,16 +1230,20 @@ bool FrameFileIO::loadTraceFile(QString filename, QVector<CANFrame>* frames)
|
||||
else thisFrame.extended = true;
|
||||
thisFrame.bus = 0;
|
||||
thisFrame.len = tokens[3].toInt();
|
||||
|
||||
if (thisFrame.len < 0) thisFrame.len = 0;
|
||||
if (thisFrame.len > 8) thisFrame.len = 8;
|
||||
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);
|
||||
frames->append(thisFrame);
|
||||
}
|
||||
else foundErrors = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
inFile->close();
|
||||
delete inFile;
|
||||
return true;
|
||||
return !foundErrors;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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