Much more implementation of CANDataGrid for CAN-FD. More or less works

now for both changed bit and signal views. There are still some
graphical tweaks to do. Probably doesn't quite work in fuzzing window
just yet.
This commit is contained in:
Collin Kidder
2022-12-04 13:15:02 -05:00
parent a022aee07b
commit 79678af7ba
11 changed files with 282 additions and 231 deletions
+42 -36
View File
@@ -26,10 +26,10 @@ FlowViewWindow::FlowViewWindow(const QVector<CANFrame> *frames, QWidget *parent)
playbackActive = false;
playbackForward = true;
memset(refBytes, 0, 8);
memset(currBytes, 0, 8);
memset(refBytes, 0, 64);
memset(currBytes, 0, 64);
memset(triggerValues, -1, sizeof(int) * 8);
triggerBits = 0;
for (int i = 0; i < 8; i++) triggerBits[i] = 0;
//ui->graphView->setInteractions();
@@ -131,7 +131,7 @@ FlowViewWindow::FlowViewWindow(const QVector<CANFrame> *frames, QWidget *parent)
connect(ui->graphView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestGraph(QPoint)));
ui->flowView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->flowView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestFlow(QPoint)));
connect(ui->flowView, SIGNAL(gridClicked(int,int)), this, SLOT(gotCellClick(int,int)));
connect(ui->flowView, SIGNAL(gridClicked(int)), this, SLOT(gotCellClick(int)));
// Prevent annoying accidental horizontal scrolling when filter list is populated with long interpreted message names
ui->listFrameID->horizontalScrollBar()->setEnabled(false);
@@ -262,13 +262,14 @@ void FlowViewWindow::changeGraphVisibility(int state){
ui->graphView->replot();
}
}
void FlowViewWindow::gotCellClick(int x, int y)
void FlowViewWindow::gotCellClick(int bitPosition)
{
int bitnum = (7-x) + (8 * y);
triggerBits = triggerBits ^ (1ull << bitnum);
if (triggerBits & (1ull << bitnum)) ui->flowView->setCellTextState(x, y, GridTextState::BOLD_BLUE);
else ui->flowView->setCellTextState(x, y, GridTextState::NORMAL);
qDebug() << "Bit Num: " << bitnum << " Hex of trigger bits: " << QString::number(triggerBits, 16);
int chunk = bitPosition / 64;
int idx = bitPosition & 63;
triggerBits[chunk] = triggerBits[chunk] ^ (1ull << idx);
if (triggerBits[chunk] & (1ull << idx)) ui->flowView->setCellTextState(bitPosition, GridTextState::BOLD_BLUE);
else ui->flowView->setCellTextState(bitPosition, GridTextState::NORMAL);
qDebug() << "Bit Num: " << bitPosition << " Hex of trigger bits: " << QString::number(triggerBits[chunk], 16);
}
void FlowViewWindow::graphRangeChanged(int range) {
@@ -454,8 +455,8 @@ void FlowViewWindow::updatedFrames(int numFrames)
refreshIDList();
updateFrameLabel();
removeAllGraphs();
memset(refBytes, 0, 8);
memset(currBytes, 0, 8);
memset(refBytes, 0, 64);
memset(currBytes, 0, 64);
updateDataView();
}
else if (numFrames == -2) //all new set of frames. Reset
@@ -518,9 +519,9 @@ void FlowViewWindow::updatedFrames(int numFrames)
if (ui->cbLiveMode->checkState() == Qt::Checked)
{
currentPosition = frameCache.count() - 1;
memset(currBytes, 0, 8);
memset(currBytes, 0, 64);
memcpy(currBytes, frameCache.at(currentPosition).payload().data(), frameCache.at(currentPosition).payload().length());
memcpy(refBytes, currBytes, 8);
memcpy(refBytes, currBytes, 64);
}
if (needRefresh)
@@ -657,9 +658,9 @@ void FlowViewWindow::changeID(QString newID)
updateGraphLocation();
memset(currBytes, 0, 8);
memset(currBytes, 0, 64);
memcpy(currBytes, frameCache.at(currentPosition).payload().constData(), frameCache.at(currentPosition).payload().length());
memcpy(refBytes, currBytes, 8);
memcpy(refBytes, currBytes, 64);
updateDataView();
ui->check_0->setChecked(true);
@@ -705,9 +706,9 @@ void FlowViewWindow::btnStopClick()
playbackActive = false;
currentPosition = 0;
memset(currBytes, 0, 8);
memset(currBytes, 0, 64);
memcpy(currBytes, frameCache.at(currentPosition).payload().constData(), frameCache.at(currentPosition).payload().length());
memcpy(refBytes, currBytes, 8);
memcpy(refBytes, currBytes, 64);
updateFrameLabel();
updateDataView();
@@ -831,31 +832,36 @@ void FlowViewWindow::updatePosition(bool forward)
if (ui->cbAutoRef->isChecked())
{
memcpy(refBytes, currBytes, 8);
memcpy(refBytes, currBytes, 64);
}
//figure out which bits changed since the previous frame and then AND that with the trigger bits. If any bits
//get through that then they're changed and a trigger so we stop playback at this frame.
uint64_t changedBits = 0;
uint8_t cngByte;
for (int i = 0; i < frameCache.at(currentPosition).payload().length(); i++)
//This is complicated by the fact that CAN-FD frames might have far more than 64 bits. It is necessary
//to thus process them 64 bits at a time and just move chunk to chunk until done.
for (int chunk = 0; chunk < frameCache.at(currentPosition).payload().length(); chunk += 8)
{
unsigned char thisByte = static_cast<unsigned char>(frameCache.at(currentPosition).payload().data()[i]);
cngByte = currBytes[i] ^ thisByte;
changedBits |= (uint64_t)cngByte << (8ull * i);
}
uint64_t changedBits = 0;
uint8_t cngByte;
int maxVal = qMin(chunk * 8 + 8, frameCache.at(currentPosition).payload().length());
for (int i = chunk * 8; i < maxVal; i++)
{
unsigned char thisByte = static_cast<unsigned char>(frameCache.at(currentPosition).payload().data()[i]);
cngByte = currBytes[i] ^ thisByte;
changedBits |= (uint64_t)cngByte << (8ull * (i & 7));
}
qDebug() << "ChangedBits: " << QString::number(changedBits, 16);
qDebug() << "TriggerBits: " << QString::number(triggerBits, 16);
changedBits &= triggerBits;
qDebug() << "Final ChangedBits: " << QString::number(changedBits, 16);
if (changedBits)
{
playbackActive = false;
playbackTimer->stop();
qDebug() << "ChangedBits: " << QString::number(changedBits, 16);
qDebug() << "TriggerBits: " << QString::number(triggerBits[chunk / 8], 16);
changedBits &= triggerBits[chunk / 8];
qDebug() << "Final ChangedBits: " << QString::number(changedBits, 16);
if (changedBits)
{
playbackActive = false;
playbackTimer->stop();
}
}
memset(currBytes, 0, 8);
memset(currBytes, 0, 64);
memcpy(currBytes, frameCache.at(currentPosition).payload().constData(), frameCache.at(currentPosition).payload().length());
if (ui->cbSync->checkState() == Qt::Checked) emit sendCenterTimeID(frameCache[currentPosition].frameId(), frameCache[currentPosition].timeStamp().microSeconds() / 1000000.0);
+4 -4
View File
@@ -39,7 +39,7 @@ private slots:
void plottableDoubleClick(QCPAbstractPlottable* plottable, QMouseEvent* event);
void gotCenterTimeID(uint32_t ID, double timestamp);
void updateTriggerValues();
void gotCellClick(int x, int y);
void gotCellClick(int bitPosition);
void graphRangeChanged(int range);
void changeGraphVisibility(int state);
@@ -51,10 +51,10 @@ private:
QList<quint32> foundID;
QList<CANFrame> frameCache;
const QVector<CANFrame> *modelFrames;
unsigned char refBytes[8];
unsigned char currBytes[8];
unsigned char refBytes[64];
unsigned char currBytes[64];
int triggerValues[8];
uint64_t triggerBits;
uint64_t triggerBits[8];
int currentPosition;
QTimer *playbackTimer;
bool playbackActive;
+15 -15
View File
@@ -26,7 +26,7 @@ FuzzingWindow::FuzzingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
connect(ui->spinTiming, SIGNAL(valueChanged(int)), this, SLOT(changePlaybackSpeed(int)));
connect(ui->listID, &QListWidget::itemChanged, this, &FuzzingWindow::idListChanged);
connect(ui->spinBytes, SIGNAL(valueChanged(int)), this, SLOT(changedNumDataBytes(int)));
connect(ui->bitfield, SIGNAL(gridClicked(int,int)), this, SLOT(bitfieldClicked(int,int)));
connect(ui->bitfield, SIGNAL(gridClicked(int)), this, SLOT(bitfieldClicked(int)));
connect(ui->txtByte0, &QLineEdit::returnPressed, this, [=](){changedDataByteText(0, ui->txtByte0->text());});
connect(ui->txtByte1, &QLineEdit::returnPressed, this, [=](){changedDataByteText(1, ui->txtByte1->text());});
connect(ui->txtByte2, &QLineEdit::returnPressed, this, [=](){changedDataByteText(2, ui->txtByte2->text());});
@@ -43,7 +43,7 @@ FuzzingWindow::FuzzingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
currentlyFuzzing = false;
for (int j = 0; j < 64; j++) bitGrid[j] = 1;
for (int j = 0; j < 512; j++) bitGrid[j] = 1;
numBits = 64;
bitAccum = 0;
redrawGrid();
@@ -146,8 +146,10 @@ void FuzzingWindow::changedNumDataBytes(int newVal)
ui->txtByte6->setEnabled((newVal > 6) ? true : false);
ui->txtByte7->setEnabled((newVal > 7) ? true : false);
ui->bitfield->setBytesToDraw(newVal);
int byt;
for (int i = 0; i < 64; i++)
for (int i = 0; i < 511; i++)
{
byt = i / 8;
if (byt >= newVal)
@@ -448,20 +450,18 @@ void FuzzingWindow::idListChanged(QListWidgetItem *item)
}
/*
bitGrid stores the state of all 64 bits.
bitGrid stores the state of all bits.
The grid is capable of showing the following colors:
White = not used (left as 0)
Gray = past the end of the valid bits (because of # of data bytes requested)
Green = fuzz it
black = always keep it set to 1
*/
void FuzzingWindow::bitfieldClicked(int x, int y)
void FuzzingWindow::bitfieldClicked(int bitPos)
{
qDebug() << "X: " << x << " Y: " << y;
int bit = (7 - x) + (y * 8);
if (bitGrid[bit] == 3) return; //naughty!
bitGrid[bit]++;
if (bitGrid[bit] > 2) bitGrid[bit] = 0;
if (bitGrid[bitPos] == 3) return; //naughty!
bitGrid[bitPos]++;
if (bitGrid[bitPos] > 2) bitGrid[bitPos] = 0;
redrawGrid();
}
@@ -469,11 +469,11 @@ void FuzzingWindow::bitfieldClicked(int x, int y)
void FuzzingWindow::redrawGrid()
{
//now update the bits in the bitfield control
uint8_t refBytes[8];
uint8_t dataBytes[8];
uint8_t usedBytes[8];
uint8_t refBytes[64];
uint8_t dataBytes[64];
uint8_t usedBytes[64];
for (int j = 0; j < 8; j++)
for (int j = 0; j < 64; j++)
{
refBytes[j] = 0;
dataBytes[j] = 0;
@@ -482,7 +482,7 @@ void FuzzingWindow::redrawGrid()
numBits = 0;
for (int i = 0; i < 64; i++)
for (int i = 0; i < 512; i++)
{
int byt = i / 8;
int bit = i % 8;
+3 -3
View File
@@ -39,7 +39,7 @@ private slots:
void setAllFilters();
void toggleFuzzing();
void idListChanged(QListWidgetItem *item);
void bitfieldClicked(int, int);
void bitfieldClicked(int);
void changedNumDataBytes(int newVal);
void updatedFrames(int numFrames);
@@ -54,8 +54,8 @@ private:
bool seqIDScan, rangeIDSelect;
int bitSequenceType;
bool currentlyFuzzing;
uint8_t currentBytes[8];
uint8_t bitGrid[64];
uint8_t currentBytes[64];
uint8_t bitGrid[512];
uint8_t numBits;
uint64_t bitAccum;
int numSentFrames;
+2
View File
@@ -1046,6 +1046,7 @@ void GraphingWindow::loadDefinitions()
gp.bias = tokens[6].toFloat();
gp.scale = tokens[7].toFloat();
gp.stride = tokens[8].toInt();
gp.bus = -1;
gp.lineColor.setRed( tokens[9].toInt() );
gp.lineColor.setGreen( tokens[10].toInt() );
@@ -1080,6 +1081,7 @@ void GraphingWindow::loadDefinitions()
else //one of the two older formats then
{
gp.ID = tokens[0].toUInt(nullptr, 16);
gp.bus = -1;
if (tokens[1] == "S") //old signal based graph definition
{
//tokens[2] is the signal name. Need to use the message ID and this name to look it up
+15 -11
View File
@@ -44,7 +44,7 @@ NewGraphDialog::NewGraphDialog(DBCHandler *handler, QWidget *parent) :
ui->coPointStyle->addItem("Peace Sign");
connect(ui->cbMessages, SIGNAL(currentIndexChanged(int)), this, SLOT(loadSignals(int)));
connect(ui->gridData, SIGNAL(gridClicked(int,int)), this, SLOT(bitfieldClicked(int,int)));
connect(ui->gridData, SIGNAL(gridClicked(int)), this, SLOT(bitfieldClicked(int)));
connect(ui->txtDataLen, SIGNAL(textChanged(QString)), this, SLOT(handleDataLenUpdate()));
connect(ui->cbIntel, SIGNAL(toggled(bool)), this, SLOT(drawBitfield()));
connect(ui->btnCopySignal, SIGNAL(clicked(bool)), this, SLOT(copySignalToParamsUI()));
@@ -300,10 +300,8 @@ void NewGraphDialog::loadSignals(int idx)
checkSignalAgreement();
}
void NewGraphDialog::bitfieldClicked(int x,int y)
void NewGraphDialog::bitfieldClicked(int bit)
{
int bit = (y * 8 + (7-x));
qDebug() << "Clicked bit: " << bit;
startBit = bit;
drawBitfield();
@@ -312,20 +310,25 @@ void NewGraphDialog::bitfieldClicked(int x,int y)
void NewGraphDialog::drawBitfield()
{
qDebug() << "Draw Bitfield";
int64_t bitField = 0;
uint8_t bitField[64];
int endBit, sBit;
bitField |= 1ull << (startBit); //make the start bit a different color to set it apart
memset(bitField, 0, 64);
//make the start bit a different color to set it apart
bitField[Utility::getByteFromBitPosition(startBit)] |= 1 << Utility::getBitFromBitPosition(startBit);
ui->gridData->setReference((unsigned char *)&bitField, false);
if (ui->cbIntel->isChecked())
{
endBit = startBit + dataLen - 1;
if (startBit < 0) startBit = 0;
if (endBit > 63) endBit = 63;
if (endBit > 511) endBit = 511;
for (int y = startBit; y <= endBit; y++)
{
bitField |= 1ull << y;
//bitField |= 1ull << y;
bitField[Utility::getByteFromBitPosition(y)] |= 1 << Utility::getBitFromBitPosition(y);
}
}
else //big endian / motorola format
@@ -335,11 +338,12 @@ void NewGraphDialog::drawBitfield()
sBit = startBit;
while (size > 0)
{
bitField |= 1ull << sBit;
//bitField |= 1ull << sBit;
bitField[Utility::getByteFromBitPosition(sBit)] |= 1 << Utility::getBitFromBitPosition(sBit);
size--;
if ((sBit % 8) == 0) sBit += 15;
else sBit--;
if (sBit > 63) sBit = 63;
if (sBit > 511) sBit = 511;
}
}
@@ -352,7 +356,7 @@ void NewGraphDialog::handleDataLenUpdate()
{
dataLen = ui->txtDataLen->text().toInt();
if (dataLen < 1) dataLen = 1;
if (dataLen > 63) dataLen = 63;
if (dataLen > 64) dataLen = 64;
drawBitfield();
checkSignalAgreement();
}
+1 -1
View File
@@ -27,7 +27,7 @@ private slots:
void fillSwatchClick();
void loadMessages();
void loadSignals(int idx);
void bitfieldClicked(int,int);
void bitfieldClicked(int);
void handleDataLenUpdate();
void drawBitfield();
void copySignalToParamsUI();