#include <plp/log.h>
#include "DeviceConfig.hh"
-#include "W1Scanner.hh"
+#include "Factory.hh"
using namespace w1;
using namespace std;
}
int main(int argc, char** argv) {
- W1Scanner *scanner;
- list<W1Device *> device_list;
- int round;
- long scan_interval;
- long store_interval;
- string location;
- 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);
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", location.c_str(), scan_interval, store_interval);
- DeviceConfig::set_base_dir_name(location);
- 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);
device_list.pop_back();
delete(device);
}
- delete(scanner);
return 0;
}