]> pilppa.com Git - lib1wire.git/commitdiff
initial device configuration support.
authorMika Laitio <lamikr@pilppa.org>
Thu, 9 Dec 2010 17:31:32 +0000 (19:31 +0200)
committerMika Laitio <lamikr@pilppa.org>
Thu, 9 Dec 2010 17:31:32 +0000 (19:31 +0200)
started adding support device configuration data.

Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/Data.cc
src/Data.hh
src/DeviceConfig.cc [new file with mode: 0644]
src/DeviceConfig.hh [new file with mode: 0644]
src/Makefile.am
src/W1DataList.cc
src/W1DataList.hh
src/W1Store.cc
src/W1Util.cc
src/W1Util.hh

index d9c6e1a70eb59dc00a93f009e057e15c4fc10fd1..ac7ed2d38c877416844e822030a0f0c0f649c923 100644 (file)
@@ -5,19 +5,32 @@
  *      Author: lamikr
  */
 
+#include <string>
 #include <iostream>
+#include <sstream>
 
 #include <stdio.h>
 #include <time.h>
 #include <malloc.h>
 
-#include "Data.hh"
 #include <plp/log.h>
 
+#include "Data.hh"
+#include "W1Util.hh"
+
 using namespace std;
 using namespace plp;
 using namespace w1;
 
+template <class NumberDataType>
+bool string_to_number(NumberDataType& result,
+                 const std::string& string_param,
+                 std::ios_base& (*format)(std::ios_base&))
+{
+       std::istringstream iss(string_param);
+       return !(iss >> format >> result).fail();
+}
+
 Data::Data(int size) {
        value_arr.resize(size);
 }
@@ -64,6 +77,37 @@ void Data::printout() {
        }
 }
 
+Data *Data::parse_data_string(const string& dataline) {
+       stringstream    ss(dataline);
+       string          item;
+       double          val;
+       Data            *ret_val;
+       int             ii;
+       bool            suc_flg;
+       vector<double>  v;
+       Date            date;
+
+       ii      = 0;
+       while(getline(ss, item, '|')) {
+               if (ii == 0) {
+                       // parse date
+                       date    = W1Util::parse_date_str(item);
+               }
+               // skip the device type and device id fields
+               // TODO: store device type and id to own file
+               else if (ii >= 3) {
+                       suc_flg = string_to_number<double>(val, item, dec);
+                       if (suc_flg) {
+                               //log_debug("adding number: %f\n", val);
+                               v.push_back(val);
+                       }
+               }
+               ii++;
+       }
+       ret_val = new Data(v, &date);
+       return ret_val;
+}
+
 DataRange::DataRange(int value_count_per_data_item) {
        val_matrix      = NULL;
        column_count    = value_count_per_data_item;
index 59d42ce7838318b070cb9297f6f4d6397337173e..14ab90e0d38276c35c37cd8edf8e1ae6ae31e7c7 100644 (file)
@@ -25,6 +25,7 @@ namespace w1 {
                        plp::Date get_date();
                        void set_date(plp::Date date);
                        void printout();
+                       static Data *parse_data_string(const std::string& dataline);
                        std::valarray<double>   value_arr;
                private:
                        plp::Date               date_time;
diff --git a/src/DeviceConfig.cc b/src/DeviceConfig.cc
new file mode 100644 (file)
index 0000000..1ecf0ba
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * DeviceConfig.cc
+ *
+ *  Created on: Dec 9, 2010
+ *      Author: lamikr
+ */
+
+#include "DeviceConfig.hh"
+
+using namespace std;
+using namespace w1;
+
+DeviceConfig::DeviceConfig(string device_id_param) {
+       device_id       = device_id_param;
+}
+
+DeviceConfig::~DeviceConfig() {
+}
+
+string DeviceConfig::get_config_value(string key) {
+       return NULL;
+}
diff --git a/src/DeviceConfig.hh b/src/DeviceConfig.hh
new file mode 100644 (file)
index 0000000..0c9a3b5
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * DeviceConfig.hh
+ *
+ *  Created on: Dec 9, 2010
+ *      Author: lamikr
+ */
+
+#ifndef DEVICECONFIG_HH_
+#define DEVICECONFIG_HH_
+
+#include <string>
+
+namespace w1 {
+       class DeviceConfig {
+               public:
+                       DeviceConfig(std::string device_id_param);
+                       virtual ~DeviceConfig();
+                       std::string get_config_value(std::string key);
+               private:
+                       std::string     device_id;
+       };
+}
+
+#endif /* DEVICECONFIG_HH_ */
index d99707102595f00a03992fc0fd69744a124ae6f0..5b77fc448e4c6083d5693762e72313e8c193be10 100644 (file)
@@ -7,6 +7,7 @@ lib1wire_la_SOURCES = \
        W1CounterDevice.cc W1CounterDevice.hh \
        W1Util.cc W1Util.hh \
        W1DataList.cc W1DataList.hh \
+       DeviceConfig.cc DeviceConfig.hh \
        Data.cc Data.hh \
        Date.cc Date.hh \
        W1Configure.hh
index e05f9baaec76c2f8fec5f67ed9d0a4a2eed6f6a6..5f85db07b6420b9ae18c4810ca02099bef9c3d92 100644 (file)
@@ -167,14 +167,7 @@ long int get_interval_type(Date *start_date,
        return ret_val;
 }
 
-string W1DataList::get_day_data(Date *date) {
-       string ret_val;
-
-       ret_val = W1Store::get_file_name(device_id, date);
-       return ret_val;
-}
-
-Data *W1DataList::get_avg_day_data(Date *date) {
+Data *W1DataList::get_daily_summary(Date *date) {
        Data    *data;
        W1Store *store;
 
@@ -187,7 +180,7 @@ Data *W1DataList::get_avg_day_data(Date *date) {
        return data;
 }
 
-DataRange *W1DataList::get_avg_day_data(Date *start_date,
+DataRange *W1DataList::get_daily_summary(Date *start_date,
                                        Date *end_date) {
        DataRange       *ret_val;
        Data            *data;
@@ -196,7 +189,7 @@ DataRange *W1DataList::get_avg_day_data(Date *start_date,
        ret_val = NULL;
        date    = start_date->clone();
        while(date->before(*end_date)) {
-               data    = get_avg_day_data(date);
+               data    = get_daily_summary(date);
                if (ret_val == NULL) {
                        ret_val = new DataRange(*data);
                }
@@ -221,23 +214,23 @@ DataRange *W1DataList::get_data(Date *start_date,
        int_type        = get_interval_type(start_date, end_date);
        switch(int_type) {
                case 0:
-                       log_debug("get avg year data\n");
+                       log_debug("get yearly summary\n");
                        break;
                case 1:
-                       log_debug("get avg month data\n");
+                       log_debug("get monthly summary\n");
                        break;
                case 2:
-                       log_debug("get avg day data\n");
-                       ret_val = get_avg_day_data(start_date, end_date);
+                       log_debug("get daily summary\n");
+                       ret_val = get_daily_summary(start_date, end_date);
                        break;
                case 3:
-                       log_debug("get avg hour data\n");
+                       log_debug("get hourly summary\n");
                        break;
                case 4:
-                       log_debug("get avg min data\n");
+                       log_debug("get minute summary data\n");
                        break;
                case 5:
-                       log_debug("get avg sec data\n");
+                       log_debug("get second summary data\n");
                        break;
        }
        return ret_val;
index 967efa6d47f06db90b7c4ffc5a4f464d388071a7..e401d8eeed32ffeee2371e674aead4d2083d70f9 100644 (file)
@@ -22,14 +22,17 @@ namespace w1 {
                        W1DataList(std::string device_id);
                        virtual ~W1DataList();
                        DataRange *get_data_range();
-                       Data *get_avg_day_data(plp::Date *date);
-                       DataRange *get_avg_day_data(plp::Date *start_date, plp::Date *end_date);
+                       /**
+                        * Get summary data calculated from the daily data items that is meaning full.
+                        * Depending from the device type, it may be daily mean value, daily delta, highest value, etc...
+                        */
+                       Data *get_daily_summary(plp::Date *date);
+                       DataRange *get_daily_summary(plp::Date *start_date, plp::Date *end_date);
                        DataRange *get_data(plp::Date *start_date, plp::Date *end_date);
                protected:
                        std::string     device_id;
                        std::string     device_dir;
                        std::string     device_ch_dir;
-                       std::string get_day_data(plp::Date *date);
                        Data *find_oldest_data(std::vector<std::string> year_vector);
                        Data *find_newest_data(std::vector<std::string> year_vector);
 
index 360724e789db6e2777c0ee1288da1824faa3c25b..23adbb02da5b57d9769da7f88c2f7ccd46bd7038 100644 (file)
@@ -138,7 +138,7 @@ void W1Store::load() {
        if (in.is_open() == true) {
                while (in.eof() == false) {
                        getline(in, line);
-                       data    = W1Util::parse_data_line(line);
+                       data    = Data::parse_data_string(line);
                        if (store_data == NULL) {
                                store_data      = new DataRange(*data);
                        }
@@ -266,13 +266,13 @@ DataRange *W1Store::get_oldest_and_newest_data() {
                                getline(in, line);
                                if (line.empty() == false) {
                                        if (o_data == NULL) {
-                                               o_data  = W1Util::parse_data_line(line);
+                                               o_data  = Data::parse_data_string(line);
                                        }
                                        prev_line       = line;
                                }
                        }
                        if (prev_line.empty() == false) {
-                               n_data  = W1Util::parse_data_line(prev_line);
+                               n_data  = Data::parse_data_string(prev_line);
                        }
                }
        }
index c5773bc781f2cdb805c770ace2d1e9389b2a32ce..ba6b944a986ab58326a6d4ae23da4b236d7d5551 100644 (file)
@@ -296,34 +296,3 @@ Date W1Util::parse_date_str(string date_str) {
        ss >>ret_val.year >>c >>ret_val.month >>c >>ret_val.day >>ret_val.hour >>c >>ret_val.min >>c >>ret_val.sec;
        return ret_val;
 }
-
-Data *W1Util::parse_data_line(const string& dataline) {
-       stringstream    ss(dataline);
-       string          item;
-       double          val;
-       Data            *ret_val;
-       int             ii;
-       bool            suc_flg;
-       vector<double>  v;
-       Date            date;
-
-       ii      = 0;
-       while(getline(ss, item, '|')) {
-               if (ii == 0) {
-                       // parse date
-                       date    = parse_date_str(item);
-               }
-               // skip the device type and device id fields
-               // TODO: store device type and id to own file
-               else if (ii >= 3) {
-                       suc_flg = string_to_number<double>(val, item, dec);
-                       if (suc_flg) {
-                               //log_debug("adding number: %f\n", val);
-                               v.push_back(val);
-                       }
-               }
-               ii++;
-       }
-       ret_val = new Data(v, &date);
-       return ret_val;
-}
index 2ddf05adbc952dc3adc8e8b7c7000ff367a61744..161d2f04b10f7578189ccd0ad302d1929c865d0e 100644 (file)
@@ -32,7 +32,6 @@ namespace w1 {
                        static std::vector<std::string> get_subdirectories(const std::string& path);
                        static std::vector<std::string> get_data_files(const std::string& path);
                        static plp::Date parse_date_str(std::string date_str);
-                       static Data *parse_data_line(const std::string& dataline);
                        static char *parse_directory_path(const char *file_path);
                        static bool mkdirs(char *path);
                        static std::ofstream *open_for_writing(const char *path);