Merge branch 'master' of github.com:collin80/SavvyCAN

Conflicts:
	SavvyCAN.pro
	mainwindow.cpp
	mainwindow.h
This commit is contained in:
Collin Kidder
2015-08-28 11:37:44 -04:00
8 changed files with 440 additions and 6 deletions
+6 -3
View File
@@ -35,7 +35,8 @@ SOURCES += main.cpp\
framefileio.cpp \
filecomparatorwindow.cpp \
mainsettingsdialog.cpp \
firmwareuploaderwindow.cpp
firmwareuploaderwindow.cpp \
discretestatewindow.cpp
HEADERS += mainwindow.h \
can_structs.h \
@@ -59,7 +60,8 @@ HEADERS += mainwindow.h \
config.h \
filecomparatorwindow.h \
mainsettingsdialog.h \
firmwareuploaderwindow.h
firmwareuploaderwindow.h \
discretestatewindow.h
FORMS += mainwindow.ui \
graphingwindow.ui \
@@ -73,7 +75,8 @@ FORMS += mainwindow.ui \
dbcsignaleditor.ui \
filecomparatorwindow.ui \
mainsettingsdialog.ui \
firmwareuploaderwindow.ui
firmwareuploaderwindow.ui \
discretestatewindow.ui
DISTFILES +=
+3 -1
View File
@@ -225,7 +225,9 @@ void DBCHandler::loadDBCFile(QString filename)
val.descript = match.captured(2);
//qDebug() << "sig val " << val.value << " desc " <<val.descript;
sig->valList.append(val);
tokenString = tokenString.right(tokenString.length() - match.captured(1).length() - match.captured(2).length() - 4);
int rightSize = tokenString.length() - match.captured(1).length() - match.captured(2).length() - 4;
if (rightSize > 0) tokenString = tokenString.right(rightSize);
else tokenString = "";
//qDebug() << "New token string: " << tokenString;
}
else tokenString = "";
+196
View File
@@ -0,0 +1,196 @@
#include "discretestatewindow.h"
#include "ui_discretestatewindow.h"
#include "mainwindow.h"
DiscreteStateWindow::DiscreteStateWindow(const QVector<CANFrame> *frames, QWidget *parent) :
QDialog(parent),
ui(new Ui::DiscreteStateWindow)
{
ui->setupUi(this);
modelFrames = frames;
operatingState = DWStates::IDLE;
timer = new QTimer();
timer->setInterval(100);
connect(ui->btnStart, SIGNAL(clicked(bool)), this, SLOT(handleStartButton()));
connect(timer, SIGNAL(timeout()), this, SLOT(handleTick()));
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));
}
DiscreteStateWindow::~DiscreteStateWindow()
{
timer->stop();
for (int i = 0; i < stateFrames.count(); i++)
{
stateFrames[i]->clear();
delete(stateFrames[i]);
}
delete timer;
delete ui;
}
void DiscreteStateWindow::updatedFrames(int numFrames)
{
CANFrame thisFrame;
if (numFrames == -1) //all frames deleted. Kill the display
{
}
else if (numFrames == -2) //all new set of frames. Reset
{
}
else //just got some new frames. See if they are relevant.
{
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++)
{
thisFrame = modelFrames->at(i);
if (operatingState == DWStates::IDLE) stateFrames[0]->append(thisFrame);
else stateFrames[currToggleState + 1]->append(thisFrame);
}
}
}
void DiscreteStateWindow::showEvent(QShowEvent* event)
{
QDialog::showEvent(event);
readSettings();
qDebug() << "DiscreteState show event was processed";
}
void DiscreteStateWindow::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event);
writeSettings();
}
void DiscreteStateWindow::readSettings()
{
QSettings settings;
if (settings.value("Main/SaveRestorePositions", false).toBool())
{
resize(settings.value("DiscreteState/WindowSize", QSize(400, 300)).toSize());
move(settings.value("DiscreteState/WindowPos", QPoint(50, 50)).toPoint());
}
}
void DiscreteStateWindow::writeSettings()
{
QSettings settings;
if (settings.value("Main/SaveRestorePositions", false).toBool())
{
settings.setValue("DiscreteState/WindowSize", size());
settings.setValue("DiscreteState/WindowPos", pos());
}
}
void DiscreteStateWindow::updateStateLabel()
{
QPalette pal;
switch(operatingState)
{
case DWStates::IDLE:
ui->lblStatus->setText("WAIT");
pal = ui->lblStatus->palette();
pal.setColor(QPalette::WindowText, Qt::red);
ui->lblStatus->setPalette(pal);
break;
case DWStates::COUNTDOWN_SIGNAL:
ui->lblStatus->setText(QString::number(ticksUntilStateChange * 0.1, 'f', 1) + "...");
pal = ui->lblStatus->palette();
pal.setColor(QPalette::WindowText, Qt::blue);
ui->lblStatus->setPalette(pal);
break;
case DWStates::COUNTDOWN_WAITING:
ui->lblStatus->setText("Return to resting state");
pal = ui->lblStatus->palette();
pal.setColor(QPalette::WindowText, Qt::red);
ui->lblStatus->setPalette(pal);
break;
case DWStates::GETTING_SIGNAL:
ui->lblStatus->setText("Go to state " + QString::number(currToggleState + 1));
pal = ui->lblStatus->palette();
pal.setColor(QPalette::WindowText, Qt::green);
ui->lblStatus->setPalette(pal);
break;
}
}
void DiscreteStateWindow::handleStartButton()
{
operatingState = DWStates::COUNTDOWN_SIGNAL;
ticksPerStateChange = ticksUntilStateChange = ui->spinFreq->value() * 10;
numToggleStates = ui->spinStates->value();
numIterations = ui->spinIterations->value();
currToggleState = 0;
currIteration = 0;
for (int i = 0; i < stateFrames.count(); i++)
{
stateFrames[i]->clear();
delete(stateFrames[i]);
}
for (int j = 0; j <= numToggleStates; j++)
{
stateFrames.append(new QVector<CANFrame>());
}
timer->start();
}
void DiscreteStateWindow::handleTick()
{
switch (operatingState)
{
case DWStates::IDLE:
break;
case DWStates::COUNTDOWN_SIGNAL:
ticksUntilStateChange--;
if (ticksUntilStateChange == 0)
{
ticksUntilStateChange = ticksPerStateChange;
operatingState = DWStates::GETTING_SIGNAL;
}
break;
case DWStates::COUNTDOWN_WAITING:
ticksUntilStateChange--;
if (ticksUntilStateChange == 0)
{
ticksUntilStateChange = ticksPerStateChange;
currIteration++;
if (currIteration == numIterations)
{
operatingState = DWStates::IDLE;
timer->stop();
//call to calculate our findings here.
}
else operatingState = DWStates::COUNTDOWN_SIGNAL;
}
break;
case DWStates::GETTING_SIGNAL:
ticksUntilStateChange--;
if (ticksUntilStateChange == 0)
{
ticksUntilStateChange = ticksPerStateChange;
operatingState = DWStates::COUNTDOWN_WAITING;
currToggleState++;
if (currToggleState == numToggleStates) currToggleState = 0;
}
break;
}
updateStateLabel();
}
void DiscreteStateWindow::calculateResults()
{
}
+57
View File
@@ -0,0 +1,57 @@
#ifndef DISCRETESTATEWINDOW_H
#define DISCRETESTATEWINDOW_H
#include <QDialog>
#include <QTimer>
#include "can_structs.h"
namespace Ui {
class DiscreteStateWindow;
}
namespace DWStates {
enum DiscreteWindowState
{
IDLE,
COUNTDOWN_SIGNAL,
COUNTDOWN_WAITING,
GETTING_SIGNAL
};
}
using namespace DWStates;
class DiscreteStateWindow : public QDialog
{
Q_OBJECT
public:
explicit DiscreteStateWindow(const QVector<CANFrame> *frames, QWidget *parent = 0);
~DiscreteStateWindow();
void showEvent(QShowEvent*);
private slots:
void updatedFrames(int);
void handleStartButton();
void handleTick();
private:
Ui::DiscreteStateWindow *ui;
const QVector<CANFrame> *modelFrames;
QList< QVector<CANFrame> *> stateFrames;
QTimer *timer;
DiscreteWindowState operatingState;
int ticksUntilStateChange;
int ticksPerStateChange;
int numToggleStates;
int currToggleState;
int numIterations;
int currIteration;
void closeEvent(QCloseEvent *event);
void readSettings();
void writeSettings();
void updateStateLabel();
void calculateResults();
};
#endif // DISCRETESTATEWINDOW_H
+154
View File
@@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DiscreteStateWindow</class>
<widget class="QDialog" name="DiscreteStateWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Single/Multi State WIndow</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label">
<property name="text">
<string>Candidate Matches:</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="treeMatches">
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Number of States:</string>
</property>
</widget>
</item>
<item row="0" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Toggle Frequency (Seconds)</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QSpinBox" name="spinFreq">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>30</number>
</property>
<property name="value">
<number>2</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinStates">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>20</number>
</property>
</widget>
</item>
<item row="0" column="2" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Iterations</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="spinIterations">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="btnStart">
<property name="text">
<string>Go for it</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="lblStatus">
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>120</red>
<green>120</green>
<blue>120</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<pointsize>26</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>WAIT</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
+16 -1
View File
@@ -10,9 +10,13 @@
/*
Things that were planned for the GVRET-PC project but never completed.
Single / Multi state - The goal is to find bits that change based on toggles or discrete state items (shifters, etc)
Range state - Find things that range like accelerator pedal inputs, road speed, tach, etc
fuzzy scope - Try to find potential places where a given value might be stored - offer guesses and the program tries to find candidates for you
or, try to find things that appear to be multi-byte integers
*/
QString MainWindow::loadedFileName = "";
@@ -105,6 +109,7 @@ MainWindow::MainWindow(QWidget *parent) :
comparatorWindow = NULL;
settingsDialog = NULL;
firmwareUploaderWindow = NULL;
discreteStateWindow = NULL;
dbcHandler = new DBCHandler;
bDirty = false;
inhibitFilterUpdate = false;
@@ -226,6 +231,12 @@ MainWindow::~MainWindow()
delete settingsDialog;
}
if (discreteStateWindow)
{
discreteStateWindow->close();
delete discreteStateWindow;
}
delete ui;
delete dbcHandler;
model->clearFrames();
@@ -1001,7 +1012,11 @@ void MainWindow::showComparisonWindow()
void MainWindow::showSingleMultiWindow()
{
//not done yet
if (!discreteStateWindow)
{
discreteStateWindow = new DiscreteStateWindow(model->getListReference());
}
discreteStateWindow->show();
}
void MainWindow::showRangeWindow()
+2
View File
@@ -18,6 +18,7 @@
#include "dbcmaineditor.h"
#include "mainsettingsdialog.h"
#include "firmwareuploaderwindow.h"
#include "discretestatewindow.h"
namespace Ui {
class MainWindow;
@@ -118,6 +119,7 @@ private:
DBCMainEditor *dbcMainEditor;
FileComparatorWindow *comparatorWindow;
MainSettingsDialog *settingsDialog;
DiscreteStateWindow *discreteStateWindow;
FirmwareUploaderWindow *firmwareUploaderWindow;
//various private storage
+5
View File
@@ -9,6 +9,8 @@
#include "can_structs.h"
#include "canframemodel.h"
namespace SERIALSTATE {
enum STATE //keep this enum synchronized with the Arduino firmware project
{
IDLE,
@@ -24,6 +26,9 @@ enum STATE //keep this enum synchronized with the Arduino firmware project
SET_SINGLEWIRE_MODE
};
}
using namespace SERIALSTATE;
class SerialWorker : public QObject
{
Q_OBJECT