Implemented the signal viewer and enabled it in the menu.
This commit is contained in:
+4
-4
@@ -36,7 +36,7 @@ s 5 47 46 45 44 43 42 41 40
|
||||
So, the bits are 12, 11, 10, 9, 8, 23, 22, 21. Yes, that's confusing. They now go in reverse value order too.
|
||||
Bit 12 is worth 128, 11 is worth 64, etc until bit 21 is worth 1.
|
||||
*/
|
||||
bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString)
|
||||
bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool outputName)
|
||||
{
|
||||
int64_t result = 0;
|
||||
bool isSigned = false;
|
||||
@@ -95,16 +95,16 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString)
|
||||
endResult = (*((double *)(&result)) * factor) + bias;
|
||||
}
|
||||
|
||||
outString = makePrettyOutput(endResult, result);
|
||||
outString = makePrettyOutput(endResult, result, outputName);
|
||||
cachedValue = endResult;
|
||||
return true;
|
||||
}
|
||||
|
||||
QString DBC_SIGNAL::makePrettyOutput(double floatVal, int64_t intVal)
|
||||
QString DBC_SIGNAL::makePrettyOutput(double floatVal, int64_t intVal, bool outputName)
|
||||
{
|
||||
QString outputString;
|
||||
|
||||
outputString = name + ": ";
|
||||
if (outputName) outputString = name + ": ";
|
||||
|
||||
if (valList.count() > 0) //if this is a value list type then look it up and display the proper string
|
||||
{
|
||||
|
||||
+2
-2
@@ -101,10 +101,10 @@ public: //TODO: this is sloppy. It shouldn't all be public!
|
||||
QList<DBC_ATTRIBUTE_VALUE> attributes;
|
||||
QList<DBC_VAL_ENUM_ENTRY> valList;
|
||||
|
||||
bool processAsText(const CANFrame &frame, QString &outString);
|
||||
bool processAsText(const CANFrame &frame, QString &outString, bool outputName = true);
|
||||
bool processAsInt(const CANFrame &frame, int32_t &outValue);
|
||||
bool processAsDouble(const CANFrame &frame, double &outValue);
|
||||
QString makePrettyOutput(double floatVal, int64_t intVal);
|
||||
QString makePrettyOutput(double floatVal, int64_t intVal, bool outputName = true);
|
||||
DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name);
|
||||
DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
|
||||
};
|
||||
|
||||
+5
-2
@@ -186,7 +186,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
//so if you want to enable them and play with them then go for it.
|
||||
ui->actionFirmware_Update->setVisible(false);
|
||||
ui->actionMotorControlConfig->setVisible(false);
|
||||
ui->actionSignal_Viewer->setVisible(false);
|
||||
//ui->actionSignal_Viewer->setVisible(false);
|
||||
ui->actionSingle_Multi_State_2->setVisible(false);
|
||||
|
||||
installEventFilter(this);
|
||||
@@ -1015,7 +1015,10 @@ void MainWindow::showSignalViewer()
|
||||
{
|
||||
if (!signalViewerWindow)
|
||||
{
|
||||
signalViewerWindow = new SignalViewerWindow();
|
||||
if (!useFiltered)
|
||||
signalViewerWindow = new SignalViewerWindow(model->getListReference());
|
||||
else
|
||||
signalViewerWindow = new SignalViewerWindow(model->getFilteredListReference());
|
||||
}
|
||||
signalViewerWindow->show();
|
||||
}
|
||||
|
||||
+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;
|
||||
|
||||
@@ -13,19 +13,24 @@ class SignalViewerWindow : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SignalViewerWindow(QWidget *parent = 0);
|
||||
explicit SignalViewerWindow(const QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||
~SignalViewerWindow();
|
||||
|
||||
private slots:
|
||||
void loadMessages();
|
||||
void loadSignals(int idx);
|
||||
void addSignal();
|
||||
void removeSelectedSignal();
|
||||
void updatedFrames(int);
|
||||
|
||||
private:
|
||||
Ui::SignalViewerWindow *ui;
|
||||
DBCHandler *dbcHandler;
|
||||
|
||||
QList<DBC_SIGNAL *> signalList;
|
||||
const QVector<CANFrame> *modelFrames;
|
||||
|
||||
void processFrame(CANFrame &frame);
|
||||
};
|
||||
|
||||
#endif // SIGNALVIEWERWINDOW_H
|
||||
|
||||
+27
-16
@@ -15,22 +15,33 @@
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="3,1">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableViewer">
|
||||
<property name="columnCount">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>300</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column/>
|
||||
<column/>
|
||||
</widget>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableViewer">
|
||||
<property name="columnCount">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>300</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column/>
|
||||
<column/>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnRemove">
|
||||
<property name="text">
|
||||
<string>Remove Selected Signal</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
|
||||
Reference in New Issue
Block a user