#include "gpio_handle.hpp" #include #include #include #include #include #include namespace gpio { using namespace phosphor::logging; std::unique_ptr BuildGpioHandle(const std::string& gpiochip, const std::string& line) { char *gpioEnd, *lineEnd; unsigned long chipId = std::strtoul(gpiochip.c_str(), &gpioEnd, 10); unsigned long lineOffset = std::strtoul(line.c_str(), &lineEnd, 10); if (!gpioEnd || gpioEnd != &gpiochip.c_str()[gpiochip.length()]) { log("Unable to handle giochip entry", entry("GPIOCHIP=%s", gpiochip.c_str())); return nullptr; } if (!lineEnd || lineEnd != &line.c_str()[line.length()]) { log("Unable to handle line entry", entry("LINE=%s", line.c_str())); return nullptr; } try { gpioplus::Chip chip(chipId); gpioplus::HandleFlags flags(chip.getLineInfo(lineOffset).flags); flags.output = true; std::vector lines = { {static_cast(lineOffset), 0}}; return std::make_unique(chip, lines, flags, "phosphor-hwmon"); } catch (const std::exception& e) { log("Unable to set up GPIO handle", entry("ERROR=%s", e.what())); return nullptr; } } } // namespace gpio