Merge branch 'master' of github.com:collin80/SavvyCAN into WIP2

This commit is contained in:
Collin Kidder
2016-08-08 15:37:41 -04:00
8 changed files with 98 additions and 42 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ TEMPLATE = app
SOURCES += main.cpp\ SOURCES += main.cpp\
mainwindow.cpp \ mainwindow.cpp \
canframemodel.cpp \ canframemodel.cpp \
utility.cpp \ utility.cpp \
qcustomplot.cpp \ qcustomplot.cpp \
+19 -6
View File
@@ -43,8 +43,21 @@ int CANFrameModel::columnCount(const QModelIndex &index) const
CANFrameModel::CANFrameModel(QObject *parent) CANFrameModel::CANFrameModel(QObject *parent)
: QAbstractTableModel(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; dbcHandler = NULL;
interpretFrames = false; interpretFrames = false;
overwriteDups = false; overwriteDups = false;
@@ -168,7 +181,7 @@ void CANFrameModel::recalcOverwrite()
while (frames.count() > lastUnique) frames.removeLast(); while (frames.count() > lastUnique) frames.removeLast();
filteredFrames.clear(); filteredFrames.clear();
filteredFrames.reserve(50000000); filteredFrames.reserve(preallocSize);
for (int i = 0; i < frames.count(); i++) for (int i = 0; i < frames.count(); i++)
{ {
@@ -380,7 +393,7 @@ void CANFrameModel::sendRefresh()
beginResetModel(); beginResetModel();
filteredFrames.clear(); filteredFrames.clear();
filteredFrames.append(tempContainer); filteredFrames.append(tempContainer);
filteredFrames.reserve(50000000); filteredFrames.reserve(preallocSize);
lastUpdateNumFrames = filteredFrames.count(); lastUpdateNumFrames = filteredFrames.count();
endResetModel(); endResetModel();
mutex.unlock(); mutex.unlock();
@@ -420,8 +433,8 @@ void CANFrameModel::clearFrames()
frames.clear(); frames.clear();
filteredFrames.clear(); filteredFrames.clear();
filters.clear(); filters.clear();
frames.reserve(50000000); frames.reserve(preallocSize);
filteredFrames.reserve(50000000); filteredFrames.reserve(preallocSize);
this->endResetModel(); this->endResetModel();
lastUpdateNumFrames = 0; lastUpdateNumFrames = 0;
mutex.unlock(); mutex.unlock();
+1
View File
@@ -67,6 +67,7 @@ private:
bool needFilterRefresh; bool needFilterRefresh;
uint64_t timeOffset; uint64_t timeOffset;
int lastUpdateNumFrames; int lastUpdateNumFrames;
uint32_t preallocSize;
}; };
+2 -12
View File
@@ -34,7 +34,6 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
ui->tableConnections->setColumnWidth(7, 75); ui->tableConnections->setColumnWidth(7, 75);
ui->ckSingleWire->setChecked(settings.value("Main/SingleWireMode", false).toBool()); ui->ckSingleWire->setChecked(settings.value("Main/SingleWireMode", false).toBool());
ui->cbSpeed->addItem(tr("<Default>"));
ui->cbSpeed->addItem(tr("125000")); ui->cbSpeed->addItem(tr("125000"));
ui->cbSpeed->addItem(tr("250000")); ui->cbSpeed->addItem(tr("250000"));
ui->cbSpeed->addItem(tr("500000")); ui->cbSpeed->addItem(tr("500000"));
@@ -176,15 +175,7 @@ void ConnectionWindow::handleOKButton()
bus.setListenOnly(ui->ckListenOnly->isChecked()); bus.setListenOnly(ui->ckListenOnly->isChecked());
bus.setSingleWire(ui->ckSingleWire->isChecked()); bus.setSingleWire(ui->ckSingleWire->isChecked());
bus.setEnabled(ui->ckEnabled->isChecked()); bus.setEnabled(ui->ckEnabled->isChecked());
if (ui->cbSpeed->currentIndex() == 0) bus.setSpeed(ui->cbSpeed->currentText().toInt());
{
bus.speed = 0;
bus.setEnabled(false);
}
else if (ui->cbSpeed->currentIndex() >= 1)
{
bus.setSpeed(ui->cbSpeed->currentText().toInt());
}
/* update bus settings */ /* update bus settings */
conn_p->setBusSettings(busId, bus); conn_p->setBusSettings(busId, bus);
@@ -204,8 +195,7 @@ void ConnectionWindow::handleOKButton()
bus.listenOnly = ui->ckListenOnly->isChecked(); bus.listenOnly = ui->ckListenOnly->isChecked();
bus.singleWire = ui->ckSingleWire->isChecked(); bus.singleWire = ui->ckSingleWire->isChecked();
if (ui->cbSpeed->currentIndex() < 1) bus.speed = 0; bus.speed = ui->cbSpeed->currentText().toInt();
else bus.speed = ui->cbSpeed->currentText().toInt();
/* update bus settings */ /* update bus settings */
conn_p->setBusSettings(i, bus); conn_p->setBusSettings(i, bus);
+55 -15
View File
@@ -158,9 +158,9 @@ void FlowViewWindow::writeSettings()
/* /*
* Keyboard shortcuts to allow for quick work without needing to move around a mouse. * Keyboard shortcuts to allow for quick work without needing to move around a mouse.
* E = resume or pause playback * R = resume or pause playback
* Q = go back one frame * T = go back one frame
* W = go forward one frame * Y = go forward one frame
*/ */
bool FlowViewWindow::eventFilter(QObject *obj, QEvent *event) bool FlowViewWindow::eventFilter(QObject *obj, QEvent *event)
{ {
@@ -371,27 +371,64 @@ void FlowViewWindow::updatedFrames(int numFrames)
else //just got some new frames. See if they are relevant. else //just got some new frames. See if they are relevant.
{ {
if (numFrames > modelFrames->count()) return; 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; bool needRefresh = false;
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++)
{ {
thisFrame = modelFrames->at(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) if (thisFrame.ID == refID)
{ {
frameCache.append(thisFrame); 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; 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) if (needRefresh)
{ {
for (int k = 0; k < 8; k++)
{
graphRef[k]->setData(x[k], y[k]);
}
ui->graphView->replot();
updateDataView(); updateDataView();
if (ui->cbSync->checkState() == Qt::Checked) emit sendCenterTimeID(frameCache[currentPosition].ID, frameCache[currentPosition].timestamp / 1000000.0); if (ui->cbSync->checkState() == Qt::Checked) emit sendCenterTimeID(frameCache[currentPosition].ID, frameCache[currentPosition].timestamp / 1000000.0);
} }
} }
updateFrameLabel();
} }
void FlowViewWindow::removeAllGraphs() void FlowViewWindow::removeAllGraphs()
@@ -409,7 +446,10 @@ void FlowViewWindow::createGraph(int byteNum)
int numEntries = frameCache.count(); 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++) for (int j = 0; j < numEntries; j++)
{ {
@@ -418,26 +458,26 @@ void FlowViewWindow::createGraph(int byteNum)
if (graphByTime) if (graphByTime)
{ {
if (secondsMode){ if (secondsMode){
x[j] = (double)(frameCache[j].timestamp) / 1000000.0; x[byteNum][j] = (double)(frameCache[j].timestamp) / 1000000.0;
} }
else else
{ {
x[j] = frameCache[j].timestamp; x[byteNum][j] = frameCache[j].timestamp;
} }
} }
else else
{ {
x[j] = j; x[byteNum][j] = j;
} }
y[j] = tempVal; y[byteNum][j] = tempVal;
if (y[j] < minval) minval = y[j]; if (y[byteNum][j] < minval) minval = y[byteNum][j];
if (y[j] > maxval) maxval = y[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()->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 ui->graphView->graph()->setLineStyle(QCPGraph::lsLine); //connect points with lines
QPen graphPen; QPen graphPen;
graphPen.setColor(graphColors[byteNum]); graphPen.setColor(graphColors[byteNum]);
+2
View File
@@ -55,6 +55,8 @@ private:
bool playbackForward; bool playbackForward;
static const QColor graphColors[8]; static const QColor graphColors[8];
bool secondsMode; bool secondsMode;
QVector<double> x[8], y[8];
QCPGraph *graphRef[8];
void refreshIDList(); void refreshIDList();
void updateFrameLabel(); void updateFrameLabel();
+4
View File
@@ -394,10 +394,12 @@ void FramePlaybackWindow::btnLoadLive()
void FramePlaybackWindow::btnBackOneClick() void FramePlaybackWindow::btnBackOneClick()
{ {
sendingBuffer.clear();
playbackTimer->stop(); //pushing this button halts automatic playback playbackTimer->stop(); //pushing this button halts automatic playback
playbackActive = false; playbackActive = false;
updatePosition(false); updatePosition(false);
emit sendFrameBatch(&sendingBuffer);
} }
void FramePlaybackWindow::btnPauseClick() void FramePlaybackWindow::btnPauseClick()
@@ -444,9 +446,11 @@ void FramePlaybackWindow::btnPlayClick()
void FramePlaybackWindow::btnFwdOneClick() void FramePlaybackWindow::btnFwdOneClick()
{ {
sendingBuffer.clear();
playbackTimer->stop(); playbackTimer->stop();
playbackActive = false; playbackActive = false;
updatePosition(true); updatePosition(true);
emit sendFrameBatch(&sendingBuffer);
} }
void FramePlaybackWindow::changePlaybackSpeed(int newSpeed) void FramePlaybackWindow::changePlaybackSpeed(int newSpeed)
+12 -6
View File
@@ -142,6 +142,7 @@ void GraphingWindow::updatedFrames(int numFrames)
} }
else //just got some new frames. See if they are relevant. else //just got some new frames. See if they are relevant.
{ {
bool appendedToGraph = false;
if (numFrames > modelFrames->count()) return; if (numFrames > modelFrames->count()) return;
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++)
{ {
@@ -151,10 +152,17 @@ void GraphingWindow::updatedFrames(int numFrames)
if (graphParams[j].ID == thisFrame.ID) if (graphParams[j].ID == thisFrame.ID)
{ {
appendToGraph(graphParams[j], thisFrame); 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();
}
} }
} }
@@ -829,7 +837,7 @@ void GraphingWindow::loadDefinitions()
for (int b = 0; b < 8; b++) for (int b = 0; b < 8; b++)
{ {
if (oldMask & (1 << b)) if (oldMask & (1ull << b))
{ {
gp.startBit = (8 * oldEnd) + b; gp.startBit = (8 * oldEnd) + b;
break; break;
@@ -838,7 +846,7 @@ void GraphingWindow::loadDefinitions()
for (int c = 7; c >= 0; c--) 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); gp.numBits -= (7-c);
break; break;
@@ -857,7 +865,7 @@ void GraphingWindow::loadDefinitions()
gp.numBits = 8; gp.numBits = 8;
for (int b = 0; b < 8; b++) for (int b = 0; b < 8; b++)
{ {
if (oldMask & (1 << b)) if (oldMask & (1ull << b))
{ {
gp.startBit = 8 * oldStart + b; gp.startBit = 8 * oldStart + b;
gp.numBits = 8 - b; gp.numBits = 8 - b;
@@ -931,8 +939,6 @@ void GraphingWindow::appendToGraph(GraphParams &params, CANFrame &frame)
params.x.append(frame.timestamp - params.xbias); params.x.append(frame.timestamp - params.xbias);
} }
params.y.append((tempVal * params.scale) + params.bias); params.y.append((tempVal * params.scale) + params.bias);
params.ref->setData(params.x,params.y);
} }
void GraphingWindow::createGraph(GraphParams &params, bool createGraphParam) void GraphingWindow::createGraph(GraphParams &params, bool createGraphParam)