From 7eaf8d6aedd300da8eb4e9d911c4ce9b2fa97cf7 Mon Sep 17 00:00:00 2001 From: Raptor Engineering Development Team Date: Wed, 24 Jan 2018 21:59:42 -0600 Subject: Add fan shutdown option to stop rotors after chassis powerdown --- control/argument.cpp | 5 ++++- control/fan.cpp | 10 ++++++++++ control/fan.hpp | 5 +++++ control/main.cpp | 11 +++++++++++ control/manager.cpp | 8 ++++++++ control/manager.hpp | 6 ++++++ control/zone.cpp | 9 +++++++++ control/zone.hpp | 10 +++++++++- 8 files changed, 62 insertions(+), 2 deletions(-) diff --git a/control/argument.cpp b/control/argument.cpp index d9b832d..e4ffb65 100644 --- a/control/argument.cpp +++ b/control/argument.cpp @@ -1,5 +1,6 @@ /** * Copyright © 2017 IBM Corporation + * Copyright © 2017-2018 Raptor Engineering, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,6 +70,7 @@ void ArgumentParser::usage(char** argv) std::cerr << " --help Print this menu\n"; std::cerr << " --init Sets fans to full speed, delays, exits\n"; std::cerr << " --control Start fan control algorithm\n"; + std::cerr << " --shutdown Shut down fan control algorithm *and* fans. ONLY use after chassis powerdown!\n"; std::cerr << std::flush; } @@ -76,11 +78,12 @@ const option ArgumentParser::options[] = { { "init", no_argument, NULL, 'i' }, { "control", no_argument, NULL, 'c' }, + { "shutdown", no_argument, NULL, 's' }, { "help", no_argument, NULL, 'h' }, { 0, 0, 0, 0}, }; -const char* ArgumentParser::optionstr = "ich?"; +const char* ArgumentParser::optionstr = "icsh?"; const std::string ArgumentParser::true_string = "true"; const std::string ArgumentParser::empty_string = ""; diff --git a/control/fan.cpp b/control/fan.cpp index b0881da..8250c5c 100644 --- a/control/fan.cpp +++ b/control/fan.cpp @@ -1,5 +1,6 @@ /** * Copyright © 2017 IBM Corporation + * Copyright © 2017-2018 Raptor Engineering, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -101,6 +102,15 @@ void Fan::setSpeed(uint64_t speed) _targetSpeed = speed; } +void Fan::disableRotor() +{ + // TODO + // This should set the enable value of the hwmon PWM entry + // For now, just set the fan speed to 0 + + setSpeed(0); +} + } } } diff --git a/control/fan.hpp b/control/fan.hpp index e7f3067..fd44c8a 100644 --- a/control/fan.hpp +++ b/control/fan.hpp @@ -56,6 +56,11 @@ class Fan return _targetSpeed; } + /** + * Disables the fan, stopping the rotor + */ + void disableRotor(); + private: /** diff --git a/control/main.cpp b/control/main.cpp index cde71d0..dd49c93 100644 --- a/control/main.cpp +++ b/control/main.cpp @@ -1,5 +1,6 @@ /** * Copyright © 2017 IBM Corporation + * Copyright © 2017-2018 Raptor Engineering, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +45,10 @@ int main(int argc, char* argv[]) { mode = Mode::control; } + else if (args["shutdown"] == "true") + { + mode = Mode::shutdown; + } else { args.usage(argv); @@ -72,6 +77,12 @@ int main(int argc, char* argv[]) manager.doInit(); return 0; } + //Shutdown mode will disable fans and exit + else if (mode == Mode::shutdown) + { + manager.doShutdown(); + return 0; + } else { r = sd_event_loop(eventPtr.get()); diff --git a/control/manager.cpp b/control/manager.cpp index d5f97d7..e48981d 100644 --- a/control/manager.cpp +++ b/control/manager.cpp @@ -1,5 +1,6 @@ /** * Copyright © 2017 IBM Corporation + * Copyright © 2017-2018 Raptor Engineering, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -169,6 +170,13 @@ void Manager::doInit() startFanControlReadyTarget(); } +void Manager::doShutdown() +{ + for (auto& z : _zones) + { + z.second->disableRotors(); + } +} void Manager::startFanControlReadyTarget() { diff --git a/control/manager.hpp b/control/manager.hpp index d5b75fc..a09445b 100644 --- a/control/manager.hpp +++ b/control/manager.hpp @@ -50,6 +50,12 @@ class Manager */ void doInit(); + /** + * Does the fan control and chassis fan shutdown, which + * disables the fans entirely (stops all rotors) + */ + void doShutdown(); + private: /** diff --git a/control/zone.cpp b/control/zone.cpp index 325a5b8..8e665f0 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -1,5 +1,6 @@ /** * Copyright © 2017 IBM Corporation + * Copyright © 2017-2018 Raptor Engineering, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -103,6 +104,14 @@ void Zone::setFullSpeed() } } +void Zone::disableRotors() +{ + for (auto& fan : _fans) + { + fan->disableRotor(); + } +} + void Zone::setActiveAllow(const Group* group, bool isActiveAllow) { _active[*(group)] = isActiveAllow; diff --git a/control/zone.hpp b/control/zone.hpp index cd7e5d6..2185afa 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -19,11 +19,13 @@ namespace control * The mode fan control will run in: * - init - only do the initialization steps * - control - run normal control algorithms + * - init - shutdown fans, stopping all rotors */ enum class Mode { init, - control + control, + shutdown }; /** @@ -69,6 +71,12 @@ class Zone */ void setFullSpeed(); + /** + * Disables the zone and stops all zone fans regardless of + * zone's active state + */ + void disableRotors(); + /** * @brief Sets the automatic fan control allowed active state * -- cgit v1.2.1