PDUUnit.h 1.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
 * PDUUnit.h
 *
 *  Created on: 26.02.2018
 *      Author: Micha Mueller
 */

#ifndef SRC_SENSORS_PDU_PDUUNIT_H_
#define SRC_SENSORS_PDU_PDUUNIT_H_

11
#include <boost/asio.hpp>
12
13
14
15
16
17
18
#include <boost/property_tree/ptree.hpp>

class PDUUnit {
public:
	PDUUnit();
	virtual ~PDUUnit();

19
20
	void setTTL(unsigned ttl) {
		_ttl = ttl;
21
22
	}

23
24
	unsigned getTTL() const {
		return _ttl;
25
26
	}

27
28
29
30
	void setHost(const std::string& host) {
		_host = host;
	}

31
32
33
34
35
36
	void initalizeStrand(boost::asio::io_service& io);

	boost::asio::io_service::strand* getStrand() const {
		return _strand;
	}

37
	/**
38
39
	 * Finds and returns the corresponding value in the energy.xml
	 * Checks if the _ptree is still up to date. If not updates it by a call to refresh().
40
	 *
41
42
43
	 * @param clustsafeID	ID of the clustsafe to find in the energy.xml
	 * @param outletID		ID of the outlet to find within the clustsafe
	 * @return				The value in the latest energy.xml, denoted by clustsafeID and outletID
44
	 */
45
	uint64_t findValue(unsigned clustsafeID, unsigned outletID);
46
47
48
49

private:

	/**
50
	 * Gets a current version of the XML-file energy.xml with sensor data and parses its content into _ptree
51
	 */
52
	void refresh();
53
54

	uint64_t 	_lastRefresh;
55
	unsigned int _ttl;
56
	std::string	_host;
57
	boost::property_tree::ptree _ptree;
58
	boost::asio::io_service::strand* _strand;
59
60
61
};

#endif /* SRC_SENSORS_PDU_PDUUNIT_H_ */