Bug fixes, moved enable to a checkbox with the rest of the checkboxes.

This commit is contained in:
Collin Kidder
2016-03-29 21:25:07 -04:00
parent 0210e963d5
commit ff5c9649a0
5 changed files with 82 additions and 60 deletions
+2 -2
View File
@@ -53,8 +53,8 @@ signals:
void error(const QString &); void error(const QString &);
void frameUpdateRapid(int); void frameUpdateRapid(int);
void frameUpdate(int); void frameUpdate(int);
void connectionSuccess(); void connectionSuccess(CANConnection *);
void connectionFailure(); void connectionFailure(CANConnection *);
void deviceInfo(int, int); //First param = driver version (or version of whatever you want), second param a status byte 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) //bus number, bus speed, status (bit 0 = enabled, 1 = single wire, 2 = listen only)
+49 -30
View File
@@ -58,6 +58,8 @@ ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
connect(ui->btnRevert, &QPushButton::clicked, this, &ConnectionWindow::handleRevert); connect(ui->btnRevert, &QPushButton::clicked, this, &ConnectionWindow::handleRevert);
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ConnectionWindow::handleConnSelectionChanged); connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ConnectionWindow::handleConnSelectionChanged);
connect(ui->btnNewConn, &QPushButton::clicked, this, &ConnectionWindow::handleNewConn); 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() ConnectionWindow::~ConnectionWindow()
@@ -80,6 +82,16 @@ void ConnectionWindow::handleNewConn()
handleConnSelectionChanged(); handleConnSelectionChanged();
} }
void ConnectionWindow::handleEnableAll()
{
}
void ConnectionWindow::handleDisableAll()
{
}
void ConnectionWindow::handleConnTypeChanged() void ConnectionWindow::handleConnTypeChanged()
{ {
if (ui->rbGVRET->isChecked()) getSerialPorts(); if (ui->rbGVRET->isChecked()) getSerialPorts();
@@ -87,6 +99,38 @@ void ConnectionWindow::handleConnTypeChanged()
if (ui->rbSocketCAN->isChecked()) getSocketcanPorts(); 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() void ConnectionWindow::handleOKButton()
{ {
QString conn; QString conn;
@@ -101,6 +145,7 @@ void ConnectionWindow::handleOKButton()
CAN_Bus *bus = connModel->getBus(whichRow); CAN_Bus *bus = connModel->getBus(whichRow);
bus->setListenOnly(ui->ckListenOnly->isChecked()); bus->setListenOnly(ui->ckListenOnly->isChecked());
bus->setSingleWire(ui->ckSingleWire->isChecked()); bus->setSingleWire(ui->ckSingleWire->isChecked());
bus->setEnabled(ui->ckEnabled->isChecked());
if (ui->cbSpeed->currentIndex() == 1) if (ui->cbSpeed->currentIndex() == 1)
{ {
bus->speed = 0; bus->speed = 0;
@@ -114,6 +159,7 @@ void ConnectionWindow::handleOKButton()
QMetaObject::invokeMethod(bus->connection, "updateBusSettings", QMetaObject::invokeMethod(bus->connection, "updateBusSettings",
Qt::QueuedConnection, Qt::QueuedConnection,
Q_ARG(CAN_Bus *, bus)); Q_ARG(CAN_Bus *, bus));
connModel->refreshView();
} }
else //new connection else //new connection
{ {
@@ -121,39 +167,11 @@ void ConnectionWindow::handleOKButton()
{ {
SerialWorker *serial = new SerialWorker(canModel, connModel->rowCount()); SerialWorker *serial = new SerialWorker(canModel, connModel->rowCount());
connect(serial, SIGNAL(busStatus(int,int,int)), this, SLOT(receiveBusStatus(int,int,int))); 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); connModel->addConnection(serial);
qDebug() << "Setup initial connection object"; 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 //call through signal/slot interface without using connect
QMetaObject::invokeMethod(serial, "updatePortName", QMetaObject::invokeMethod(serial, "updatePortName",
Qt::QueuedConnection, Qt::QueuedConnection,
@@ -204,6 +222,7 @@ void ConnectionWindow::handleConnSelectionChanged()
ui->cbPort->setCurrentIndex(0); ui->cbPort->setCurrentIndex(0);
ui->ckListenOnly->setChecked(false); ui->ckListenOnly->setChecked(false);
ui->ckSingleWire->setChecked(false); ui->ckSingleWire->setChecked(false);
ui->ckEnabled->setChecked(true);
} }
else else
{ {
@@ -218,9 +237,9 @@ void ConnectionWindow::handleConnSelectionChanged()
if (bus->connection->getConnTypeName() == "SOCKETCAN") ui->rbSocketCAN->setChecked(true); if (bus->connection->getConnTypeName() == "SOCKETCAN") ui->rbSocketCAN->setChecked(true);
ui->ckListenOnly->setChecked(bus->isListenOnly()); ui->ckListenOnly->setChecked(bus->isListenOnly());
ui->ckSingleWire->setChecked(bus->isSingleWire()); ui->ckSingleWire->setChecked(bus->isSingleWire());
ui->ckEnabled->setChecked(bus->isActive());
int speed = bus->getSpeed(); int speed = bus->getSpeed();
setSpeed(speed); setSpeed(speed);
//connModel->refreshView();
} }
} }
+3
View File
@@ -56,7 +56,10 @@ private slots:
void handleRemoveConn(); void handleRemoveConn();
void handleRevert(); void handleRevert();
void handleNewConn(); void handleNewConn();
void handleEnableAll();
void handleDisableAll();
void receiveBusStatus(int bus, int speed, int status); void receiveBusStatus(int bus, int speed, int status);
void connectionSuccess(CANConnection *conn);
private: private:
Ui::ConnectionWindow *ui; Ui::ConnectionWindow *ui;
+9 -9
View File
@@ -33,6 +33,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item> <item>
<widget class="QPushButton" name="btnNewConn"> <widget class="QPushButton" name="btnNewConn">
<property name="text"> <property name="text">
@@ -40,15 +42,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="btnBusActivate">
<property name="text">
<string>Activate Selected Connection</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="btnRemoveBus"> <widget class="QPushButton" name="btnRemoveBus">
<property name="text"> <property name="text">
@@ -152,6 +145,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="ckEnabled">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="1,2"> <layout class="QHBoxLayout" name="horizontalLayout_3" stretch="1,2">
<item> <item>
+18 -18
View File
@@ -134,7 +134,7 @@ void SerialWorker::connectionTimeout()
qDebug() << "Failed to connect to GVRET at that com port"; qDebug() << "Failed to connect to GVRET at that com port";
//ticker->stop(); //ticker->stop();
closeSerialPort(); //make sure it's properly closed anyway 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 0 = " << can0Baud;
qDebug() << "Baud 1 = " << can1Baud; qDebug() << "Baud 1 = " << can1Baud;
can0Baud &= 0x80000000; can0Baud |= 0x80000000;
if (can0Enabled) can0Baud &= 0x40000000; if (can0Enabled) can0Baud |= 0x40000000;
if (can0ListenOnly) can0Baud &= 0x20000000; if (can0ListenOnly) can0Baud |= 0x20000000;
can1Baud &= 0x80000000; can1Baud |= 0x80000000;
if (can1Enabled) can1Baud &= 0x40000000; if (can1Enabled) can1Baud |= 0x40000000;
if (can1ListenOnly) can1Baud &= 0x20000000; if (can1ListenOnly) can1Baud |= 0x20000000;
if (deviceSingleWireMode > 0) can1Baud &= 0x10000000; if (deviceSingleWireMode > 0) can1Baud |= 0x10000000;
isConnected = true; isConnected = true;
emit connectionSuccess(); emit connectionSuccess(this);
int can0Status = 0x78; //updating everything we can update int can0Status = 0x78; //updating everything we can update
int can1Status = 0x78; int can1Status = 0x78;
if (can0Enabled) can0Status +=1; if (can0Enabled) can0Status +=1;
@@ -431,8 +431,8 @@ void SerialWorker::procRXChar(unsigned char c)
if (can1Enabled) can1Status += 1; if (can1Enabled) can1Status += 1;
if (deviceSingleWireMode > 0) can1Status += 2; if (deviceSingleWireMode > 0) can1Status += 2;
if (can1ListenOnly) can1Status += 4; if (can1ListenOnly) can1Status += 4;
emit busStatus(busBase, can0Baud, can0Status); emit busStatus(busBase, can0Baud & 0xFFFFF, can0Status);
emit busStatus(busBase + 1, can1Baud, can1Status); emit busStatus(busBase + 1, can1Baud & 0xFFFFF, can1Status);
break; break;
} }
rx_step++; rx_step++;
@@ -585,17 +585,17 @@ void SerialWorker::updateBusSettings(CAN_Bus *bus)
if (busNum == 0) if (busNum == 0)
{ {
can0Baud = bus->getSpeed(); can0Baud = bus->getSpeed();
can0Baud &= 0x80000000; can0Baud |= 0x80000000;
if (bus->isActive()) if (bus->isActive())
{ {
can0Baud &= 0x40000000; can0Baud |= 0x40000000;
can0Enabled = true; can0Enabled = true;
} }
else can0Enabled = false; else can0Enabled = false;
if (bus->isListenOnly()) if (bus->isListenOnly())
{ {
can0Baud &= 0x20000000; can0Baud |= 0x20000000;
can0ListenOnly = true; can0ListenOnly = true;
} }
else can0ListenOnly = false; else can0ListenOnly = false;
@@ -603,24 +603,24 @@ void SerialWorker::updateBusSettings(CAN_Bus *bus)
if (busNum == 1) if (busNum == 1)
{ {
can1Baud = bus->getSpeed(); can1Baud = bus->getSpeed();
can1Baud &= 0x80000000; can1Baud |= 0x80000000;
if (bus->isActive()) if (bus->isActive())
{ {
can1Baud &= 0x40000000; can1Baud |= 0x40000000;
can1Enabled = true; can1Enabled = true;
} }
else can1Enabled = false; else can1Enabled = false;
if (bus->isListenOnly()) if (bus->isListenOnly())
{ {
can1Baud &= 0x20000000; can1Baud |= 0x20000000;
can1ListenOnly = true; can1ListenOnly = true;
} }
else can1ListenOnly = false; else can1ListenOnly = false;
if (bus->isSingleWire()) if (bus->isSingleWire())
{ {
can1Baud &= 0x10000000; can1Baud |= 0x10000000;
deviceSingleWireMode = 1; deviceSingleWireMode = 1;
} }
else deviceSingleWireMode = 0; else deviceSingleWireMode = 0;