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:
@@ -256,6 +256,10 @@ void CANConnection::setCapSuspended(bool pIsSuspended) {
|
||||
mIsCapSuspended = pIsSuspended;
|
||||
}
|
||||
|
||||
void CANConnection::debugInput(QByteArray bytes) {
|
||||
|
||||
}
|
||||
|
||||
bool CANConnection::addTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver)
|
||||
{
|
||||
/*
|
||||
|
||||
@@ -91,6 +91,11 @@ signals:
|
||||
*/
|
||||
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:
|
||||
|
||||
@@ -175,6 +180,8 @@ public slots:
|
||||
*/
|
||||
bool removeAllTargettedFrames(QObject *receiver);
|
||||
|
||||
void debugInput(QByteArray bytes);
|
||||
|
||||
protected:
|
||||
|
||||
//determine if the passed frame is part of a filter or not.
|
||||
|
||||
@@ -22,7 +22,6 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
|
||||
qRegisterMetaType<const CANFrame *>("const CANFrame *");
|
||||
qRegisterMetaType<const QList<CANFrame> *>("const QList<CANFrame> *");
|
||||
|
||||
|
||||
connModel = new CANConnectionModel(this);
|
||||
ui->tableConnections->setModel(connModel);
|
||||
ui->tableConnections->setColumnWidth(0, 50);
|
||||
@@ -39,7 +38,13 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
|
||||
ui->cbSpeed->addItem(tr("250000"));
|
||||
ui->cbSpeed->addItem(tr("500000"));
|
||||
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 */
|
||||
loadConnections();
|
||||
@@ -59,6 +64,10 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
|
||||
connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll);
|
||||
connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll);
|
||||
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()
|
||||
@@ -119,6 +128,28 @@ void ConnectionWindow::setActiveAll(bool pActive)
|
||||
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()
|
||||
{
|
||||
@@ -209,14 +240,17 @@ void ConnectionWindow::handleOKButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConnectionWindow::currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
Q_UNUSED(previous);
|
||||
|
||||
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 */
|
||||
ui->stPort->setEnabled(selIdx==-1);
|
||||
ui->gbType->setEnabled(selIdx==-1);
|
||||
@@ -235,11 +269,16 @@ void ConnectionWindow::currentRowChanged(const QModelIndex ¤t, const QMode
|
||||
}
|
||||
else
|
||||
{
|
||||
int busId;
|
||||
bool ret;
|
||||
CANBus bus;
|
||||
CANConnection* conn_p = connModel->getAtIdx(selIdx, busId);
|
||||
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);
|
||||
if(!ret) return;
|
||||
|
||||
@@ -252,6 +291,29 @@ void ConnectionWindow::currentRowChanged(const QModelIndex ¤t, 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()
|
||||
{
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
signals:
|
||||
void updateBusSettings(CANBus *bus);
|
||||
void updatePortName(QString port);
|
||||
void sendDebugData(QByteArray bytes);
|
||||
|
||||
public slots:
|
||||
void setSpeed(int speed0);
|
||||
@@ -42,15 +43,21 @@ public slots:
|
||||
|
||||
void setSuspendAll(bool pSuspend);
|
||||
|
||||
void getDebugText(QString debugText);
|
||||
|
||||
private slots:
|
||||
void handleOKButton();
|
||||
void handleConnTypeChanged();
|
||||
void currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void consoleEnableChanged(bool checked);
|
||||
void handleRemoveConn();
|
||||
void handleEnableAll();
|
||||
void handleDisableAll();
|
||||
void handleRevert();
|
||||
void handleNewConn();
|
||||
void handleClearDebugText();
|
||||
void handleSendHex();
|
||||
void handleSendText();
|
||||
void connectionStatus(CANCon::status);
|
||||
|
||||
private:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <QCanBusFrame>
|
||||
#include <QSerialPortInfo>
|
||||
#include <QSettings>
|
||||
#include <QStringBuilder>
|
||||
|
||||
#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 */
|
||||
{
|
||||
qDebug() << "GVRetSerial()";
|
||||
debugOutput("GVRetSerial()");
|
||||
|
||||
serial = NULL;
|
||||
rx_state = IDLE;
|
||||
@@ -30,6 +32,7 @@ GVRetSerial::~GVRetSerial()
|
||||
{
|
||||
stop();
|
||||
qDebug() << "~GVRetSerial()";
|
||||
debugOutput("~GVRetSerial()");
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +129,7 @@ void GVRetSerial::piSetBusSettings(int pBusIdx, CANBus bus)
|
||||
/* update baud rates */
|
||||
QByteArray buffer;
|
||||
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[1] = 5; //setup canbus
|
||||
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;
|
||||
|
||||
//qDebug() << "writing " << buffer.length() << " bytes to serial port";
|
||||
debugOutput("writing " + QString::number(buffer.length()) + " bytes to serial port");
|
||||
serial->write(buffer);
|
||||
|
||||
return true;
|
||||
@@ -208,6 +213,7 @@ void GVRetSerial::connectDevice()
|
||||
serial = new QSerialPort(QSerialPortInfo(getPort()));
|
||||
if(!serial) {
|
||||
qDebug() << "can't open serial port " << getPort();
|
||||
debugOutput("can't open serial port " + getPort());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -252,6 +258,12 @@ void GVRetSerial::connectDevice()
|
||||
continuousTimeSync = true;
|
||||
|
||||
serial->write(output);
|
||||
QString buildDebug;
|
||||
buildDebug = "Write to serial -> ";
|
||||
foreach (int byt, output) {
|
||||
buildDebug = buildDebug % QString::number(byt, 16) % " ";
|
||||
}
|
||||
debugOutput(buildDebug);
|
||||
|
||||
if(doValidation) {
|
||||
QTimer::singleShot(1000, this, SLOT(connectionTimeout()));
|
||||
@@ -300,15 +312,23 @@ void GVRetSerial::readSerialData()
|
||||
{
|
||||
QByteArray data = serial->readAll();
|
||||
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()));
|
||||
for (int i = 0; i < data.length(); i++)
|
||||
{
|
||||
c = data.at(i);
|
||||
//qDebug() << c << " " << QString::number(c, 16) << " " << QString(c);
|
||||
debugBuild = debugBuild % QString::number(c, 16) % " ";
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -54,6 +54,9 @@ protected:
|
||||
|
||||
void disconnectDevice();
|
||||
|
||||
public slots:
|
||||
void debugInput(QByteArray bytes);
|
||||
|
||||
private slots:
|
||||
void connectDevice();
|
||||
void connectionTimeout();
|
||||
|
||||
+75
-2
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>956</width>
|
||||
<height>527</height>
|
||||
<height>665</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -224,7 +224,11 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cbSpeed"/>
|
||||
<widget class="QComboBox" name="cbSpeed">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
@@ -246,6 +250,75 @@
|
||||
</item>
|
||||
</layout>
|
||||
</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>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
||||
Reference in New Issue
Block a user