diff --git a/canframemodel.cpp b/canframemodel.cpp index 92f7fa0..1aab17d 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -17,6 +17,7 @@ CANFrameModel::CANFrameModel(QObject *parent) dbcHandler = NULL; interpretFrames = false; overwriteDups = false; + timeOffset = 0; } void CANFrameModel::setDBCHandler(DBCHandler *handler) @@ -36,6 +37,18 @@ void CANFrameModel::setInterpetMode(bool mode) } } +void CANFrameModel::normalizeTiming() +{ + if (frames.count() == 0) return; + this->beginResetModel(); + timeOffset = frames[0].timestamp; + for (int i = 0; i < frames.count(); i++) + { + frames[i].timestamp -= timeOffset; + } + this->endResetModel(); +} + void CANFrameModel::setOverwriteMode(bool mode) { overwriteDups = mode; @@ -140,6 +153,7 @@ void CANFrameModel::addFrame(CANFrame &frame, bool autoRefresh = false) { mutex.lock(); if (autoRefresh) beginInsertRows(QModelIndex(), frames.count() + 1, frames.count() + 1); + frame.timestamp -= timeOffset; frames.append(frame); if (autoRefresh) endInsertRows(); mutex.unlock(); diff --git a/canframemodel.h b/canframemodel.h index 51d7f8a..fffb73f 100644 --- a/canframemodel.h +++ b/canframemodel.h @@ -29,6 +29,7 @@ public: void setDBCHandler(DBCHandler *); void setInterpetMode(bool); void setOverwriteMode(bool); + void normalizeTiming(); QVector *getListReference(); @@ -38,6 +39,7 @@ private: QMutex mutex; bool interpretFrames; //should we use the dbcHandler? bool overwriteDups; //should we display all frames or only the newest for each ID? + uint64_t timeOffset; }; diff --git a/mainwindow.cpp b/mainwindow.cpp index a03b963..65f6569 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -130,6 +130,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionSave_Decoded_Frames, SIGNAL(triggered(bool)), this, SLOT(handleSaveDecoded())); connect(ui->actionSingle_Multi_State, SIGNAL(triggered(bool)), this, SLOT(showSingleMultiWindow())); connect(ui->actionFile_Comparison, SIGNAL(triggered(bool)), this, SLOT(showComparisonWindow())); + connect(ui->btnNormalize, SIGNAL(clicked(bool)), this, SLOT(normalizeTiming())); lbStatusConnected.setText(tr("Not connected")); updateFileStatus(); @@ -268,6 +269,11 @@ void MainWindow::clearFrames() emit framesUpdated(-1); } +void MainWindow::normalizeTiming() +{ + model->normalizeTiming(); +} + void MainWindow::changeBaudRates() { int Speed1 = 0, Speed2 = 0; diff --git a/mainwindow.h b/mainwindow.h index d037b7e..d3527f6 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -58,6 +58,7 @@ private slots: void overwriteToggled(bool); void showDBCEditor(); void toggleCapture(); + void normalizeTiming(); public slots: void gotFrames(int, int); diff --git a/mainwindow.ui b/mainwindow.ui index d0ccf66..ce7faad 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -201,6 +201,13 @@ + + + + Normalize Frame Timing + + +