Power Manager C++

Namespaces

 dpyPowermanager
 Deepsy PowerManager namespace that includes the different enums, structs or method signatures that should be used.
 

Classes

class  Power
 Class which interfaces with the API logic. More...
 
class  PowerClient
 This class allows to interact with the Power Manager Service. More...
 

Detailed Description

PowerManager API related documentation

Here we will give you a quick overview of basic Power Manager capabilities. If you find Power Manager API useful and would like to know more details, please check out further sections of the Power Manager documentation or contact the Deepsy platform team.

Examples

Creating a class object:

std::string ip_address = "127.0.0.1"
Power power(ip_address);


To get the power Manager publication. It is possible to configure what kind of messages that it is wanted to receive.

#include <dpy/powermanagerApi.h>
int our_handler_function(int error_code ,dpyPowermanager::PM_actions pm)
{
std::cout << "Error code: " << error_code;
std::cout << "Power Manager action identity: " << pm.identity;
std::cout << "Power Manager action timestamp: " << pm.timestamp;
std::cout << "Power Manager action: " << pm.action;
std::cout << "Power Manager action cause: " << pm.cause;
}
int main()
{
std::shared_ptr<Power> power = std::make_shared<Power>("127.0.0.1");
power->getPowerStatus_S(&our_handler_function, dpyPowermanager::STARTED_COMPLETED);
}


To send a status request It is possible to request a change in the power status. Every function is used in the same way.

#include <dpy/powermanagerApi.h>
void answer_handler(int error_code)
{
if (error_code == 0) {
std::cout << "\nThe operation was successful";
} else {
std::cout << "\nThe operation was unsuccessful";
}
}
int main()
{
Power power("127.0.0.1");
// shutdown, reboot, standby, abort and critical battery
power.shutdown(&answer_handler);
power.abort(&answer_handler);
//Enabled
power.setAutomaticPM(&answer_handler, 1);
}


Get/Set transition intervals (cancel time and guard time):

#include <dpy/powermanagerApi.h>
#include <iostream>
volatile bool waiting = true;
void transition_intervals_handler(boost::system::error_code &ec, dpyPowermanager::TransitionIntervals transitionIntervals)
{
if (ec) {
std::cout << "\rError : " << ec.message() << std::endl;
} else {
std::cout << "The value of the cancel time is: " << transitionIntervals.cancelTime << std::endl;
std::cout << "The value of the guard time is: " << transitionIntervals.guardTime << std::endl;
}
waiting = false;
}
void answer_sync_pm_handler(boost::system::error_code ec)
{
if (ec.value() == 0) {
std::cout << "\rSynchronous operation performed successfully" << std::endl;
} else {
std::cout << "\r" << ec.message() << std::endl;
}
waiting = false;
}
int main()
{
Power power("127.0.0.1");
waiting = true;
std::cout << "\rReading current transition intervals values" << std::endl;
power.asyncGetTransitionIntervals(transition_intervals_handler);
while (waiting) {
usleep(300000);
}
waiting = true;
usleep(1000000);
std::cout << "\rSetting cancel time to 15 seconds and guard time to 7 seconds" << std::endl;
uint32_t cancelTime, guardTime;
cancelTime = 15;
guardTime = 7;
power.asyncSetTransitionIntervals(answer_sync_pm_handler, cancelTime, guardTime);
while (waiting) {
usleep(300000);
}
waiting = true;
usleep(1000000);
std::cout << "\rReading new transition intervals values" << std::endl;
power.asyncGetTransitionIntervals(transition_intervals_handler);
while (waiting) {
usleep(300000);
}
return 0;
}

Get/Set wakeup time :

#include <dpy/powermanagerApi.h>
#include <iostream>
volatile bool waiting = true;
void print_wakeup_time_handler (boost::system::error_code &ec, struct tm wakeupTime)
{
if (ec) {
std::cout << "\rError : " << ec.message() << std::endl;
} else {
char dateTimeStr[50];
strftime(dateTimeStr, sizeof(dateTimeStr), "%a %b %d %Y %H:%M:%S %Z%z", &wakeupTime);
std::cout << "The wakeup date and time is : " << dateTimeStr << std::endl;
}
waiting = false;
}
void answer_sync_pm_handler(boost::system::error_code ec)
{
if (ec.value() == 0) {
std::cout << "\rSynchronous operation performed successfully" << std::endl;
} else {
std::cout << "\r" << ec.message() << std::endl;
}
waiting = false;
}
int main()
{
Power power("127.0.0.1");
waiting = true;
std::cout << "\rReading current wakeup date and time" << std::endl;
power.asyncGetWakeupTime(print_wakeup_time_handler);
while (waiting) {
usleep(300000);
}
waiting = true;
usleep(1000000);
std::cout << "\rSetting wakeup date and time to Thu Dec 14 2023 17:50:00 (local time)" << std::endl;
struct tm wakeupTime;
wakeupTime.tm_mday = 14;
wakeupTime.tm_mon = 11; //December (months since January)
wakeupTime.tm_year = 2023 - 1900; //years since 1900
wakeupTime.tm_sec = 0;
wakeupTime.tm_min = 50;
wakeupTime.tm_hour = 17;
power.asyncSetWakeupTime(answer_sync_pm_handler, wakeupTime, true);
while (waiting) {
usleep(300000);
}
waiting = true;
usleep(1000000);
std::cout << "\rReading new wakeup date and time" << std::endl;
power.asyncGetWakeupTime(print_wakeup_time_handler);
while (waiting) {
usleep(300000);
}
return 0;
}

Set/Get/Cancel ignition off timeout (OBU shuts down if Ignition button remains off for long time):

#include <dpy/powermanagerApi.h>
#include <iostream>
volatile bool waiting = true;
void print_ignition_off_timeout_handler (boost::system::error_code &ec, int minutes)
{
if (ec) {
std::cout << "\rError : " << ec.message() << std::endl;
} else {
if (minutes == 0) {
std::cout << "The ignition off timeout is cancelled" << std::endl;
} else {
std::cout << "The ignition off timeout is " << minutes << std::endl;
}
}
waiting = false;
}
void answer_async_pm_handler(boost::system::error_code ec)
{
if (ec.value() == 0) {
std::cout << "\rAsynchronous operation performed successfully" << std::endl;
} else {
std::cout << "\r" << ec.message() << std::endl;
}
waiting = false;
}
int main()
{
Power power("127.0.0.1");
waiting = true;
std::cout << "\rSetting Ignition off timeout to 15 minutes" << std::endl;
int32_t ignitionOffMinutes = 15;
power.asyncSetIgnitionOffTimeout(answer_async_pm_handler, ignitionOffMinutes);
while (waiting) {
usleep(300000);
}
waiting = true;
usleep(1000000);
std::cout << "\rReading Ignition off timeout value" << std::endl;
power.asyncGetIgnitionOffTimeout(print_ignition_off_timeout_handler);
while (waiting) {
usleep(300000);
}
waiting = true;
usleep(1000000);
std::cout << "\rCancelling ignition off timeout" << std::endl;
power.asyncCancelIgnitionOffTimeout(answer_async_pm_handler);
while (waiting) {
usleep(300000);
}
waiting = true;
usleep(1000000);
std::cout << "\rReading Ignition off timeout value" << std::endl;
power.asyncGetIgnitionOffTimeout(print_ignition_off_timeout_handler);
while (waiting) {
usleep(300000);
}
return 0;
}