diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-02-17 17:17:24 +0000 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-02-20 11:14:55 +0000 |
commit | 15250b2e51e8383a0df4b6e5a870c07e914d406d (patch) | |
tree | 6c7d0d8c9b41edfacb9749b7694df7c5f8042f98 /src/can-utils.cpp | |
parent | f97e5f6d0b15df8fe8c7a4621e40c6a23bbac137 (diff) |
Fix: timer.* issues
Change-Id: I1c3721403198b3c5525a811bd3c7cbf6b8e78e5b
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/can-utils.cpp')
-rw-r--r-- | src/can-utils.cpp | 109 |
1 files changed, 56 insertions, 53 deletions
diff --git a/src/can-utils.cpp b/src/can-utils.cpp index 3aa2ca88..8d5f0252 100644 --- a/src/can-utils.cpp +++ b/src/can-utils.cpp @@ -212,69 +212,72 @@ void can_bus_t::start_threads() * params[std::ifstream& conf_file] conf_file ifstream to the JSON configuration * file located at the rootdir of the binding */ - void init_can_dev() - { - std::vector<std::string> devices_name; - int i, t; - - devices_name = read_conf(conf_file_); - - t = devices_name.size(); - i=0 - - for(const auto& device : devices_name) - { - can_bus_dev_t(device); - i++; - } - - NOTICE(interface_, "Initialized %d/%d can bus device(s)", i, t); - } +int init_can_dev() +{ + std::vector<std::string> devices_name; + int i, t, ret; + + devices_name = read_conf(conf_file_); + + if (devices_name) + { + t = devices_name.size(); + i=0 + + for(const auto& device : devices_name) + { + can_bus_dev_t(device); + i++; + } + + NOTICE(interface_, "Initialized %d/%d can bus device(s)", i, t); + return 0; + } + ERROR(interface_, "init_can_dev: Error at CAN device initialization."); + return 1; +} /** * @brief Read the conf file and extract device name * - * @params[std::ifstream& conf_file] conf_file JSON configuration - * file located at the rootdir of the binding - * * @return[std:vector<std::string>] return a vector of device name */ - std::vector<std::string> read_conf(std::ifstream& conf_file) - { - std::vector<std::string> ret; - std::string fd_conf_content; +std::vector<std::string> read_conf() +{ + std::vector<std::string> ret; + std::string fd_conf_content; json_object jo, canbus; - int n, i, ok; - + int n, i, ok; + /* Open JSON conf file */ - if (conf_file) + if (conf_file_) { - conf_file.seekg(0, std::ios::end); - conf_file.resize(conf_file.tellg()); - conf_file.seekg(0, std::ios::beg); - conf_file.read(&fd_conf_content[0], fd_conf_content.size()); - conf_file.close(); - - jo = json_tokener_parse(&fd_conf_content); - - if (jo == NULL || !json_object_object_get_ex(&jo, "canbus", &&canbus)) - ERROR(interface_, "Can't find canbus node in the configuration file. Please review it."); - else if (json_object_get_type(canbus) != json_type_array) - ret.push_back(json_object_get_string(a)); - else - { - n = json_object_array_length(a); - ok = 0; - for (i = 0 ; i < n ; i++) - ret.push_back(json_object_get_string(json_object_array_get_idx(a, i))); - } - return ret; + conf_file_.seekg(0, std::ios::end); + conf_file_.resize(conf_file_.tellg()); + conf_file_.seekg(0, std::ios::beg); + conf_file_.read(&fd_conf_content[0], fd_conf_content.size()); + conf_file_.close(); + + jo = json_tokener_parse(&fd_conf_content); + + if (jo == NULL || !json_object_object_get_ex(&jo, "canbus", &&canbus)) + { + ERROR(interface_, "Can't find canbus node in the configuration file. Please review it."); + ret = nullptr; + } + else if (json_object_get_type(canbus) != json_type_array) + ret.push_back(json_object_get_string(a)); + else + { + n = json_object_array_length(a); + ok = 0; + for (i = 0 ; i < n ; i++) + ret.push_back(json_object_get_string(json_object_array_get_idx(a, i))); + } + return ret; } - else - { - ERROR(interface_, "Problem at reading the conf file"); - return 0; - } + ERROR(interface_, "Problem at reading the conf file"); + return nullptr; } /** |