Reorganized the main window to properly resize. Added baud rate setting. Added ability to send frames from this application.
This commit is contained in:
+10
-9
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 3.4.0, 2015-05-05T23:03:39. -->
|
||||
<!-- Written by QtCreator 3.4.0, 2015-05-06T22:38:23. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
@@ -8,7 +8,7 @@
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
<value type="int">0</value>
|
||||
<value type="int">1</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||
@@ -413,15 +413,16 @@
|
||||
<value type="int">13</value>
|
||||
<value type="int">14</value>
|
||||
</valuelist>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">-1</value>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments"></value>
|
||||
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value>
|
||||
<value type="bool" key="ProjectExplorer.CustomExecutableRunConfiguration.UseTerminal">false</value>
|
||||
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory">%{buildDir}</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Executable</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">SavvyCAN</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Collin/Desktop/SavvyCAN/SavvyCAN.pro</value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">SavvyCAN.pro</value>
|
||||
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
|
||||
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
|
||||
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
|
||||
+63
-3
@@ -45,13 +45,25 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui->cbSerialPorts->addItem(ports[i].portName());
|
||||
}
|
||||
|
||||
ui->cbSpeed1->addItem(tr("Disabled"));
|
||||
ui->cbSpeed1->addItem(tr("125000"));
|
||||
ui->cbSpeed1->addItem(tr("250000"));
|
||||
ui->cbSpeed1->addItem(tr("500000"));
|
||||
ui->cbSpeed1->addItem(tr("1000000"));
|
||||
ui->cbSpeed1->addItem(tr("33333"));
|
||||
ui->cbSpeed2->addItem(tr("Disabled"));
|
||||
ui->cbSpeed2->addItem(tr("125000"));
|
||||
ui->cbSpeed2->addItem(tr("250000"));
|
||||
ui->cbSpeed2->addItem(tr("500000"));
|
||||
ui->cbSpeed2->addItem(tr("1000000"));
|
||||
ui->cbSpeed2->addItem(tr("33333"));
|
||||
|
||||
SerialWorker *worker = new SerialWorker();
|
||||
worker->moveToThread(&serialWorkerThread);
|
||||
connect(&serialWorkerThread, &QThread::finished, worker, &QObject::deleteLater);
|
||||
//connect(this, &Controller::operate, worker, &Worker::doWork);
|
||||
//connect(worker, &Worker::resultReady, this, &Controller::handleResults);
|
||||
connect(this, &MainWindow::sendSerialPort, worker, &SerialWorker::setSerialPort, Qt::QueuedConnection);
|
||||
connect(worker, &SerialWorker::receivedFrame, this, &MainWindow::gotFrame, Qt::QueuedConnection);
|
||||
connect(this, &MainWindow::updateBaudRates, worker, &SerialWorker::updateBaudRates, Qt::QueuedConnection);
|
||||
serialWorkerThread.start();
|
||||
|
||||
graphingWindow = NULL;
|
||||
@@ -65,7 +77,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
connect(ui->btnClearFrames, SIGNAL(clicked(bool)), this, SLOT(clearFrames()));
|
||||
connect(ui->actionSave_Log_File, SIGNAL(triggered(bool)), this, SLOT(handleSaveFile()));
|
||||
connect(ui->action_Playback, SIGNAL(triggered(bool)), this, SLOT(showPlaybackWindow()));
|
||||
|
||||
connect(ui->btnBaudSet, SIGNAL(clicked(bool)), this, SLOT(changeBaudRates()));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -101,6 +113,54 @@ void MainWindow::clearFrames()
|
||||
ui->lbNumFrames->setText(QString::number(model->rowCount()));
|
||||
}
|
||||
|
||||
void MainWindow::changeBaudRates()
|
||||
{
|
||||
int Speed1 = 0, Speed2 = 0;
|
||||
|
||||
switch (ui->cbSpeed1->currentIndex())
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
//CRTD format from Mark Webb-Johnson / OVMS project
|
||||
/*
|
||||
Sample data in CRTD format
|
||||
|
||||
@@ -29,12 +29,14 @@ private slots:
|
||||
void showFrameDataAnalysis();
|
||||
void clearFrames();
|
||||
void showPlaybackWindow();
|
||||
void changeBaudRates();
|
||||
|
||||
public slots:
|
||||
void gotFrame(CANFrame *frame);
|
||||
|
||||
signals:
|
||||
void sendSerialPort(QString portName);
|
||||
void updateBaudRates(int, int);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
+161
-116
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>927</width>
|
||||
<width>800</width>
|
||||
<height>500</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -26,127 +26,172 @@
|
||||
<string>SavvyCAN</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<widget class="QTableView" name="canFramesView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>10</y>
|
||||
<width>675</width>
|
||||
<height>421</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>11</pointsize>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>720</x>
|
||||
<y>20</y>
|
||||
<width>71</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Serial Port</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="cbSerialPorts">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>790</x>
|
||||
<y>20</y>
|
||||
<width>131</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btnConnect">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>720</x>
|
||||
<y>50</y>
|
||||
<width>201</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Connect To Dongle</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>720</x>
|
||||
<y>160</y>
|
||||
<width>71</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string># of frames:</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btnClearFrames">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>710</x>
|
||||
<y>180</y>
|
||||
<width>201</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Clear Frames</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="lbNumFrames">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>810</x>
|
||||
<y>160</y>
|
||||
<width>55</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="cbAutoScroll">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>710</x>
|
||||
<y>250</y>
|
||||
<width>201</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Auto scroll window</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QTableView" name="canFramesView">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>11</pointsize>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Serial Port</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cbSerialPorts"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnConnect">
|
||||
<property name="text">
|
||||
<string>Connect To Dongle</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>CANBus Speeds:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>First Bus:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cbSpeed1"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>7</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Second Bus:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cbSpeed2"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnBaudSet">
|
||||
<property name="text">
|
||||
<string>Set Baud Rates</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string># Of Frames:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QLabel" name="lbNumFrames">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="cbAutoScroll">
|
||||
<property name="text">
|
||||
<string>Auto Scroll Window</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnClearFrames">
|
||||
<property name="text">
|
||||
<string>Clear Frames</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>927</width>
|
||||
<width>800</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
||||
@@ -50,6 +50,54 @@ void SerialWorker::readSerialData()
|
||||
}
|
||||
}
|
||||
|
||||
void SerialWorker::sendFrame(CANFrame *frame, int bus = 0)
|
||||
{
|
||||
QByteArray buffer;
|
||||
int c;
|
||||
int ID;
|
||||
|
||||
ID = frame->ID;
|
||||
if (frame->extended) ID |= 1 << 31;
|
||||
|
||||
buffer[0] = 0xF1; //start of a command over serial
|
||||
buffer[1] = 0; //command ID for sending a CANBUS frame
|
||||
buffer[2] = (unsigned char)(ID & 0xFF); //four bytes of ID LSB first
|
||||
buffer[3] = (unsigned char)(ID >> 8);
|
||||
buffer[4] = (unsigned char)(ID >> 16);
|
||||
buffer[5] = (unsigned char)(ID >> 24);
|
||||
buffer[6] = (unsigned char)(bus & 1);
|
||||
buffer[7] = (unsigned char)frame->len;
|
||||
for (c = 0; c < frame->len; c++)
|
||||
{
|
||||
buffer[8 + c] = frame->data[c];
|
||||
}
|
||||
buffer[8 + frame->len] = 0;
|
||||
|
||||
if (serial == NULL) return;
|
||||
if (!serial->isOpen()) return;
|
||||
serial->write(buffer);
|
||||
}
|
||||
|
||||
void SerialWorker::updateBaudRates(int Speed1, int Speed2)
|
||||
{
|
||||
QByteArray buffer;
|
||||
qDebug() << "Got signal to update bauds. 1: " << Speed1 <<" 2: " << Speed2;
|
||||
buffer[0] = 0xF1; //start of a command over serial
|
||||
buffer[1] = 5; //setup canbus
|
||||
buffer[2] = (unsigned char)(Speed1 & 0xFF); //four bytes of ID LSB first
|
||||
buffer[3] = (unsigned char)(Speed1 >> 8);
|
||||
buffer[4] = (unsigned char)(Speed1 >> 16);
|
||||
buffer[5] = (unsigned char)(Speed1 >> 24);
|
||||
buffer[6] = (unsigned char)(Speed2 & 0xFF); //four bytes of ID LSB first
|
||||
buffer[7] = (unsigned char)(Speed2 >> 8);
|
||||
buffer[8] = (unsigned char)(Speed2 >> 16);
|
||||
buffer[9] = (unsigned char)(Speed2 >> 24);
|
||||
buffer[10] = 0;
|
||||
if (serial == NULL) return;
|
||||
if (!serial->isOpen()) return;
|
||||
serial->write(buffer);
|
||||
}
|
||||
|
||||
void SerialWorker::procRXChar(unsigned char c)
|
||||
{
|
||||
switch (rx_state)
|
||||
|
||||
+8
-5
@@ -26,14 +26,17 @@ public:
|
||||
~SerialWorker();
|
||||
|
||||
signals: //we emit signals
|
||||
void error(const QString &s);
|
||||
void receivedFrame(CANFrame *frame);
|
||||
void error(const QString &);
|
||||
void receivedFrame(CANFrame *);
|
||||
|
||||
private slots: //we receive things in slots
|
||||
void readSerialData();
|
||||
void readSerialData();
|
||||
|
||||
public slots:
|
||||
void setSerialPort(QString portName);
|
||||
void setSerialPort(QString);
|
||||
void sendFrame(CANFrame *, int);
|
||||
void updateBaudRates(int, int);
|
||||
|
||||
|
||||
private:
|
||||
QString portName;
|
||||
@@ -43,7 +46,7 @@ private:
|
||||
int rx_step;
|
||||
CANFrame *buildFrame;
|
||||
|
||||
void procRXChar(unsigned char c);
|
||||
void procRXChar(unsigned char);
|
||||
};
|
||||
|
||||
#endif // SERIALTHREAD_H
|
||||
|
||||
Reference in New Issue
Block a user