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 28
/
tp20.h
135 lines (114 loc) · 2.99 KB
/
tp20.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
/*
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 TP20_H
#define TP20_H
#include <QObject>
#include <QTimer>
#include "elm327.h"
#include "canframe.h"
#include "util.h"
typedef struct {
quint8 dest;
quint8 opcode;
quint8 rxID;
quint8 rxV;
quint8 rxPre;
quint8 txID;
quint8 txV;
quint8 txPre;
quint8 app;
} chanSetup;
typedef struct {
quint8 opcode;
quint8 bs;
quint8 T1;
quint8 T2;
quint8 T3;
quint8 T4;
} chanParam;
typedef struct {
quint8 opcode;
quint8 bs;
} chanParamShort;
typedef struct {
quint8 opcode;
quint8 seq;
} dataTrans;
typedef struct {
quint8 opcode;
quint8 seq;
quint16 len;
} dataTransFirst;
class tp20 : public QObject
{
Q_OBJECT
public:
tp20(elm327* elm, QObject *parent = 0);
int getChannelDest();
bool getElmInitialised();
void setSlowRecvTimeout(int slow);
void setKeepAliveInterval(int time);
public slots:
void initialiseElm(bool open);
void portClosed();
void openChannel(int dest, int timeout);
void closeChannel();
void sendData(const QByteArray &data, int requestedTimeout);
private slots:
void sendKeepAlive();
signals:
void log(const QString &txt, int logLevel = stdLog);
void elmInitDone(bool ok);
void channelOpened(bool ok);
void response(QByteArray* data);
private:
elm327* elm;
QList<canFrame*>* lastResponse;
int channelDest;
quint16 txID;
quint16 rxID;
quint8 bs;
quint8 t1;
quint8 t3;
quint8 txSeq;
quint8 rxSeq;
QTimer keepAliveTimer;
QMutex sendLock;
bool elmInitilised;
bool getResponseCAN(bool replyExpected = true);
QString getResponseStr();
bool getResponseStatus(int expectedResult);
bool checkResponse(int len);
chanSetup getAsCS(int i);
chanParam getAsCP(int i);
dataTrans getAsDT(int i);
dataTransFirst getAsDTFirst(int i);
bool checkSeq();
bool checkACK();
bool sendACK(bool dataFollowing = false);
bool checkForCommands();
void recvData();
void writeToElmStr(const QString &str);
void writeToElmBA(const QByteArray &str);
void setSendCanID(int id);
void setRecvCanID(int id);
void setChannelClosed();
void elmInitialisationFailed();
QString decodeError(int status);
bool applyRecvTimeout(int msecs);
int recvTimeout;
int slowRecvTimeout;
};
#endif // TP20_H