4 * Created on: Oct 20, 2010
15 #include "DeviceConfig.hh"
18 #include "W1Device.hh"
23 W1Device::W1Device(int family_code_param,
24 string device_id_param,
25 dirent *direntry_param) {
30 rootdir = W1_SCAN_ROOTDIR;
31 temp_str = W1_SLAVE_FILE;
32 dir_path = rootdir + "/" + direntry_param->d_name;
33 slave_file = dir_path + "/" + temp_str;
34 log_debug("w1 data file: %s\n", slave_file.c_str());
35 family_code = family_code_param;
40 W1Device::~W1Device() {
41 list<Data *>::iterator iter;
44 for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
51 int W1Device::get_w1_family_code() {
55 string W1Device::get_id() {
59 string W1Device::get_name() {
62 if (name.empty() == true) {
63 cfg = Factory::get_device_config(id);
65 name = cfg->get_cfg_value("name");
72 void W1Device::set_name(string name_param) {
76 cfg = Factory::get_device_config(id);
78 cfg->set_cfg_value("name", name_param);
83 void W1Device::printout() {
87 data = get_and_collect_data();
89 text = data->to_string();
93 log_error("Could not data for %s device: %s\n", get_device_type().c_str(), get_name().c_str());
97 string W1Device::to_string(double dbl_val, int digit_count) {
101 out << fixed << setprecision(digit_count) << dbl_val;
107 Data *W1Device::get_and_collect_data() {
109 vector<double> *vect;
112 vect = get_raw_data();
114 ret_val = new Data(vect, get_unit());
115 collect_data(ret_val);
121 void W1Device::collect_data(Data *data) {
122 // TODO: add mutex for memory_cache
123 memory_cache.push_back(data);
126 void W1Device::save_data() {
127 list<Data *>::iterator iter;
131 dec_precision = get_data_decimal_precision();
132 W1Store::save(id, &memory_cache, dec_precision);
133 for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
134 data = (Data *)*iter;
137 memory_cache.clear();