return ret_val;
}
-string Data::to_string() {
+string Data::to_string(int dec_precision) {
unsigned int ii;
ostringstream out;
string ret_val;
ret_val = date_time.to_string();
if (value_arr.size() > 0) {
for (ii = 0; ii < value_arr.size(); ii++) {
- out << fixed << setprecision(3) << value_arr[ii];
- ret_val.append("|");
- ret_val.append(out.str());
+ out << "|" << fixed << setprecision(dec_precision) << value_arr[ii];
}
+ ret_val.append(out.str());
if (unit.empty() == false) {
ret_val.append(" ");
ret_val.append(unit.c_str());
return ret_val;
}
+string Data::to_string() {
+ return to_string(3);
+}
+
DataRange::DataRange(Data *data) {
val_matrix = NULL;
column_count = data->value_arr.size();
virtual ~Data();
Data *clone();
void printout();
+ std::string to_string(int dec_precision);
std::string to_string();
static Data *parse_string(const std::string& data_str);
plp::Date get_date();
#include <vector>
+#include <plp/log.h>
+
#include "W1CounterDevice.hh"
using namespace std;
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;
+ if (ifs.is_open() == false) {
+ log_error("%s: %s failed to read data from file: %s\n", id.c_str(), get_device_type().c_str(), slave_file.c_str());
+ log_error("Verify that you have w1_ds2423 kernel module loaded.\n");
ifs.close();
}
}
string W1CounterDevice::get_device_type() {
return "Counter Device";
}
+
+unsigned int W1CounterDevice::get_data_decimal_precision() {
+ return 0;
+}
std::string get_device_type();
protected:
std::vector<double> *get_raw_data();
+ unsigned int get_data_decimal_precision();
bool is_supported_w1_family_code(int family_code);
};
}
}
W1Device::~W1Device() {
+ list<Data *>::iterator iter;
+ Data *data;
+
+ for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
+ data = (Data *)*iter;
+ delete(data);
+ }
+ memory_cache.clear();
}
int W1Device::get_w1_family_code() {
name = name_param;
}
-string W1Device::get_time() {
- time_t wtime;
- struct tm *ltime;
- char buffer[80];
- string ret_val;
-
- time(&wtime);
- ltime = localtime(&wtime);
- strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", ltime);
- ret_val = buffer;
- return ret_val;
-}
-
void W1Device::printout() {
Data *data;
string text;
return ret_val;
}
-/*
-Data *W1Device::get_formatted_data(Data *data) {
- Data *ret_val;
-
- ret_val = get_time() + "|" + raw_data + " " + get_unit();
- add_to_save_fifo(ret_val);
- return ret_val;
-}
-*/
-
void W1Device::collect_data(Data *data) {
// TODO: add mutex for memory_cache
memory_cache.push_back(data);
void W1Device::save_data() {
list<Data *>::iterator iter;
Data *data;
+ int dec_precision;
- W1Store::save(id, &memory_cache);
+ dec_precision = get_data_decimal_precision();
+ W1Store::save(id, &memory_cache, dec_precision);
for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
data = (Data *)*iter;
delete(data);
void set_name(std::string name_param);
virtual std::string get_unit() = 0;
virtual std::string get_device_type() = 0;
- std::string get_time();
Data *get_and_collect_data();
virtual void save_data();
virtual void printout();
protected:
virtual std::vector<double> *get_raw_data() = 0;
+ virtual unsigned int get_data_decimal_precision() = 0;
void collect_data(Data *data);
std::string to_string(double val, int digit_count);
//Data *get_formatted_data(Data *data);
}
void W1Store::save(string device_id,
- std::list<Data *> *data_list) {
+ std::list<Data *> *data_list,
+ int dec_precision) {
string n_path;
string f_path;
string line;
}
if ((ostream != NULL) &&
(ostream->is_open() == true)) {
- line = data->to_string();
+ line = data->to_string(dec_precision);
if (line.length() > 0) {
log_debug("storing line: %s\n", line.c_str());
*ostream << line << endl;
virtual ~W1Store();
static std::string get_dir_name(std::string device_id, plp::Date *ltime);
static std::string get_file_name(std::string device_id, plp::Date *ltime);
- static void save(std::string device_id, std::list<Data *> *data_list);
+ static void save(std::string device_id, std::list<Data *> *data_list, int dec_precision);
bool load();
Data *get_sum();
Data *get_delta();
W1TemperatureSensor::W1TemperatureSensor(int family_code_param,
string device_id_param,
dirent *direntry_param): W1Device(family_code_param, device_id_param, direntry_param) {
- string text;
-
log_debug("trying to open file: %s\n", slave_file.c_str());
+
ifstream ifs(slave_file.c_str());
if (ifs.is_open() == false) {
- text = get_time() + ": device type = " + get_device_type() + ", id = " + id + ", could not read file: " + slave_file + "\n";
- log_debug(text.c_str());
- log_debug("verify that you have w1_therm kernel module loaded.\n");
+ log_error("%s: %s failed to read data from file: %s\n", id.c_str(), get_device_type().c_str(), slave_file.c_str());
+ log_error("Verify that you have w1_therm kernel module loaded.\n");
ifs.close();
}
}
string W1TemperatureSensor::get_device_type() {
return "Temperature Sensor";
}
+
+unsigned int W1TemperatureSensor::get_data_decimal_precision() {
+ return 3;
+}
std::string get_device_type();
protected:
std::vector<double> *get_raw_data();
+ unsigned int get_data_decimal_precision();
bool is_supported_w1_family_code(int family_code);
};
}