]> pilppa.org Git - lib1wire.git/blob - src/W1Device.cc
initial version
[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 <time.h>
9
10 #include "W1Device.hh"
11
12 using namespace w1;
13 using namespace std;
14
15 W1Device::W1Device(dirent *direntry, int family_code_param, string id_param) {
16         string rootdir;
17         string device_dir;
18         string temp_str;
19
20         rootdir         = W1_SCAN_ROOTDIR;
21         temp_str        = W1_SLAVE_FILE;
22         dir_path        = rootdir + "/" + direntry->d_name;
23         slave_file      = dir_path + "/" + temp_str;
24         family_code     = family_code_param;
25         id                      = id_param;
26         name            = id_param;
27 }
28
29 W1Device::~W1Device() {
30 }
31
32 int W1Device::get_family_code() {
33         return family_code;
34 }
35
36 string W1Device::get_id() {
37         return id;
38 }
39
40 string W1Device::get_name() {
41         return name;
42 }
43
44 void W1Device::set_name(string name_param) {
45         name    = name_param;
46 }
47
48 string W1Device::get_time() {
49         time_t          wtime;
50         struct tm       *ltime;
51         char            buffer[80];
52         string          ret_val;
53
54         time(&wtime);
55         ltime   = localtime(&wtime);
56         strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", ltime);
57         ret_val = buffer;
58         return ret_val;
59 }
60
61 void W1Device::printout() {
62         string text;
63
64         text    = get_time() + ": device type = <unknown>, id = " + id + ", value = " + get_value();
65         cout << text << endl;
66 }