-
Notifications
You must be signed in to change notification settings - Fork 1
/
wbh.h
215 lines (189 loc) · 5.7 KB
/
wbh.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <stdint.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Error codes */
enum {
ERR_SYNTAX = 1, /**< "?" */
ERR_DATA, /**< "DATA ERROR" */
ERR_TIMEOUT, /**< timeout while waiting for response from interface */
ERR_SERIAL, /**< serial port I/O error */
ERR_INVAL, /**< invalid parameter */
};
/** Protocol version */
typedef enum {
PROT_KW1281 = 1, /**< KW1281 */
PROT_KW2000, /**< KW2000 (aka KW2089) */
} wbh_protocol_t;
/** WBH interface state */
typedef struct {
int fd; /**< serial device file descriptor */
char *name; /**< serial device file name */
} wbh_interface_t;
/** Baud rates */
typedef enum {
BAUD_AUTO = 0,
BAUD_1200,
BAUD_2400,
BAUD_4800,
BAUD_9600,
BAUD_10400,
} wbh_baudrate_t;
/** WBH diagnostic device state */
typedef struct {
uint8_t id; /**< device ID */
wbh_interface_t *iface;
wbh_protocol_t protocol; /**< protocol ID (KW1281 or KW2000) */
wbh_baudrate_t baudrate;
const char *specs; /**< raw specification data as sent by
the device on connect */
} wbh_device_t;
/** read analog value pin 0..5
@param iface WBH interface handle
@param pin pin number
@return analog value or negative error code
*/
int wbh_get_analog(wbh_interface_t *iface, uint8_t pin);
/** read block delay time
@param iface WBH interface handle
@return block delay time in ms or negative error code
*/
int wbh_get_bdt(wbh_interface_t *iface);
/** set block delay time
@param iface WBH interface handle
@param bdt block delay time (ms)
@return zero or negative error code
*/
int wbh_set_bdt(wbh_interface_t *iface, uint8_t bdt);
/** read inter-byte time
@param iface WBH interface handle
@return inter-byte delay in ms or negative error code
*/
int wbh_get_ibt(wbh_interface_t *iface);
/** set inter-byte time
@param iface WBH interface handle
@param ibt inter-byte delay time (ms)
@return zero or negative error code
*/
int wbh_set_ibt(wbh_interface_t *iface, uint8_t ibt);
/** initialize WBH interface
@param tty serial device name
@return WBH interface handle or NULL on error
*/
wbh_interface_t *wbh_init(const char *tty);
/** shut down WBH interface
@param iface WBH interface handle
@return zero or negative error code
*/
int wbh_shutdown(wbh_interface_t* iface);
/** connect to diagnostic device
@param iface WBH interface handle
@param device device ID
@return WBH device handle or NULL on error
*/
wbh_device_t *wbh_connect(wbh_interface_t *iface, uint8_t device);
/** disconnect from diagnostic device
@param dev WBH device handle
@return zero or negative error code
*/
int wbh_disconnect(wbh_device_t *dev);
/** force a specific baud rate for diagnostic device connection
@param iface WBH interface handle
@param baudrate baud rate
@return zero or negative error code
*/
int wbh_force_baud_rate(wbh_interface_t *iface, wbh_baudrate_t baudrate);
/** reset interface
@param iface WBH interface handle
@return zero or negative error code
*/
int wbh_reset(wbh_interface_t *iface);
/** send a custom command to the diagnostic device
@param dev diagnostic device handle
@param cmd command string
@param data response buffer
@param data_size size of response buffer
@param timeout time to wait for data
@return bytes read or negative error code
*/
int wbh_send_command(wbh_device_t *dev, char *cmd, char *data,
size_t data_size, int timeout);
/** retrieve a human-readable description of the last error
@return error string
*/
const char *wbh_get_error(void);
/** diagnostic trouble code (DTC) structure */
typedef struct {
uint16_t error_code; /**< error code */
uint8_t status_code; /**< status code (cause of error) */
} wbh_dtc_t;
/** retrieve diagnostic error code (DTC) list
@param dev diagnostic device handle
@return pointer to wbh_error_code array, NULL on error
*/
wbh_dtc_t *wbh_get_dtc(wbh_device_t *dev);
/** free DTC array
@param dtc pointer to DTC array
*/
void wbh_free_dtc(wbh_dtc_t *dtc);
/** scan for devices
Scans for active devices by trying to connect to them one by one.
@param iface WBH interface handle
@param start first device ID to scan
@param end last device ID to scan
@return zero-terminated array of active device IDs
*/
uint8_t *wbh_scan_devices(wbh_interface_t *iface, uint8_t start, uint8_t end);
/** free scanned devices array
@param devices pointer to device array
*/
void wbh_free_devices(uint8_t *devices);
/** run actuator diagnosis ("Stellglieddiagnose")
@param dev diagnostic device handle
@return tested component code, 0 if no more components, or negative error code
*/
int wbh_actuator_diagnosis(wbh_device_t *dev);
/** units that measurements can have */
typedef enum {
UNIT_ENDOFLIST = 0, /**< indicates the end of the measurements list */
UNIT_RPM,
UNIT_PERCENT,
UNIT_DEG,
UNIT_CELSIUS,
UNIT_VOLT,
UNIT_KMH,
UNIT_OHM,
UNIT_MILLIMETER,
UNIT_BAR,
UNIT_MILLISECOND,
UNIT_MILLIBAR,
UNIT_AMPERE,
UNIT_DEG_KW,
UNIT_KW,
UNIT_LITER,
UNIT_LITERS_PER_HOUR,
UNIT_KM,
UNIT_MILLIGRAMS_PER_HOUR,
UNIT_AMPERE_HOUR,
UNIT_TIME, /**< hours, minutes, have to be read from raw array */
UNIT_NM,
UNIT_SECOND,
UNIT_METERS_PER_SECOND_SQUARED,
UNIT_CHARS,
UNIT_GS,
UNIT_DEG_PER_SECOND,
UNIT_BITFIELD,
UNIT_NONE,
UNIT_UNKNOWN,
} wbh_unit_t;
const char *wbh_unit_name(wbh_unit_t unit);
typedef struct {
float value; /**< measurement value (float) */
wbh_unit_t unit; /**< measurement unit */
uint8_t raw[3]; /**< raw data used to calculate the value */
} wbh_measurement_t;
wbh_measurement_t *wbh_read_measurements(wbh_device_t *dev, uint8_t group);
#ifdef __cplusplus
}
#endif