2 * Copyright (C) 2015, 2016 "IoT.bzh"
3 * Author "Romain Forlot" <romain.forlot@iot.bzh>
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 /* max. number of CAN interfaces given on the cmdline */
21 /* buffer sizes for CAN frame string representations */
22 #define CL_ID (sizeof("12345678##1"))
23 #define CL_DATA sizeof(".AA")
24 #define CL_BINDATA sizeof(".10101010")
26 /* CAN FD ASCII hex short representation with DATA_SEPERATORs */
27 #define CL_CFSZ (2*CL_ID + 64*CL_DATA)
29 #define CANID_DELIM '#'
32 * Interface between the daemon and the binding
34 static const struct afb_binding_interface *interface;
37 * the type of position expected
39 * here, this type is the selection of protocol
44 type_DEFAULT = type_CAN,
48 #define type_size sizeof(enum type)-2
53 static const char * const type_NAMES[type_size] = {
58 /* CAN variable initialization */
59 struct canfd_frame canfd_frame;
65 struct sockaddr_can txAddress;
69 * each generated event
71 typedef struct _event event;
73 event *next; /* link for the next event */
74 const char *name; /* name of the event */
75 struct afb_event afb_event; /* the event for the binder */
76 openxc_CanMessage can_message; /* value for the can_message */
80 * each can event, will browse by the id
82 typedef struct _can_event can_event;
84 can_event *next; /* Link to the next other can message */
85 event *events; /* events for the can message */
86 uint32_t id; /* id of the event for unsubscribe */
87 enum type type; /* the type of data expected */
90 can_event *can_events_list;
92 /* TODO : Add help comments :p */
93 static int connect_to_event_loop();
95 const char hex_asc_upper[] = "0123456789ABCDEF";
97 #define hex_asc_upper_lo(x) hex_asc_upper[((x) & 0x0F)]
98 #define hex_asc_upper_hi(x) hex_asc_upper[((x) & 0xF0) >> 4]
100 static inline void put_hex_byte(char *buf, __u8 byte)
102 buf[0] = hex_asc_upper_hi(byte);
103 buf[1] = hex_asc_upper_lo(byte);
106 static inline void _put_id(char *buf, int end_offset, canid_t id)
108 /* build 3 (SFF) or 8 (EFF) digit CAN identifier */
109 while (end_offset >= 0) {
110 buf[end_offset--] = hex_asc_upper[id & 0xF];
115 #define put_sff_id(buf, id) _put_id(buf, 2, id)
116 #define put_eff_id(buf, id) _put_id(buf, 7, id)
118 static void parse_can_frame(openxc_CanMessage *can_message, struct canfd_frame *canfd_frame, int maxdlen);
121 // Initialize default can_handler values
122 static struct can_handler can_handler = {
125 .is_fdmode_on = false,
128 static void send_event();