Add new heatmap mode to CAN data grid widget, put that widget onto

Frame Info Window. Made Frame Info Window able to have the two sides
resized relative to each other
This commit is contained in:
Collin Kidder
2023-01-15 17:05:43 -05:00
parent bbb5c99e78
commit 74ec42a720
5 changed files with 126 additions and 73 deletions
+66 -29
View File
@@ -72,7 +72,10 @@ CANDataGrid::CANDataGrid(QWidget *parent) :
bytesToDraw = 8; //default to the old behavior bytesToDraw = 8; //default to the old behavior
for (int x = 0; x < 8; x++) for (int x = 0; x < 8; x++)
for (int y = 0; y < 64; y++) for (int y = 0; y < 64; y++)
{
textStates[y][x] = GridTextState::NORMAL; textStates[y][x] = GridTextState::NORMAL;
heatData[y * 8 + x] = 0;
}
blackBrush = QBrush(Qt::black); blackBrush = QBrush(Qt::black);
whiteBrush = QBrush(Qt::white); whiteBrush = QBrush(Qt::white);
@@ -83,6 +86,26 @@ CANDataGrid::CANDataGrid(QWidget *parent) :
grayBrush = QBrush(QColor(230,230,230)); grayBrush = QBrush(QColor(230,230,230));
xOffset = 0; xOffset = 0;
yOffset = 0; yOffset = 0;
//generate the palette
/* //this one looks sort of like a fire. It was my first idea but never really got to where I liked it
for(int x = 1; x < 256; x++)
{
int lum = x * 2;
if (lum < 40) lum = 40;
if (lum > 250) lum = 250;
fire[x] = QColor::fromHsl((int)(x / 3.5), 255 - ((256 - x) / 10), lum);
}
*/
for(int x = 1; x < 256; x++)
{
int hue = 256 - x;
fire[x] = QColor::fromHsl(hue, 255, 127);
}
fire[0] = Qt::black;
} }
CANDataGrid::~CANDataGrid() CANDataGrid::~CANDataGrid()
@@ -241,12 +264,12 @@ void CANDataGrid::paintCommonBeginning()
neededXDivisions = 32; neededXDivisions = 32;
} }
if (gridMode == GridMode::CHANGED_BITS) if (gridMode != GridMode::SIGNAL_VIEW)
{ {
bigTextSize = qMin(viewport.size().height(), viewport.size().width()) / (textRestrict * 3.25); bigTextSize = qMin(viewport.size().height(), viewport.size().width()) / (textRestrict * 3.25);
smallTextSize = qMin(viewport.size().height(), viewport.size().width()) / (textRestrict * 4.0); smallTextSize = qMin(viewport.size().height(), viewport.size().width()) / (textRestrict * 4.0);
} }
if (gridMode == GridMode::SIGNAL_VIEW) else
{ {
bigTextSize = qMin(viewport.size().height(), viewport.size().width()) / (textRestrict * 3.50); bigTextSize = qMin(viewport.size().height(), viewport.size().width()) / (textRestrict * 3.50);
smallTextSize = qMin(viewport.size().height(), viewport.size().width()) / (textRestrict * 5.5); smallTextSize = qMin(viewport.size().height(), viewport.size().width()) / (textRestrict * 5.5);
@@ -342,45 +365,53 @@ void CANDataGrid::paintGridCells()
if ((thisByte & (1 << bitIdx)) == (1 << bitIdx)) thisBit = true; if ((thisByte & (1 << bitIdx)) == (1 << bitIdx)) thisBit = true;
if ((prevByte & (1 << bitIdx)) == (1 << bitIdx)) prevBit = true; if ((prevByte & (1 << bitIdx)) == (1 << bitIdx)) prevBit = true;
if (thisBit) if (gridMode == GridMode::HEAT_VIEW)
{ {
if (prevBit) painter->setBrush(QBrush(fire[heatData[bit]]));
{
if ((signalColors.count() > 0) && (gridMode == GridMode::SIGNAL_VIEW)) painter->setBrush(blackHashBrush);
else painter->setBrush(blackBrush);
}
else
{
if ((signalColors.count() > 0) && (gridMode == GridMode::SIGNAL_VIEW)) painter->setBrush(greenHashBrush);
else painter->setBrush(greenBrush);
}
} }
else else
{ {
if (prevBit) if (thisBit)
{ {
painter->setBrush(redBrush); if (prevBit)
{
if ((signalColors.count() > 0) && (gridMode == GridMode::SIGNAL_VIEW)) painter->setBrush(blackHashBrush);
else painter->setBrush(blackBrush);
}
else
{
if ((signalColors.count() > 0) && (gridMode == GridMode::SIGNAL_VIEW)) painter->setBrush(greenHashBrush);
else painter->setBrush(greenBrush);
}
} }
else else
{ {
usedSigNum = -1; if (prevBit)
if ((usedData[byteIdx] & (1 << bitIdx)) == (1 << bitIdx))
{ {
if (gridMode == GridMode::SIGNAL_VIEW) usedSigNum = getUsedSignalNum(bit); painter->setBrush(redBrush);
if (usedSigNum == -1) }
else
{
usedSigNum = -1;
if ((usedData[byteIdx] & (1 << bitIdx)) == (1 << bitIdx))
{ {
grayBrush = QBrush(QColor(0xB6, 0xB6, 0xB6), Qt::BDiagPattern); if (gridMode == GridMode::SIGNAL_VIEW) usedSigNum = getUsedSignalNum(bit);
painter->setBrush(grayBrush); if (usedSigNum == -1)
{
grayBrush = QBrush(QColor(0xB6, 0xB6, 0xB6), Qt::BDiagPattern);
painter->setBrush(grayBrush);
}
else
{
int idx = usedSigNum % signalColors.length(); //can only use as many colors as have been defined
painter->setBrush(QBrush(signalColors[idx]));
}
} }
else else painter->setBrush(whiteBrush);
{
int idx = usedSigNum % signalColors.length(); //can only use as many colors as have been defined
painter->setBrush(QBrush(signalColors[idx]));
}
} }
else painter->setBrush(whiteBrush);
} }
} }
painter->drawRect(nearX + (x * xSector), nearY + (y * ySector), xSector, ySector); painter->drawRect(nearX + (x * xSector), nearY + (y * ySector), xSector, ySector);
switch (textStates[byteIdx][bitIdx]) switch (textStates[byteIdx][bitIdx])
{ {
@@ -419,7 +450,7 @@ void CANDataGrid::paintGridCells()
* We already have a big bitmap that tells us which signals occupy which bits so every time there is a new * We already have a big bitmap that tells us which signals occupy which bits so every time there is a new
* signal look ahead to see if there's room in the row to just run the signal name through as long as needed. * signal look ahead to see if there's room in the row to just run the signal name through as long as needed.
*/ */
if (signalNames.count() > 0) if ( (signalNames.count() > 0) && (gridMode == GridMode::SIGNAL_VIEW) )
{ {
painter->setFont(sigNameFont); painter->setFont(sigNameFont);
@@ -590,3 +621,9 @@ void CANDataGrid::setUsed(unsigned char *newData, bool bUpdate = false)
if (bytesToTransfer < 64) memset(refData + bytesToTransfer, 0, 64 - bytesToTransfer); if (bytesToTransfer < 64) memset(refData + bytesToTransfer, 0, 64 - bytesToTransfer);
if (bUpdate) this->update(); if (bUpdate) this->update();
} }
void CANDataGrid::setHeat(unsigned char *newData)
{
memcpy(heatData, newData, 512);
this->update();
}
+5 -1
View File
@@ -36,7 +36,8 @@ enum GridTextState
enum GridMode enum GridMode
{ {
CHANGED_BITS, //traditional view, bunch of bits we color to show what's set and how the bits have changed over time CHANGED_BITS, //traditional view, bunch of bits we color to show what's set and how the bits have changed over time
SIGNAL_VIEW //special view for DBC window where we draw the signals in the bits they take up SIGNAL_VIEW, //special view for DBC window where we draw the signals in the bits they take up
HEAT_VIEW //another special mode where each bit is given a heat level and we color each bit based on that. Use refData for storage of those values
}; };
extern QVector<QColor> signalColors; extern QVector<QColor> signalColors;
@@ -52,6 +53,7 @@ public:
void setReference(unsigned char *, bool); void setReference(unsigned char *, bool);
void updateData(unsigned char *, bool); void updateData(unsigned char *, bool);
void setUsed(unsigned char *, bool); void setUsed(unsigned char *, bool);
void setHeat(unsigned char *);
void saveImage(QString filename, int width, int height); void saveImage(QString filename, int width, int height);
void setCellTextState(int bitPos, GridTextState state); void setCellTextState(int bitPos, GridTextState state);
GridTextState getCellTextState(int bitPos); GridTextState getCellTextState(int bitPos);
@@ -76,6 +78,7 @@ private:
unsigned char refData[64]; unsigned char refData[64];
unsigned char data[64]; unsigned char data[64];
unsigned char usedData[64]; unsigned char usedData[64];
unsigned char heatData[512];
int usedSignalNum[512]; //so we can specify which signal claims this bit int usedSignalNum[512]; //so we can specify which signal claims this bit
QVector<QString> signalNames; QVector<QString> signalNames;
GridTextState textStates[64][8]; //first dimension is bytes, second is bits GridTextState textStates[64][8]; //first dimension is bytes, second is bits
@@ -101,6 +104,7 @@ private:
QFont sigNameFont; QFont sigNameFont;
QFontMetrics *smallMetric; QFontMetrics *smallMetric;
QFontMetrics *largeMetric; QFontMetrics *largeMetric;
QColor fire[256];
void paintGridCells(); void paintGridCells();
void paintCommonBeginning(); void paintCommonBeginning();
+47 -28
View File
@@ -41,27 +41,40 @@ FrameInfoWindow::FrameInfoWindow(const QVector<CANFrame> *frames, QWidget *paren
{ {
graphByte[i] = new QCustomPlot(); graphByte[i] = new QCustomPlot();
setupByteGraph(graphByte[i], i); setupByteGraph(graphByte[i], i);
ui->gridLayout->addWidget(graphByte[i], i / 4, i & 3); ui->gridLower->addWidget(graphByte[i], i / 4, i & 3);
} }
ui->graphHistogram->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | ui->gridUpper->addWidget(new QLabel("Heatmap"), 0, 0);
heatmap = new CANDataGrid();
heatmap->setMode(GridMode::HEAT_VIEW);
ui->gridUpper->addWidget(heatmap, 1, 0);
ui->gridUpper->addWidget(new QLabel("Bit Histogram"), 0, 1);
graphHistogram = new QCustomPlot();
ui->gridUpper->addWidget(graphHistogram, 1, 1);
ui->gridUpper->setRowMinimumHeight(0, 20);
ui->gridUpper->setRowStretch(0, 1);
ui->gridUpper->setRowStretch(1, 10);
graphHistogram->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables); QCP::iSelectLegend | QCP::iSelectPlottables);
ui->graphHistogram->xAxis->setRange(0, 63); graphHistogram->xAxis->setRange(0, 63);
ui->graphHistogram->yAxis->setRange(0, 100); graphHistogram->yAxis->setRange(0, 100);
QSharedPointer<QCPAxisTickerLog> graphHistoLogTicker(new QCPAxisTickerLog); QSharedPointer<QCPAxisTickerLog> graphHistoLogTicker(new QCPAxisTickerLog);
ui->graphHistogram->yAxis->setTicker(graphHistoLogTicker); graphHistogram->yAxis->setTicker(graphHistoLogTicker);
ui->graphHistogram->yAxis2->setTicker(graphHistoLogTicker); graphHistogram->yAxis2->setTicker(graphHistoLogTicker);
ui->graphHistogram->yAxis->setNumberFormat("eb"); // e = exponential, b = beautiful decimal powers graphHistogram->yAxis->setNumberFormat("eb"); // e = exponential, b = beautiful decimal powers
ui->graphHistogram->yAxis->setNumberPrecision(0); //log ticker always picks powers of 10 so no need or use for precision graphHistogram->yAxis->setNumberPrecision(0); //log ticker always picks powers of 10 so no need or use for precision
ui->graphHistogram->axisRect()->setupFullAxesBox(); graphHistogram->axisRect()->setupFullAxesBox();
ui->graphHistogram->setBufferDevicePixelRatio(1); graphHistogram->setBufferDevicePixelRatio(1);
ui->graphHistogram->xAxis->setLabel("Bits"); graphHistogram->xAxis->setLabel("Bits");
ui->graphHistogram->yAxis->setLabel("Instances"); graphHistogram->yAxis->setLabel("Instances");
ui->graphHistogram->legend->setVisible(false); graphHistogram->legend->setVisible(false);
ui->timeHistogram->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | ui->timeHistogram->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables); QCP::iSelectLegend | QCP::iSelectPlottables);
@@ -84,15 +97,15 @@ FrameInfoWindow::FrameInfoWindow(const QVector<CANFrame> *frames, QWidget *paren
if (useOpenGL) if (useOpenGL)
{ {
ui->graphHistogram->setAntialiasedElements(QCP::aeAll); graphHistogram->setAntialiasedElements(QCP::aeAll);
ui->graphHistogram->setOpenGl(true); graphHistogram->setOpenGl(true);
ui->timeHistogram->setAntialiasedElements(QCP::aeAll); ui->timeHistogram->setAntialiasedElements(QCP::aeAll);
ui->timeHistogram->setOpenGl(true); ui->timeHistogram->setOpenGl(true);
} }
else else
{ {
ui->graphHistogram->setOpenGl(false); graphHistogram->setOpenGl(false);
ui->graphHistogram->setAntialiasedElements(QCP::aeNone); graphHistogram->setAntialiasedElements(QCP::aeNone);
ui->timeHistogram->setOpenGl(false); ui->timeHistogram->setOpenGl(false);
ui->timeHistogram->setAntialiasedElements(QCP::aeNone); ui->timeHistogram->setAntialiasedElements(QCP::aeNone);
} }
@@ -304,6 +317,7 @@ void FrameInfoWindow::updateDetailsWindow(QString newID)
double maxY = -1000.0; double maxY = -1000.0;
uint8_t changedBits[8]; uint8_t changedBits[8];
uint8_t referenceBits[8]; uint8_t referenceBits[8];
uint8_t heatVals[512];
//these two used by bitflip heatmap functionality //these two used by bitflip heatmap functionality
uint8_t refByte[8]; uint8_t refByte[8];
@@ -649,6 +663,7 @@ void FrameInfoWindow::updateDetailsWindow(QString newID)
//heat map output //heat map output
dataBase = new QTreeWidgetItem(); dataBase = new QTreeWidgetItem();
dataBase->setText(0, tr("Bitchange Heatmap")); dataBase->setText(0, tr("Bitchange Heatmap"));
memset(heatVals, 0, 512); //always clear the array before populating it.
for (int c = 0; c < 8 * maxLen; c++) for (int c = 0; c < 8 * maxLen; c++)
{ {
tempItem = new QTreeWidgetItem(); tempItem = new QTreeWidgetItem();
@@ -659,9 +674,13 @@ void FrameInfoWindow::updateDetailsWindow(QString newID)
histGraphX.append(c); histGraphX.append(c);
histGraphY.append(bitfieldHistogram[c]); histGraphY.append(bitfieldHistogram[c]);
if (bitfieldHistogram[c] > maxY) maxY = bitfieldHistogram[c]; if (bitfieldHistogram[c] > maxY) maxY = bitfieldHistogram[c];
uint8_t heat = bitFlipHeat[c] * 255;
if ((heat < 1) && (bitFlipHeat[c] > 0.0001)) heat = 1; //make sure any little bit of heat causes at least some output
qDebug() << "Heat for bit " << c << " is " << heat;
heatVals[c] = heat;
} }
baseNode->addChild(dataBase); baseNode->addChild(dataBase);
heatmap->setHeat(heatVals);
QHash<QString, QHash<QString, int>>::const_iterator it = signalInstances.constBegin(); QHash<QString, QHash<QString, int>>::const_iterator it = signalInstances.constBegin();
while (it != signalInstances.constEnd()) { while (it != signalInstances.constEnd()) {
@@ -681,19 +700,19 @@ void FrameInfoWindow::updateDetailsWindow(QString newID)
ui->treeDetails->insertTopLevelItem(0, baseNode); ui->treeDetails->insertTopLevelItem(0, baseNode);
ui->graphHistogram->clearGraphs(); graphHistogram->clearGraphs();
ui->graphHistogram->addGraph(); graphHistogram->addGraph();
ui->graphHistogram->graph()->setData(histGraphX, histGraphY); graphHistogram->graph()->setData(histGraphX, histGraphY);
ui->graphHistogram->graph()->setLineStyle(QCPGraph::lsStepLeft); //connect points with lines graphHistogram->graph()->setLineStyle(QCPGraph::lsStepLeft); //connect points with lines
QBrush graphBrush; QBrush graphBrush;
graphBrush.setColor(Qt::red); graphBrush.setColor(Qt::red);
graphBrush.setStyle(Qt::SolidPattern); graphBrush.setStyle(Qt::SolidPattern);
ui->graphHistogram->graph()->setPen(Qt::NoPen); graphHistogram->graph()->setPen(Qt::NoPen);
ui->graphHistogram->graph()->setBrush(graphBrush); graphHistogram->graph()->setBrush(graphBrush);
ui->graphHistogram->yAxis->setRange(0.8, maxY * 1.2); graphHistogram->yAxis->setRange(0.8, maxY * 1.2);
ui->graphHistogram->yAxis->setScaleType(QCPAxis::stLogarithmic); graphHistogram->yAxis->setScaleType(QCPAxis::stLogarithmic);
ui->graphHistogram->axisRect()->setupFullAxesBox(); graphHistogram->axisRect()->setupFullAxesBox();
ui->graphHistogram->replot(); graphHistogram->replot();
for (int graphs = 0; graphs < 8; graphs++) for (int graphs = 0; graphs < 8; graphs++)
{ {
+3
View File
@@ -5,6 +5,7 @@
#include <QFile> #include <QFile>
#include <QListWidget> #include <QListWidget>
#include <QTreeWidget> #include <QTreeWidget>
#include <candatagrid.h>
#include "can_structs.h" #include "can_structs.h"
#include "bus_protocols/j1939_handler.h" #include "bus_protocols/j1939_handler.h"
#include "dbc/dbchandler.h" #include "dbc/dbchandler.h"
@@ -32,6 +33,8 @@ private slots:
private: private:
Ui::FrameInfoWindow *ui; Ui::FrameInfoWindow *ui;
QCustomPlot *graphByte[8]; QCustomPlot *graphByte[8];
QCustomPlot *graphHistogram;
CANDataGrid *heatmap;
QList<int> foundID; QList<int> foundID;
QList<CANFrame> frameCache; QList<CANFrame> frameCache;
+5 -15
View File
@@ -22,7 +22,7 @@
<property name="handleWidth"> <property name="handleWidth">
<number>8</number> <number>8</number>
</property> </property>
<widget class="QWidget" name=""> <widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,4"> <layout class="QHBoxLayout" name="horizontalLayout" stretch="1,4">
@@ -120,20 +120,10 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name=""> <widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,1,0,2"> <layout class="QVBoxLayout" name="verticalLayout_4" stretch="2,0,2">
<item> <item>
<widget class="QLabel" name="label"> <layout class="QGridLayout" name="gridUpper"/>
<property name="text">
<string>Bit Histograph</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QCustomPlot" name="graphHistogram" native="true"/>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
@@ -146,7 +136,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout" rowstretch="0"/> <layout class="QGridLayout" name="gridLower" rowstretch="0"/>
</item> </item>
</layout> </layout>
</widget> </widget>