RDK Documentation (Open Sourced RDK Components)
test_pwrMgr.c
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 /**
22 * @defgroup iarmmgrs
23 * @{
24 * @defgroup test
25 * @{
26 **/
27 
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include "libIBus.h"
33 #include "pwrMgr.h"
34 #include <string.h>
35 static void _eventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
36 {
37 
38 
39  printf("Event handler invoked :: \n");
40  if (strcmp(owner,IARM_BUS_PWRMGR_NAME) == 0)
41  {
42  switch (eventId)
43  {
45  {
46  //IARM_Bus_PWRMgr_SetDeepSleepTimeOut_Param_t *param = (IARM_Bus_PWRMgr_SetDeepSleepTimeOut_Param_t *)data;
47  printf("Time out event called \n");
48  printf("Deep Sleep time out occured \n");
49  }
50  break;
52  {
54  printf("Event IARM_BUS_PWRMGR_EVENT_MODECHANGED: State Changed %d to %d\n",
55  param->data.state.curState, param->data.state.newState);
56  }
57  break;
58 #ifdef ENABLE_THERMAL_PROTECTION
59 
61  {
63  printf("Event IARM_BUS_PWRMGR_EVENT_THERMAL_MODECHANGED: State Changed %d to %d\n \
64  Current temperature is %f ", param->data.therm.curLevel, param->data.therm.newLevel,
65  param->data.therm.curTemperature);
66  }
67  break;
68 #endif //ENABLE_THERMAL_PROTECTION
69 
70  default:
71  break;
72 
73  }
74  }
75 
76 
77 }
78 
79 int main()
80 {
81 
82  IARM_Result_t err;
83  int input;
84  unsigned int timeOut;
85 
86  do{
87  printf("Tring to initialize IARM..\n");
88 
89  err = IARM_Bus_Init("PowerMgrTest");
90 
91  if(IARM_RESULT_SUCCESS != err)
92  {
93  printf("Error initialing IARM bus()... error code : %d\n",err);
94  break;
95  }
96 
97  printf("Trying to connect..\n");
98 
99  err = IARM_Bus_Connect();
100 
101  if(IARM_RESULT_SUCCESS != err)
102  {
103  printf("Error connecting to IARM bus()... error code : %d\n",err);
104  break;
105  }
106  }while(0);
107 
109 #ifdef ENABLE_THERMAL_PROTECTION
111 #endif
113 
114  do{
115  printf("Enter command..\n");
116  printf("c - check power status\n");
117  printf("s - set power status\n");
118  printf("w - warehouse reset the box\n");
119  printf("t - set time out \n");
120 #ifdef ENABLE_THERMAL_PROTECTION
121  printf("v - get current temperature \n");
122  printf("u - set temperature thresholds: \n");
123 #endif
124  printf("x - exit..\n");
125 
126 
127  input = getchar();
128 
129  switch(input)
130  {
131  IARM_Result_t err;
132  /*coverity[unterminated_case]*/
133  case 't':
134  {
136  printf("Enter time out \n :");
137  scanf("%d",&timeOut);
138  param.timeout = timeOut;
141  (void *)&param,
142  sizeof(param));
143  if( err == IARM_RESULT_SUCCESS)
144  {
145  printf("Successfully set the time out \n");
146  }
147  }
148 #ifdef ENABLE_THERMAL_PROTECTION
149  case 'v':
150  {
151  IARM_Bus_PWRMgr_GetThermalState_Param_t param;
153  IARM_BUS_PWRMGR_API_GetThermalState,
154  (void *)&param,
155  sizeof(param));
156  if(err == IARM_RESULT_SUCCESS)
157  {
158  printf("Current level is : (%d), temperature : %f \n",param.curLevel,param.curTemperature);
159  }
160  }
161  break;
162  case 'u':
163  {
164  IARM_Bus_PWRMgr_SetTempThresholds_Param_t param;
165  int temperature;
166  printf("Enter high temperature level \n :");
167  scanf("%d",&temperature);
168  param.tempHigh = temperature;
169  printf("Enter critical temperature level \n :");
170  scanf("%d",&temperature);
171  param.tempCritical = temperature;
172 
174  IARM_BUS_PWRMGR_API_SetTemperatureThresholds,
175  (void *)&param,
176  sizeof(param));
177  if(err == IARM_RESULT_SUCCESS)
178  {
179  printf("Threshold temperature levels updated \n");
180  }
181  }
182  break;
183 #endif
184 
185 
186  /*coverity[fallthrough]*/
187  case 'c':
188  {
192  (void *)&param,
193  sizeof(param));
194  if(err == IARM_RESULT_SUCCESS)
195  {
196  printf("Current state is : (%d)\n",param.curState);
197  }
198  }
199  break;
200  case 's':
201  {
203  int state = 'x';
204  printf("Give a state to set..\n");
205  printf("n - Power on\n");
206  printf("f - Power off\n");
207  printf("b - Standby\n");
208  printf("l - light sleep \n");
209  printf("d - deep sleep \n");
210 
211  while(state != 'n' && state != 'f' && state != 'b' && state != 'l' && state != 'd')
212  {
213  printf("Give a valid state n/f/b/l/d\n");
214  state = getchar();
215  }
216 
217  switch(state)
218  {
219  case 'n': param.newState = IARM_BUS_PWRMGR_POWERSTATE_ON;break;
220  case 'f': param.newState = IARM_BUS_PWRMGR_POWERSTATE_OFF;break;
221  case 'b': param.newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;break;
222  case 'l': param.newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP;break;
223  case 'd': param.newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP;break;
224  }
225 
228  (void *)&param,
229  sizeof(param));
230  if(err == IARM_RESULT_SUCCESS)
231  {
232  printf("Successfully set the state..\n");
233  }
234  }
235  break;
236  case 'w':
237  {
240  NULL, 0);
241  if(err == IARM_RESULT_SUCCESS)
242  {
243  printf("Successfully executed Warehouse reset command..\n");
244  }
245 
246  }
247  break;
248  }
249 
250  }while(input != 'x');
253 #ifdef ENABLE_THERMAL_PROTECTION
255 #endif
257  IARM_Bus_Term();
258 }
259 
260 
261 /** @} */
262 /** @} */
IARM_BUS_PWRMGR_API_SetPowerState
#define IARM_BUS_PWRMGR_API_SetPowerState
Definition: pwrMgr.h:158
IARM_BUS_PWRMGR_NAME
#define IARM_BUS_PWRMGR_NAME
Definition: pwrMgr.h:54
_IARM_Bus_PWRMgr_SetPowerState_Param_t
Structure which holds the new powerstate to be set to the device.
Definition: pwrMgr.h:163
IARM_Bus_Term
IARM_Result_t IARM_Bus_Term(void)
This API is used to terminate the IARM-Bus library.
_IARM_Bus_PWRMgr_GetPowerState_Param_t
Structure which holds the current power state of the CPE.
Definition: pwrMgr.h:173
IARM_Bus_Call
IARM_Result_t IARM_Bus_Call(const char *ownerName, const char *methodName, void *arg, size_t argLen)
This API is used to Invoke RPC method by its application name and method name.
Definition: iarm_bus.c:57
_PWRMgr_EventData_t
Structure which holds the event data.
Definition: pwrMgr.h:117
IARM_BUS_PWRMGR_API_WareHouseReset
#define IARM_BUS_PWRMGR_API_WareHouseReset
Definition: pwrMgr.h:178
IARM_BUS_PWRMGR_API_GetPowerState
#define IARM_BUS_PWRMGR_API_GetPowerState
Definition: pwrMgr.h:168
_IARM_Bus_PWRMgr_SetDeepSleepTimeOut_Param_t::timeout
unsigned int timeout
Definition: pwrMgr.h:199
IARM_Bus_RegisterEventHandler
IARM_Result_t IARM_Bus_RegisterEventHandler(const char *ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler)
This API register to listen to event and provide the callback function for event notification....
Definition: iarmMgrMocks.cpp:43
IARM_Bus_Disconnect
IARM_Result_t IARM_Bus_Disconnect(void)
This API disconnect Application from IARM Bus so the application will not receive any IARM event or R...
IARM_BUS_PWRMGR_API_SetDeepSleepTimeOut
#define IARM_BUS_PWRMGR_API_SetDeepSleepTimeOut
Definition: pwrMgr.h:193
libIBus.h
RDK IARM-Bus API Declarations.
IARM_BUS_PWRMGR_EVENT_MODECHANGED
@ IARM_BUS_PWRMGR_EVENT_MODECHANGED
Definition: pwrMgr.h:60
pwrMgr.h
IARM-Bus Power Manager Public API.
IARM_BUS_PWRMGR_EVENT_DEEPSLEEP_TIMEOUT
@ IARM_BUS_PWRMGR_EVENT_DEEPSLEEP_TIMEOUT
Definition: pwrMgr.h:61
IARM_Bus_Connect
IARM_Result_t IARM_Bus_Connect(void)
This API is used to connect application to the IARM bus daemon. After connected, the application can ...
Definition: iarmMgrMocks.cpp:33
_IARM_Bus_PWRMgr_SetPowerState_Param_t::newState
IARM_Bus_PWRMgr_PowerState_t newState
Definition: pwrMgr.h:164
IARM_Bus_UnRegisterEventHandler
IARM_Result_t IARM_Bus_UnRegisterEventHandler(const char *ownerName, IARM_EventId_t eventId)
This API is used to Remove ALL handlers registered for the given event. This API remove the all the e...
IARM_BUS_PWRMGR_EVENT_THERMAL_MODECHANGED
@ IARM_BUS_PWRMGR_EVENT_THERMAL_MODECHANGED
Definition: pwrMgr.h:64
_IARM_Bus_PWRMgr_SetDeepSleepTimeOut_Param_t
Structure which holds the timeout value to set for Deep sleep.
Definition: pwrMgr.h:198
IARM_Bus_Init
IARM_Result_t IARM_Bus_Init(const char *name)
This API is used to initialize the IARM-Bus library.
Definition: iarmMgrMocks.cpp:38