From: Mika Laitio Date: Thu, 10 Mar 2011 17:58:58 +0000 (+0200) Subject: sensor data read fixes. X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=557fe3a639d7bd6fd146fdc9d573cf53bb2adff0;p=lib1wire.git sensor data read fixes. Signed-off-by: Mika Laitio --- diff --git a/src/W1Device.cc b/src/W1Device.cc index a5f89df..f2e8590 100644 --- a/src/W1Device.cc +++ b/src/W1Device.cc @@ -108,16 +108,21 @@ Data *W1Device::get_data() { Data *ret_val; vector *vect; + log_debug("get_data() started\n"); ret_val = NULL; vect = get_raw_data(); if (vect != NULL) { + log_debug("get_data() got raw data\n"); ret_val = new Data(vect, get_unit()); cache(ret_val); delete(vect); + log_debug("get_data() got raw data done\n"); } else { + log_debug("get_data() try to read old already saved data\n"); // read old data already saved ret_val = reader->get_latest_data(); + log_debug("get_data() try to read old already saved data done\n"); } return ret_val; } diff --git a/src/W1Device.hh b/src/W1Device.hh index 6ce0999..a930303 100644 --- a/src/W1Device.hh +++ b/src/W1Device.hh @@ -15,6 +15,7 @@ #include #include +#include #include #include diff --git a/src_test/test_w1_datalog_read.cc b/src_test/test_w1_datalog_read.cc index 80822bd..48425e2 100644 --- a/src_test/test_w1_datalog_read.cc +++ b/src_test/test_w1_datalog_read.cc @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include "Factory.hh" @@ -50,7 +52,8 @@ int main(int argc, char** argv) { Data *fdata; Data *ldata; DataReader *reader; - Device *device; + Device *dev; + SensorDevice *device; DataRange *dr; DataRange *dr2; list dev_lst; @@ -68,35 +71,38 @@ int main(int argc, char** argv) { } dev_lst = Factory::get_device_list(); for(list_iter = dev_lst.begin(); list_iter != dev_lst.end(); list_iter++) { - device = (Device *)*list_iter; - if (device != NULL) { - reader = device->get_device_data(); - if (reader != NULL) { - dr = reader->get_data_range(); - if (dr != NULL) { - fdata = dr->get_first(); - if (fdata != NULL) { - fdata->printout(); - ldata = dr->get_last(); - if (ldata != NULL) { - ldata->printout(); - plp::Date d1; - plp::Date d2; + dev = (Device *)*list_iter; + if (dev != NULL) { + device = dynamic_cast(dev); + if (device != NULL) { + reader = device->get_device_data(); + if (reader != NULL) { + dr = reader->get_data_range(); + if (dr != NULL) { + fdata = dr->get_first(); + if (fdata != NULL) { + fdata->printout(); + ldata = dr->get_last(); + if (ldata != NULL) { + ldata->printout(); + plp::Date d1; + plp::Date d2; - d1 = fdata->get_date(); - d2 = ldata->get_date(); - dr2 = reader->get_data(&d1, &d2); - if (dr2 != NULL) { - dr2->printout(); - delete(dr2); + d1 = fdata->get_date(); + d2 = ldata->get_date(); + dr2 = reader->get_data(&d1, &d2); + if (dr2 != NULL) { + dr2->printout(); + delete(dr2); + } + delete(ldata); } - delete(ldata); + delete(fdata); } - delete(fdata); + delete(dr); } - delete(dr); + delete(reader); } - delete(reader); } } }