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;
+}