Custom sender is no longer crashing

There are a TON of explorations I did here, many may be unnecessary, but this is a stake in the ground.

The main issue was the strange queue logic in canconmanager::sendFrame which puts the tx data in the rx
queue so it will show up in the displayed data.  It caused SIGABRT and SIGSEG to show up everywhere.
It is NOT fixed yet, but TX works over the wire you just can't see it in the tableview.

I thought at first it was only when overwrite data was active, so I put in a a pile of changes to keep
frames and filtered frames as two seperate copies of data where frames was always complete and filtered
was only what was seen in the mainwindow.  It made it so the graphing window would work with overwrite
data active which is an improvement.  I wouldn't roll these changes back.  Because of these changes I
had to update the frame sorting code adjust the refresh function in canframemode.cpp

I also thought it was related to UI updates, but its not, that's been confirmed.

I put a mutex around the custom sender tick timer so that the 1ms timer wouldn't re-enter its callback.
This didn't fix the crash, but it sure seems to make a lot of sense, and the way I did it no elasped
time is lost for tracking purposes, and in reality theres no way 1ms was consistent anyway.

I put a mutex around the shrinking of frames and filteredframes to make sure we weren't deleting at
the same time as accessing, but honestly we acccess those lists in many places without semaphores so
that probably did nothing.

Fixed a bug in FrameSenderWindow:DoModifiers that was improperly parsing and sometimes crashing when
looking for the ~ operator before a symbol.

Also added some minor work to keep row expansion functioning when changing filters or sorting.  Need
to make some tweaks so it stops trying so hard when overwrite is not active

Theres also code in main.c taht makes debugging output super verbose.

Committing now to start cleanup
This commit is contained in:
Andy Huska
2022-11-01 15:01:07 -05:00
parent cfe643b390
commit 1b41decd20
16 changed files with 237 additions and 124 deletions
+66 -43
View File
@@ -32,13 +32,13 @@ FrameSenderWindow::FrameSenderWindow(const QVector<CANFrame> *frames, QWidget *p
createBlankRow();
connect(ui->tableSender, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
connect(intervalTimer, SIGNAL(timeout()), this, SLOT(handleTick()));
connect(intervalTimer, SIGNAL(timeout()), this, SLOT(handleTick()), Qt::QueuedConnection);
connect(ui->btnClearGrid, SIGNAL(clicked(bool)), this, SLOT(clearGrid()));
connect(ui->btnDisableAll, SIGNAL(clicked(bool)), this, SLOT(disableAll()));
connect(ui->btnEnableAll, SIGNAL(clicked(bool)), this, SLOT(enableAll()));
connect(ui->btnLoadGrid, SIGNAL(clicked(bool)), this, SLOT(loadGrid()));
connect(ui->btnSaveGrid, SIGNAL(clicked(bool)), this, SLOT(saveGrid()));
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)), Qt::QueuedConnection);
intervalTimer->start();
elapsedTimer.start();
@@ -181,8 +181,8 @@ void FrameSenderWindow::processIncomingFrame(CANFrame *frame)
for (int trig = 0; trig < sendingData[sd].triggers.count(); trig++)
{
Trigger *thisTrigger = &sendingData[sd].triggers[trig];
qDebug() << "Trigger ID: " << thisTrigger->ID;
qDebug() << "Frame ID: " << frame->frameId();
//qDebug() << "Trigger ID: " << thisTrigger->ID;
//qDebug() << "Frame ID: " << frame->frameId();
if (thisTrigger->ID > 0 && (uint32_t)thisTrigger->ID == frame->frameId())
{
if (thisTrigger->bus == frame->bus || thisTrigger->bus == -1)
@@ -195,7 +195,7 @@ void FrameSenderWindow::processIncomingFrame(CANFrame *frame)
sendingData[sd].count++;
doModifiers(sd);
updateGridRow(sd);
CANConManager::getInstance()->sendFrame(sendingData[sd]);
CANConManager::getInstance()->sendFrame(CANFrame(sendingData[sd]));
}
else //delayed sending frame
{
@@ -290,6 +290,8 @@ void FrameSenderWindow::loadGrid()
}
}
createBlankRow();
setupGrid();
}
@@ -424,44 +426,54 @@ void FrameSenderWindow::handleTick()
{
FrameSendData *sendData;
Trigger *trigger;
int elapsed = elapsedTimer.restart();
if (elapsed == 0) elapsed = 1;
//Modifier modifier;
for (int i = 0; i < sendingData.count(); i++)
if(mutex.tryLock())
{
sendData = &sendingData[i];
if (!sendData->enabled)
int elapsed = elapsedTimer.restart();
if (elapsed == 0) elapsed = 1;
//Modifier modifier;
for (int i = 0; i < sendingData.count(); i++)
{
if (sendData->triggers.count() > 0)
sendData = &sendingData[i];
if (!sendData->enabled)
{
for (int j = 0; j < sendData->triggers.count(); j++) //resetting currCount when line is disabled
if (sendData->triggers.count() > 0)
{
sendData->triggers[j].currCount = 0;
for (int j = 0; j < sendData->triggers.count(); j++) //resetting currCount when line is disabled
{
sendData->triggers[j].currCount = 0;
}
}
continue; //abort any processing on this if it is not enabled.
}
if (sendData->triggers.count() == 0) break;
for (int j = 0; j < sendData->triggers.count(); j++)
{
trigger = &sendData->triggers[j];
if (trigger->currCount >= trigger->maxCount) continue; //don't process if we've sent max frames we were supposed to
if (!trigger->readyCount) continue; //don't tick if not ready to tick
//is it time to fire?
trigger->msCounter += elapsed; //gives proper tracking even if timer doesn't fire as fast as it should
if (trigger->msCounter >= trigger->milliseconds)
{
trigger->msCounter = 0;
sendData->count++;
trigger->currCount++;
doModifiers(i);
updateGridRow(i);
//qDebug() << "About to try to send a frame";
CANConManager::getInstance()->sendFrame(sendingData[i]);
if (trigger->ID > 0) trigger->readyCount = false; //reset flag if this is a timed ID trigger
}
}
continue; //abort any processing on this if it is not enabled.
}
if (sendData->triggers.count() == 0) return;
for (int j = 0; j < sendData->triggers.count(); j++)
{
trigger = &sendData->triggers[j];
if (trigger->currCount >= trigger->maxCount) continue; //don't process if we've sent max frames we were supposed to
if (!trigger->readyCount) continue; //don't tick if not ready to tick
//is it time to fire?
trigger->msCounter += elapsed; //gives proper tracking even if timer doesn't fire as fast as it should
if (trigger->msCounter >= trigger->milliseconds)
{
trigger->msCounter = 0;
sendData->count++;
trigger->currCount++;
doModifiers(i);
updateGridRow(i);
qDebug() << "About to try to send a frame";
CANConManager::getInstance()->sendFrame(sendingData[i]);
if (trigger->ID > 0) trigger->readyCount = false; //reset flag if this is a timed ID trigger
}
}
mutex.unlock();
}
else
{
qDebug() << "framesenderwindow::handleTick() couldn't get mutex, elapsed is: " << elapsedTimer.elapsed();
}
}
/// <summary>
@@ -479,7 +491,7 @@ void FrameSenderWindow::doModifiers(int idx)
if (sendData->modifiers.count() == 0) return; //if no modifiers just leave right now
qDebug() << "Executing mods";
//qDebug() << "Executing mods";
for (int i = 0; i < sendData->modifiers.count(); i++)
{
@@ -648,10 +660,10 @@ void FrameSenderWindow::processModifierText(int line)
{
thisOp.operation = parseOperation(operation);
QString secondOp = Utility::grabAlphaNumeric(mods[i]);
if (mods[i][0] == '~')
if (secondOp.length() > 0 && secondOp[0] == '~')
{
thisOp.second.notOper = true;
mods[i] = mods[i].remove(0, 1); //remove the ~ character
secondOp = secondOp.remove(0, 1); //remove the ~ character
}
else thisOp.second.notOper = false;
thisOp.second.bus = sendingData[line].bus;
@@ -797,7 +809,7 @@ ModifierOperationType FrameSenderWindow::parseOperation(QString op)
/// <param name="idx"></param>
void FrameSenderWindow::updateGridRow(int idx)
{
qDebug() << "updateGridRow";
//qDebug() << "updateGridRow";
inhibitChanged = true;
FrameSendData *temp = &sendingData[idx];
@@ -807,16 +819,27 @@ void FrameSenderWindow::updateGridRow(int idx)
const unsigned char *data = reinterpret_cast<const unsigned char *>(temp->payload().constData());
int dataLen = temp->payload().length();
if (item == nullptr) item = new QTableWidgetItem();
item->setText(QString::number(temp->count));
if (temp->frameType() != QCanBusFrame::RemoteRequestFrame) {
if (item == nullptr)
{
//item = new QTableWidgetItem();
//item->setText(QString::number(temp->count)); //crashes here ---qt_Static_metacall -> handleTick ->here
}
else
{
item->setText(QString::number(temp->count)); //crashes here ---qt_Static_metacall -> handleTick ->here
}
if (temp->frameType() != QCanBusFrame::RemoteRequestFrame)
{
for (int i = 0; i < dataLen; i++)
{
dataString.append(Utility::formatNumber(data[i]));
dataString.append(" ");
}
ui->tableSender->item(gridLine, 6)->setText(dataString);
} else {
}
else
{
ui->tableSender->item(gridLine, 6)->setText("");
}
inhibitChanged = false;