Implemented the signal viewer and enabled it in the menu.
This commit is contained in:
+79
-8
@@ -1,14 +1,18 @@
|
||||
#include "signalviewerwindow.h"
|
||||
#include "ui_signalviewerwindow.h"
|
||||
#include "helpwindow.h"
|
||||
#include "mainwindow.h"
|
||||
#include <QDebug>
|
||||
|
||||
SignalViewerWindow::SignalViewerWindow(QWidget *parent) :
|
||||
SignalViewerWindow::SignalViewerWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::SignalViewerWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowFlags(Qt::Window);
|
||||
|
||||
modelFrames = frames;
|
||||
|
||||
QStringList headers;
|
||||
headers << "Signal" << "Value";
|
||||
ui->tableViewer->setHorizontalHeaderLabels(headers);
|
||||
@@ -21,6 +25,8 @@ SignalViewerWindow::SignalViewerWindow(QWidget *parent) :
|
||||
|
||||
connect(ui->cbMessages, SIGNAL(currentIndexChanged(int)), this, SLOT(loadSignals(int)));
|
||||
connect(ui->btnAdd, SIGNAL(clicked(bool)), this, SLOT(addSignal()));
|
||||
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));
|
||||
connect(ui->btnRemove, SIGNAL(clicked(bool)), this, SLOT(removeSelectedSignal()));
|
||||
|
||||
loadMessages();
|
||||
}
|
||||
@@ -30,14 +36,79 @@ SignalViewerWindow::~SignalViewerWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void SignalViewerWindow::updatedFrames(int numFrames)
|
||||
{
|
||||
CANFrame thisFrame;
|
||||
|
||||
if (numFrames == -1) //all frames deleted. Don't care
|
||||
{
|
||||
}
|
||||
else if (numFrames == -2) //all new set of frames. Reset
|
||||
{
|
||||
for (int i = 0; i < modelFrames->count(); i++)
|
||||
{
|
||||
thisFrame = modelFrames->at(i);
|
||||
processFrame(thisFrame);
|
||||
}
|
||||
}
|
||||
else //just got some new frames. See if they are relevant.
|
||||
{
|
||||
if (numFrames > modelFrames->count()) return;
|
||||
|
||||
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++)
|
||||
{
|
||||
thisFrame = modelFrames->at(i);
|
||||
processFrame(thisFrame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SignalViewerWindow::processFrame(CANFrame &frame)
|
||||
{
|
||||
QString sigString;
|
||||
DBC_SIGNAL *sig;
|
||||
for (int i = 0; i < signalList.count(); i++)
|
||||
{
|
||||
sig = signalList.at(i);
|
||||
if (!sig) return;
|
||||
if (sig->parentMessage->ID == frame.ID)
|
||||
{
|
||||
if (sig->processAsText(frame, sigString, false)) //if true we could interpret the signal so update it in the list
|
||||
{
|
||||
QTableWidgetItem *item = ui->tableViewer->item(i, 1);
|
||||
if (!item)
|
||||
{
|
||||
item = new QTableWidgetItem(sigString);
|
||||
ui->tableViewer->setItem(i, 1, item);
|
||||
}
|
||||
else item->setText(sigString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SignalViewerWindow::removeSelectedSignal()
|
||||
{
|
||||
int selRow = ui->tableViewer->currentRow();
|
||||
if (selRow < 0) return; //no selected row
|
||||
signalList.removeAt(selRow);
|
||||
ui->tableViewer->removeRow(selRow);
|
||||
}
|
||||
|
||||
void SignalViewerWindow::loadMessages()
|
||||
{
|
||||
int numFiles;
|
||||
ui->cbMessages->clear();
|
||||
if (dbcHandler == NULL) return;
|
||||
if (dbcHandler->getFileCount() == 0) dbcHandler->createBlankFile();
|
||||
for (int x = 0; x < dbcHandler->getFileByIdx(0)->messageHandler->getCount(); x++)
|
||||
if (dbcHandler == nullptr) return;
|
||||
if ((numFiles = dbcHandler->getFileCount()) == 0) return;
|
||||
qDebug() << numFiles;
|
||||
for (int f = 0; f < numFiles; f++)
|
||||
{
|
||||
ui->cbMessages->addItem(dbcHandler->getFileByIdx(0)->messageHandler->findMsgByIdx(x)->name);
|
||||
qDebug() << dbcHandler->getFileByIdx(f)->messageHandler->getCount();
|
||||
for (int x = 0; x < dbcHandler->getFileByIdx(f)->messageHandler->getCount(); x++)
|
||||
{
|
||||
ui->cbMessages->addItem(dbcHandler->getFileByIdx(f)->messageHandler->findMsgByIdx(x)->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +119,9 @@ void SignalViewerWindow::loadSignals(int idx)
|
||||
//in the data structure so it should have been possible to just
|
||||
//look it up based on index but by name is probably safer and this operation
|
||||
//is not time critical at all.
|
||||
DBC_MESSAGE *msg = dbcHandler->getFileByIdx(0)->messageHandler->findMsgByName(ui->cbMessages->currentText());
|
||||
DBC_MESSAGE *msg = dbcHandler->findMessage(ui->cbMessages->currentText());
|
||||
|
||||
if (msg == NULL) return;
|
||||
if (msg == nullptr) return;
|
||||
ui->cbSignals->clear();
|
||||
for (int x = 0; x < msg->sigHandler->getCount(); x++)
|
||||
{
|
||||
@@ -60,7 +131,7 @@ void SignalViewerWindow::loadSignals(int idx)
|
||||
|
||||
void SignalViewerWindow::addSignal()
|
||||
{
|
||||
DBC_MESSAGE *msg = dbcHandler->getFileByIdx(0)->messageHandler->findMsgByName(ui->cbMessages->currentText());
|
||||
DBC_MESSAGE *msg = dbcHandler->findMessage(ui->cbMessages->currentText());
|
||||
if (!msg) return;
|
||||
DBC_SIGNAL *sig = msg->sigHandler->findSignalByName(ui->cbSignals->currentText());
|
||||
if (!sig) return;
|
||||
|
||||
Reference in New Issue
Block a user