From 83dba70b46600014932da34e8744ba70584077aa Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Wed, 22 Dec 2010 02:03:14 +0200 Subject: [PATCH] Initial support for reading and writing device specific config data. Signed-off-by: Mika Laitio --- configure.ac | 4 +- src/Data.cc | 24 ++--- src/Data.hh | 1 - src/Date.cc | 3 +- src/DeviceConfig.cc | 153 +++++++++++++++++++++++++++++- src/DeviceConfig.hh | 32 ++++++- src/Factory.cc | 67 +++++++++++++ src/Factory.hh | 28 ++++++ src/Makefile.am | 3 +- src/W1CounterDevice.cc | 23 +++-- src/W1CounterDevice.hh | 6 +- src/W1DataList.cc | 7 +- src/W1Device.cc | 16 ++-- src/W1Device.hh | 6 +- src/W1Scanner.cc | 22 ++--- src/W1Scanner.hh | 2 +- src/W1Store.cc | 29 +----- src/W1Store.hh | 3 - src/W1TemperatureSensor.cc | 18 ++-- src/W1TemperatureSensor.hh | 6 +- src/W1Util.cc | 2 - src_test/Makefile.am | 2 +- src_test/test_w1_datalog_read.cc | 14 ++- src_test/test_w1_datalog_write.cc | 8 +- 24 files changed, 360 insertions(+), 119 deletions(-) create mode 100644 src/Factory.cc create mode 100644 src/Factory.hh diff --git a/configure.ac b/configure.ac index 010f01f..a8fc4c7 100644 --- a/configure.ac +++ b/configure.ac @@ -9,7 +9,9 @@ CFLAGS="$CFLAGS -ggdb -Wall -Werror" LDFLAGS="$LDFLAGS" AC_SUBST(CFLAGS) AC_SUBST(LDFLAGS) -AC_MSG_NOTICE([objective c Makefile]) +CXXFLAGS="$CXXFLAGS -ggdb -Wall -Werror" +AC_SUBST(CXXFLAGS) +AC_MSG_NOTICE([lib1wire Makefile]) AM_INIT_AUTOMAKE($PACKAGE, $VERSION) diff --git a/src/Data.cc b/src/Data.cc index 98425c6..388dbef 100644 --- a/src/Data.cc +++ b/src/Data.cc @@ -45,13 +45,13 @@ Data::Data(int size, double default_value) { } Data::Data(vector vector_param, Date *date_param) { - int ii; - int size; + unsigned int ii; + unsigned int size; size = vector_param.size(); //log_debug("Data(), value count: %d\n", size); value_arr.resize(size); - for (int ii = 0; ii < vector_param.size(); ii++) { + for (ii = 0; ii < vector_param.size(); ii++) { value_arr[ii] = vector_param.at(ii); //log_debug("Data(), value[%d]: %f\n", ii, value_arr[ii]); } @@ -59,8 +59,11 @@ Data::Data(vector vector_param, Date *date_param) { } Data::Data(std::valarray value_arr_param, Date *date_param) { + unsigned int ii; + value_arr.resize(value_arr_param.size()); - for (int ii = 0; ii < value_arr_param.size(); ii++) { + + for (ii = 0; ii < value_arr_param.size(); ii++) { value_arr[ii] = value_arr_param[ii]; } date_time.copy(date_param); @@ -78,7 +81,7 @@ void Data::set_date(plp::Date date) { } void Data::printout() { - int ii; + unsigned int ii; date_time.printout(); for (ii = 0; ii < value_arr.size(); ii++) { @@ -131,8 +134,8 @@ DataRange::DataRange(Data data) { } DataRange::~DataRange() { - int ii; - Date *date; + unsigned int ii; + Date *date; if (val_matrix != NULL) { free(val_matrix); @@ -145,10 +148,9 @@ DataRange::~DataRange() { } void DataRange::add_data(Data data) { - int ii; - int r_count; - int indx; - Date date; + unsigned int ii; + int indx; + Date date; //log_debug("old row_count: %d, column_count: %d, value_arr_size: %d\n", row_count, column_count, data.value_arr.size()); val_matrix = (double *)realloc(val_matrix, ((row_count + 1) * column_count) * sizeof(double)); diff --git a/src/Data.hh b/src/Data.hh index 3907a9b..35af7c6 100644 --- a/src/Data.hh +++ b/src/Data.hh @@ -11,7 +11,6 @@ #include #include #include -#include #include "Date.hh" diff --git a/src/Date.cc b/src/Date.cc index b8b5714..8c03c5b 100644 --- a/src/Date.cc +++ b/src/Date.cc @@ -57,7 +57,7 @@ bool Date::is_leap_year() { ret_val = false; if ((year % 4 == 0) && - (year % 400 == 0) || (year % 100 != 0)) { + ((year % 400 == 0) || (year % 100 != 0))) { ret_val = true; } return ret_val; @@ -141,7 +141,6 @@ string Date::to_string() { char buffer[30]; string ret_val; - int n, a=5, b=3; sprintf(buffer, "%016d%02d%02d%02d%02d%02d", year, month, day, hour, min, sec); ret_val = buffer; return ret_val; diff --git a/src/DeviceConfig.cc b/src/DeviceConfig.cc index aa191cc..ee06135 100644 --- a/src/DeviceConfig.cc +++ b/src/DeviceConfig.cc @@ -7,20 +7,167 @@ #include "DeviceConfig.hh" +#include +#include + +#include +#include "W1Util.hh" +#include "W1Configure.hh" + +#include "Factory.hh" + using namespace std; using namespace w1; +string DeviceConfig::store_base_dir = DEFAULT_STORAGE_BASE_DIR; + +ConfigHandle::ConfigHandle(uci_context *ctx_param, uci_package *pkg_param) { + ctx = ctx_param; + pkg = pkg_param; +} + +ConfigHandle::~ConfigHandle() { + uci_unload(ctx, pkg); + uci_free_context(ctx); +} + DeviceConfig::DeviceConfig(string device_id_param) { device_id = device_id_param; + uci_handle = load_device_config(device_id_param); + if (uci_handle != NULL) { + device_type = get_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE); + } + else { + log_error("Could not read device config\n"); + } } DeviceConfig::~DeviceConfig() { + if (uci_handle != NULL) { + delete(uci_handle); + uci_handle = NULL; + } +} + +void DeviceConfig::set_base_dir_name(string store_param) { + int pos; + int b_count; + + pos = store_param.find_last_of("/"); + b_count = store_param.length(); + if (pos == (b_count - 1)) { + store_base_dir = store_param; + } + else { + store_base_dir = store_param + "/"; + } +} + +string DeviceConfig::get_base_dir_name() { + return store_base_dir; +} + +string DeviceConfig::get_dir_name(string device_id_param) { + string ret_val; + string d_name; + + d_name = DeviceConfig::get_base_dir_name(); + ret_val = W1Util::concat_paths(d_name, device_id_param); + return ret_val; +} + +string DeviceConfig::get_file_name(string device_id_param) { + string ret_val; + string fname; + + fname = DEVICE_CONFIG__FILE_NAME; + ret_val = get_dir_name(device_id); + ret_val = W1Util::concat_paths(ret_val, fname); + return ret_val; +} + +string DeviceConfig::get_cfg_value(string key) { + struct uci_section *section; + struct uci_option *option; + string ret_val; + + if (uci_handle != NULL) { + section = uci_lookup_section(uci_handle->ctx, uci_handle->pkg, DEVICE_CONFIG__SECTION_NAME); + if (section != NULL) { + option = uci_lookup_option(uci_handle->ctx, section, key.c_str()); + switch (option->type) { + case UCI_TYPE_STRING: + log_info("config file: key: %s option name: %s, value: %s\n", key.c_str(), option->e.name, option->v.string); + ret_val = option->v.string; + break; + default: + log_error("config file: key: %s can not parse parameter value\n", key.c_str()); + break; + } + } + } + return ret_val; } -string DeviceConfig::get_config_value(string key) { - return NULL; +void DeviceConfig::set_cfg_value(string key, string value) { + string cfg_dir; + string cfg_fl; + + cfg_dir = get_dir_name(device_id); + cfg_fl = DEVICE_CONFIG__FILE_NAME; + + set_config_value(cfg_dir.c_str(), + cfg_fl.c_str(), + DEVICE_CONFIG__SECTION_TYPE, + DEVICE_CONFIG__SECTION_NAME, + key.c_str(), + value.c_str()); } enum_summary_calculation DeviceConfig::get_summary_calculation_type() { - return MEAN; + enum_summary_calculation ret_val; + + ret_val = MEAN; + if (device_type.empty() == false) { + if (device_type.compare("counter") == 0) { + ret_val = DELTA; + } + } + return ret_val;; +} + +ConfigHandle *DeviceConfig::load_device_config(string device_id_param) { + int err_flg; + struct uci_context *ctx; + struct uci_package *pkg; + string cfg_fl; + string cfg_dir; + ConfigHandle *ret_val; + + ret_val = NULL; + cfg_dir = get_dir_name(device_id_param); + if (cfg_dir.empty() == false) { + cfg_fl = get_file_name(device_id_param); + ctx = uci_alloc_context(); + if (ctx != NULL) { + log_debug("uci_set_confdir: %s\n", cfg_dir.c_str()); + uci_set_confdir(ctx, cfg_dir.c_str()); + if (access(cfg_fl.c_str(), R_OK) != 0) { + log_debug("loading file: %s\n", cfg_fl.c_str()); + err_flg = uci_load(ctx, cfg_fl.c_str(), &pkg); + if (err_flg == UCI_OK) { + log_debug("Loaded device configuration: %s, UCI_OK: %d, err flg: %d\n.", cfg_fl.c_str(), UCI_OK, err_flg); + ret_val = new ConfigHandle(ctx, pkg); + } + else { + log_debug("Failed to load file: %s, UCI_OK: %d, err flg: %d\n.", cfg_fl.c_str(), UCI_OK, err_flg); + set_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE, "unknowntype"); + } + } + } + else { + log_error("Failed to load device device configurations, invalid device id: %s.\n", cfg_dir.c_str()); + } + } + return ret_val; } diff --git a/src/DeviceConfig.hh b/src/DeviceConfig.hh index ced5c81..c2cfb31 100644 --- a/src/DeviceConfig.hh +++ b/src/DeviceConfig.hh @@ -10,17 +10,45 @@ #include +extern "C" { +#include +#include +} + +#define DEVICE_CONFIG__FILE_NAME "dev_cfg.txt" +#define DEVICE_CONFIG__SECTION_TYPE "device" +#define DEVICE_CONFIG__SECTION_NAME "base_data" +#define DEVICE_CONFIG_VALUE_KEY__TYPE "type" +#define DEVICE_CONFIG_VALUE_KEY__NAME "name" + namespace w1 { enum enum_summary_calculation {SUM, DELTA, MEAN, MAX, MIN}; + struct ConfigHandle { + public: + ConfigHandle(uci_context *ctx_param, uci_package *pkg_param); + ~ConfigHandle(); + struct uci_context *ctx; + struct uci_package *pkg; + }; + class DeviceConfig { public: DeviceConfig(std::string device_id_param); virtual ~DeviceConfig(); - std::string get_config_value(std::string key); + static std::string get_base_dir_name(); + static void set_base_dir_name(std::string store_param); + std::string get_cfg_value(std::string key); + void set_cfg_value(std::string key, std::string value); enum_summary_calculation get_summary_calculation_type(); private: - std::string device_id; + static std::string store_base_dir; + std::string device_id; + std::string device_type; + ConfigHandle *uci_handle; + ConfigHandle *load_device_config(std::string device_id_param); + std::string get_dir_name(std::string device_id); + std::string get_file_name(std::string device_id_param); }; } diff --git a/src/Factory.cc b/src/Factory.cc new file mode 100644 index 0000000..e9637a4 --- /dev/null +++ b/src/Factory.cc @@ -0,0 +1,67 @@ +/* + * Factory.cc + * + * Created on: Dec 11, 2010 + * Author: lamikr + */ + +#include +#include "Factory.hh" +#include "W1TemperatureSensor.hh" +#include "W1CounterDevice.hh" + +using namespace w1; +using namespace std; + +Factory::Factory() { + // TODO Auto-generated constructor stub +} + +Factory::~Factory() { + // TODO Auto-generated destructor stub +} + +W1Device *Factory::get_device(int family_code, + string device_id, + dirent *direntry_param) { + W1Device *ret_val; + DeviceConfig *config; + + ret_val = NULL; + log_debug("family_code: %d\n", family_code); + switch(family_code) { + case 0x10: + case 0x28: + ret_val = new W1TemperatureSensor(family_code, device_id, direntry_param); + log_debug("temperature sensor: %d\n", ret_val->get_family_code()); + break; + case 0x1d: + ret_val = new W1CounterDevice(family_code, device_id, direntry_param); + log_debug("counter device: %d\n", family_code); + break; + default: + log_debug("device not created, unsupported device type: %d\n", family_code); + break; + } + if (ret_val != NULL) { + // check that device config exist + // if not, create default... + config = get_device_config(device_id); + if (config != NULL) { + string type; + type = config->get_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE); + if (type.empty() == true) { + type = ret_val->get_device_type(); + config->set_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE, type); + } + } + } + return ret_val; +} + +DeviceConfig *Factory::get_device_config(string device_id) { + DeviceConfig *ret_val; + + ret_val = new DeviceConfig(device_id); + return ret_val; +} diff --git a/src/Factory.hh b/src/Factory.hh new file mode 100644 index 0000000..595e271 --- /dev/null +++ b/src/Factory.hh @@ -0,0 +1,28 @@ +/* + * Factory.hh + * + * Created on: Dec 11, 2010 + * Author: lamikr + */ + +#ifndef FACTORY_HH_ +#define FACTORY_HH_ + +#include + +#include + +#include "DeviceConfig.hh" +#include "W1Device.hh" + +namespace w1 { + class Factory { + public: + Factory(); + virtual ~Factory(); + static W1Device *get_device(int family_code, std::string device_id, dirent *direntry_param); + static DeviceConfig *get_device_config(std::string device_id); + }; +} + +#endif /* FACTORY_HH_ */ diff --git a/src/Makefile.am b/src/Makefile.am index 5b77fc4..67a7a4b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,6 @@ lib_LTLIBRARIES = lib1wire.la lib1wire_la_SOURCES = \ + Factory.cc Factory.hh \ W1Device.cc W1Device.hh \ W1Scanner.cc W1Scanner.hh \ W1Store.cc W1Store.hh \ @@ -12,7 +13,7 @@ lib1wire_la_SOURCES = \ Date.cc Date.hh \ W1Configure.hh lib1wire_la_LDFLAGS = $(SRC_LIBS) $(all_libraries) -version-info 1:0:0 -no-undefined -AM_CPPFLAGS = $(SRC_CFLAGS) -Iidl +AM_CPPFLAGS = $(SRC_CFLAGS) DISTCLEANFILES = Makefile.in diff --git a/src/W1CounterDevice.cc b/src/W1CounterDevice.cc index 4f500e9..53c95f9 100644 --- a/src/W1CounterDevice.cc +++ b/src/W1CounterDevice.cc @@ -13,14 +13,14 @@ using namespace std; using namespace w1; -W1CounterDevice::W1CounterDevice(dirent *direntry, - int family_code_param, - string id_param): W1Device(direntry, family_code_param, id_param) { +W1CounterDevice::W1CounterDevice(int family_code_param, + string device_id_param, + dirent *direntry_param): W1Device(family_code_param, device_id_param, direntry_param) { + string text; + ifstream ifs(slave_file.c_str()); if (ifs.is_open() == true) { - string text; - - text = get_time() + ": device type = " + get_devicetype_name() + ", id = " + id + ", could not read file: " + slave_file; + text = get_time() + ": device type = " + get_device_type() + ", id = " + id + ", could not read file: " + slave_file; cout << text << endl; cout << "verify that you have w1_ds2423 kernel module loaded." << endl; ifs.close(); @@ -44,11 +44,10 @@ bool W1CounterDevice::is_supported_family_code(int family_code) { } string W1CounterDevice::get_raw_value() { - string ret_val; - string value_line; - int pos; - int length; - int ii; + string ret_val; + string value_line; + int pos; + int length; ret_val = ""; ifstream ifs(slave_file.c_str()); @@ -85,6 +84,6 @@ string W1CounterDevice::get_unit() { return ""; } -string W1CounterDevice::get_devicetype_name() { +string W1CounterDevice::get_device_type() { return "Counter Device"; } diff --git a/src/W1CounterDevice.hh b/src/W1CounterDevice.hh index b2080e0..837488c 100644 --- a/src/W1CounterDevice.hh +++ b/src/W1CounterDevice.hh @@ -13,11 +13,13 @@ namespace w1 { class W1CounterDevice: public w1::W1Device { public: - W1CounterDevice(dirent *direntry, int family_code_param, std::string id_param); + W1CounterDevice(int family_code_param, + std::string device_id_param, + dirent *direntry_param); virtual ~W1CounterDevice(); std::string get_raw_value(); std::string get_unit(); - std::string get_devicetype_name(); + std::string get_device_type(); protected: bool is_supported_family_code(int family_code); }; diff --git a/src/W1DataList.cc b/src/W1DataList.cc index 844db8e..9f2674f 100644 --- a/src/W1DataList.cc +++ b/src/W1DataList.cc @@ -12,6 +12,7 @@ #include "W1Util.hh" #include "W1DataList.hh" #include "W1Store.hh" +#include "DeviceConfig.hh" #include "plp/log.h" @@ -25,7 +26,7 @@ W1DataList::W1DataList(string device_id_param) { device_config = new DeviceConfig(device_id_param); summary_calc_type = device_config->get_summary_calculation_type(); device_id = device_id_param; - base_dir = W1Store::get_base_dir_name(); + base_dir = DeviceConfig::get_base_dir_name(); device_dir = W1Util::concat_paths(base_dir, device_id); device_ch_dir = W1Util::concat_paths(base_dir, "cache"); device_ch_dir = W1Util::concat_paths(device_ch_dir, device_id); @@ -36,7 +37,7 @@ W1DataList::~W1DataList() { } Data *W1DataList::find_oldest_data(vector year_vector) { - int ii; + unsigned int ii; string year_dir; string month_dir; vector month_vector; @@ -108,8 +109,6 @@ Data *W1DataList::find_newest_data(vector year_vector) { DataRange *W1DataList::get_data_range() { DataRange *ret_val; - DIR *data_dir; - struct dirent *year_dirent; vector year_list; Data *first_data; Data *newest_data; diff --git a/src/W1Device.cc b/src/W1Device.cc index 843910a..467a335 100644 --- a/src/W1Device.cc +++ b/src/W1Device.cc @@ -8,6 +8,7 @@ #include #include +#include #include "W1Store.hh" #include "W1Device.hh" @@ -15,20 +16,21 @@ using namespace w1; using namespace std; -W1Device::W1Device(dirent *direntry, - int family_code_param, - string id_param) { +W1Device::W1Device(int family_code_param, + string device_id_param, + dirent *direntry_param) { string rootdir; string device_dir; string temp_str; rootdir = W1_SCAN_ROOTDIR; temp_str = W1_SLAVE_FILE; - dir_path = rootdir + "/" + direntry->d_name; + dir_path = rootdir + "/" + direntry_param->d_name; slave_file = dir_path + "/" + temp_str; + log_debug("w1 data file: %s\n", slave_file.c_str()); family_code = family_code_param; - id = id_param; - name = id_param; + id = device_id_param; + name = device_id_param; } W1Device::~W1Device() { @@ -82,7 +84,7 @@ string W1Device::get_formatted_value() { string W1Device::get_formatted_value(string value) { string ret_val; - ret_val = get_time() + "|" + get_devicetype_name() + "|" + id + "|" + value + " " + get_unit(); + ret_val = get_time() + "|" + get_device_type() + "|" + id + "|" + value + " " + get_unit(); add_to_memory_cache(ret_val); return ret_val; } diff --git a/src/W1Device.hh b/src/W1Device.hh index 9eab016..a6902f7 100644 --- a/src/W1Device.hh +++ b/src/W1Device.hh @@ -25,7 +25,9 @@ namespace w1 { class W1Device { public: - W1Device(dirent *direntry, int family_code_param, std::string id_param); + W1Device(int family_code_param, + std::string device_id_param, + dirent *direntry_param); virtual ~W1Device(); int get_family_code(); std::string get_id(); @@ -34,7 +36,7 @@ namespace w1 { virtual std::string get_raw_value() = 0; std::string get_formatted_value(); virtual std::string get_unit() = 0; - virtual std::string get_devicetype_name() = 0; + virtual std::string get_device_type() = 0; std::string get_time(); virtual void printout(); virtual void store(); diff --git a/src/W1Scanner.cc b/src/W1Scanner.cc index 390c251..d40108e 100644 --- a/src/W1Scanner.cc +++ b/src/W1Scanner.cc @@ -18,6 +18,7 @@ #include "W1Scanner.hh" #include "W1TemperatureSensor.hh" #include "W1CounterDevice.hh" +#include "Factory.hh" using namespace w1; using namespace std; @@ -38,7 +39,7 @@ W1Scanner::W1Scanner() { W1Scanner::~W1Scanner() { } -W1Device *W1Scanner::create_device(dirent *direntry) { +W1Device *W1Scanner::create_device(dirent *direntry_param) { string folder_name; string tmp_str; string device_name; @@ -48,7 +49,7 @@ W1Device *W1Scanner::create_device(dirent *direntry) { W1Device *ret_val; ret_val = NULL; - folder_name = direntry->d_name; + folder_name = direntry_param->d_name; pos = folder_name.find("-"); if (pos > 0) { tmp_str = folder_name.substr(0, pos); @@ -57,20 +58,9 @@ W1Device *W1Scanner::create_device(dirent *direntry) { if (suc_flg == true) { log_debug("family_code: %d\n", family_code); device_name = folder_name.substr(pos + 1, folder_name.length() - pos); - switch(family_code) { - case 0x10: - case 0x28: - ret_val = new W1TemperatureSensor(direntry, family_code, device_name); - log_debug("temperature sensor: %d\n", ret_val->get_family_code()); - break; - case 0x1d: - log_debug("counter device: %d\n", family_code); - ret_val = new W1CounterDevice(direntry, family_code, device_name); - break; - default: - log_debug("device not created the device, unsupported device type: %d\n", family_code); - break; - } + ret_val = Factory::get_device(family_code, + device_name, + direntry_param); } } return ret_val; diff --git a/src/W1Scanner.hh b/src/W1Scanner.hh index c5e5529..21a7c7b 100644 --- a/src/W1Scanner.hh +++ b/src/W1Scanner.hh @@ -26,7 +26,7 @@ namespace w1 { std::list get_device_list(); private: //int parse_family_code(std::string folder_name); - W1Device *create_device(dirent *direntry); + W1Device *create_device(dirent *direntry_param); }; } diff --git a/src/W1Store.cc b/src/W1Store.cc index 80dde72..fda285e 100644 --- a/src/W1Store.cc +++ b/src/W1Store.cc @@ -27,8 +27,6 @@ using namespace std; using namespace w1; using namespace plp; -std::string W1Store::store_base_dir = DEFAULT_STORAGE_BASE_DIR; - W1Store::W1Store(string device_id, Date *date_time) { store_data = NULL; @@ -50,30 +48,14 @@ W1Store::~W1Store() { } } -void W1Store::set_base_dir_name(string store_param) { - int pos; - int b_count; - - pos = store_param.find_last_of("/"); - b_count = store_param.length(); - if (pos == (b_count - 1)) { - store_base_dir = store_param; - } - else { - store_base_dir = store_param + "/"; - } -} - -string W1Store::get_base_dir_name() { - return store_base_dir; -} - string W1Store::get_dir_name(string device_id, Date *date_time) { string ret_val; char buffer[30]; + string d_name; + d_name = DeviceConfig::get_base_dir_name(); snprintf(buffer, 30, "%d/%02d", date_time->year, date_time->month); - ret_val = W1Util::concat_paths(store_base_dir, device_id); + ret_val = W1Util::concat_paths(d_name, device_id); ret_val = ret_val + "/" + buffer; return ret_val; } @@ -157,7 +139,6 @@ Data *W1Store::get_sum() { double new_val; int ii; int jj; - Date *date; Data *data; Data *ret_val; @@ -260,7 +241,6 @@ Data *W1Store::get_max() { double new_val; int ii; int jj; - Date *date; Data *data; Data *ret_val; double min_val; @@ -308,7 +288,6 @@ Data *W1Store::get_min() { double new_val; int ii; int jj; - Date *date; Data *data; Data *ret_val; double max_val; @@ -414,7 +393,6 @@ DataRange *W1Store::get_oldest_and_newest_data() { Data *W1Store::get_oldest_data() { int row_count; - int col_count; Data *ret_val; DataRange *dr; @@ -432,7 +410,6 @@ Data *W1Store::get_oldest_data() { Data *W1Store::get_newest_data() { int row_count; - int col_count; Data *ret_val; DataRange *dr; diff --git a/src/W1Store.hh b/src/W1Store.hh index d27768a..53b124a 100644 --- a/src/W1Store.hh +++ b/src/W1Store.hh @@ -21,8 +21,6 @@ namespace w1 { plp::Date *date_time); W1Store(std::string file_name_param); virtual ~W1Store(); - static std::string get_base_dir_name(); - static void set_base_dir_name(std::string store_param); static std::string get_dir_name(std::string device_id, plp::Date *ltime); static std::string get_file_name(std::string device_id, plp::Date *ltime); static void store(std::string device_id, std::list *string_list); @@ -36,7 +34,6 @@ namespace w1 { w1::Data *get_newest_data(); w1::DataRange *get_oldest_and_newest_data(); protected: - static std::string store_base_dir; std::string store_file_name; DataRange *store_data; DataRange *range_data; diff --git a/src/W1TemperatureSensor.cc b/src/W1TemperatureSensor.cc index bfa7291..b02bb29 100644 --- a/src/W1TemperatureSensor.cc +++ b/src/W1TemperatureSensor.cc @@ -28,7 +28,6 @@ bool string_to_number(NumberDataType& result, string convert_celcius_value_to_three_digits(string raw_value) { string ret_val; - int int_val; bool suc_flg; double dbl_val; @@ -45,15 +44,15 @@ string convert_celcius_value_to_three_digits(string raw_value) { return ret_val; } -W1TemperatureSensor::W1TemperatureSensor(dirent *direntry, - int family_code_param, - string id_param): W1Device(direntry, family_code_param, id_param) { +W1TemperatureSensor::W1TemperatureSensor(int family_code_param, + string device_id_param, + dirent *direntry_param): W1Device(family_code_param, device_id_param, direntry_param) { + string text; + log_debug("trying to open file: %s\n", slave_file.c_str()); ifstream ifs(slave_file.c_str()); if (ifs.is_open() == false) { - string text; - - text = get_time() + ": device type = " + get_devicetype_name() + ", id = " + id + ", could not read file: " + slave_file + "\n"; + text = get_time() + ": device type = " + get_device_type() + ", id = " + id + ", could not read file: " + slave_file + "\n"; log_debug(text.c_str()); log_debug("verify that you have w1_therm kernel module loaded.\n"); ifs.close(); @@ -82,8 +81,7 @@ string W1TemperatureSensor::get_raw_value() { string last_line; int pos; int length; - string formatted_data; - int int_value; + string format; ret_val = ""; ifstream ifs(slave_file.c_str()); @@ -111,6 +109,6 @@ string W1TemperatureSensor::get_unit() { return "C"; } -string W1TemperatureSensor::get_devicetype_name() { +string W1TemperatureSensor::get_device_type() { return "Temperature Sensor"; } diff --git a/src/W1TemperatureSensor.hh b/src/W1TemperatureSensor.hh index f5235d6..6946c5c 100644 --- a/src/W1TemperatureSensor.hh +++ b/src/W1TemperatureSensor.hh @@ -13,11 +13,13 @@ namespace w1 { class W1TemperatureSensor : public W1Device { public: - W1TemperatureSensor(dirent *direntry, int family_code_param, std::string id_param); + W1TemperatureSensor(int family_code_param, + std::string device_id_param, + dirent *direntry_param); virtual ~W1TemperatureSensor(); std::string get_raw_value(); std::string get_unit(); - std::string get_devicetype_name(); + std::string get_device_type(); protected: bool is_supported_family_code(int family_code); }; diff --git a/src/W1Util.cc b/src/W1Util.cc index ba6b944..08dc7e0 100644 --- a/src/W1Util.cc +++ b/src/W1Util.cc @@ -108,9 +108,7 @@ bool W1Util::mkdirs(char *path) { std::ofstream *W1Util::open_for_writing(const char *f_path) { char *d_path; - char *p; size_t b_count; - int ii; ofstream *ret_val; bool b_flg; diff --git a/src_test/Makefile.am b/src_test/Makefile.am index be3a2db..0812159 100644 --- a/src_test/Makefile.am +++ b/src_test/Makefile.am @@ -8,6 +8,6 @@ test_w1_datalog_read_LDADD = $(SRC_LIBS) ../src/.libs/lib1wire.a test_w1_datalog_write_SOURCES = test_w1_datalog_write.cc test_w1_datalog_write_LDADD = $(SRC_LIBS) ../src/.libs/lib1wire.a -AM_CPPFLAGS = $(SRC_CFLAGS) -I../src +AM_CPPFLAGS = -I../src DISTCLEANFILES = Makefile.in \ No newline at end of file diff --git a/src_test/test_w1_datalog_read.cc b/src_test/test_w1_datalog_read.cc index 50003ed..0c4a5b9 100644 --- a/src_test/test_w1_datalog_read.cc +++ b/src_test/test_w1_datalog_read.cc @@ -14,9 +14,10 @@ #include #include "W1DataList.hh" -#include "W1Store.hh" +#include "DeviceConfig.hh" #include "W1Scanner.hh" +#include "Date.hh" #include "W1Util.hh" using namespace w1; @@ -46,9 +47,7 @@ bool try_parse_long(const char *str, long *result) { } int main(int argc, char** argv) { - int round; string loc; - bool err_flg; Data *fdata; Data *ldata; W1DataList *dlist; @@ -65,7 +64,7 @@ int main(int argc, char** argv) { else { log_warning("No storage location parameter given, using default location: %s\n", loc.c_str()); } - W1Store::set_base_dir_name(loc); + DeviceConfig::set_base_dir_name(loc); dlist = new W1DataList("0008014e9e09"); if (dlist != NULL) { dr = dlist->get_data_range(); @@ -76,7 +75,12 @@ int main(int argc, char** argv) { ldata = dr->get_last_data(); if (ldata != NULL) { ldata->printout(); - dr2 = dlist->get_data(&fdata->get_date(), &ldata->get_date()); + plp::Date d1; + plp::Date d2; + + d1 = fdata->get_date(); + d2 = ldata->get_date(); + dr2 = dlist->get_data(&d1, &d2); delete(ldata); if (dr2 != NULL) { delete(dr2); diff --git a/src_test/test_w1_datalog_write.cc b/src_test/test_w1_datalog_write.cc index 5931f5f..f5a86d8 100644 --- a/src_test/test_w1_datalog_write.cc +++ b/src_test/test_w1_datalog_write.cc @@ -13,7 +13,7 @@ #include -#include "W1Store.hh" +#include "DeviceConfig.hh" #include "W1Scanner.hh" using namespace w1; @@ -49,7 +49,6 @@ int main(int argc, char** argv) { long scan_interval; long store_interval; string location; - bool err_flg; W1Device *device; // default values than can be overwritten with parameters @@ -69,8 +68,8 @@ int main(int argc, char** argv) { if (argc > 3) { try_parse_long(argv[3], &store_interval); } - log_info("start scanning, data saved to location: %s, scan interval: %d, store interval: %d\n", location.c_str(), scan_interval, store_interval); - W1Store::set_base_dir_name(location); + log_info("start scanning, data saved to location: %s, scan interval: %ld, store interval: %ld\n", location.c_str(), scan_interval, store_interval); + DeviceConfig::set_base_dir_name(location); scanner = new W1Scanner(); device_list = scanner->get_device_list(); round = 0; @@ -81,7 +80,6 @@ int main(int argc, char** argv) { round++; for(list::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++) { device = (W1Device *)*list_iter; - device->printout(); sleep(1); if (round >= store_interval) { -- 2.41.0