Switched to a safer way to deal with signals in the graphing window.

Previously it was possible to crash the program by graphing with a
signal and then loading a different DBC file. No more will that
happen. Also, there is an error message if you load a graph definition
file that relies on a DBC file that you don't have loaded.
This commit is contained in:
Collin Kidder
2016-01-12 22:35:19 -05:00
parent c8666b4147
commit d831f985f5
3 changed files with 35 additions and 15 deletions
+28 -6
View File
@@ -690,7 +690,7 @@ void GraphingWindow::saveDefinitions()
{
outFile->putChar('S');
outFile->putChar(',');
outFile->write(iter->signal->name.toUtf8());
outFile->write(iter->signal.toUtf8());
outFile->putChar(',');
}
else
@@ -728,6 +728,7 @@ void GraphingWindow::loadDefinitions()
{
QString filename;
QFileDialog dialog;
bool dbcMissing = false;
QStringList filters;
filters.append(QString(tr("Graph definition (*.gdf)")));
@@ -761,9 +762,15 @@ void GraphingWindow::loadDefinitions()
DBC_MESSAGE *msg = dbcHandler->findMsgByID(gp.ID);
if (msg != NULL)
{
gp.signal = dbcHandler->findSignalByName(msg, tokens[2]);
DBC_SIGNAL *sig = dbcHandler->findSignalByName(msg, tokens[2]);
if (sig == NULL) dbcMissing = true;
gp.signal = tokens[2];
}
else
{
gp.signal = "";
dbcMissing = true;
}
else gp.signal = NULL;
}
else
{
@@ -798,6 +805,12 @@ void GraphingWindow::loadDefinitions()
}
}
inFile->close();
if (dbcMissing)
{
QMessageBox msg;
msg.setText("One or more graphs could not be loaded\r\nbecause the signal could not be found.\r\nPerhaps you forgot to load\r\nthe DBC file?");
msg.exec();
}
}
}
@@ -837,8 +850,12 @@ void GraphingWindow::appendToGraph(GraphParams &params, CANFrame &frame)
if (params.isDBCSignal)
{
double tempValue;
DBC_MESSAGE *msg = dbcHandler->findMsgByID(params.ID);
DBC_SIGNAL *sig = NULL;
if (msg) sig = dbcHandler->findSignalByName(msg, params.signal);
if (sig == NULL) return;
//if the given signal was found and successfully processed in this frame then add it to the graph
if (dbcHandler->processSignalDouble(frame, *params.signal, tempValue))
if (dbcHandler->processSignalDouble(frame, *sig, tempValue))
{
//qDebug() << "tempValue: " << tempValue;
if (secondsMode)
@@ -967,10 +984,15 @@ void GraphingWindow::createGraph(GraphParams &params, bool createGraphParam)
float yminval=10000000.0, ymaxval = -1000000.0;
float xminval=10000000000.0, xmaxval = -10000000000.0;
GraphParams *refParam = &params;
DBC_MESSAGE *msg = NULL;
DBC_SIGNAL *sig = NULL;
if (params.isDBCSignal)
{
qDebug() << "New signal graph: " << params.signal->name <<" in ID:" << params.ID;
msg = dbcHandler->findMsgByID(params.ID);
if (msg) sig = dbcHandler->findSignalByName(msg, params.signal);
if (sig == NULL) return;
qDebug() << "New signal graph: " << params.signal <<" in ID:" << params.ID;
}
else
{
@@ -1001,7 +1023,7 @@ void GraphingWindow::createGraph(GraphParams &params, bool createGraphParam)
for (int j = 0; j < numEntries; j++)
{
//if the given signal was found and successfully processed in this frame then add it to the graph
if (dbcHandler->processSignalDouble(frameCache[j], *params.signal, tempValue))
if (dbcHandler->processSignalDouble(frameCache[j], *sig, tempValue))
{
//qDebug() << "tempValue: " << tempValue;
if (secondsMode)
+1 -1
View File
@@ -25,7 +25,7 @@ public:
QCPGraph *ref;
QString graphName;
bool isDBCSignal; //is this graph actually a DBC signal? If so the below pointer should be filled out
DBC_SIGNAL *signal;
QString signal;
//the below stuff is used for internal purposes only - code should be refactored so these can be private
QVector<double> x, y;
double xbias;
+6 -8
View File
@@ -76,8 +76,7 @@ void NewGraphDialog::setParams(GraphParams &params)
}
else
{
setStandardActive(true);
ui->txtID->setText(Utility::formatNumber(params.ID));
setStandardActive(true);
ui->txtBias->setText(QString::number(params.bias));
ui->txtMask->setText(Utility::formatNumber(params.mask));
ui->txtScale->setText(QString::number(params.scale));
@@ -94,6 +93,7 @@ void NewGraphDialog::setParams(GraphParams &params)
}
}
ui->txtID->setText(Utility::formatNumber(params.ID));
ui->txtName->setText(params.graphName);
QPalette p = ui->colorSwatch->palette();
p.setColor(QPalette::Button, params.color);
@@ -108,10 +108,8 @@ void NewGraphDialog::getParams(GraphParams &params)
if (params.isDBCSignal)
{
DBC_MESSAGE *msg = dbcHandler->findMsgByName(ui->cbMessages->currentText());
if (msg != NULL)
params.signal = dbcHandler->findSignalByName(msg, ui->cbSignals->currentText());
params.ID = params.signal->parentMessage->ID;
params.signal = ui->cbSignals->currentText();
params.ID = Utility::ParseStringToNum(ui->txtID->text());
params.bias = 0;
params.isSigned = false;
params.mask = 0;
@@ -127,7 +125,7 @@ void NewGraphDialog::getParams(GraphParams &params)
params.mask = Utility::ParseStringToNum(ui->txtMask->text());
params.scale = ui->txtScale->text().toFloat();
params.stride = Utility::ParseStringToNum(ui->txtStride->text());
params.signal = NULL;
params.signal = "";
QStringList values = ui->txtData->text().split('-');
params.startByte = -1;
@@ -188,7 +186,7 @@ void NewGraphDialog::fillFormFromSignal(int idx)
if (sig == NULL) return;
params.graphName = sig->name;
//params.ID = msg->ID;
params.ID = msg->ID;
//params.bias = sig->bias;
//params.scale = sig->factor;
//params.stride = 1;