| #include "tlbmc/hal/fru_scanner_adc.h" |
| |
| #include <cstdint> |
| #include <memory> |
| #include <string> |
| #include <utility> |
| #include <vector> |
| |
| #include "bus_topology.pb.h" |
| #include "absl/log/log.h" |
| #include "absl/memory/memory.h" |
| #include "absl/status/statusor.h" |
| #include "absl/strings/str_cat.h" |
| #include "tlbmc/hal/fru_scanner.h" |
| #include "tlbmc/hal/shared_mem/static_server_impl.h" |
| #include "status.pb.h" |
| |
| namespace milotic_tlbmc { |
| |
| PresenceStatus FruScannerAdc::GetAdcFruPresenceStatus(const std::string& name) { |
| // Use short-term workaround(shared_mem) to get the adc fru info. |
| absl::StatusOr<std::pair<float, uint64_t>> sensor_reading = |
| StaticSharedMemoryServer::GetInstance().ReadSensorValue( |
| absl::StrCat("sharedmem_", name, "_status")); |
| if (!sensor_reading.ok()) { |
| LOG(WARNING) << "Failed to read sensor value for " << name << ": " |
| << sensor_reading.status(); |
| // If the sensor value is not available, return NOT_SCANNED. |
| return PresenceStatus::PRESENCE_STATUS_NOT_SCANNED; |
| } |
| |
| if (sensor_reading->first == 0.0f) { |
| return PresenceStatus::PRESENCE_STATUS_NOT_FOUND; |
| } |
| return PresenceStatus::PRESENCE_STATUS_PRESENT; |
| } |
| |
| absl::StatusOr<std::vector<std::unique_ptr<AdcFruInfo>>> |
| FruScannerAdc::ScanAllAdcFrus() const { |
| std::vector<std::unique_ptr<AdcFruInfo>> adc_frus; |
| for (const auto& component : adc_components_) { |
| auto adc_fru = std::make_unique<AdcFruInfo>(); |
| adc_fru->presence_status = GetAdcFruPresenceStatus(component.plugin_id()); |
| adc_fru->expected_barepath = component.barepath(); |
| adc_frus.push_back(std::move(adc_fru)); |
| } |
| return adc_frus; |
| } |
| |
| std::unique_ptr<FruScannerAdc> FruScannerAdc::Create(const Options& options) { |
| std::vector<uhmm::BmcMonitoredComponentsResponse::MonitoredComponent> |
| adc_components; |
| for (const auto& component : options.components) { |
| // Only ADC components are supported by FruScannerAdc as of now. |
| if (component.probe_path() != uhmm::BmcMonitoredComponentsResponse:: |
| MonitoredComponent::PROBE_PATH_ADC) { |
| LOG(WARNING) << "FruScannerAdc::Create: Skipping non-ADC component: " |
| << component.barepath(); |
| continue; |
| } |
| adc_components.push_back(component); |
| } |
| |
| return absl::WrapUnique(new FruScannerAdc(std::move(adc_components))); |
| } |
| |
| FruScannerAdc::FruScannerAdc( |
| std::vector<uhmm::BmcMonitoredComponentsResponse::MonitoredComponent> |
| components) |
| : adc_components_(std::move(components)) {} |
| |
| } // namespace milotic_tlbmc |