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");
}
}
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());
}
}
}
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);
}
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;
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;
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;
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);
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);
};
}
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());