summaryrefslogtreecommitdiffstats
path: root/low-can-binding.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-14 11:18:58 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-14 11:18:58 +0100
commit9e11d2500f4a41afa2f293baee77f71b90652153 (patch)
treef9720cfb963b516974971723da2d6700fdffe795 /low-can-binding.cpp
parent91aab46150dacda677c8751942abc452998cdf8d (diff)
Added JSON conf file read and initialize CanBus
object with device name retrieve from conf file. Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding.cpp')
-rw-r--r--low-can-binding.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/low-can-binding.cpp b/low-can-binding.cpp
index bb219be2..b6098907 100644
--- a/low-can-binding.cpp
+++ b/low-can-binding.cpp
@@ -48,7 +48,6 @@
*/
static const struct afb_binding_interface *interface;
-
/********************************************************************************
*
* Event management
@@ -229,10 +228,26 @@ const struct afb_binding *afbBindingV1Register (const struct afb_binding_interfa
int afbBindingV1ServiceInit(struct afb_service service)
{
+ std::ifstream fd_conf;
+ std::string fd_conf_content;
+ json_object jo_canbus;
+
/* Open JSON conf file */
+ jo_canbus = json_object_new_object();
+ fd_conf = afb_daemon_rootdir_open_locale(interface->daemon, "canbus.json", O_RDONLY, NULL);
+ if (fd_conf)
+ {
+ fd_conf.seekg(0, std::ios::end);
+ fd_conf_content.resize(fd_conf.tellg());
+ fd_conf.seekg(0, std::ios::beg);
+ fd_conf.read(&fd_conf_content[0], fd_conf_content.size());
+ fd_conf.close();
+ }
+
+ jo_canbus = json_tokener_parse(&fd_conf_content);
/* Open CAN socket */
- CanBus_c CanBus_handler(interface);
+ CanBus_c CanBus_handler(interface, json_object_get_string(json_object_object_get(jo_canbus, "deviceName"));
CanBus_handler.open();
CanBus_handler.start_threads();
}