Updates to cause connection to GVRET to be easier to verify. It should be pretty clear when you are connected now.

This commit is contained in:
Collin Kidder
2015-05-19 22:46:56 -04:00
parent 2841a2a72c
commit feccc2336d
5 changed files with 119 additions and 50 deletions
+48 -44
View File
@@ -68,6 +68,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(worker, &SerialWorker::receivedFrame, this, &MainWindow::gotFrame, Qt::QueuedConnection); connect(worker, &SerialWorker::receivedFrame, this, &MainWindow::gotFrame, Qt::QueuedConnection);
connect(this, &MainWindow::updateBaudRates, worker, &SerialWorker::updateBaudRates, Qt::QueuedConnection); connect(this, &MainWindow::updateBaudRates, worker, &SerialWorker::updateBaudRates, Qt::QueuedConnection);
connect(this, &MainWindow::sendCANFrame, worker, &SerialWorker::sendFrame, Qt::QueuedConnection); connect(this, &MainWindow::sendCANFrame, worker, &SerialWorker::sendFrame, Qt::QueuedConnection);
connect(worker, &SerialWorker::connectionSuccess, this, &MainWindow::connectionSucceeded, Qt::QueuedConnection);
serialWorkerThread.start(); serialWorkerThread.start();
graphingWindow = NULL; graphingWindow = NULL;
@@ -92,7 +93,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->actionSave_DBC_File, SIGNAL(triggered(bool)), this, SLOT(handleSaveDBC())); connect(ui->actionSave_DBC_File, SIGNAL(triggered(bool)), this, SLOT(handleSaveDBC()));
lbStatusConnected.setText(tr("Not connected")); lbStatusConnected.setText(tr("Not connected"));
lbStatusBauds.setText(tr("Baud 1: 0 Baud 2: 0")); updateBaudLabel(0,0);
lbStatusDatabase.setText(tr("No database loaded")); lbStatusDatabase.setText(tr("No database loaded"));
ui->statusBar->addWidget(&lbStatusConnected); ui->statusBar->addWidget(&lbStatusConnected);
ui->statusBar->addWidget(&lbStatusBauds); ui->statusBar->addWidget(&lbStatusBauds);
@@ -114,6 +115,18 @@ MainWindow::~MainWindow()
serialWorkerThread.wait(); serialWorkerThread.wait();
} }
void MainWindow::updateBaudLabel(int baud0, int baud1)
{
QString labelText;
labelText = tr("Baud 0: ");
if (baud0 > 0) labelText += QString::number(baud0);
else labelText += tr("disabled");
labelText += tr(" Baud 1: ");
if (baud1 > 0) labelText += QString::number(baud1);
else labelText += tr("disabled");
lbStatusBauds.setText(labelText);
}
void MainWindow::gotFrame(CANFrame *frame) void MainWindow::gotFrame(CANFrame *frame)
{ {
qDebug() << "got frame from serial side. ID was " << frame->ID; qDebug() << "got frame from serial side. ID was " << frame->ID;
@@ -142,50 +155,12 @@ void MainWindow::changeBaudRates()
{ {
int Speed1 = 0, Speed2 = 0; int Speed1 = 0, Speed2 = 0;
switch (ui->cbSpeed1->currentIndex()) Speed1 = ui->cbSpeed1->currentText().toInt();
{ Speed2 = ui->cbSpeed2->currentText().toInt();
case 0: //disable
break;
case 1:
Speed1 = 125000;
break;
case 2:
Speed1 = 250000;
break;
case 3:
Speed1 = 500000;
break;
case 4:
Speed1 = 1000000;
break;
case 5:
Speed1 = 33333;
break;
}
switch (ui->cbSpeed2->currentIndex())
{
case 0: //disable
break;
case 1:
Speed2 = 125000;
break;
case 2:
Speed2 = 250000;
break;
case 3:
Speed2 = 500000;
break;
case 4:
Speed2 = 1000000;
break;
case 5:
Speed2 = 33333;
break;
}
emit updateBaudRates(Speed1, Speed2); emit updateBaudRates(Speed1, Speed2);
lbStatusBauds.setText(tr("Baud 1: ") + QString::number(Speed1) + tr(" Baud 2:") + QString::number(Speed2)); updateBaudLabel(Speed1, Speed2);
} }
//CRTD format from Mark Webb-Johnson / OVMS project //CRTD format from Mark Webb-Johnson / OVMS project
@@ -628,6 +603,9 @@ void MainWindow::handleLoadDBC()
//right now there is only one file type that can be loaded here so just do it. //right now there is only one file type that can be loaded here so just do it.
dbcHandler->loadDBCFile(filename); dbcHandler->loadDBCFile(filename);
dbcHandler->listDebugging();
QStringList fileList = filename.split('/');
lbStatusDatabase.setText(fileList[fileList.length() - 1] + tr(" loaded."));
} }
void MainWindow::handleSaveDBC() void MainWindow::handleSaveDBC()
@@ -661,13 +639,39 @@ void MainWindow::connButtonPress()
{ {
if (ports.at(x).portName() == ui->cbSerialPorts->currentText()) if (ports.at(x).portName() == ui->cbSerialPorts->currentText())
{ {
emit sendSerialPort(&ports[x]); emit sendSerialPort(&ports[x]);
lbStatusConnected.setText(tr("Connected to port ") + ports[x].portName()); lbStatusConnected.setText(tr("Attempting to connect to port ") + ports[x].portName());
return; return;
} }
} }
} }
void MainWindow::connectionSucceeded(int baud0, int baud1)
{
lbStatusConnected.setText(tr("Connected to GVRET"));
//now update the status message for baud rates
updateBaudLabel(baud0, baud1);
//finally, find the baud rate in the list of rates or
//add it to the bottom if needed (that'll be weird though...
int idx = ui->cbSpeed1->findText(QString::number(baud0));
if (idx > -1) ui->cbSpeed1->setCurrentIndex(idx);
else
{
ui->cbSpeed1->addItem(QString::number(baud0));
ui->cbSpeed1->setCurrentIndex(ui->cbSpeed1->count() - 1);
}
idx = ui->cbSpeed2->findText(QString::number(baud0));
if (idx > -1) ui->cbSpeed2->setCurrentIndex(idx);
else
{
ui->cbSpeed2->addItem(QString::number(baud1));
ui->cbSpeed2->setCurrentIndex(ui->cbSpeed2->count() - 1);
}
ui->btnConnect->setEnabled(false);
}
void MainWindow::showGraphingWindow() void MainWindow::showGraphingWindow()
{ {
if (!graphingWindow) graphingWindow = new GraphingWindow(model->getListReference()); if (!graphingWindow) graphingWindow = new GraphingWindow(model->getListReference());
+2
View File
@@ -42,6 +42,7 @@ private slots:
public slots: public slots:
void gotFrame(CANFrame *frame); void gotFrame(CANFrame *frame);
void connectionSucceeded(int, int);
signals: signals:
void sendSerialPort(QSerialPortInfo *port); void sendSerialPort(QSerialPortInfo *port);
@@ -74,6 +75,7 @@ private:
void saveLogFile(QString); void saveLogFile(QString);
void saveMicrochipFile(QString); void saveMicrochipFile(QString);
void addFrameToDisplay(CANFrame &, bool); void addFrameToDisplay(CANFrame &, bool);
void updateBaudLabel(int, int);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H
+1 -1
View File
@@ -65,7 +65,7 @@
<item> <item>
<widget class="QPushButton" name="btnConnect"> <widget class="QPushButton" name="btnConnect">
<property name="text"> <property name="text">
<string>Connect To Dongle</string> <string>Connect To GVRET</string>
</property> </property>
</widget> </widget>
</item> </item>
+62 -3
View File
@@ -13,17 +13,29 @@ SerialWorker::SerialWorker(QObject *parent) : QObject(parent)
SerialWorker::~SerialWorker() SerialWorker::~SerialWorker()
{ {
if (serial != NULL) delete serial; if (serial != NULL)
{
if (serial->isOpen())
{
serial->clear();
serial->close();
}
serial->disconnect(); //disconnect all signals
delete serial;
}
} }
void SerialWorker::setSerialPort(QSerialPortInfo *port) void SerialWorker::setSerialPort(QSerialPortInfo *port)
{ {
if (!(serial == NULL)) if (serial != NULL)
{ {
if (serial->isOpen()) if (serial->isOpen())
{ {
serial->clear();
serial->close(); serial->close();
} }
serial->disconnect(); //disconnect all signals
delete serial; delete serial;
} }
@@ -37,8 +49,10 @@ void SerialWorker::setSerialPort(QSerialPortInfo *port)
serial->setDataTerminalReady(true); serial->setDataTerminalReady(true);
serial->setRequestToSend(true); serial->setRequestToSend(true);
QByteArray output; QByteArray output;
output.append(0xE7); //this puts the device into binary comm mode
output.append(0xE7); output.append(0xE7);
output.append(0xE7); output.append(0xF1); //signal we want to issue a command
output.append(0x06); //request canbus stats from the board
serial->write(output); serial->write(output);
///isConnected = true; ///isConnected = true;
connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData())); connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData()));
@@ -137,6 +151,9 @@ void SerialWorker::procRXChar(unsigned char c)
case 5: //we set canbus specs we don't accept replies. case 5: //we set canbus specs we don't accept replies.
rx_state = IDLE; rx_state = IDLE;
break; break;
case 6: //get canbus parameters from GVRET
rx_state = GET_CANBUS_PARAMS;
rx_step = 0;
} }
break; break;
case BUILD_CAN_FRAME: case BUILD_CAN_FRAME:
@@ -213,5 +230,47 @@ void SerialWorker::procRXChar(unsigned char c)
} }
rx_step++; rx_step++;
break; break;
case GET_CANBUS_PARAMS:
switch (rx_step)
{
case 0:
can0Enabled = c;
break;
case 1:
can0Baud = c;
break;
case 2:
can0Baud |= c << 8;
break;
case 3:
can0Baud |= c << 16;
break;
case 4:
can0Baud |= c << 24;
break;
case 5:
can1Enabled = c;
break;
case 6:
can1Baud = c;
break;
case 7:
can1Baud |= c << 8;
break;
case 8:
can1Baud |= c << 16;
break;
case 9:
can1Baud |= c << 24;
rx_step = IDLE;
qDebug() << "Baud 0 = " << can0Baud;
qDebug() << "Baud 1 = " << can1Baud;
if (!can1Enabled) can1Baud = 0;
if (!can0Enabled) can0Baud = 0;
emit connectionSuccess(can0Baud, can1Baud);
break;
}
rx_step++;
break;
} }
} }
+6 -2
View File
@@ -15,7 +15,8 @@ enum STATE //keep this enum synchronized with the Arduino firmware project
GET_DIG_INPUTS, GET_DIG_INPUTS,
GET_ANALOG_INPUTS, GET_ANALOG_INPUTS,
SET_DIG_OUTPUTS, SET_DIG_OUTPUTS,
SETUP_CANBUS SETUP_CANBUS,
GET_CANBUS_PARAMS
}; };
class SerialWorker : public QObject class SerialWorker : public QObject
@@ -29,6 +30,8 @@ public:
signals: //we emit signals signals: //we emit signals
void error(const QString &); void error(const QString &);
void receivedFrame(CANFrame *); void receivedFrame(CANFrame *);
void connectionSuccess(int, int);
void connectionFailure();
private slots: //we receive things in slots private slots: //we receive things in slots
void readSerialData(); void readSerialData();
@@ -38,7 +41,6 @@ public slots:
void sendFrame(const CANFrame *, int); void sendFrame(const CANFrame *, int);
void updateBaudRates(int, int); void updateBaudRates(int, int);
private: private:
QString portName; QString portName;
bool quit; bool quit;
@@ -46,6 +48,8 @@ private:
STATE rx_state; STATE rx_state;
int rx_step; int rx_step;
CANFrame *buildFrame; CANFrame *buildFrame;
int can0Baud, can1Baud;
bool can0Enabled, can1Enabled;
void procRXChar(unsigned char); void procRXChar(unsigned char);
}; };