summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--can-utils.cpp3
-rw-r--r--low-can-binding.cpp19
2 files changed, 19 insertions, 3 deletions
diff --git a/can-utils.cpp b/can-utils.cpp
index abfe0a0..6721410 100644
--- a/can-utils.cpp
+++ b/can-utils.cpp
@@ -23,9 +23,10 @@
*
*********************************************************************************/
-CanBus_c::CanBus_c(afb_binding_interface *itf)
+CanBus_c::CanBus_c(afb_binding_interface *itf, const std:string& dev_name)
{
interface = itf;
+ deviceName = dev_name;
}
int CanBus_c::open()
diff --git a/low-can-binding.cpp b/low-can-binding.cpp
index bb219be..b609890 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();
}