X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=src%2FW1Device.cc;fp=src%2FW1Device.cc;h=7bb44183c489287c846d95487dbafa44abe25773;hb=6dea0b59503a71874c4476c05044fff3c5ae26a5;hp=6719be76c32ea428a363f4c85d17986ebebb8e44;hpb=c4d8504b99fa1e354d15b2b91e4e2797f54ba028;p=lib1wire.git diff --git a/src/W1Device.cc b/src/W1Device.cc index 6719be7..7bb4418 100644 --- a/src/W1Device.cc +++ b/src/W1Device.cc @@ -6,6 +6,8 @@ */ #include #include +#include +#include #include #include @@ -36,7 +38,7 @@ W1Device::W1Device(int family_code_param, W1Device::~W1Device() { } -int W1Device::get_family_code() { +int W1Device::get_w1_family_code() { return family_code; } @@ -66,34 +68,66 @@ string W1Device::get_time() { } void W1Device::printout() { - string text; + Data *data; + string text; + + data = get_and_collect_data(); + if (data != NULL) { + text = data->to_string(); + cout << text << endl; + } + else { + log_error("Could not data for %s device: %s\n", get_device_type().c_str(), get_name().c_str()); + } +} + +string W1Device::to_string(double dbl_val, int digit_count) { + string ret_val; + ostringstream out; - text = get_formatted_data(); - cout << text << endl; + out << fixed << setprecision(digit_count) << dbl_val; + ret_val = out.str(); + return ret_val; } -string W1Device::get_formatted_data() { - string ret_val; - string val; - val = get_raw_data(); - ret_val = get_formatted_data(val); +Data *W1Device::get_and_collect_data() { + Data *ret_val; + vector *vect; + + ret_val = NULL; + vect = get_raw_data(); + if (vect != NULL) { + ret_val = new Data(vect, get_unit()); + collect_data(ret_val); + delete(vect); + } return ret_val; } -string W1Device::get_formatted_data(string raw_data) { - string ret_val; +/* +Data *W1Device::get_formatted_data(Data *data) { + Data *ret_val; ret_val = get_time() + "|" + raw_data + " " + get_unit(); - add_to_memory_cache(ret_val); + add_to_save_fifo(ret_val); return ret_val; } +*/ -void W1Device::add_to_memory_cache(std::string formatted_data) { +void W1Device::collect_data(Data *data) { // TODO: add mutex for memory_cache - memory_cache.push_back(formatted_data); + memory_cache.push_back(data); } -void W1Device::store() { - W1Store::store(id, &memory_cache); +void W1Device::save_data() { + list::iterator iter; + Data *data; + + W1Store::save(id, &memory_cache); + for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) { + data = (Data *)*iter; + delete(data); + } + memory_cache.clear(); }