/* * W1CounterDevice.cc * * Created on: Oct 30, 2010 * Author: lamikr */ #include #include #include #include #include #include #include "W1CounterDevice.hh" using namespace std; using namespace w1; template bool string_to_number(NumberDataType& result, const std::string& string_param, std::ios_base& (*format)(std::ios_base&)) { std::istringstream iss(string_param); return !(iss >> format >> result).fail(); } W1CounterDevice::W1CounterDevice(string device_id_param, string device_type_param, dirent *direntry_param): W1Device(device_id_param, device_type_param, direntry_param) { string text; ifstream ifs(slave_file.c_str()); if (ifs.is_open() == false) { log_error("%s: %s failed to read data from file: %s\n", id.c_str(), get_type().c_str(), slave_file.c_str()); log_error("Verify that you have w1_ds2423 kernel module loaded.\n"); ifs.close(); } } W1CounterDevice::~W1CounterDevice() { // TODO Auto-generated destructor stub } vector *W1CounterDevice::get_raw_data() { int pos; int b_cnt; string val_str; int val_int; vector *ret_val; ret_val = NULL; ifstream ifs(slave_file.c_str()); if (ifs.is_open() == true) { while(getline(ifs, val_str)) { b_cnt = val_str.length(); if (b_cnt > 0) { pos = val_str.find("crc=YES c="); if ((pos >= 0) && ((pos + 10) < b_cnt)) { if (ret_val == NULL) { ret_val = new vector(); } val_str = val_str.substr(pos + 10); string_to_number(val_int, val_str, dec); ret_val->push_back(val_int); } } } ifs.close(); } return ret_val; } string W1CounterDevice::get_unit() { return ""; } unsigned int W1CounterDevice::get_data_decimal_precision() { return 0; }