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 "low-can-hat.hpp"
25 #include <json-c/json.h>
27 #include "application.hpp"
28 #include "../can/can-bus.hpp"
32 #include <afb/afb-service-itf.h>
35 // Interface between the daemon and the binding
36 const struct afb_binding_interface *binder_interface;
40 static const struct afb_verb_desc_v1 verbs[]=
42 { .name= "subscribe", .session= AFB_SESSION_NONE, .callback= subscribe, .info= "subscribe to notification of CAN bus messages." },
43 { .name= "unsubscribe", .session= AFB_SESSION_NONE, .callback= unsubscribe, .info= "unsubscribe a previous subscription." }
46 static const struct afb_binding binding_desc {
47 AFB_BINDING_VERSION_1,
49 "Low level CAN bus service",
55 const struct afb_binding *afbBindingV1Register (const struct afb_binding_interface *itf)
57 binder_interface = itf;
62 /// @brief Initialize the binding.
64 /// @param[in] service Structure which represent the Application Framework Binder.
66 /// @return Exit code, zero if success.
67 int afbBindingV1ServiceInit(struct afb_service service)
69 can_bus_t& can_bus_manager = application_t::instance().get_can_bus_manager();
71 can_bus_manager.set_can_devices();
72 can_bus_manager.start_threads();
74 /// Initialize Diagnostic manager that will handle obd2 requests.
75 /// We pass by default the first CAN bus device to its Initialization.
76 /// TODO: be able to choose the CAN bus device that will be use as Diagnostic bus.
77 if(application_t::instance().get_diagnostic_manager().initialize())
80 ERROR(binder_interface, "%s: There was something wrong with CAN device Initialization.", __FUNCTION__);