Skip to content

Commit

Permalink
Sender at bottom of main window is now operational.
Browse files Browse the repository at this point in the history
  • Loading branch information
collin80 committed Feb 14, 2024
1 parent a7dd904 commit d5a94a1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 49 deletions.
18 changes: 11 additions & 7 deletions framesenderobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,15 @@ void FrameSenderObject::timerTriggered()
sendingList.clear();
if(mutex.tryLock())
{
//get elapsed microseconds since last tick (in case timer skips or is otherwise inaccurate, though there are no guarantees about elapsed timer either)
quint64 elapsed = sendingElapsed.nsecsElapsed() / 1000;
/*
* Requested tick interval was 1ms but the actual interval could be wildly different. So, we track
* by counting microseconds and accumulating. This creates decent stability even for long intervals
*/
quint64 elapsed = sendingElapsed.nsecsElapsed() / 1000ul;
if (elapsed == 0) elapsed = 1;
sendingElapsed.start();
sendingLastTimeStamp += elapsed;
//qDebug() << playbackLastTimeStamp;
//qDebug() << sendingLastTimeStamp;
//qDebug() << "El: " << elapsed;
statusCounter++;
for (int i = 0; i < sendingData.count(); i++)
Expand All @@ -178,19 +181,20 @@ void FrameSenderObject::timerTriggered()
}
if (sendData->triggers.count() == 0)
{
qDebug() << "No triggers to process";
//qDebug() << "No triggers to process";
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->currCount >= trigger->maxCount) || (trigger->maxCount == -1) ) 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)
//qDebug() << trigger->msCounter;
if (trigger->msCounter >= (trigger->milliseconds * 1000))
{
trigger->msCounter -= trigger->milliseconds;
trigger->msCounter -= (trigger->milliseconds * 1000);
sendData->count++;
trigger->currCount++;
doModifiers(i);
Expand Down
36 changes: 22 additions & 14 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,12 @@ MainWindow::MainWindow(QWidget *parent) :
ui->actionSingle_Multi_State_2->setVisible(false);

QStringList headers;
headers << "En" << "Bus" << "ID" << "Len" << "Ext" << "Rem" << "Data"
headers << "En" << "Bus" << "ID" << "Ext" << "Rem" << "Data"
<< "Interval" << "Count";
ui->tableSimpleSender->setColumnCount(9);
ui->tableSimpleSender->setColumnCount(8);
ui->tableSimpleSender->setColumnWidth(SIMP_COL::SC_COL_EN, 70);
ui->tableSimpleSender->setColumnWidth(SIMP_COL::SC_COL_BUS, 70);
ui->tableSimpleSender->setColumnWidth(SIMP_COL::SC_COL_ID, 70);
ui->tableSimpleSender->setColumnWidth(SIMP_COL::SC_COL_LEN, 70);
ui->tableSimpleSender->setColumnWidth(SIMP_COL::SC_COL_EXT, 70);
ui->tableSimpleSender->setColumnWidth(SIMP_COL::SC_COL_REM, 70);
ui->tableSimpleSender->setColumnWidth(SIMP_COL::SC_COL_DATA, 300);
Expand Down Expand Up @@ -489,7 +488,12 @@ void MainWindow::processSenderCellChange(int line, int col)

if (!tempData)
{
qDebug() << "Need to set up a new entry in senders";
FrameSendData dat;
dat.enabled = false;
dat.count = 0;
dat.frameCount = 0;
dat.bus = 0;
frameSender->addSendRecord(dat);
tempData = frameSender->getSendRecordRef(line);
}
Expand Down Expand Up @@ -530,13 +534,6 @@ void MainWindow::processSenderCellChange(int line, int col)
}
qDebug() << "setting ID to " << tempVal;
break;
case SIMP_COL::SC_COL_LEN:
tempVal = Utility::ParseStringToNum(ui->tableSimpleSender->item(line, SIMP_COL::SC_COL_LEN)->text());
if (tempVal < 0) tempVal = 0;
if (tempVal > 8) tempVal = 8;
arr.resize(tempVal);
tempData->setPayload(arr);
break;
case SIMP_COL::SC_COL_EXT:
if (ui->tableSimpleSender->item(line, SIMP_COL::SC_COL_EXT)->checkState() == Qt::Checked) {
tempData->setExtendedFrameFormat(true);
Expand All @@ -555,9 +552,9 @@ void MainWindow::processSenderCellChange(int line, int col)
for (int i = 0; i < 8; i++) tempData->payload().data()[i] = 0;

#if QT_VERSION >= QT_VERSION_CHECK( 5, 14, 0 )
tokens = ui->tableSimpleSender->item(line, ST_COLS::SENDTAB_COL_DATA)->text().split(" ", Qt::SkipEmptyParts);
tokens = ui->tableSimpleSender->item(line, SIMP_COL::SC_COL_DATA)->text().split(" ", Qt::SkipEmptyParts);
#else
tokens = ui->tableSender->item(line, ST_COLS::SENDTAB_COL_DATA)->text().split(" ", QString::SkipEmptyParts);
tokens = ui->tableSimpleSender->item(line, SIMP_COL::SC_COL_DATA)->text().split(" ", QString::SkipEmptyParts);
#endif
arr.clear();
arr.reserve(tokens.count());
Expand All @@ -569,7 +566,7 @@ void MainWindow::processSenderCellChange(int line, int col)
break;
case SIMP_COL::SC_COL_INTERVAL: //interval in ms

QString trigger = ui->tableSimpleSender->item(line, ST_COLS::SENDTAB_COL_TRIGGER)->text().toUpper();
QString trigger = ui->tableSimpleSender->item(line, SIMP_COL::SC_COL_INTERVAL)->text().toUpper();

Trigger thisTrigger;
thisTrigger.bus = -1; //-1 means we don't care which
Expand Down Expand Up @@ -598,7 +595,6 @@ void MainWindow::processSenderCellChange(int line, int col)
}
}


void MainWindow::createSenderRow()
{
int row = ui->tableSimpleSender->rowCount();
Expand Down Expand Up @@ -1018,6 +1014,18 @@ void MainWindow::tickGUIUpdate()
}
}

//refresh the count for all the frame senders
FrameSendData *tempData;
int numRows = ui->tableSimpleSender->rowCount();
for (int i = 0; i < numRows; i++)
{
tempData = frameSender->getSendRecordRef(i);
if (tempData)
{
ui->tableSimpleSender->item(i, SIMP_COL::SC_COL_COUNT)->setText(QString::number( tempData->count ));
}
}

rxFrames = 0;
//}
}
Expand Down
11 changes: 5 additions & 6 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ enum SIMP_COL
SC_COL_EN = 0,
SC_COL_BUS = 1,
SC_COL_ID = 2,
SC_COL_LEN = 3,
SC_COL_EXT = 4,
SC_COL_REM = 5,
SC_COL_DATA = 6,
SC_COL_INTERVAL = 7,
SC_COL_COUNT = 8,
SC_COL_EXT = 3,
SC_COL_REM = 4,
SC_COL_DATA = 5,
SC_COL_INTERVAL = 6,
SC_COL_COUNT = 7,
};

namespace Ui {
Expand Down
48 changes: 26 additions & 22 deletions ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,34 @@
<string>SavvyCAN</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="5,1">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="4,1">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="3,1">
<item>
<widget class="QTableView" name="canFramesView">
<property name="font">
<font>
<pointsize>11</pointsize>
<bold>false</bold>
</font>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="4,1">
<item>
<widget class="QTableView" name="canFramesView">
<property name="font">
<font>
<pointsize>11</pointsize>
<bold>false</bold>
</font>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableSimpleSender"/>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -364,9 +371,6 @@
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="tableSimpleSender"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
Expand Down

0 comments on commit d5a94a1

Please sign in to comment.