Skip to content

Commit

Permalink
Merge branch 'master' of github.com:collin80/SavvyCAN into WIP2
Browse files Browse the repository at this point in the history
  • Loading branch information
collin80 committed Aug 8, 2016
2 parents 4885b4b + 8ab3042 commit 6a8b20a
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 42 deletions.
2 changes: 1 addition & 1 deletion SavvyCAN.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
mainwindow.cpp \
canframemodel.cpp \
utility.cpp \
qcustomplot.cpp \
Expand Down
25 changes: 19 additions & 6 deletions canframemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,21 @@ int CANFrameModel::columnCount(const QModelIndex &index) const
CANFrameModel::CANFrameModel(QObject *parent)
: QAbstractTableModel(parent)
{
frames.reserve(50000000); //yes, preallocating a huge number of frames.
filteredFrames.reserve(50000000); //the goal is to prevent a reallocation from ever happening

if (QSysInfo::WordSize > 32)
{
qDebug() << "64 bit OS detected. Requesting a large preallocation";
preallocSize = 50000000;
}
else //if compiling for 32 bit you can't ask for gigabytes of preallocation so tone it down.
{
qDebug() << "32 bit OS detected. Requesting a much restricted prealloc";
preallocSize = 5000000;
}

frames.reserve(preallocSize);
filteredFrames.reserve(preallocSize); //the goal is to prevent a reallocation from ever happening

dbcHandler = NULL;
interpretFrames = false;
overwriteDups = false;
Expand Down Expand Up @@ -168,7 +181,7 @@ void CANFrameModel::recalcOverwrite()
while (frames.count() > lastUnique) frames.removeLast();

filteredFrames.clear();
filteredFrames.reserve(50000000);
filteredFrames.reserve(preallocSize);

for (int i = 0; i < frames.count(); i++)
{
Expand Down Expand Up @@ -380,7 +393,7 @@ void CANFrameModel::sendRefresh()
beginResetModel();
filteredFrames.clear();
filteredFrames.append(tempContainer);
filteredFrames.reserve(50000000);
filteredFrames.reserve(preallocSize);
lastUpdateNumFrames = filteredFrames.count();
endResetModel();
mutex.unlock();
Expand Down Expand Up @@ -420,8 +433,8 @@ void CANFrameModel::clearFrames()
frames.clear();
filteredFrames.clear();
filters.clear();
frames.reserve(50000000);
filteredFrames.reserve(50000000);
frames.reserve(preallocSize);
filteredFrames.reserve(preallocSize);
this->endResetModel();
lastUpdateNumFrames = 0;
mutex.unlock();
Expand Down
1 change: 1 addition & 0 deletions canframemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public slots:
bool needFilterRefresh;
uint64_t timeOffset;
int lastUpdateNumFrames;
uint32_t preallocSize;
};


Expand Down
14 changes: 2 additions & 12 deletions connectionwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
ui->tableConnections->setColumnWidth(7, 75);
ui->ckSingleWire->setChecked(settings.value("Main/SingleWireMode", false).toBool());

ui->cbSpeed->addItem(tr("<Default>"));
ui->cbSpeed->addItem(tr("125000"));
ui->cbSpeed->addItem(tr("250000"));
ui->cbSpeed->addItem(tr("500000"));
Expand Down Expand Up @@ -176,15 +175,7 @@ void ConnectionWindow::handleOKButton()
bus.setListenOnly(ui->ckListenOnly->isChecked());
bus.setSingleWire(ui->ckSingleWire->isChecked());
bus.setEnabled(ui->ckEnabled->isChecked());
if (ui->cbSpeed->currentIndex() == 0)
{
bus.speed = 0;
bus.setEnabled(false);
}
else if (ui->cbSpeed->currentIndex() >= 1)
{
bus.setSpeed(ui->cbSpeed->currentText().toInt());
}
bus.setSpeed(ui->cbSpeed->currentText().toInt());
/* update bus settings */
conn_p->setBusSettings(busId, bus);

Expand All @@ -204,8 +195,7 @@ void ConnectionWindow::handleOKButton()
bus.listenOnly = ui->ckListenOnly->isChecked();
bus.singleWire = ui->ckSingleWire->isChecked();

if (ui->cbSpeed->currentIndex() < 1) bus.speed = 0;
else bus.speed = ui->cbSpeed->currentText().toInt();
bus.speed = ui->cbSpeed->currentText().toInt();

/* update bus settings */
conn_p->setBusSettings(i, bus);
Expand Down
74 changes: 57 additions & 17 deletions flowviewwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ void FlowViewWindow::writeSettings()

/*
* Keyboard shortcuts to allow for quick work without needing to move around a mouse.
* E = resume or pause playback
* Q = go back one frame
* W = go forward one frame
* R = resume or pause playback
* T = go back one frame
* Y = go forward one frame
*/
bool FlowViewWindow::eventFilter(QObject *obj, QEvent *event)
{
Expand Down Expand Up @@ -371,27 +371,64 @@ void FlowViewWindow::updatedFrames(int numFrames)
else //just got some new frames. See if they are relevant.
{
if (numFrames > modelFrames->count()) return;
int refID = frameCache[0].ID;
int refID;
if (frameCache.count() > 0) refID = frameCache[0].ID;
else refID = 0;
bool needRefresh = false;
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++)
{
thisFrame = modelFrames->at(i);

if (!foundID.contains(thisFrame.ID))
{
foundID.append(thisFrame.ID);
QListWidgetItem* item = new QListWidgetItem(Utility::formatNumber(thisFrame.ID), ui->listFrameID);
}

if (thisFrame.ID == refID)
{
frameCache.append(thisFrame);
if (ui->cbLiveMode->checkState() == Qt::Checked)

for (int k = 0; k < 8; k++)
{
currentPosition = frameCache.count() - 1;
if (ui->cbTimeGraph->isChecked())
{
if (secondsMode){
x[k].append((double)(thisFrame.timestamp) / 1000000.0);
}
else
{
x[k].append(thisFrame.timestamp);
}
}
else
{
x[k].append(x[k].count());
}
y[k].append(thisFrame.data[k]);
needRefresh = true;
}
}
}
}
if (ui->cbLiveMode->checkState() == Qt::Checked)
{
currentPosition = frameCache.count() - 1;
memcpy(currBytes, frameCache.at(currentPosition).data, 8);
memcpy(refBytes, currBytes, 8);

}
if (needRefresh)
{
updateDataView();
for (int k = 0; k < 8; k++)
{
graphRef[k]->setData(x[k], y[k]);
}
ui->graphView->replot();
updateDataView();
if (ui->cbSync->checkState() == Qt::Checked) emit sendCenterTimeID(frameCache[currentPosition].ID, frameCache[currentPosition].timestamp / 1000000.0);
}
}
updateFrameLabel();
}

void FlowViewWindow::removeAllGraphs()
Expand All @@ -409,7 +446,10 @@ void FlowViewWindow::createGraph(int byteNum)

int numEntries = frameCache.count();

QVector<double> x(numEntries), y(numEntries);
x[byteNum].clear();
y[byteNum].clear();
x[byteNum].resize(numEntries);
y[byteNum].resize(numEntries);

for (int j = 0; j < numEntries; j++)
{
Expand All @@ -418,26 +458,26 @@ void FlowViewWindow::createGraph(int byteNum)
if (graphByTime)
{
if (secondsMode){
x[j] = (double)(frameCache[j].timestamp) / 1000000.0;
x[byteNum][j] = (double)(frameCache[j].timestamp) / 1000000.0;
}
else
{
x[j] = frameCache[j].timestamp;
x[byteNum][j] = frameCache[j].timestamp;
}
}
else
{
x[j] = j;
x[byteNum][j] = j;
}

y[j] = tempVal;
if (y[j] < minval) minval = y[j];
if (y[j] > maxval) maxval = y[j];
y[byteNum][j] = tempVal;
if (y[byteNum][j] < minval) minval = y[byteNum][j];
if (y[byteNum][j] > maxval) maxval = y[byteNum][j];
}

ui->graphView->addGraph();
graphRef[byteNum] = ui->graphView->addGraph();
ui->graphView->graph()->setName(QString("Graph %1").arg(ui->graphView->graphCount()-1));
ui->graphView->graph()->setData(x,y);
ui->graphView->graph()->setData(x[byteNum],y[byteNum]);
ui->graphView->graph()->setLineStyle(QCPGraph::lsLine); //connect points with lines
QPen graphPen;
graphPen.setColor(graphColors[byteNum]);
Expand Down
2 changes: 2 additions & 0 deletions flowviewwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ private slots:
bool playbackForward;
static const QColor graphColors[8];
bool secondsMode;
QVector<double> x[8], y[8];
QCPGraph *graphRef[8];

void refreshIDList();
void updateFrameLabel();
Expand Down
4 changes: 4 additions & 0 deletions frameplaybackwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,12 @@ void FramePlaybackWindow::btnLoadLive()

void FramePlaybackWindow::btnBackOneClick()
{
sendingBuffer.clear();
playbackTimer->stop(); //pushing this button halts automatic playback
playbackActive = false;

updatePosition(false);
emit sendFrameBatch(&sendingBuffer);
}

void FramePlaybackWindow::btnPauseClick()
Expand Down Expand Up @@ -444,9 +446,11 @@ void FramePlaybackWindow::btnPlayClick()

void FramePlaybackWindow::btnFwdOneClick()
{
sendingBuffer.clear();
playbackTimer->stop();
playbackActive = false;
updatePosition(true);
emit sendFrameBatch(&sendingBuffer);
}

void FramePlaybackWindow::changePlaybackSpeed(int newSpeed)
Expand Down
18 changes: 12 additions & 6 deletions graphingwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void GraphingWindow::updatedFrames(int numFrames)
}
else //just got some new frames. See if they are relevant.
{
bool appendedToGraph = false;
if (numFrames > modelFrames->count()) return;
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++)
{
Expand All @@ -151,10 +152,17 @@ void GraphingWindow::updatedFrames(int numFrames)
if (graphParams[j].ID == thisFrame.ID)
{
appendToGraph(graphParams[j], thisFrame);
appendedToGraph = true;
}
}
}
ui->graphingView->replot();
if (appendedToGraph) {
for (int j = 0; j < graphParams.count(); j++)
{
graphParams[j].ref->setData(graphParams[j].x, graphParams[j].y);
}
ui->graphingView->replot();
}
}
}

Expand Down Expand Up @@ -829,7 +837,7 @@ void GraphingWindow::loadDefinitions()

for (int b = 0; b < 8; b++)
{
if (oldMask & (1 << b))
if (oldMask & (1ull << b))
{
gp.startBit = (8 * oldEnd) + b;
break;
Expand All @@ -838,7 +846,7 @@ void GraphingWindow::loadDefinitions()

for (int c = 7; c >= 0; c--)
{
if ( oldMask & (1<<(((numBytes - 1) * 8) + c)) )
if ( oldMask & (1ull << (((numBytes - 1) * 8) + c)) )
{
gp.numBits -= (7-c);
break;
Expand All @@ -857,7 +865,7 @@ void GraphingWindow::loadDefinitions()
gp.numBits = 8;
for (int b = 0; b < 8; b++)
{
if (oldMask & (1 << b))
if (oldMask & (1ull << b))
{
gp.startBit = 8 * oldStart + b;
gp.numBits = 8 - b;
Expand Down Expand Up @@ -931,8 +939,6 @@ void GraphingWindow::appendToGraph(GraphParams &params, CANFrame &frame)
params.x.append(frame.timestamp - params.xbias);
}
params.y.append((tempVal * params.scale) + params.bias);

params.ref->setData(params.x,params.y);
}

void GraphingWindow::createGraph(GraphParams &params, bool createGraphParam)
Expand Down

0 comments on commit 6a8b20a

Please sign in to comment.