]> pilppa.org Git - lib1wire.git/blobdiff - src/W1CounterDevice.cc
fix build warnings
[lib1wire.git] / src / W1CounterDevice.cc
index d4a20f69de840644343d6d7c7bdad809506cb975..c77b872db77786d3da509746e232645f9ad7cbaa 100644 (file)
@@ -7,22 +7,36 @@
 
 #include <iostream>
 #include <fstream>
+#include <sstream>
+#include <iomanip>
+
+#include <vector>
+
+#include <plp/log.h>
 
 #include "W1CounterDevice.hh"
 
 using namespace std;
 using namespace w1;
 
-W1CounterDevice::W1CounterDevice(int family_code_param,
-                               string device_id_param,
-                               dirent *direntry_param): W1Device(family_code_param, device_id_param, direntry_param) {
+template <class NumberDataType>
+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() == true) {
-               text    = get_time() + ": device type = " + get_device_type() + ", id = " + id + ", could not read file: " + slave_file;
-               cout << text << endl;
-               cout << "verify that you have w1_ds2423 kernel module loaded." << endl;
+       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();
        }
 }
@@ -31,49 +45,30 @@ W1CounterDevice::~W1CounterDevice() {
        // TODO Auto-generated destructor stub
 }
 
-bool W1CounterDevice::is_supported_family_code(int family_code) {
-       bool    ret_val;
-
-       ret_val = false;
-       switch(family_code) {
-               case 0x1d:
-                       ret_val = true;
-                       break;
-       }
-       return ret_val;
-}
-
-string W1CounterDevice::get_raw_data() {
-       string  ret_val;
-       string  value_line;
-       int     pos;
-       int     length;
+vector<double> *W1CounterDevice::get_raw_data() {
+       int             pos;
+       int             b_cnt;
+       string          val_str;
+       int             val_int;
+       vector<double>  *ret_val;
 
-       ret_val = "<could not read>";
+       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);
-                               }
-                               else {
-                                       value_line      = "";
+                                   ((pos + 10) < b_cnt)) {
+                                       if (ret_val == NULL) {
+                                               ret_val = new vector<double>();
+                                       }
+                                       val_str = val_str.substr(pos + 10);
+                                       string_to_number<int>(val_int, val_str, dec);
+                                       ret_val->push_back(val_int);
                                }
                        }
-                       else {
-                               value_line      = "";
-                       }
-                       if (ret_val.length() == 0) {
-                               ret_val = value_line;
-                       }
-                       else {
-                               ret_val = ret_val + "|" + value_line;
-                       }
                }
                ifs.close();
        }
@@ -84,6 +79,6 @@ string W1CounterDevice::get_unit() {
        return "";
 }
 
-string W1CounterDevice::get_device_type() {
-       return "Counter Device";
+unsigned int W1CounterDevice::get_data_decimal_precision() {
+       return 0;
 }