From d7ead1c059ca51e1d71e0f3928f41733d4c7f29c Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Thu, 9 Dec 2010 19:31:32 +0200 Subject: [PATCH] initial device configuration support. started adding support device configuration data. Signed-off-by: Mika Laitio --- src/Data.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++- src/Data.hh | 1 + src/DeviceConfig.cc | 22 ++++++++++++++++++++++ src/DeviceConfig.hh | 24 +++++++++++++++++++++++ src/Makefile.am | 1 + src/W1DataList.cc | 27 ++++++++++---------------- src/W1DataList.hh | 9 ++++++--- src/W1Store.cc | 6 +++--- src/W1Util.cc | 31 ------------------------------ src/W1Util.hh | 1 - 10 files changed, 112 insertions(+), 56 deletions(-) create mode 100644 src/DeviceConfig.cc create mode 100644 src/DeviceConfig.hh diff --git a/src/Data.cc b/src/Data.cc index d9c6e1a..ac7ed2d 100644 --- a/src/Data.cc +++ b/src/Data.cc @@ -5,19 +5,32 @@ * Author: lamikr */ +#include #include +#include #include #include #include -#include "Data.hh" #include +#include "Data.hh" +#include "W1Util.hh" + using namespace std; using namespace plp; using namespace w1; +template +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 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(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; diff --git a/src/Data.hh b/src/Data.hh index 59d42ce..14ab90e 100644 --- a/src/Data.hh +++ b/src/Data.hh @@ -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 value_arr; private: plp::Date date_time; diff --git a/src/DeviceConfig.cc b/src/DeviceConfig.cc new file mode 100644 index 0000000..1ecf0ba --- /dev/null +++ b/src/DeviceConfig.cc @@ -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 index 0000000..0c9a3b5 --- /dev/null +++ b/src/DeviceConfig.hh @@ -0,0 +1,24 @@ +/* + * DeviceConfig.hh + * + * Created on: Dec 9, 2010 + * Author: lamikr + */ + +#ifndef DEVICECONFIG_HH_ +#define DEVICECONFIG_HH_ + +#include + +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_ */ diff --git a/src/Makefile.am b/src/Makefile.am index d997071..5b77fc4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/W1DataList.cc b/src/W1DataList.cc index e05f9ba..5f85db0 100644 --- a/src/W1DataList.cc +++ b/src/W1DataList.cc @@ -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; diff --git a/src/W1DataList.hh b/src/W1DataList.hh index 967efa6..e401d8e 100644 --- a/src/W1DataList.hh +++ b/src/W1DataList.hh @@ -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 year_vector); Data *find_newest_data(std::vector year_vector); diff --git a/src/W1Store.cc b/src/W1Store.cc index 360724e..23adbb0 100644 --- a/src/W1Store.cc +++ b/src/W1Store.cc @@ -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); } } } diff --git a/src/W1Util.cc b/src/W1Util.cc index c5773bc..ba6b944 100644 --- a/src/W1Util.cc +++ b/src/W1Util.cc @@ -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 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(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; -} diff --git a/src/W1Util.hh b/src/W1Util.hh index 2ddf05a..161d2f0 100644 --- a/src/W1Util.hh +++ b/src/W1Util.hh @@ -32,7 +32,6 @@ namespace w1 { static std::vector get_subdirectories(const std::string& path); static std::vector 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); -- 2.41.1