summaryrefslogtreecommitdiffstats
path: root/presence/tach_detect.cpp
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-06-08 23:21:03 -0400
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-07-08 17:18:09 -0400
commit8e9a8e75ab05e6ab69634ea365231dc6cee56087 (patch)
tree8a2e11fcd22c5907857105eee0e321d9bf7b94e6 /presence/tach_detect.cpp
parent1fd8f74126c14b72493e4e7bec2262999b85fdbe (diff)
downloadphosphor-fan-presence-8e9a8e75ab05e6ab69634ea365231dc6cee56087.tar.gz
phosphor-fan-presence-8e9a8e75ab05e6ab69634ea365231dc6cee56087.zip
presence: Check DBus for initial state
At startup load the initial state from the DBus object if one exists already. Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com> Change-Id: Ia4ad2f3c2b5c521406d9a186113b11cf8ed69b14
Diffstat (limited to 'presence/tach_detect.cpp')
-rw-r--r--presence/tach_detect.cpp43
1 files changed, 38 insertions, 5 deletions
diff --git a/presence/tach_detect.cpp b/presence/tach_detect.cpp
index 8c860d5..6284f89 100644
--- a/presence/tach_detect.cpp
+++ b/presence/tach_detect.cpp
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <phosphor-logging/log.hpp>
#include <vector>
#include "fan_enclosure.hpp"
#include "fan_detect_defs.hpp"
@@ -22,6 +23,10 @@
int main(void)
{
+ using namespace phosphor::fan;
+ using namespace std::literals::string_literals;
+ using namespace phosphor::logging;
+
std::vector<std::unique_ptr<phosphor::fan::presence::FanEnclosure>> fans;
for (auto const& detectMap: fanDetectMap)
@@ -30,13 +35,42 @@ int main(void)
{
for (auto const& fanProp: detectMap.second)
{
+ auto path = "/xyz/openbmc_project/inventory"s +
+ std::get<0>(fanProp);
+
+ auto state = presence::UNKNOWN;
+ try
+ {
+ auto boolstate = util::SDBusPlus::getProperty<bool>(
+ path,
+ "xyz.openbmc_project.Inventory.Item"s,
+ "Present"s);
+ state = boolstate ?
+ presence::PRESENT : presence::NOT_PRESENT;
+ }
+ catch (const std::exception& err)
+ {
+ log<level::INFO>(err.what());
+ }
+
auto fan = std::make_unique<
- phosphor::fan::presence::FanEnclosure>(fanProp);
+ phosphor::fan::presence::FanEnclosure>(fanProp,
+ state);
for (auto const &fanSensor: std::get<2>(fanProp))
{
+ auto initialSpeed = static_cast<int64_t>(0);
+ auto sensorPath =
+ "/xyz/openbmc_project/sensors/fan_tach/"s +
+ fanSensor;
+ initialSpeed = util::SDBusPlus::getProperty<int64_t>(
+ sensorPath,
+ "xyz.openbmc_project.Sensor.Value"s,
+ "Value"s);
+
auto sensor = std::make_unique<
phosphor::fan::presence::TachSensor>(fanSensor,
- *fan);
+ *fan,
+ initialSpeed != 0);
fan->addSensor(std::move(sensor));
}
@@ -48,10 +82,9 @@ int main(void)
while (true)
{
- using namespace phosphor::fan::util;
// Respond to dbus signals
- SDBusPlus::getBus().process_discard();
- SDBusPlus::getBus().wait();
+ util::SDBusPlus::getBus().process_discard();
+ util::SDBusPlus::getBus().wait();
}
return 0;
}
OpenPOWER on IntegriCloud