-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathautomon.h
167 lines (141 loc) · 6.05 KB
/
automon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
This file is part of the Automon Project (OBD Diagnostics) - http://www.automon.io/
Source Repository: https://github.com/donaloconnor/automon/
Copyright (c) 2015, Donal O'Connor <[email protected]>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef AUTOMON_H
#define AUTOMON_H
#include <QLCDNumber>
#include "command.h"
#include "coolanttempsensor.h"
#include "dtc.h"
#include "dtchelper.h"
#include "sensor.h"
#include "serialhelper.h"
#include "enginerpm.h"
#include "engineruntime.h"
#include "vehiclespeed.h"
#include "fuelpressure.h"
#include "throttleposition.h"
#include "fuellevelinput.h"
#include "mafairflowrate.h"
#include "commandedegr.h"
#include "o2voltage.h"
#include "rule.h"
#ifdef Q_OS_MACX
#include <err.h>
#else
#include "error.h"
#endif
#include "exceptions.h"
/* TURN OFF DEBUG */
#define DEBUGAUTOMON 1 /* Specifies if debug messages will be printed or not */
#define TURNOFFECHO 1 /* Warning don't remove this. It will probably upset formulas that work on fact no echo */
#define ADAPTIVETIMING 1 /* If set, adaptive timing will be set to speed up communication with ECU. Better to let enabled */
//#define RULEFILE "/home/eclipse/rules"
//#define DTCCODEFILE "/home/eclipse/codes"
//#define RULEFILE "rules" /* Location of file for storing of user defined rules */
//#define DTCCODEFILE "codes" /* Location of the DTC code description file */
// [LA]
#define RULEFILE ":/files/rules" /* Location of file for storing of user defined rules */
#define DTCCODEFILE ":/files/codes" /* Location of the DTC code description file */
namespace AutomonKernel
{
class Automon : public QObject
{
Q_OBJECT
public:
Automon(QString port = "/dev/ttyUSB0");
~Automon();
QString getVin();
QString getOBDStandardType();
QString getOBDProtocol();
QString getElmVersion();
QString getVoltage() const;
QList<Sensor*> getFreezeFrame() const;
QList<Sensor*> getAllSensors() const;
QList<DTC*> getDTCs() const;
bool sendCommand(Command & command);
void addSensor(Sensor * newSensor);
bool addActiveSensorByCommand(QString command);
bool removeActiveSensorByCommand(QString command);
bool startMonitoring();
void stopMonitoring();
Sensor * getActiveSensorByCommand(QString command) const;
Sensor * getSensorByCommand(QString command) const;
bool connectSensorToSlot(Sensor * sender,QObject * receiver) const;
bool disconnectSensorFromSlot(Sensor * sender, QObject * receiver) const;
bool connectToErrorToSlot(QObject * receiver);
bool setSensorFrequency(Sensor * sensor, int frequency) const;
bool addActiveSensor(Sensor * sensor);
bool checkMil() const;
int getNumCodes();
bool resetMilAndClearCodes();
bool init();
bool testElmConnectivity() const;
bool refreshDTCInformation() const;
static QList<int> getBytes(Command & command);
static QString cleanResponse(QString response);
bool saveRuleList();
bool loadRuleList();
QStringList getRuleList();
void addRuleString(QString rule);
void removeRuleString(QString rule);
QString convertRuleToEnglish(QString rule) const;
void removeRuleEnglishMeaningString(QString rule);
QStringList extractSensorsFromRule(QString & rule) const;
void removeAllActiveSensors() const;
bool isMonitoring() const;
signals:
void sendErrorMessage(QString); /* Used to send an error message to connected Slots */
/* Used to send updates of progress during init stages to splash screen */
void updateStatus(const QString & message, int alignment = Qt::AlignLeft, const QColor & color = Qt::black);
public slots:
void receiveErrorMessage(QString);
private:
bool initialiseBus();
void loadSensors();
void updateSensorSupport();
QStringList m_ruleList;
SerialHelper * m_serialHelper;
DTCHelper * m_dtcHelper;
QList<Sensor*> m_sensors;
QList<Sensor*> m_activeSensors;
QList<Sensor*> freezeFrame;
QList<DTC*> m_dtcs;
bool m_milOn;
int m_numberDTCs;
/*
Constant cache data. First time, ECU will be queried for this. But further requests will
be from these set variables to reduce communication with ECU
*/
QString m_vinNumber;
QString m_protocol;
QString m_standardType;
QString m_elmVersion;
/*
This variable is used as a check if the serial I/O thread is monitoring.
Used for the main Automon application to prevent two tasks running together
*/
bool m_isMonitoring;
};
}
#endif // AUTOMON_H