4 * Created on: Oct 20, 2010
16 #include <plp/DeviceConfig.hh>
17 #include <plp/Device.hh>
25 #define DEFAULT_READ_INTERVAL_SECONDS 600
26 #define DEFAULT_MAX_READ_COUNT -1
28 bool try_parse_long(const char *str, long *result) {
35 new_result = strtol(str, &endptr, 10);
37 log_error("invalid input %s, could not convert to integer.\n", str);
41 log_error("invalid input %s, could not convert to integer.\n", str);
51 int main(int argc, char** argv) {
54 long read_interval_seconds;
57 list<Device *> device_list;
58 list<Device *>::iterator iter;
60 // default values than can be overwritten with parameters
62 read_interval_seconds = DEFAULT_READ_INTERVAL_SECONDS;
63 cnt_max_scans = DEFAULT_MAX_READ_COUNT;
68 log_info("no parameter given using default values:\n");
69 log_info("\ttest_w1_datalog_write %s %ld %ld\n\n", loc.c_str(), read_interval_seconds, cnt_max_scans);
70 log_info("usage:\n\ttest_w1_datalog_write <result_save_path> <read_interval_seconds> <max_read_count>\n");
71 log_info("\tmax_read_count == -1: read devices until application is terminated\n\n");
74 try_parse_long(argv[2], &read_interval_seconds);
77 try_parse_long(argv[3], &cnt_max_scans);
79 log_info("searching 1-wire devices\n");
80 if (read_interval_seconds == DEFAULT_READ_INTERVAL_SECONDS) {
81 log_info("\tdevice read interval: %ld seconds (default value)\n", read_interval_seconds);
84 log_info("\tdevice read interval: %ld seconds\n", read_interval_seconds);
86 log_info("\tdata save dir: %s\n", loc.c_str());
87 if (cnt_max_scans == DEFAULT_MAX_READ_COUNT) {
88 log_info("\tmax read count: %ld (default value, devices will be read until application is terminated)\n\n", cnt_max_scans);
91 log_info("\tmax read count: %ld\n\n", cnt_max_scans);
93 DeviceConfig::set_base_dir_name(loc);
94 device_list = Factory::get_device_list();
96 if (device_list.size() > 0) {
99 if ((cnt_max_scans != -1) &&
100 (read_count_total > cnt_max_scans)) {
101 log_info("closing the application, max read count reached. (%ld)\n", cnt_max_scans);
104 for (iter = device_list.begin(); iter != device_list.end(); iter++) {
105 device = (Device *)*iter;
106 if (device->get_lifecycle_state() == LIFECYCLE_STATUS__AVAILABLE) {
111 log_debug("device not available, %s.\n", device->get_id().c_str());
114 sleep(read_interval_seconds);
118 log_debug("could not find devices.\n");
120 log_debug("trying to start emptying list\n");
121 while (device_list.empty() == false) {
122 device = device_list.back();
123 device_list.pop_back();
124 log_debug("calling delete\n");