/*
- * DeviceData.cc
+ * DataReader.cc
*
* Created on: Nov 7, 2010
* Author: lamikr
#include <string.h>
#include "W1Util.hh"
-#include "DeviceData.hh"
+#include "DataReader.hh"
#include "StoreDay.hh"
#include "StoreCache.hh"
#include "DeviceConfig.hh"
return !(iss >> format >> result).fail();
}
-DeviceData::DeviceData(string device_id_param) {
+DataReader::DataReader(string device_id_param) {
string base_dir;
device_config = NULL;
device_ch_dir = W1Util::concat_paths(device_ch_dir, device_id);
}
-DeviceData::~DeviceData() {
+DataReader::~DataReader() {
if (device_config != NULL) {
delete(device_config);
device_config = NULL;
}
}
-Data *DeviceData::find_newest_data(vector<string> year_name_vector_param) {
+Data *DataReader::find_newest_data(vector<string> year_name_vector_param) {
string year_name;
int size;
Data *ret_val;
return ret_val;
}
-Data *DeviceData::find_oldest_data(vector<string> year_name_vector_param) {
+Data *DataReader::find_oldest_data(vector<string> year_name_vector_param) {
int size;
string year_name;
Data *ret_val;
return ret_val;
}
-DataRange *DeviceData::get_data_range() {
+DataRange *DataReader::get_data_range() {
DataRange *ret_val;
vector<string> y_list;
Data *o_data;
return ret_val;
}
-DataRange *DeviceData::get_summary(Date *date_param,
+DataRange *DataReader::get_summary(Date *date_param,
EnumSummaryCalculationType calc_type_param,
EnumSummaryPeriod period_type_param) {
DataRange *ret_val;
return ret_val;
}
-DataRange *DeviceData::get_yearly_summary(Date *date,
+DataRange *DataReader::get_yearly_summary(Date *date,
EnumSummaryCalculationType calc_type_param) {
return get_summary(date, calc_type_param, PERIOD_YEARLY);
}
-DataRange *DeviceData::get_yearly_summary(Date *date) {
+DataRange *DataReader::get_yearly_summary(Date *date) {
DataRange *ret_val;
if (device_config == NULL) {
return ret_val;
}
-DataRange *DeviceData::get_yearly_summary(Date *start_date,
+DataRange *DataReader::get_yearly_summary(Date *start_date,
Date *end_date) {
DataRange *ret_val;
DataRange *data;
return ret_val;
}
-DataRange *DeviceData::get_monthly_summary(Date *date,
+DataRange *DataReader::get_monthly_summary(Date *date,
EnumSummaryCalculationType calc_type_param) {
return get_summary(date, calc_type_param, PERIOD_MONTHLY);
}
-DataRange *DeviceData::get_monthly_summary(Date *date) {
+DataRange *DataReader::get_monthly_summary(Date *date) {
DataRange *ret_val;
if (device_config == NULL) {
return ret_val;
}
-DataRange *DeviceData::get_monthly_summary(Date *start_date,
+DataRange *DataReader::get_monthly_summary(Date *start_date,
Date *end_date) {
DataRange *ret_val;
DataRange *data;
return ret_val;
}
-DataRange *DeviceData::get_daily_summary(Date *date,
+DataRange *DataReader::get_daily_summary(Date *date,
EnumSummaryCalculationType calc_type_param) {
return get_summary(date, calc_type_param, PERIOD_DAILY);
}
-DataRange *DeviceData::get_daily_summary(Date *date) {
+DataRange *DataReader::get_daily_summary(Date *date) {
DataRange *ret_val;
if (device_config == NULL) {
return ret_val;
}
-DataRange *DeviceData::get_daily_summary(Date *start_date,
+DataRange *DataReader::get_daily_summary(Date *start_date,
Date *end_date) {
DataRange *ret_val;
DataRange *data;
return ret_val;
}
-DataRange *DeviceData::get_hourly_summary(Date *date,
+DataRange *DataReader::get_hourly_summary(Date *date,
EnumSummaryCalculationType calc_type_param) {
return get_summary(date, calc_type_param, PERIOD_HOURLY);
}
-DataRange *DeviceData::get_hourly_summary(Date *date) {
+DataRange *DataReader::get_hourly_summary(Date *date) {
DataRange *ret_val;
if (device_config == NULL) {
return ret_val;
}
-DataRange *DeviceData::get_hourly_summary(Date *start_date,
+DataRange *DataReader::get_hourly_summary(Date *start_date,
Date *end_date) {
DataRange *ret_val;
DataRange *dta_lst;
return ret_val;
}
-DataRange *DeviceData::get_data(Date *start_date,
+DataRange *DataReader::get_data(Date *start_date,
Date *end_date) {
DataRange *ret_val;
EnumSummaryPeriod period;
}
return ret_val;
}
+
+string DataReader::get_device_id() {
+ return device_id;
+}
+
+/**
+ * Read device type from the device specific config file
+ */
+string DataReader::get_device_type() {
+ string ret_val;
+
+ if (device_config == NULL) {
+ device_config = Factory::get_device_config(device_id);
+ ret_val = device_config->get_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE);
+ }
+ return ret_val;
+}
/*
- * DeviceData.hh
+ * DataReader.hh
*
* Created on: Nov 7, 2010
* Author: lamikr
#include <time.h>
namespace plp {
- class DeviceData {
+ class DataReader {
public:
- DeviceData(std::string device_id);
- virtual ~DeviceData();
+ DataReader(std::string device_id);
+ virtual ~DataReader();
plp::DataRange *get_data_range();
/**
* Get monthly summary data.
plp::DataRange *get_hourly_summary(plp::Date *date);
plp::DataRange *get_hourly_summary(plp::Date *start_date, plp::Date *end_date);
plp::DataRange *get_data(plp::Date *start_date, plp::Date *end_date);
+ std::string get_device_id();
+ std::string get_device_type();
protected:
std::string device_id;
std::string device_dir;
#include <string>
+#include "DataReader.hh"
+
namespace plp {
- class DeviceTypeGeneric {
+ enum EnumDeviceLifeCycleStatus {LIFECYCLE_STATUS__UNAVAILABLE, LIFECYCLE_STATUS__AVAILABLE};
+
+ class Device {
public:
virtual std::string get_id() = 0;
virtual std::string get_name() = 0;
virtual void set_name(std::string name_param) = 0;
virtual std::string get_device_type() = 0;
+ virtual plp::DataReader *get_device_data() = 0;
+ virtual EnumDeviceLifeCycleStatus get_lifecycle_state() = 0;
virtual void printout() = 0;
};
}
--- /dev/null
+/*
+ * DeviceTypes.hh
+ *
+ * Created on: Mar 3, 2011
+ * Author: lamikr
+ */
+
+#ifndef DEVICETYPES_HH_
+#define DEVICETYPES_HH_
+
+#define DEVICE_TYPE_UNKNOWN "Unknown"
+#define DEVICE_TYPE_TEMPERATURESENSOR "Temperature Sensor"
+#define DEVICE_TYPE_COUNTER_DEVICE "Counter Device"
+
+#endif /* DEVICETYPES_HH_ */
#include <string.h>
#include <plp/log.h>
+
+#include "DeviceTypes.hh"
#include "Factory.hh"
#include "W1TemperatureSensor.hh"
#include "W1CounterDevice.hh"
// TODO Auto-generated destructor stub
}
-W1Device *Factory::get_device(int family_code,
- string device_id,
+int Factory::get_family_code_by_device_type(string device_type_param) {
+ int ret_val = -1;
+
+ if (device_type_param.compare(DEVICE_TYPE_TEMPERATURESENSOR) == 0) {
+ ret_val = 0x10;
+ }
+ else if (device_type_param.compare(DEVICE_TYPE_COUNTER_DEVICE) == 0) {
+ ret_val = 0x1d;
+ }
+ return ret_val;
+}
+
+string Factory::get_device_type_by_family_code(int family_code_param) {
+ string ret_val;
+
+ switch(family_code_param) {
+ case 0x10:
+ case 0x28:
+ ret_val = DEVICE_TYPE_TEMPERATURESENSOR;
+ break;
+ case 0x1d:
+ ret_val = DEVICE_TYPE_COUNTER_DEVICE;
+ break;
+ default:
+ ret_val = DEVICE_TYPE_UNKNOWN;
+ log_error("Unknown w1 device type: %d\n", family_code_param);
+ break;
+ }
+ return ret_val;
+}
+
+Device *Factory::create_w1_device(int family_code_param,
+ string device_id_param,
dirent *direntry_param) {
- W1Device *ret_val;
+ Device *ret_val;
DeviceConfig *config;
string type;
ret_val = NULL;
- switch(family_code) {
+ type = get_device_type_by_family_code(family_code_param);
+ switch(family_code_param) {
case 0x10:
case 0x28:
- ret_val = new W1TemperatureSensor(family_code, device_id, direntry_param);
+ ret_val = new W1TemperatureSensor(type, device_id_param, direntry_param);
break;
case 0x1d:
- ret_val = new W1CounterDevice(family_code, device_id, direntry_param);
+ ret_val = new W1CounterDevice(type, device_id_param, direntry_param);
break;
case 0x81:
// 0x81 is the 1-wire USB dongle... No need to create device for it.
break;
default:
- log_debug("Unsupported 1-wire-family code: %#x, device not created: %s\n", family_code, device_id.c_str());
+ log_debug("Unsupported 1-wire-family code: %#x, device not created: %s\n", family_code_param, device_id_param.c_str());
break;
}
if (ret_val != NULL) {
- log_debug("%s: %#x\n", ret_val->get_device_type().c_str(), ret_val->get_w1_family_code());
// check that device config exist
- config = get_device_config(device_id);
+ config = get_device_config(device_id_param);
if (config != NULL) {
// if not, create default device config
type = config->get_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE);
return ret_val;
}
-W1Device *Factory::create_device(dirent *direntry_param, int *err_code_param) {
- string folder_name;
- string tmp_str;
- string device_name;
- int pos;
- int family_code;
- bool suc_flg;
- W1Device *ret_val;
+Device *Factory::create_w1_device(string device_type_param,
+ string device_id_param) {
+ int family_code;
+ Device *ret_val;
+
+ family_code = get_family_code_by_device_type(device_type_param);
+ ret_val = create_w1_device(family_code, device_id_param, NULL);
+ return ret_val;
+}
+
+Device *Factory::create_w1_device(dirent *direntry_param, int *err_code_param) {
+ string folder_name;
+ string tmp_str;
+ string device_name;
+ int pos;
+ int family_code;
+ bool suc_flg;
+ Device *ret_val;
ret_val = NULL;
*err_code_param = 0;
if (suc_flg == true) {
log_debug("1-wire device family code: %#x\n", family_code);
device_name = folder_name.substr(pos + 1, folder_name.length() - pos);
- ret_val = Factory::get_device(family_code,
+ ret_val = Factory::create_w1_device(family_code,
device_name,
direntry_param);
if ((ret_val == NULL) &&
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;
+list<Device *> Factory::get_device_list() {
+ DIR *dir;
+ int err_flg;
+ struct dirent *direntry;
+ Device *device;
+ bool is_subdir;
+ list<DataReader *> rdr_list;
+ list<Device *> ret_val;
+ list<Device *>::iterator dev_iter;
+ list<DataReader *>::iterator rdr_iter;
+ DataReader *reader;
+ string id1;
+ string id2;
+ string type;
+ string dev_type;
+ bool found;
+ // scan through the list of devices detected from the 1-wire network
dir = opendir(W1_SCAN_ROOTDIR);
if (dir != NULL) {
direntry = readdir(dir);
is_subdir = W1Util::is_subdirectory(W1_SCAN_ROOTDIR, direntry);
if (is_subdir == true) {
err_flg = 0;
- device = create_device(direntry, &err_flg);
+ device = create_w1_device(direntry, &err_flg);
if (device != NULL) {
ret_val.push_back(device);
}
log_error("Failed to close 1-wire device directory: %s\n", W1_SCAN_ROOTDIR);
}
}
+ // scan through the list of devices which have saved data
+ rdr_list = get_data_reader_list();
+ for (rdr_iter = rdr_list.begin(); rdr_iter != rdr_list.end(); rdr_iter++) {
+ reader = (DataReader *)*rdr_iter;
+ id1 = reader->get_device_id();
+ found = false;
+ for (dev_iter = ret_val.begin(); dev_iter != ret_val.end(); dev_iter++) {
+ device = (Device *)*dev_iter;
+ id2 = device->get_id();
+ if (id1.compare(id2) == 0) {
+ found = true;
+ break;
+ }
+ }
+ if (found == false) {
+ // reader device is not in the list of active devices. create and add it to list as in-active one...
+ type = reader->get_device_type();
+ device = create_w1_device(type, id1);
+ ret_val.push_back(device);
+ }
+ }
return ret_val;
}
-list<DeviceData *> Factory::get_device_data_list() {
+list<DataReader *> Factory::get_data_reader_list() {
DIR *dir;
string dr_name;
int err_flg;
struct dirent *direntry;
- DeviceData *dev_dta;
+ DataReader *reader;
bool is_subdir;
- list<DeviceData *> ret_val;
+ list<DataReader *> ret_val;
dr_name = DeviceConfig::get_base_dir_name();
dir = opendir(dr_name.c_str());
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);
- ret_val.push_back(dev_dta);
+ reader = new DataReader(direntry->d_name);
+ ret_val.push_back(reader);
}
}
direntry = readdir(dir);
#define FACTORY_HH_
#include <string>
+#include <list>
#include <dirent.h>
#include "DeviceConfig.hh"
-#include "DeviceData.hh"
-#include "W1Device.hh"
+#include "DataReader.hh"
+#include "Device.hh"
#ifndef W1_SCAN_ROOTDIR
#define W1_SCAN_ROOTDIR "/sys/bus/w1/devices"
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<plp::DeviceData *> get_device_data_list();
+ static std::list<plp::Device *> get_device_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, int *err_code_param);
+ static plp::Device *create_w1_device(int family_code, std::string device_id, dirent *direntry_param);
+ static plp::Device *create_w1_device(std::string device_type_param, std::string device_id_param);
+ static plp::Device *create_w1_device(dirent *direntry_param, int *err_code_param);
+ static std::list<plp::DataReader *> get_data_reader_list();
+ static int get_family_code_by_device_type(std::string device_type_param);
+ static std::string get_device_type_by_family_code(int family_code_param);
};
}
lib_LTLIBRARIES = lib1wire.la
lib1wire_la_SOURCES = \
Data.cc Data.hh \
+ DataReader.cc DataReader.hh \
Date.cc Date.hh \
+ Device.hh \
DeviceConfig.cc DeviceConfig.hh \
- DeviceData.cc DeviceData.hh \
- DeviceTypeGeneric.hh \
- DeviceTypeSensor.hh \
+ DeviceTypes.hh \
+ SensorDevice.hh \
Factory.cc Factory.hh \
Store.cc Store.hh \
StoreDay.cc StoreDay.hh \
lib1wireincludedir=$(includedir)/w1
lib1wireinclude_HEADERS = \
Data.hh \
+ DataReader.hh \
Date.hh \
+ Device.hh \
DeviceConfig.hh \
- DeviceData.hh \
- DeviceTypeGeneric.hh \
- DeviceTypeSensor.hh \
+ DeviceTypes.hh \
+ SensorDevice.hh \
Factory.hh \
Store.hh \
StoreDay.hh \
#include <string>
-#include "DeviceTypeGeneric.hh"
+#include "Device.hh"
namespace plp {
- class DeviceTypeSensor : public DeviceTypeGeneric {
+ class SensorDevice : public Device {
public:
- virtual std::string get_unit() = 0;
- virtual plp::Data *get_data() = 0;
- virtual void save_data() = 0;
+ virtual std::string get_unit() = 0;
+ virtual plp::Data *get_data() = 0;
};
}
#include "StoreCache.hh"
#include "StoreDay.hh"
#include "DeviceConfig.hh"
-#include "DeviceData.hh"
#include "W1Util.hh"
using namespace std;
return !(iss >> format >> result).fail();
}
-W1CounterDevice::W1CounterDevice(int family_code_param,
+W1CounterDevice::W1CounterDevice(string device_type_param,
string device_id_param,
- dirent *direntry_param): W1Device(family_code_param, device_id_param, direntry_param) {
+ dirent *direntry_param): W1Device(device_type_param, device_id_param, direntry_param) {
string text;
ifstream ifs(slave_file.c_str());
// TODO Auto-generated destructor stub
}
-bool W1CounterDevice::is_supported_w1_family_code(int family_code) {
- bool ret_val;
-
- ret_val = false;
- switch(family_code) {
- case 0x1d:
- ret_val = true;
- break;
- }
- return ret_val;
-}
-
vector<double> *W1CounterDevice::get_raw_data() {
int pos;
int b_cnt;
return "";
}
-string W1CounterDevice::get_device_type() {
- return "Counter Device";
-}
-
unsigned int W1CounterDevice::get_data_decimal_precision() {
return 0;
}
namespace w1 {
class W1CounterDevice: public W1Device {
public:
- W1CounterDevice(int family_code_param,
+ W1CounterDevice(std::string device_type_param,
std::string device_id_param,
dirent *direntry_param);
virtual ~W1CounterDevice();
std::string get_unit();
- std::string get_device_type();
protected:
std::vector<double> *get_raw_data();
unsigned int get_data_decimal_precision();
- bool is_supported_w1_family_code(int family_code);
};
}
using namespace w1;
using namespace plp;
-W1Device::W1Device(int family_code_param,
+W1Device::W1Device(string device_type_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_param->d_name;
- slave_file = dir_path + "/" + temp_str;
- log_debug("1-wire device's data file: %s\n", slave_file.c_str());
- family_code = family_code_param;
- id = device_id_param;
+ type = device_type_param;
+ id = device_id_param;
+ if (direntry_param != NULL) {
+ rootdir = W1_SCAN_ROOTDIR;
+ temp_str = W1_SLAVE_FILE;
+ dir_path = rootdir + "/" + direntry_param->d_name;
+ slave_file = dir_path + "/" + temp_str;
+ lifecycle_status = LIFECYCLE_STATUS__AVAILABLE;
+ log_debug("1-wire device's data file: %s\n", slave_file.c_str());
+ }
+ else {
+ lifecycle_status = LIFECYCLE_STATUS__UNAVAILABLE;
+ }
name = "";
}
W1Device::~W1Device() {
- list<Data *>::iterator iter;
- Data *data;
-
- for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
- data = (Data *)*iter;
- delete(data);
- }
- memory_cache.clear();
-}
-
-int W1Device::get_w1_family_code() {
- return family_code;
+ save_and_clean_cache();
}
string W1Device::get_id() {
if (name.empty() == true) {
cfg = Factory::get_device_config(id);
if (cfg != NULL) {
- name = cfg->get_cfg_value("name");
+ name = cfg->get_cfg_value(DEVICE_CONFIG_VALUE_KEY__NAME);
delete(cfg);
}
}
name = name_param;
cfg = Factory::get_device_config(id);
if (cfg != NULL) {
- cfg->set_cfg_value("name", name_param);
+ cfg->set_cfg_value(DEVICE_CONFIG_VALUE_KEY__NAME, name_param);
delete(cfg);
}
}
void W1Device::printout() {
Data *data;
string text;
+ string type;
+ string name;
data = get_data();
if (data != NULL) {
cout << text << endl;
}
else {
- log_error("Could not data for %s device: %s\n", get_device_type().c_str(), get_name().c_str());
+ type = get_device_type();
+ name = get_name();
+ log_error("Could not data for %s device: %s\n", type.c_str(), name.c_str());
}
}
vect = get_raw_data();
if (vect != NULL) {
ret_val = new Data(vect, get_unit());
- collect_data(ret_val);
+ cache(ret_val);
delete(vect);
}
return ret_val;
}
-void W1Device::collect_data(Data *data) {
+void W1Device::cache(Data *data) {
// TODO: add mutex for memory_cache
memory_cache.push_back(data);
+ if (memory_cache.size() > 5) {
+ save_and_clean_cache();
+ }
}
-void W1Device::save_data() {
+void W1Device::save_and_clean_cache() {
list<Data *>::iterator iter;
Data *data;
int dec_precision;
}
memory_cache.clear();
}
+
+DataReader *W1Device::get_device_data() {
+ string id;
+
+ id = get_id();
+ return new DataReader(id);
+}
+
+EnumDeviceLifeCycleStatus W1Device::get_lifecycle_state() {
+ return lifecycle_status;
+}
+
+string W1Device::get_device_type() {
+ return type;
+}
#include <stdbool.h>
#include "Data.hh"
-#include "DeviceTypeSensor.hh"
+#include "SensorDevice.hh"
+#include "Device.hh"
#ifndef W1_SCAN_ROOTDIR
#define W1_SCAN_ROOTDIR "/sys/bus/w1/devices"
#endif
namespace w1 {
- class W1Device : public plp::DeviceTypeSensor {
+ class W1Device : public plp::SensorDevice {
public:
- W1Device(int family_code_param,
+ W1Device(std::string device_type_param,
std::string device_id_param,
dirent *direntry_param);
virtual ~W1Device();
- int get_w1_family_code();
std::string get_id();
std::string get_name();
void set_name(std::string name_param);
void printout();
plp::Data *get_data();
- void save_data();
+ plp::DataReader *get_device_data();
+ std::string get_device_type();
+ plp::EnumDeviceLifeCycleStatus get_lifecycle_state();
protected:
+ void save_and_clean_cache();
virtual std::vector<double> *get_raw_data() = 0;
virtual unsigned int get_data_decimal_precision() = 0;
- void collect_data(plp::Data *data);
+ void cache(plp::Data *data);
std::string to_string(double val, int digit_count);
//Data *get_formatted_data(Data *data);
- virtual bool is_supported_w1_family_code(int family_code) = 0;
- int family_code;
std::string id;
+ std::string type;
std::string name;
std::string dir_path;
std::string slave_file;
std::list<plp::Data *> memory_cache;
+ plp::EnumDeviceLifeCycleStatus lifecycle_status;
};
}
return dbl_val;
}
-W1TemperatureSensor::W1TemperatureSensor(int family_code_param,
+W1TemperatureSensor::W1TemperatureSensor(string device_type_param,
string device_id_param,
- dirent *direntry_param): W1Device(family_code_param, device_id_param, direntry_param) {
+ dirent *direntry_param): W1Device(device_type_param, device_id_param, direntry_param) {
ifstream ifs(slave_file.c_str());
if (ifs.is_open() == false) {
log_error("%s: %s failed to read data from file: %s\n", id.c_str(), get_device_type().c_str(), slave_file.c_str());
W1TemperatureSensor::~W1TemperatureSensor() {
}
-bool W1TemperatureSensor::is_supported_w1_family_code(int family_code) {
- bool ret_val;
-
- ret_val = false;
- switch(family_code) {
- case 0x10:
- case 0x28:
- ret_val = true;
- break;
- }
- return ret_val;
-}
-
vector<double> *W1TemperatureSensor::get_raw_data() {
vector<double> *ret_val;
string tmp_str;
return CONST_UNIT_CELCIUS;
}
-string W1TemperatureSensor::get_device_type() {
- return "Temperature Sensor";
-}
-
unsigned int W1TemperatureSensor::get_data_decimal_precision() {
return 3;
}
namespace w1 {
class W1TemperatureSensor : public W1Device {
public:
- W1TemperatureSensor(int family_code_param,
+ W1TemperatureSensor(std::string device_type_param,
std::string device_id_param,
dirent *direntry_param);
virtual ~W1TemperatureSensor();
std::string get_unit();
- std::string get_device_type();
protected:
std::vector<double> *get_raw_data();
unsigned int get_data_decimal_precision();
- bool is_supported_w1_family_code(int family_code);
};
}
#include <plp/log.h>
#include "Date.hh"
-#include "DeviceData.hh"
+#include "DataReader.hh"
#include "DeviceConfig.hh"
#include "Factory.hh"
#include "W1Util.hh"
}
int main(int argc, char** argv) {
- string loc;
- Data *fdata;
- Data *ldata;
- DeviceData *dta;
- DataRange *dr;
- DataRange *dr2;
- list<DeviceData *> dta_list;
+ string loc;
+ Data *fdata;
+ Data *ldata;
+ DataReader *reader;
+ Device *device;
+ DataRange *dr;
+ DataRange *dr2;
+ list<Device *> dev_lst;
+ list<Device *>::iterator list_iter;
// default values than can be overwritten with parameters
loc = "/tmp/w1data";
log_warning("No storage location parameter given, using default location: %s\n", loc.c_str());
}
DeviceConfig::set_base_dir_name(loc);
- 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();
- if (fdata != NULL) {
- fdata->printout();
- ldata = dr->get_last();
- if (ldata != NULL) {
- ldata->printout();
- plp::Date d1;
- plp::Date d2;
+ 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;
- d1 = fdata->get_date();
- d2 = ldata->get_date();
- dr2 = dta->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(dta);
}
}
return 0;
#include "DeviceConfig.hh"
#include "Factory.hh"
+#include "Device.hh"
using namespace w1;
using namespace std;
+using namespace plp;
#define DEFAULT_READ_INTERVAL_SECONDS 600
-#define DEFAULT_SAVE_INTERVAL_COUNT 5
#define DEFAULT_MAX_READ_COUNT -1
bool try_parse_long(const char *str, long *result) {
}
int main(int argc, char** argv) {
- list<W1Device *> device_list;
- int read_count_afer_save;
+ list<Device *> device_list;
int read_count_total;
long cnt_max_scans;
long read_interval_seconds;
- long save_interval_count;
string loc;
- W1Device *device;
- list<W1Device *>::iterator iter;
+ Device *device;
+ list<Device *>::iterator iter;
// default values than can be overwritten with parameters
loc = "/tmp/w1data";
read_interval_seconds = DEFAULT_READ_INTERVAL_SECONDS;
- save_interval_count = DEFAULT_SAVE_INTERVAL_COUNT;
cnt_max_scans = DEFAULT_MAX_READ_COUNT;
if (argc > 1) {
loc = argv[1];
}
else {
log_info("no parameter given using default values:\n");
- log_info("\ttest_w1_datalog_write %s %ld %ld %ld\n\n", loc.c_str(), read_interval_seconds, save_interval_count, cnt_max_scans);
- log_info("usage:\n\ttest_w1_datalog_write <result_save_path> <read_interval_seconds> <save_interval_count> <max_read_count>\n");
- log_info("\tsave_interval_count == -1: do not save data that is read\n");
+ log_info("\ttest_w1_datalog_write %s %ld %ld\n\n", loc.c_str(), read_interval_seconds, cnt_max_scans);
+ log_info("usage:\n\ttest_w1_datalog_write <result_save_path> <read_interval_seconds> <max_read_count>\n");
log_info("\tmax_read_count == -1: read devices until application is terminated\n\n");
}
if (argc > 2) {
try_parse_long(argv[2], &read_interval_seconds);
}
if (argc > 3) {
- try_parse_long(argv[3], &save_interval_count);
- }
- if (argc > 4) {
- try_parse_long(argv[4], &cnt_max_scans);
+ try_parse_long(argv[3], &cnt_max_scans);
}
log_info("searching 1-wire devices\n");
if (read_interval_seconds == DEFAULT_READ_INTERVAL_SECONDS) {
else {
log_info("\tdevice read interval: %ld seconds\n", read_interval_seconds);
}
- if (save_interval_count != -1) {
- if (save_interval_count == DEFAULT_SAVE_INTERVAL_COUNT) {
- log_info("\tsave interval: %ld (default value)\n", save_interval_count);
- }
- else {
- log_info("\tsave interval: %ld\n", save_interval_count);
- }
- log_info("\tdata save dir: %s\n", loc.c_str());
- }
- else {
- log_info("\tresults are not saved\n");
- }
+ log_info("\tdata save dir: %s\n", loc.c_str());
if (cnt_max_scans == DEFAULT_MAX_READ_COUNT) {
log_info("\tmax read count: %ld (default value, devices will be read until application is terminated)\n\n", cnt_max_scans);
}
}
DeviceConfig::set_base_dir_name(loc);
device_list = Factory::get_device_list();
- read_count_afer_save = 0;
read_count_total = 0;
if (device_list.size() > 0) {
while(1) {
- read_count_afer_save++;
read_count_total++;
if ((cnt_max_scans != -1) &&
(read_count_total > cnt_max_scans)) {
break;
}
for(iter = device_list.begin(); iter != device_list.end(); iter++) {
- device = (W1Device *)*iter;
- device->printout();
- sleep(1);
- if ((save_interval_count != -1) &&
- (read_count_afer_save >= save_interval_count)) {
- device->save_data();
+ device = (Device *)*iter;
+ if (device->get_lifecycle_state() == LIFECYCLE_STATUS__AVAILABLE) {
+ device->printout();
+ sleep(1);
+ }
+ else {
+ log_debug("device not available, %s.\n", device->get_id().c_str());
}
}
sleep(read_interval_seconds);
- if ((save_interval_count != -1) &&
- (read_count_afer_save >= save_interval_count)) {
- read_count_afer_save = 0;
- }
}
}
else {