forked from Polyconseil/libcanardbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcandbc-model.h
357 lines (299 loc) · 6.93 KB
/
candbc-model.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#ifndef INCLUDE_DBCMODEL_H
#define INCLUDE_DBCMODEL_H
#include <stdlib.h>
#if WITH_DMALLOC
#include <dmalloc.h>
#endif
#include <candbc-types.h>
/* macros */
#define DECLARE_LIST(tlist,tobj) \
typedef struct tlist ## _s \
{ \
tobj ## _t tobj; \
struct tlist ## _s *next; \
} tlist ## _t
#define DECLARE_LIST_FREE(tlist,tobj) \
void tlist ## _free(tlist ## _t *tlist);
#define DEFINE_LIST_FREE(tlist,tobj) \
void tlist ## _free(tlist ## _t *tlist) \
{ \
while(tlist != NULL) { \
tlist ## _t *next = tlist->next; \
free(tlist->tobj); \
free(tlist); \
tlist = next; \
} \
}
#define DECLARE_PLIST(tlist,tobj) \
typedef struct tlist ## _s \
{ \
tobj ## _t *tobj; \
struct tlist ## _s *next; \
} tlist ## _t
#define DEFINE_PLIST_FREE(tlist, tobj) \
void tlist ## _free(tlist ## _t *tlist) \
{ \
while(tlist != NULL) { \
tlist ## _t *next = tlist->next; \
tobj ## _free(tlist->tobj); \
free(tlist); \
tlist = next; \
} \
}
#define DECLARE_PLIST_FREE(tlist, tobj) \
void tlist ## _free(tlist ## _t *tlist);
#define DEFINE_PLIST_DUP(tlist, tobj) \
tlist##_t *tlist##_dup(tlist##_t *orig) \
{ \
tlist##_t *first = NULL; \
tlist##_t *current = NULL; \
for(;orig != NULL; orig=orig->next) { \
tlist##_t *new = (tlist##_t *)malloc(sizeof(tlist##_t)); \
if(current != NULL) { current->next = new; } \
if(first == NULL) { first = new; } \
new->tobj = tobj##_dup(orig->tobj); \
new->next = NULL; \
current = new; \
} \
return first; \
}
#define CREATE(type,obj) type *(obj) = (type *)malloc(sizeof(type))
/* string type */
typedef char * string_t;
DECLARE_LIST(string_list, string);
#define STR0(x) ((x)?(x):"(null)")
/* signal group */
typedef struct {
uint32 id;
string_t name;
string_list_t *signal_name_list;
} signal_group_t;
/* signal group list */
DECLARE_PLIST(signal_group_list, signal_group);
/* attribute object class */
typedef enum {
aoc_undefined,
aoc_object,
aoc_relation,
} attribute_object_class_t;
/* multiplex type */
typedef enum {
m_signal,
m_multiplexor,
m_multiplexed
} mux_t;
/* multiplex info */
typedef struct {
mux_t mux_type;
uint32 mux_value;
} mux_info_t;
/* signal val type */
typedef enum {
svt_integer,
svt_float,
svt_double
} signal_val_type_t;
/* attribute value type */
typedef enum {
vt_integer,
vt_float,
vt_string,
vt_enum,
vt_hex
} value_type_t;
/* attribute value union */
typedef union {
sint32 int_val;
double double_val;
string_t string_val;
string_t enum_val;
uint32 hex_val;
} value_union_t;
/* attribute value */
typedef struct {
value_type_t value_type;
value_union_t value;
} attribute_value_t;
/* attribute */
typedef struct {
string_t name;
attribute_value_t *value;
} attribute_t;
/* attribute list */
DECLARE_PLIST(attribute_list, attribute);
/* node */
typedef struct {
string_t name;
string_t comment;
attribute_list_t *attribute_list;
} node_t;
/* node list */
DECLARE_PLIST(node_list, node);
/* value map entry */
typedef struct {
uint32 index;
string_t value;
} val_map_entry_t;
DECLARE_PLIST(val_map, val_map_entry);
/* value table */
typedef struct {
string_t name;
string_t comment;
val_map_t *val_map;
} valtable_t;
DECLARE_PLIST(valtable_list, valtable);
/* signal */
typedef struct {
string_t name;
mux_t mux_type;
uint32 mux_value;
uint8 bit_start;
uint8 bit_len;
uint8 endianness;
uint8 signedness;
double scale;
double offset;
double min;
double max;
signal_val_type_t signal_val_type;
string_t unit;
string_list_t *receiver_list;
string_t comment;
attribute_list_t *attribute_list;
val_map_t *val_map;
} signal_t;
DECLARE_PLIST(signal_list, signal);
/* message */
typedef struct {
uint32 id;
string_t name;
uint8 len;
string_t sender;
signal_list_t *signal_list;
string_t comment;
attribute_list_t *attribute_list;
string_list_t *transmitter_list;
} message_t;
/* message list */
DECLARE_PLIST(message_list, message);
/* relational attribute */
typedef struct {
string_t name;
attribute_value_t *attribute_value;
node_t *node;
message_t *message;
signal_t *signal;
} attribute_rel_t;
/* relational attribute list */
DECLARE_PLIST(attribute_rel_list, attribute_rel);
/* attribute_object type */
typedef enum {
ot_network,
ot_node,
ot_message,
ot_signal,
ot_envvar,
ot_node_signal,
ot_node_message,
ot_integer,
ot_float,
ot_string,
ot_enum,
ot_hex
} object_type_t;
/* integer range */
typedef struct {
sint32 min;
sint32 max;
} int_range_t;
/* double range */
typedef struct {
double min;
double max;
} double_range_t;
/* hex range */
typedef struct {
uint32 min;
uint32 max;
} hex_range_t;
/* attribute definition */
typedef struct {
object_type_t object_type;
string_t name;
value_type_t value_type;
/* range */
union {
int_range_t int_range;
double_range_t double_range;
hex_range_t hex_range;
string_list_t *enum_list;
} range;
/* default value */
value_union_t default_value;
} attribute_definition_t;
/* attribute definition list */
DECLARE_PLIST(attribute_definition_list, attribute_definition);
/* network */
typedef struct {
attribute_list_t *attribute_list;
string_t comment;
} network_t;
/* env variable */
typedef enum {
at_unrestricted = 0,
at_readonly = 1,
at_writeonly = 2,
at_readwrite = 3,
} accesstype_t;
typedef enum {
et_integer = 0,
et_float = 1,
et_string = 2,
et_data = 3,
} envtype_t;
typedef struct {
string_t name;
envtype_t envtype;
accesstype_t access;
uint32 min;
uint32 max;
string_t unit;
uint32 initial;
uint32 index;
string_list_t *node_list;
val_map_t *val_map;
string_t comment;
} envvar_t;
/* envvar list */
DECLARE_PLIST(envvar_list, envvar);
/* dbc */
typedef struct {
string_t filename;
string_t version;
node_list_t *node_list;
valtable_list_t *valtable_list;
message_list_t *message_list;
envvar_list_t *envvar_list;
attribute_rel_list_t *attribute_rel_list;
attribute_definition_list_t *attribute_definition_list;
signal_group_list_t *signal_group_list;
network_t *network;
} dbc_t;
/* functions */
DECLARE_LIST_FREE(string_list, string);
DECLARE_PLIST_FREE(val_map, val_map_entry);
DECLARE_PLIST_FREE(valtable_list, valtable);
#ifdef __cplusplus
extern "C" {
#endif
void string_free(string_t string);
void valtable_free(valtable_t *valtable);
void attribute_value_free(attribute_value_t *attribute_value);
void message_free(message_t *message);
void dbc_free(dbc_t *dbc);
char *string_merge(char *in, char *app);
dbc_t *dbc_read_file(char *filename);
#ifdef __cplusplus
}
#endif
#endif