James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | #include "sensor.hpp" |
| 3 | |
| 4 | #include <boost/asio/deadline_timer.hpp> |
| 5 | #include <boost/container/flat_map.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 6 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 7 | #include <chrono> |
| 8 | #include <limits> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 9 | #include <memory> |
| 10 | #include <optional> |
| 11 | #include <string> |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
| 14 | enum class IpmbType |
| 15 | { |
| 16 | meSensor, |
| 17 | PXE1410CVR, |
| 18 | IR38363VR, |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 19 | ADM1278HSC, |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 20 | mpsVR |
| 21 | }; |
| 22 | |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 23 | enum class IpmbSubType |
| 24 | { |
| 25 | temp, |
| 26 | curr, |
| 27 | power, |
Adrian Ambrożewicz | 45e9277 | 2020-06-04 13:59:55 +0200 | [diff] [blame] | 28 | volt, |
| 29 | util |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame^] | 32 | enum class ReadingFormat |
| 33 | { |
| 34 | byte0, |
| 35 | byte3, |
| 36 | elevenBit, |
| 37 | elevenBitShift, |
| 38 | }; |
| 39 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 40 | struct IpmbSensor : public Sensor |
| 41 | { |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 42 | IpmbSensor(std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 43 | boost::asio::io_service& io, const std::string& name, |
| 44 | const std::string& sensorConfiguration, |
| 45 | sdbusplus::asio::object_server& objectServer, |
| 46 | std::vector<thresholds::Threshold>&& thresholds, |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 47 | uint8_t deviceAddress, std::string& sensorTypeName); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 48 | ~IpmbSensor(); |
| 49 | |
| 50 | void checkThresholds(void) override; |
| 51 | void read(void); |
| 52 | void init(void); |
| 53 | void loadDefaults(void); |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 54 | void runInitCmd(void); |
James Feist | 551087a | 2019-12-09 11:17:12 -0800 | [diff] [blame] | 55 | void processError(void); |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame^] | 56 | double processReading(const std::vector<uint8_t>& data); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 57 | |
| 58 | IpmbType type; |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 59 | IpmbSubType subType; |
| 60 | double scaleVal; |
| 61 | double offsetVal; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 62 | uint8_t commandAddress; |
| 63 | uint8_t netfn; |
| 64 | uint8_t command; |
| 65 | uint8_t deviceAddress; |
James Feist | 551087a | 2019-12-09 11:17:12 -0800 | [diff] [blame] | 66 | uint8_t errorCount; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 67 | std::vector<uint8_t> commandData; |
| 68 | std::optional<uint8_t> initCommand; |
| 69 | std::vector<uint8_t> initData; |
| 70 | |
| 71 | // to date all ipmb sensors are power on only |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 72 | PowerState readState; |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame^] | 73 | ReadingFormat readingFormat; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 74 | |
| 75 | private: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 76 | sdbusplus::asio::object_server& objectServer; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 77 | std::shared_ptr<sdbusplus::asio::connection> dbusConnection; |
| 78 | boost::asio::deadline_timer waitTimer; |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 79 | }; |