-AC_INIT(src/W1Scanner.cc)
+AC_INIT(src/Data.cc)
AM_CONFIG_HEADER(config.h)
AC_CONFIG_MACRO_DIR([m4])
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,
ret_val = NULL;
cfg_dir = get_dir_name(device_id_param);
if (cfg_dir.empty() == false) {
+ if (access(cfg_dir.c_str(), W_OK) != 0) {
+ W1Util::mkdirs(cfg_dir.c_str());
+ }
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) {
+ 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) {
set_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE, "unknowntype");
}
}
+ else {
+ log_error("Failed to load device device configuration, file does not exit: %s.\n", cfg_fl.c_str());
+ }
}
else {
- log_error("Failed to load device device configurations, invalid device id: %s.\n", cfg_dir.c_str());
+ log_error("Failed to load device device configuration, invalid device id: %s.\n", cfg_dir.c_str());
}
}
return ret_val;
/*
- * W1DataList.cc
+ * DeviceData.cc
*
* Created on: Nov 7, 2010
* Author: lamikr
#include <string.h>
#include "W1Util.hh"
-#include "W1DataList.hh"
+#include "DeviceData.hh"
#include "W1Store.hh"
#include "DeviceConfig.hh"
+#include "Factory.hh"
#include "plp/log.h"
using namespace std;
using namespace plp;
-W1DataList::W1DataList(string device_id_param) {
+DeviceData::DeviceData(string device_id_param) {
string base_dir;
- device_config = new DeviceConfig(device_id_param);
+ device_config = Factory::get_device_config(device_id_param);
summary_calc_type = device_config->get_summary_calculation_type();
device_id = device_id_param;
base_dir = DeviceConfig::get_base_dir_name();
device_ch_dir = W1Util::concat_paths(device_ch_dir, device_id);
}
-W1DataList::~W1DataList() {
+DeviceData::~DeviceData() {
delete(device_config);
}
-Data *W1DataList::find_oldest_data(vector<string> year_vector) {
+Data *DeviceData::find_oldest_data(vector<string> year_vector) {
unsigned int ii;
string year_dir;
string month_dir;
return ret_val;
}
-Data *W1DataList::find_newest_data(vector<string> year_vector) {
+Data *DeviceData::find_newest_data(vector<string> year_vector) {
int ii;
string year_dir;
string month_dir;
return ret_val;
}
-DataRange *W1DataList::get_data_range() {
+DataRange *DeviceData::get_data_range() {
DataRange *ret_val;
vector<string> year_list;
Data *first_data;
return ret_val;
}
-Data *W1DataList::get_daily_summary(Date *date) {
+Data *DeviceData::get_daily_summary(Date *date) {
Data *ret_val;
W1Store *store;
return ret_val;
}
-DataRange *W1DataList::get_daily_summary(Date *start_date,
+DataRange *DeviceData::get_daily_summary(Date *start_date,
Date *end_date) {
DataRange *ret_val;
Data *data;
return ret_val;
}
-DataRange *W1DataList::get_data(Date *start_date,
+DataRange *DeviceData::get_data(Date *start_date,
Date *end_date) {
DataRange *ret_val;
int int_type;
/*
- * W1DataList.hh
+ * DeviceData.hh
*
* Created on: Nov 7, 2010
* Author: lamikr
#include <time.h>
namespace w1 {
- class W1DataList {
+ class DeviceData {
public:
- W1DataList(std::string device_id);
- virtual ~W1DataList();
+ DeviceData(std::string device_id);
+ virtual ~DeviceData();
DataRange *get_data_range();
/**
* Get summary data calculated from the daily data items that is meaning full.
* Author: lamikr
*/
+#include <string>
+#include <sstream>
+#include <iostream>
+
+#include <string.h>
+
#include <plp/log.h>
#include "Factory.hh"
#include "W1TemperatureSensor.hh"
#include "W1CounterDevice.hh"
+#include "W1Util.hh"
using namespace w1;
using namespace std;
+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();
+}
+
Factory::Factory() {
// TODO Auto-generated constructor stub
}
return ret_val;
}
+W1Device *Factory::create_device(dirent *direntry_param) {
+ string folder_name;
+ string tmp_str;
+ string device_name;
+ int pos;
+ int family_code;
+ bool suc_flg;
+ W1Device *ret_val;
+
+ ret_val = NULL;
+ folder_name = direntry_param->d_name;
+ pos = folder_name.find("-");
+ if (pos > 0) {
+ tmp_str = folder_name.substr(0, pos);
+ // number in string is in hex format, convert to int
+ suc_flg = string_to_number<int>(family_code, tmp_str, hex);
+ if (suc_flg == true) {
+ log_debug("family_code: %d\n", family_code);
+ device_name = folder_name.substr(pos + 1, folder_name.length() - pos);
+ ret_val = Factory::get_device(family_code,
+ device_name,
+ direntry_param);
+ }
+ }
+ return ret_val;
+}
+
+list<W1Device *> Factory::get_device_list() {
+ DIR *dir;
+ int err_flg;
+ struct dirent *direntry;
+ W1Device *device;
+ bool is_subdir;
+ list<W1Device *> ret_val;
+
+ printf("get_device_list() started\n");
+ dir = opendir(W1_SCAN_ROOTDIR);
+ if (dir != NULL) {
+ direntry = readdir(dir);
+ while(direntry != NULL) {
+ is_subdir = W1Util::is_subdirectory(W1_SCAN_ROOTDIR, direntry);
+ if (is_subdir == true) {
+ log_info("dir_name: %s\n", direntry->d_name);
+ device = create_device(direntry);
+ if (device != NULL) {
+ log_info("device: %d\n", device->get_family_code());
+ ret_val.push_back(device);
+ }
+ else {
+ log_info("unsupported device-directory: %s\n", direntry->d_name);
+ }
+ }
+ direntry = readdir(dir);
+ }
+ err_flg = closedir(dir);
+ if (err_flg < 0) {
+ log_error("failed to close 1-wire device directory: %s\n", W1_SCAN_ROOTDIR);
+ }
+ }
+ return ret_val;
+}
+
+list<DeviceData *> Factory::get_device_data_list() {
+ DIR *dir;
+ string dr_name;
+ int err_flg;
+ struct dirent *direntry;
+ DeviceData *dev_dta;
+ bool is_subdir;
+ list<DeviceData *> ret_val;
+
+ printf("get_device_list() started\n");
+ dr_name = DeviceConfig::get_base_dir_name();
+ dir = opendir(dr_name.c_str());
+ if (dir != NULL) {
+ direntry = readdir(dir);
+ while(direntry != NULL) {
+ if (strcmp(direntry->d_name, "cache") != 0) {
+ is_subdir = W1Util::is_subdirectory(dr_name.c_str(), direntry);
+ if (is_subdir == true) {
+ dev_dta = new DeviceData(direntry->d_name);
+ log_info("dir_name: %s\n", direntry->d_name);
+ ret_val.push_back(dev_dta);
+ }
+ }
+ direntry = readdir(dir);
+ }
+ err_flg = closedir(dir);
+ if (err_flg < 0) {
+ log_error("failed to close 1-wire device data directory: %s\n", dr_name.c_str());
+ }
+ }
+ return ret_val;
+}
+
DeviceConfig *Factory::get_device_config(string device_id) {
DeviceConfig *ret_val;
#include <dirent.h>
#include "DeviceConfig.hh"
+#include "DeviceData.hh"
#include "W1Device.hh"
+#ifndef W1_SCAN_ROOTDIR
+ #define W1_SCAN_ROOTDIR "/sys/bus/w1/devices"
+#endif
+
namespace w1 {
class Factory {
public:
Factory();
virtual ~Factory();
static W1Device *get_device(int family_code, std::string device_id, dirent *direntry_param);
+ static std::list<W1Device *> get_device_list();
+ static std::list<DeviceData *> get_device_data_list();
static DeviceConfig *get_device_config(std::string device_id);
+ private:
+ //int parse_family_code(std::string folder_name);
+ static W1Device *create_device(dirent *direntry_param);
};
}
lib1wire_la_SOURCES = \
Factory.cc Factory.hh \
W1Device.cc W1Device.hh \
- W1Scanner.cc W1Scanner.hh \
W1Store.cc W1Store.hh \
W1TemperatureSensor.cc W1TemperatureSensor.hh \
W1CounterDevice.cc W1CounterDevice.hh \
W1Util.cc W1Util.hh \
- W1DataList.cc W1DataList.hh \
+ DeviceData.cc DeviceData.hh \
DeviceConfig.cc DeviceConfig.hh \
Data.cc Data.hh \
Date.cc Date.hh \
lib1wireincludedir=$(includedir)/w1
lib1wireinclude_HEADERS = \
+ Data.hh \
+ Date.hh \
+ DeviceConfig.hh \
+ DeviceData.hh \
+ Factory.hh \
+ W1CounterDevice.hh \
W1Device.hh \
- W1Scanner.hh \
W1Store.hh \
W1TemperatureSensor.hh \
- Date.hh \
- W1CounterDevice.hh
\ No newline at end of file
+ W1Util.hh
\ No newline at end of file
+++ /dev/null
-/*
- * W1Scanner.cc
- *
- * Created on: Oct 20, 2010
- * Author: lamikr
- */
-
-#include <string.h>
-#include <malloc.h>
-
-#include <string>
-#include <sstream>
-#include <iostream>
-
-#include <plp/log.h>
-
-#include "W1Util.hh"
-#include "W1Scanner.hh"
-#include "W1TemperatureSensor.hh"
-#include "W1CounterDevice.hh"
-#include "Factory.hh"
-
-using namespace w1;
-using namespace std;
-
-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();
-}
-
-W1Scanner::W1Scanner() {
- log_debug("W1Scanner created\n");
-}
-
-W1Scanner::~W1Scanner() {
-}
-
-W1Device *W1Scanner::create_device(dirent *direntry_param) {
- string folder_name;
- string tmp_str;
- string device_name;
- int pos;
- int family_code;
- bool suc_flg;
- W1Device *ret_val;
-
- ret_val = NULL;
- folder_name = direntry_param->d_name;
- pos = folder_name.find("-");
- if (pos > 0) {
- tmp_str = folder_name.substr(0, pos);
- // number in string is in hex format, convert to int
- suc_flg = string_to_number<int>(family_code, tmp_str, hex);
- if (suc_flg == true) {
- log_debug("family_code: %d\n", family_code);
- device_name = folder_name.substr(pos + 1, folder_name.length() - pos);
- ret_val = Factory::get_device(family_code,
- device_name,
- direntry_param);
- }
- }
- return ret_val;
-}
-
-list<W1Device *> W1Scanner::get_device_list() {
- DIR *dir;
- int err_flg;
- struct dirent *direntry;
- W1Device *device;
- list<W1Device *> ret_val;
- bool is_subdir;
-
- printf("get_device_list() started\n");
- dir = opendir(W1_SCAN_ROOTDIR);
- if (dir != NULL) {
- direntry = readdir(dir);
- while(direntry != NULL) {
- is_subdir = W1Util::is_subdirectory(W1_SCAN_ROOTDIR, direntry);
- if (is_subdir == true) {
- log_info("dir_name: %s\n", direntry->d_name);
- device = create_device(direntry);
- if (device != NULL) {
- log_info("device: %d\n", device->get_family_code());
- ret_val.push_back(device);
- }
- else {
- log_info("unsupported device-directory: %s\n", direntry->d_name);
- }
- }
- direntry = readdir(dir);
- }
- err_flg = closedir(dir);
- if (err_flg < 0) {
- log_error("failed to close 1-wire device directory scanned: %s\n", W1_SCAN_ROOTDIR);
- }
- }
- return ret_val;
-}
+++ /dev/null
-/*
- * W1Scanner.hh
- *
- * Created on: Oct 20, 2010
- * Author: lamikr
- */
-
-#ifndef W1SCANNER_HH_
-#define W1SCANNER_HH_
-
-#include <dirent.h>
-#include <list>
-#include <string>
-
-#include "W1Device.hh"
-
-#ifndef W1_SCAN_ROOTDIR
- #define W1_SCAN_ROOTDIR "/sys/bus/w1/devices"
-#endif
-
-namespace w1 {
- class W1Scanner {
- public:
- W1Scanner();
- virtual ~W1Scanner();
- std::list<W1Device *> get_device_list();
- private:
- //int parse_family_code(std::string folder_name);
- W1Device *create_device(dirent *direntry_param);
- };
-}
-
-#endif /* W1SCANNER_HH_ */
#include <plp/log.h>
+#include "DeviceConfig.hh"
#include "W1Configure.hh"
#include "W1Store.hh"
#include "W1Util.hh"
return ret_val;
}
-bool W1Util::mkdirs(char *path) {
+bool W1Util::mkdirs(const char *path) {
bool ret_val;
char *p;
int err_flg;
ret_val = true;
if (path != NULL) {
// go through each directory one by and and create if not exist
- for (p = path; *p; p++) {
+ for (p = (char *)path; *p; p++) {
if ((p != path) &&
((*p == '/') ||
(*p == '\\'))) {
*p = '\0';
- // test whether directory exist and is writable
- if (access(path, F_OK)) {
+ // if dir does not exist, create it
+ if (access(path, F_OK) != 0) {
log_debug("trying to create directory: %s\n", path);
err_flg = mkdir(path, S_IRWXU);
if (err_flg != 0) {
}
}
if (ret_val == true) {
- // test also the existense of whole directory
- if (access(path, F_OK)) {
+ // if dir does not exist, create it
+ if (access(path, F_OK) != 0) {
log_debug("trying to create directory: %s\n", path);
err_flg = mkdir(path, S_IRWXU);
if (err_flg != 0) {
#include <dirent.h>
#include <stdbool.h>
-#include "W1DataList.hh"
-
namespace w1 {
class W1Util {
public:
static std::vector<std::string> get_data_files(const std::string& path);
static plp::Date parse_date_str(std::string date_str);
static char *parse_directory_path(const char *file_path);
- static bool mkdirs(char *path);
+ static bool mkdirs(const char *path);
static std::ofstream *open_for_writing(const char *path);
};
}
#include <plp/log.h>
-#include "W1DataList.hh"
-#include "DeviceConfig.hh"
-#include "W1Scanner.hh"
-
#include "Date.hh"
+#include "DeviceData.hh"
+#include "DeviceConfig.hh"
+#include "Factory.hh"
#include "W1Util.hh"
using namespace w1;
}
int main(int argc, char** argv) {
- string loc;
- Data *fdata;
- Data *ldata;
- W1DataList *dlist;
- DataRange *dr;
- DataRange *dr2;
+ string loc;
+ Data *fdata;
+ Data *ldata;
+ DeviceData *dta;
+ DataRange *dr;
+ DataRange *dr2;
+ list<DeviceData *> dta_list;
// default values than can be overwritten with parameters
- //location = "/tmp/";
- loc = "/home/lamikr/own/src/plp/w1data2/";
+ loc = "/tmp/w1data";
if (argc > 1) {
loc = argv[1];
log_info("storage location: %s\n", loc.c_str());
log_warning("No storage location parameter given, using default location: %s\n", loc.c_str());
}
DeviceConfig::set_base_dir_name(loc);
- dlist = new W1DataList("0008014e9e09");
- if (dlist != NULL) {
- dr = dlist->get_data_range();
- if (dr != NULL) {
- fdata = dr->get_first_data();
- if (fdata != NULL) {
- fdata->printout();
- ldata = dr->get_last_data();
- if (ldata != NULL) {
- ldata->printout();
- plp::Date d1;
- plp::Date d2;
+ dta_list = Factory::get_device_data_list();
+ for(list<DeviceData *>::iterator list_iter = dta_list.begin(); list_iter != dta_list.end(); list_iter++) {
+ dta = (DeviceData *)*list_iter;
+ if (dta != NULL) {
+ dr = dta->get_data_range();
+ if (dr != NULL) {
+ fdata = dr->get_first_data();
+ if (fdata != NULL) {
+ fdata->printout();
+ ldata = dr->get_last_data();
+ if (ldata != NULL) {
+ ldata->printout();
+ 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);
+ d1 = fdata->get_date();
+ d2 = ldata->get_date();
+ dr2 = dta->get_data(&d1, &d2);
+ delete(ldata);
+ if (dr2 != NULL) {
+ delete(dr2);
+ }
}
+ delete(fdata);
}
- delete(fdata);
+ delete(dr);
}
- delete(dr);
+ delete(dta);
}
- delete(dlist);
}
return 0;
}
#include <plp/log.h>
#include "DeviceConfig.hh"
-#include "W1Scanner.hh"
+#include "Factory.hh"
using namespace w1;
using namespace std;
}
int main(int argc, char** argv) {
- W1Scanner *scanner;
list<W1Device *> device_list;
int round;
long scan_interval;
long store_interval;
- string location;
+ string loc;
W1Device *device;
// default values than can be overwritten with parameters
- location = "/tmp/";
- scan_interval = 2; //600;
+ loc = "/tmp/w1data";
+ scan_interval = 600; //600;
store_interval = 2;
if (argc > 1) {
- location = argv[1];
- log_info("storage location: %s\n", location.c_str());
+ loc = argv[1];
+ log_info("storage location: %s\n", loc.c_str());
}
else {
- log_warning("No storage location parameter given, using default location: %s\n", location.c_str());
+ log_warning("No storage location parameter given, using default location: %s\n", loc.c_str());
}
if (argc > 2) {
try_parse_long(argv[2], &scan_interval);
if (argc > 3) {
try_parse_long(argv[3], &store_interval);
}
- 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();
+ log_info("start scanning, data saved to location: %s, scan interval: %ld, store interval: %ld\n", loc.c_str(), scan_interval, store_interval);
+ DeviceConfig::set_base_dir_name(loc);
+ device_list = Factory::get_device_list();
round = 0;
- int t = 0;
if (device_list.size() > 0) {
- while(t < 3) {
- t++;
+ while(1) {
round++;
for(list<W1Device *>::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++) {
device = (W1Device *)*list_iter;
device_list.pop_back();
delete(device);
}
- delete(scanner);
return 0;
}