Tomáš Pecka | d03044f | 2020-11-12 14:33:10 +0100 | [diff] [blame^] | 1 | #include "Factory.h" |
| 2 | #include "health/outputs/LedSysfsDriver.h" |
| 3 | #include "health/outputs/SlotWrapper.h" |
| 4 | #include "health/outputs/callables.h" |
| 5 | #include "ietf-hardware/IETFHardware.h" |
| 6 | #include "ietf-hardware/sysfs/EMMC.h" |
| 7 | #include "ietf-hardware/sysfs/HWMon.h" |
| 8 | |
| 9 | namespace velia::ietf_hardware { |
| 10 | |
| 11 | std::shared_ptr<IETFHardware> create(const std::string& applianceName) |
| 12 | { |
| 13 | auto ietfHardware = std::make_shared<velia::ietf_hardware::IETFHardware>(); |
| 14 | |
| 15 | if (applianceName == "czechlight-clearfog") { |
| 16 | auto hwmonFans = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/bus/i2c/devices/1-002e/hwmon/"); |
| 17 | auto sysfsTempFront = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/devices/platform/soc/soc:internal-regs/f1011100.i2c/i2c-1/1-002e/hwmon/"); |
| 18 | auto sysfsTempCpu = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/devices/virtual/thermal/thermal_zone0/"); |
| 19 | auto sysfsTempMII0 = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/devices/platform/soc/soc:internal-regs/f1072004.mdio/mdio_bus/f1072004.mdio-mii/f1072004.mdio-mii:00/hwmon/"); |
| 20 | auto sysfsTempMII1 = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/devices/platform/soc/soc:internal-regs/f1072004.mdio/mdio_bus/f1072004.mdio-mii/f1072004.mdio-mii:01/hwmon/"); |
| 21 | auto emmc = std::make_shared<velia::ietf_hardware::sysfs::EMMC>("/sys/block/mmcblk0/device/"); |
| 22 | |
| 23 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::StaticData("ne", std::nullopt, {{"class", "iana-hardware:chassis"}, {"mfg-name", "CESNET"s}})); // FIXME: We have an EEPROM at the PCB for storing these information, but it's so far unused. We could also use U-Boot env variables for this. |
| 24 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::StaticData("ne:ctrl", "ne", {{"class", "iana-hardware:module"}})); |
| 25 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::Fans("ne:fans", "ne", hwmonFans, 4)); |
| 26 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-front", "ne:ctrl", sysfsTempFront, 1)); |
| 27 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-cpu", "ne:ctrl", sysfsTempCpu, 1)); |
| 28 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-internal-0", "ne:ctrl", sysfsTempMII0, 1)); |
| 29 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-internal-1", "ne:ctrl", sysfsTempMII1, 1)); |
| 30 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::EMMC("ne:ctrl:emmc", "ne:ctrl", emmc)); |
| 31 | } else { |
| 32 | throw std::runtime_error("Unknown appliance '" + applianceName + "'"); |
| 33 | } |
| 34 | |
| 35 | return ietfHardware; |
| 36 | } |
| 37 | |
| 38 | } |
| 39 | |
| 40 | namespace velia::health { |
| 41 | boost::signals2::SlotWrapper<void, health::State> createOutput(const std::string& applianceName) |
| 42 | { |
| 43 | if (applianceName == "czechlight-clearfog") { |
| 44 | return boost::signals2::SlotWrapper<void, State>(std::make_shared<LedOutputCallback>( |
| 45 | std::make_shared<LedSysfsDriver>("/sys/class/leds/status:red/"), |
| 46 | std::make_shared<LedSysfsDriver>("/sys/class/leds/status:green/"), |
| 47 | std::make_shared<LedSysfsDriver>("/sys/class/leds/status:blue/"))); |
| 48 | } else { |
| 49 | throw std::runtime_error("Unknown appliance '" + applianceName + "'"); |
| 50 | } |
| 51 | } |
| 52 | } |