]> pilppa.org Git - lib1wire.git/blob - src/W1CounterDevice.cc
d4a20f69de840644343d6d7c7bdad809506cb975
[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(int family_code_param,
17                                 string device_id_param,
18                                 dirent *direntry_param): W1Device(family_code_param, device_id_param, direntry_param) {
19         string text;
20
21         ifstream ifs(slave_file.c_str());
22         if (ifs.is_open() == true) {
23                 text    = get_time() + ": device type = " + get_device_type() + ", 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_data() {
47         string  ret_val;
48         string  value_line;
49         int     pos;
50         int     length;
51
52         ret_val = "<could not read>";
53         ifstream ifs(slave_file.c_str());
54         if (ifs.is_open() == true) {
55                 ret_val = "";
56                 while(getline(ifs, value_line)) {
57                         length  = value_line.length();
58                         if (length > 0) {
59                                 pos     = value_line.find("crc=YES c=");
60                                 if ((pos >= 0) &&
61                                     (pos + 10 < length)) {
62                                         value_line      = value_line.substr(pos + 10);
63                                 }
64                                 else {
65                                         value_line      = "";
66                                 }
67                         }
68                         else {
69                                 value_line      = "";
70                         }
71                         if (ret_val.length() == 0) {
72                                 ret_val = value_line;
73                         }
74                         else {
75                                 ret_val = ret_val + "|" + value_line;
76                         }
77                 }
78                 ifs.close();
79         }
80         return ret_val;
81 }
82
83 string W1CounterDevice::get_unit() {
84         return "";
85 }
86
87 string W1CounterDevice::get_device_type() {
88         return "Counter Device";
89 }