]> pilppa.com Git - lib1wire.git/commitdiff
cleanups for log messages.
authorMika Laitio <lamikr@pilppa.org>
Mon, 24 Jan 2011 19:40:41 +0000 (21:40 +0200)
committerMika Laitio <lamikr@pilppa.org>
Mon, 24 Jan 2011 19:40:41 +0000 (21:40 +0200)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/DeviceConfig.cc
src/Factory.cc
src/Factory.hh
src/W1TemperatureSensor.cc

index 066a22ca838a359c7698509da5eab8ff8367c29b..70027925ebb045eace8e17ad0bed5fc0b4fc75bb 100644 (file)
@@ -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);
                                }
index c8dc6949f957fe6f1c71b7e8f15338ad26d32eba..b10c3eaa46342ec9e5d3def1b9fe2fbd16f9a866 100644 (file)
@@ -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<int>(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<W1Device *> 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);
index a5cf254c31f60c4ae958ebc00f584948c7778ad9..415ce9584717c7cb23194fbaeb06c9c1b80deac3 100644 (file)
@@ -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);
        };
 }
 
index e738bfc34cb905f652a7d28e96c4dea90ae308bf..e01e1cc0677e80f2ba8cb899ee2bece040a40340 100644 (file)
@@ -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());