Modules | |
Enumerations | |
Events related with Power Manager | |
Exceptions thrown by Power Manager | |
Classes | |
class | PowerManagerDeepsyService |
Power Manager Deepsy Service. Allows to get the power object and sending commands to the power service More... | |
class | PowerService |
Power service object that allows to request power operations, set configuration and get values. Also allows to get power events | |
class | PowerTimer |
Timers for the power service More... | |
Detailed Description
To work with Deepsy Power service it is necessary to use PowerManagerDeepsyService located in GMV.ITS.HAL.DEEPSY.PowerManager.Facade
PowerManagerDeepsyService has an optional parameter indicating the IP address of remote service. For instance:
To obtain a power object:
PowerManagerDeepsyService is an IDisposable interface. An object that may hold resources (such as file or socket handles) until it is closed. The Dispose() method of an IDisposable object is called automatically when exiting a try-with-resources block, or exiting a using clause where it was declared. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur:
If this object is not inside a try with resources block, it is recommended to call to Dispose() in order to finalize properly;
Examples
-
Get current status
using System;namespace GMV.ITS.HAL.DEEPSY.Examples.PowerManager{class PowerCurrentStatusApp{static void Main(string[] args){PowerManagerDeepsyService powerManagerService = new PowerManagerDeepsyService("192.168.0.144");IPowerManager myPower = powerManagerService.GetPower();PowerStatus.Status status = myPower.GetPowerStatus();Console.WriteLine($"Current power status: {status}");Console.WriteLine($"Current power status: {decodeStatusToString(status)}");}{switch (status){case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.GOING_TO_POWER_OFF:return "GOING_TO_POWER_OFF";case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.GOING_TO_REBOOT:return "GOING_TO_REBOOT";case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.GOING_TO_SLEEP:return "GOING_TO_SLEEP";case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.IDLE:return "IDLE";case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.POWERING_OFF:return "POWERING_OFF";case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.REBOOTING:return "REBOOTING";default:return "SLEEPING";}}}}
-
Make a request and abort it
When you made a request such as REBOOT, SHUTDOWN or STANDBY, it can be cancelled before receiving an event of type COMPLETED_MSG using the Abort() method. It is important to note that when the state of the Power is one of the following: REBOOTING, POWERING_OFF or SLEEPING the request cannot be cancelled.using System;namespace GMV.ITS.HAL.DEEPSY.Examples.PowerManager{class PowerRebootAbortApp{static void Main(string[] args){IPowerManagerService powerManagerService = new PowerManagerDeepsyService("192.168.0.144");IPowerManager myPower = powerManagerService.GetPower();myPower.PowerEvent += MyPower_PowerEvent;PowerStatus.Status status = myPower.GetPowerStatus();Console.WriteLine($"Current power status: {decodeStatusToString(status)} [{status}]");if (status == PowerStatus.Status.IDLE){myPower.Reboot();}status = myPower.GetPowerStatus();Console.WriteLine($"Current power status: {decodeStatusToString(status)} [{status}]");if (status == PowerStatus.Status.GOING_TO_REBOOT){myPower.Abort();}status = myPower.GetPowerStatus();Console.WriteLine($"Current power status: {decodeStatusToString(status)} [{status}]");}private static void MyPower_PowerEvent(object sender, DEEPSY.PowerManager.Interface.Event.IPowerEvent e){}{switch (status){case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.GOING_TO_POWER_OFF:return "GOING_TO_POWER_OFF";case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.GOING_TO_REBOOT:return "GOING_TO_REBOOT";case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.GOING_TO_SLEEP:return "GOING_TO_SLEEP";case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.IDLE:return "IDLE";case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.POWERING_OFF:return "POWERING_OFF";case DEEPSY.PowerManager.Interface.Enum.PowerStatus.Status.REBOOTING:return "REBOOTING";default:return "SLEEPING";}}}}
-
Subscribe to events
PowerEvent : This event happens when the Power change its status PowerStatus . To receive this kind of events, it is necessary to subscribe to the PowerManagerusing System;namespace GMV.ITS.HAL.DEEPSY.Examples.PowerManager{class PowerEventsApp{static void Main(string[] args){PowerManagerDeepsyService powerManagerService = new PowerManagerDeepsyService("192.168.0.144");IPowerManager myPower = powerManagerService.GetPower();myPower.PowerEvent += MyPower_PowerEvent;Console.WriteLine("Press ESC for exit");while (Console.ReadKey().Key != ConsoleKey.Escape){}}private static void MyPower_PowerEvent(object sender, DEEPSY.PowerManager.Interface.Event.IPowerEvent e){Console.WriteLine("Power Event received:");Console.WriteLine($"Timestamp: {e.TimeStamp}");Console.WriteLine($"Cause: {e.PowerCause}");Console.WriteLine($"Action: {e.PowerAction}");Console.WriteLine($"Type: {e.PowerType}");}}}
-
Transition Intervals
cancelTime: seconds within it's possible to abort any power transition request guardTime: seconds after cancel time expires before requested power transition takes effectusing System;namespace GMV.ITS.HAL.DEEPSY.Examples.PowerManager{class TransitionIntervalsApp{static void Main(string[] args){using (PowerManagerDeepsyService powerManagerService = new PowerManagerDeepsyService("192.168.0.144")){IPowerManager myPower = powerManagerService.GetPower();// Get default transition intervalsConsole.WriteLine($"Obtaining default transition intervals:");// Wait for 2 secondsSystem.Threading.Thread.Sleep(2000);IPowerTransitionIntervals intervalsDef = myPower.GetTransitionIntervals();Console.WriteLine($"Cancel Time: {intervalsDef.CancelTime}");Console.WriteLine($"Guard Time: {intervalsDef.GuardTime}");// Wait for 1 secondSystem.Threading.Thread.Sleep(1000);// Set new values for transition intervalsint cancelT = 17;int guardT = 8;Console.WriteLine($"Setting new transition intervals: {cancelT} (cancel), {guardT} (guard)");// Wait for 2 secondsSystem.Threading.Thread.Sleep(2000);PowerTransitionIntervals intervalsNew = new PowerTransitionIntervals(cancelT, guardT);myPower.SetTransitionIntervals(intervalsNew);// Get configured transition intervalsConsole.WriteLine($"Obtaining configured transition intervals:");// Wait for 2 secondsSystem.Threading.Thread.Sleep(2000);IPowerTransitionIntervals intervalsGot = myPower.GetTransitionIntervals();Console.WriteLine($"Cancel Time: " + intervalsGot.CancelTime);Console.WriteLine($"Guard Time: " + intervalsGot.GuardTime);// Wait for 1 secondSystem.Threading.Thread.Sleep(1000);// Restore default transition intervalsConsole.WriteLine($"Setting default transition intervals again: {intervalsDef.CancelTime} (cancel), {intervalsDef.GuardTime} (guard)");myPower.SetTransitionIntervals(intervalsDef);// Wait for 1 secondSystem.Threading.Thread.Sleep(1000);}}}}
-
Wakeup Time
wakeupTime: date and time at which the system will wake up from a shutdown/standby state.using System;namespace GMV.ITS.HAL.DEEPSY.Examples.PowerManager{class PowerWakeupTimeApp{static void Main(string[] args){using (PowerManagerDeepsyService powerManagerService = new PowerManagerDeepsyService("192.168.0.140")){IPowerManager myPower = powerManagerService.GetPower();String dateTimeFormat = "ddd MMM dd yyyy HH:mm:ss";// Get default wakeup timeConsole.WriteLine($"Obtaining default wakeup date and time:");// Wait for 1 secondSystem.Threading.Thread.Sleep(1000);DateTime wakeupTimeDefault = myPower.GetWakeupTime();Console.WriteLine($"Wake up date and time: {wakeupTimeDefault.ToString(dateTimeFormat)}");Console.WriteLine($"Setting wakeup date and time to Thu Dec 14 2023 16:13:00 (local time)");//assigns year, month, day, hour, min, secondsDateTime localWakeupTimeNew = new DateTime(2023, 12, 14, 16, 13, 0, DateTimeKind.Local);myPower.SetWakeupTime(localWakeupTimeNew);Console.WriteLine($"Obtaining configured wakeup date and time:");// Wait for 1 secondSystem.Threading.Thread.Sleep(1000);DateTime wakeupTimeGot = myPower.GetWakeupTime();Console.WriteLine($"Wake up date and time: {wakeupTimeGot.ToString(dateTimeFormat)}");Console.WriteLine($"Setting wakeup date and time to Thu Dec 14 2023 16:13:00 (UTC time)");//assigns year, month, day, hour, min, secondsDateTime utcWakeupTimeNew = new DateTime(2023, 12, 14, 16, 13, 0, DateTimeKind.Utc);myPower.SetWakeupTime(utcWakeupTimeNew);Console.WriteLine($"Obtaining configured wakeup date and time:");// Wait for 1 secondSystem.Threading.Thread.Sleep(1000);wakeupTimeGot = myPower.GetWakeupTime();Console.WriteLine($"Wake up date and time: {wakeupTimeGot.ToString(dateTimeFormat)}");// Restore default wakeup timeConsole.WriteLine($"Setting default wakeup time again: {wakeupTimeDefault.ToString(dateTimeFormat)}");myPower.SetWakeupTime(wakeupTimeDefault);// Wait for 1 secondSystem.Threading.Thread.Sleep(1000);}}}}