IPMISensorBase.h 2.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
 * IPMISensorBase.h
 *
 *  Created on: 13.08.2018
 *      Author: Micha Mueller
 */

#ifndef SRC_SENSORS_IPMI_IPMISENSORBASE_H_
#define SRC_SENSORS_IPMI_IPMISENSORBASE_H_

11
#include "sensorbase.h"
12
13
14
15
16
17

#include "IPMIHost.h"

#include <boost/tokenizer.hpp>
#include <boost/regex.hpp>
#include <vector>
Micha Mueller's avatar
Micha Mueller committed
18
#include <sstream>
19

20
class IPMISensorBase: public SensorBase {
21
22
23
24
25
public:
	IPMISensorBase(const std::string& name) :
		SensorBase(name),
		_recordId(0),
		_factor(1),
26
27
		_lsb(0),
		_msb(0) {}
28

29
30
31
32
33
	IPMISensorBase(const IPMISensorBase& other) : SensorBase(other),
	    _recordId(other._recordId),
	    _sdrRecord(other._sdrRecord),
	    _factor(other._factor),
	    _rawCmd(other._rawCmd),
34
35
	    _lsb(other._lsb),
	    _msb(other._msb) {}
36
37
38
39
40
41
42
43
44

	virtual ~IPMISensorBase() {}

	IPMISensorBase& operator=(const IPMISensorBase& other) {
	  SensorBase::operator=(other);
	  _recordId = other._recordId;
	  _sdrRecord = other._sdrRecord;
	  _factor = other._factor;
	  _rawCmd = other._rawCmd;
45
46
	  _lsb = other._lsb;
	  _msb = other._msb;
47
48

	  return *this;
49
50
51
	}

	uint16_t	getRecordId()	const { return _recordId; }
52
	const 		std::vector<uint8_t>& getSdrRecord() const { return _sdrRecord; }
53
54
	double		getFactor()		const { return _factor; }
	const		std::vector<uint8_t>& getRawCmd() const { return _rawCmd; }
Micha Mueller's avatar
Micha Mueller committed
55
56
57
58
59
60
61
62
	std::string getRawCmdString() const {
	  std::stringstream ss;
	  ss << "0x";
	  for (auto i : _rawCmd) {
	    ss << std::hex << i;
	  }
	  return ss.str();
	}
63
64
	uint8_t		getLsb()		const { return _lsb; }
	uint8_t		getMsb()		const { return _msb; }
65

66
	void setRecordId(const std::string& recordId)	{ _recordId = stoul(recordId);	}
67
    void setSdrRecord(const std::vector<uint8_t>& sdrRecord) { _sdrRecord = sdrRecord; }
68
	void setFactor(const std::string& factor)		{ _factor = stod(factor); }
69
70
71
72
73
74
75
76
	void setRawCmd(std::string& rawCmd) {
		boost::regex expr("(?:0x)?([0-9a-fA-F]+)");
		boost::regex_token_iterator<std::string::iterator> it { rawCmd.begin(),	rawCmd.end(), expr, 1 };
		boost::regex_token_iterator<std::string::iterator> end;
		while (it != end) {
			_rawCmd.push_back(stoi(*it++, NULL, 16));
		}
	}
77
78
79
80
	void setLsb(const std::string& lsb)		{ _lsb = stoi(lsb); }
	void setLsb(uint8_t lsb)		{ _lsb = lsb; }
	void setMsb(const std::string& msb)		{ _msb = stoi(msb); }
	void setMsb(uint8_t msb)		{ _msb = msb; }
81

82
83
84
85
86
87
88
	void printConfig(LOG_LEVEL ll, LOGGER& lg, unsigned leadingSpaces=16) {
		std::string leading(leadingSpaces, ' ');
        LOG_VAR(ll) << leading << "    Record Id:  " <<  _recordId;
        LOG_VAR(ll) << leading << "    Factor:     " << _factor;
        LOG_VAR(ll) << leading << "    Raw Cmd:    " << getRawCmdString();
        LOG_VAR(ll) << leading << "    lsb: " << _lsb;
        LOG_VAR(ll) << leading << "    msb: " << _msb;
Micha Mueller's avatar
Micha Mueller committed
89
90
    }

91
92
protected:
	uint16_t _recordId;
93
	std::vector<uint8_t> _sdrRecord;
94
95
96
	double _factor;

	std::vector<uint8_t> _rawCmd;
97
98
	uint8_t _lsb;
	uint8_t _msb;
99
100
101
};

#endif /* SRC_SENSORS_IPMI_IPMISENSORBASE_H_ */