diff --git a/canframemodel.cpp b/canframemodel.cpp index a130a13..e02d425 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -66,6 +66,9 @@ CANFrameModel::CANFrameModel(QObject *parent) //the goal is to prevent a reallocation from ever happening frames.reserve(preallocSize); + //this is pretty wasteful. We're storing all frames twice. It may be better for filteredFrames to be a list of pointers. + //Pointers take up 8 bytes instead of 56 so this is quite a savings for RAM usage. But, then filteredFrames would + //work differently from frames above so the two could not be used interchangeably. Still think about what can be done. filteredFrames.reserve(preallocSize); dbcHandler = DBCHandler::getReference(); diff --git a/config.h b/config.h index 10428fa..01c1845 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #ifndef CONFIG #define CONFIG -#define VERSION 211 +#define VERSION 212 //try to keep this in sync. //SavvyCAN will complain if you connect a GVRET board with a revision diff --git a/frameplaybackwindow.cpp b/frameplaybackwindow.cpp index 30167a5..93515c1 100644 --- a/frameplaybackwindow.cpp +++ b/frameplaybackwindow.cpp @@ -1,4 +1,5 @@ #include "frameplaybackwindow.h" +#include "mainwindow.h" #include "ui_frameplaybackwindow.h" #include #include @@ -48,6 +49,8 @@ FramePlaybackWindow::FramePlaybackWindow(const QVector *frames, QWidge currentPosition = 0; forward = true; isPlaying = false; + wantPlaying = false; + haveIncomingTraffic = false; updateFrameLabel(); @@ -72,6 +75,7 @@ FramePlaybackWindow::FramePlaybackWindow(const QVector *frames, QWidge connect(ui->btnLoadFilters, &QAbstractButton::clicked, this, &FramePlaybackWindow::loadFilters); connect(ui->btnSaveFilters, &QAbstractButton::clicked, this, &FramePlaybackWindow::saveFilters); connect(ui->cbOriginalTiming, &QCheckBox::toggled, this, &FramePlaybackWindow::useOrigTimingClicked); + connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); connect(&playbackObject, &FramePlaybackObject::EndOfFrameCache, this, &FramePlaybackWindow::EndOfFrameCache); connect(&playbackObject, &FramePlaybackObject::statusUpdate, this, &FramePlaybackWindow::getStatusUpdate); @@ -101,6 +105,8 @@ void FramePlaybackWindow::showEvent(QShowEvent *) { readSettings(); installEventFilter(this); + + //any time the view is shown we'll go see how many buses are registered and redo the combobox to match int numBuses = CANConManager::getInstance()->getNumBuses(); ui->comboCANBus->clear(); for (int n = 0; n < numBuses; n++) ui->comboCANBus->addItem(QString::number(n)); @@ -279,6 +285,32 @@ void FramePlaybackWindow::loadFilters() } } +void FramePlaybackWindow::updatedFrames(int numFrames) +{ + CANFrame thisFrame; + + if (numFrames == -1) //all frames deleted. Don't care + { + } + else if (numFrames == -2) //all new set of frames. Don't care + { + } + else //just got some new frames. + { + if (numFrames > 0) + { + haveIncomingTraffic = true; + if (wantPlaying && !isPlaying) + { + isPlaying = true; + updateFrameLabel(); + if (forward) playbackObject.startPlaybackForward(); + else playbackObject.startPlaybackBackward(); + } + } + } +} + void FramePlaybackWindow::refreshIDList() { if (currentSeqNum < 0 || currentSeqItem == nullptr) @@ -338,6 +370,8 @@ void FramePlaybackWindow::EndOfFrameCache() else //not looping so stop playback entirely { isPlaying = false; + wantPlaying = false; + haveIncomingTraffic = false; playbackObject.stopPlayback(); } } @@ -361,6 +395,8 @@ void FramePlaybackWindow::EndOfFrameCache() else //not looping so stop playback entirely { isPlaying = false; + wantPlaying = false; + haveIncomingTraffic = false; playbackObject.stopPlayback(); } } @@ -395,7 +431,10 @@ void FramePlaybackWindow::updateFrameLabel() ui->lblCurrPlayback->setText(currentSeqItem->filename); - ui->lblPosition->setText(QString::number(currentPosition) + tr(" of ") + QString::number(seqItems[row].data.count())); + if (wantPlaying && !isPlaying) + ui->lblPosition->setText(QString::number(currentPosition) + tr(" of ") + QString::number(seqItems[row].data.count()) + " (WAITING)"); + else + ui->lblPosition->setText(QString::number(currentPosition) + tr(" of ") + QString::number(seqItems[row].data.count())); } void FramePlaybackWindow::seqTableCellClicked(int row, int col) @@ -539,26 +578,36 @@ void FramePlaybackWindow::btnBackOneClick() { forward = false; isPlaying = false; + wantPlaying = false; playbackObject.stepPlaybackBackward(); + updateFrameLabel(); } void FramePlaybackWindow::btnPauseClick() { isPlaying = false; + wantPlaying = false; playbackObject.pausePlayback(); + updateFrameLabel(); } void FramePlaybackWindow::btnReverseClick() { forward = false; - isPlaying = true; - playbackObject.startPlaybackBackward(); + wantPlaying = true; + if (!ui->ckWaitForTraffic->isChecked()) + { + playbackObject.startPlaybackBackward(); + isPlaying = true; + } updateFrameLabel(); } void FramePlaybackWindow::btnStopClick() { isPlaying = false; + wantPlaying = false; + haveIncomingTraffic = false; playbackObject.stopPlayback(); if (seqItems.count() > 0) { @@ -574,20 +623,28 @@ void FramePlaybackWindow::btnStopClick() ui->tblSequence->setCurrentCell(0, 0); refreshIDList(); } + updateFrameLabel(); } void FramePlaybackWindow::btnPlayClick() { forward = true; - isPlaying = true; - playbackObject.startPlaybackForward(); + wantPlaying = true; + if (!ui->ckWaitForTraffic->isChecked()) + { + playbackObject.startPlaybackForward(); + isPlaying = true; + } + updateFrameLabel(); } void FramePlaybackWindow::btnFwdOneClick() { forward = true; isPlaying = false; + wantPlaying = false; playbackObject.stepPlaybackForward(); + updateFrameLabel(); } void FramePlaybackWindow::changePlaybackSpeed(int newSpeed) diff --git a/frameplaybackwindow.h b/frameplaybackwindow.h index 64bb149..860b614 100644 --- a/frameplaybackwindow.h +++ b/frameplaybackwindow.h @@ -44,6 +44,7 @@ private slots: void useOrigTimingClicked(); void getStatusUpdate(int frameNum); void EndOfFrameCache(); + void updatedFrames(int); private: Ui::FramePlaybackWindow *ui; @@ -55,8 +56,10 @@ private: int currentSeqNum; FramePlaybackObject playbackObject; bool forward; + bool wantPlaying; bool isPlaying; int currentPosition; + bool haveIncomingTraffic = false; void refreshIDList(); void updateFrameLabel(); diff --git a/ui/frameplaybackwindow.ui b/ui/frameplaybackwindow.ui index b49c350..a8c3d8a 100644 --- a/ui/frameplaybackwindow.ui +++ b/ui/frameplaybackwindow.ui @@ -107,6 +107,13 @@ + + + + Wait for traffic before starting playback + + +