Start using .clang-format
Used the one from docs/style/cpp.
Change-Id: I3bdc2b353bf18a437266b362d8205b8463a9ce2b
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/power-supply/argument.cpp b/power-supply/argument.cpp
index a275c6a..342515c 100644
--- a/power-supply/argument.cpp
+++ b/power-supply/argument.cpp
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <iostream>
-#include <iterator>
+#include "argument.hpp"
+
#include <algorithm>
#include <cassert>
-#include "argument.hpp"
+#include <iostream>
+#include <iterator>
namespace witherspoon
{
@@ -81,16 +82,15 @@
std::cerr << std::flush;
}
-const option ArgumentParser::options[] =
-{
- { "path", required_argument, NULL, 'p' },
- { "instance", required_argument, NULL, 'n' },
- { "inventory", required_argument, NULL, 'i' },
- { "num-history-records", required_argument, NULL, 'r' },
- { "sync-gpio-path", required_argument, NULL, 'a' },
- { "sync-gpio-num", required_argument, NULL, 'u' },
- { "help", no_argument, NULL, 'h' },
- { 0, 0, 0, 0},
+const option ArgumentParser::options[] = {
+ {"path", required_argument, NULL, 'p'},
+ {"instance", required_argument, NULL, 'n'},
+ {"inventory", required_argument, NULL, 'i'},
+ {"num-history-records", required_argument, NULL, 'r'},
+ {"sync-gpio-path", required_argument, NULL, 'a'},
+ {"sync-gpio-num", required_argument, NULL, 'u'},
+ {"help", no_argument, NULL, 'h'},
+ {0, 0, 0, 0},
};
const char* ArgumentParser::optionStr = "p:n:i:r:a:u:h";
@@ -98,5 +98,5 @@
const std::string ArgumentParser::trueString = "true";
const std::string ArgumentParser::emptyString = "";
-}
-}
+} // namespace power
+} // namespace witherspoon
diff --git a/power-supply/average.hpp b/power-supply/average.hpp
index 817f0bf..a61a436 100644
--- a/power-supply/average.hpp
+++ b/power-supply/average.hpp
@@ -12,8 +12,8 @@
template <typename T>
using ServerObject = typename sdbusplus::server::object::object<T>;
-using AverageInterface = sdbusplus::org::open_power::
- Sensor::Aggregation::History::server::Average;
+using AverageInterface =
+ sdbusplus::org::open_power::Sensor::Aggregation::History::server::Average;
/**
* @class Average
@@ -25,33 +25,30 @@
*/
class Average : public ServerObject<AverageInterface>
{
- public:
+ public:
+ static constexpr auto name = "average";
- static constexpr auto name = "average";
+ Average() = delete;
+ Average(const Average&) = delete;
+ Average& operator=(const Average&) = delete;
+ Average(Average&&) = delete;
+ Average& operator=(Average&&) = delete;
+ ~Average() = default;
- Average() = delete;
- Average(const Average&) = delete;
- Average& operator=(const Average&) = delete;
- Average(Average&&) = delete;
- Average& operator=(Average&&) = delete;
- ~Average() = default;
-
- /**
- * @brief Constructor
- *
- * @param[in] bus - D-Bus object
- * @param[in] objectPath - the D-Bus object path
- */
- Average(sdbusplus::bus::bus& bus,
- const std::string& objectPath) :
- ServerObject<AverageInterface>(bus, objectPath.c_str())
- {
- unit(Average::Unit::Watts);
- scale(0);
- }
+ /**
+ * @brief Constructor
+ *
+ * @param[in] bus - D-Bus object
+ * @param[in] objectPath - the D-Bus object path
+ */
+ Average(sdbusplus::bus::bus& bus, const std::string& objectPath) :
+ ServerObject<AverageInterface>(bus, objectPath.c_str())
+ {
+ unit(Average::Unit::Watts);
+ scale(0);
+ }
};
-
-}
-}
-}
+} // namespace history
+} // namespace power
+} // namespace witherspoon
diff --git a/power-supply/main.cpp b/power-supply/main.cpp
index 62249c5..93b4b77 100644
--- a/power-supply/main.cpp
+++ b/power-supply/main.cpp
@@ -13,13 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "config.h"
+
+#include "argument.hpp"
+#include "device_monitor.hpp"
+#include "power_supply.hpp"
+
#include <iostream>
#include <phosphor-logging/log.hpp>
#include <sdeventplus/event.hpp>
-#include "argument.hpp"
-#include "config.h"
-#include "power_supply.hpp"
-#include "device_monitor.hpp"
using namespace witherspoon::power;
using namespace phosphor::logging;
@@ -78,14 +80,9 @@
// Timer to delay setting internal presence tracking. Allows for servicing
// the power supply.
std::chrono::seconds presentDelay(2);
- auto psuDevice = std::make_unique<psu::PowerSupply>(objname,
- std::move(instance),
- std::move(objpath),
- std::move(invpath),
- bus,
- event,
- powerOnDelay,
- presentDelay);
+ auto psuDevice = std::make_unique<psu::PowerSupply>(
+ objname, std::move(instance), std::move(objpath), std::move(invpath),
+ bus, event, powerOnDelay, presentDelay);
// Get the number of input power history records to keep in D-Bus.
long int numRecords = 0;
@@ -108,9 +105,9 @@
auto syncGPIONum = (options)["sync-gpio-num"];
if (((syncGPIOPath == ArgumentParser::emptyString) &&
- (syncGPIONum != ArgumentParser::emptyString)) ||
+ (syncGPIONum != ArgumentParser::emptyString)) ||
((syncGPIOPath != ArgumentParser::emptyString) &&
- (syncGPIONum == ArgumentParser::emptyString)))
+ (syncGPIONum == ArgumentParser::emptyString)))
{
std::cerr << "Invalid sync GPIO number or path\n";
return -7;
@@ -126,16 +123,13 @@
std::string basePath =
std::string{INPUT_HISTORY_SENSOR_ROOT} + '/' + name;
- psuDevice->enableHistory(basePath,
- numRecords,
- syncGPIOPath,
- gpioNum);
+ psuDevice->enableHistory(basePath, numRecords, syncGPIOPath, gpioNum);
// Systemd object manager
sdbusplus::server::manager::manager objManager{bus, basePath.c_str()};
std::string busName =
- std::string{INPUT_HISTORY_BUSNAME_ROOT} + '.' + name;
+ std::string{INPUT_HISTORY_BUSNAME_ROOT} + '.' + name;
bus.request_name(busName.c_str());
}
diff --git a/power-supply/maximum.hpp b/power-supply/maximum.hpp
index e1fbffc..d952d2b 100644
--- a/power-supply/maximum.hpp
+++ b/power-supply/maximum.hpp
@@ -12,8 +12,8 @@
template <typename T>
using ServerObject = typename sdbusplus::server::object::object<T>;
-using MaximumInterface = sdbusplus::org::open_power::
- Sensor::Aggregation::History::server::Maximum;
+using MaximumInterface =
+ sdbusplus::org::open_power::Sensor::Aggregation::History::server::Maximum;
/**
* @class Maximum
@@ -25,33 +25,30 @@
*/
class Maximum : public ServerObject<MaximumInterface>
{
- public:
+ public:
+ static constexpr auto name = "maximum";
- static constexpr auto name = "maximum";
+ Maximum() = delete;
+ Maximum(const Maximum&) = delete;
+ Maximum& operator=(const Maximum&) = delete;
+ Maximum(Maximum&&) = delete;
+ Maximum& operator=(Maximum&&) = delete;
+ ~Maximum() = default;
- Maximum() = delete;
- Maximum(const Maximum&) = delete;
- Maximum& operator=(const Maximum&) = delete;
- Maximum(Maximum&&) = delete;
- Maximum& operator=(Maximum&&) = delete;
- ~Maximum() = default;
-
- /**
- * @brief Constructor
- *
- * @param[in] bus - D-Bus object
- * @param[in] objectPath - the D-Bus object path
- */
- Maximum(sdbusplus::bus::bus& bus,
- const std::string& objectPath) :
- ServerObject<MaximumInterface>(bus, objectPath.c_str())
- {
- unit(Maximum::Unit::Watts);
- scale(0);
- }
+ /**
+ * @brief Constructor
+ *
+ * @param[in] bus - D-Bus object
+ * @param[in] objectPath - the D-Bus object path
+ */
+ Maximum(sdbusplus::bus::bus& bus, const std::string& objectPath) :
+ ServerObject<MaximumInterface>(bus, objectPath.c_str())
+ {
+ unit(Maximum::Unit::Watts);
+ scale(0);
+ }
};
-
-}
-}
-}
+} // namespace history
+} // namespace power
+} // namespace witherspoon
diff --git a/power-supply/power_supply.cpp b/power-supply/power_supply.cpp
index ff98457..5988ea9 100644
--- a/power-supply/power_supply.cpp
+++ b/power-supply/power_supply.cpp
@@ -13,19 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <functional>
-#include <phosphor-logging/log.hpp>
-#include <phosphor-logging/elog.hpp>
-#include <org/open_power/Witherspoon/Fault/error.hpp>
-#include <xyz/openbmc_project/Common/Device/error.hpp>
-#include <xyz/openbmc_project/Software/Version/server.hpp>
+#include "power_supply.hpp"
+
#include "elog-errors.hpp"
#include "gpio.hpp"
#include "names_values.hpp"
-#include "power_supply.hpp"
#include "pmbus.hpp"
#include "utility.hpp"
+#include <functional>
+#include <org/open_power/Witherspoon/Fault/error.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/log.hpp>
+#include <xyz/openbmc_project/Common/Device/error.hpp>
+#include <xyz/openbmc_project/Software/Version/server.hpp>
+
namespace witherspoon
{
namespace power
@@ -66,42 +68,30 @@
constexpr auto INPUT_HISTORY = "input_history";
PowerSupply::PowerSupply(const std::string& name, size_t inst,
- const std::string& objpath,
- const std::string& invpath,
- sdbusplus::bus::bus& bus,
- const sdeventplus::Event& e,
- std::chrono::seconds& t,
- std::chrono::seconds& p)
- : Device(name, inst), monitorPath(objpath), pmbusIntf(objpath),
- inventoryPath(INVENTORY_OBJ_PATH + invpath), bus(bus),
- presentInterval(p),
- presentTimer(e, std::bind([this]()
- {
- // The hwmon path may have changed.
- pmbusIntf.findHwmonDir();
- this->present = true;
+ const std::string& objpath, const std::string& invpath,
+ sdbusplus::bus::bus& bus, const sdeventplus::Event& e,
+ std::chrono::seconds& t, std::chrono::seconds& p) :
+ Device(name, inst),
+ monitorPath(objpath), pmbusIntf(objpath),
+ inventoryPath(INVENTORY_OBJ_PATH + invpath), bus(bus), presentInterval(p),
+ presentTimer(e, std::bind([this]() {
+ // The hwmon path may have changed.
+ pmbusIntf.findHwmonDir();
+ this->present = true;
- // Sync the INPUT_HISTORY data for all PSs
- syncHistory();
+ // Sync the INPUT_HISTORY data for all PSs
+ syncHistory();
- // Update the inventory for the new device
- updateInventory();
- })),
- powerOnInterval(t),
- powerOnTimer(e, std::bind([this]()
- {
- this->powerOn = true;
- }))
+ // Update the inventory for the new device
+ updateInventory();
+ })),
+ powerOnInterval(t),
+ powerOnTimer(e, std::bind([this]() { this->powerOn = true; }))
{
using namespace sdbusplus::bus;
- presentMatch = std::make_unique<match_t>(bus,
- match::rules::propertiesChanged(
- inventoryPath,
- INVENTORY_IFACE),
- [this](auto& msg)
- {
- this->inventoryChanged(msg);
- });
+ presentMatch = std::make_unique<match_t>(
+ bus, match::rules::propertiesChanged(inventoryPath, INVENTORY_IFACE),
+ [this](auto& msg) { this->inventoryChanged(msg); });
// Get initial presence state.
updatePresence();
@@ -109,14 +99,9 @@
updateInventory();
// Subscribe to power state changes
- powerOnMatch = std::make_unique<match_t>(bus,
- match::rules::propertiesChanged(
- POWER_OBJ_PATH,
- POWER_IFACE),
- [this](auto& msg)
- {
- this->powerStateChanged(msg);
- });
+ powerOnMatch = std::make_unique<match_t>(
+ bus, match::rules::propertiesChanged(POWER_OBJ_PATH, POWER_IFACE),
+ [this](auto& msg) { this->powerStateChanged(msg); });
// Get initial power state.
updatePowerState();
}
@@ -204,7 +189,7 @@
present = false;
presentTimer.setEnabled(false);
- //Clear out the now outdated inventory properties
+ // Clear out the now outdated inventory properties
updateInventory();
}
}
@@ -216,8 +201,8 @@
{
// Use getProperty utility function to get presence status.
std::string service = "xyz.openbmc_project.Inventory.Manager";
- util::getProperty(INVENTORY_IFACE, PRESENT_PROP, inventoryPath,
- service, bus, this->present);
+ util::getProperty(INVENTORY_IFACE, PRESENT_PROP, inventoryPath, service,
+ bus, this->present);
}
void PowerSupply::powerStateChanged(sdbusplus::message::message& msg)
@@ -225,14 +210,15 @@
int32_t state = 0;
std::string msgSensor;
std::map<std::string, sdbusplus::message::variant<int32_t, int32_t>>
- msgData;
+ msgData;
msg.read(msgSensor, msgData);
// Check if it was the Present property that changed.
auto valPropMap = msgData.find("state");
if (valPropMap != msgData.end())
{
- state = sdbusplus::message::variant_ns::get<int32_t>(valPropMap->second);
+ state =
+ sdbusplus::message::variant_ns::get<int32_t>(valPropMap->second);
// Power is on when state=1. Set the fault logged variables to false
// and start the power on timer when the state changes to 1.
@@ -247,7 +233,6 @@
powerOn = false;
}
}
-
}
void PowerSupply::updatePowerState()
@@ -257,17 +242,11 @@
try
{
- auto service = util::getService(POWER_OBJ_PATH,
- POWER_IFACE,
- bus);
+ auto service = util::getService(POWER_OBJ_PATH, POWER_IFACE, bus);
// Use getProperty utility function to get power state.
- util::getProperty<int32_t>(POWER_IFACE,
- "state",
- POWER_OBJ_PATH,
- service,
- bus,
- state);
+ util::getProperty<int32_t>(POWER_IFACE, "state", POWER_OBJ_PATH,
+ service, bus, state);
if (state)
{
@@ -283,7 +262,6 @@
log<level::INFO>("Failed to get power state. Assuming it is off.");
powerOn = false;
}
-
}
void PowerSupply::checkInputFault(const uint16_t statusWord)
@@ -304,8 +282,7 @@
}
else
{
- if ((inputFault > 0) &&
- !(statusWord & status_word::INPUT_FAULT_WARN) &&
+ if ((inputFault > 0) && !(statusWord & status_word::INPUT_FAULT_WARN) &&
!(statusWord & status_word::VIN_UV_FAULT))
{
inputFault = 0;
@@ -344,17 +321,16 @@
nv.add("STATUS_WORD", statusWord);
captureCmd(nv, STATUS_INPUT, Type::Debug);
- using metadata = org::open_power::Witherspoon::Fault::
- PowerSupplyInputFault;
+ using metadata =
+ org::open_power::Witherspoon::Fault::PowerSupplyInputFault;
report<PowerSupplyInputFault>(
- metadata::RAW_STATUS(nv.get().c_str()),
- metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
+ metadata::RAW_STATUS(nv.get().c_str()),
+ metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
faultFound = true;
}
}
-
}
void PowerSupply::checkPGOrUnitOffFault(const uint16_t statusWord)
@@ -392,17 +368,15 @@
captureCmd(nv, STATUS_IOUT, Type::Debug);
captureCmd(nv, STATUS_MFR, Type::Debug);
- using metadata = org::open_power::Witherspoon::Fault::
- PowerSupplyShouldBeOn;
+ using metadata =
+ org::open_power::Witherspoon::Fault::PowerSupplyShouldBeOn;
// A power supply is OFF (or pgood low) but should be on.
report<PowerSupplyShouldBeOn>(
- metadata::RAW_STATUS(nv.get().c_str()),
- metadata::CALLOUT_INVENTORY_PATH(
- inventoryPath.c_str()));
+ metadata::RAW_STATUS(nv.get().c_str()),
+ metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
}
}
-
}
void PowerSupply::checkCurrentOutOverCurrentFault(const uint16_t statusWord)
@@ -435,11 +409,11 @@
captureCmd(nv, STATUS_MFR, Type::Debug);
using metadata = org::open_power::Witherspoon::Fault::
- PowerSupplyOutputOvercurrent;
+ PowerSupplyOutputOvercurrent;
report<PowerSupplyOutputOvercurrent>(
- metadata::RAW_STATUS(nv.get().c_str()),
- metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
+ metadata::RAW_STATUS(nv.get().c_str()),
+ metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
faultFound = true;
}
@@ -476,11 +450,11 @@
captureCmd(nv, STATUS_MFR, Type::Debug);
using metadata = org::open_power::Witherspoon::Fault::
- PowerSupplyOutputOvervoltage;
+ PowerSupplyOutputOvervoltage;
report<PowerSupplyOutputOvervoltage>(
- metadata::RAW_STATUS(nv.get().c_str()),
- metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
+ metadata::RAW_STATUS(nv.get().c_str()),
+ metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
faultFound = true;
}
@@ -514,12 +488,12 @@
captureCmd(nv, STATUS_TEMPERATURE, Type::Debug);
captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
- using metadata = org::open_power::Witherspoon::Fault::
- PowerSupplyFanFault;
+ using metadata =
+ org::open_power::Witherspoon::Fault::PowerSupplyFanFault;
report<PowerSupplyFanFault>(
- metadata::RAW_STATUS(nv.get().c_str()),
- metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
+ metadata::RAW_STATUS(nv.get().c_str()),
+ metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
faultFound = true;
}
@@ -570,11 +544,11 @@
captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
using metadata = org::open_power::Witherspoon::Fault::
- PowerSupplyTemperatureFault;
+ PowerSupplyTemperatureFault;
report<PowerSupplyTemperatureFault>(
- metadata::RAW_STATUS(nv.get().c_str()),
- metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
+ metadata::RAW_STATUS(nv.get().c_str()),
+ metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
faultFound = true;
}
@@ -605,14 +579,12 @@
{
auto path = callout + "/fault";
// Get the service name from the mapper for the fault callout
- auto service = util::getService(path,
- ASSOCIATION_IFACE,
- bus);
+ auto service = util::getService(path, ASSOCIATION_IFACE, bus);
// Use getProperty utility function to get log entries (endpoints)
EndpointList logEntries;
- util::getProperty(ASSOCIATION_IFACE, ENDPOINTS_PROP, path, service,
- bus, logEntries);
+ util::getProperty(ASSOCIATION_IFACE, ENDPOINTS_PROP, path, service, bus,
+ logEntries);
// It is possible that all such entries for this callout have since
// been deleted.
@@ -621,8 +593,8 @@
return;
}
- auto logEntryService = util::getService(logEntries[0], LOGGING_IFACE,
- bus);
+ auto logEntryService =
+ util::getService(logEntries[0], LOGGING_IFACE, bus);
if (logEntryService.empty())
{
return;
@@ -643,9 +615,7 @@
util::setProperty(LOGGING_IFACE, RESOLVED_PROP, logEntry,
logEntryService, bus, resolved);
}
-
}
-
}
catch (std::exception& e)
{
@@ -653,7 +623,6 @@
entry("CALLOUT=%s", callout.c_str()),
entry("ERROR=%s", message.c_str()));
}
-
}
void PowerSupply::updateInventory()
@@ -678,25 +647,33 @@
{
sn = pmbusIntf.readString(SERIAL_NUMBER, Type::HwmonDeviceDebug);
}
- catch (ReadFailure& e) { }
+ catch (ReadFailure& e)
+ {
+ }
try
{
pn = pmbusIntf.readString(PART_NUMBER, Type::HwmonDeviceDebug);
}
- catch (ReadFailure& e) { }
+ catch (ReadFailure& e)
+ {
+ }
try
{
ccin = pmbusIntf.readString(CCIN, Type::HwmonDeviceDebug);
}
- catch (ReadFailure& e) { }
+ catch (ReadFailure& e)
+ {
+ }
try
{
version = pmbusIntf.readString(FW_VERSION, Type::HwmonDeviceDebug);
}
- catch (ReadFailure& e) { }
+ catch (ReadFailure& e)
+ {
+ }
}
// Build the object map and send it to the inventory
@@ -716,18 +693,16 @@
versionProps.emplace(VERSION_PROP, version);
interfaces.emplace(VERSION_IFACE, std::move(versionProps));
- //For Notify(), just send the relative path of the inventory
- //object so remove the INVENTORY_OBJ_PATH prefix
+ // For Notify(), just send the relative path of the inventory
+ // object so remove the INVENTORY_OBJ_PATH prefix
auto path = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH));
object.emplace(path, std::move(interfaces));
try
{
- auto service = util::getService(
- INVENTORY_OBJ_PATH,
- INVENTORY_MGR_IFACE,
- bus);
+ auto service =
+ util::getService(INVENTORY_OBJ_PATH, INVENTORY_MGR_IFACE, bus);
if (service.empty())
{
@@ -735,11 +710,8 @@
return;
}
- auto method = bus.new_method_call(
- service.c_str(),
- INVENTORY_OBJ_PATH,
- INVENTORY_MGR_IFACE,
- "Notify");
+ auto method = bus.new_method_call(service.c_str(), INVENTORY_OBJ_PATH,
+ INVENTORY_MGR_IFACE, "Notify");
method.append(std::move(object));
@@ -747,30 +719,23 @@
if (reply.is_method_error())
{
log<level::ERR>(
- "Unable to update power supply inventory properties",
- entry("PATH=%s", path.c_str()));
+ "Unable to update power supply inventory properties",
+ entry("PATH=%s", path.c_str()));
}
// TODO: openbmc/openbmc#2756
// Calling Notify() with an enumerated property crashes inventory
// manager, so let it default to Unknown and now set it to the
// right value.
- auto purpose = version::convertForMessage(
- version::Version::VersionPurpose::Other);
+ auto purpose =
+ version::convertForMessage(version::Version::VersionPurpose::Other);
- util::setProperty(
- VERSION_IFACE,
- VERSION_PURPOSE_PROP,
- inventoryPath,
- service,
- bus,
- purpose);
+ util::setProperty(VERSION_IFACE, VERSION_PURPOSE_PROP, inventoryPath,
+ service, bus, purpose);
}
catch (std::exception& e)
{
- log<level::ERR>(
- e.what(),
- entry("PATH=%s", inventoryPath.c_str()));
+ log<level::ERR>(e.what(), entry("PATH=%s", inventoryPath.c_str()));
}
}
@@ -780,12 +745,11 @@
if (syncGPIODevPath.empty())
{
- //Sync not implemented
+ // Sync not implemented
return;
}
- GPIO gpio{syncGPIODevPath,
- static_cast<gpioNum_t>(syncGPIONumber),
+ GPIO gpio{syncGPIODevPath, static_cast<gpioNum_t>(syncGPIONumber),
Direction::output};
try
@@ -800,7 +764,7 @@
}
catch (std::exception& e)
{
- //Do nothing. There would already be a journal entry.
+ // Do nothing. There would already be a journal entry.
}
}
@@ -827,17 +791,16 @@
{
if (!recordManager)
{
- //Not enabled
+ // Not enabled
return;
}
- //Read just the most recent average/max record
- auto data = pmbusIntf.readBinary(
- INPUT_HISTORY,
- pmbus::Type::HwmonDeviceDebug,
- history::RecordManager::RAW_RECORD_SIZE);
+ // Read just the most recent average/max record
+ auto data =
+ pmbusIntf.readBinary(INPUT_HISTORY, pmbus::Type::HwmonDeviceDebug,
+ history::RecordManager::RAW_RECORD_SIZE);
- //Update D-Bus only if something changed (a new record ID, or cleared out)
+ // Update D-Bus only if something changed (a new record ID, or cleared out)
auto changed = recordManager->add(data);
if (changed)
{
@@ -846,6 +809,6 @@
}
}
-}
-}
-}
+} // namespace psu
+} // namespace power
+} // namespace witherspoon
diff --git a/power-supply/power_supply.hpp b/power-supply/power_supply.hpp
index a56e2e2..d997423 100644
--- a/power-supply/power_supply.hpp
+++ b/power-supply/power_supply.hpp
@@ -1,8 +1,4 @@
#pragma once
-#include <sdbusplus/bus/match.hpp>
-#include <sdeventplus/clock.hpp>
-#include <sdeventplus/event.hpp>
-#include <sdeventplus/utility/timer.hpp>
#include "average.hpp"
#include "device.hpp"
#include "maximum.hpp"
@@ -10,6 +6,11 @@
#include "pmbus.hpp"
#include "record_manager.hpp"
+#include <sdbusplus/bus/match.hpp>
+#include <sdeventplus/clock.hpp>
+#include <sdeventplus/event.hpp>
+#include <sdeventplus/utility/timer.hpp>
+
namespace witherspoon
{
namespace power
@@ -27,395 +28,389 @@
*/
class PowerSupply : public Device
{
- public:
- PowerSupply() = delete;
- PowerSupply(const PowerSupply&) = delete;
- PowerSupply(PowerSupply&&) = default;
- PowerSupply& operator=(const PowerSupply&) = default;
- PowerSupply& operator=(PowerSupply&&) = default;
- ~PowerSupply() = default;
+ public:
+ PowerSupply() = delete;
+ PowerSupply(const PowerSupply&) = delete;
+ PowerSupply(PowerSupply&&) = default;
+ PowerSupply& operator=(const PowerSupply&) = default;
+ PowerSupply& operator=(PowerSupply&&) = default;
+ ~PowerSupply() = default;
- /**
- * Constructor
- *
- * @param[in] name - the device name
- * @param[in] inst - the device instance
- * @param[in] objpath - the path to monitor
- * @param[in] invpath - the inventory path to use
- * @param[in] bus - D-Bus bus object
- * @param[in] e - event object
- * @param[in] t - time to allow power supply to assert PG#
- * @param[in] p - time to allow power supply presence state to
- * settle/deglitch and allow for application of power
- * prior to fault checking
- */
- PowerSupply(const std::string& name, size_t inst,
- const std::string& objpath,
- const std::string& invpath,
- sdbusplus::bus::bus& bus,
- const sdeventplus::Event& e,
- std::chrono::seconds& t,
- std::chrono::seconds& p);
+ /**
+ * Constructor
+ *
+ * @param[in] name - the device name
+ * @param[in] inst - the device instance
+ * @param[in] objpath - the path to monitor
+ * @param[in] invpath - the inventory path to use
+ * @param[in] bus - D-Bus bus object
+ * @param[in] e - event object
+ * @param[in] t - time to allow power supply to assert PG#
+ * @param[in] p - time to allow power supply presence state to
+ * settle/deglitch and allow for application of power
+ * prior to fault checking
+ */
+ PowerSupply(const std::string& name, size_t inst,
+ const std::string& objpath, const std::string& invpath,
+ sdbusplus::bus::bus& bus, const sdeventplus::Event& e,
+ std::chrono::seconds& t, std::chrono::seconds& p);
- /**
- * Power supply specific function to analyze for faults/errors.
- *
- * Various PMBus status bits will be checked for fault conditions.
- * If a certain fault bits are on, the appropriate error will be
- * committed.
- */
- void analyze() override;
+ /**
+ * Power supply specific function to analyze for faults/errors.
+ *
+ * Various PMBus status bits will be checked for fault conditions.
+ * If a certain fault bits are on, the appropriate error will be
+ * committed.
+ */
+ void analyze() override;
- /**
- * Write PMBus CLEAR_FAULTS
- *
- * This function will be called in various situations in order to clear
- * any fault status bits that may have been set, in order to start over
- * with a clean state. Presence changes and power state changes will
- * want to clear any faults logged.
- */
- void clearFaults() override;
+ /**
+ * Write PMBus CLEAR_FAULTS
+ *
+ * This function will be called in various situations in order to clear
+ * any fault status bits that may have been set, in order to start over
+ * with a clean state. Presence changes and power state changes will
+ * want to clear any faults logged.
+ */
+ void clearFaults() override;
- /**
- * Mark error for specified callout and message as resolved.
- *
- * @param[in] callout - The callout to be resolved (inventory path)
- * @parma[in] message - The message for the fault to be resolved
- */
- void resolveError(const std::string& callout,
- const std::string& message);
+ /**
+ * Mark error for specified callout and message as resolved.
+ *
+ * @param[in] callout - The callout to be resolved (inventory path)
+ * @parma[in] message - The message for the fault to be resolved
+ */
+ void resolveError(const std::string& callout, const std::string& message);
- /**
- * Enables making the input power history available on D-Bus
- *
- * @param[in] objectPath - the D-Bus object path to use
- * @param[in] maxRecords - the number of history records to keep
- * @param[in] syncGPIOPath - The gpiochip device path to use for
- * sending the sync command
- * @paramp[in] syncGPIONum - the GPIO number for the sync command
- */
- void enableHistory(const std::string& objectPath,
- size_t numRecords,
- const std::string& syncGPIOPath,
- size_t syncGPIONum);
+ /**
+ * Enables making the input power history available on D-Bus
+ *
+ * @param[in] objectPath - the D-Bus object path to use
+ * @param[in] maxRecords - the number of history records to keep
+ * @param[in] syncGPIOPath - The gpiochip device path to use for
+ * sending the sync command
+ * @paramp[in] syncGPIONum - the GPIO number for the sync command
+ */
+ void enableHistory(const std::string& objectPath, size_t numRecords,
+ const std::string& syncGPIOPath, size_t syncGPIONum);
- private:
- /**
- * The path to use for reading various PMBus bits/words.
- */
- std::string monitorPath;
+ private:
+ /**
+ * The path to use for reading various PMBus bits/words.
+ */
+ std::string monitorPath;
- /**
- * @brief Pointer to the PMBus interface
- *
- * Used to read out of or write to the /sysfs tree(s) containing files
- * that a device driver monitors the PMBus interface to the power
- * supplies.
- */
- witherspoon::pmbus::PMBus pmbusIntf;
+ /**
+ * @brief Pointer to the PMBus interface
+ *
+ * Used to read out of or write to the /sysfs tree(s) containing files
+ * that a device driver monitors the PMBus interface to the power
+ * supplies.
+ */
+ witherspoon::pmbus::PMBus pmbusIntf;
- /**
- * @brief D-Bus path to use for this power supply's inventory status.
- */
- std::string inventoryPath;
+ /**
+ * @brief D-Bus path to use for this power supply's inventory status.
+ */
+ std::string inventoryPath;
- /** @brief Connection for sdbusplus bus */
- sdbusplus::bus::bus& bus;
+ /** @brief Connection for sdbusplus bus */
+ sdbusplus::bus::bus& bus;
- /** @brief True if the power supply is present. */
- bool present = false;
+ /** @brief True if the power supply is present. */
+ bool present = false;
- /** @brief Used to subscribe to D-Bus property changes for Present */
- std::unique_ptr<sdbusplus::bus::match_t> presentMatch;
+ /** @brief Used to subscribe to D-Bus property changes for Present */
+ std::unique_ptr<sdbusplus::bus::match_t> presentMatch;
- /**
- * @brief Interval for setting present to true.
- *
- * The amount of time to wait from not present to present change before
- * updating the internal present indicator. Allows person servicing
- * the power supply some time to plug in the cable.
- */
- std::chrono::seconds presentInterval;
+ /**
+ * @brief Interval for setting present to true.
+ *
+ * The amount of time to wait from not present to present change before
+ * updating the internal present indicator. Allows person servicing
+ * the power supply some time to plug in the cable.
+ */
+ std::chrono::seconds presentInterval;
- /**
- * @brief Timer used to delay setting the internal present state.
- *
- * The timer used to do the callback after the present property has
- * changed.
- */
- sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> presentTimer;
+ /**
+ * @brief Timer used to delay setting the internal present state.
+ *
+ * The timer used to do the callback after the present property has
+ * changed.
+ */
+ sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> presentTimer;
- /** @brief True if a fault has already been found and not cleared */
- bool faultFound = false;
+ /** @brief True if a fault has already been found and not cleared */
+ bool faultFound = false;
- /** @brief True if the power is on. */
- bool powerOn = false;
+ /** @brief True if the power is on. */
+ bool powerOn = false;
- /**
- * @brief Equal to FAULT_COUNT if power on fault has been
- * detected.
- */
- size_t powerOnFault = 0;
+ /**
+ * @brief Equal to FAULT_COUNT if power on fault has been
+ * detected.
+ */
+ size_t powerOnFault = 0;
- /**
- * @brief Interval to setting powerOn to true.
- *
- * The amount of time to wait from power state on to setting the
- * internal powerOn state to true. The amount of time the power supply
- * is allowed to delay setting DGood/PG#.
- */
- std::chrono::seconds powerOnInterval;
+ /**
+ * @brief Interval to setting powerOn to true.
+ *
+ * The amount of time to wait from power state on to setting the
+ * internal powerOn state to true. The amount of time the power supply
+ * is allowed to delay setting DGood/PG#.
+ */
+ std::chrono::seconds powerOnInterval;
- /**
- * @brief Timer used to delay setting the internal powerOn state.
- *
- * The timer used to do the callback after the power state has been on
- * long enough.
- */
- sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> powerOnTimer;
+ /**
+ * @brief Timer used to delay setting the internal powerOn state.
+ *
+ * The timer used to do the callback after the power state has been on
+ * long enough.
+ */
+ sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> powerOnTimer;
- /** @brief Used to subscribe to D-Bus power on state changes */
- std::unique_ptr<sdbusplus::bus::match_t> powerOnMatch;
+ /** @brief Used to subscribe to D-Bus power on state changes */
+ std::unique_ptr<sdbusplus::bus::match_t> powerOnMatch;
- /** @brief Indicates that a read failure has occurred.
- *
- * @details This will be incremented each time a read failure is
- * encountered. If it is incremented to FAULT_COUNT, an error
- * will be logged.
- */
- size_t readFail = 0;
+ /** @brief Indicates that a read failure has occurred.
+ *
+ * @details This will be incremented each time a read failure is
+ * encountered. If it is incremented to FAULT_COUNT, an error
+ * will be logged.
+ */
+ size_t readFail = 0;
- /** @brief Has a PMBus read failure already been logged? */
- bool readFailLogged = false;
+ /** @brief Has a PMBus read failure already been logged? */
+ bool readFailLogged = false;
- /**
- * @brief Indicates an input fault or warning if equal to FAULT_COUNT.
- *
- * @details This is the "INPUT FAULT OR WARNING" bit in the high byte,
- * or the VIN_UV_FAULT bit in the low byte in the STATUS_WORD
- * command response. If either of those bits are on, this will
- * be incremented.
- */
- size_t inputFault = 0;
+ /**
+ * @brief Indicates an input fault or warning if equal to FAULT_COUNT.
+ *
+ * @details This is the "INPUT FAULT OR WARNING" bit in the high byte,
+ * or the VIN_UV_FAULT bit in the low byte in the STATUS_WORD
+ * command response. If either of those bits are on, this will
+ * be incremented.
+ */
+ size_t inputFault = 0;
- /**
- * @brief Indicates output over current fault if equal to FAULT_COUNT
- *
- * @details This is incremented when the "IOUT_OC_FAULT" bit in the low
- * byte from the STATUS_WORD command response is on.
- */
- size_t outputOCFault = 0;
+ /**
+ * @brief Indicates output over current fault if equal to FAULT_COUNT
+ *
+ * @details This is incremented when the "IOUT_OC_FAULT" bit in the low
+ * byte from the STATUS_WORD command response is on.
+ */
+ size_t outputOCFault = 0;
- /**
- * @brief Indicates output overvoltage fault if equal to FAULT_COUNT.
- *
- * @details This is incremented when the "VOUT_OV_FAULT" bit in the
- * STATUS_WORD command response is on.
- */
- size_t outputOVFault = 0;
+ /**
+ * @brief Indicates output overvoltage fault if equal to FAULT_COUNT.
+ *
+ * @details This is incremented when the "VOUT_OV_FAULT" bit in the
+ * STATUS_WORD command response is on.
+ */
+ size_t outputOVFault = 0;
- /**
- * @brief Indicates a fan fault or warning condition was detected if
- * equal to FAULT_COUNT.
- *
- * @details This is incremented when the 'FAN_FAULT' bit in the
- * STATUS_WORD command response is on.
- */
- size_t fanFault = 0;
+ /**
+ * @brief Indicates a fan fault or warning condition was detected if
+ * equal to FAULT_COUNT.
+ *
+ * @details This is incremented when the 'FAN_FAULT' bit in the
+ * STATUS_WORD command response is on.
+ */
+ size_t fanFault = 0;
- /**
- * @brief Indicates a temperature fault or warn condition was detected
- * if equal to FAULT_COUNT.
- *
- * @details This is incremented when the 'TEMPERATURE_FAULT_WARN' bit
- * in the STATUS_WORD command response is on, or if the
- * 'OT_FAULT' bit in the STATUS_TEMPERATURE command response
- * is on.
- */
- size_t temperatureFault = 0;
+ /**
+ * @brief Indicates a temperature fault or warn condition was detected
+ * if equal to FAULT_COUNT.
+ *
+ * @details This is incremented when the 'TEMPERATURE_FAULT_WARN' bit
+ * in the STATUS_WORD command response is on, or if the
+ * 'OT_FAULT' bit in the STATUS_TEMPERATURE command response
+ * is on.
+ */
+ size_t temperatureFault = 0;
- /**
- * @brief Class that manages the input power history records.
- */
- std::unique_ptr<history::RecordManager> recordManager;
+ /**
+ * @brief Class that manages the input power history records.
+ */
+ std::unique_ptr<history::RecordManager> recordManager;
- /**
- * @brief The D-Bus object for the average input power history
- */
- std::unique_ptr<history::Average> average;
+ /**
+ * @brief The D-Bus object for the average input power history
+ */
+ std::unique_ptr<history::Average> average;
- /**
- * @brief The D-Bus object for the maximum input power history
- */
- std::unique_ptr<history::Maximum> maximum;
+ /**
+ * @brief The D-Bus object for the maximum input power history
+ */
+ std::unique_ptr<history::Maximum> maximum;
- /**
- * @brief The base D-Bus object path to use for the average
- * and maximum objects.
- */
- std::string historyObjectPath;
+ /**
+ * @brief The base D-Bus object path to use for the average
+ * and maximum objects.
+ */
+ std::string historyObjectPath;
- /**
- * @brief The GPIO device path to use for sending the 'sync'
- * command to the PS.
- */
- std::string syncGPIODevPath;
+ /**
+ * @brief The GPIO device path to use for sending the 'sync'
+ * command to the PS.
+ */
+ std::string syncGPIODevPath;
- /**
- * @brief The GPIO number to use for sending the 'sync'
- * command to the PS.
- */
- size_t syncGPIONumber = 0;
+ /**
+ * @brief The GPIO number to use for sending the 'sync'
+ * command to the PS.
+ */
+ size_t syncGPIONumber = 0;
- /**
- * @brief Callback for inventory property changes
- *
- * Process change of Present property for power supply.
- *
- * @param[in] msg - Data associated with Present change signal
- *
- */
- void inventoryChanged(sdbusplus::message::message& msg);
+ /**
+ * @brief Callback for inventory property changes
+ *
+ * Process change of Present property for power supply.
+ *
+ * @param[in] msg - Data associated with Present change signal
+ *
+ */
+ void inventoryChanged(sdbusplus::message::message& msg);
- /**
- * Updates the presence status by querying D-Bus
- *
- * The D-Bus inventory properties for this power supply will be read to
- * determine if the power supply is present or not and update this
- * objects present member variable to reflect current status.
- */
- void updatePresence();
+ /**
+ * Updates the presence status by querying D-Bus
+ *
+ * The D-Bus inventory properties for this power supply will be read to
+ * determine if the power supply is present or not and update this
+ * objects present member variable to reflect current status.
+ */
+ void updatePresence();
- /**
- * @brief Updates the poweredOn status by querying D-Bus
- *
- * The D-Bus property for the system power state will be read to
- * determine if the system is powered on or not.
- */
- void updatePowerState();
+ /**
+ * @brief Updates the poweredOn status by querying D-Bus
+ *
+ * The D-Bus property for the system power state will be read to
+ * determine if the system is powered on or not.
+ */
+ void updatePowerState();
- /**
- * @brief Callback for power state property changes
- *
- * Process changes to the powered on stat property for the system.
- *
- * @param[in] msg - Data associated with the power state signal
- */
- void powerStateChanged(sdbusplus::message::message& msg);
+ /**
+ * @brief Callback for power state property changes
+ *
+ * Process changes to the powered on stat property for the system.
+ *
+ * @param[in] msg - Data associated with the power state signal
+ */
+ void powerStateChanged(sdbusplus::message::message& msg);
- /**
- * @brief Wrapper for PMBus::read() and adding metadata
- *
- * @param[out] nv - NamesValues instance to store cmd string and value
- * @param[in] cmd - String for the command to read data from.
- * @param[in] type - The type of file to read the command from.
- */
- void captureCmd(util::NamesValues& nv, const std::string& cmd,
- witherspoon::pmbus::Type type);
+ /**
+ * @brief Wrapper for PMBus::read() and adding metadata
+ *
+ * @param[out] nv - NamesValues instance to store cmd string and value
+ * @param[in] cmd - String for the command to read data from.
+ * @param[in] type - The type of file to read the command from.
+ */
+ void captureCmd(util::NamesValues& nv, const std::string& cmd,
+ witherspoon::pmbus::Type type);
- /**
- * @brief Checks for input voltage faults and logs error if needed.
- *
- * Check for voltage input under voltage fault (VIN_UV_FAULT) and/or
- * input fault or warning (INPUT_FAULT), and logs appropriate error(s).
- *
- * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
- */
- void checkInputFault(const uint16_t statusWord);
+ /**
+ * @brief Checks for input voltage faults and logs error if needed.
+ *
+ * Check for voltage input under voltage fault (VIN_UV_FAULT) and/or
+ * input fault or warning (INPUT_FAULT), and logs appropriate error(s).
+ *
+ * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
+ */
+ void checkInputFault(const uint16_t statusWord);
- /**
- * @brief Checks for power good negated or unit is off in wrong state
- *
- * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
- */
- void checkPGOrUnitOffFault(const uint16_t statusWord);
+ /**
+ * @brief Checks for power good negated or unit is off in wrong state
+ *
+ * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
+ */
+ void checkPGOrUnitOffFault(const uint16_t statusWord);
- /**
- * @brief Checks for output current over current fault.
- *
- * IOUT_OC_FAULT is checked, if on, appropriate error is logged.
- *
- * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
- */
- void checkCurrentOutOverCurrentFault(const uint16_t statusWord);
+ /**
+ * @brief Checks for output current over current fault.
+ *
+ * IOUT_OC_FAULT is checked, if on, appropriate error is logged.
+ *
+ * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
+ */
+ void checkCurrentOutOverCurrentFault(const uint16_t statusWord);
- /**
- * @brief Checks for output overvoltage fault.
- *
- * VOUT_OV_FAULT is checked, if on, appropriate error is logged.
- *
- * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
- */
- void checkOutputOvervoltageFault(const uint16_t statusWord);
+ /**
+ * @brief Checks for output overvoltage fault.
+ *
+ * VOUT_OV_FAULT is checked, if on, appropriate error is logged.
+ *
+ * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
+ */
+ void checkOutputOvervoltageFault(const uint16_t statusWord);
- /**
- * @brief Checks for a fan fault or warning condition.
- *
- * The high byte of STATUS_WORD is checked to see if the "FAN FAULT OR
- * WARNING" bit is turned on. If it is on, log an error.
- *
- * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
- */
- void checkFanFault(const uint16_t statusWord);
+ /**
+ * @brief Checks for a fan fault or warning condition.
+ *
+ * The high byte of STATUS_WORD is checked to see if the "FAN FAULT OR
+ * WARNING" bit is turned on. If it is on, log an error.
+ *
+ * @param[in] statusWord - 2 byte STATUS_WORD value read from sysfs
+ */
+ void checkFanFault(const uint16_t statusWord);
- /**
- * @brief Checks for a temperature fault or warning condition.
- *
- * The low byte of STATUS_WORD is checked to see if the "TEMPERATURE
- * FAULT OR WARNING" bit is turned on. If it is on, log an error,
- * call out the power supply indicating the fault/warning condition.
- *
- * @parma[in] statusWord - 2 byte STATUS_WORD value read from sysfs
- */
- void checkTemperatureFault(const uint16_t statusWord);
+ /**
+ * @brief Checks for a temperature fault or warning condition.
+ *
+ * The low byte of STATUS_WORD is checked to see if the "TEMPERATURE
+ * FAULT OR WARNING" bit is turned on. If it is on, log an error,
+ * call out the power supply indicating the fault/warning condition.
+ *
+ * @parma[in] statusWord - 2 byte STATUS_WORD value read from sysfs
+ */
+ void checkTemperatureFault(const uint16_t statusWord);
- /**
- * @brief Adds properties to the inventory.
- *
- * Reads the values from the device and writes them to the
- * associated power supply D-Bus inventory object.
- *
- * This needs to be done on startup, and each time the presence
- * state changes.
- *
- * Properties added:
- * - Serial Number
- * - Part Number
- * - CCIN (Customer Card Identification Number) - added as the Model
- * - Firmware version
- */
- void updateInventory();
+ /**
+ * @brief Adds properties to the inventory.
+ *
+ * Reads the values from the device and writes them to the
+ * associated power supply D-Bus inventory object.
+ *
+ * This needs to be done on startup, and each time the presence
+ * state changes.
+ *
+ * Properties added:
+ * - Serial Number
+ * - Part Number
+ * - CCIN (Customer Card Identification Number) - added as the Model
+ * - Firmware version
+ */
+ void updateInventory();
- /**
- * @brief Toggles the GPIO to sync power supply input history readings
- *
- * This GPIO is connected to all supplies. This will clear the
- * previous readings out of the supplies and restart them both at the
- * same time zero and at record ID 0. The supplies will return 0
- * bytes of data for the input history command right after this until
- * a new entry shows up.
- *
- * This will cause the code to delete all previous history data and
- * start fresh.
- */
- void syncHistory();
+ /**
+ * @brief Toggles the GPIO to sync power supply input history readings
+ *
+ * This GPIO is connected to all supplies. This will clear the
+ * previous readings out of the supplies and restart them both at the
+ * same time zero and at record ID 0. The supplies will return 0
+ * bytes of data for the input history command right after this until
+ * a new entry shows up.
+ *
+ * This will cause the code to delete all previous history data and
+ * start fresh.
+ */
+ void syncHistory();
- /**
- * @brief Reads the most recent input history record from the power
- * supply and updates the average and maximum properties in
- * D-Bus if there is a new reading available.
- *
- * This will still run every time analyze() is called so code can
- * post new data as soon as possible and the timestamp will more
- * accurately reflect the correct time.
- *
- * D-Bus is only updated if there is a change and the oldest record
- * will be pruned if the property already contains the max number of
- * records.
- */
- void updateHistory();
+ /**
+ * @brief Reads the most recent input history record from the power
+ * supply and updates the average and maximum properties in
+ * D-Bus if there is a new reading available.
+ *
+ * This will still run every time analyze() is called so code can
+ * post new data as soon as possible and the timestamp will more
+ * accurately reflect the correct time.
+ *
+ * D-Bus is only updated if there is a change and the oldest record
+ * will be pruned if the property already contains the max number of
+ * records.
+ */
+ void updateHistory();
};
-}
-}
-}
+} // namespace psu
+} // namespace power
+} // namespace witherspoon
diff --git a/power-supply/record_manager.cpp b/power-supply/record_manager.cpp
index ec6e917..b585ba0 100644
--- a/power-supply/record_manager.cpp
+++ b/power-supply/record_manager.cpp
@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <chrono>
-#include <math.h>
-#include <phosphor-logging/log.hpp>
#include "record_manager.hpp"
+#include <math.h>
+
+#include <chrono>
+#include <phosphor-logging/log.hpp>
+
namespace witherspoon
{
namespace power
@@ -31,47 +33,46 @@
{
if (rawRecord.size() == 0)
{
- //The PS has no data - either the power supply just started up,
- //or it just got a SYNC. Clear the history.
+ // The PS has no data - either the power supply just started up,
+ // or it just got a SYNC. Clear the history.
records.clear();
return true;
}
try
{
- //Peek at the ID to see if more processing is needed.
+ // Peek at the ID to see if more processing is needed.
auto id = getRawRecordID(rawRecord);
if (!records.empty())
{
auto previousID = std::get<recIDPos>(records.front());
- //Already have this record. Done.
+ // Already have this record. Done.
if (previousID == id)
{
return false;
}
- //Check that the sequence ID is in order.
- //If not, clear out current list.
+ // Check that the sequence ID is in order.
+ // If not, clear out current list.
if ((previousID + 1) != id)
{
- //If it just rolled over from 0xFF to 0x00, then no
- //need to clear. If we see a 0 seemingly out of nowhere,
- //then it was a sync so clear the old records.
+ // If it just rolled over from 0xFF to 0x00, then no
+ // need to clear. If we see a 0 seemingly out of nowhere,
+ // then it was a sync so clear the old records.
auto rolledOver =
- (previousID == lastSequenceID) &&
- (id == FIRST_SEQUENCE_ID);
+ (previousID == lastSequenceID) && (id == FIRST_SEQUENCE_ID);
if (!rolledOver)
{
if (id != FIRST_SEQUENCE_ID)
{
log<level::INFO>(
- "Noncontiguous INPUT_HISTORY sequence ID "
- "found. Clearing old entries",
- entry("OLD_ID=%ld", previousID),
- entry("NEW_ID=%ld", id));
+ "Noncontiguous INPUT_HISTORY sequence ID "
+ "found. Clearing old entries",
+ entry("OLD_ID=%ld", previousID),
+ entry("NEW_ID=%ld", id));
}
records.clear();
}
@@ -80,7 +81,7 @@
records.push_front(std::move(createRecord(rawRecord)));
- //If no more should be stored, prune the oldest
+ // If no more should be stored, prune the oldest
if (records.size() > maxRecords)
{
records.pop_back();
@@ -100,8 +101,7 @@
for (const auto& r : records)
{
- list.emplace_back(std::get<recTimePos>(r),
- std::get<recAvgPos>(r));
+ list.emplace_back(std::get<recTimePos>(r), std::get<recAvgPos>(r));
}
return list;
@@ -113,20 +113,18 @@
for (const auto& r : records)
{
- list.emplace_back(std::get<recTimePos>(r),
- std::get<recMaxPos>(r));
+ list.emplace_back(std::get<recTimePos>(r), std::get<recMaxPos>(r));
}
return list;
}
-size_t RecordManager::getRawRecordID(
- const std::vector<uint8_t>& data) const
+size_t RecordManager::getRawRecordID(const std::vector<uint8_t>& data) const
{
if (data.size() != RAW_RECORD_SIZE)
{
log<level::ERR>("Invalid INPUT_HISTORY size",
- entry("SIZE=%d", data.size()));
+ entry("SIZE=%d", data.size()));
throw InvalidRecordException{};
}
@@ -135,7 +133,7 @@
Record RecordManager::createRecord(const std::vector<uint8_t>& data)
{
- //The raw record format is:
+ // The raw record format is:
// 0xAABBCCDDEE
//
// where:
@@ -145,7 +143,8 @@
auto id = getRawRecordID(data);
auto time = std::chrono::duration_cast<std::chrono::milliseconds>(
- std::chrono::system_clock::now().time_since_epoch()).count();
+ std::chrono::system_clock::now().time_since_epoch())
+ .count();
auto val = static_cast<uint16_t>(data[2]) << 8 | data[1];
auto averagePower = linearToInteger(val);
@@ -158,20 +157,20 @@
int64_t RecordManager::linearToInteger(uint16_t data)
{
- //The exponent is the first 5 bits, followed by 11 bits of mantissa.
+ // The exponent is the first 5 bits, followed by 11 bits of mantissa.
int8_t exponent = (data & 0xF800) >> 11;
int16_t mantissa = (data & 0x07FF);
- //If exponent's MSB on, then it's negative.
- //Convert from two's complement.
+ // If exponent's MSB on, then it's negative.
+ // Convert from two's complement.
if (exponent & 0x10)
{
exponent = (~exponent) & 0x1F;
exponent = (exponent + 1) * -1;
}
- //If mantissa's MSB on, then it's negative.
- //Convert from two's complement.
+ // If mantissa's MSB on, then it's negative.
+ // Convert from two's complement.
if (mantissa & 0x400)
{
mantissa = (~mantissa) & 0x07FF;
@@ -182,6 +181,6 @@
return value;
}
-}
-}
-}
+} // namespace history
+} // namespace power
+} // namespace witherspoon
diff --git a/power-supply/record_manager.hpp b/power-supply/record_manager.hpp
index 53e5b9b..7ebcc3f 100644
--- a/power-supply/record_manager.hpp
+++ b/power-supply/record_manager.hpp
@@ -25,12 +25,10 @@
*/
class InvalidRecordException : public std::runtime_error
{
- public:
-
- InvalidRecordException() :
- std::runtime_error("Invalid history record")
- {
- }
+ public:
+ InvalidRecordException() : std::runtime_error("Invalid history record")
+ {
+ }
};
/**
@@ -49,157 +47,153 @@
*/
class RecordManager
{
- public:
+ public:
+ static constexpr auto RAW_RECORD_SIZE = 5;
+ static constexpr auto RAW_RECORD_ID_OFFSET = 0;
+ static constexpr auto FIRST_SEQUENCE_ID = 0;
+ static constexpr auto LAST_SEQUENCE_ID = 0xFF;
- static constexpr auto RAW_RECORD_SIZE = 5;
- static constexpr auto RAW_RECORD_ID_OFFSET = 0;
- static constexpr auto FIRST_SEQUENCE_ID = 0;
- static constexpr auto LAST_SEQUENCE_ID = 0xFF;
+ using DBusRecord = std::tuple<uint64_t, int64_t>;
+ using DBusRecordList = std::vector<DBusRecord>;
- using DBusRecord = std::tuple<uint64_t, int64_t>;
- using DBusRecordList = std::vector<DBusRecord>;
+ RecordManager() = delete;
+ ~RecordManager() = default;
+ RecordManager(const RecordManager&) = default;
+ RecordManager& operator=(const RecordManager&) = default;
+ RecordManager(RecordManager&&) = default;
+ RecordManager& operator=(RecordManager&&) = default;
- RecordManager() = delete;
- ~RecordManager() = default;
- RecordManager(const RecordManager&) = default;
- RecordManager& operator=(const RecordManager&) = default;
- RecordManager(RecordManager&&) = default;
- RecordManager& operator=(RecordManager&&) = default;
+ /**
+ * @brief Constructor
+ *
+ * @param[in] maxRec - the maximum number of history
+ * records to keep at a time
+ */
+ RecordManager(size_t maxRec) : RecordManager(maxRec, LAST_SEQUENCE_ID)
+ {
+ }
- /**
- * @brief Constructor
- *
- * @param[in] maxRec - the maximum number of history
- * records to keep at a time
- */
- RecordManager(size_t maxRec) :
- RecordManager(maxRec, LAST_SEQUENCE_ID)
- {
- }
+ /**
+ * @brief Constructor
+ *
+ * @param[in] maxRec - the maximum number of history
+ * records to keep at a time
+ * @param[in] lastSequenceID - the last sequence ID the power supply
+ * will use before starting over
+ */
+ RecordManager(size_t maxRec, size_t lastSequenceID) :
+ maxRecords(maxRec), lastSequenceID(lastSequenceID)
+ {
+ }
- /**
- * @brief Constructor
- *
- * @param[in] maxRec - the maximum number of history
- * records to keep at a time
- * @param[in] lastSequenceID - the last sequence ID the power supply
- * will use before starting over
- */
- RecordManager(size_t maxRec, size_t lastSequenceID) :
- maxRecords(maxRec),
- lastSequenceID(lastSequenceID)
- {
- }
+ /**
+ * @brief Adds a new entry to the history
+ *
+ * Also checks to see if the old history should be
+ * cleared, such as when there is an invalid record
+ * sequence ID or if there was no data from the PS.
+ *
+ * @param[in] rawRecord - the record data straight
+ * from the power supply
+ *
+ * @return bool - If there has been a change to the
+ * history records that needs to be
+ * reflected in D-Bus.
+ */
+ bool add(const std::vector<uint8_t>& rawRecord);
- /**
- * @brief Adds a new entry to the history
- *
- * Also checks to see if the old history should be
- * cleared, such as when there is an invalid record
- * sequence ID or if there was no data from the PS.
- *
- * @param[in] rawRecord - the record data straight
- * from the power supply
- *
- * @return bool - If there has been a change to the
- * history records that needs to be
- * reflected in D-Bus.
- */
- bool add(const std::vector<uint8_t>& rawRecord);
+ /**
+ * @brief Returns the history of average input power
+ * in a representation used by D-Bus.
+ *
+ * @return DBusRecordList - A list of averages with
+ * a timestamp for each entry.
+ */
+ DBusRecordList getAverageRecords();
- /**
- * @brief Returns the history of average input power
- * in a representation used by D-Bus.
- *
- * @return DBusRecordList - A list of averages with
- * a timestamp for each entry.
- */
- DBusRecordList getAverageRecords();
+ /**
+ * @brief Returns the history of maximum input power
+ * in a representation used by D-Bus.
+ *
+ * @return DBusRecordList - A list of maximums with
+ * a timestamp for each entry.
+ */
+ DBusRecordList getMaximumRecords();
- /**
- * @brief Returns the history of maximum input power
- * in a representation used by D-Bus.
- *
- * @return DBusRecordList - A list of maximums with
- * a timestamp for each entry.
- */
- DBusRecordList getMaximumRecords();
+ /**
+ * @brief Converts a Linear Format power number to an integer
+ *
+ * The PMBus spec describes a 2 byte Linear Format
+ * number that is composed of an exponent and mantissa
+ * in two's complement notation.
+ *
+ * Value = Mantissa * 2**Exponent
+ *
+ * @return int64_t the converted value
+ */
+ static int64_t linearToInteger(uint16_t data);
- /**
- * @brief Converts a Linear Format power number to an integer
- *
- * The PMBus spec describes a 2 byte Linear Format
- * number that is composed of an exponent and mantissa
- * in two's complement notation.
- *
- * Value = Mantissa * 2**Exponent
- *
- * @return int64_t the converted value
- */
- static int64_t linearToInteger(uint16_t data);
+ /**
+ * @brief Returns the number of records
+ *
+ * @return size_t - the number of records
+ *
+ */
+ inline size_t getNumRecords() const
+ {
+ return records.size();
+ }
- /**
- * @brief Returns the number of records
- *
- * @return size_t - the number of records
- *
- */
- inline size_t getNumRecords() const
- {
- return records.size();
- }
+ /**
+ * @brief Deletes all records
+ */
+ inline void clear()
+ {
+ records.clear();
+ }
- /**
- * @brief Deletes all records
- */
- inline void clear()
- {
- records.clear();
- }
+ private:
+ /**
+ * @brief returns the sequence ID from a raw history record
+ *
+ * Throws InvalidRecordException if the data is the wrong length.
+ *
+ * @param[in] data - the raw record data as the PS returns it
+ *
+ * @return size_t - the ID from byte 0
+ */
+ size_t getRawRecordID(const std::vector<uint8_t>& data) const;
- private:
+ /**
+ * @brief Creates an instance of a Record from the raw PS data
+ *
+ * @param[in] data - the raw record data as the PS returns it
+ *
+ * @return Record - A filled in Record instance
+ */
+ Record createRecord(const std::vector<uint8_t>& data);
- /**
- * @brief returns the sequence ID from a raw history record
- *
- * Throws InvalidRecordException if the data is the wrong length.
- *
- * @param[in] data - the raw record data as the PS returns it
- *
- * @return size_t - the ID from byte 0
- */
- size_t getRawRecordID(const std::vector<uint8_t>& data) const;
+ /**
+ * @brief The maximum number of entries to keep in the history.
+ *
+ * When a new record is added, the oldest one will be removed.
+ */
+ const size_t maxRecords;
- /**
- * @brief Creates an instance of a Record from the raw PS data
- *
- * @param[in] data - the raw record data as the PS returns it
- *
- * @return Record - A filled in Record instance
- */
- Record createRecord(const std::vector<uint8_t>& data);
+ /**
+ * @brief The last ID the power supply returns before rolling over
+ * back to the first ID of 0.
+ */
+ const size_t lastSequenceID;
- /**
- * @brief The maximum number of entries to keep in the history.
- *
- * When a new record is added, the oldest one will be removed.
- */
- const size_t maxRecords;
-
- /**
- * @brief The last ID the power supply returns before rolling over
- * back to the first ID of 0.
- */
- const size_t lastSequenceID;
-
- /**
- * @brief The list of timestamp/average/maximum records.
- * Newer records are added to the front, and older ones
- * removed from the back.
- */
- std::deque<Record> records;
+ /**
+ * @brief The list of timestamp/average/maximum records.
+ * Newer records are added to the front, and older ones
+ * removed from the back.
+ */
+ std::deque<Record> records;
};
-}
-}
-}
+} // namespace history
+} // namespace power
+} // namespace witherspoon
diff --git a/power-supply/test/test_records.cpp b/power-supply/test/test_records.cpp
index 20b638b..e500322 100644
--- a/power-supply/test/test_records.cpp
+++ b/power-supply/test/test_records.cpp
@@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <gtest/gtest.h>
-#include <iostream>
-#include "names_values.hpp"
#include "../record_manager.hpp"
+#include "names_values.hpp"
+
+#include <iostream>
+
+#include <gtest/gtest.h>
using namespace witherspoon::power::history;
@@ -29,41 +31,41 @@
*/
TEST(LinearFormatTest, TestConversions)
{
- //Mantissa > 0, exponent = 0
+ // Mantissa > 0, exponent = 0
EXPECT_EQ(0, RecordManager::linearToInteger(0));
EXPECT_EQ(1, RecordManager::linearToInteger(1));
EXPECT_EQ(38, RecordManager::linearToInteger(0x26));
EXPECT_EQ(1023, RecordManager::linearToInteger(0x3FF));
- //Mantissa < 0, exponent = 0
+ // Mantissa < 0, exponent = 0
EXPECT_EQ(-1, RecordManager::linearToInteger(0x7FF));
EXPECT_EQ(-20, RecordManager::linearToInteger(0x7EC));
EXPECT_EQ(-769, RecordManager::linearToInteger(0x4FF));
EXPECT_EQ(-989, RecordManager::linearToInteger(0x423));
EXPECT_EQ(-1024, RecordManager::linearToInteger(0x400));
- //Mantissa >= 0, exponent > 0
- //M = 1, E = 2
+ // Mantissa >= 0, exponent > 0
+ // M = 1, E = 2
EXPECT_EQ(4, RecordManager::linearToInteger(0x1001));
- //M = 1000, E = 10
+ // M = 1000, E = 10
EXPECT_EQ(1024000, RecordManager::linearToInteger(0x53E8));
- //M = 10, E = 15
+ // M = 10, E = 15
EXPECT_EQ(327680, RecordManager::linearToInteger(0x780A));
- //Mantissa >= 0, exponent < 0
- //M = 0, E = -1
+ // Mantissa >= 0, exponent < 0
+ // M = 0, E = -1
EXPECT_EQ(0, RecordManager::linearToInteger(0xF800));
- //M = 100, E = -2
+ // M = 100, E = -2
EXPECT_EQ(25, RecordManager::linearToInteger(0xF064));
- //Mantissa < 0, exponent < 0
- //M = -100, E = -1
+ // Mantissa < 0, exponent < 0
+ // M = -100, E = -1
EXPECT_EQ(-50, RecordManager::linearToInteger(0xFF9C));
- //M = -1024, E = -7
+ // M = -1024, E = -7
EXPECT_EQ(-8, RecordManager::linearToInteger(0xCC00));
}
@@ -76,10 +78,8 @@
*
* @return vector<uint8_t> the record buffer
*/
-std::vector<uint8_t> makeRawRecord(
- uint8_t sequenceID,
- uint16_t avgPower,
- uint16_t maxPower)
+std::vector<uint8_t> makeRawRecord(uint8_t sequenceID, uint16_t avgPower,
+ uint16_t maxPower)
{
std::vector<uint8_t> record;
@@ -92,13 +92,12 @@
return record;
}
-
/**
* Test record queue management
*/
TEST(ManagerTest, TestRecordAdds)
{
- //Hold 5 max records. IDs roll over at 8.
+ // Hold 5 max records. IDs roll over at 8.
RecordManager mgr{5, 8};
EXPECT_EQ(0, mgr.getNumRecords());
@@ -118,7 +117,7 @@
mgr.add(makeRawRecord(4, 0, 0));
EXPECT_EQ(5, mgr.getNumRecords());
- //start pruning
+ // start pruning
mgr.add(makeRawRecord(5, 0, 0));
EXPECT_EQ(5, mgr.getNumRecords());
@@ -131,30 +130,30 @@
mgr.add(makeRawRecord(8, 0, 0));
EXPECT_EQ(5, mgr.getNumRecords());
- //rollover
+ // rollover
mgr.add(makeRawRecord(0, 0, 0));
EXPECT_EQ(5, mgr.getNumRecords());
mgr.add(makeRawRecord(1, 0, 0));
EXPECT_EQ(5, mgr.getNumRecords());
- //nonsequential ID, clear previous
+ // nonsequential ID, clear previous
mgr.add(makeRawRecord(4, 0, 10));
EXPECT_EQ(1, mgr.getNumRecords());
- //back to normal
+ // back to normal
mgr.add(makeRawRecord(5, 1, 11));
EXPECT_EQ(2, mgr.getNumRecords());
- //One more good record
+ // One more good record
mgr.add(makeRawRecord(6, 2, 12));
EXPECT_EQ(3, mgr.getNumRecords());
- //Add a garbage length record. No size change
+ // Add a garbage length record. No size change
mgr.add(std::vector<uint8_t>(6, 0));
EXPECT_EQ(3, mgr.getNumRecords());
- //Test the DBus Records
+ // Test the DBus Records
auto avgRecords = mgr.getAverageRecords();
EXPECT_EQ(3, avgRecords.size());
@@ -175,8 +174,7 @@
max--;
}
- //Add a zero length record. Records cleared.
+ // Add a zero length record. Records cleared.
mgr.add(std::vector<uint8_t>{});
EXPECT_EQ(0, mgr.getNumRecords());
}
-