IPMIHost.h 3.07 KB
Newer Older
1
/*
2
 * IPMIHost.h
3
4
5
6
7
8
9
10
11
12
13
 *
 *  Created on: 18 Jan 2017
 *      Author: ottmi
 */

#ifndef IPMIHOST_H_
#define IPMIHOST_H_

#include <string>
#include <list>
#include <freeipmi/freeipmi.h>
14
#include <boost/asio.hpp>
15
#include "../../includes/Logging.h"
16

17
18
19
20
21
class IPMIHost {
public:
	IPMIHost();
	virtual ~IPMIHost();

22
23
	/* Translate recordId to SDR record */
	bool getSdrRecord(uint16_t recordId, std::vector<uint8_t>& record);
24
	/* Send raw command to BMC. Returns sensor reading as responded by BMC. */
25
	int64_t sendRawCmd(const std::vector<uint8_t>& rawCmd, uint16_t start, uint16_t stop);
26
	/* Read the sensor specified by its record id. Returns sensor reading. */
27
	double readSensorRecord(std::vector<uint8_t>& record);
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

	void increaseErrorCount();
	const uint64_t getDelayFactor() const;

	void setAuth(uint8_t auth)						{ _auth = auth; }
	void setHostName(const std::string& hostName)	{ _hostName = hostName; }
	void setPassword(const std::string& password)	{	_password = password; }
	void setCache(const std::string& cacheDir)		{ _cache = cacheDir + ".ipmiPluginSdrCache." + _hostName; }
	void setPriv(uint8_t priv)						{ _priv = priv; }
	void setUserName(const std::string& userName)	{ _userName = userName; }
	void setMqttPart(const std::string& mqttPart) {
		_mqttPart = mqttPart;
		if (_mqttPart.front() != '/') {
			_mqttPart.insert(0, "/");
		}
		if (_mqttPart.back() == '/') {
			_mqttPart.erase(_mqttPart.size()-1);
		}
	}
	void setSessionTimeout(uint32_t sessionTimeout) { _sessionTimeout = sessionTimeout; }
	void setRetransmissionTimeout(uint32_t retransmissionTimeout) { _retransmissionTimeout = retransmissionTimeout; }
	void initializeStrand(boost::asio::io_service& io);
	void setDelayNextReadUntil(uint64_t delayNextReadUntil) { _delayNextReadUntil = delayNextReadUntil; }

	uint8_t getAuth() 					const { return _auth; }
	const std::string& getHostName()	const { return _hostName; }
	const std::string& getPassword()	const { return _password; }
	const std::string& getCache()		const { return _cache; }
	uint8_t getPriv()					const { return _priv; }
	const std::string& getUserName()	const { return _userName; }
	const std::string& getMqttPart()	const { return _mqttPart; }
	boost::asio::io_service::strand* getStrand() const { return _strand; }
	uint64_t getDelayNextReadUntil()	const { return _delayNextReadUntil; }

private:
	/* Open/close connection to BMC (sets/destroys _ipmiCtx) */
	int connect();
	int disconnect();

	/* Open and create/destroy SDR cache (sets/destroys _sdrCtx and _sensorReadCtx) */
	void createSdrCache();
	void destroySdrCache();

	/* Various context structs, required to make use of FreeIPMI */
	ipmi_ctx_t		_ipmiCtx;
	ipmi_sensor_read_ctx_t	_sensorReadCtx;

	std::string	_hostName;
	std::string	_userName;
	std::string	_password;
	std::string	_cache;
	uint8_t		_auth;
	uint8_t		_priv;
	std::string	_mqttPart;
	uint32_t	_sessionTimeout;
	uint32_t	_retransmissionTimeout;
	boost::asio::io_service::strand*	_strand;
	boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
	uint32_t	_errorCount;
87
	std::string _errorMsg;
88
89
	volatile uint64_t	_delayNextReadUntil;
};
90
91

#endif /* IPMIHOST_H_ */