sensors/zones: place in namespace and cleanup
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I527dbc8477a232945f696227a7b0b2adbee45175
diff --git a/pid/builder.cpp b/pid/builder.cpp
index 0ffadf1..b76d134 100644
--- a/pid/builder.cpp
+++ b/pid/builder.cpp
@@ -28,6 +28,9 @@
#include <memory>
#include <unordered_map>
+namespace pid_control
+{
+
static constexpr bool deferSignals = true;
static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone";
@@ -135,3 +138,5 @@
return zones;
}
+
+} // namespace pid_control
diff --git a/pid/builder.hpp b/pid/builder.hpp
index a493a67..0ee3420 100644
--- a/pid/builder.hpp
+++ b/pid/builder.hpp
@@ -8,7 +8,12 @@
#include <memory>
#include <unordered_map>
+namespace pid_control
+{
+
std::unordered_map<int64_t, std::unique_ptr<PIDZone>>
buildZones(const std::map<int64_t, conf::PIDConf>& zonePids,
std::map<int64_t, struct conf::ZoneConfig>& zoneConfigs,
SensorManager& mgr, sdbusplus::bus::bus& modeControlBus);
+
+}
diff --git a/pid/buildjson.cpp b/pid/buildjson.cpp
index 9b3937b..c178293 100644
--- a/pid/buildjson.cpp
+++ b/pid/buildjson.cpp
@@ -23,6 +23,9 @@
#include <map>
#include <tuple>
+namespace pid_control
+{
+
using json = nlohmann::json;
namespace conf
@@ -152,3 +155,5 @@
return std::make_pair(pidConfig, zoneConfig);
}
+
+} // namespace pid_control
diff --git a/pid/buildjson.hpp b/pid/buildjson.hpp
index 2ac573a..5489c5a 100644
--- a/pid/buildjson.hpp
+++ b/pid/buildjson.hpp
@@ -7,6 +7,9 @@
#include <map>
#include <tuple>
+namespace pid_control
+{
+
using json = nlohmann::json;
/**
@@ -18,3 +21,5 @@
std::pair<std::map<int64_t, conf::PIDConf>,
std::map<int64_t, struct conf::ZoneConfig>>
buildPIDsFromJson(const json& data);
+
+} // namespace pid_control
diff --git a/pid/controller.hpp b/pid/controller.hpp
index 5530843..5680052 100644
--- a/pid/controller.hpp
+++ b/pid/controller.hpp
@@ -5,6 +5,9 @@
#include <string>
+namespace pid_control
+{
+
/*
* Base class for controllers. Each controller that implements this needs to
* provide an inputProc, process, and outputProc.
@@ -23,3 +26,5 @@
virtual std::string getID(void) = 0;
};
+
+} // namespace pid_control
diff --git a/pid/ec/pid.cpp b/pid/ec/pid.cpp
index 7d8b403..98968f7 100644
--- a/pid/ec/pid.cpp
+++ b/pid/ec/pid.cpp
@@ -16,6 +16,8 @@
#include "pid.hpp"
+namespace pid_control
+{
namespace ec
{
@@ -119,3 +121,4 @@
}
} // namespace ec
+} // namespace pid_control
diff --git a/pid/ec/pid.hpp b/pid/ec/pid.hpp
index 74ad5a7..29c7bb3 100644
--- a/pid/ec/pid.hpp
+++ b/pid/ec/pid.hpp
@@ -2,6 +2,8 @@
#include <cstdint>
+namespace pid_control
+{
namespace ec
{
@@ -54,3 +56,4 @@
};
} // namespace ec
+} // namespace pid_control
diff --git a/pid/ec/stepwise.cpp b/pid/ec/stepwise.cpp
index 0a5c0b0..0065228 100644
--- a/pid/ec/stepwise.cpp
+++ b/pid/ec/stepwise.cpp
@@ -20,8 +20,11 @@
#include <cstddef>
#include <limits>
+namespace pid_control
+{
namespace ec
{
+
double stepwise(const ec::StepwiseInfo& info, double input)
{
double value = info.output[0]; // if we are below the lowest
@@ -43,4 +46,6 @@
return value;
}
-} // namespace ec
\ No newline at end of file
+
+} // namespace ec
+} // namespace pid_control
diff --git a/pid/ec/stepwise.hpp b/pid/ec/stepwise.hpp
index 3ce847a..88db332 100644
--- a/pid/ec/stepwise.hpp
+++ b/pid/ec/stepwise.hpp
@@ -20,6 +20,8 @@
#include <cstddef>
#include <vector>
+namespace pid_control
+{
namespace ec
{
constexpr size_t maxStepwisePoints = 20;
@@ -36,4 +38,5 @@
double stepwise(const ec::StepwiseInfo& info, double value);
-} // namespace ec
\ No newline at end of file
+} // namespace ec
+} // namespace pid_control
diff --git a/pid/fan.hpp b/pid/fan.hpp
index 7792d04..a16942b 100644
--- a/pid/fan.hpp
+++ b/pid/fan.hpp
@@ -1,9 +1,14 @@
#pragma once
+namespace pid_control
+{
+
enum class FanSpeedDirection
{
DOWN,
UP,
NEUTRAL, /* not sure this will ever happen, but for completeness. */
};
+
+}
diff --git a/pid/fancontroller.cpp b/pid/fancontroller.cpp
index dd26d16..41f24da 100644
--- a/pid/fancontroller.cpp
+++ b/pid/fancontroller.cpp
@@ -23,6 +23,9 @@
#include <algorithm>
#include <iostream>
+namespace pid_control
+{
+
std::unique_ptr<PIDController>
FanController::createFanPid(ZoneInterface* owner, const std::string& id,
const std::vector<std::string>& inputs,
@@ -140,3 +143,5 @@
return;
}
+
+} // namespace pid_control
diff --git a/pid/fancontroller.hpp b/pid/fancontroller.hpp
index d14aef7..25eebad 100644
--- a/pid/fancontroller.hpp
+++ b/pid/fancontroller.hpp
@@ -8,6 +8,9 @@
#include <string>
#include <vector>
+namespace pid_control
+{
+
/*
* A FanController is a PID controller that reads a number of fans and given
* the output then tries to set them to the goal values set by the thermal
@@ -45,3 +48,5 @@
std::vector<std::string> _inputs;
FanSpeedDirection _direction;
};
+
+} // namespace pid_control
diff --git a/pid/pidcontroller.cpp b/pid/pidcontroller.cpp
index e3eaaff..e7a4ad1 100644
--- a/pid/pidcontroller.cpp
+++ b/pid/pidcontroller.cpp
@@ -27,6 +27,9 @@
#include <thread>
#include <vector>
+namespace pid_control
+{
+
void PIDController::process(void)
{
double input;
@@ -78,3 +81,5 @@
return;
}
+
+} // namespace pid_control
diff --git a/pid/pidcontroller.hpp b/pid/pidcontroller.hpp
index fd41c09..cb92377 100644
--- a/pid/pidcontroller.hpp
+++ b/pid/pidcontroller.hpp
@@ -8,6 +8,9 @@
#include <memory>
#include <vector>
+namespace pid_control
+{
+
class ZoneInterface;
/*
@@ -63,3 +66,5 @@
std::string _id;
double lastInput = std::numeric_limits<double>::quiet_NaN();
};
+
+} // namespace pid_control
diff --git a/pid/pidloop.cpp b/pid/pidloop.cpp
index 8dc6221..f046c9d 100644
--- a/pid/pidloop.cpp
+++ b/pid/pidloop.cpp
@@ -28,6 +28,9 @@
#include <thread>
#include <vector>
+namespace pid_control
+{
+
static void processThermals(PIDZone* zone)
{
// Get the latest margins.
@@ -121,3 +124,5 @@
pidControlLoop(zone, timer, false, ms100cnt);
});
}
+
+} // namespace pid_control
diff --git a/pid/pidloop.hpp b/pid/pidloop.hpp
index 3a67954..cf4b7ce 100644
--- a/pid/pidloop.hpp
+++ b/pid/pidloop.hpp
@@ -4,6 +4,9 @@
#include <boost/asio/steady_timer.hpp>
+namespace pid_control
+{
+
/**
* Main pid control loop for a given zone.
* This function calls itself indefinitely in an async loop to calculate
@@ -16,3 +19,5 @@
*/
void pidControlLoop(PIDZone* zone, boost::asio::steady_timer& timer,
bool first = true, int ms100cnt = 0);
+
+} // namespace pid_control
diff --git a/pid/stepwisecontroller.cpp b/pid/stepwisecontroller.cpp
index c72d61a..e8eb344 100644
--- a/pid/stepwisecontroller.cpp
+++ b/pid/stepwisecontroller.cpp
@@ -30,6 +30,9 @@
#include <thread>
#include <vector>
+namespace pid_control
+{
+
void StepwiseController::process(void)
{
// Get input value
@@ -105,3 +108,5 @@
}
return;
}
+
+} // namespace pid_control
diff --git a/pid/stepwisecontroller.hpp b/pid/stepwisecontroller.hpp
index 90e2317..e192fc7 100644
--- a/pid/stepwisecontroller.hpp
+++ b/pid/stepwisecontroller.hpp
@@ -8,6 +8,9 @@
#include <memory>
#include <vector>
+namespace pid_control
+{
+
class ZoneInterface;
class StepwiseController : public Controller
@@ -52,3 +55,5 @@
double lastInput = std::numeric_limits<double>::quiet_NaN();
double lastOutput = std::numeric_limits<double>::quiet_NaN();
};
+
+} // namespace pid_control
diff --git a/pid/thermalcontroller.cpp b/pid/thermalcontroller.cpp
index 5a5b9cc..35dcd15 100644
--- a/pid/thermalcontroller.cpp
+++ b/pid/thermalcontroller.cpp
@@ -22,6 +22,9 @@
#include <algorithm>
+namespace pid_control
+{
+
ThermalType getThermalType(const std::string& typeString)
{
/* Currently it only supports the two types. */
@@ -106,3 +109,5 @@
return;
}
+
+} // namespace pid_control
diff --git a/pid/thermalcontroller.hpp b/pid/thermalcontroller.hpp
index 74e85ab..6144d49 100644
--- a/pid/thermalcontroller.hpp
+++ b/pid/thermalcontroller.hpp
@@ -7,6 +7,9 @@
#include <string>
#include <vector>
+namespace pid_control
+{
+
/*
* A ThermalController is a PID controller that reads a number of sensors and
* provides the setpoints for the fans.
@@ -58,3 +61,5 @@
std::vector<std::string> _inputs;
ThermalType type;
};
+
+} // namespace pid_control
diff --git a/pid/util.cpp b/pid/util.cpp
index 0a8f892..ad7c139 100644
--- a/pid/util.cpp
+++ b/pid/util.cpp
@@ -21,6 +21,9 @@
#include <cstring>
#include <iostream>
+namespace pid_control
+{
+
void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial)
{
std::memset(info, 0x00, sizeof(ec::pid_info_t));
@@ -57,3 +60,5 @@
return;
}
+
+} // namespace pid_control
diff --git a/pid/zone.cpp b/pid/zone.cpp
index 6a63671..9484658 100644
--- a/pid/zone.cpp
+++ b/pid/zone.cpp
@@ -32,6 +32,9 @@
#include <iostream>
#include <memory>
+namespace pid_control
+{
+
using tstamp = std::chrono::high_resolution_clock::time_point;
using namespace std::literals::chrono_literals;
@@ -380,3 +383,5 @@
{
return getFailSafeMode();
}
+
+} // namespace pid_control
diff --git a/pid/zone.hpp b/pid/zone.hpp
index dc2ceb8..9dc433a 100644
--- a/pid/zone.hpp
+++ b/pid/zone.hpp
@@ -23,6 +23,9 @@
using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode;
using ModeObject = ServerObject<ModeInterface>;
+namespace pid_control
+{
+
class ZoneInterface
{
public:
@@ -119,3 +122,5 @@
std::vector<std::unique_ptr<Controller>> _fans;
std::vector<std::unique_ptr<Controller>> _thermals;
};
+
+} // namespace pid_control