1 #pragma once 2 3 #include <sensor.hpp> 4 5 using IpmbMethodType = 6 std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>; 7 8 enum class SDRType 9 { 10 sdrType01 = 1, 11 sdrType02 = 2, 12 sdrType03 = 3 13 }; 14 15 namespace sdr 16 { 17 // IPMB Commands 18 static constexpr uint8_t netfnStorageReq = 0x0a; 19 static constexpr uint8_t cmdStorageGetSdrInfo = 0x20; 20 static constexpr uint8_t cmdStorageReserveSdr = 0x22; 21 static constexpr uint8_t cmdStorageGetSdr = 0x23; 22 23 // Get SDR Commands 24 static constexpr uint8_t sdrNxtRecLSB = 0; 25 static constexpr uint8_t sdrNxtRecMSB = 1; 26 static constexpr uint8_t perCountByte = 16; 27 28 // Sensor Record Bytes 29 static constexpr uint8_t sdrType = 5; 30 static constexpr uint8_t dataLengthByte = 6; 31 static constexpr uint8_t sdrSensorNum = 9; 32 33 } // namespace sdr 34 35 namespace sdrtype01 36 { 37 // Negative Handle Commands 38 static constexpr uint8_t maxPosReadingMargin = 127; 39 static constexpr uint8_t twosCompVal = 128; 40 static constexpr double thermalConst = 256; 41 42 static constexpr uint8_t sdrSensNoThres = 0; 43 static constexpr uint8_t sensorCapability = 13; 44 static constexpr uint8_t sdrNegHandle = 24; 45 static constexpr uint8_t sdrUnitType = 25; 46 static constexpr uint8_t sdrLinearByte = 27; 47 48 // SDR Type 1 Thresholds Commands 49 static constexpr uint8_t mDataByte = 28; 50 static constexpr uint8_t mTolDataByte = 29; 51 static constexpr uint8_t bDataByte = 30; 52 static constexpr uint8_t bAcuDataByte = 31; 53 static constexpr uint8_t rbExpDataByte = 33; 54 static constexpr uint8_t upperCriticalThreshold = 43; 55 static constexpr uint8_t lowerCriticalThreshold = 46; 56 static constexpr uint8_t nameLengthByte = 53; 57 58 } // namespace sdrtype01 59 60 struct 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 70 struct SensorValConversion 71 { 72 uint16_t mValue = 0; 73 double bValue = 0; 74 double expoVal = 0; 75 uint8_t negRead = 0; 76 }; 77 78 inline std::map<int, std::vector<SensorInfo>> sensorRecord; 79 inline std::map<int, std::map<uint8_t, SensorValConversion>> sensorValRecord; 80 81 class 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 98 std::vector<uint8_t> sdrCommandData; 99 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 }; 119