Code restructuration
[apps/low-level-can-service.git] / ll-can-binding.h
1 /*
2  * Copyright (C) 2015, 2016 "IoT.bzh"
3  * Author "Romain Forlot" <romain.forlot@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /*
19  * Interface between the daemon and the binding
20  */
21 static const struct afb_binding_interface *interface;
22
23 /*
24  * the type of position expected
25  *
26  * here, this type is the selection of protocol
27  */
28 enum type {
29         type_OBDII,
30         type_CAN,
31         type_DEFAULT = type_CAN,
32         type_INVALID = -1
33 };
34
35 #define type_size sizeof(enum type)-2
36
37 /*
38  * names of the types
39  */
40 static const char * const type_NAMES[type_size] = {
41         "OBDII",
42         "CAN"
43 };
44
45 /* CAN variable initialization */
46 struct canfd_frame canfd_frame;
47
48 struct can_handler {
49         int socket;
50         char *device;
51         bool is_fdmode_on;
52         struct sockaddr_can txAddress;
53 };
54
55 /*
56  * each generated event
57  */
58 typedef struct _event event;
59 struct _event {
60         event *next;                    /* link for the next event */
61         const char *name;               /* name of the event */
62         struct afb_event afb_event;     /* the event for the binder */
63         openxc_CanMessage can_message;  /* value for the can_message */
64 };
65
66 /*
67  * each can event, will browse by the id
68  */
69 typedef struct _can_event can_event;
70 struct _can_event {
71         can_event *next;        /* Link to the next other can message */
72         event *events;          /* events for the can message */
73         uint32_t id;            /* id of the event for unsubscribe */
74         enum type type;         /* the type of data expected */
75 };
76
77 can_event *can_events_list;
78
79 // Initialize default can_handler values
80 static struct can_handler can_handler = {
81         .socket = -1,
82         .device = "vcan0",
83         .is_fdmode_on = false,
84 };
85
86 /* Redefining openxc_CanMessage_init_default for C */
87 #ifdef openxc_CanMessage_init_default
88 #undef openxc_CanMessage_init_default
89 #endif
90 openxc_CanMessage openxc_CanMessage_init_default = {.has_bus = false, .bus = 0, .has_id = false, .id = 0, .has_data = false, .data = {0, {0}}, .has_frame_format = false, .frame_format = (openxc_CanMessage_FrameFormat)0};