It's now possible to freely connect and disconnect from/to the GVRET device.
This commit is contained in:
+21
-6
@@ -85,6 +85,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(worker, &SerialWorker::connectionSuccess, this, &MainWindow::connectionSucceeded, Qt::QueuedConnection);
|
connect(worker, &SerialWorker::connectionSuccess, this, &MainWindow::connectionSucceeded, Qt::QueuedConnection);
|
||||||
connect(worker, &SerialWorker::connectionFailure, this, &MainWindow::connectionFailed, Qt::QueuedConnection);
|
connect(worker, &SerialWorker::connectionFailure, this, &MainWindow::connectionFailed, Qt::QueuedConnection);
|
||||||
connect(worker, &SerialWorker::deviceInfo, this, &MainWindow::gotDeviceInfo, Qt::QueuedConnection);
|
connect(worker, &SerialWorker::deviceInfo, this, &MainWindow::gotDeviceInfo, Qt::QueuedConnection);
|
||||||
|
connect(this, &MainWindow::closeSerialPort, worker, &SerialWorker::closeSerialPort, Qt::QueuedConnection);
|
||||||
serialWorkerThread.start();
|
serialWorkerThread.start();
|
||||||
|
|
||||||
graphingWindow = NULL;
|
graphingWindow = NULL;
|
||||||
@@ -116,6 +117,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->statusBar->addWidget(&lbStatusConnected);
|
ui->statusBar->addWidget(&lbStatusConnected);
|
||||||
ui->statusBar->addWidget(&lbStatusBauds);
|
ui->statusBar->addWidget(&lbStatusBauds);
|
||||||
ui->statusBar->addWidget(&lbStatusDatabase);
|
ui->statusBar->addWidget(&lbStatusDatabase);
|
||||||
|
|
||||||
|
isConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@@ -654,15 +657,25 @@ void MainWindow::showEditSignalsWindow()
|
|||||||
|
|
||||||
void MainWindow::connButtonPress()
|
void MainWindow::connButtonPress()
|
||||||
{
|
{
|
||||||
for (int x = 0; x < ports.count(); x++)
|
if (!isConnected)
|
||||||
{
|
{
|
||||||
if (ports.at(x).portName() == ui->cbSerialPorts->currentText())
|
for (int x = 0; x < ports.count(); x++)
|
||||||
{
|
{
|
||||||
emit sendSerialPort(&ports[x]);
|
if (ports.at(x).portName() == ui->cbSerialPorts->currentText())
|
||||||
lbStatusConnected.setText(tr("Attempting to connect to port ") + ports[x].portName());
|
{
|
||||||
return;
|
emit sendSerialPort(&ports[x]);
|
||||||
|
lbStatusConnected.setText(tr("Attempting to connect to port ") + ports[x].portName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit closeSerialPort();
|
||||||
|
isConnected = false;
|
||||||
|
lbStatusConnected.setText(tr("Not Connected"));
|
||||||
|
ui->btnConnect->setText(tr("Connect to GVRET"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::connectionSucceeded(int baud0, int baud1)
|
void MainWindow::connectionSucceeded(int baud0, int baud1)
|
||||||
@@ -688,7 +701,9 @@ void MainWindow::connectionSucceeded(int baud0, int baud1)
|
|||||||
ui->cbSpeed2->addItem(QString::number(baud1));
|
ui->cbSpeed2->addItem(QString::number(baud1));
|
||||||
ui->cbSpeed2->setCurrentIndex(ui->cbSpeed2->count() - 1);
|
ui->cbSpeed2->setCurrentIndex(ui->cbSpeed2->count() - 1);
|
||||||
}
|
}
|
||||||
ui->btnConnect->setEnabled(false);
|
//ui->btnConnect->setEnabled(false);
|
||||||
|
ui->btnConnect->setText(tr("Disconnect from GVRET"));
|
||||||
|
isConnected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::connectionFailed()
|
void MainWindow::connectionFailed()
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public slots:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sendSerialPort(QSerialPortInfo *port);
|
void sendSerialPort(QSerialPortInfo *port);
|
||||||
|
void closeSerialPort();
|
||||||
void updateBaudRates(int, int);
|
void updateBaudRates(int, int);
|
||||||
void sendCANFrame(const CANFrame *, int);
|
void sendCANFrame(const CANFrame *, int);
|
||||||
|
|
||||||
@@ -69,6 +70,7 @@ private:
|
|||||||
QLabel lbStatusConnected;
|
QLabel lbStatusConnected;
|
||||||
QLabel lbStatusBauds;
|
QLabel lbStatusBauds;
|
||||||
QLabel lbStatusDatabase;
|
QLabel lbStatusDatabase;
|
||||||
|
bool isConnected;
|
||||||
void loadCRTDFile(QString);
|
void loadCRTDFile(QString);
|
||||||
void loadNativeCSVFile(QString);
|
void loadNativeCSVFile(QString);
|
||||||
void loadGenericCSVFile(QString);
|
void loadGenericCSVFile(QString);
|
||||||
|
|||||||
+26
-6
@@ -11,12 +11,8 @@ SerialWorker::SerialWorker(CANFrameModel *model, QObject *parent) : QObject(pare
|
|||||||
rx_step = 0;
|
rx_step = 0;
|
||||||
buildFrame = new CANFrame;
|
buildFrame = new CANFrame;
|
||||||
canModel = model;
|
canModel = model;
|
||||||
ticker.setInterval(250); //tick four times per second
|
|
||||||
ticker.setSingleShot(false); //keep ticking
|
|
||||||
ticker.start();
|
|
||||||
gotFrames = 0;
|
gotFrames = 0;
|
||||||
|
ticker = NULL;
|
||||||
connect(&ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SerialWorker::~SerialWorker()
|
SerialWorker::~SerialWorker()
|
||||||
@@ -32,7 +28,7 @@ SerialWorker::~SerialWorker()
|
|||||||
serial->disconnect(); //disconnect all signals
|
serial->disconnect(); //disconnect all signals
|
||||||
delete serial;
|
delete serial;
|
||||||
}
|
}
|
||||||
ticker.stop();
|
ticker->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialWorker::setSerialPort(QSerialPortInfo *port)
|
void SerialWorker::setSerialPort(QSerialPortInfo *port)
|
||||||
@@ -68,6 +64,14 @@ void SerialWorker::setSerialPort(QSerialPortInfo *port)
|
|||||||
connected = false;
|
connected = false;
|
||||||
connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData()));
|
connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData()));
|
||||||
QTimer::singleShot(1000, this, SLOT(connectionTimeout()));
|
QTimer::singleShot(1000, this, SLOT(connectionTimeout()));
|
||||||
|
if (ticker == NULL)
|
||||||
|
{
|
||||||
|
ticker = new QTimer;
|
||||||
|
connect(ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
|
||||||
|
}
|
||||||
|
ticker->setInterval(250); //tick four times per second
|
||||||
|
ticker->setSingleShot(false); //keep ticking
|
||||||
|
ticker->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialWorker::connectionTimeout()
|
void SerialWorker::connectionTimeout()
|
||||||
@@ -77,6 +81,7 @@ void SerialWorker::connectionTimeout()
|
|||||||
{
|
{
|
||||||
//then emit the the failure signal and see if anyone cares
|
//then emit the the failure signal and see if anyone cares
|
||||||
qDebug() << "Failed to connect to GVRET at that com port";
|
qDebug() << "Failed to connect to GVRET at that com port";
|
||||||
|
ticker->stop();
|
||||||
emit connectionFailure();
|
emit connectionFailure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,6 +340,7 @@ void SerialWorker::procRXChar(unsigned char c)
|
|||||||
|
|
||||||
void SerialWorker::handleTick()
|
void SerialWorker::handleTick()
|
||||||
{
|
{
|
||||||
|
//qDebug() << "Tick!";
|
||||||
if (gotFrames > 0)
|
if (gotFrames > 0)
|
||||||
{
|
{
|
||||||
emit receivedFrames(); //notify interested parties that there are new frames
|
emit receivedFrames(); //notify interested parties that there are new frames
|
||||||
@@ -342,3 +348,17 @@ void SerialWorker::handleTick()
|
|||||||
gotFrames = 0;
|
gotFrames = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//totally shuts down the whole thing
|
||||||
|
void SerialWorker::closeSerialPort()
|
||||||
|
{
|
||||||
|
if (serial->isOpen())
|
||||||
|
{
|
||||||
|
serial->clear();
|
||||||
|
serial->close();
|
||||||
|
}
|
||||||
|
serial->disconnect();
|
||||||
|
ticker->stop();
|
||||||
|
delete serial;
|
||||||
|
serial = NULL;
|
||||||
|
}
|
||||||
|
|||||||
+2
-1
@@ -44,6 +44,7 @@ private slots: //we receive things in slots
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setSerialPort(QSerialPortInfo*);
|
void setSerialPort(QSerialPortInfo*);
|
||||||
|
void closeSerialPort();
|
||||||
void sendFrame(const CANFrame *, int);
|
void sendFrame(const CANFrame *, int);
|
||||||
void updateBaudRates(int, int);
|
void updateBaudRates(int, int);
|
||||||
|
|
||||||
@@ -53,7 +54,7 @@ private:
|
|||||||
bool connected;
|
bool connected;
|
||||||
QSerialPort *serial;
|
QSerialPort *serial;
|
||||||
CANFrameModel *canModel;
|
CANFrameModel *canModel;
|
||||||
QTimer ticker;
|
QTimer *ticker;
|
||||||
int gotFrames;
|
int gotFrames;
|
||||||
STATE rx_state;
|
STATE rx_state;
|
||||||
int rx_step;
|
int rx_step;
|
||||||
|
|||||||
Reference in New Issue
Block a user