blob: 27b9952208d889c758ae29eb9f7a5f1d3081948c [file] [log] [blame]
Václav Kubernát97e5ea12021-03-24 00:36:57 +01001#include <atomic>
2#include <condition_variable>
3#include <mutex>
4#include <thread>
5#include "IETFHardware.h"
6#include "ietf-hardware/sysfs/HWMon.h"
7
8namespace velia::ietf_hardware {
9class TransientI2C {
10public:
11 TransientI2C(const uint8_t bus, const uint8_t address, const std::string& driverName);
12 virtual ~TransientI2C();
13 virtual bool isPresent() const;
14 virtual void bind() const;
15 virtual void unbind() const;
16private:
17 uint8_t m_address;
18 std::string m_driverName;
19 std::string m_isPresentPath;
20 std::string m_bindPath;
21 std::string m_unbindPath;
22 std::string m_addressString;
23};
24
25/**
26 * This class manages two things:
27 * 1) dynamic loading/unloading of the driver for the PSUs
28 * 2) reading of hwmon values for the PSUs
29 */
30struct FspYhPsu {
31public:
32 FspYhPsu(const std::filesystem::path& hwmonDir, const std::string& psuName, std::shared_ptr<TransientI2C> i2c);
33 ~FspYhPsu();
34 velia::ietf_hardware::DataTree readValues();
35private:
36 std::mutex m_mtx;
37 std::mutex m_condMtx;
38 std::condition_variable m_cond;
39 std::thread m_psuWatcher;
40 std::atomic<bool> m_exit;
41 std::shared_ptr<TransientI2C> m_i2c;
42
43 std::filesystem::path m_hwmonDir;
44 std::string m_psuName;
45
46 std::shared_ptr<velia::ietf_hardware::sysfs::HWMon> m_hwmon;
Tomáš Pecka23536bf2023-04-27 18:30:55 +020047
48 std::string m_namePrefix;
49 velia::ietf_hardware::DataTree m_staticData;
Václav Kubernát97e5ea12021-03-24 00:36:57 +010050 std::vector<std::function<velia::ietf_hardware::DataTree()>> m_properties;
51
52 void createPower();
53};
54}