4 * Created on: Oct 20, 2010
15 #include "DeviceConfig.hh"
18 #include "W1Device.hh"
24 W1Device::W1Device(int family_code_param,
25 string device_id_param,
26 dirent *direntry_param) {
31 rootdir = W1_SCAN_ROOTDIR;
32 temp_str = W1_SLAVE_FILE;
33 dir_path = rootdir + "/" + direntry_param->d_name;
34 slave_file = dir_path + "/" + temp_str;
35 log_debug("w1 data file: %s\n", slave_file.c_str());
36 family_code = family_code_param;
41 W1Device::~W1Device() {
42 list<Data *>::iterator iter;
45 for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
52 int W1Device::get_w1_family_code() {
56 string W1Device::get_id() {
60 string W1Device::get_name() {
63 if (name.empty() == true) {
64 cfg = Factory::get_device_config(id);
66 name = cfg->get_cfg_value("name");
73 void W1Device::set_name(string name_param) {
77 cfg = Factory::get_device_config(id);
79 cfg->set_cfg_value("name", name_param);
84 void W1Device::printout() {
88 data = get_and_collect_data();
90 text = data->to_string();
94 log_error("Could not data for %s device: %s\n", get_device_type().c_str(), get_name().c_str());
98 string W1Device::to_string(double dbl_val, int digit_count) {
102 out << fixed << setprecision(digit_count) << dbl_val;
108 Data *W1Device::get_and_collect_data() {
110 vector<double> *vect;
113 vect = get_raw_data();
115 ret_val = new Data(vect, get_unit());
116 collect_data(ret_val);
122 void W1Device::collect_data(Data *data) {
123 // TODO: add mutex for memory_cache
124 memory_cache.push_back(data);
127 void W1Device::save_data() {
128 list<Data *>::iterator iter;
132 dec_precision = get_data_decimal_precision();
133 Store::save(id, &memory_cache, dec_precision);
134 for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
135 data = (Data *)*iter;
138 memory_cache.clear();