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->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll);
|
||||
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->btnClearDebug, &QPushButton::clicked, this, &ConnectionWindow::handleClearDebugText);
|
||||
connect(ui->btnSendHex, &QPushButton::clicked, this, &ConnectionWindow::handleSendHex);
|
||||
@@ -149,6 +150,19 @@ void ConnectionWindow::setActiveAll(bool pActive)
|
||||
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) {
|
||||
int busId;
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ private slots:
|
||||
void handleRemoveConn();
|
||||
void handleEnableAll();
|
||||
void handleDisableAll();
|
||||
void handleReconnect();
|
||||
void handleRevert();
|
||||
void handleNewConn();
|
||||
void handleClearDebugText();
|
||||
|
||||
@@ -328,6 +328,7 @@ void GVRetSerial::connectDevice()
|
||||
|
||||
/* connect reading event */
|
||||
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;
|
||||
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();
|
||||
//qDebug() << "Tick!";
|
||||
/*
|
||||
|
||||
if( CANCon::CONNECTED == getStatus() )
|
||||
{
|
||||
if (!gotValidated && doValidation)
|
||||
@@ -792,16 +869,16 @@ void GVRetSerial::handleTick()
|
||||
qDebug() << "Comm validation failed. ";
|
||||
|
||||
setStatus(CANCon::NOT_CONNECTED);
|
||||
emit status(getStatus());
|
||||
//emit status(getStatus());
|
||||
|
||||
disconnectDevice(); //start by stopping everything.
|
||||
//Then wait 500ms and restart the connection automatically
|
||||
QTimer::singleShot(500, this, SLOT(connectDevice()));
|
||||
//QTimer::singleShot(500, this, SLOT(connectDevice()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (doValidation); //qDebug() << "Comm connection validated";
|
||||
}
|
||||
*/
|
||||
if (doValidation && serial && serial->isOpen()) sendCommValidation();
|
||||
}
|
||||
|
||||
@@ -813,9 +890,6 @@ void GVRetSerial::sendCommValidation()
|
||||
gotValidated = false;
|
||||
output.append((char)0xF1); //another command to the GVRET
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ private slots:
|
||||
void connectDevice();
|
||||
void connectionTimeout();
|
||||
void readSerialData();
|
||||
void serialError(QSerialPort::SerialPortError err);
|
||||
void handleTick();
|
||||
|
||||
private:
|
||||
|
||||
@@ -38,6 +38,13 @@
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnReconnect">
|
||||
<property name="text">
|
||||
<string>Reconnect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnRemoveBus">
|
||||
<property name="text">
|
||||
|
||||
Reference in New Issue
Block a user