X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=src%2FW1CounterDevice.cc;h=82a0beda2a00e5212ee5c1a59cdc416e49b4b0cc;hb=af341b7dfafac0912f513879565ebd856aa77915;hp=2566e1d4888114c0ccad31f28965a510948f39a0;hpb=c7979a0225a21182f68d40374723a649d032908d;p=lib1wire.git diff --git a/src/W1CounterDevice.cc b/src/W1CounterDevice.cc index 2566e1d..82a0bed 100644 --- a/src/W1CounterDevice.cc +++ b/src/W1CounterDevice.cc @@ -7,24 +7,36 @@ #include #include +#include +#include + +#include + +#include #include "W1CounterDevice.hh" using namespace std; using namespace w1; -W1CounterDevice::W1CounterDevice(dirent *direntry, - int family_code_param, - string id_param): W1Device(direntry, family_code_param, id_param) { +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(int family_code_param, + string device_id_param, + dirent *direntry_param): W1Device(family_code_param, device_id_param, direntry_param) { + string text; + ifstream ifs(slave_file.c_str()); if (ifs.is_open() == false) { - string text; - - text = get_time() + ": device type = " + get_devicetype_name() + ", id = " + id + ", could not read file: " + slave_file; - cout << text << endl; - cout << "verify that you have w1_ds2423 kernel module loaded." << endl; - } - else { + log_error("%s: %s failed to read data from file: %s\n", id.c_str(), get_device_type().c_str(), slave_file.c_str()); + log_error("Verify that you have w1_ds2423 kernel module loaded.\n"); ifs.close(); } } @@ -33,7 +45,7 @@ W1CounterDevice::~W1CounterDevice() { // TODO Auto-generated destructor stub } -bool W1CounterDevice::is_supported_family_code(int family_code) { +bool W1CounterDevice::is_supported_w1_family_code(int family_code) { bool ret_val; ret_val = false; @@ -45,37 +57,29 @@ bool W1CounterDevice::is_supported_family_code(int family_code) { return ret_val; } -string W1CounterDevice::get_value() { - string ret_val; - string value_line; +vector *W1CounterDevice::get_raw_data() { int pos; - int length; - int ii; + int b_cnt; + string val_str; + int val_dbl; + vector *ret_val; - ret_val = ""; + ret_val = NULL; ifstream ifs(slave_file.c_str()); if (ifs.is_open() == true) { - ret_val = ""; - while(getline(ifs, value_line)) { - length = value_line.length(); - if (length > 0) { - pos = value_line.find("crc=YES c="); + 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 < length)) { - value_line = value_line.substr(pos + 10); + ((pos + 10) < b_cnt)) { + if (ret_val == NULL) { + ret_val = new vector(); + } + val_str = val_str.substr(pos + 10); + string_to_number(val_dbl, val_str, dec); + ret_val->push_back(val_dbl); } - else { - value_line = ""; - } - } - else { - value_line = ""; - } - if (ret_val.length() == 0) { - ret_val = value_line; - } - else { - ret_val = ret_val + "|" + value_line; } } ifs.close(); @@ -87,6 +91,10 @@ string W1CounterDevice::get_unit() { return ""; } -string W1CounterDevice::get_devicetype_name() { +string W1CounterDevice::get_device_type() { return "Counter Device"; } + +unsigned int W1CounterDevice::get_data_decimal_precision() { + return 0; +}