Add a reset connection button. Automatically disconnects and
reconnects to try to heal a broken connection.
This commit is contained in:
@@ -66,6 +66,11 @@ void CANConManager::remove(CANConnection* pConn_p)
|
||||
mConns.removeOne(pConn_p);
|
||||
}
|
||||
|
||||
void CANConManager::replace(int idx, CANConnection* pConn_p)
|
||||
{
|
||||
mConns.replace(idx, pConn_p);
|
||||
}
|
||||
|
||||
//Get total number of buses currently registered with the program
|
||||
int CANConManager::getNumBuses()
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
|
||||
void add(CANConnection* pConn_p);
|
||||
void remove(CANConnection* pConn_p);
|
||||
void replace(int idx, CANConnection* pConn_p);
|
||||
QList<CANConnection*>& getConnections();
|
||||
void stopAllConnections();
|
||||
|
||||
|
||||
@@ -126,6 +126,14 @@ void CANConnectionModel::remove(CANConnection* pConn_p)
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void CANConnectionModel::replace(int idx , CANConnection* pConn_p)
|
||||
{
|
||||
CANConManager* manager = CANConManager::getInstance();
|
||||
|
||||
beginResetModel();
|
||||
manager->replace(idx, pConn_p);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
CANConnection* CANConnectionModel::getAtIdx(int pIdx) const
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
|
||||
void add(CANConnection* pConn_p);
|
||||
void remove(CANConnection* pConn_p);
|
||||
void replace(int idx , CANConnection* pConn_p);
|
||||
|
||||
CANConnection* getAtIdx(int) const;
|
||||
void refresh(int pIndex=-1);
|
||||
|
||||
@@ -55,6 +55,7 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
|
||||
connect(ui->ckEnableConsole, &QCheckBox::toggled, this, &ConnectionWindow::consoleEnableChanged);
|
||||
connect(ui->btnClearDebug, &QPushButton::clicked, this, &ConnectionWindow::handleClearDebugText);
|
||||
connect(ui->btnNewConnection, &QPushButton::clicked, this, &ConnectionWindow::handleNewConn);
|
||||
connect(ui->btnResetConn, &QPushButton::clicked, this, &ConnectionWindow::handleResetConn);
|
||||
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &ConnectionWindow::currentRowChanged);
|
||||
connect(ui->tabBuses, &QTabBar::currentChanged, this, &ConnectionWindow::currentTabChanged);
|
||||
connect(ui->btnSaveBus, &QPushButton::clicked, this, &ConnectionWindow::saveBusSettings);
|
||||
@@ -207,6 +208,53 @@ void ConnectionWindow::handleNewConn()
|
||||
delete thisDialog;
|
||||
}
|
||||
|
||||
void ConnectionWindow::handleRemoveConn()
|
||||
{
|
||||
int selIdx = ui->tableConnections->selectionModel()->currentIndex().row();
|
||||
if (selIdx <0) return;
|
||||
|
||||
qDebug() << "remove connection at index: " << selIdx;
|
||||
|
||||
CANConnection* conn_p = connModel->getAtIdx(selIdx);
|
||||
if(!conn_p) return;
|
||||
|
||||
/* remove connection from model & manager */
|
||||
connModel->remove(conn_p);
|
||||
|
||||
/* stop and delete connection */
|
||||
conn_p->stop();
|
||||
delete conn_p;
|
||||
|
||||
/* select first connection in list */
|
||||
ui->tableConnections->selectRow(0);
|
||||
}
|
||||
|
||||
void ConnectionWindow::handleResetConn()
|
||||
{
|
||||
QString port, driver;
|
||||
CANCon::type type;
|
||||
|
||||
int selIdx = ui->tableConnections->selectionModel()->currentIndex().row();
|
||||
if (selIdx <0) return;
|
||||
|
||||
qDebug() << "remove connection at index: " << selIdx;
|
||||
|
||||
CANConnection* conn_p = connModel->getAtIdx(selIdx);
|
||||
if(!conn_p) return;
|
||||
|
||||
type = conn_p->getType();
|
||||
port = conn_p->getPort();
|
||||
driver = conn_p->getDriver();
|
||||
|
||||
/* stop and delete connection */
|
||||
conn_p->stop();
|
||||
|
||||
conn_p = nullptr;
|
||||
|
||||
conn_p = create(type, port, driver);
|
||||
if (conn_p) connModel->replace(selIdx, conn_p);
|
||||
}
|
||||
|
||||
/* status */
|
||||
void ConnectionWindow::connectionStatus(CANConStatus pStatus)
|
||||
{
|
||||
@@ -365,27 +413,6 @@ void ConnectionWindow::handleSendText() {
|
||||
emit sendDebugData(bytes);
|
||||
}
|
||||
|
||||
void ConnectionWindow::handleRemoveConn()
|
||||
{
|
||||
int selIdx = ui->tableConnections->selectionModel()->currentIndex().row();
|
||||
if (selIdx <0) return;
|
||||
|
||||
qDebug() << "remove connection at index: " << selIdx;
|
||||
|
||||
CANConnection* conn_p = connModel->getAtIdx(selIdx);
|
||||
if(!conn_p) return;
|
||||
|
||||
/* remove connection from model & manager */
|
||||
connModel->remove(conn_p);
|
||||
|
||||
/* stop and delete connection */
|
||||
conn_p->stop();
|
||||
delete conn_p;
|
||||
|
||||
/* select first connection in list */
|
||||
ui->tableConnections->selectRow(0);
|
||||
}
|
||||
|
||||
CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QString pDriver)
|
||||
{
|
||||
CANConnection* conn_p;
|
||||
|
||||
@@ -46,6 +46,7 @@ private slots:
|
||||
void consoleEnableChanged(bool checked);
|
||||
void handleRemoveConn();
|
||||
void handleNewConn();
|
||||
void handleResetConn();
|
||||
void handleClearDebugText();
|
||||
void handleSendHex();
|
||||
void handleSendText();
|
||||
|
||||
@@ -43,6 +43,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnResetConn">
|
||||
<property name="text">
|
||||
<string>Reset Selected Device</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnDisconnect">
|
||||
<property name="text">
|
||||
|
||||
Reference in New Issue
Block a user