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 | |
Tomáš Pecka | 4b98876 | 2020-12-03 08:38:49 +0100 | [diff] [blame] | 23 | /* FIXME: |
| 24 | * Publish more properties for ne element. We have an EEPROM at the PCB for storing serial numbers (etc.), but it's so far unused. We could also use U-Boot env variables |
| 25 | * This will be needed for sdn-roadm-line only. So we should also parse the model from /proc/cmdline here |
| 26 | */ |
| 27 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::StaticData("ne", std::nullopt, {{"description", "Czechlight project"s}})); |
| 28 | |
Tomáš Pecka | d03044f | 2020-11-12 14:33:10 +0100 | [diff] [blame] | 29 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::StaticData("ne:ctrl", "ne", {{"class", "iana-hardware:module"}})); |
| 30 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::Fans("ne:fans", "ne", hwmonFans, 4)); |
| 31 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-front", "ne:ctrl", sysfsTempFront, 1)); |
| 32 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-cpu", "ne:ctrl", sysfsTempCpu, 1)); |
| 33 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-internal-0", "ne:ctrl", sysfsTempMII0, 1)); |
| 34 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-internal-1", "ne:ctrl", sysfsTempMII1, 1)); |
| 35 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::EMMC("ne:ctrl:emmc", "ne:ctrl", emmc)); |
| 36 | } else { |
| 37 | throw std::runtime_error("Unknown appliance '" + applianceName + "'"); |
| 38 | } |
| 39 | |
| 40 | return ietfHardware; |
| 41 | } |
| 42 | |
| 43 | } |
| 44 | |
| 45 | namespace velia::health { |
| 46 | boost::signals2::SlotWrapper<void, health::State> createOutput(const std::string& applianceName) |
| 47 | { |
| 48 | if (applianceName == "czechlight-clearfog") { |
| 49 | return boost::signals2::SlotWrapper<void, State>(std::make_shared<LedOutputCallback>( |
| 50 | std::make_shared<LedSysfsDriver>("/sys/class/leds/status:red/"), |
| 51 | std::make_shared<LedSysfsDriver>("/sys/class/leds/status:green/"), |
| 52 | std::make_shared<LedSysfsDriver>("/sys/class/leds/status:blue/"))); |
| 53 | } else { |
| 54 | throw std::runtime_error("Unknown appliance '" + applianceName + "'"); |
| 55 | } |
| 56 | } |
| 57 | } |