4 * Created on: Oct 30, 2010
15 #include "W1CounterDevice.hh"
20 template <class NumberDataType>
21 bool string_to_number(NumberDataType& result,
22 const std::string& string_param,
23 std::ios_base& (*format)(std::ios_base&))
25 std::istringstream iss(string_param);
26 return !(iss >> format >> result).fail();
29 W1CounterDevice::W1CounterDevice(int family_code_param,
30 string device_id_param,
31 dirent *direntry_param): W1Device(family_code_param, device_id_param, direntry_param) {
34 ifstream ifs(slave_file.c_str());
35 if (ifs.is_open() == true) {
36 text = get_time() + ": device type = " + get_device_type() + ", id = " + id + ", could not read file: " + slave_file;
38 cout << "verify that you have w1_ds2423 kernel module loaded." << endl;
43 W1CounterDevice::~W1CounterDevice() {
44 // TODO Auto-generated destructor stub
47 bool W1CounterDevice::is_supported_w1_family_code(int family_code) {
59 vector<double> *W1CounterDevice::get_raw_data() {
64 vector<double> *ret_val;
67 ifstream ifs(slave_file.c_str());
68 if (ifs.is_open() == true) {
69 while(getline(ifs, val_str)) {
70 b_cnt = val_str.length();
72 pos = val_str.find("crc=YES c=");
74 ((pos + 10) < b_cnt)) {
75 if (ret_val == NULL) {
76 ret_val = new vector<double>();
78 val_str = val_str.substr(pos + 10);
79 string_to_number<int>(val_dbl, val_str, dec);
80 ret_val->push_back(val_dbl);
89 string W1CounterDevice::get_unit() {
93 string W1CounterDevice::get_device_type() {
94 return "Counter Device";