Fixes to allow for rapid frame updating in screens that need it, more

implementation of UDS scanner (and fixes to make it work with current
code base)
This commit is contained in:
Collin Kidder
2017-05-11 21:42:12 -04:00
parent b309cce30b
commit d38b94120d
7 changed files with 179 additions and 100 deletions
+13 -12
View File
@@ -49,12 +49,12 @@ CANFrameModel::CANFrameModel(QObject *parent)
if (QSysInfo::WordSize > 32)
{
qDebug() << "64 bit OS detected. Requesting a large preallocation";
preallocSize = 20000000;
preallocSize = 10000000;
}
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 = 4000000;
preallocSize = 2000000;
}
frames.reserve(preallocSize);
@@ -106,7 +106,7 @@ void CANFrameModel::setInterpetMode(bool mode)
void CANFrameModel::normalizeTiming()
{
mutex.lock();
if (frames.count() == 0) return;
if (frames.count() == 0) return;
timeOffset = frames[0].timestamp;
for (int i = 0; i < frames.count(); i++)
{
@@ -240,7 +240,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
if (!timeSeconds) return QString::number(thisFrame.timestamp);
else return QString::number((double)thisFrame.timestamp / 1000000.0, 'f', 6);
break;
case 1: //id
case 1: //id
return Utility::formatNumber(thisFrame.ID);
break;
case 2: //ext
@@ -281,7 +281,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
tempString.append(sigString);
tempString.append("\n");
}
}
}
}
}
return tempString;
@@ -351,7 +351,7 @@ void CANFrameModel::addFrame(const CANFrame& frame, bool autoRefresh = false)
}
if (!overwriteDups)
{
{
frames.append(tempFrame);
if (filters[tempFrame.ID])
{
@@ -366,14 +366,14 @@ void CANFrameModel::addFrame(const CANFrame& frame, bool autoRefresh = false)
for (int i = 0; i < frames.count(); i++)
{
if (frames[i].ID == tempFrame.ID)
{
{
frames.replace(i, tempFrame);
found = true;
break;
}
}
if (!found)
{
{
frames.append(tempFrame);
if (filters[tempFrame.ID])
{
@@ -409,9 +409,9 @@ void CANFrameModel::addFrames(const CANConnection*, const QVector<CANFrame>& pFr
}
void CANFrameModel::sendRefresh()
{
{
qDebug() << "Sending mass refresh";
QVector<CANFrame> tempContainer;
QVector<CANFrame> tempContainer;
int count = frames.count();
for (int i = 0; i < count; i++)
{
@@ -423,8 +423,9 @@ void CANFrameModel::sendRefresh()
mutex.lock();
beginResetModel();
filteredFrames.clear();
filteredFrames.append(tempContainer);
filteredFrames.reserve(preallocSize);
filteredFrames.append(tempContainer);
lastUpdateNumFrames = filteredFrames.count();
endResetModel();
mutex.unlock();
@@ -479,7 +480,7 @@ void CANFrameModel::clearFrames()
* allows for a mass import of frames into the model
*/
void CANFrameModel::insertFrames(const QVector<CANFrame> &newFrames)
{
{
//not resetting the model here because the serial worker automatically does a bulk refresh every 1/4 second
//and that refresh will cause the view to update. If you do both it usually ends up thinking you have
//double the number of frames.
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef CONFIG
#define CONFIG
#define VERSION 166
#define VERSION 167
//try to keep this in sync.
//SavvyCAN will complain if you connect a GVRET board with a revision
+3 -3
View File
@@ -17,7 +17,7 @@ CANConManager* CANConManager::getInstance()
CANConManager::CANConManager(QObject *parent): QObject(parent)
{
connect(&mTimer, SIGNAL(timeout()), this, SLOT(refreshCanList()));
mTimer.setInterval(125); /*tick 8 times a second */
mTimer.setInterval(62); /*tick 16 times a second */
mTimer.setSingleShot(false);
mTimer.start();
@@ -39,7 +39,7 @@ CANConManager::~CANConManager()
void CANConManager::add(CANConnection* pConn_p)
{
{
mConns.append(pConn_p);
}
@@ -196,7 +196,7 @@ bool CANConManager::sendFrames(const QList<CANFrame>& pFrames)
bool CANConManager::addTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver)
{
int tempBusVal;
int busBase = 0;
int busBase = 0;
foreach (CANConnection* conn, mConns)
{
+2 -2
View File
@@ -101,7 +101,7 @@ signals:
void suspendCapturing(bool);
//-1 = frames cleared, -2 = a new file has been loaded (so all frames are different), otherwise # of new frames
void framesUpdated(int numFrames); //something has updated the frame list
void framesUpdated(int numFrames); //something has updated the frame list (send at gui update frequency)
void frameUpdateRapid(int numFrames);
void settingsUpdated();
void sendCenterTimeID(int32_t ID, double timestamp);
@@ -112,7 +112,7 @@ private:
//canbus related data
CANFrameModel *model;
DBCHandler *dbcHandler;
DBCHandler *dbcHandler;
QByteArray inputBuffer;
QTimer updateTimer;
QTime *elapsedTime;
+55 -49
View File
@@ -17,7 +17,7 @@ UDSScanWindow::UDSScanWindow(const QVector<CANFrame> *frames, QWidget *parent) :
waitTimer->setInterval(100);
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));
connect(MainWindow::getReference(), SIGNAL(frameUpdateRapid(int)), this, SLOT(rapidFrames(int)));
connect(CANConManager::getInstance(), &CANConManager::framesReceived, this, &UDSScanWindow::rapidFrames);
connect(ui->btnScan, &QPushButton::clicked, this, &UDSScanWindow::scanUDS);
connect(waitTimer, &QTimer::timeout, this, &UDSScanWindow::timeOut);
@@ -33,6 +33,23 @@ UDSScanWindow::~UDSScanWindow()
delete waitTimer;
}
void UDSScanWindow::sendOnBuses(CANFrame &frame, int buses)
{
if (buses < ui->cbBuses->count()- 1)
{
frame.bus = buses;
sendingFrames.append(frame);
}
else
{
for (int c = 0; c < ui->cbBuses->count() - 1; c++)
{
frame.bus = c;
sendingFrames.append(frame);
}
}
}
void UDSScanWindow::scanUDS()
{
if (currentlyRunning)
@@ -43,6 +60,8 @@ void UDSScanWindow::scanUDS()
ui->btnScan->setText("Start Scan");
}
waitTimer->setInterval(ui->spinDelay->value());
ui->listResults->clear();
sendingFrames.clear();
@@ -54,62 +73,51 @@ void UDSScanWindow::scanUDS()
int buses = ui->cbBuses->currentIndex();
//start out by sending tester present to every address to see if anyone replies
for (id = startID; id <= endID; id++)
{
frame.ID = id;
frame.len = 8;
frame.extended = false;
frame.data[0] = 2;
frame.data[1] = 0x3E; //tester present
frame.data[2] = 0;
frame.data[3] = 0;frame.data[4] = 0;frame.data[5] = 0;
frame.data[6] = 0;frame.data[7] = 0;
if (buses < ui->cbBuses->count()- 1)
if (ui->ckTester->isChecked())
{
frame.bus = buses;
sendingFrames.append(frame);
}
else
{
for (int c = 0; c < ui->cbBuses->count() - 1; c++)
{
frame.bus = c;
sendingFrames.append(frame);
}
}
}
//then try asking for the various diagnostic session types
for (typ = 1; typ < 5; typ++)
{
for (id = startID; id <= endID; id++)
{
frame.ID = id;
frame.len = 8;
frame.extended = false;
frame.data[0] = 2;
frame.data[1] = 0x10;
frame.data[2] = typ;
frame.data[1] = 0x3E; //tester present
frame.data[2] = 0;
frame.data[3] = 0;frame.data[4] = 0;frame.data[5] = 0;
frame.data[6] = 0;frame.data[7] = 0;
if (buses < ui->cbBuses->count()- 1)
sendOnBuses(frame, buses);
}
if (ui->ckSession->isChecked())
{
for (typ = 1; typ < 4; typ++) //try each type of session access
{
frame.bus = buses;
sendingFrames.append(frame);
}
else
{
for (int c = 0; c < ui->cbBuses->count() - 1; c++)
{
frame.bus = c;
sendingFrames.append(frame);
}
frame.data[0] = 2;
frame.data[1] = 0x10;
frame.data[2] = typ;
frame.data[3] = 0;frame.data[4] = 0;frame.data[5] = 0;
frame.data[6] = 0;frame.data[7] = 0;
sendOnBuses(frame, buses);
}
}
if (ui->ckReset->isChecked()) //try to command a reset of the ECU. You're likely to know if it works. ;)
{
frame.data[0] = 2;
frame.data[1] = 0x11; //Reset
frame.data[2] = 1; //hard reset. 2 = key off/on 3 = soft reset
frame.data[3] = 0;frame.data[4] = 0;frame.data[5] = 0;
frame.data[6] = 0;frame.data[7] = 0;
sendOnBuses(frame, buses);
}
if (ui->ckSecurity->isChecked()) //try to enter security mode - very likely to get a response if an ECU exists.
{
frame.data[0] = 2;
frame.data[1] = 0x27; //request security mode
frame.data[2] = 1; //request seed from ECU
frame.data[3] = 0;frame.data[4] = 0;frame.data[5] = 0;
frame.data[6] = 0;frame.data[7] = 0;
sendOnBuses(frame, buses);
}
}
waitTimer->start();
@@ -135,26 +143,24 @@ void UDSScanWindow::updatedFrames(int numFrames)
//Updates here are nearly once per millisecond if there is heavy traffic. That's more like it!
//TODO: I really doubt this works anymore with the new connection system. This breaks the UDS scanner for now! ;(
void UDSScanWindow::rapidFrames(int numFrames)
void UDSScanWindow::rapidFrames(const CANConnection* conn, const QVector<CANFrame>& pFrames)
{
CANFrame thisFrame;
QString result;
uint32_t id;
int offset = ui->spinReplyOffset->value();
CANFrame sentFrame;
bool gotReply = false;
if (numFrames > modelFrames->count()) return;
if (pFrames.length() <= 0) return;
int numSending = sendingFrames.length();
if (numSending == 0) return;
if (currIdx >= numSending) return;
sentFrame = sendingFrames[currIdx];
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++)
foreach(const CANFrame& thisFrame, pFrames)
{
if (currIdx >= numSending) return;
thisFrame = modelFrames->at(i);
id = thisFrame.ID;
if ((id == (uint32_t)(sentFrame.ID + offset)) || ui->cbAllowAdaptiveOffset->isChecked())
+3 -1
View File
@@ -2,6 +2,7 @@
#define UDSSCANWINDOW_H
#include "can_structs.h"
#include "connections/canconnection.h"
#include <QDialog>
@@ -19,7 +20,7 @@ public:
private slots:
void updatedFrames(int numFrames);
void rapidFrames(int numFrames);
void rapidFrames(const CANConnection* conn, const QVector<CANFrame>& pFrames);
void scanUDS();
void timeOut();
@@ -32,6 +33,7 @@ private:
bool currentlyRunning;
void sendNextMsg();
void sendOnBuses(CANFrame &frame, int buses);
};
#endif // UDSSCANWINDOW_H
+102 -32
View File
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>742</width>
<height>527</height>
<height>628</height>
</rect>
</property>
<property name="windowTitle">
@@ -65,41 +65,111 @@
</layout>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Reply Offset:</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Reply Offset:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinReplyOffset">
<property name="minimum">
<number>-128</number>
</property>
<property name="maximum">
<number>128</number>
</property>
<property name="value">
<number>8</number>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbAllowAdaptiveOffset">
<property name="text">
<string>Allow adaptive reply offset</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSpinBox" name="spinReplyOffset">
<property name="minimum">
<number>-128</number>
</property>
<property name="maximum">
<number>128</number>
</property>
<property name="value">
<number>8</number>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Scan Types:</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ckTester">
<property name="text">
<string>Tester Present</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ckSession">
<property name="text">
<string>Session Control</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ckReset">
<property name="text">
<string>ECU Reset</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ckSecurity">
<property name="text">
<string>Security Access</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="cbAllowAdaptiveOffset">
<property name="text">
<string>Allow adaptive reply offset</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Buses to scan</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbBuses"/>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Buses to scan</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbBuses"/>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Maximum reply delay</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinDelay">
<property name="minimum">
<number>50</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="btnScan">