4 * Created on: Oct 20, 2010
16 #include "W1Device.hh"
21 W1Device::W1Device(int family_code_param,
22 string device_id_param,
23 dirent *direntry_param) {
28 rootdir = W1_SCAN_ROOTDIR;
29 temp_str = W1_SLAVE_FILE;
30 dir_path = rootdir + "/" + direntry_param->d_name;
31 slave_file = dir_path + "/" + temp_str;
32 log_debug("w1 data file: %s\n", slave_file.c_str());
33 family_code = family_code_param;
35 name = device_id_param;
38 W1Device::~W1Device() {
39 list<Data *>::iterator iter;
42 for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
49 int W1Device::get_w1_family_code() {
53 string W1Device::get_id() {
57 string W1Device::get_name() {
61 void W1Device::set_name(string name_param) {
65 void W1Device::printout() {
69 data = get_and_collect_data();
71 text = data->to_string();
75 log_error("Could not data for %s device: %s\n", get_device_type().c_str(), get_name().c_str());
79 string W1Device::to_string(double dbl_val, int digit_count) {
83 out << fixed << setprecision(digit_count) << dbl_val;
89 Data *W1Device::get_and_collect_data() {
94 vect = get_raw_data();
96 ret_val = new Data(vect, get_unit());
97 collect_data(ret_val);
103 void W1Device::collect_data(Data *data) {
104 // TODO: add mutex for memory_cache
105 memory_cache.push_back(data);
108 void W1Device::save_data() {
109 list<Data *>::iterator iter;
113 dec_precision = get_data_decimal_precision();
114 W1Store::save(id, &memory_cache, dec_precision);
115 for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
116 data = (Data *)*iter;
119 memory_cache.clear();