/* * W1TemperatureSensor.cc * * Created on: Oct 20, 2010 * Author: lamikr */ #include #include #include #include "W1TemperatureSensor.hh" using namespace std; using namespace w1; W1TemperatureSensor::W1TemperatureSensor(dirent *direntry, int family_code_param, string id_param): W1Device(direntry, family_code_param, id_param) { ifstream ifs(slave_file.c_str()); if (ifs.is_open() == false) { string text; text = get_time() + ": device type = temperature sensor, id = " + id + ", could not read file: " + slave_file; cout << text << endl; cout << "verify that you have w1_therm kernel module loaded" << endl; } else { ifs.close(); } } W1TemperatureSensor::~W1TemperatureSensor() { } bool W1TemperatureSensor::is_supported_family_code(int family_code) { bool ret_val; ret_val = false; switch(family_code) { case 0x10: case 0x28: ret_val = true; break; } return ret_val; } string W1TemperatureSensor::get_value() { vector text_file; string temp; string ret_val; string last_line; int pos; int length; ret_val = ""; ifstream ifs(slave_file.c_str()); if (ifs.is_open() == true) { while(getline(ifs, temp)) { if (temp.length() > 0) { last_line = temp; //cout << ret_val << endl; } } ifs.close(); length = last_line.length(); if (length > 0) { pos = last_line.find("t="); if ((pos >= 0) && (pos + 2 < length)) { ret_val = last_line.substr(pos + 2); } } } return ret_val; } string W1TemperatureSensor::get_unit() { return "C"; } void W1TemperatureSensor::printout() { string text; text = get_time() + ": device type = temperature sensor, id = " + id + ", value = " + get_value(); cout << text << endl; }