Add fault handling code mostly used to detect when the serial port disappears while a GVRET style device is connected. Beginnings of code to add a reconnect button.
This commit is contained in:
@@ -56,6 +56,7 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
|
|||||||
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &ConnectionWindow::currentRowChanged);
|
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &ConnectionWindow::currentRowChanged);
|
||||||
connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll);
|
connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll);
|
||||||
connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll);
|
connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll);
|
||||||
|
connect(ui->btnReconnect, &QPushButton::clicked, this, &ConnectionWindow::handleReconnect);
|
||||||
connect(ui->btnRemoveBus, &QPushButton::clicked, this, &ConnectionWindow::handleRemoveConn);
|
connect(ui->btnRemoveBus, &QPushButton::clicked, this, &ConnectionWindow::handleRemoveConn);
|
||||||
connect(ui->btnClearDebug, &QPushButton::clicked, this, &ConnectionWindow::handleClearDebugText);
|
connect(ui->btnClearDebug, &QPushButton::clicked, this, &ConnectionWindow::handleClearDebugText);
|
||||||
connect(ui->btnSendHex, &QPushButton::clicked, this, &ConnectionWindow::handleSendHex);
|
connect(ui->btnSendHex, &QPushButton::clicked, this, &ConnectionWindow::handleSendHex);
|
||||||
@@ -149,6 +150,19 @@ void ConnectionWindow::setActiveAll(bool pActive)
|
|||||||
connModel->refresh();
|
connModel->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionWindow::handleReconnect()
|
||||||
|
{
|
||||||
|
int selIdx = ui->tableConnections->selectionModel()->currentIndex().row();
|
||||||
|
if (selIdx <0) return;
|
||||||
|
|
||||||
|
int busId;
|
||||||
|
CANConnection* conn_p = connModel->getAtIdx(selIdx, busId);
|
||||||
|
if(!conn_p) return;
|
||||||
|
|
||||||
|
conn_p->stop();
|
||||||
|
conn_p->start();
|
||||||
|
}
|
||||||
|
|
||||||
void ConnectionWindow::consoleEnableChanged(bool checked) {
|
void ConnectionWindow::consoleEnableChanged(bool checked) {
|
||||||
int busId;
|
int busId;
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ private slots:
|
|||||||
void handleRemoveConn();
|
void handleRemoveConn();
|
||||||
void handleEnableAll();
|
void handleEnableAll();
|
||||||
void handleDisableAll();
|
void handleDisableAll();
|
||||||
|
void handleReconnect();
|
||||||
void handleRevert();
|
void handleRevert();
|
||||||
void handleNewConn();
|
void handleNewConn();
|
||||||
void handleClearDebugText();
|
void handleClearDebugText();
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ GVRetSerial::~GVRetSerial()
|
|||||||
|
|
||||||
|
|
||||||
void GVRetSerial::piStarted()
|
void GVRetSerial::piStarted()
|
||||||
{
|
{
|
||||||
connectDevice();
|
connectDevice();
|
||||||
|
|
||||||
/* start timer */
|
/* start timer */
|
||||||
@@ -328,6 +328,7 @@ void GVRetSerial::connectDevice()
|
|||||||
|
|
||||||
/* connect reading event */
|
/* connect reading event */
|
||||||
connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData()));
|
connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData()));
|
||||||
|
connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(serialError(QSerialPort::SerialPortError)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -344,6 +345,82 @@ void GVRetSerial::disconnectDevice() {
|
|||||||
delete serial;
|
delete serial;
|
||||||
serial = NULL;
|
serial = NULL;
|
||||||
}
|
}
|
||||||
|
setStatus(CANCon::NOT_CONNECTED);
|
||||||
|
CANConStatus stats;
|
||||||
|
stats.conStatus = getStatus();
|
||||||
|
stats.numHardwareBuses = mNumBuses;
|
||||||
|
emit status(stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GVRetSerial::serialError(QSerialPort::SerialPortError err)
|
||||||
|
{
|
||||||
|
QString errMessage;
|
||||||
|
bool killConnection = false;
|
||||||
|
switch (err)
|
||||||
|
{
|
||||||
|
case QSerialPort::NoError:
|
||||||
|
return;
|
||||||
|
case QSerialPort::DeviceNotFoundError:
|
||||||
|
errMessage = "Device not found error on serial";
|
||||||
|
killConnection = true;
|
||||||
|
break;
|
||||||
|
case QSerialPort::PermissionError:
|
||||||
|
errMessage = "Permission error on serial port";
|
||||||
|
killConnection = true;
|
||||||
|
break;
|
||||||
|
case QSerialPort::OpenError:
|
||||||
|
errMessage = "Open error on serial port";
|
||||||
|
killConnection = true;
|
||||||
|
break;
|
||||||
|
case QSerialPort::ParityError:
|
||||||
|
errMessage = "Parity error on serial port";
|
||||||
|
break;
|
||||||
|
case QSerialPort::FramingError:
|
||||||
|
errMessage = "Framing error on serial port";
|
||||||
|
break;
|
||||||
|
case QSerialPort::BreakConditionError:
|
||||||
|
errMessage = "Break error on serial port";
|
||||||
|
break;
|
||||||
|
case QSerialPort::WriteError:
|
||||||
|
errMessage = "Write error on serial port";
|
||||||
|
break;
|
||||||
|
case QSerialPort::ReadError:
|
||||||
|
errMessage = "Read error on serial port";
|
||||||
|
break;
|
||||||
|
case QSerialPort::ResourceError:
|
||||||
|
errMessage = "Serial port seems to have disappeared.";
|
||||||
|
killConnection = true;
|
||||||
|
break;
|
||||||
|
case QSerialPort::UnsupportedOperationError:
|
||||||
|
errMessage = "Unsupported operation on serial port";
|
||||||
|
killConnection = true;
|
||||||
|
break;
|
||||||
|
case QSerialPort::UnknownError:
|
||||||
|
errMessage = "Beats me what happened to the serial port.";
|
||||||
|
killConnection = true;
|
||||||
|
break;
|
||||||
|
case QSerialPort::TimeoutError:
|
||||||
|
errMessage = "Timeout error on serial port";
|
||||||
|
killConnection = true;
|
||||||
|
break;
|
||||||
|
case QSerialPort::NotOpenError:
|
||||||
|
errMessage = "The serial port isn't open dummy";
|
||||||
|
killConnection = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
serial->clearError();
|
||||||
|
serial->flush();
|
||||||
|
serial->close();
|
||||||
|
if (errMessage.length() > 1)
|
||||||
|
{
|
||||||
|
qDebug() << errMessage;
|
||||||
|
debugOutput(errMessage);
|
||||||
|
}
|
||||||
|
if (killConnection)
|
||||||
|
{
|
||||||
|
qDebug() << "Shooting the serial object in the head. It deserves it.";
|
||||||
|
disconnectDevice();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -781,7 +858,7 @@ void GVRetSerial::handleTick()
|
|||||||
{
|
{
|
||||||
if (lastSystemTimeBasis != CANConManager::getInstance()->getTimeBasis()) rebuildLocalTimeBasis();
|
if (lastSystemTimeBasis != CANConManager::getInstance()->getTimeBasis()) rebuildLocalTimeBasis();
|
||||||
//qDebug() << "Tick!";
|
//qDebug() << "Tick!";
|
||||||
/*
|
|
||||||
if( CANCon::CONNECTED == getStatus() )
|
if( CANCon::CONNECTED == getStatus() )
|
||||||
{
|
{
|
||||||
if (!gotValidated && doValidation)
|
if (!gotValidated && doValidation)
|
||||||
@@ -792,16 +869,16 @@ void GVRetSerial::handleTick()
|
|||||||
qDebug() << "Comm validation failed. ";
|
qDebug() << "Comm validation failed. ";
|
||||||
|
|
||||||
setStatus(CANCon::NOT_CONNECTED);
|
setStatus(CANCon::NOT_CONNECTED);
|
||||||
emit status(getStatus());
|
//emit status(getStatus());
|
||||||
|
|
||||||
disconnectDevice(); //start by stopping everything.
|
disconnectDevice(); //start by stopping everything.
|
||||||
//Then wait 500ms and restart the connection automatically
|
//Then wait 500ms and restart the connection automatically
|
||||||
QTimer::singleShot(500, this, SLOT(connectDevice()));
|
//QTimer::singleShot(500, this, SLOT(connectDevice()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (doValidation); //qDebug() << "Comm connection validated";
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
if (doValidation && serial && serial->isOpen()) sendCommValidation();
|
if (doValidation && serial && serial->isOpen()) sendCommValidation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -813,9 +890,6 @@ void GVRetSerial::sendCommValidation()
|
|||||||
gotValidated = false;
|
gotValidated = false;
|
||||||
output.append((char)0xF1); //another command to the GVRET
|
output.append((char)0xF1); //another command to the GVRET
|
||||||
output.append((char)0x09); //request a reply to get validation
|
output.append((char)0x09); //request a reply to get validation
|
||||||
//send it twice for good measure.
|
|
||||||
output.append((char)0xF1); //another command to the GVRET
|
|
||||||
output.append((char)0x09); //request a reply to get validation
|
|
||||||
|
|
||||||
serial->write(output);
|
serial->write(output);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ private slots:
|
|||||||
void connectDevice();
|
void connectDevice();
|
||||||
void connectionTimeout();
|
void connectionTimeout();
|
||||||
void readSerialData();
|
void readSerialData();
|
||||||
|
void serialError(QSerialPort::SerialPortError err);
|
||||||
void handleTick();
|
void handleTick();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -38,6 +38,13 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnReconnect">
|
||||||
|
<property name="text">
|
||||||
|
<string>Reconnect</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnRemoveBus">
|
<widget class="QPushButton" name="btnRemoveBus">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|||||||
Reference in New Issue
Block a user