2 * Copyright (C) 2015, 2016 "IoT.bzh"
3 * Author "Romain Forlot" <romain.forlot@iot.bzh>
4 * Author "Loic Collignon" <loic.collignon@iot.bzh>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include <linux/can.h>
20 #include <linux/can/raw.h>
23 #include <afb/afb-binding.h>
25 #include "can-utils.h"
26 #include "can-decoder.h"
27 #include "openxc.pb.h"
29 void can_decode_message(CanBus_c *can_bus)
31 CanMessage_c *can_message;
33 std:vector <CanSignal> *signals;
35 openxc_VehicleMessage vehicle_message;
36 openxc_SimpleMessage s_message;
37 openxc_DynamicField key, ret;
40 vehicle_message = {.has_type = true,
41 .type = openxc_VehicleMessage_Type::openxc_VehicleMessage_Type_SIMPLE,
42 .has_simple_message = true };
46 if(can_message = can_bus->next_can_message())
48 /* First we have to found which CanSignal is */
49 key = { .has_type = true,
50 .type = openxc_DynamicField_Type::openxc_DynamicField_Type_NUM,
51 .has_numeric_value = true,
52 .numeric_value = (double)can_message.get_id() };
54 signals = GetSignals(key);
56 /* Decoding the message ! Don't kill the messenger ! */
57 for(i=0; i< signals.size(); i++)
60 if(afb_event_is_valid(sig->event))
62 ret = decoder.decodeSignal(&sig, can_message, SIGNALS, SIGNALS.size(), true);
64 s_message = {.has_name = true,
65 .name = sig->genericName,
70 vehicle_message.simple_message = s_message;
71 vehicle_message_q.push(vehicle_message);