]> pilppa.org Git - lib1wire.git/blob - src/W1CounterDevice.cc
storage data cleanup. allow specifying storage dir location
[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() == false) {
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         }
27         else {
28                 ifs.close();
29         }
30 }
31
32 W1CounterDevice::~W1CounterDevice() {
33         // TODO Auto-generated destructor stub
34 }
35
36 bool W1CounterDevice::is_supported_family_code(int family_code) {
37         bool    ret_val;
38
39         ret_val = false;
40         switch(family_code) {
41                 case 0x1d:
42                         ret_val = true;
43                         break;
44         }
45         return ret_val;
46 }
47
48 string W1CounterDevice::get_value() {
49         string          ret_val;
50         string          value_line;
51         int             pos;
52         int             length;
53         int             ii;
54
55         ret_val = "<could not read>";
56         ifstream ifs(slave_file.c_str());
57         if (ifs.is_open() == true) {
58                 ret_val = "";
59                 while(getline(ifs, value_line)) {
60                         length  = value_line.length();
61                         if (length > 0) {
62                                 pos     = value_line.find("crc=YES c=");
63                                 if ((pos >= 0) &&
64                                     (pos + 10 < length)) {
65                                         value_line      = value_line.substr(pos + 10);
66                                 }
67                                 else {
68                                         value_line      = "";
69                                 }
70                         }
71                         else {
72                                 value_line      = "";
73                         }
74                         if (ret_val.length() == 0) {
75                                 ret_val = value_line;
76                         }
77                         else {
78                                 ret_val = ret_val + "|" + value_line;
79                         }
80                 }
81                 ifs.close();
82         }
83         return ret_val;
84 }
85
86 string W1CounterDevice::get_unit() {
87         return "";
88 }
89
90 string W1CounterDevice::get_devicetype_name() {
91         return "Counter Device";
92 }