Skip to content

Commit

Permalink
FreeEmsPlugin: Better handling of disconnect detection and reconnect …
Browse files Browse the repository at this point in the history
…syncing

EMSTune will now pop up a display when it detects that it has connected to
a device with differing non-readonly memory locations. It will also allow the
user to either send local changes to the ECU,or accept ECU defaults as the
current memory situation.

The plugin will also notify the user when it has detected that the ECU has
gone silent for more than 1500 milliseconds. This will be user configurable
in the future once plugin-specific settings are supported.

Added functionality to actually check if incoming data is
different from what is stored in application memory and
sendinga notification to the the user. This is a temp commit
to trigger a test build and will be replaced with an actual
commit containing a proper diff window of some sort of the data

iTEmp
  • Loading branch information
malcom2073 committed May 20, 2014
1 parent 192346b commit 9ad63d8
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 17 deletions.
9 changes: 6 additions & 3 deletions core/core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ SOURCES += src/main.cpp\
src/gaugeutil.cpp \
src/roundgaugeitem.cpp \
src/scalarparam.cpp \
src/comboparam.cpp
src/comboparam.cpp \
src/ramdiffwindow.cpp


HEADERS += src/mainwindow.h \
Expand Down Expand Up @@ -172,7 +173,8 @@ HEADERS += src/mainwindow.h \
src/roundgaugeitem.h \
src/gaugeutil.h \
src/scalarparam.h \
src/comboparam.h
src/comboparam.h \
src/ramdiffwindow.h

FORMS += src/mainwindow.ui \
src/comsettings.ui \
Expand All @@ -194,7 +196,8 @@ FORMS += src/mainwindow.ui \
src/firmwaremetadata.ui \
src/scalarparam.ui \
src/comboparam.ui \
src/parameterwidget.ui
src/parameterwidget.ui \
src/ramdiffwindow.ui
SUBDIRS += plugins
OTHER_FILES += \
README.md \
Expand Down
53 changes: 53 additions & 0 deletions core/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
QLOG_INFO() << "Full hash:" << define2string(GIT_HASH);
progressView=0;
emsComms=0;
ramDiffWindow=0;
m_interrogationInProgress = false;
m_debugLogs = false;
emsSilenceTimer = new QTimer(this);
connect(emsSilenceTimer,SIGNAL(timeout()),this,SLOT(emsCommsSilenceTimerTick()));

// emsData = new EmsData();
// connect(emsData,SIGNAL(updateRequired(unsigned short)),this,SLOT(updateDataWindows(unsigned short)));
Expand Down Expand Up @@ -607,12 +610,33 @@ void MainWindow::emsCommsSilence()
{
//This is called when the ems has been silent for 5 seconds, when it was previously talking.
QLOG_WARN() << "EMS HAS GONE SILENT";
ui.statusLabel->setStyleSheet("background-color: rgb(255, 0, 0);");
ui.statusLabel->setText("EMS SILENT");
emsSilenceTimer->start(250);
QMessageBox::information(this,"Warning","ECU has gone silent. If this is unintentional, it may be a sign that something is wrong...");

}
void MainWindow::emsCommsSilenceTimerTick()
{
if (m_emsSilenceLabelIsRed)
{
m_emsSilenceLabelIsRed = false;
ui.statusLabel->setStyleSheet("color: rgb(255, 255, 0);\nbackground-color: rgb(255, 85, 0);");
}
else
{
m_emsSilenceLabelIsRed = true;
ui.statusLabel->setStyleSheet("color: rgb(255, 255, 0);\nbackground-color: rgb(255, 0, 0);");
}
}

void MainWindow::emsCommsSilenceBroken()
{
//This is called when ems had previously been talking, gone silent, then started talking again.
ui.statusLabel->setText("<font bgcolor=\"#00FF00\">Status Normal</font>");
emsSilenceTimer->stop();
QLOG_WARN() << "EMS HAS GONE NOISEY";
ui.statusLabel->setStyleSheet("");
}

void MainWindow::emsCommsDisconnected()
Expand All @@ -623,6 +647,7 @@ void MainWindow::emsCommsDisconnected()
ui.actionConnect->setEnabled(true);
ui.actionDisconnect->setEnabled(false);
m_offlineMode = true;
ui.statusLabel->setText("<font bgcolor=\"#FF0000\">DISCONNECTED</font>");
}

void MainWindow::setPlugin(QString plugin)
Expand Down Expand Up @@ -704,6 +729,8 @@ void MainWindow::setPlugin(QString plugin)
connect(emsComms,SIGNAL(memoryDirty()),statusView,SLOT(setEmsMemoryDirty()));
connect(emsComms,SIGNAL(memoryClean()),statusView,SLOT(setEmsMemoryClean()));
connect(emsComms,SIGNAL(datalogDescriptor(QString)),this,SLOT(datalogDescriptor(QString)));
connect(emsComms,SIGNAL(ramLocationDirty(unsigned short)),this,SLOT(ramLocationDirty(unsigned short)));
connect(emsComms,SIGNAL(flashLocationDirty(unsigned short)),this,SLOT(flashLocationDirty(unsigned short)));
emsComms->setBaud(m_comBaud);
emsComms->setPort(m_comPort);
emsComms->setLogsEnabled(m_saveLogs);
Expand Down Expand Up @@ -1342,6 +1369,7 @@ void MainWindow::loadWizards(QString dir)
void MainWindow::emsCommsConnected()
{

ui.statusLabel->setText("<font bgcolor=\"#FF0000\">Connected</font>");
m_interrogationFailureCount = 0;
ui.actionSave_Offline_Data->setEnabled(true);
ui.actionLoad_Offline_Data->setEnabled(true);
Expand Down Expand Up @@ -2121,3 +2149,28 @@ void MainWindow::datalogDescriptor(QString data)
{
Q_UNUSED(data)
}
void MainWindow::ramLocationDirty(unsigned short locationid)
{
if (!ramDiffWindow)
{
ramDiffWindow = new RamDiffWindow();
connect(ramDiffWindow,SIGNAL(acceptLocalChanges()),this,SLOT(dirtyRamAcceptLocalChanges()));
connect(ramDiffWindow,SIGNAL(rejectLocalChanges()),this,SLOT(dirtyRamRejectLocalChanges()));
ramDiffWindow->show();
}
ramDiffWindow->setDirtyLocation(locationid);
//QMessageBox::information(0,"Error","Ram location dirty 0x" + QString::number(locationid,16));
}
void MainWindow::dirtyRamAcceptLocalChanges()
{
emsComms->acceptLocalChanges();
}
void MainWindow::dirtyRamRejectLocalChanges()
{
emsComms->rejectLocalChanges();
}

void MainWindow::flashLocationDirty(unsigned short locationid)
{
QMessageBox::information(0,"Error","Flash location dirty 0x" + QString::number(locationid,16));
}
10 changes: 10 additions & 0 deletions core/src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
#include "serialportstatus.h"
#include <QPluginLoader>
#include "parameterview.h"
#include "ramdiffwindow.h"
#include "wizardview.h"

class RawDataBlock
{
public:
Expand Down Expand Up @@ -129,6 +131,8 @@ class MainWindow : public QMainWindow
QMdiSubWindow *packetStatusMdiWindow;
QMdiSubWindow *aboutMdiWindow;
QMdiSubWindow *emsStatusMdiWindow;
RamDiffWindow *ramDiffWindow;
QTimer *emsSilenceTimer;

ParameterView *parameterView;
QMdiSubWindow *parameterMdiWindow;
Expand All @@ -137,6 +141,7 @@ class MainWindow : public QMainWindow
void checkMessageCounters(int sequencenumber);
DataPacketDecoder *dataPacketDecoder;
void populateDataFields();
bool m_emsSilenceLabelIsRed;

Ui::MainWindow ui;
QString m_pluginFileName;
Expand Down Expand Up @@ -250,6 +255,11 @@ private slots:
void emsMemoryDirty();
void emsMemoryClean();
void datalogDescriptor(QString data);
void ramLocationDirty(unsigned short locationid);
void flashLocationDirty(unsigned short locationid);
void dirtyRamAcceptLocalChanges();
void dirtyRamRejectLocalChanges();
void emsCommsSilenceTimerTick();

};

Expand Down
23 changes: 23 additions & 0 deletions core/src/ramdiffwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "ramdiffwindow.h"
#include "ui_ramdiffwindow.h"

RamDiffWindow::RamDiffWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::RamDiffWindow)
{
ui->setupUi(this);
ui->tableWidget->setColumnCount(1);
ui->tableWidget->setColumnWidth(0,200);
connect(ui->pushLocalButton,SIGNAL(clicked()),this,SIGNAL(acceptLocalChanges()));
connect(ui->pullRemoteButton,SIGNAL(clicked()),this,SIGNAL(rejectLocalChanges()));
}

RamDiffWindow::~RamDiffWindow()
{
delete ui;
}
void RamDiffWindow::setDirtyLocation(unsigned short locationid)
{
ui->tableWidget->setRowCount(ui->tableWidget->rowCount()+1);
ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,0,new QTableWidgetItem(QString::number(locationid)));
}
25 changes: 25 additions & 0 deletions core/src/ramdiffwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef RAMDIFFWINDOW_H
#define RAMDIFFWINDOW_H

#include <QWidget>

namespace Ui {
class RamDiffWindow;
}

class RamDiffWindow : public QWidget
{
Q_OBJECT

public:
explicit RamDiffWindow(QWidget *parent = 0);
~RamDiffWindow();
void setDirtyLocation(unsigned short locationid);
private:
Ui::RamDiffWindow *ui;
signals:
void acceptLocalChanges();
void rejectLocalChanges();
};

#endif // RAMDIFFWINDOW_H
87 changes: 87 additions & 0 deletions core/src/ramdiffwindow.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RamDiffWindow</class>
<widget class="QWidget" name="RamDiffWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>679</width>
<height>458</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;h2&gt;Warning&lt;/h2&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>The ECU has different RAM in memory than the tuner. This could be a result of the ECU resetting, or otherwise losing sync with the tuner. The locations which are different, are listed below</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>To accept the local tuner changes, click below to send these changes to the ECU.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushLocalButton">
<property name="text">
<string>Accept Local</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>To accept the ECU changes, click below to wipe out any local changes.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pullRemoteButton">
<property name="text">
<string>Accept Remote</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
6 changes: 4 additions & 2 deletions lib/core/emscomms.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,16 @@ class EmsComms : public QThread
virtual QByteArray generatePacket(QByteArray header,QByteArray payload)=0;
virtual int updateBlockInRam(unsigned short location,unsigned short offset, unsigned short size,QByteArray data)=0;
virtual int updateBlockInFlash(unsigned short location,unsigned short offset, unsigned short size,QByteArray data)=0;
virtual int retrieveBlockFromRam(unsigned short location, unsigned short offset, unsigned short size)=0;
virtual int retrieveBlockFromFlash(unsigned short location, unsigned short offset, unsigned short size)=0;
virtual int retrieveBlockFromRam(unsigned short location, unsigned short offset, unsigned short size,bool mark=true)=0;
virtual int retrieveBlockFromFlash(unsigned short location, unsigned short offset, unsigned short size,bool mark=true)=0;
virtual int burnBlockFromRamToFlash(unsigned short location,unsigned short offset, unsigned short size)=0;
virtual void setInterByteSendDelay(int milliseconds)=0;
virtual void setlogsDebugEnabled(bool enabled)=0;
virtual int enableDatalogStream()=0;
virtual int disableDatalogStream()=0;
virtual void writeAllRamToRam()=0;
virtual void acceptLocalChanges()=0;
virtual void rejectLocalChanges()=0;
};
Q_DECLARE_INTERFACE(EmsComms,"EmsComms/1.0")
#endif // EMSCOMMS_H
Loading

0 comments on commit 9ad63d8

Please sign in to comment.