From: Mika Laitio Date: Sun, 2 Jan 2011 22:40:20 +0000 (+0200) Subject: Support for setting and reading device name from config file. X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=7075fbe1f4e774856a90116e4414a08c37f692f0;p=lib1wire.git Support for setting and reading device name from config file. Signed-off-by: Mika Laitio --- diff --git a/src/W1Device.cc b/src/W1Device.cc index a765cd3..c9c2e7e 100644 --- a/src/W1Device.cc +++ b/src/W1Device.cc @@ -12,6 +12,8 @@ #include #include +#include "DeviceConfig.hh" +#include "Factory.hh" #include "W1Store.hh" #include "W1Device.hh" @@ -32,7 +34,7 @@ W1Device::W1Device(int family_code_param, log_debug("w1 data file: %s\n", slave_file.c_str()); family_code = family_code_param; id = device_id_param; - name = device_id_param; + name = ""; } W1Device::~W1Device() { @@ -55,11 +57,27 @@ string W1Device::get_id() { } string W1Device::get_name() { + DeviceConfig *cfg; + + if (name.empty() == true) { + cfg = Factory::get_device_config(id); + if (cfg != NULL) { + name = cfg->get_cfg_value("name"); + delete(cfg); + } + } return name; } void W1Device::set_name(string name_param) { + DeviceConfig *cfg; + name = name_param; + cfg = Factory::get_device_config(id); + if (cfg != NULL) { + cfg->set_cfg_value("name", name_param); + delete(cfg); + } } void W1Device::printout() { diff --git a/src/W1Device.hh b/src/W1Device.hh index 321159a..90b5532 100644 --- a/src/W1Device.hh +++ b/src/W1Device.hh @@ -53,7 +53,6 @@ namespace w1 { std::string dir_path; std::string slave_file; std::list memory_cache; - private: }; } diff --git a/src_test/test_w1_datalog_write.cc b/src_test/test_w1_datalog_write.cc index 126a02f..cbba3d3 100644 --- a/src_test/test_w1_datalog_write.cc +++ b/src_test/test_w1_datalog_write.cc @@ -68,14 +68,13 @@ int main(int argc, char** argv) { if (argc > 3) { try_parse_long(argv[3], &store_interval); } - log_info("start scanning, data saved to location: %s, scan interval: %ld, store interval: %ld\n", loc.c_str(), scan_interval, store_interval); + log_info("scanning 1-wire devices\n"); + log_info("data save dir: %s, scan interval: %ld, save interval: %ld\n", loc.c_str(), scan_interval, store_interval); DeviceConfig::set_base_dir_name(loc); device_list = Factory::get_device_list(); round = 0; if (device_list.size() > 0) { - int ii = 0; - while(ii < 6) { - ii++; + while(1) { round++; for(iter = device_list.begin(); iter != device_list.end(); iter++) { device = (W1Device *)*iter;