4 * Created on: Oct 30, 2010
17 #include "W1CounterDevice.hh"
22 template <class NumberDataType>
23 bool string_to_number(NumberDataType& result,
24 const std::string& string_param,
25 std::ios_base& (*format)(std::ios_base&))
27 std::istringstream iss(string_param);
28 return !(iss >> format >> result).fail();
31 W1CounterDevice::W1CounterDevice(string device_id_param,
32 string device_type_param,
33 dirent *direntry_param): W1Device(device_id_param, device_type_param, direntry_param) {
36 ifstream ifs(slave_file.c_str());
37 if (ifs.is_open() == false) {
38 log_error("%s: %s failed to read data from file: %s\n", id.c_str(), get_type().c_str(), slave_file.c_str());
39 log_error("Verify that you have w1_ds2423 kernel module loaded.\n");
44 W1CounterDevice::~W1CounterDevice() {
45 // TODO Auto-generated destructor stub
48 vector<double> *W1CounterDevice::get_raw_data() {
53 vector<double> *ret_val;
56 ifstream ifs(slave_file.c_str());
57 if (ifs.is_open() == true) {
58 while(getline(ifs, val_str)) {
59 b_cnt = val_str.length();
61 pos = val_str.find("crc=YES c=");
63 ((pos + 10) < b_cnt)) {
64 if (ret_val == NULL) {
65 ret_val = new vector<double>();
67 val_str = val_str.substr(pos + 10);
68 string_to_number<int>(val_int, val_str, dec);
69 ret_val->push_back(val_int);
78 string W1CounterDevice::get_unit() {
82 unsigned int W1CounterDevice::get_data_decimal_precision() {