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.
|
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.
|
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;
|
int64_t result = 0;
|
||||||
bool isSigned = false;
|
bool isSigned = false;
|
||||||
@@ -95,16 +95,16 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString)
|
|||||||
endResult = (*((double *)(&result)) * factor) + bias;
|
endResult = (*((double *)(&result)) * factor) + bias;
|
||||||
}
|
}
|
||||||
|
|
||||||
outString = makePrettyOutput(endResult, result);
|
outString = makePrettyOutput(endResult, result, outputName);
|
||||||
cachedValue = endResult;
|
cachedValue = endResult;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DBC_SIGNAL::makePrettyOutput(double floatVal, int64_t intVal)
|
QString DBC_SIGNAL::makePrettyOutput(double floatVal, int64_t intVal, bool outputName)
|
||||||
{
|
{
|
||||||
QString outputString;
|
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
|
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_ATTRIBUTE_VALUE> attributes;
|
||||||
QList<DBC_VAL_ENUM_ENTRY> valList;
|
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 processAsInt(const CANFrame &frame, int32_t &outValue);
|
||||||
bool processAsDouble(const CANFrame &frame, double &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 *findAttrValByName(QString name);
|
||||||
DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
|
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.
|
//so if you want to enable them and play with them then go for it.
|
||||||
ui->actionFirmware_Update->setVisible(false);
|
ui->actionFirmware_Update->setVisible(false);
|
||||||
ui->actionMotorControlConfig->setVisible(false);
|
ui->actionMotorControlConfig->setVisible(false);
|
||||||
ui->actionSignal_Viewer->setVisible(false);
|
//ui->actionSignal_Viewer->setVisible(false);
|
||||||
ui->actionSingle_Multi_State_2->setVisible(false);
|
ui->actionSingle_Multi_State_2->setVisible(false);
|
||||||
|
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
@@ -1015,7 +1015,10 @@ void MainWindow::showSignalViewer()
|
|||||||
{
|
{
|
||||||
if (!signalViewerWindow)
|
if (!signalViewerWindow)
|
||||||
{
|
{
|
||||||
signalViewerWindow = new SignalViewerWindow();
|
if (!useFiltered)
|
||||||
|
signalViewerWindow = new SignalViewerWindow(model->getListReference());
|
||||||
|
else
|
||||||
|
signalViewerWindow = new SignalViewerWindow(model->getFilteredListReference());
|
||||||
}
|
}
|
||||||
signalViewerWindow->show();
|
signalViewerWindow->show();
|
||||||
}
|
}
|
||||||
|
|||||||
+79
-8
@@ -1,14 +1,18 @@
|
|||||||
#include "signalviewerwindow.h"
|
#include "signalviewerwindow.h"
|
||||||
#include "ui_signalviewerwindow.h"
|
#include "ui_signalviewerwindow.h"
|
||||||
#include "helpwindow.h"
|
#include "helpwindow.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
SignalViewerWindow::SignalViewerWindow(QWidget *parent) :
|
SignalViewerWindow::SignalViewerWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::SignalViewerWindow)
|
ui(new Ui::SignalViewerWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setWindowFlags(Qt::Window);
|
setWindowFlags(Qt::Window);
|
||||||
|
|
||||||
|
modelFrames = frames;
|
||||||
|
|
||||||
QStringList headers;
|
QStringList headers;
|
||||||
headers << "Signal" << "Value";
|
headers << "Signal" << "Value";
|
||||||
ui->tableViewer->setHorizontalHeaderLabels(headers);
|
ui->tableViewer->setHorizontalHeaderLabels(headers);
|
||||||
@@ -21,6 +25,8 @@ SignalViewerWindow::SignalViewerWindow(QWidget *parent) :
|
|||||||
|
|
||||||
connect(ui->cbMessages, SIGNAL(currentIndexChanged(int)), this, SLOT(loadSignals(int)));
|
connect(ui->cbMessages, SIGNAL(currentIndexChanged(int)), this, SLOT(loadSignals(int)));
|
||||||
connect(ui->btnAdd, SIGNAL(clicked(bool)), this, SLOT(addSignal()));
|
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();
|
loadMessages();
|
||||||
}
|
}
|
||||||
@@ -30,14 +36,79 @@ SignalViewerWindow::~SignalViewerWindow()
|
|||||||
delete ui;
|
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()
|
void SignalViewerWindow::loadMessages()
|
||||||
{
|
{
|
||||||
|
int numFiles;
|
||||||
ui->cbMessages->clear();
|
ui->cbMessages->clear();
|
||||||
if (dbcHandler == NULL) return;
|
if (dbcHandler == nullptr) return;
|
||||||
if (dbcHandler->getFileCount() == 0) dbcHandler->createBlankFile();
|
if ((numFiles = dbcHandler->getFileCount()) == 0) return;
|
||||||
for (int x = 0; x < dbcHandler->getFileByIdx(0)->messageHandler->getCount(); x++)
|
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
|
//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
|
//look it up based on index but by name is probably safer and this operation
|
||||||
//is not time critical at all.
|
//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();
|
ui->cbSignals->clear();
|
||||||
for (int x = 0; x < msg->sigHandler->getCount(); x++)
|
for (int x = 0; x < msg->sigHandler->getCount(); x++)
|
||||||
{
|
{
|
||||||
@@ -60,7 +131,7 @@ void SignalViewerWindow::loadSignals(int idx)
|
|||||||
|
|
||||||
void SignalViewerWindow::addSignal()
|
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;
|
if (!msg) return;
|
||||||
DBC_SIGNAL *sig = msg->sigHandler->findSignalByName(ui->cbSignals->currentText());
|
DBC_SIGNAL *sig = msg->sigHandler->findSignalByName(ui->cbSignals->currentText());
|
||||||
if (!sig) return;
|
if (!sig) return;
|
||||||
|
|||||||
@@ -13,19 +13,24 @@ class SignalViewerWindow : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SignalViewerWindow(QWidget *parent = 0);
|
explicit SignalViewerWindow(const QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||||
~SignalViewerWindow();
|
~SignalViewerWindow();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void loadMessages();
|
void loadMessages();
|
||||||
void loadSignals(int idx);
|
void loadSignals(int idx);
|
||||||
void addSignal();
|
void addSignal();
|
||||||
|
void removeSelectedSignal();
|
||||||
|
void updatedFrames(int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::SignalViewerWindow *ui;
|
Ui::SignalViewerWindow *ui;
|
||||||
DBCHandler *dbcHandler;
|
DBCHandler *dbcHandler;
|
||||||
|
|
||||||
QList<DBC_SIGNAL *> signalList;
|
QList<DBC_SIGNAL *> signalList;
|
||||||
|
const QVector<CANFrame> *modelFrames;
|
||||||
|
|
||||||
|
void processFrame(CANFrame &frame);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SIGNALVIEWERWINDOW_H
|
#endif // SIGNALVIEWERWINDOW_H
|
||||||
|
|||||||
+27
-16
@@ -15,22 +15,33 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="3,1">
|
<layout class="QHBoxLayout" name="horizontalLayout" stretch="3,1">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableWidget" name="tableViewer">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<property name="columnCount">
|
<item>
|
||||||
<number>2</number>
|
<widget class="QTableWidget" name="tableViewer">
|
||||||
</property>
|
<property name="columnCount">
|
||||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
<number>2</number>
|
||||||
<number>300</number>
|
</property>
|
||||||
</attribute>
|
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||||
<attribute name="horizontalHeaderStretchLastSection">
|
<number>300</number>
|
||||||
<bool>true</bool>
|
</attribute>
|
||||||
</attribute>
|
<attribute name="horizontalHeaderStretchLastSection">
|
||||||
<attribute name="verticalHeaderStretchLastSection">
|
<bool>true</bool>
|
||||||
<bool>false</bool>
|
</attribute>
|
||||||
</attribute>
|
<attribute name="verticalHeaderStretchLastSection">
|
||||||
<column/>
|
<bool>false</bool>
|
||||||
<column/>
|
</attribute>
|
||||||
</widget>
|
<column/>
|
||||||
|
<column/>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnRemove">
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove Selected Signal</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
|||||||
Reference in New Issue
Block a user