-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobd2widget.h
More file actions
167 lines (130 loc) · 5.1 KB
/
Copy pathobd2widget.h
File metadata and controls
167 lines (130 loc) · 5.1 KB
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
#ifndef OBD2WIDGET_H
#define OBD2WIDGET_H
#include <QWidget>
#include <QLabel>
#include <QBitArray>
#include <QByteArray>
#include <QtSerialPort/QSerialPort>
namespace Ui {
class OBD2Widget;
}
struct OBD_PAGE_t {
int block0;
int block1;
int block2;
int block3;
int block4;
int block5;
OBD_PAGE_t(int a=-1, int b=-1, int c=-1, int d=-1, int e=-1, int f=-1) :
block0(a),
block1(b),
block2(c),
block3(d),
block4(e),
block5(f){}
};
struct PID_INFO_t {
QString requestStr;
QString labelStr;
QString unit;
bool hasConversion;
float conversionFactor;
QString usUnit;
bool codeSupport;
PID_INFO_t(QString req, QString label, QString un) :
requestStr(req), labelStr(label), unit(un), hasConversion(false), conversionFactor(1), usUnit(un) {
codeSupport = (requestStr.compare("") != 0);
}
PID_INFO_t(QString req, QString label, QString un, float con, QString us) :
requestStr(req), labelStr(label), unit(un), hasConversion(true), conversionFactor(con), usUnit(us) {
codeSupport = (requestStr.compare("") != 0);
}
PID_INFO_t(QString req, QString label, QString un, bool hasCon, float con, QString us) :
requestStr(req), labelStr(label), unit(un), hasConversion(hasCon), conversionFactor(con), usUnit(us) {
codeSupport = (requestStr.compare("") != 0);
}
PID_INFO_t() : requestStr(""), labelStr(""), unit(""), hasConversion(false), conversionFactor(0), usUnit(""), codeSupport(false) {}
};
class OBD2Widget : public QWidget
{
Q_OBJECT
public:
enum OBD2_PID {PID_SHORT_TERM_FUEL_TRIM = 0x06,
PID_LONG_TERM_FUEL_TRIM = 0x07,
PID_ENGINE_RPM = 0x0C,
PID_MAF_AIRFLOW_RATE = 0x10,
PID_COLLANT_TEMP = 0x05,
PID_TIMING_ADVANCE = 0x0E,
PID_ENGINE_LOAD = 0x04,
PID_FUEL_PRESURE = 0x0A,
PID_VEHICLE_SPEED = 0x0D,
PID_INTAKE_AIR_TEMP = 0x0F,
PID_THROTTLE_POSITION = 0x11,
PID_RELATIVE_THROTTLE_POSITION = 0x45,
PID_AMBIENT_AIR_TEMP = 0x46,
PID_ENGINE_FUEL_RATE = 0x5E,
PID_EXHAUST_GAS_TEMP_11 = 0x78
};
explicit OBD2Widget(QWidget *parent = 0, QString portName = "", int baudrate = QSerialPort::Baud9600);
~OBD2Widget();
void connectSerialPort(QString portName = "", int baudrate = QSerialPort::Baud9600);
void setPages(QList<int> pageitems);
// void setUpdateTime()
// bool setDataLabel(QLabel* label, int pid);
// bool setValueLabel(QLabel* label, int pid);
// bool setValueLabelTest(QLabel* label, int pid, QString response);
private slots:
void updateObdValues();
void nextPageClicked();
void prevPageClicked();
private:
Ui::OBD2Widget *ui;
// std::vector<OBD_PAGE_t> m_obdPages;
QList<OBD_PAGE_t> m_obdPages;
QSerialPort *obdSerial;
bool isSerialGood;
int pageNum;
std::map<int, PID_INFO_t> pidInfo;
std::map<int, bool> pidSupported;
QString obdRequest(QString req);
QString parseResult(QString str, int pid);
QString preParseResultString(QString str);
void parseResultStr(QString str, int* a, int* b, int* c, int* d);
//for uncommon pids...
void parseResultStr(QString str, int* a, int* b, int* c, int* d, int* e);
void parseResultStr(QString str, int* a, int* b, int* c, int* d, int* e, int* f, int* g);
void parseResultStr(QString str, int* a, int* b, int* c, int* d, int* e, int* f, int* g, int* h, int* i);
void parseResultStr(QString str, int* a, int* b, int* c, int* d, int* e, int* f, int* g, int* h, int* i, int* j, int* k, int* l, int* m);
QBitArray decodePIDSupport(QString str);
void loadSupportedPids();
void setLabels();
void setValues();
void setDataLabel(QLabel* label, int pid);
void setValueLabel(QLabel* label, int pid);
void resizeEvent ( QResizeEvent * event );
struct EGT_DATA {
bool sensor1Supported;
bool sensor2Supported;
bool sensor3Supported;
bool sensor4Supported;
float sensor1Temp;
float sensor2Temp;
float sensor3Temp;
float sensor4Temp;
EGT_DATA(bool a=false, bool b=false, bool c=false, bool d=false, float e=0.0, float f=0.0, float g=0.0, float h=0.0) :
sensor1Supported(a), sensor2Supported(b), sensor3Supported(c), sensor4Supported(d),
sensor1Temp(e), sensor2Temp(f), sensor3Temp(g), sensor4Temp(h) {}
EGT_DATA(int a, int b, int c, int d, int e, int f, int g, int h, int i) {
unsigned char tmpa = a;
sensor1Supported = (tmpa & 0x01) > 0;
sensor2Supported = (tmpa & 0x02) > 0;
sensor3Supported = (tmpa & 0x04) > 0;
sensor4Supported = (tmpa & 0x08) > 0;
sensor1Temp = (b*256+c)/10.0 - 10.0;
sensor2Temp = (d*256+e)/10.0 - 10.0;
sensor3Temp = (f*256+g)/10.0 - 10.0;
sensor4Temp = (h*256+i)/10.0 - 10.0;
}
};
};
#endif // OBD2WIDGET_H