/* * W1CounterDevice.cc * * Created on: Oct 30, 2010 * Author: lamikr */ #include #include #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) { 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; ifs.close(); } } 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; ret_val = ""; 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="); if ((pos >= 0) && (pos + 10 < length)) { value_line = value_line.substr(pos + 10); } else { value_line = ""; } } else { value_line = ""; } if (ret_val.length() == 0) { ret_val = value_line; } else { ret_val = ret_val + "|" + value_line; } } ifs.close(); } return ret_val; } string W1CounterDevice::get_unit() { return ""; } string W1CounterDevice::get_device_type() { return "Counter Device"; }