Added a serial console to the connection window which can be used to

figure out what is going on with a connected device. Currently really
only useful for GVRET style devices.
This commit is contained in:
Collin Kidder
2017-04-11 21:09:29 -04:00
parent f4c6c3fbd9
commit e2811af479
7 changed files with 183 additions and 7 deletions
+4
View File
@@ -256,6 +256,10 @@ void CANConnection::setCapSuspended(bool pIsSuspended) {
mIsCapSuspended = pIsSuspended; mIsCapSuspended = pIsSuspended;
} }
void CANConnection::debugInput(QByteArray bytes) {
}
bool CANConnection::addTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver) bool CANConnection::addTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver)
{ {
/* /*
+7
View File
@@ -91,6 +91,11 @@ signals:
*/ */
void status(CANCon::status pStatus); void status(CANCon::status pStatus);
/**
* @brief Event sent when device has done something worthy of debugging output.
* @param debugString: String based output to show for debugging purposes
*/
void debugOutput(QString debugString);
public slots: public slots:
@@ -175,6 +180,8 @@ public slots:
*/ */
bool removeAllTargettedFrames(QObject *receiver); bool removeAllTargettedFrames(QObject *receiver);
void debugInput(QByteArray bytes);
protected: protected:
//determine if the passed frame is part of a filter or not. //determine if the passed frame is part of a filter or not.
+66 -4
View File
@@ -22,7 +22,6 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
qRegisterMetaType<const CANFrame *>("const CANFrame *"); qRegisterMetaType<const CANFrame *>("const CANFrame *");
qRegisterMetaType<const QList<CANFrame> *>("const QList<CANFrame> *"); qRegisterMetaType<const QList<CANFrame> *>("const QList<CANFrame> *");
connModel = new CANConnectionModel(this); connModel = new CANConnectionModel(this);
ui->tableConnections->setModel(connModel); ui->tableConnections->setModel(connModel);
ui->tableConnections->setColumnWidth(0, 50); ui->tableConnections->setColumnWidth(0, 50);
@@ -41,6 +40,12 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
ui->cbSpeed->addItem(tr("1000000")); ui->cbSpeed->addItem(tr("1000000"));
ui->cbSpeed->addItem(tr("33333")); ui->cbSpeed->addItem(tr("33333"));
ui->textConsole->setEnabled(false);
ui->btnClearDebug->setEnabled(false);
ui->btnSendHex->setEnabled(false);
ui->btnSendText->setEnabled(false);
ui->lineSend->setEnabled(false);
/* load connection configuration */ /* load connection configuration */
loadConnections(); loadConnections();
@@ -59,6 +64,10 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll); connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll);
connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll); connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll);
connect(ui->btnRemoveBus, &QPushButton::clicked, this, &ConnectionWindow::handleRemoveConn); connect(ui->btnRemoveBus, &QPushButton::clicked, this, &ConnectionWindow::handleRemoveConn);
connect(ui->btnClearDebug, &QPushButton::clicked, this, &ConnectionWindow::handleClearDebugText);
connect(ui->btnSendHex, &QPushButton::clicked, this, &ConnectionWindow::handleSendHex);
connect(ui->btnSendText, &QPushButton::clicked, this, &ConnectionWindow::handleSendText);
connect(ui->ckEnableConsole, &QCheckBox::toggled, this, &ConnectionWindow::consoleEnableChanged);
} }
ConnectionWindow::~ConnectionWindow() ConnectionWindow::~ConnectionWindow()
@@ -119,6 +128,28 @@ void ConnectionWindow::setActiveAll(bool pActive)
connModel->refresh(); connModel->refresh();
} }
void ConnectionWindow::consoleEnableChanged(bool checked) {
int busId;
CANConnection* conn_p = connModel->getAtIdx(ui->tableConnections->currentIndex().row(), busId);
ui->textConsole->setEnabled(checked);
ui->btnClearDebug->setEnabled(checked);
ui->btnSendHex->setEnabled(checked);
ui->btnSendText->setEnabled(checked);
ui->lineSend->setEnabled(checked);
if(!conn_p) return;
if (checked) { //enable console
connect(conn_p, SIGNAL(debugOutput(QString)), this, SLOT(getDebugText(QString)));
connect(this, SIGNAL(sendDebugData(QByteArray)), conn_p, SLOT(debugInput(QByteArray)));
}
else { //turn it off
disconnect(conn_p, SIGNAL(debugOutput(QString)), 0, 0);
disconnect(this, SIGNAL(sendDebugData(QByteArray)), conn_p, SLOT(debugInput(QByteArray)));
}
}
void ConnectionWindow::handleNewConn() void ConnectionWindow::handleNewConn()
{ {
@@ -209,14 +240,17 @@ void ConnectionWindow::handleOKButton()
} }
} }
void ConnectionWindow::currentRowChanged(const QModelIndex &current, const QModelIndex &previous) void ConnectionWindow::currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
{ {
Q_UNUSED(previous); Q_UNUSED(previous);
int selIdx = current.row(); int selIdx = current.row();
int busId;
disconnect(connModel->getAtIdx(previous.row(), busId), SIGNAL(debugOutput(QString)), 0, 0);
disconnect(this, SIGNAL(sendDebugData(QByteArray)), connModel->getAtIdx(previous.row(), busId), SLOT(debugInput(QByteArray)));
/* enable / diable connection type */ /* enable / diable connection type */
ui->stPort->setEnabled(selIdx==-1); ui->stPort->setEnabled(selIdx==-1);
ui->gbType->setEnabled(selIdx==-1); ui->gbType->setEnabled(selIdx==-1);
@@ -235,11 +269,16 @@ void ConnectionWindow::currentRowChanged(const QModelIndex &current, const QMode
} }
else else
{ {
int busId;
bool ret; bool ret;
CANBus bus; CANBus bus;
CANConnection* conn_p = connModel->getAtIdx(selIdx, busId); CANConnection* conn_p = connModel->getAtIdx(selIdx, busId);
if(!conn_p) return; if(!conn_p) return;
if (ui->ckEnableConsole->isChecked()) { //only connect if console is actually enabled
connect(conn_p, SIGNAL(debugOutput(QString)), this, SLOT(getDebugText(QString)));
connect(this, SIGNAL(sendDebugData(QByteArray)), conn_p, SLOT(debugInput(QByteArray)));
}
ret = conn_p->getBusSettings(busId, bus); ret = conn_p->getBusSettings(busId, bus);
if(!ret) return; if(!ret) return;
@@ -252,6 +291,29 @@ void ConnectionWindow::currentRowChanged(const QModelIndex &current, const QMode
} }
} }
void ConnectionWindow::getDebugText(QString debugText) {
ui->textConsole->append(debugText);
}
void ConnectionWindow::handleClearDebugText() {
ui->textConsole->clear();
}
void ConnectionWindow::handleSendHex() {
QByteArray bytes;
QStringList tokens = ui->lineSend->text().split(' ');
foreach (QString token, tokens) {
bytes.append(token.toInt(nullptr, 16));
}
emit sendDebugData(bytes);
}
void ConnectionWindow::handleSendText() {
QByteArray bytes;
bytes = ui->lineSend->text().toLatin1();
bytes.append('\r'); //add carriage return for line ending
emit sendDebugData(bytes);
}
void ConnectionWindow::selectSerial() void ConnectionWindow::selectSerial()
{ {
+7
View File
@@ -35,6 +35,7 @@ public:
signals: signals:
void updateBusSettings(CANBus *bus); void updateBusSettings(CANBus *bus);
void updatePortName(QString port); void updatePortName(QString port);
void sendDebugData(QByteArray bytes);
public slots: public slots:
void setSpeed(int speed0); void setSpeed(int speed0);
@@ -42,15 +43,21 @@ public slots:
void setSuspendAll(bool pSuspend); void setSuspendAll(bool pSuspend);
void getDebugText(QString debugText);
private slots: private slots:
void handleOKButton(); void handleOKButton();
void handleConnTypeChanged(); void handleConnTypeChanged();
void currentRowChanged(const QModelIndex &current, const QModelIndex &previous); void currentRowChanged(const QModelIndex &current, const QModelIndex &previous);
void consoleEnableChanged(bool checked);
void handleRemoveConn(); void handleRemoveConn();
void handleEnableAll(); void handleEnableAll();
void handleDisableAll(); void handleDisableAll();
void handleRevert(); void handleRevert();
void handleNewConn(); void handleNewConn();
void handleClearDebugText();
void handleSendHex();
void handleSendText();
void connectionStatus(CANCon::status); void connectionStatus(CANCon::status);
private: private:
+20
View File
@@ -3,6 +3,7 @@
#include <QCanBusFrame> #include <QCanBusFrame>
#include <QSerialPortInfo> #include <QSerialPortInfo>
#include <QSettings> #include <QSettings>
#include <QStringBuilder>
#include "gvretserial.h" #include "gvretserial.h"
@@ -11,6 +12,7 @@ GVRetSerial::GVRetSerial(QString portName) :
mTimer(this) /*NB: set this as parent of timer to manage it from working thread */ mTimer(this) /*NB: set this as parent of timer to manage it from working thread */
{ {
qDebug() << "GVRetSerial()"; qDebug() << "GVRetSerial()";
debugOutput("GVRetSerial()");
serial = NULL; serial = NULL;
rx_state = IDLE; rx_state = IDLE;
@@ -30,6 +32,7 @@ GVRetSerial::~GVRetSerial()
{ {
stop(); stop();
qDebug() << "~GVRetSerial()"; qDebug() << "~GVRetSerial()";
debugOutput("~GVRetSerial()");
} }
@@ -126,6 +129,7 @@ void GVRetSerial::piSetBusSettings(int pBusIdx, CANBus bus)
/* update baud rates */ /* update baud rates */
QByteArray buffer; QByteArray buffer;
qDebug() << "Got signal to update bauds. 1: " << can0Baud <<" 2: " << can1Baud; qDebug() << "Got signal to update bauds. 1: " << can0Baud <<" 2: " << can1Baud;
debugOutput("Got signal to update bauds. 1: " + QString::number(can0Baud) + " 2: " + QString::number(can1Baud));
buffer[0] = (char)0xF1; //start of a command over serial buffer[0] = (char)0xF1; //start of a command over serial
buffer[1] = 5; //setup canbus buffer[1] = 5; //setup canbus
buffer[2] = (unsigned char)(can0Baud & 0xFF); //four bytes of ID LSB first buffer[2] = (unsigned char)(can0Baud & 0xFF); //four bytes of ID LSB first
@@ -175,6 +179,7 @@ bool GVRetSerial::piSendFrame(const CANFrame& frame)
buffer[8 + frame.len] = 0; buffer[8 + frame.len] = 0;
//qDebug() << "writing " << buffer.length() << " bytes to serial port"; //qDebug() << "writing " << buffer.length() << " bytes to serial port";
debugOutput("writing " + QString::number(buffer.length()) + " bytes to serial port");
serial->write(buffer); serial->write(buffer);
return true; return true;
@@ -208,6 +213,7 @@ void GVRetSerial::connectDevice()
serial = new QSerialPort(QSerialPortInfo(getPort())); serial = new QSerialPort(QSerialPortInfo(getPort()));
if(!serial) { if(!serial) {
qDebug() << "can't open serial port " << getPort(); qDebug() << "can't open serial port " << getPort();
debugOutput("can't open serial port " + getPort());
return; return;
} }
@@ -252,6 +258,12 @@ void GVRetSerial::connectDevice()
continuousTimeSync = true; continuousTimeSync = true;
serial->write(output); serial->write(output);
QString buildDebug;
buildDebug = "Write to serial -> ";
foreach (int byt, output) {
buildDebug = buildDebug % QString::number(byt, 16) % " ";
}
debugOutput(buildDebug);
if(doValidation) { if(doValidation) {
QTimer::singleShot(1000, this, SLOT(connectionTimeout())); QTimer::singleShot(1000, this, SLOT(connectionTimeout()));
@@ -300,15 +312,23 @@ void GVRetSerial::readSerialData()
{ {
QByteArray data = serial->readAll(); QByteArray data = serial->readAll();
unsigned char c; unsigned char c;
QString debugBuild;
debugOutput("Got data from serial. Len = " % QString::number(data.length()));
//qDebug() << (tr("Got data from serial. Len = %0").arg(data.length())); //qDebug() << (tr("Got data from serial. Len = %0").arg(data.length()));
for (int i = 0; i < data.length(); i++) for (int i = 0; i < data.length(); i++)
{ {
c = data.at(i); c = data.at(i);
//qDebug() << c << " " << QString::number(c, 16) << " " << QString(c); //qDebug() << c << " " << QString::number(c, 16) << " " << QString(c);
debugBuild = debugBuild % QString::number(c, 16) % " ";
procRXChar(c); procRXChar(c);
} }
debugOutput(debugBuild);
} }
//Debugging data sent from connection window. Inject it into Comm traffic.
void GVRetSerial::debugInput(QByteArray bytes) {
serial->write(bytes);
}
void GVRetSerial::procRXChar(unsigned char c) void GVRetSerial::procRXChar(unsigned char c)
{ {
+3
View File
@@ -54,6 +54,9 @@ protected:
void disconnectDevice(); void disconnectDevice();
public slots:
void debugInput(QByteArray bytes);
private slots: private slots:
void connectDevice(); void connectDevice();
void connectionTimeout(); void connectionTimeout();
+75 -2
View File
@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>956</width> <width>956</width>
<height>527</height> <height>665</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -224,7 +224,11 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="cbSpeed"/> <widget class="QComboBox" name="cbSpeed">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
@@ -246,6 +250,75 @@
</item> </item>
</layout> </layout>
</item> </item>
<item alignment="Qt::AlignHCenter">
<widget class="QCheckBox" name="ckEnableConsole">
<property name="text">
<string>Enable Console</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Device Console:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="textConsole">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Send:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineSend">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QPushButton" name="btnSendHex">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Send Hex</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnSendText">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Send Text</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnClearDebug">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">