]> pilppa.org Git - lib1wire.git/blob - src_test/test_w1.cc
increased the storage intervals from test application
[lib1wire.git] / src_test / test_w1.cc
1 /*
2  * test_w1.cc
3  *
4  *  Created on: Oct 20, 2010
5  *      Author: lamikr
6  */
7 #include <list>
8 #include <string>
9 #include <iostream>
10
11 #include <plp/log.h>
12
13 #include "W1Store.hh"
14 #include "W1Scanner.hh"
15
16 using namespace w1;
17 using namespace std;
18
19 int main(int argc, char** argv) {
20         W1Scanner               *scanner;
21         list<W1Device *>        device_list;
22         int                     round;
23         int                     interval_seconds;
24         int                     store_interval;
25         string                  location;
26
27         location                = "/tmp/";
28         if (argc > 1) {
29                 location        = argv[1];
30                 log_info("storage location: %s\n", location.c_str());
31         }
32         else {
33                 log_warning("storage location was not given as a parameter, using default location: %s\n", location.c_str());
34         }
35         W1Store::set_location(location.c_str());
36         interval_seconds        = 600;
37         store_interval          = 6;
38         scanner                 = new W1Scanner();
39         device_list             = scanner->get_device_list();
40         round                   = 0;
41         if (device_list.size() > 0) {
42                 while(1) {
43                         round++;
44                         for(list<W1Device *>::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++)
45                         {
46                                 W1Device *device = (W1Device *)*list_iter;
47
48                                 device->printout();
49                                 sleep(1);
50                                 if (round >= store_interval) {
51                                         device->store();
52                                 }
53                         }
54                         sleep(interval_seconds);
55                         if (round >= store_interval) {
56                                 round = 0;
57                         }
58                 }
59         }
60         else {
61                 log_debug("could not find 1-wire devices.\n");
62         }
63         return 0;
64 }