Tomáš Pecka | d03044f | 2020-11-12 14:33:10 +0100 | [diff] [blame] | 1 | #include "Factory.h" |
Tomáš Pecka | d03044f | 2020-11-12 14:33:10 +0100 | [diff] [blame] | 2 | #include "ietf-hardware/IETFHardware.h" |
| 3 | #include "ietf-hardware/sysfs/EMMC.h" |
| 4 | #include "ietf-hardware/sysfs/HWMon.h" |
| 5 | |
| 6 | namespace velia::ietf_hardware { |
| 7 | |
| 8 | std::shared_ptr<IETFHardware> create(const std::string& applianceName) |
| 9 | { |
| 10 | auto ietfHardware = std::make_shared<velia::ietf_hardware::IETFHardware>(); |
| 11 | |
| 12 | if (applianceName == "czechlight-clearfog") { |
| 13 | auto hwmonFans = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/bus/i2c/devices/1-002e/hwmon/"); |
| 14 | auto sysfsTempFront = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/devices/platform/soc/soc:internal-regs/f1011100.i2c/i2c-1/1-002e/hwmon/"); |
| 15 | auto sysfsTempCpu = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/devices/virtual/thermal/thermal_zone0/"); |
| 16 | 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/"); |
| 17 | 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/"); |
| 18 | auto emmc = std::make_shared<velia::ietf_hardware::sysfs::EMMC>("/sys/block/mmcblk0/device/"); |
| 19 | |
Tomáš Pecka | 4b98876 | 2020-12-03 08:38:49 +0100 | [diff] [blame] | 20 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::StaticData("ne", std::nullopt, {{"description", "Czechlight project"s}})); |
| 21 | |
Tomáš Pecka | d03044f | 2020-11-12 14:33:10 +0100 | [diff] [blame] | 22 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::StaticData("ne:ctrl", "ne", {{"class", "iana-hardware:module"}})); |
| 23 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::Fans("ne:fans", "ne", hwmonFans, 4)); |
| 24 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-front", "ne:ctrl", sysfsTempFront, 1)); |
| 25 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-cpu", "ne:ctrl", sysfsTempCpu, 1)); |
| 26 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-internal-0", "ne:ctrl", sysfsTempMII0, 1)); |
| 27 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-internal-1", "ne:ctrl", sysfsTempMII1, 1)); |
| 28 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::EMMC("ne:ctrl:emmc", "ne:ctrl", emmc)); |
Jan Kundrát | 0163815 | 2021-02-05 19:13:25 +0100 | [diff] [blame^] | 29 | } else if (applianceName == "czechlight-clearfog-g2") { |
| 30 | auto fans = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/bus/i2c/devices/1-0020/hwmon/"); |
| 31 | auto tempMainBoard = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/bus/i2c/devices/1-0048/hwmon/"); |
| 32 | auto tempFans = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/bus/i2c/devices/1-0049/hwmon/"); |
| 33 | auto tempCpu = std::make_shared<velia::ietf_hardware::sysfs::HWMon>("/sys/devices/virtual/thermal/thermal_zone0/"); |
| 34 | auto tempMII0 = 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/"); |
| 35 | auto tempMII1 = 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/"); |
| 36 | auto emmc = std::make_shared<velia::ietf_hardware::sysfs::EMMC>("/sys/block/mmcblk0/device/"); |
| 37 | |
| 38 | /* FIXME: |
| 39 | * 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 |
| 40 | * This will be needed for sdn-roadm-line only. So we should also parse the model from /proc/cmdline here |
| 41 | */ |
| 42 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::StaticData("ne", std::nullopt, {{"description", "Czechlight project"s}})); |
| 43 | |
| 44 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::StaticData("ne:ctrl", "ne", {{"class", "iana-hardware:module"}})); |
| 45 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::Fans("ne:fans", "ne", fans, 4)); |
| 46 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-front", "ne:ctrl", tempMainBoard, 1)); |
| 47 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-cpu", "ne:ctrl", tempCpu, 1)); |
| 48 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-rear", "ne:ctrl", tempFans, 1)); |
| 49 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-internal-0", "ne:ctrl", tempMII0, 1)); |
| 50 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-internal-1", "ne:ctrl", tempMII1, 1)); |
| 51 | ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::EMMC("ne:ctrl:emmc", "ne:ctrl", emmc)); |
Tomáš Pecka | d03044f | 2020-11-12 14:33:10 +0100 | [diff] [blame] | 52 | } else { |
| 53 | throw std::runtime_error("Unknown appliance '" + applianceName + "'"); |
| 54 | } |
| 55 | |
| 56 | return ietfHardware; |
| 57 | } |
| 58 | |
| 59 | } |