]> pilppa.org Git - lib1wire.git/blobdiff - src_test/test_w1.cc
storage data cleanup. allow specifying storage dir location
[lib1wire.git] / src_test / test_w1.cc
index 6c6c1167f31b311a89496be63c3e4ed6505d1090..e0ceb1d4c4f4eec634d07798d87480c7d8d36f1f 100644 (file)
@@ -8,47 +8,54 @@
 #include <string>
 #include <iostream>
 
-#include <unistd.h>
+#include <plp/log.h>
 
+#include "W1Store.hh"
 #include "W1Scanner.hh"
 
 using namespace w1;
 using namespace std;
 
-int main(int argc, char** argv)
-{
-       W1Scanner                       *scanner;
+int main(int argc, char** argv) {
+       W1Scanner               *scanner;
        list<W1Device *>        device_list;
-       int                                     round;
-       int                                     interval_seconds;
-       int                                     store_interval;
+       int                     round;
+       int                     interval_seconds;
+       int                     store_interval;
+       string                  location;
 
-       interval_seconds        = 60;
-       store_interval          = 10;
-       scanner                         = new W1Scanner();
-       device_list                     = scanner->get_device_list();
-       round                           = 0;
-       while(1) {
-               round++;
-               for(list<W1Device *>::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++)
-               {
-                       W1Device *device = (W1Device *)*list_iter;
-/*
-                       string name     = device->get_name();
-                       string value    = device->get_value();
-                       string unit             = device->get_unit();
-                       cout << name << ": " << value << " " << unit << endl;
-*/
-                       device->printout();
-                       sleep(1);
+       location                = "/tmp/";
+       if (argc > 1) {
+               location        = argv[1];
+               log_info("storage location: %s\n", location.c_str());
+       }
+       W1Store::set_location(location.c_str());
+       interval_seconds        = 3;
+       store_interval          = 3;
+       scanner                 = new W1Scanner();
+       device_list             = scanner->get_device_list();
+       round                   = 0;
+       if (device_list.size() > 0) {
+               while(1) {
+                       round++;
+                       for(list<W1Device *>::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++)
+                       {
+                               W1Device *device = (W1Device *)*list_iter;
+
+                               device->printout();
+                               sleep(1);
+                               if (round >= store_interval) {
+                                       device->store();
+                               }
+                       }
+                       sleep(interval_seconds);
                        if (round >= store_interval) {
-                               device->store();
+                               round = 0;
                        }
                }
-               sleep(interval_seconds);
-               if (round >= store_interval) {
-                       round = 0;
-               }
+       }
+       else {
+               log_debug("could not find 1-wire devices.\n");
        }
        return 0;
 }