]> pilppa.com Git - lib1wire.git/commitdiff
sensor data read fixes.
authorMika Laitio <lamikr@pilppa.org>
Thu, 10 Mar 2011 17:58:58 +0000 (19:58 +0200)
committerMika Laitio <lamikr@pilppa.org>
Thu, 10 Mar 2011 17:58:58 +0000 (19:58 +0200)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/W1Device.cc
src/W1Device.hh
src_test/test_w1_datalog_read.cc

index a5f89dfc9f487c17df8e86adb02ec1c24fb1ac96..f2e85902c0c6e3afa1b75085beda15e5ba27c063 100644 (file)
@@ -108,16 +108,21 @@ Data *W1Device::get_data() {
        Data            *ret_val;
        vector<double>  *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;
 }
index 6ce09990ccf1962672e0055fad09e83ecf889d89..a9303030859cc5c0713ca48259f2cab36f4129b9 100644 (file)
@@ -15,6 +15,7 @@
 #include <stdbool.h>
 
 #include <plp/Data.hh>
+#include <plp/DataReader.hh>
 #include <plp/SensorDevice.hh>
 #include <plp/Device.hh>
 
index 80822bd76a5016f17e882f3dfb0f52423ed0e332..48425e21b342069775512f050fcaeb0bc9c2d85d 100644 (file)
@@ -15,6 +15,8 @@
 #include <plp/Date.hh>
 #include <plp/DataReader.hh>
 #include <plp/DeviceConfig.hh>
+#include <plp/Device.hh>
+#include <plp/SensorDevice.hh>
 
 #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<Device *>                  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<SensorDevice *>(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);
                        }
                }
        }