Fleshed out more importers, added some preliminaries for serial port support.
This commit is contained in:
+5
-3
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
QT += core gui
|
QT += core gui
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets serialport
|
||||||
|
|
||||||
TARGET = SavvyCAN
|
TARGET = SavvyCAN
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
@@ -14,10 +14,12 @@ TEMPLATE = app
|
|||||||
|
|
||||||
SOURCES += main.cpp\
|
SOURCES += main.cpp\
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
canframemodel.cpp
|
canframemodel.cpp \
|
||||||
|
utility.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
can_structs.h \
|
can_structs.h \
|
||||||
canframemodel.h
|
canframemodel.h \
|
||||||
|
utility.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui
|
FORMS += mainwindow.ui
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 3.4.0, 2015-04-27T17:16:33. -->
|
<!-- Written by QtCreator 3.4.0, 2015-04-27T20:47:19. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
|||||||
+117
-4
@@ -3,7 +3,9 @@
|
|||||||
#include "can_structs.h"
|
#include "can_structs.h"
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QtSerialPort/QSerialPortInfo>
|
||||||
#include "canframemodel.h"
|
#include "canframemodel.h"
|
||||||
|
#include "utility.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
@@ -22,6 +24,15 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->canFramesView->setColumnWidth(3, 40);
|
ui->canFramesView->setColumnWidth(3, 40);
|
||||||
ui->canFramesView->setColumnWidth(4, 40);
|
ui->canFramesView->setColumnWidth(4, 40);
|
||||||
ui->canFramesView->setColumnWidth(5, 300);
|
ui->canFramesView->setColumnWidth(5, 300);
|
||||||
|
|
||||||
|
QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
|
||||||
|
|
||||||
|
for (int i = 0; i < ports.count(); i++)
|
||||||
|
{
|
||||||
|
ui->cbSerialPorts->addItem(ports[i].portName());
|
||||||
|
}
|
||||||
|
|
||||||
|
port = new QSerialPort(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@@ -43,12 +54,15 @@ void MainWindow::loadNativeCSVFile(QString filename)
|
|||||||
{
|
{
|
||||||
QFile *inFile = new QFile(filename);
|
QFile *inFile = new QFile(filename);
|
||||||
CANFrame thisFrame;
|
CANFrame thisFrame;
|
||||||
|
QByteArray line;
|
||||||
|
|
||||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
line = inFile->readLine(); //read out the header first and discard it.
|
||||||
|
|
||||||
while (!inFile->atEnd()) {
|
while (!inFile->atEnd()) {
|
||||||
QByteArray line = inFile->readLine();
|
line = inFile->readLine();
|
||||||
if (line.length() > 2)
|
if (line.length() > 2)
|
||||||
{
|
{
|
||||||
QList<QByteArray> tokens = line.split(',');
|
QList<QByteArray> tokens = line.split(',');
|
||||||
@@ -64,7 +78,8 @@ void MainWindow::loadNativeCSVFile(QString filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
thisFrame.ID = tokens[1].toInt(NULL, 16);
|
thisFrame.ID = tokens[1].toInt(NULL, 16);
|
||||||
thisFrame.extended = tokens[2].toInt();
|
if (tokens[2].contains("True")) thisFrame.extended = 1;
|
||||||
|
else thisFrame.extended = 0;
|
||||||
thisFrame.bus = tokens[3].toInt();
|
thisFrame.bus = tokens[3].toInt();
|
||||||
thisFrame.len = tokens[4].toInt();
|
thisFrame.len = tokens[4].toInt();
|
||||||
for (int c = 0; c < 8; c++) thisFrame.data[c] = 0;
|
for (int c = 0; c < 8; c++) thisFrame.data[c] = 0;
|
||||||
@@ -80,6 +95,37 @@ void MainWindow::loadNativeCSVFile(QString filename)
|
|||||||
|
|
||||||
void MainWindow::loadGenericCSVFile(QString filename)
|
void MainWindow::loadGenericCSVFile(QString filename)
|
||||||
{
|
{
|
||||||
|
QFile *inFile = new QFile(filename);
|
||||||
|
CANFrame thisFrame;
|
||||||
|
QByteArray line;
|
||||||
|
|
||||||
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
return;
|
||||||
|
|
||||||
|
line = inFile->readLine(); //read out the header first and discard it.
|
||||||
|
|
||||||
|
while (!inFile->atEnd()) {
|
||||||
|
line = inFile->readLine();
|
||||||
|
if (line.length() > 2)
|
||||||
|
{
|
||||||
|
QList<QByteArray> tokens = line.split(',');
|
||||||
|
|
||||||
|
QDateTime stamp = QDateTime::currentDateTime();
|
||||||
|
thisFrame.timestamp = (long)(((stamp.time().hour() * 3600) + (stamp.time().minute() * 60) + (stamp.time().second()) * 1000) + stamp.time().msec());
|
||||||
|
thisFrame.ID = tokens[0].toInt(NULL, 16);
|
||||||
|
if (thisFrame.ID > 0x7FF) thisFrame.extended = true;
|
||||||
|
else thisFrame.extended = false;
|
||||||
|
thisFrame.bus = 0;
|
||||||
|
QList<QByteArray> dataTok = tokens[1].split(' ');
|
||||||
|
thisFrame.len = dataTok.length();
|
||||||
|
if (thisFrame.len > 8) thisFrame.len = 8;
|
||||||
|
for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = dataTok[d].toInt(NULL, 16);
|
||||||
|
|
||||||
|
addFrameToDisplay(thisFrame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inFile->close();
|
||||||
|
model->sendRefresh();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,11 +136,58 @@ void MainWindow::loadLogFile(QString filename)
|
|||||||
|
|
||||||
void MainWindow::loadMicrochipFile(QString filename)
|
void MainWindow::loadMicrochipFile(QString filename)
|
||||||
{
|
{
|
||||||
|
QFile *inFile = new QFile(filename);
|
||||||
|
CANFrame thisFrame;
|
||||||
|
QByteArray line;
|
||||||
|
bool inComment = false;
|
||||||
|
|
||||||
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
return;
|
||||||
|
|
||||||
|
line = inFile->readLine(); //read out the header first and discard it.
|
||||||
|
|
||||||
|
while (!inFile->atEnd()) {
|
||||||
|
line = inFile->readLine();
|
||||||
|
if (line.length() > 2)
|
||||||
|
{
|
||||||
|
if (line.startsWith("//"))
|
||||||
|
{
|
||||||
|
inComment = !inComment;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
tokens:
|
||||||
|
0 = timestamp
|
||||||
|
1 = Transmission direction
|
||||||
|
2 = ID
|
||||||
|
3 = Data byte length
|
||||||
|
4-x = The data bytes
|
||||||
|
*/
|
||||||
|
if (!inComment)
|
||||||
|
{
|
||||||
|
QList<QByteArray> tokens = line.split(';');
|
||||||
|
QDateTime stamp = QDateTime::currentDateTime();
|
||||||
|
thisFrame.timestamp = (long)(((stamp.time().hour() * 3600) + (stamp.time().minute() * 60) + (stamp.time().second()) * 1000) + stamp.time().msec());
|
||||||
|
|
||||||
|
//thisFrame.ID = Utility::ParseStringToNum(tokens[2]);
|
||||||
|
if (thisFrame.ID <= 0x7FF) thisFrame.extended = false;
|
||||||
|
else thisFrame.extended = true;
|
||||||
|
thisFrame.bus = 0;
|
||||||
|
thisFrame.len = tokens[3].toInt();
|
||||||
|
//for (int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)Utility::ParseStringToNum(tokens[4 + d]);
|
||||||
|
addFrameToDisplay(thisFrame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inFile->close();
|
||||||
|
model->sendRefresh();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::handleLoadFile()
|
void MainWindow::handleLoadFile()
|
||||||
{
|
{
|
||||||
QString filename;
|
QString filename;
|
||||||
@@ -122,3 +215,23 @@ void MainWindow::handleLoadFile()
|
|||||||
if (dialog.selectedNameFilter() == filters[3]) loadLogFile(filename);
|
if (dialog.selectedNameFilter() == filters[3]) loadLogFile(filename);
|
||||||
if (dialog.selectedNameFilter() == filters[4]) loadMicrochipFile(filename);
|
if (dialog.selectedNameFilter() == filters[4]) loadMicrochipFile(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::connButtonPress()
|
||||||
|
{
|
||||||
|
if (port->isOpen())
|
||||||
|
{
|
||||||
|
port->close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
port->setPortName(ui->cbSerialPorts->currentText());
|
||||||
|
port->open(QIODevice::ReadWrite);
|
||||||
|
QByteArray output;
|
||||||
|
output.append(0xE7);
|
||||||
|
output.append(0xE7);
|
||||||
|
port->write(output);
|
||||||
|
///isConnected = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QSerialPort>
|
||||||
#include "canframemodel.h"
|
#include "canframemodel.h"
|
||||||
#include "can_structs.h"
|
#include "can_structs.h"
|
||||||
|
|
||||||
@@ -19,10 +20,12 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleLoadFile();
|
void handleLoadFile();
|
||||||
|
void connButtonPress();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
CANFrameModel *model;
|
CANFrameModel *model;
|
||||||
|
QSerialPort *port;
|
||||||
void loadCRTDFile(QString);
|
void loadCRTDFile(QString);
|
||||||
void loadNativeCSVFile(QString);
|
void loadNativeCSVFile(QString);
|
||||||
void loadGenericCSVFile(QString);
|
void loadGenericCSVFile(QString);
|
||||||
|
|||||||
+57
-4
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1016</width>
|
<width>927</width>
|
||||||
<height>600</height>
|
<height>500</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>600</height>
|
<height>500</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -42,13 +42,49 @@
|
|||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</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>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menuBar">
|
<widget class="QMenuBar" name="menuBar">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1016</width>
|
<width>927</width>
|
||||||
<height>26</height>
|
<height>26</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@@ -154,8 +190,25 @@
|
|||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>btnConnect</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>MainWindow</receiver>
|
||||||
|
<slot>connButtonPress()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>820</x>
|
||||||
|
<y>103</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>463</x>
|
||||||
|
<y>249</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
</connections>
|
</connections>
|
||||||
<slots>
|
<slots>
|
||||||
<slot>handleLoadFile()</slot>
|
<slot>handleLoadFile()</slot>
|
||||||
|
<slot>connButtonPress()</slot>
|
||||||
</slots>
|
</slots>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#include "utility.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
#ifndef UTILITY_H
|
||||||
|
#define UTILITY_H
|
||||||
|
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Utility
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static int ParseStringToNum(QByteArray input)
|
||||||
|
{
|
||||||
|
int temp = 0;
|
||||||
|
|
||||||
|
input = input.toUpper();
|
||||||
|
if (input.startsWith("0X")) //hex number
|
||||||
|
{
|
||||||
|
temp = input.right(input.size() - 2).toInt(NULL, 16);
|
||||||
|
}
|
||||||
|
else if (input.startsWith("B")) //binary number
|
||||||
|
{
|
||||||
|
input = input.right(input.size() - 1); //remove the B
|
||||||
|
for (int i = 0; i < input.length(); i++)
|
||||||
|
{
|
||||||
|
if (input[i] == '1') temp += 1 << (input.length() - i - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else //decimal number
|
||||||
|
{
|
||||||
|
temp = input.toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static long GetTimeMS()
|
||||||
|
{
|
||||||
|
QDateTime stamp = QDateTime::currentDateTime();
|
||||||
|
return (long)(((stamp.time().hour() * 3600) + (stamp.time().minute() * 60) + (stamp.time().second()) * 1000) + stamp.time().msec());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UTILITY_H
|
||||||
Reference in New Issue
Block a user