]> pilppa.org Git - lib1wire.git/blobdiff - src_test/test_w1_datalog_write.cc
Support for setting and reading device name from config file.
[lib1wire.git] / src_test / test_w1_datalog_write.cc
index db0febca0cdaf3fa9da16df0971b98c10f11c75d..cbba3d3adfeb74171d0daf00b3a10886edc66fd1 100644 (file)
@@ -13,8 +13,8 @@
 
 #include <plp/log.h>
 
-#include "W1Store.hh"
-#include "W1Scanner.hh"
+#include "DeviceConfig.hh"
+#include "Factory.hh"
 
 using namespace w1;
 using namespace std;
@@ -43,25 +43,24 @@ bool try_parse_long(const char *str, long *result) {
 }
 
 int main(int argc, char** argv) {
-       W1Scanner               *scanner;
-       list<W1Device *>        device_list;
-       int                     round;
-       long                    scan_interval;
-       long                    store_interval;
-       string                  location;
-       bool                    err_flg;
-       W1Device                *device;
+       list<W1Device *>                device_list;
+       int                             round;
+       long                            scan_interval;
+       long                            store_interval;
+       string                          loc;
+       W1Device                        *device;
+       list<W1Device *>::iterator      iter;
 
        // default values than can be overwritten with parameters
-       location        = "/tmp/";
-       scan_interval   = 2; //600;
+       loc     = "/tmp/w1data";
+       scan_interval   = 600; //600;
        store_interval  = 2;
        if (argc > 1) {
-               location        = argv[1];
-               log_info("storage location: %s\n", location.c_str());
+               loc     = argv[1];
+               log_info("storage location: %s\n", loc.c_str());
        }
        else {
-               log_warning("No storage location parameter given, using default location: %s\n", location.c_str());
+               log_warning("No storage location parameter given, using default location: %s\n", loc.c_str());
        }
        if (argc > 2) {
                try_parse_long(argv[2], &scan_interval);
@@ -69,23 +68,20 @@ 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: %d, store interval: %d\n", location.c_str(), scan_interval, store_interval);
-       W1Store::set_store_base_dir(location.c_str());
-       scanner         = new W1Scanner();
-       device_list     = scanner->get_device_list();
+       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;
-       int     t = 0;
        if (device_list.size() > 0) {
-               while(t < 3) {
-                       t++;
+               while(1) {
                        round++;
-                       for(list<W1Device *>::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++) {
-                               device = (W1Device *)*list_iter;
-
+                       for(iter = device_list.begin(); iter != device_list.end(); iter++) {
+                               device = (W1Device *)*iter;
                                device->printout();
                                sleep(1);
                                if (round >= store_interval) {
-                                       device->store();
+                                       device->save_data();
                                }
                        }
                        sleep(scan_interval);
@@ -102,7 +98,5 @@ int main(int argc, char** argv) {
                device_list.pop_back();
                delete(device);
        }
-
-       delete(scanner);
        return 0;
 }