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) if (QSysInfo::WordSize > 32)
{ {
qDebug() << "64 bit OS detected. Requesting a large preallocation"; 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. 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"; qDebug() << "32 bit OS detected. Requesting a much restricted prealloc";
preallocSize = 4000000; preallocSize = 2000000;
} }
frames.reserve(preallocSize); frames.reserve(preallocSize);
@@ -106,7 +106,7 @@ void CANFrameModel::setInterpetMode(bool mode)
void CANFrameModel::normalizeTiming() void CANFrameModel::normalizeTiming()
{ {
mutex.lock(); mutex.lock();
if (frames.count() == 0) return; if (frames.count() == 0) return;
timeOffset = frames[0].timestamp; timeOffset = frames[0].timestamp;
for (int i = 0; i < frames.count(); i++) 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); if (!timeSeconds) return QString::number(thisFrame.timestamp);
else return QString::number((double)thisFrame.timestamp / 1000000.0, 'f', 6); else return QString::number((double)thisFrame.timestamp / 1000000.0, 'f', 6);
break; break;
case 1: //id case 1: //id
return Utility::formatNumber(thisFrame.ID); return Utility::formatNumber(thisFrame.ID);
break; break;
case 2: //ext case 2: //ext
@@ -281,7 +281,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
tempString.append(sigString); tempString.append(sigString);
tempString.append("\n"); tempString.append("\n");
} }
} }
} }
} }
return tempString; return tempString;
@@ -351,7 +351,7 @@ void CANFrameModel::addFrame(const CANFrame& frame, bool autoRefresh = false)
} }
if (!overwriteDups) if (!overwriteDups)
{ {
frames.append(tempFrame); frames.append(tempFrame);
if (filters[tempFrame.ID]) 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++) for (int i = 0; i < frames.count(); i++)
{ {
if (frames[i].ID == tempFrame.ID) if (frames[i].ID == tempFrame.ID)
{ {
frames.replace(i, tempFrame); frames.replace(i, tempFrame);
found = true; found = true;
break; break;
} }
} }
if (!found) if (!found)
{ {
frames.append(tempFrame); frames.append(tempFrame);
if (filters[tempFrame.ID]) if (filters[tempFrame.ID])
{ {
@@ -409,9 +409,9 @@ void CANFrameModel::addFrames(const CANConnection*, const QVector<CANFrame>& pFr
} }
void CANFrameModel::sendRefresh() void CANFrameModel::sendRefresh()
{ {
qDebug() << "Sending mass refresh"; qDebug() << "Sending mass refresh";
QVector<CANFrame> tempContainer; QVector<CANFrame> tempContainer;
int count = frames.count(); int count = frames.count();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
@@ -423,8 +423,9 @@ void CANFrameModel::sendRefresh()
mutex.lock(); mutex.lock();
beginResetModel(); beginResetModel();
filteredFrames.clear(); filteredFrames.clear();
filteredFrames.append(tempContainer);
filteredFrames.reserve(preallocSize); filteredFrames.reserve(preallocSize);
filteredFrames.append(tempContainer);
lastUpdateNumFrames = filteredFrames.count(); lastUpdateNumFrames = filteredFrames.count();
endResetModel(); endResetModel();
mutex.unlock(); mutex.unlock();
@@ -479,7 +480,7 @@ void CANFrameModel::clearFrames()
* allows for a mass import of frames into the model * allows for a mass import of frames into the model
*/ */
void CANFrameModel::insertFrames(const QVector<CANFrame> &newFrames) 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 //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 //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. //double the number of frames.
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef CONFIG #ifndef CONFIG
#define CONFIG #define CONFIG
#define VERSION 166 #define VERSION 167
//try to keep this in sync. //try to keep this in sync.
//SavvyCAN will complain if you connect a GVRET board with a revision //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) CANConManager::CANConManager(QObject *parent): QObject(parent)
{ {
connect(&mTimer, SIGNAL(timeout()), this, SLOT(refreshCanList())); 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.setSingleShot(false);
mTimer.start(); mTimer.start();
@@ -39,7 +39,7 @@ CANConManager::~CANConManager()
void CANConManager::add(CANConnection* pConn_p) void CANConManager::add(CANConnection* pConn_p)
{ {
mConns.append(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) bool CANConManager::addTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver)
{ {
int tempBusVal; int tempBusVal;
int busBase = 0; int busBase = 0;
foreach (CANConnection* conn, mConns) foreach (CANConnection* conn, mConns)
{ {
+2 -2
View File
@@ -101,7 +101,7 @@ signals:
void suspendCapturing(bool); void suspendCapturing(bool);
//-1 = frames cleared, -2 = a new file has been loaded (so all frames are different), otherwise # of new frames //-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 frameUpdateRapid(int numFrames);
void settingsUpdated(); void settingsUpdated();
void sendCenterTimeID(int32_t ID, double timestamp); void sendCenterTimeID(int32_t ID, double timestamp);
@@ -112,7 +112,7 @@ private:
//canbus related data //canbus related data
CANFrameModel *model; CANFrameModel *model;
DBCHandler *dbcHandler; DBCHandler *dbcHandler;
QByteArray inputBuffer; QByteArray inputBuffer;
QTimer updateTimer; QTimer updateTimer;
QTime *elapsedTime; QTime *elapsedTime;
+55 -49
View File
@@ -17,7 +17,7 @@ UDSScanWindow::UDSScanWindow(const QVector<CANFrame> *frames, QWidget *parent) :
waitTimer->setInterval(100); waitTimer->setInterval(100);
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); 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(ui->btnScan, &QPushButton::clicked, this, &UDSScanWindow::scanUDS);
connect(waitTimer, &QTimer::timeout, this, &UDSScanWindow::timeOut); connect(waitTimer, &QTimer::timeout, this, &UDSScanWindow::timeOut);
@@ -33,6 +33,23 @@ UDSScanWindow::~UDSScanWindow()
delete waitTimer; 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() void UDSScanWindow::scanUDS()
{ {
if (currentlyRunning) if (currentlyRunning)
@@ -43,6 +60,8 @@ void UDSScanWindow::scanUDS()
ui->btnScan->setText("Start Scan"); ui->btnScan->setText("Start Scan");
} }
waitTimer->setInterval(ui->spinDelay->value());
ui->listResults->clear(); ui->listResults->clear();
sendingFrames.clear(); sendingFrames.clear();
@@ -54,62 +73,51 @@ void UDSScanWindow::scanUDS()
int buses = ui->cbBuses->currentIndex(); 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++) for (id = startID; id <= endID; id++)
{ {
frame.ID = id; frame.ID = id;
frame.len = 8; frame.len = 8;
frame.extended = false; 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[0] = 2;
frame.data[1] = 0x10; frame.data[1] = 0x3E; //tester present
frame.data[2] = typ; frame.data[2] = 0;
frame.data[3] = 0;frame.data[4] = 0;frame.data[5] = 0; frame.data[3] = 0;frame.data[4] = 0;frame.data[5] = 0;
frame.data[6] = 0;frame.data[7] = 0; frame.data[6] = 0;frame.data[7] = 0;
sendOnBuses(frame, buses);
if (buses < ui->cbBuses->count()- 1) }
if (ui->ckSession->isChecked())
{
for (typ = 1; typ < 4; typ++) //try each type of session access
{ {
frame.bus = buses; frame.data[0] = 2;
sendingFrames.append(frame); frame.data[1] = 0x10;
} frame.data[2] = typ;
else frame.data[3] = 0;frame.data[4] = 0;frame.data[5] = 0;
{ frame.data[6] = 0;frame.data[7] = 0;
for (int c = 0; c < ui->cbBuses->count() - 1; c++) sendOnBuses(frame, buses);
{
frame.bus = c;
sendingFrames.append(frame);
}
} }
} }
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(); 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! //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! ;( //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; QString result;
uint32_t id; uint32_t id;
int offset = ui->spinReplyOffset->value(); int offset = ui->spinReplyOffset->value();
CANFrame sentFrame; CANFrame sentFrame;
bool gotReply = false; bool gotReply = false;
if (numFrames > modelFrames->count()) return; if (pFrames.length() <= 0) return;
int numSending = sendingFrames.length(); int numSending = sendingFrames.length();
if (numSending == 0) return; if (numSending == 0) return;
if (currIdx >= numSending) return; if (currIdx >= numSending) return;
sentFrame = sendingFrames[currIdx]; sentFrame = sendingFrames[currIdx];
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) foreach(const CANFrame& thisFrame, pFrames)
{ {
if (currIdx >= numSending) return; if (currIdx >= numSending) return;
thisFrame = modelFrames->at(i);
id = thisFrame.ID; id = thisFrame.ID;
if ((id == (uint32_t)(sentFrame.ID + offset)) || ui->cbAllowAdaptiveOffset->isChecked()) if ((id == (uint32_t)(sentFrame.ID + offset)) || ui->cbAllowAdaptiveOffset->isChecked())
+3 -1
View File
@@ -2,6 +2,7 @@
#define UDSSCANWINDOW_H #define UDSSCANWINDOW_H
#include "can_structs.h" #include "can_structs.h"
#include "connections/canconnection.h"
#include <QDialog> #include <QDialog>
@@ -19,7 +20,7 @@ public:
private slots: private slots:
void updatedFrames(int numFrames); void updatedFrames(int numFrames);
void rapidFrames(int numFrames); void rapidFrames(const CANConnection* conn, const QVector<CANFrame>& pFrames);
void scanUDS(); void scanUDS();
void timeOut(); void timeOut();
@@ -32,6 +33,7 @@ private:
bool currentlyRunning; bool currentlyRunning;
void sendNextMsg(); void sendNextMsg();
void sendOnBuses(CANFrame &frame, int buses);
}; };
#endif // UDSSCANWINDOW_H #endif // UDSSCANWINDOW_H
+102 -32
View File
@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>742</width> <width>742</width>
<height>527</height> <height>628</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -65,41 +65,111 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_5"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="text"> <item>
<string>Reply Offset:</string> <widget class="QLabel" name="label_5">
</property> <property name="text">
</widget> <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>
<item> <item>
<widget class="QSpinBox" name="spinReplyOffset"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="minimum"> <item>
<number>-128</number> <widget class="QLabel" name="label_6">
</property> <property name="text">
<property name="maximum"> <string>Scan Types:</string>
<number>128</number> </property>
</property> </widget>
<property name="value"> </item>
<number>8</number> <item>
</property> <widget class="QCheckBox" name="ckTester">
</widget> <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>
<item> <item>
<widget class="QCheckBox" name="cbAllowAdaptiveOffset"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="text"> <item>
<string>Allow adaptive reply offset</string> <widget class="QLabel" name="label">
</property> <property name="text">
</widget> <string>Buses to scan</string>
</item> </property>
<item> </widget>
<widget class="QLabel" name="label"> </item>
<property name="text"> <item>
<string>Buses to scan</string> <widget class="QComboBox" name="cbBuses"/>
</property> </item>
</widget> <item>
</item> <widget class="QLabel" name="label_7">
<item> <property name="text">
<widget class="QComboBox" name="cbBuses"/> <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>
<item> <item>
<widget class="QPushButton" name="btnScan"> <widget class="QPushButton" name="btnScan">