]> pilppa.org Git - lib1wire.git/blob - src/W1Device.cc
cleanups, renamed get_*_values functions to get_*_data
[lib1wire.git] / src / W1Device.cc
1 /*
2  * W1Device.cc
3  *
4  *  Created on: Oct 20, 2010
5  *      Author: lamikr
6  */
7 #include <iostream>
8 #include <fstream>
9
10 #include <time.h>
11 #include <plp/log.h>
12
13 #include "W1Store.hh"
14 #include "W1Device.hh"
15
16 using namespace w1;
17 using namespace std;
18
19 W1Device::W1Device(int family_code_param,
20                 string device_id_param,
21                 dirent *direntry_param) {
22         string rootdir;
23         string device_dir;
24         string temp_str;
25
26         rootdir         = W1_SCAN_ROOTDIR;
27         temp_str        = W1_SLAVE_FILE;
28         dir_path        = rootdir + "/" + direntry_param->d_name;
29         slave_file      = dir_path + "/" + temp_str;
30         log_debug("w1 data file: %s\n", slave_file.c_str());
31         family_code     = family_code_param;
32         id              = device_id_param;
33         name            = device_id_param;
34 }
35
36 W1Device::~W1Device() {
37 }
38
39 int W1Device::get_family_code() {
40         return family_code;
41 }
42
43 string W1Device::get_id() {
44         return id;
45 }
46
47 string W1Device::get_name() {
48         return name;
49 }
50
51 void W1Device::set_name(string name_param) {
52         name    = name_param;
53 }
54
55 string W1Device::get_time() {
56         time_t          wtime;
57         struct tm       *ltime;
58         char            buffer[80];
59         string          ret_val;
60
61         time(&wtime);
62         ltime   = localtime(&wtime);
63         strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", ltime);
64         ret_val = buffer;
65         return ret_val;
66 }
67
68 void W1Device::printout() {
69         string text;
70
71         text    = get_formatted_data();
72         cout << text << endl;
73 }
74
75 string W1Device::get_formatted_data() {
76         string ret_val;
77         string val;
78
79         val     = get_raw_data();
80         ret_val = get_formatted_data(val);
81         return ret_val;
82 }
83
84 string W1Device::get_formatted_data(string raw_data) {
85         string ret_val;
86
87         ret_val = get_time() + "|" + raw_data + " " + get_unit();
88         add_to_memory_cache(ret_val);
89         return ret_val;
90 }
91
92 void W1Device::add_to_memory_cache(std::string formatted_data) {
93         // TODO: add mutex for memory_cache
94         memory_cache.push_back(formatted_data);
95 }
96
97 void W1Device::store() {
98         W1Store::store(id, &memory_cache);
99 }