]> pilppa.org Git - lib1wire.git/blob - src/W1CounterDevice.cc
Initial support for reading log-data.
[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
11 #include "W1CounterDevice.hh"
12
13 using namespace std;
14 using namespace w1;
15
16 W1CounterDevice::W1CounterDevice(dirent *direntry,
17                                 int family_code_param,
18                                 string id_param): W1Device(direntry, family_code_param, id_param) {
19         ifstream ifs(slave_file.c_str());
20         if (ifs.is_open() == true) {
21                 string text;
22
23                 text    = get_time() + ": device type = " + get_devicetype_name() + ", id = " + id + ", could not read file: " + slave_file;
24                 cout << text << endl;
25                 cout << "verify that you have w1_ds2423 kernel module loaded." << endl;
26                 ifs.close();
27         }
28 }
29
30 W1CounterDevice::~W1CounterDevice() {
31         // TODO Auto-generated destructor stub
32 }
33
34 bool W1CounterDevice::is_supported_family_code(int family_code) {
35         bool    ret_val;
36
37         ret_val = false;
38         switch(family_code) {
39                 case 0x1d:
40                         ret_val = true;
41                         break;
42         }
43         return ret_val;
44 }
45
46 string W1CounterDevice::get_raw_value() {
47         string          ret_val;
48         string          value_line;
49         int             pos;
50         int             length;
51         int             ii;
52
53         ret_val = "<could not read>";
54         ifstream ifs(slave_file.c_str());
55         if (ifs.is_open() == true) {
56                 ret_val = "";
57                 while(getline(ifs, value_line)) {
58                         length  = value_line.length();
59                         if (length > 0) {
60                                 pos     = value_line.find("crc=YES c=");
61                                 if ((pos >= 0) &&
62                                     (pos + 10 < length)) {
63                                         value_line      = value_line.substr(pos + 10);
64                                 }
65                                 else {
66                                         value_line      = "";
67                                 }
68                         }
69                         else {
70                                 value_line      = "";
71                         }
72                         if (ret_val.length() == 0) {
73                                 ret_val = value_line;
74                         }
75                         else {
76                                 ret_val = ret_val + "|" + value_line;
77                         }
78                 }
79                 ifs.close();
80         }
81         return ret_val;
82 }
83
84 string W1CounterDevice::get_unit() {
85         return "";
86 }
87
88 string W1CounterDevice::get_devicetype_name() {
89         return "Counter Device";
90 }