diff --git a/canconnection.h b/canconnection.h index 598d967..2a824cb 100644 --- a/canconnection.h +++ b/canconnection.h @@ -53,8 +53,8 @@ signals: void error(const QString &); void frameUpdateRapid(int); void frameUpdate(int); - void connectionSuccess(); - void connectionFailure(); + void connectionSuccess(CANConnection *); + void connectionFailure(CANConnection *); void deviceInfo(int, int); //First param = driver version (or version of whatever you want), second param a status byte //bus number, bus speed, status (bit 0 = enabled, 1 = single wire, 2 = listen only) diff --git a/connectionwindow.cpp b/connectionwindow.cpp index fe757f6..cb61e1f 100644 --- a/connectionwindow.cpp +++ b/connectionwindow.cpp @@ -58,6 +58,8 @@ ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) : connect(ui->btnRevert, &QPushButton::clicked, this, &ConnectionWindow::handleRevert); connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ConnectionWindow::handleConnSelectionChanged); connect(ui->btnNewConn, &QPushButton::clicked, this, &ConnectionWindow::handleNewConn); + connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll); + connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll); } ConnectionWindow::~ConnectionWindow() @@ -80,6 +82,16 @@ void ConnectionWindow::handleNewConn() handleConnSelectionChanged(); } +void ConnectionWindow::handleEnableAll() +{ + +} + +void ConnectionWindow::handleDisableAll() +{ + +} + void ConnectionWindow::handleConnTypeChanged() { if (ui->rbGVRET->isChecked()) getSerialPorts(); @@ -87,6 +99,38 @@ void ConnectionWindow::handleConnTypeChanged() if (ui->rbSocketCAN->isChecked()) getSocketcanPorts(); } +void ConnectionWindow::connectionSuccess(CANConnection *conn) +{ + CAN_Bus bus; + bus.active = true; + bus.busNum = conn->getBusBase(); + bus.connection = conn; + bus.listenOnly = ui->ckListenOnly->isChecked(); + bus.singleWire = ui->ckSingleWire->isChecked(); + + if (ui->cbSpeed->currentIndex() < 1) bus.speed = 0; //default speed + else if (ui->cbSpeed->currentIndex() == 1) + { + bus.speed = 0; + bus.active = false; + } + else bus.speed = ui->cbSpeed->currentText().toInt(); + connModel->addBus(bus); + + int numBuses = conn->getNumBuses(); + for (int i = 1; i < numBuses; i++) + { + bus.active = false; + bus.listenOnly = false; + bus.singleWire = false; + bus.speed = 250000; + bus.busNum = conn->getBusBase() + i; + bus.connection = conn; + connModel->addBus(bus); + qDebug() << "Added bus " << bus.busNum; + } +} + void ConnectionWindow::handleOKButton() { QString conn; @@ -101,6 +145,7 @@ void ConnectionWindow::handleOKButton() CAN_Bus *bus = connModel->getBus(whichRow); bus->setListenOnly(ui->ckListenOnly->isChecked()); bus->setSingleWire(ui->ckSingleWire->isChecked()); + bus->setEnabled(ui->ckEnabled->isChecked()); if (ui->cbSpeed->currentIndex() == 1) { bus->speed = 0; @@ -109,11 +154,12 @@ void ConnectionWindow::handleOKButton() else if (ui->cbSpeed->currentIndex() > 1) { bus->setSpeed(ui->cbSpeed->currentText().toInt()); - } + } //call through signal/slot interface without using connect QMetaObject::invokeMethod(bus->connection, "updateBusSettings", Qt::QueuedConnection, Q_ARG(CAN_Bus *, bus)); + connModel->refreshView(); } else //new connection { @@ -121,39 +167,11 @@ void ConnectionWindow::handleOKButton() { SerialWorker *serial = new SerialWorker(canModel, connModel->rowCount()); connect(serial, SIGNAL(busStatus(int,int,int)), this, SLOT(receiveBusStatus(int,int,int))); + connect(serial, SIGNAL(connectionSuccess(CANConnection*)), this, SLOT(connectionSuccess(CANConnection*))); connModel->addConnection(serial); qDebug() << "Setup initial connection object"; - CAN_Bus bus; - bus.active = true; - bus.busNum = serial->getBusBase(); - bus.connection = serial; - bus.listenOnly = ui->ckListenOnly->isChecked(); - bus.singleWire = ui->ckSingleWire->isChecked(); - - if (ui->cbSpeed->currentIndex() < 1) bus.speed = 0; //default speed - else if (ui->cbSpeed->currentIndex() == 1) - { - bus.speed = 0; - bus.active = false; - } - else bus.speed = ui->cbSpeed->currentText().toInt(); - connModel->addBus(bus); - - int numBuses = serial->getNumBuses(); - for (int i = 1; i < numBuses; i++) - { - bus.active = false; - bus.listenOnly = false; - bus.singleWire = false; - bus.speed = 250000; - bus.busNum = serial->getBusBase() + i; - bus.connection = serial; - connModel->addBus(bus); - qDebug() << "Added bus " << bus.busNum; - } - //call through signal/slot interface without using connect QMetaObject::invokeMethod(serial, "updatePortName", Qt::QueuedConnection, @@ -204,6 +222,7 @@ void ConnectionWindow::handleConnSelectionChanged() ui->cbPort->setCurrentIndex(0); ui->ckListenOnly->setChecked(false); ui->ckSingleWire->setChecked(false); + ui->ckEnabled->setChecked(true); } else { @@ -218,9 +237,9 @@ void ConnectionWindow::handleConnSelectionChanged() if (bus->connection->getConnTypeName() == "SOCKETCAN") ui->rbSocketCAN->setChecked(true); ui->ckListenOnly->setChecked(bus->isListenOnly()); ui->ckSingleWire->setChecked(bus->isSingleWire()); + ui->ckEnabled->setChecked(bus->isActive()); int speed = bus->getSpeed(); setSpeed(speed); - //connModel->refreshView(); } } diff --git a/connectionwindow.h b/connectionwindow.h index b3efdd5..51b6c37 100644 --- a/connectionwindow.h +++ b/connectionwindow.h @@ -56,7 +56,10 @@ private slots: void handleRemoveConn(); void handleRevert(); void handleNewConn(); + void handleEnableAll(); + void handleDisableAll(); void receiveBusStatus(int bus, int speed, int status); + void connectionSuccess(CANConnection *conn); private: Ui::ConnectionWindow *ui; diff --git a/connectionwindow.ui b/connectionwindow.ui index db0cd9a..f157991 100644 --- a/connectionwindow.ui +++ b/connectionwindow.ui @@ -33,19 +33,12 @@ - - - - New Connection - - - - + - Activate Selected Connection + New Connection @@ -152,6 +145,13 @@ + + + + Enabled + + + diff --git a/serialworker.cpp b/serialworker.cpp index 31a6734..3b2bbf2 100644 --- a/serialworker.cpp +++ b/serialworker.cpp @@ -134,7 +134,7 @@ void SerialWorker::connectionTimeout() qDebug() << "Failed to connect to GVRET at that com port"; //ticker->stop(); closeSerialPort(); //make sure it's properly closed anyway - emit connectionFailure(); + emit connectionFailure(this); } } @@ -413,17 +413,17 @@ void SerialWorker::procRXChar(unsigned char c) qDebug() << "Baud 0 = " << can0Baud; qDebug() << "Baud 1 = " << can1Baud; - can0Baud &= 0x80000000; - if (can0Enabled) can0Baud &= 0x40000000; - if (can0ListenOnly) can0Baud &= 0x20000000; + can0Baud |= 0x80000000; + if (can0Enabled) can0Baud |= 0x40000000; + if (can0ListenOnly) can0Baud |= 0x20000000; - can1Baud &= 0x80000000; - if (can1Enabled) can1Baud &= 0x40000000; - if (can1ListenOnly) can1Baud &= 0x20000000; - if (deviceSingleWireMode > 0) can1Baud &= 0x10000000; + can1Baud |= 0x80000000; + if (can1Enabled) can1Baud |= 0x40000000; + if (can1ListenOnly) can1Baud |= 0x20000000; + if (deviceSingleWireMode > 0) can1Baud |= 0x10000000; isConnected = true; - emit connectionSuccess(); + emit connectionSuccess(this); int can0Status = 0x78; //updating everything we can update int can1Status = 0x78; if (can0Enabled) can0Status +=1; @@ -431,8 +431,8 @@ void SerialWorker::procRXChar(unsigned char c) if (can1Enabled) can1Status += 1; if (deviceSingleWireMode > 0) can1Status += 2; if (can1ListenOnly) can1Status += 4; - emit busStatus(busBase, can0Baud, can0Status); - emit busStatus(busBase + 1, can1Baud, can1Status); + emit busStatus(busBase, can0Baud & 0xFFFFF, can0Status); + emit busStatus(busBase + 1, can1Baud & 0xFFFFF, can1Status); break; } rx_step++; @@ -585,17 +585,17 @@ void SerialWorker::updateBusSettings(CAN_Bus *bus) if (busNum == 0) { can0Baud = bus->getSpeed(); - can0Baud &= 0x80000000; + can0Baud |= 0x80000000; if (bus->isActive()) { - can0Baud &= 0x40000000; + can0Baud |= 0x40000000; can0Enabled = true; } else can0Enabled = false; if (bus->isListenOnly()) { - can0Baud &= 0x20000000; + can0Baud |= 0x20000000; can0ListenOnly = true; } else can0ListenOnly = false; @@ -603,24 +603,24 @@ void SerialWorker::updateBusSettings(CAN_Bus *bus) if (busNum == 1) { can1Baud = bus->getSpeed(); - can1Baud &= 0x80000000; + can1Baud |= 0x80000000; if (bus->isActive()) { - can1Baud &= 0x40000000; + can1Baud |= 0x40000000; can1Enabled = true; } else can1Enabled = false; if (bus->isListenOnly()) { - can1Baud &= 0x20000000; + can1Baud |= 0x20000000; can1ListenOnly = true; } else can1ListenOnly = false; if (bus->isSingleWire()) { - can1Baud &= 0x10000000; + can1Baud |= 0x10000000; deviceSingleWireMode = 1; } else deviceSingleWireMode = 0;