]> pilppa.com Git - lib1wire.git/commitdiff
Support for setting and reading device name from config file.
authorMika Laitio <lamikr@pilppa.org>
Sun, 2 Jan 2011 22:40:20 +0000 (00:40 +0200)
committerMika Laitio <lamikr@pilppa.org>
Sun, 2 Jan 2011 22:40:20 +0000 (00:40 +0200)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/W1Device.cc
src/W1Device.hh
src_test/test_w1_datalog_write.cc

index a765cd36a6091432b4d2577ae6828efc3f36694b..c9c2e7ed225318caa6b40630c6d2075d33796392 100644 (file)
@@ -12,6 +12,8 @@
 #include <time.h>
 #include <plp/log.h>
 
+#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() {
index 321159abecd682afd1a0501ff99921dd98df98a0..90b5532860790d287f6bdda828fcf379bad998f2 100644 (file)
@@ -53,7 +53,6 @@ namespace w1 {
                        std::string dir_path;
                        std::string slave_file;
                        std::list<w1::Data *> memory_cache;
-               private:
        };
 }
 
index 126a02f4d503080b06b3b42446122b2fd4e07a66..cbba3d3adfeb74171d0daf00b3a10886edc66fd1 100644 (file)
@@ -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;