]> pilppa.org Git - lib1wire.git/blob - src/W1CounterDevice.cc
fix build warnings
[lib1wire.git] / src / W1CounterDevice.cc
1 /*
2  * W1CounterDevice.cc
3  *
4  *  Created on: Oct 30, 2010
5  *      Author: lamikr
6  */
7
8 #include <iostream>
9 #include <fstream>
10 #include <sstream>
11 #include <iomanip>
12
13 #include <vector>
14
15 #include <plp/log.h>
16
17 #include "W1CounterDevice.hh"
18
19 using namespace std;
20 using namespace w1;
21
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&))
26 {
27         std::istringstream iss(string_param);
28         return !(iss >> format >> result).fail();
29 }
30
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) {
34         string text;
35
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");
40                 ifs.close();
41         }
42 }
43
44 W1CounterDevice::~W1CounterDevice() {
45         // TODO Auto-generated destructor stub
46 }
47
48 vector<double> *W1CounterDevice::get_raw_data() {
49         int             pos;
50         int             b_cnt;
51         string          val_str;
52         int             val_int;
53         vector<double>  *ret_val;
54
55         ret_val = NULL;
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();
60                         if (b_cnt > 0) {
61                                 pos     = val_str.find("crc=YES c=");
62                                 if ((pos >= 0) &&
63                                     ((pos + 10) < b_cnt)) {
64                                         if (ret_val == NULL) {
65                                                 ret_val = new vector<double>();
66                                         }
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);
70                                 }
71                         }
72                 }
73                 ifs.close();
74         }
75         return ret_val;
76 }
77
78 string W1CounterDevice::get_unit() {
79         return "";
80 }
81
82 unsigned int W1CounterDevice::get_data_decimal_precision() {
83         return 0;
84 }