From af341b7dfafac0912f513879565ebd856aa77915 Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Mon, 24 Jan 2011 21:40:41 +0200 Subject: [PATCH] cleanups for log messages. Signed-off-by: Mika Laitio --- src/DeviceConfig.cc | 29 +++++++++++++++++------------ src/Factory.cc | 32 +++++++++++++++++++++++--------- src/Factory.hh | 2 +- src/W1TemperatureSensor.cc | 2 -- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/DeviceConfig.cc b/src/DeviceConfig.cc index 066a22c..7002792 100644 --- a/src/DeviceConfig.cc +++ b/src/DeviceConfig.cc @@ -38,7 +38,7 @@ DeviceConfig::DeviceConfig(string device_id_param) { device_type = get_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE); } else { - log_error("Could not read device config\n"); + log_error("Could not read device configuration.\n"); } } @@ -95,14 +95,19 @@ string DeviceConfig::get_cfg_value(string key) { section = uci_lookup_section(uci_handle->_ctx, uci_handle->_pkg, DEVICE_CONFIG__SECTION_NAME); if (section != NULL) { option = uci_lookup_option(uci_handle->_ctx, section, key.c_str()); - switch (option->type) { - case UCI_TYPE_STRING: - log_info("key: %s option name: %s, value: %s\n", key.c_str(), option->e.name, option->v.string); - ret_val = option->v.string; - break; - default: - log_error("key: %s Failed to read parameter value\n", key.c_str()); - break; + if (option != NULL) { + switch (option->type) { + case UCI_TYPE_STRING: + log_info("key: %s option name: %s, value: %s\n", key.c_str(), option->e.name, option->v.string); + ret_val = option->v.string; + break; + default: + log_error("key: %s Failed to read parameter value\n", key.c_str()); + break; + } + } + else { + log_error("key: %s Failed to read parameter value\n", key.c_str()); } } } @@ -153,15 +158,15 @@ ConfigHandle *DeviceConfig::load_device_config(string device_id_param) { if (access(cfg_fl.c_str(), R_OK) == 0) { ctx = uci_alloc_context(); if (ctx != NULL) { - log_debug("uci_set_confdir: %s\n", cfg_dir.c_str()); + //log_debug("uci_set_confdir: %s\n", cfg_dir.c_str()); uci_set_confdir(ctx, cfg_dir.c_str()); err_flg = uci_load(ctx, cfg_fl.c_str(), &pkg); if (err_flg == UCI_OK) { - log_debug("Loaded device configuration: %s\n.", cfg_fl.c_str()); + //log_debug("Loaded device configuration: %s.\n", cfg_fl.c_str()); ret_val = new ConfigHandle(ctx, pkg); } else { - log_debug("Failed to load device configuration: %s, err code: %d\n.", cfg_fl.c_str(), UCI_OK); + log_debug("Failed to load device configuration: %s, err code: %d.\n", cfg_fl.c_str(), UCI_OK); set_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE, ""); uci_free_context(ctx); } diff --git a/src/Factory.cc b/src/Factory.cc index c8dc694..b10c3ea 100644 --- a/src/Factory.cc +++ b/src/Factory.cc @@ -53,6 +53,9 @@ W1Device *Factory::get_device(int family_code, case 0x1d: ret_val = new W1CounterDevice(family_code, device_id, direntry_param); break; + case 0x81: + // 0x81 is the 1-wire USB dongle... No need to create device for it. + break; default: log_debug("Unsupported 1-wire-family code: %#x, device not created: %s\n", family_code, device_id.c_str()); break; @@ -75,7 +78,7 @@ W1Device *Factory::get_device(int family_code, return ret_val; } -W1Device *Factory::create_device(dirent *direntry_param) { +W1Device *Factory::create_device(dirent *direntry_param, int *err_code_param) { string folder_name; string tmp_str; string device_name; @@ -85,18 +88,26 @@ W1Device *Factory::create_device(dirent *direntry_param) { W1Device *ret_val; ret_val = NULL; + *err_code_param = 0; folder_name = direntry_param->d_name; pos = folder_name.find("-"); if (pos > 0) { tmp_str = folder_name.substr(0, pos); // number in string is in hex format, convert to int suc_flg = string_to_number(family_code, tmp_str, hex); - if (suc_flg == true) { - log_debug("1-wire device family code: %#x\n", family_code); - device_name = folder_name.substr(pos + 1, folder_name.length() - pos); - ret_val = Factory::get_device(family_code, - device_name, - direntry_param); + // if family code = 0x81 (1-wire usb dongle), do not try to create the device + if (family_code != 0x81) { + if (suc_flg == true) { + log_debug("1-wire device family code: %#x\n", family_code); + device_name = folder_name.substr(pos + 1, folder_name.length() - pos); + ret_val = Factory::get_device(family_code, + device_name, + direntry_param); + if ((ret_val == NULL) && + (family_code != 0x81)) { + *err_code_param = 1; + } + } } } return ret_val; @@ -116,12 +127,15 @@ list Factory::get_device_list() { while(direntry != NULL) { is_subdir = W1Util::is_subdirectory(W1_SCAN_ROOTDIR, direntry); if (is_subdir == true) { - device = create_device(direntry); + err_flg = 0; + device = create_device(direntry, &err_flg); if (device != NULL) { ret_val.push_back(device); } else { - log_info("Unsupported 1-wire device detected: %s\n", direntry->d_name); + if (err_flg != 0) { + log_info("Unsupported 1-wire device detected: %s\n", direntry->d_name); + } } } direntry = readdir(dir); diff --git a/src/Factory.hh b/src/Factory.hh index a5cf254..415ce95 100644 --- a/src/Factory.hh +++ b/src/Factory.hh @@ -31,7 +31,7 @@ namespace w1 { static DeviceConfig *get_device_config(std::string device_id); private: //int parse_family_code(std::string folder_name); - static W1Device *create_device(dirent *direntry_param); + static W1Device *create_device(dirent *direntry_param, int *err_code_param); }; } diff --git a/src/W1TemperatureSensor.cc b/src/W1TemperatureSensor.cc index e738bfc..e01e1cc 100644 --- a/src/W1TemperatureSensor.cc +++ b/src/W1TemperatureSensor.cc @@ -53,8 +53,6 @@ double convert_w1_temperature_to_celcius(string raw_value, int *err_flg) { W1TemperatureSensor::W1TemperatureSensor(int family_code_param, string device_id_param, dirent *direntry_param): W1Device(family_code_param, device_id_param, direntry_param) { - log_debug("trying to open file: %s\n", slave_file.c_str()); - ifstream ifs(slave_file.c_str()); if (ifs.is_open() == false) { log_error("%s: %s failed to read data from file: %s\n", id.c_str(), get_device_type().c_str(), slave_file.c_str()); -- 2.41.0