blob: 8b0a393b33e9b6bcc3c3bc38a2c2696585c3ca24 [file] [log] [blame]
Jayashree Dhanapal3746c552022-03-21 14:45:52 +05301#pragma once
2
3#include <sensor.hpp>
4
5using IpmbMethodType =
6 std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>;
7
8enum class SDRType
9{
10 sdrType01 = 1,
11 sdrType02 = 2,
12 sdrType03 = 3
13};
14
15namespace sdr
16{
17// IPMB Commands
18static constexpr uint8_t netfnStorageReq = 0x0a;
19static constexpr uint8_t cmdStorageGetSdrInfo = 0x20;
20static constexpr uint8_t cmdStorageReserveSdr = 0x22;
21static constexpr uint8_t cmdStorageGetSdr = 0x23;
22
23// Get SDR Commands
24static constexpr uint8_t sdrNxtRecLSB = 0;
25static constexpr uint8_t sdrNxtRecMSB = 1;
26static constexpr uint8_t perCountByte = 16;
27
28// Sensor Record Bytes
29static constexpr uint8_t sdrType = 5;
30static constexpr uint8_t dataLengthByte = 6;
31static constexpr uint8_t sdrSensorNum = 9;
32
33} // namespace sdr
34
35namespace sdrtype01
36{
37// Negative Handle Commands
38static constexpr uint8_t maxPosReadingMargin = 127;
39static constexpr uint8_t twosCompVal = 128;
40static constexpr double thermalConst = 256;
41
42static constexpr uint8_t sdrSensNoThres = 0;
43static constexpr uint8_t sensorCapability = 13;
44static constexpr uint8_t sdrNegHandle = 24;
45static constexpr uint8_t sdrUnitType = 25;
46static constexpr uint8_t sdrLinearByte = 27;
47
48// SDR Type 1 Thresholds Commands
49static constexpr uint8_t mDataByte = 28;
50static constexpr uint8_t mTolDataByte = 29;
51static constexpr uint8_t bDataByte = 30;
52static constexpr uint8_t bAcuDataByte = 31;
53static constexpr uint8_t rbExpDataByte = 33;
54static constexpr uint8_t upperCriticalThreshold = 43;
55static constexpr uint8_t lowerCriticalThreshold = 46;
56static constexpr uint8_t nameLengthByte = 53;
57
58} // namespace sdrtype01
59
60struct SensorInfo
61{
62 std::string sensorReadName;
63 uint8_t sensorUnit = 0;
64 double thresUpperCri = 0;
65 double thresLowerCri = 0;
66 uint8_t sensorNumber = 0;
67 uint8_t sensCap = 0;
68};
69
70struct SensorValConversion
71{
72 uint16_t mValue = 0;
73 double bValue = 0;
74 double expoVal = 0;
75 uint8_t negRead = 0;
76};
77
78inline std::map<int, std::vector<SensorInfo>> sensorRecord;
79inline std::map<int, std::map<uint8_t, SensorValConversion>> sensorValRecord;
80
81class IpmbSDRDevice : public std::enable_shared_from_this<IpmbSDRDevice>
82{
83 public:
84 IpmbSDRDevice(std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
85 uint8_t cmdAddr);
86
87 uint8_t commandAddress = 0;
88 int hostIndex = 0;
89
90 std::shared_ptr<sdbusplus::asio::connection> conn;
91
92 std::vector<uint8_t> sdrData;
93 uint16_t validRecordCount = 1;
94 uint8_t iCnt = 0;
95 uint8_t nextRecordIDLSB = 0;
96 uint8_t nextRecordIDMSB = 0;
97
Ed Tanous739ab192024-04-03 18:50:37 -070098 std::vector<uint8_t> sdrCommandData;
Jayashree Dhanapal3746c552022-03-21 14:45:52 +053099
100 void getSDRRepositoryInfo();
101
102 void reserveSDRRepository(uint16_t recordCount);
103
104 void getSDRSensorData(uint16_t recordCount, uint8_t resrvIDLSB,
105 uint8_t resrvIDMSB);
106
107 void handleSDRData(const std::vector<uint8_t>& data, uint16_t recordCount,
108 uint8_t resrvIDLSB, uint8_t resrvIDMSB);
109
110 void checkSDRData(std::vector<uint8_t>& sdrDataBytes,
111 uint8_t dataLength) const;
112
113 static void checkSDRType01Threshold(std::vector<uint8_t>& sdrDataBytes,
114 int busIndex, std::string tempName);
115
116 inline static double sensorValCalculation(uint16_t mValue, double bValue,
117 double expValue, double value);
118};