blob: a209230e285fd9e541eaaf3127242063fea9c73c [file] [log] [blame]
#include "utility.hpp"
#include <nlohmann/json.hpp>
#include <phosphor-logging/log.hpp>
#include <algorithm>
#include <fstream>
using json = nlohmann::json;
using namespace phosphor::logging;
using namespace utility;
constexpr auto gpioDefsFile = "/etc/default/obmc/gpio/gpio_defs.json";
int main(void)
{
std::ifstream gpioDefsStream(gpioDefsFile);
if (!gpioDefsStream.is_open())
{
log<level::ERR>("Error opening gpio definitions file",
entry("FILE=%s", gpioDefsFile));
return 1;
}
auto data = json::parse(gpioDefsStream, nullptr, false);
if (data.is_discarded())
{
log<level::ERR>("Error parsing gpio definitions file",
entry("FILE=%s", gpioDefsFile));
return 1;
}
// To determine what pins are needed to deassert, look in the
// gpioDefsFile for the defined "power_up_outs" under
// gpio_configs->power_config. Then match the name up with
// its definition in "gpio_definitions" to determine the pin id's.
auto gpios = data["gpio_configs"]["power_config"]["power_up_outs"];
if (gpios.size() <= 0)
{
log<level::ERR>("Could not find power_up_outs defs",
entry("FILE=%s", gpioDefsFile));
return 1;
}
auto defs = data["gpio_definitions"];
for (const auto& gpio : gpios)
{
auto gpioEntry =
std::find_if(defs.begin(), defs.end(), [&gpio](const auto& g) {
return g["name"] == gpio["name"];
});
if (gpioEntry != defs.end())
{
std::string pin = (*gpioEntry)["pin"];
bool activeLow = gpio["polarity"];
if (!gpioSetValue(pin, !activeLow, false))
{
log<level::ERR>("chassiskill::gpioSetValue() failed",
entry("PIN=%s", pin.c_str()));
return 1;
}
else
{
log<level::INFO>("'chassiskill' operation complete",
entry("PIN=%s", pin.c_str()));
}
}
}
return 0;
}