This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
kwp2000.h
187 lines (160 loc) · 4.95 KB
/
kwp2000.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
Copyright 2013 Jared Wiltshire
This file is part of VAG Blocks.
VAG Blocks is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VAG Blocks is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VAG Blocks. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KWP2000_H
#define KWP2000_H
#include <QObject>
#include <QThread>
#include <QVariant>
#include <QMap>
#include <QVector>
#include <QFile>
#include <QTextStream>
#include <QFileInfo>
#include "serialport.h"
#include "elm327.h"
#include "tp20.h"
#include "util.h"
#include "serialsettings.h"
typedef struct {
int blockNum;
int pos;
} blockRef;
typedef struct {
QList<blockRef> refs;
QVariant val;
} sampleValue;
typedef struct {
QString units;
QString desc;
QVariant val;
int indexToSampleValue;
} blockValue;
typedef struct {
QString blockName;
QString desc[4];
QString subDesc[4];
QString longDesc[4];
QString binDesc[4];
} blockLabels_t;
typedef struct {
int number;
int addr;
QString name;
bool isPresent;
int status;
} moduleInfo_t;
class kwp2000 : public QObject
{
Q_OBJECT
public:
explicit kwp2000(QObject *parent = 0);
~kwp2000();
void setSerialParams(const serialSettings &in);
int getChannelDest() const;
int getNumBlocksOpen() const;
bool getBlockOpen(int i) const;
bool getPortOpen() const;
bool getElmInitialised() const;
static QVariant decodeBlockData(quint8 id, quint8 a, quint8 b, QString &units);
QVariant getBlockValue(int blockNum, int pos);
QString getBlockUnits(int blockNum, int pos);
QString getBlockDesc(int blockNum, int pos);
blockLabels_t getBlockLabel(int blockNum);
QString getLabelFileName();
void setLabelDir(QString dir);
QString getLabelDir();
const QMap<int, moduleInfo_t>& getModuleList() const;
const QList<sampleValue>& getSample() const;
QFileInfo getLogfileInfo();
void setTimeouts(int slow, int norm, int fast);
void setKeepAliveInterval(int time);
signals:
void log(const QString &txt, int logLevel = stdLog);
void diagStarted(int param);
void newBlockData(int blockNum);
void channelOpen(bool status);
void blockOpen(int num);
void blockClosed(int num);
void portOpened(bool open);
void portClosed();
void elmInitialised(bool ok);
void newEcuInfo(QStringList info);
void newModuleInfo(QStringList info);
void labelsLoaded(bool ok);
void moduleListRefreshed();
void sampleFormatChanged();
void loggingStarted();
public slots:
void openPort();
void closePort();
void closePortBlocking();
void openChannel(int i);
void closeChannel();
void startDiag(int param = 0x89);
void openBlock(int blockNum);
void closeBlock(int blockNum);
void closeAllBlocks();
void channelOpenSlot(bool status);
void miscCommand(const QByteArray &cmd);
void startLogging();
void stopLogging();
void loadLabelFile();
void openGW_refresh(bool ok = true);
private slots:
void recvKWP(QByteArray* data);
void readBlockTimeout();
private:
QThread* elmThread;
QThread* tpThread;
elm327* elm;
tp20* tp;
void readBlocks();
int nextBlock;
bool readingBlocks;
QTimer readBlockTimer;
void blockDataHandler(QByteArray* data, quint8 param);
void startDiagHandler(QByteArray* data, quint8 param);
void miscHandler(QByteArray* data, quint8 respCode, quint8 param);
void longIdHandler(QByteArray* data);
void shortIdHandler(QByteArray* data);
void queryModulesHandler(QByteArray* data);
QString logFileName;
QFile* logFile;
QTextStream logOut;
QString labelFileName;
QFile* labelFile;
QTextStream labelIn;
QMap<int, QVector<blockValue> > currentBlocks;
QList<sampleValue> sample;
void writeSample();
void updateSample(int block);
QMap<int, blockLabels_t> blockLabels;
QStringList modulePartNum;
QStringList ecuPartNum;
QString labelDir;
QString findLabelFromRedir(QString partNum, QString dirStr);
QList<QByteArray> interpretRawData(QByteArray* raw);
QMap<int, moduleInfo_t> moduleList;
QMap<int, int> addrToModuleMap;
void initModuleNames();
QMap<int, QString> moduleNames;
bool doModuleRefresh;
void changeSampleFormat();
int destModule;
int slowRecvTimeout;
int normRecvTimeout;
int fastRecvTimeout;
};
#endif // KWP2000_H