]> pilppa.org Git - lib1wire.git/blob - src_test/test_w1.cc
e0ceb1d4c4f4eec634d07798d87480c7d8d36f1f
[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         W1Store::set_location(location.c_str());
33         interval_seconds        = 3;
34         store_interval          = 3;
35         scanner                 = new W1Scanner();
36         device_list             = scanner->get_device_list();
37         round                   = 0;
38         if (device_list.size() > 0) {
39                 while(1) {
40                         round++;
41                         for(list<W1Device *>::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++)
42                         {
43                                 W1Device *device = (W1Device *)*list_iter;
44
45                                 device->printout();
46                                 sleep(1);
47                                 if (round >= store_interval) {
48                                         device->store();
49                                 }
50                         }
51                         sleep(interval_seconds);
52                         if (round >= store_interval) {
53                                 round = 0;
54                         }
55                 }
56         }
57         else {
58                 log_debug("could not find 1-wire devices.\n");
59         }
60         return 0;
61 }