Skip to content

Commit 6fda9cf

Browse files
authored
Merge pull request #1026 from esaulenka/LawicelFixes
Lawicel fixes
2 parents ccb27b7 + 267c93c commit 6fda9cf

7 files changed

Lines changed: 75 additions & 108 deletions

File tree

connections/canconnection.cpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,21 @@ CANConnection::CANConnection(QString pPort,
4242
if (pBusSpeed > 0) mBusData[0].mBus.setSpeed(pBusSpeed);
4343
mBusData[0].mBus.setCanFD(pCanFd);
4444
if (pDataRate > 0) {
45-
mBusData[0].mBus.setDataRate(pDataRate);
46-
if (pCanFd) {
47-
mBusData[0].mBus.setCanFD(pCanFd);
48-
}
45+
mBusData[0].mBus.setDataRate(pDataRate);
46+
if (pCanFd) {
47+
mBusData[0].mBus.setCanFD(pCanFd);
48+
}
4949
}
5050

5151
/* if needed, create a thread and move ourself into it */
5252
if(pUseThread) {
5353
mThread_p = new QThread();
54+
/* move ourself to the thread */
55+
if (!moveToThread(mThread_p)) {
56+
qWarning() << "CANConnection::start(): cannot moveToThread()";
57+
}
58+
/* start the thread */
59+
mThread_p->start(QThread::HighPriority);
5460
}
5561
}
5662

@@ -64,34 +70,23 @@ CANConnection::~CANConnection()
6470
delete mThread_p;
6571
mThread_p = nullptr;
6672
}
67-
68-
mBusData.clear();
6973
}
7074

7175

7276
void CANConnection::start()
7377
{
7478
if( mThread_p && (mThread_p != QThread::currentThread()) )
7579
{
76-
/* move ourself to the thread */
77-
moveToThread(mThread_p); /*TODO handle errors */
78-
/* connect started() */
79-
connect(mThread_p, SIGNAL(started()), this, SLOT(start()));
80-
/* start the thread */
81-
mThread_p->start(QThread::HighPriority);
80+
QMetaObject::invokeMethod(this, "start",
81+
Qt::BlockingQueuedConnection);
8282
return;
8383
}
8484

8585
/* set started flag */
8686
mStarted = true;
8787

8888
QSettings settings;
89-
90-
if (settings.value("Main/TimeClock", false).toBool())
91-
{
92-
useSystemTime = true;
93-
}
94-
else useSystemTime = false;
89+
useSystemTime = settings.value("Main/TimeClock", false).toBool();
9590

9691
/* in multithread case, this will be called before entering thread event loop */
9792
return piStarted();
@@ -115,25 +110,24 @@ void CANConnection::suspend(bool pSuspend)
115110
void CANConnection::stop()
116111
{
117112
/* 1) execute in mThread_p context */
118-
if( mThread_p && mStarted && (mThread_p != QThread::currentThread()) )
113+
if( mThread_p && (mThread_p != QThread::currentThread()) )
119114
{
120115
/* if thread is finished, it means we call this function for the second time so we can leave */
121116
if( !mThread_p->isFinished() )
122117
{
123118
/* we need to call piStop() */
124119
QMetaObject::invokeMethod(this, "stop",
125120
Qt::BlockingQueuedConnection);
126-
/* 3) stop thread */
127-
mThread_p->quit();
128-
if(!mThread_p->wait()) {
129-
qDebug() << "can't stop thread";
130-
}
131121
}
132122
return;
133123
}
134124

135125
/* 2) call piStop in mThread context */
136-
return piStop();
126+
if (mStarted)
127+
{
128+
piStop();
129+
}
130+
mStarted = false;
137131
}
138132

139133

connections/canconnection.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ public slots:
212212
protected:
213213
int mNumBuses; //protected to allow connected device to figure out how many buses are available
214214
QVector<BusData> mBusData;
215-
bool mConsoleOutput; //send debugging info to the console?
216215
int mSerialSpeed;
217216

218217
//determine if the passed frame is part of a filter or not.

connections/connectionwindow.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,15 @@ void ConnectionWindow::saveConnections()
599599

600600
/* save connections */
601601
foreach(CANConnection* conn_p, conns)
602-
{ CANBus bus;
602+
{
603+
CANBus bus;
603604

604605
if (conn_p->getBusSettings(0, bus)) {
605-
busSpeeds.append(bus.getSpeed());
606-
CanFds.append(bus.isCanFD() ? 1 : 0);
607-
DataRates.append(bus.getDataRate());
606+
busSpeeds.append(bus.getSpeed());
607+
CanFds.append(bus.isCanFD() ? 1 : 0);
608+
DataRates.append(bus.getDataRate());
608609
}
609-
serialSpeeds.append(conn_p->getSerialSpeed());
610+
serialSpeeds.append(conn_p->getSerialSpeed());
610611
portNames.append(conn_p->getPort());
611612
devTypes.append(conn_p->getType());
612613
driverNames.append(conn_p->getDriver());

connections/gvretserial.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <QtNetwork>
88

99
#include "gvretserial.h"
10+
#include "canconmanager.h"
1011

1112
GVRetSerial::GVRetSerial(QString portName, bool useTcp) :
1213
CANConnection(portName, "gvret", CANCon::GVRET_SERIAL, 0, 0, false, 0, 3, 4000, true),
@@ -21,7 +22,6 @@ GVRetSerial::GVRetSerial(QString portName, bool useTcp) :
2122
rx_state = IDLE;
2223
rx_step = 0;
2324
validationCounter = 10; //how many times we can miss validation before we die
24-
isAutoRestart = false;
2525
espSerialMode = true;
2626

2727
timeBasis = 0;
@@ -236,8 +236,6 @@ bool GVRetSerial::piSendFrame(const CommFrame& frame)
236236

237237
//qDebug() << "Sending out GVRET frame with id " << frame.ID << " on bus " << frame.bus;
238238

239-
framesRapid++;
240-
241239
if (serial == nullptr && tcpClient == nullptr && udpClient == nullptr) return false;
242240
if (serial && !serial->isOpen()) return false;
243241
if (tcpClient && !tcpClient->isOpen()) return false;
@@ -307,16 +305,16 @@ void GVRetSerial::connectDevice()
307305
sendDebug("TCP Connection to a GVRET device");
308306
tcpClient = new QTcpSocket();
309307
tcpClient->connectToHost(getPort(), 23);
310-
connect(tcpClient, SIGNAL(readyRead()), this, SLOT(readSerialData()));
311-
connect(tcpClient, SIGNAL(connected()), this, SLOT(deviceConnected()));
308+
connect(tcpClient, &QTcpSocket::readyRead, this, &GVRetSerial::readSerialData);
309+
connect(tcpClient, &QTcpSocket::connected, this, &GVRetSerial::deviceConnected);
312310
sendDebug("Created TCP Socket");
313311
// */
314312
/*
315313
qDebug() << "UDP Connection to a GVRET device";
316314
udpClient = new QUdpSocket();
317315
udpClient->connectToHost(getPort(), 17222);
318-
connect(udpClient, SIGNAL(readyRead()), this, SLOT(readSerialData()));
319-
//connect(udpClient, SIGNAL(connected()), this, SLOT(tcpConnected()));
316+
connect(udpClient, &QUdpSocket::readyRead, this, &GVRetSerial::readSerialData);
317+
//connect(udpClient, &QUdpSocket::connected, this, &GVRetSerial::tcpConnected);
320318
debugOutput("Created UDP Socket");
321319
tcpConnected();
322320
*/
@@ -331,8 +329,8 @@ void GVRetSerial::connectDevice()
331329
sendDebug("Created Serial Port Object");
332330

333331
/* connect reading event */
334-
connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData()));
335-
connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(serialError(QSerialPort::SerialPortError)));
332+
connect(serial, &QSerialPort::readyRead, this, &GVRetSerial::readSerialData);
333+
connect(serial, &QSerialPort::errorOccurred, this, &GVRetSerial::serialError);
336334

337335
/* configure */
338336
serial->setBaudRate(1000000); //most GVRET devices ignore baud, ESP32 needs it set explicitly to the proper value
@@ -350,7 +348,7 @@ void GVRetSerial::connectDevice()
350348
{
351349
serial->setDataTerminalReady(false); //ESP32 uses these for bootloader selection and reset so turn them off
352350
serial->setRequestToSend(false);
353-
QTimer::singleShot(3000, this, SLOT(deviceConnected())); //give ESP32 some time as it could have rebooted
351+
QTimer::singleShot(3000, this, &GVRetSerial::deviceConnected); //give ESP32 some time as it could have rebooted
354352
}
355353
}
356354
else
@@ -410,7 +408,7 @@ void GVRetSerial::deviceConnected()
410408
sendToSerial(output);
411409

412410
if(doValidation) {
413-
QTimer::singleShot(5000, this, SLOT(connectionTimeout()));
411+
QTimer::singleShot(5000, this, &GVRetSerial::connectionTimeout);
414412
}
415413
else {
416414
setStatus(CANCon::CONNECTED);
@@ -563,7 +561,7 @@ void GVRetSerial::connectionTimeout()
563561
else
564562
{
565563
/* start timer */
566-
connect(&mTimer, SIGNAL(timeout()), this, SLOT(handleTick()));
564+
connect(&mTimer, &QTimer::timeout, this, &GVRetSerial::handleTick);
567565
mTimer.setInterval(250); //tick four times per second
568566
mTimer.setSingleShot(false); //keep ticking
569567
mTimer.start();
@@ -943,13 +941,13 @@ void GVRetSerial::procRXChar(unsigned char c)
943941
stats.numHardwareBuses = mNumBuses;
944942
emit status(stats);
945943

946-
int can0Status = 0x78; //updating everything we can update
947-
int can1Status = 0x78;
948-
if (can0Enabled) can0Status +=1;
949-
if (can0ListenOnly) can0Status += 4;
950-
if (can1Enabled) can1Status += 1;
951-
if (deviceSingleWireMode > 0) can1Status += 2;
952-
if (can1ListenOnly) can1Status += 4;
944+
// int can0Status = 0x78; //updating everything we can update
945+
// int can1Status = 0x78;
946+
// if (can0Enabled) can0Status +=1;
947+
// if (can0ListenOnly) can0Status += 4;
948+
// if (can1Enabled) can1Status += 1;
949+
// if (deviceSingleWireMode > 0) can1Status += 2;
950+
// if (can1ListenOnly) can1Status += 4;
953951
//emit busStatus(busBase, can0Baud & 0xFFFFF, can0Status);
954952
//emit busStatus(busBase + 1, can1Baud & 0xFFFFF, can1Status);
955953
break;
@@ -1122,7 +1120,7 @@ void GVRetSerial::handleTick()
11221120

11231121
disconnectDevice(); //start by stopping everything.
11241122
//Then wait 500ms and restart the connection automatically
1125-
//QTimer::singleShot(500, this, SLOT(connectDevice()));
1123+
//QTimer::singleShot(500, this, &GVRetSerial::connectDevice);
11261124
return;
11271125
}
11281126
}

connections/gvretserial.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@
77
#include <QTimer>
88
#include <QTcpSocket>
99
#include <QUdpSocket>
10-
11-
/*************/
12-
#include <QDateTime>
13-
/*************/
14-
15-
#include "canframemodel.h"
1610
#include "canconnection.h"
17-
#include "canconmanager.h"
11+
1812

1913
namespace SERIALSTATE {
2014

@@ -80,18 +74,15 @@ private slots:
8074

8175
protected:
8276
QTimer mTimer;
83-
QThread mThread;
8477

8578
bool doValidation;
8679
int validationCounter;
87-
bool isAutoRestart;
8880
bool continuousTimeSync;
8981
bool useTcp;
9082
bool espSerialMode; //special serial mode for ESP32 based boards - no flow control and much slower serial baud speed
9183
QSerialPort *serial;
9284
QTcpSocket *tcpClient;
9385
QUdpSocket *udpClient;
94-
int framesRapid;
9586
STATE rx_state;
9687
int rx_step;
9788
CommFrame buildFrame;

0 commit comments

Comments
 (0)