#include <errno.h>
#include <stdlib.h>
+#include <unistd.h>
#include <plp/log.h>
#include <plp/DeviceConfig.hh>
#include <plp/Device.hh>
+#include <plp/str_util.h>
+
#include "Factory.hh"
using namespace w1;
#define DEFAULT_READ_INTERVAL_SECONDS 600
#define DEFAULT_MAX_READ_COUNT -1
-bool try_parse_long(const char *str, long *result) {
- int new_result;
- char *endptr;
- bool ret_val;
-
- ret_val = false;
- errno = 0;
- new_result = strtol(str, &endptr, 10);
- if (errno != 0) {
- log_error("invalid input %s, could not convert to integer.\n", str);
- }
- else {
- if (endptr == str) {
- log_error("invalid input %s, could not convert to integer.\n", str);
- }
- else {
- *result = new_result;
- ret_val = true;
- }
- }
- return ret_val;
-}
-
int main(int argc, char** argv) {
int read_count_total;
long cnt_max_scans;
log_info("\tmax_read_count == -1: read devices until application is terminated\n\n");
}
if (argc > 2) {
- try_parse_long(argv[2], &read_interval_seconds);
+ parse_long(argv[2], &read_interval_seconds);
}
if (argc > 3) {
- try_parse_long(argv[3], &cnt_max_scans);
+ parse_long(argv[3], &cnt_max_scans);
}
log_info("searching 1-wire devices\n");
if (read_interval_seconds == DEFAULT_READ_INTERVAL_SECONDS) {
else {
log_debug("could not find devices.\n");
}
- log_debug("trying to start emptying list\n");
+ log_debug("trying to empty device list\n");
while (device_list.empty() == false) {
device = device_list.back();
device_list.pop_back();