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() {
41 int W1Device::get_w1_family_code() {
45 string W1Device::get_id() {
49 string W1Device::get_name() {
53 void W1Device::set_name(string name_param) {
57 string W1Device::get_time() {
64 ltime = localtime(&wtime);
65 strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", ltime);
70 void W1Device::printout() {
74 data = get_and_collect_data();
76 text = data->to_string();
80 log_error("Could not data for %s device: %s\n", get_device_type().c_str(), get_name().c_str());
84 string W1Device::to_string(double dbl_val, int digit_count) {
88 out << fixed << setprecision(digit_count) << dbl_val;
94 Data *W1Device::get_and_collect_data() {
99 vect = get_raw_data();
101 ret_val = new Data(vect, get_unit());
102 collect_data(ret_val);
109 Data *W1Device::get_formatted_data(Data *data) {
112 ret_val = get_time() + "|" + raw_data + " " + get_unit();
113 add_to_save_fifo(ret_val);
118 void W1Device::collect_data(Data *data) {
119 // TODO: add mutex for memory_cache
120 memory_cache.push_back(data);
123 void W1Device::save_data() {
124 list<Data *>::iterator iter;
127 W1Store::save(id, &memory_cache);
128 for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
129 data = (Data *)*iter;
132 memory_cache.clear();