46 #ifdef OFFLINE_MAINT_REBOOT
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50 #include <sys/types.h>
52 #include <sys/ioctl.h>
61 #include "comcastIrKeyCodes.h"
63 #include "plat_power.h"
66 #include "libIBusDaemon.h"
71 #include "pwrlogger.h"
73 #include "resetModes.h"
76 #include "deepSleepMgr.h"
77 #include "productTraits.h"
78 #include "exception.hpp"
84 static void _speechEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
85 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
86 #include "ctrlm_ipc.h"
87 #include "ctrlm_ipc_rcu.h"
88 static void _ctrlmMessageHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
90 #ifdef USE_UNIFIED_RF4CE_MGR_API_4
91 #include "vrexMgrApi.h"
95 #ifdef RF4CE_GENMSO_API
97 static void _rfMessageHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
98 #elif defined(RF4CE_API)
100 static void _rf4ceMessageHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
101 #elif defined(RF4CE_GPMSO_API)
102 #include "rf4ceMgr.h"
103 static void _gpMessageHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
105 #warning "No RF4CE API defined"
110 #define PADDING_SIZE 32
111 #define _UIMGR_SETTINGS_MAGIC 0xFEBEEFAC
114 unsigned int brightness;
122 volatile IARM_Bus_PWRMgr_PowerState_t powerState;
124 #ifdef ENABLE_DEEP_SLEEP
125 uint32_t deep_sleep_timeout;
127 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
130 char padding[PADDING_SIZE];
133 typedef enum _UIDev_PowerState_t {
134 UIDEV_POWERSTATE_OFF,
135 UIDEV_POWERSTATE_STANDBY,
137 UIDEV_POWERSTATE_UNKNOWN
138 } UIDev_PowerState_t;
144 UIDev_PowerState_t powerState;
145 char padding[PADDING_SIZE];
149 static const char *m_settingsFile = NULL;
150 static bool isCecLocalLogicEnabled =
false;
152 #define MAX_NUM_VIDEO_PORTS 5
160 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
161 #ifndef POWER_KEY_SENSITIVITY
162 #define POWER_KEY_SENSITIVITY 500
164 static struct timeval powerKeyIntervals[] = {
171 #define PWRMGR_SET_POWER_KEYDOWN_TM() do\
173 if (POWER_KEY_SENSITIVITY) {\
174 struct timeval __tv;\
175 gettimeofday(&__tv, NULL);\
176 printf("[POWERKEY-DOWN][%ld\[%d]\r\n", __tv.tv_sec, __tv.tv_usec);\
178 powerKeyIntervals[0] = (__tv);\
179 powerKeyIntervals[1].tv_sec = 0;\
180 powerKeyIntervals[1].tv_usec = 0;\
184 #define PWRMGR_SET_POWER_KEYUP_TM() do\
186 if (POWER_KEY_SENSITIVITY && powerKeyIntervals[0].tv_sec != 0) {\
187 struct timeval __tv;\
188 gettimeofday(&__tv, NULL);\
189 printf("[POWERKEY-UP ][%ld\[%d]\r\n", __tv.tv_sec, __tv.tv_usec);\
191 powerKeyIntervals[1] = (__tv);\
197 #define TIMEVAL_DIFF(t2,t1) ((int)(((((int)(t2.tv_sec - t1.tv_sec)) - 1) * 1000) + (((1000*1000 + t2.tv_usec) - t1.tv_usec)/1000)))
198 #define PWRMGR_GET_POWER_KEY_INTERVAL() \
199 (((powerKeyIntervals[1].tv_sec) && (powerKeyIntervals[1].tv_sec >= powerKeyIntervals[0].tv_sec)) ?\
200 (TIMEVAL_DIFF(powerKeyIntervals[1], powerKeyIntervals[0])) :\
201 (POWER_KEY_SENSITIVITY))
203 static volatile IARM_Bus_PWRMgr_PowerState_t transitionState;
204 static volatile IARM_Bus_PWRMgr_PowerState_t targetState;
206 static pthread_cond_t powerStateCond = PTHREAD_COND_INITIALIZER;
207 static pthread_mutex_t powerStateMutex = PTHREAD_MUTEX_INITIALIZER;
208 static pthread_t asyncPowerThreadId = NULL;
210 static void _SetPowerStateAsync(IARM_Bus_PWRMgr_PowerState_t curState, IARM_Bus_PWRMgr_PowerState_t newState);
212 static pthread_mutex_t wareHouseOpsMutex = PTHREAD_MUTEX_INITIALIZER;
213 static pthread_t asyncPowerWarehouseOpsThreadId = NULL;
216 static void _sleepModeChangeHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
217 static void _controlEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
218 static void _irEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
219 static void _systemStateChangeHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
220 static IARM_Result_t _SetPowerState(
void *arg);
221 static IARM_Result_t _GetPowerState(
void *arg);
222 static IARM_Result_t _WareHouseReset(
void *arg);
223 static IARM_Result_t _WareHouseClear(
void *arg);
224 static IARM_Result_t _ColdFactoryReset(
void *);
225 static IARM_Result_t _FactoryReset(
void *);
226 static IARM_Result_t _UserFactoryReset(
void *);
227 static IARM_Result_t _GetPowerStateBeforeReboot(
void *arg);
228 static IARM_Result_t _HandleReboot(
void *arg);
229 #ifdef ENABLE_SET_WAKEUP_SRC_CONFIG
230 static IARM_Result_t _SetWakeupSrcConfig(
void *arg);
231 #endif //ENABLE_SET_WAKEUP_SRC_CONFIG
232 static IARM_Result_t _handleDeepsleepTimeoutWakeup(
void *arg);
233 static void handleDeepsleepTimeoutWakeup (
void * arg);
234 static void* deepsleepTimeoutWakeupThread (
void * arg);
236 static int _InitSettings(
const char *settingsFile);
237 static int _WriteSettings(
const char *settingsFile);
240 static int _SetLEDStatus(IARM_Bus_PWRMgr_PowerState_t state);
242 int _SetAVPortsPowerState(IARM_Bus_PWRMgr_PowerState_t powerState);
243 static IARM_Bus_PWRMgr_PowerState_t _ConvertUIDevToIARMBusPowerState(UIDev_PowerState_t powerState);
244 static IARM_Result_t _SetStandbyVideoState(
void *arg);
245 static IARM_Result_t _GetStandbyVideoState(
void *arg);
246 static int ecm_connectivity_lost = 0;
249 static bool deepSleepWakeup =
false;
250 extern void IARM_Bus_PWRMGR_RegisterSleepTimerAPIs(
void *);
254 static IARM_Bus_Daemon_SysMode_t isEASInProgress = IARM_BUS_SYS_MODE_NORMAL;
257 GMainLoop *pwrMgr_Gloop = NULL;
258 static gboolean heartbeatMsg(gpointer data);
259 std::string powerStateBeforeReboot_gc;
260 static IARM_Bus_PWRMgr_PowerState_t g_last_known_power_state = IARM_BUS_PWRMGR_POWERSTATE_ON;
261 #ifdef ENABLE_DEEP_SLEEP
266 static IARM_Result_t _SetDeepSleepTimeOut(
void *arg);
269 static gboolean deep_sleep_wakeup_fn(gpointer data);
272 static uint32_t getWakeupTime();
275 static gboolean invoke_deep_sleep_on_bootup_timeout(gpointer data);
278 static uint32_t deep_sleep_wakeup_timeout_sec = 28800;
279 static uint8_t IsWakeupTimerSet = 0;
280 static guint wakeup_event_src = 0;
281 static guint dsleep_bootup_event_src = 0;
282 static time_t timeAtDeepSleep = 0;
284 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
285 static bool nwStandbyMode_gs =
false;
288 #ifdef OFFLINE_MAINT_REBOOT
289 gint64 standby_time = 0;
290 static bool rfcUpdated =
false;
291 static int standby_reboot_threshold = 86400*3;
292 static int force_reboot_threshold = 172800*3;
294 #define MAX_RFC_LEN 15
296 #define UPTIME_ABOVE_STANDBY_REBOOT(time) (time >= standby_reboot_threshold)
297 #define UPTIME_ABOVE_FORCE_REBOOT(time) (time >= force_reboot_threshold)
298 #define REBOOT_GRACE_INTERVAL(u, s) ((u - s) >= 900)
300 #define STANDBY_REBOOT_ENABLE "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.StandbyReboot.Enable"
301 #define STANDBY_REBOOT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.StandbyReboot.StandbyAutoReboot"
302 #define FORCE_REBOOT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.StandbyReboot.ForceAutoReboot"
305 static IARM_Result_t _SetNetworkStandbyMode(
void *arg);
306 static IARM_Result_t _GetNetworkStandbyMode(
void *arg);
308 static void setPowerStateBeforeReboot (IARM_Bus_PWRMgr_PowerState_t powerState) {
309 switch (powerState) {
310 case IARM_BUS_PWRMGR_POWERSTATE_OFF:
311 powerStateBeforeReboot_gc = std::string (
"OFF");
313 case IARM_BUS_PWRMGR_POWERSTATE_STANDBY:
314 powerStateBeforeReboot_gc = std::string (
"STANDBY");
316 case IARM_BUS_PWRMGR_POWERSTATE_ON:
317 powerStateBeforeReboot_gc = std::string (
"ON");
319 case IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP:
320 powerStateBeforeReboot_gc = std::string (
"LIGHT_SLEEP");
322 case IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP:
323 powerStateBeforeReboot_gc = std::string (
"DEEP_SLEEP");
326 powerStateBeforeReboot_gc = std::string (
"UNKNOWN");
329 printf (
"[%s]:[%d] powerStateBeforeReboot: %s \n", __FUNCTION__, __LINE__, powerStateBeforeReboot_gc.c_str());
332 static bool get_video_port_standby_setting(
const char * port)
336 __TIMESTAMP();LOG(
"Error! Port name is NULL!\n");
339 for(
int i = 0; i < MAX_NUM_VIDEO_PORTS; i++)
343 return g_standby_video_port_setting[i].isEnabled;
349 IARM_Result_t PWRMgr_Start(
int argc,
char *argv[])
351 char *settingsFile = NULL;
354 if (argc == 2) settingsFile = argv[1];
356 setvbuf(stdout, NULL, _IOLBF, 0);
359 #ifdef POWERMGR_PRODUCT_PROFILE_ID
360 if(
true == pwrMgrProductTraits::ux_controller::initialize_ux_controller(POWERMGR_PRODUCT_PROFILE_ID))
362 ux = pwrMgrProductTraits::ux_controller::get_instance();
367 LOG(
"pwrmgr product traits not supported.\n");
380 LOG(
"Exception Caught during [device::Manager::Initialize]\r\n");
383 _InitSettings(settingsFile);
384 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
385 transitionState = m_settings.powerState;
386 targetState = m_settings.powerState;
400 #ifdef ENABLE_DEEP_SLEEP
414 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
420 #ifdef USE_UNIFIED_RF4CE_MGR_API_4
427 #ifdef RF4CE_GENMSO_API
429 #elif defined(RF4CE_API)
431 #elif defined(RF4CE_GPMSO_API)
434 #warning "No RF4CE API defined"
445 #ifdef ENABLE_SET_WAKEUP_SRC_CONFIG
447 #endif //ENABLE_SET_WAKEUP_SRC_CONFIG
449 #ifdef ENABLE_THERMAL_PROTECTION
450 initializeThermalProtection();
451 #endif //ENABLE_THERMAL_PROTECTION
454 pwrMgr_Gloop = g_main_loop_new ( NULL , FALSE );
455 if(pwrMgr_Gloop != NULL){
456 g_timeout_add_seconds (300 , heartbeatMsg , pwrMgr_Gloop);
462 IARM_Bus_PWRMGR_RegisterSleepTimerAPIs(pwrMgr_Gloop);
463 RFC_ParamData_t rfcParam;
464 WDMP_STATUS status = getRFCParameter(
"TestComponent",
"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.CECLocalLogic.Enable", &rfcParam);
465 if(strncmp(rfcParam.value,
"true",4) == 0)
467 isCecLocalLogicEnabled=
true;
468 LOG(
"pwrMgr:RFC CEC Local Logic feature enabled \r\n");
470 char *rdk_deep_sleep_wakeup = getenv(
"RDK_DEEPSLEEP_WAKEUP_ON_POWER_BUTTON");
471 deepSleepWakeup = (rdk_deep_sleep_wakeup && atoi(rdk_deep_sleep_wakeup));
476 printf (
"initial value m_sleepMode:%d \n", m_sleepMode);
480 LOG(
"PwrMgr: Exception coughht while processing getPreferredSleepMode\r\n");
482 return IARM_RESULT_SUCCESS;
485 IARM_Result_t PWRMgr_Loop()
491 g_main_loop_run (pwrMgr_Gloop);
492 g_main_loop_unref(pwrMgr_Gloop);
494 return IARM_RESULT_SUCCESS;
497 #ifdef OFFLINE_MAINT_REBOOT
498 bool isStandbyRebootEnabled()
500 RFC_ParamData_t rfcParam;
501 char* key = STANDBY_REBOOT_ENABLE;
502 if (WDMP_SUCCESS == getRFCParameter(
"PwrMgr", key, &rfcParam))
504 return (strncasecmp(rfcParam.value,
"true", 4) == 0);
510 int getStandbyRebootValue(
char* key)
512 RFC_ParamData_t param;
513 char rfcVal[MAX_RFC_LEN+1] = {0};
516 if (WDMP_SUCCESS == getRFCParameter(
"PwrMgr", key, ¶m))
518 len = strlen(param.value);
519 if (len > MAX_RFC_LEN)
524 if ( (param.value[0] ==
'"') && (param.value[len] ==
'"'))
526 strncpy (rfcVal, ¶m.value[1], len - 1);
531 strncpy (rfcVal, param.value, MAX_RFC_LEN-1);
544 return ((stat(
"/tmp/addressaquired_ipv4", &buf) != 0)
545 && (stat(
"/tmp/addressaquired_ipv6", &buf) != 0));
548 struct ifaddrs *ifAddr, *ifAddrIt;
552 for (ifAddrIt = ifAddr; ifAddrIt != NULL; ifAddrIt = ifAddrIt->ifa_next)
554 if (NULL != ifAddrIt->ifa_addr
555 && (!strcmp(ifAddrIt->ifa_name,
"eth0:0") || !strcmp(ifAddrIt->ifa_name,
"wlan0:0")))
557 LOG(
"ifa_name=%s sa_family=%s ifa_flags=0x%X\n",
559 ifAddrIt->ifa_addr->sa_family == AF_INET?
"AF_INET" : ifAddrIt->ifa_addr->sa_family == AF_INET6?
"AF_INET6" :
"None",
560 (ifAddrIt->ifa_flags & IFF_RUNNING) );
563 if (NULL != ifAddrIt->ifa_addr
564 && (ifAddrIt->ifa_addr->sa_family == AF_INET || ifAddrIt->ifa_addr->sa_family == AF_INET6)
565 && (!strcmp(ifAddrIt->ifa_name,
"eth0:0") || !strcmp(ifAddrIt->ifa_name,
"wlan0:0"))
566 && (ifAddrIt->ifa_flags & IFF_RUNNING))
579 IARM_Bus_PWRMgr_PowerState_t curState = pSettings->powerState;
580 LOG(
"%s PowerState = %d\n", __func__, curState);
581 return (curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY
582 || curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP);
588 static gboolean heartbeatMsg(gpointer data)
592 LOG(
"I-ARM POWER Mgr: HeartBeat at %s\r\n", ctime(&curr));
594 #ifdef OFFLINE_MAINT_REBOOT
597 LOG(
"StandbyReboot.Enable = %s\n", isStandbyRebootEnabled() ?
"true" :
"false");
599 standby_reboot_threshold = getStandbyRebootValue(STANDBY_REBOOT);
600 if (standby_reboot_threshold == -1)
602 standby_reboot_threshold = 86400*3;
604 LOG(
"StandbyReboot.StandbyAutoReboot = %d\n", standby_reboot_threshold);
606 force_reboot_threshold = getStandbyRebootValue(FORCE_REBOOT);
607 if (force_reboot_threshold == -1)
609 force_reboot_threshold = 172800*3;
611 LOG(
"StandbyReboot.ForceAutoReboot = %d\n", force_reboot_threshold);
615 if (isStandbyRebootEnabled())
617 gint64 uptime = g_get_monotonic_time()/G_USEC_PER_SEC;
618 if (UPTIME_ABOVE_STANDBY_REBOOT(uptime))
620 if (REBOOT_GRACE_INTERVAL(uptime, standby_time) && isInStandby())
622 LOG(
"Going to reboot after %lld\n", uptime);
624 system(
"sh /rebootNow.sh -s PwrMgr -r 'Standby Maintenance reboot' -o 'Standby Maintenance reboot'");
627 if (UPTIME_ABOVE_FORCE_REBOOT(uptime))
629 LOG(
"Going to reboot after %lld\n", uptime);
631 system(
"sh /rebootNow.sh -s PwrMgr -r 'Forced Maintenance reboot' -o 'Forced Maintenance reboot'");
641 IARM_Result_t PWRMgr_Stop(
void)
646 g_main_loop_quit(pwrMgr_Gloop);
653 LOG(
"Exception Caught during [device::Manager::Initialize]\r\n");
658 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
664 #ifdef USE_UNIFIED_RF4CE_MGR_API_4
671 #ifdef RF4CE_GENMSO_API
673 #elif defined(RF4CE_API)
675 #elif defined(RF4CE_GPMSO_API)
678 #warning "No RF4CE API defined"
686 return IARM_RESULT_SUCCESS;
689 void _sleepModeChangeHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
691 if (strcmp(owner,IARM_BUS_DSMGR_NAME) == 0)
697 m_sleepMode = eventData->data.sleepModeInfo.sleepMode;
698 printf(
"%s m_sleepMode :%d \n",__FUNCTION__,m_sleepMode);
708 static void _systemStateChangeHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
714 unsigned long secs = 0;
715 IARM_Bus_SYSMgr_SystemState_t stateId = sysEventData->data.systemStates.stateId;
716 state = sysEventData->data.systemStates.state;
717 error = sysEventData->data.systemStates.error;
723 case IARM_BUS_SYSMGR_SYSSTATE_DSG_CA_TUNNEL:
724 case IARM_BUS_SYSMGR_SYSSTATE_ECM_IP:
727 fp = fopen(
"/proc/uptime",
"r");
730 setvbuf(fp, (
char *) NULL, _IONBF, 0);
731 fseek(fp, 0, SEEK_SET);
732 if(0 > fscanf(fp,
"%ld", &secs))
734 LOG(
"Error: fscanf on uptime failed \r\n");
736 ecm_connectivity_lost = 1;
742 LOG(
"Error: fopen on uptime failed \r\n");
744 ecm_connectivity_lost = 1;
749 if(0 == ecm_connectivity_lost)
751 if (stateId == IARM_BUS_SYSMGR_SYSSTATE_ECM_IP)
753 LOG(
"[PwrMgr] ECM connectivity Lost on ECM_IP Event..\r\n");
754 ecm_connectivity_lost = 1;
756 else if ((stateId == IARM_BUS_SYSMGR_SYSSTATE_DSG_CA_TUNNEL) && (0 == state))
758 LOG(
"[PwrMgr] ECM connectivity Lost on DSG_CA_TUNNEL Event ..\r\n");
759 ecm_connectivity_lost = 1;
767 if(1 == ecm_connectivity_lost)
769 if (stateId == IARM_BUS_SYSMGR_SYSSTATE_ECM_IP)
771 LOG(
"[PwrMgr] ECM connectivity recovered on ECM_IP Event..\r\n");
772 ecm_connectivity_lost = 0;
774 else if ((stateId == IARM_BUS_SYSMGR_SYSSTATE_DSG_CA_TUNNEL) && (2 == state))
776 LOG(
"[PwrMgr] ECM connectivity recovered on DSG_CA_TUNNEL Event..\r\n");
777 ecm_connectivity_lost = 0;
789 static void _irEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
793 int keyCode = irEventData->data.irkey.keyCode;
794 int keyType = irEventData->data.irkey.keyType;
795 int isFP = irEventData->data.irkey.isFP;
803 LOG(
"Unexpected Key type recieved %X\r\n",
keyType);
808 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
809 if( (
keyType == KET_KEYDOWN) && (keyCode == KED_FP_POWER))
811 PWRMGR_SET_POWER_KEYDOWN_TM();
815 if( (
keyType == KET_KEYUP) && (keyCode == KED_FP_POWER) && isFP && ecm_connectivity_lost )
818 LOG(
"[PwrMgr] Rebooting the box due to ECM connectivity Loss ..\r\n");
819 m_settings.powerState = IARM_BUS_PWRMGR_POWERSTATE_ON;
820 _WriteSettings(m_settingsFile);
821 PwrMgr_Reset(IARM_BUS_PWRMGR_POWERSTATE_ON,
false);
828 IARM_Bus_PWRMgr_PowerState_t curState = pSettings->powerState;
829 IARM_Bus_PWRMgr_PowerState_t newState = ((curState == IARM_BUS_PWRMGR_POWERSTATE_ON) ? IARM_BUS_PWRMGR_POWERSTATE_STANDBY : IARM_BUS_PWRMGR_POWERSTATE_ON);
830 #ifdef ENABLE_LLAMA_PLATCO
832 if(curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP && keyCode != KED_DEEPSLEEP_WAKEUP)
834 LOG(
" Ignoring the IR Events in Deepsleep Mode ..\r\n");
839 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
843 if (( (
keyType == KET_KEYUP) && (keyCode == KED_DISCRETE_POWER_ON) && (newState == IARM_BUS_PWRMGR_POWERSTATE_ON) ) ||
844 ((
keyType == KET_KEYUP) && (keyCode == KED_DISCRETE_POWER_STANDBY) && (newState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY)))
847 LOG(
"Setting Discrete Powerstate cur=%d,new=%d\r\n", curState, newState);
850 _SetPowerState((
void *)¶m);
857 if (keyCode == KED_UNDEFINEDKEY)
861 static int skipWakupKey = 0;
863 int isPassthruKey= 0;
864 static const int passthruKeys[] = {
873 static const int skipWakeupKeys[] = {
877 KED_DISCRETE_POWER_ON,
878 KED_DISCRETE_POWER_STANDBY,
889 static const char *keytypeString[3] = {
"Pressed",
"Released",
"Repeat"};
891 #ifdef _ENABLE_WAKEUP_KEY
894 for (i = 0; i <
sizeof(passthruKeys) /
sizeof(passthruKeys[0]); i++) {
895 if (keyCode == passthruKeys[i]) {
901 for (i = 0; i <
sizeof(skipWakeupKeys) /
sizeof(skipWakeupKeys[0]); i++) {
902 if (keyCode == skipWakeupKeys[i]) {
916 __TIMESTAMP();LOG(
"%s Power %s\n",((isFP == 1) ?
"FrontPanel":
"RF/IR"),keytypeString[((
keyType>>8)-0x80)]);
919 #ifdef _DISABLE_KEY_POWEROFF
920 const int disableFPResetLogic = 1;
922 const int disableFPResetLogic = 0;
925 if (disableFPResetLogic && keyCode == KED_FP_POWER && isFP) {
926 printf(
"Disable FP Reset Logic\r\n");
929 static const int skipControlKeys[] = {
935 bool is_control_key =
false;
936 for (
int i = 0; i <
sizeof(skipControlKeys) /
sizeof(skipControlKeys[0]); ++i) {
937 if (keyCode == skipControlKeys[i]) {
938 is_control_key =
true;
942 if (!is_control_key) {
943 resetState = checkResetSequence(
keyType,keyCode);
946 __TIMESTAMP();LOG(
"Control Key (%02x, %02x), do not check Reset sequence", keyCode,
keyType);
952 if ((keyCode == KED_FP_POWER) || (keyCode == KED_RF_POWER) || isWakeupKey)
956 IARM_Bus_PWRMgr_PowerState_t curState = pSettings->powerState;
957 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
958 if (POWER_KEY_SENSITIVITY) {
959 curState = transitionState;
962 IARM_Bus_PWRMgr_PowerState_t newState;
965 newState = ((curState == IARM_BUS_PWRMGR_POWERSTATE_ON) ? IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP: IARM_BUS_PWRMGR_POWERSTATE_ON);
969 newState = ((curState == IARM_BUS_PWRMGR_POWERSTATE_ON) ? IARM_BUS_PWRMGR_POWERSTATE_STANDBY : IARM_BUS_PWRMGR_POWERSTATE_ON);
971 if((keyCode == KED_DEEPSLEEP_WAKEUP) && (
keyType == KET_KEYUP) && (curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP))
973 #ifdef PLATCO_BOOTTO_STANDBY
974 newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
975 LOG(
"KED_DEEPSLEEP_WAKEUP in DEEP_SLEEP so change the state to STANDBY cur=%d,new=%d\r\n", curState, newState);
977 newState = IARM_BUS_PWRMGR_POWERSTATE_ON;
978 LOG(
"KED_DEEPSLEEP_WAKEUP in DEEP_SLEEP so change the state to ON cur=%d,new=%d\r\n", curState, newState);
981 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
990 if (isWakeupKey &&
keyType == KET_KEYDOWN) {
991 if (curState != IARM_BUS_PWRMGR_POWERSTATE_ON) {
1000 #ifdef _DISABLE_KEY_POWEROFF
1001 const int disableKeyPowerOff = 1;
1003 const int disableKeyPowerOff = 0;
1006 #ifdef _ENABLE_WAKEUP_KEY
1008 if (((keyCode == KED_RF_POWER || isWakeupKey) && curState != IARM_BUS_PWRMGR_POWERSTATE_ON && (keyCode == KED_SELECT ? difftime(time(NULL), xre_timer) >= 3.0:1)) || (keyCode == KED_FP_POWER))
1011 if ((keyCode == KED_RF_POWER) || (isWakeupKey && curState != IARM_BUS_PWRMGR_POWERSTATE_ON && (keyCode == KED_SELECT ? difftime(time(NULL), xre_timer) >= 3.0:1)) || (keyCode == KED_FP_POWER))
1014 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
1015 LOG(
"before handling Power Manager Settings State vs new State(%x, %x) transition state %x \r\n", curState, newState, transitionState);
1018 if (
keyType == KET_KEYUP && curState != newState && (resetState == 0)) {
1019 LOG(
"Setting Powerstate cur=%d,new=%d\r\n", curState, newState);
1023 int doNothandlePowerKey = ((disableKeyPowerOff) && (curState == IARM_BUS_PWRMGR_POWERSTATE_ON) && (newState != IARM_BUS_PWRMGR_POWERSTATE_ON));
1024 if ((deepSleepWakeup) && (curState != IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP)){
1025 doNothandlePowerKey = 1;
1026 LOG(
"RDK_DEEPSLEEP_WAKEUP_ON_POWER_BUTTON is set, power-ON only from DEEPSLEEP\r\n");
1029 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
1030 if (doNothandlePowerKey) {
1031 printf(
"Ignore Power Key when in ON state \r\n");
1035 PWRMGR_SET_POWER_KEYUP_TM();
1036 if (PWRMGR_GET_POWER_KEY_INTERVAL() >= POWER_KEY_SENSITIVITY) {
1037 LOG(
"Taking PowerKey for Sensitivity %d, cur=%d,new=%d\r\n", PWRMGR_GET_POWER_KEY_INTERVAL(), curState, newState);
1038 _SetPowerStateAsync(curState, newState);
1041 LOG(
"Ignoring PowerKey for Sensitivity %d, cur=%d,new=%d\r\n", PWRMGR_GET_POWER_KEY_INTERVAL(), curState, newState);
1045 if (!doNothandlePowerKey) {
1046 _SetPowerState((
void *)¶m);
1049 if (!doNothandlePowerKey) {
1050 setResetPowerState(newState);
1054 LOG(
"NOT NOT NOT Setting Powerstate cur=%d,new=%d on keyType %x\r\n", curState, newState,
keyType);
1067 static IARM_Result_t _SetPowerState(
void *arg)
1069 IARM_Result_t retCode = IARM_RESULT_SUCCESS;
1072 IARM_Bus_CommonAPI_PowerPreChange_Param_t powerPreChangeParam;
1073 IARM_Bus_PWRMgr_PowerState_t newState = param->
newState;
1074 IARM_Bus_PWRMgr_PowerState_t curState = pSettings->powerState;
1075 static const char *powerstateString[5] = {
"OFF",
"STANDBY",
"ON",
"LIGHTSLEEP",
"DEEPSLEEP"};
1077 if(curState != newState) {
1079 #ifdef ENABLE_DEEP_SLEEP
1085 if(dsleep_bootup_event_src)
1087 g_source_remove(dsleep_bootup_event_src);
1088 dsleep_bootup_event_src = 0;
1089 __TIMESTAMP();LOG(
"Removed Deep sleep boot up event Time source %d \r\n",dsleep_bootup_event_src);
1092 if( (IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP == curState)
1093 && (IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP != newState))
1095 IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
1098 (
char *)
"GetDeepSleepStatus",
1103 LOG(
"%s deepsleep in progress ignoreing the request dsStatus %d rpcRet :%d\r\n",__FUNCTION__,dsStatus,rpcRet);
1106 IARM_Bus_CommonAPI_PowerPreChange_Param_t deepSleepWakeupParam;
1108 __TIMESTAMP();LOG(
"Waking up from Deep Sleep.. \r\n");
1109 deepSleepWakeupParam.curState = curState;
1110 deepSleepWakeupParam.newState = newState;
1113 IARM_BusDaemon_DeepSleepWakeup(deepSleepWakeupParam);
1117 __TIMESTAMP();LOG(
"Power Mode Change from %s to %s start\n",powerstateString[curState],powerstateString[newState]);
1119 powerPreChangeParam.newState = param->
newState;
1120 powerPreChangeParam.curState = pSettings->powerState;
1122 IARM_BusDaemon_PowerPrechange(powerPreChangeParam);
1123 __TIMESTAMP();LOG(
"Power Mode Change from %s to %s end\n",powerstateString[curState],powerstateString[newState]);
1126 ux->applyPowerStateChangeConfig(newState, curState);
1128 _SetAVPortsPowerState(newState);
1129 _SetLEDStatus(newState);
1131 #ifdef OFFLINE_MAINT_REBOOT
1132 if(newState != IARM_BUS_PWRMGR_POWERSTATE_ON){
1134 standby_time = g_get_monotonic_time()/G_USEC_PER_SEC;
1135 LOG(
"Power state changed at %lld\n", standby_time);
1139 pSettings->powerState = newState;
1140 _WriteSettings(m_settingsFile);
1141 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
1142 if(transitionState != newState)
1144 transitionState = newState;
1146 if(targetState != newState)
1148 targetState = newState;
1151 #ifndef ENABLE_LLAMA_PLATCO
1152 if (newState != IARM_BUS_PWRMGR_POWERSTATE_ON) {
1154 LOG(
"Invoking clean up script\r\n");
1155 if(param->
keyCode != KED_FP_POWER)
1157 system(
"/lib/rdk/standbyCleanup.sh");
1161 __TIMESTAMP();LOG(
"Standby operation due to KED_FP_POWER key press, Invoking script with forceShutdown \r\n");
1162 system(
"/lib/rdk/standbyCleanup.sh --forceShutdown");
1172 LOG(
"[PwrMgr] Post Power Mode Change Event \r\n");
1175 _eventData.data.state.curState = curState;
1176 _eventData.data.state.newState = newState;
1178 #ifdef ENABLE_DEEP_SLEEP
1179 if(IsWakeupTimerSet)
1182 _eventData.data.state.deep_sleep_timeout = deep_sleep_wakeup_timeout_sec;
1187 deep_sleep_wakeup_timeout_sec = getWakeupTime();
1188 _eventData.data.state.deep_sleep_timeout = deep_sleep_wakeup_timeout_sec;
1191 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1192 _eventData.data.state.nwStandbyMode = nwStandbyMode_gs;
1199 if(IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP == newState)
1208 time(&timeAtDeepSleep);
1209 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1210 #ifndef USE_WAKEUP_TIMER_EVT
1211 wakeup_event_src = g_timeout_add_seconds ((guint)1, deep_sleep_wakeup_fn, pwrMgr_Gloop);
1213 __TIMESTAMP();LOG(
"deep_sleep_wakeup_fn is not running\r\n");
1215 __TIMESTAMP();LOG(
"Networkstandbymode for Source %d is: %s \r\n",wakeup_event_src, (nwStandbyMode_gs?(
"Enabled"):(
"Disabled")));
1217 wakeup_event_src = g_timeout_add_seconds ((guint)30, deep_sleep_wakeup_fn, pwrMgr_Gloop);
1219 __TIMESTAMP();LOG(
"Added Deep Sleep Wakeup Time Source %d for %d Sec \r\n",wakeup_event_src,deep_sleep_wakeup_timeout_sec);
1222 else if(wakeup_event_src)
1225 __TIMESTAMP();LOG(
"Removed Deep sleep Wakeup Time source %d for %d Sec.. \r\n",wakeup_event_src,deep_sleep_wakeup_timeout_sec);
1226 g_source_remove(wakeup_event_src);
1227 wakeup_event_src = 0;
1228 timeAtDeepSleep = 0;
1233 if(IARM_BUS_PWRMGR_POWERSTATE_ON == newState)
1235 __TIMESTAMP();LOG(
"IARMCEC_SendCECImageViewOn and IARMCEC_SendCECActiveSource. \r\n");
1244 LOG(
"Warning:PowerState is same as requested\r\n");
1250 static IARM_Result_t _GetPowerState(
void *arg)
1254 param->
curState = pSettings->powerState;
1256 return IARM_RESULT_SUCCESS;
1259 static IARM_Result_t _GetPowerStateBeforeReboot(
void *arg)
1263 strncpy (param->
powerStateBeforeReboot, powerStateBeforeReboot_gc.c_str(), strlen(powerStateBeforeReboot_gc.c_str()));
1264 return IARM_RESULT_SUCCESS;
1268 static IARM_Result_t _HandleReboot(
void *arg)
1271 param->reboot_reason_custom[
sizeof(param->reboot_reason_custom) - 1] =
'\0';
1272 param->reboot_reason_custom[
sizeof(param->reboot_reason_other) - 1] =
'\0';
1273 param->requestor[
sizeof(param->requestor) - 1] =
'\0';
1277 if(0 == strncmp(PWRMGR_REBOOT_REASON_MAINTENANCE, param->reboot_reason_custom,
sizeof(param->reboot_reason_custom)))
1278 ux->applyPreMaintenanceRebootConfig(m_settings.powerState);
1280 ux->applyPreRebootConfig(m_settings.powerState);
1282 performReboot(param->requestor, param->reboot_reason_custom, param->reboot_reason_other);
1283 return IARM_RESULT_SUCCESS;
1286 #ifdef ENABLE_SET_WAKEUP_SRC_CONFIG
1287 static IARM_Result_t _SetWakeupSrcConfig(
void *arg)
1289 IARM_Result_t retCode = IARM_RESULT_IPCCORE_FAIL;
1294 IARM_Bus_PWRMgr_SetWakeupSrcConfig_Param_t *param = (IARM_Bus_PWRMgr_SetWakeupSrcConfig_Param_t *)arg;
1295 LOG(
"[PwrMgr] Setting WakeupSrcConfiguration for src type %d to %d\n", param->srcType,param->config);
1296 result = PLAT_API_SetWakeupSrc(param->srcType, param->config);
1297 retCode = result?IARM_RESULT_IPCCORE_FAIL:IARM_RESULT_SUCCESS;
1301 retCode = IARM_RESULT_INVALID_PARAM;
1305 #endif //ENABLE_SET_WAKEUP_SRC_CONFIG
1307 static void* _AsyncPowerWareHouseOperation(
void *pWareHouseOpnArg)
1311 pthread_mutex_lock(&wareHouseOpsMutex);
1312 if (NULL == pWareHouseOpn) {
1313 LOG(
"_AsyncPowerWareHouseOperation pWareHouseOpnArg is NULL\r\n");
1314 pthread_mutex_unlock(&wareHouseOpsMutex);
1315 asyncPowerWarehouseOpsThreadId = NULL;
1321 wareHouseOpnEventData.
status = IARM_BUS_PWRMGR_WAREHOUSE_INPROGRESS;
1322 LOG(
"_AsyncPowerWareHouseOperation pWareHouseOpnArg is %d pWareHouseOpn is %d\r\n", *((
int*)pWareHouseOpnArg), *pWareHouseOpn);
1324 if (IARM_BUS_PWRMGR_WAREHOUSE_RESET == (*pWareHouseOpn)) {
1325 processWHResetNoReboot();
1326 wareHouseOpnEventData.
status = IARM_BUS_PWRMGR_WAREHOUSE_COMPLETED;
1328 else if (IARM_BUS_PWRMGR_WAREHOUSE_CLEAR == (*pWareHouseOpn)) {
1329 processWHClearNoReboot();
1330 wareHouseOpnEventData.
status = IARM_BUS_PWRMGR_WAREHOUSE_COMPLETED;
1334 LOG(
"_AsyncPowerWareHouseOperation unexpected pWareHouseOpnArg %d\r\n", (*pWareHouseOpn));
1335 wareHouseOpnEventData.
status = IARM_BUS_PWRMGR_WAREHOUSE_FAILED;
1338 LOG(
"_AsyncPowerWareHouseOperation broadcasted IARM_BUS_PWRMGR_EVENT_WAREHOUSEOPS_STATUSCHANGED event\r\n");
1341 free (pWareHouseOpn); pWareHouseOpn=NULL;
1342 pthread_mutex_unlock(&wareHouseOpsMutex);
1343 asyncPowerWarehouseOpsThreadId = NULL;
1350 IARM_Result_t retCode = IARM_RESULT_SUCCESS;
1352 if (asyncPowerWarehouseOpsThreadId == NULL)
1355 *pWareHouseOpn = eWareHouseOpn;
1356 LOG(
"_SetPowerWareHouseOperation eWareHouseOpn is %d pWareHouseOpn is %d\r\n", eWareHouseOpn, *pWareHouseOpn);
1357 int err = pthread_create(&asyncPowerWarehouseOpsThreadId, NULL, _AsyncPowerWareHouseOperation, (
void*)pWareHouseOpn);
1359 LOG(
"_AsyncPowerWareHouseOperation thread create failed \r\n");
1361 err = pthread_detach(asyncPowerWarehouseOpsThreadId);
1363 LOG(
"_AsyncPowerWareHouseOperation thread detach failed \r\n");
1366 LOG(
"_AsyncPowerWareHouseOperation thread detach success \r\n");
1370 retCode = IARM_RESULT_INVALID_STATE;
1371 LOG(
"_SetPowerWareHouseOperation already in progress %d. Pls call it once existing reset finished.\r\n", retCode);
1376 static IARM_Result_t _WareHouseReset(
void *arg)
1379 int ret = param->
suppressReboot ? _SetPowerWareHouseOperation (IARM_BUS_PWRMGR_WAREHOUSE_RESET) : processWHReset();
1380 LOG(
"_WareHouseReset returned : %d\r\n", ret);
1383 return IARM_RESULT_SUCCESS;
1385 return IARM_RESULT_IPCCORE_FAIL;
1388 static IARM_Result_t _WareHouseClear(
void *arg)
1391 int ret = param->
suppressReboot ? _SetPowerWareHouseOperation (IARM_BUS_PWRMGR_WAREHOUSE_CLEAR) : processWHClear();
1392 LOG(
"_WareHouseClear returned : %d\r\n", ret);
1395 return IARM_RESULT_SUCCESS;
1397 return IARM_RESULT_IPCCORE_FAIL;
1400 static IARM_Result_t _ColdFactoryReset(
void *)
1402 int ret = processColdFactoryReset();
1403 LOG(
"_ColdFactoryReset returned : %d\r\n", ret);
1406 return IARM_RESULT_SUCCESS;
1408 return IARM_RESULT_IPCCORE_FAIL;
1411 static IARM_Result_t _FactoryReset(
void *)
1413 int ret = processFactoryReset();
1414 LOG(
"_FactoryReset returned : %d\r\n", ret);
1417 return IARM_RESULT_SUCCESS;
1419 return IARM_RESULT_IPCCORE_FAIL;
1422 static IARM_Result_t _UserFactoryReset(
void *)
1424 int ret = processUserFactoryReset();
1425 LOG(
"_UserFactoryReset returned : %d\r\n", ret);
1428 return IARM_RESULT_SUCCESS;
1430 return IARM_RESULT_IPCCORE_FAIL;
1433 static IARM_Result_t _SetStandbyVideoState(
void *arg)
1436 if(NULL == param->port)
1439 __TIMESTAMP();LOG(
"[PwrMgr] empty port name. Cannot proceed.\n");
1440 return IARM_RESULT_SUCCESS;
1446 for(i = 0; i < MAX_NUM_VIDEO_PORTS; i++)
1451 g_standby_video_port_setting[i].isEnabled = ((0 == param->isEnabled) ?
false :
true);
1455 if(MAX_NUM_VIDEO_PORTS == i)
1458 for(i = 0; i < MAX_NUM_VIDEO_PORTS; i++)
1460 if(
'\0' == g_standby_video_port_setting[i].port[0])
1463 g_standby_video_port_setting[i].isEnabled = ((0 == param->isEnabled) ?
false :
true);
1468 if(MAX_NUM_VIDEO_PORTS == i)
1470 __TIMESTAMP();LOG(
"Error! Out of room to write new video port setting for standby mode.\n");
1476 if((IARM_BUS_PWRMGR_POWERSTATE_ON != m_settings.powerState) && (IARM_BUS_PWRMGR_POWERSTATE_OFF != m_settings.powerState))
1479 __TIMESTAMP();LOG(
"[PwrMgr] Setting standby %s port status to %s.\n", param->port, ((1 == param->isEnabled)?
"enabled" :
"disabled"));
1480 if(1 == param->isEnabled)
1487 __TIMESTAMP();LOG(
"[PwrMgr] video port %s will be %s when going into standby mode.\n", param->port, ((1 == param->isEnabled)?
"enabled" :
"disabled"));
1492 __TIMESTAMP();LOG(
"Exception Caught during [PWRMgr - _SetStandbyVideoState]. Possible bad video port.\n");
1495 return IARM_RESULT_SUCCESS;
1498 static IARM_Result_t _GetStandbyVideoState(
void *arg)
1501 if(NULL == param->port)
1503 __TIMESTAMP();LOG(
"Bad port name. Cannot get state.\n");
1504 return IARM_RESULT_SUCCESS;
1514 __TIMESTAMP();LOG(
"Exception Caught during [PWRMgr - _GetStandbyVideoState]. Possible bad video port.\n");
1516 return IARM_RESULT_SUCCESS;
1518 param->isEnabled = ((
true == get_video_port_standby_setting(param->port))? 1 : 0);
1520 return IARM_RESULT_SUCCESS;
1523 static int _InitSettings(
const char *settingsFile)
1525 if (settingsFile == NULL) settingsFile =
"/opt/uimgr_settings.bin";
1527 m_settingsFile = settingsFile;
1528 LOG(
"Initializing settings at file %s\r\n", settingsFile);
1530 int ret = open(settingsFile, O_CREAT|O_RDWR, S_IRWXU|S_IRUSR);
1537 int read_size =
sizeof(uint32_t) * 3;
1538 lseek(fd, 0, SEEK_SET);
1539 ret = read(fd, pSettings,read_size);
1540 if((ret == read_size))
1542 switch(pSettings->version)
1547 lseek(fd, 0, SEEK_SET);
1549 read_size = pSettings->length;
1550 ret = read(fd, &uiMgrSettings,read_size);
1551 if(ret == read_size)
1554 pSettings->magic = _UIMGR_SETTINGS_MAGIC;
1555 pSettings->version = 1;
1557 pSettings->powerState =
1558 _ConvertUIDevToIARMBusPowerState(uiMgrSettings.powerState);
1559 g_last_known_power_state = pSettings->powerState;
1560 #ifdef ENABLE_DEEP_SLEEP
1561 pSettings->deep_sleep_timeout = deep_sleep_wakeup_timeout_sec;
1563 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1564 pSettings->nwStandbyMode = nwStandbyMode_gs;
1566 lseek(fd, 0, SEEK_SET);
1567 write(fd, pSettings, pSettings->length);
1581 LOG(
"[PwrMgr] Length of Persistence matches with Current Data Size \r\n");
1582 lseek(fd, 0, SEEK_SET);
1583 read_size = pSettings->length;
1584 ret = read(fd, pSettings,read_size);
1585 if(ret != read_size)
1588 LOG(
"[PwrMgr] error case, not able to read full length \r\n");
1592 g_last_known_power_state = pSettings->powerState;
1593 #ifdef ENABLE_DEEP_SLEEP
1594 deep_sleep_wakeup_timeout_sec = pSettings->deep_sleep_timeout;
1595 __TIMESTAMP();LOG(
"Persisted deep_sleep_delay = %d Secs \r\n",deep_sleep_wakeup_timeout_sec);
1597 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1598 nwStandbyMode_gs = pSettings->nwStandbyMode;
1599 __TIMESTAMP();LOG(
"Persisted network standby mode is: %s \r\n", nwStandbyMode_gs?(
"Enabled"):(
"Disabled"));
1601 #ifdef PLATCO_BOOTTO_STANDBY
1602 if(stat(
"/tmp/pwrmgr_restarted",&buf) != 0)
1604 pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
1605 __TIMESTAMP();LOG(
"Setting default powerstate to standby\n\r");
1613 LOG(
"[PwrMgr] Length of Persistence is less than Current Data Size \r\n");
1614 lseek(fd, 0, SEEK_SET);
1615 read_size = pSettings->length;
1616 ret = read(fd, pSettings,read_size);
1617 if(ret != read_size)
1619 LOG(
"[PwrMgr] Read Failed for Data Length %d \r\n",ret);
1627 g_last_known_power_state = pSettings->powerState;
1628 lseek(fd, 0, SEEK_SET);
1629 #ifdef ENABLE_DEEP_SLEEP
1630 pSettings->deep_sleep_timeout = deep_sleep_wakeup_timeout_sec;
1632 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1633 pSettings->nwStandbyMode = nwStandbyMode_gs;
1635 #ifdef PLATCO_BOOTTO_STANDBY
1636 if(stat(
"/tmp/pwrmgr_restarted",&buf) != 0) {
1637 pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
1641 LOG(
"[PwrMgr] Write PwrMgr Settings File With Current Data Length %d \r\n",pSettings->length);
1642 ret = write(fd, pSettings, pSettings->length);
1643 if(ret != pSettings->length)
1645 LOG(
"[PwrMgr] Write Failed For New Data Length %d \r\n",ret);
1653 LOG(
"[PwrMgr] Length of Persistence is more than Current Data Size. \r\n");
1655 lseek(fd, 0, SEEK_SET);
1657 ret = read(fd,pSettings,read_size);
1658 if(ret != read_size)
1660 LOG(
"[PwrMgr] Read Failed for Data Length %d \r\n",ret);
1666 g_last_known_power_state = pSettings->powerState;
1667 lseek(fd, 0, SEEK_SET);
1669 LOG(
"[PwrMgr] Write and Truncate PwrMgr Settings File With Current Data Length %d ........\r\n",pSettings->length);
1670 ret = write(fd, pSettings, pSettings->length);
1671 if(ret != pSettings->length)
1673 LOG(
"[PwrMgr] Write Failed For New Data Length %d \r\n",ret);
1680 lseek(fd, 0, SEEK_SET);
1681 fret = ftruncate(fd,pSettings->length);
1684 LOG(
"[PwrMgr] Truncate Failed For New Data Length %d \r\n",fret);
1705 #ifdef PLATCO_BOOTTO_STANDBY
1706 if(stat(
"/tmp/pwrmgr_restarted",&buf) != 0) {
1707 powerStateBeforeReboot_gc = std::string(
"UNKNOWN");
1708 printf (
"[%s]:[%d] powerStateBeforeReboot: %s\n", __FUNCTION__, __LINE__, powerStateBeforeReboot_gc.c_str());
1715 lseek(fd, 0, SEEK_SET);
1716 LOG(
"Initial Creation of UIMGR Settings\r\n");
1717 pSettings->magic = _UIMGR_SETTINGS_MAGIC;
1718 pSettings->version = 1;
1719 pSettings->length =
sizeof(*pSettings) - PADDING_SIZE;
1720 pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_ON;
1721 #ifdef ENABLE_DEEP_SLEEP
1722 pSettings->deep_sleep_timeout = deep_sleep_wakeup_timeout_sec;
1724 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1725 pSettings->nwStandbyMode = nwStandbyMode_gs;
1727 #ifdef PLATCO_BOOTTO_STANDBY
1728 if(stat(
"/tmp/pwrmgr_restarted",&buf) != 0)
1729 pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
1731 ret = write(fd, pSettings, pSettings->length);
1736 #ifdef ENABLE_DEEP_SLEEP
1740 if(pSettings->powerState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP)
1742 __TIMESTAMP();LOG(
"Box Reboots with Deep Sleep mode.. Start a Event Time SOurce .. \r\n");
1743 guint dsleep_bootup_timeout = 3600;
1744 dsleep_bootup_event_src = g_timeout_add_seconds (dsleep_bootup_timeout,invoke_deep_sleep_on_bootup_timeout,pwrMgr_Gloop);
1745 __TIMESTAMP();LOG(
"Added Time source %d to put the box to deep sleep after %d Sec.. \r\n",dsleep_bootup_event_src,dsleep_bootup_timeout);
1749 setPowerStateBeforeReboot (g_last_known_power_state);
1750 __TIMESTAMP();LOG(
"Setting PowerStateBeforeReboot %d \r\n", g_last_known_power_state);
1755 ux->applyPostRebootConfig(pSettings->powerState, g_last_known_power_state);
1757 IARM_Bus_PWRMgr_PowerState_t state;
1760 if (pSettings->powerState == state) {
1761 LOG(
"PowerState is already sync'd with hardware to %d\r\n", state);
1765 LOG(
"PowerState sync hardware state %d with UIMGR to %d\r\n", state, pSettings->powerState);
1769 _SetAVPortsPowerState(pSettings->powerState);
1773 }
while(state != pSettings->powerState && loopCount < 10);
1775 if (state != pSettings->powerState) {
1776 LOG(
"CRITICAL ERROR: PowerState sync failed \r\n");
1777 pSettings->powerState = state;
1782 _SetAVPortsPowerState(pSettings->powerState);
1783 _SetLEDStatus(pSettings->powerState);
1787 lseek(fd, 0, SEEK_SET);
1788 ret = write(fd, pSettings, pSettings->length);
1798 #ifdef PLATCO_BOOTTO_STANDBY
1799 if(stat(
"/tmp/pwrmgr_restarted",&buf) != 0) {
1801 _eventData.data.state.curState = IARM_BUS_PWRMGR_POWERSTATE_OFF;
1802 _eventData.data.state.newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
1803 LOG(
"%s: Init setting powermode change from OFF to STANDBY \r\n", __FUNCTION__);
1808 if (ret > 0 && ret < (
int)
sizeof(*pSettings)) {
1809 _DumpSettings(pSettings);
1813 if (ret > (
int)
sizeof(*pSettings)) {
1814 LOG(
"Error: Should not have read that much ! \r\n");
1824 LOG(
"Error: Failed to operate on uimgr_settings.bin, reason=[%s]\r\n", strerror(errno));
1831 static int _WriteSettings(
const char *settingsFile)
1834 int fd = open(settingsFile, O_WRONLY);
1838 lseek(fd, 0, SEEK_SET);
1840 ret = write(fd, pSettings, pSettings->length);
1846 LOG(
"Error: Failed to write on [%s], reason=[%s]\r\n", settingsFile, strerror(errno));
1849 LOG(
"Settings updated successfully\r\n");
1850 _DumpSettings(pSettings);
1858 LOG(
"PWRMGR-Settings-Mag: %X\r\n", pSettings->magic);
1859 LOG(
"PWRMGR-Settings-Ver: %d\r\n", pSettings->version);
1860 LOG(
"PWRMGR-Settings-Len: %d\r\n", pSettings->length );
1861 LOG(
"PWRMGR-Settings-PWR: %d\r\n", pSettings->powerState);
1862 LOG(
"PWRMGR-Settings-Brightness: %d\r\n", pSettings->ledSettings.brightness);
1863 #ifdef ENABLE_DEEP_SLEEP
1864 LOG(
"PWRMGR-Settings-Deep Sleep Timeout: %d\r\n", pSettings->deep_sleep_timeout);
1868 static int _SetLEDStatus(IARM_Bus_PWRMgr_PowerState_t powerState)
1872 if( powerState != IARM_BUS_PWRMGR_POWERSTATE_ON )
1874 #ifdef FP_POWER_LED_ON_IN_LOW_POWER_MODE //For devices like TVs that are expected to have lights on when in one of the standby modes.
1876 LOG(
"[PWRMgr-_SetLEDStatus] Settings the Power LED State to ON\r\n");
1879 LOG(
"[PWRMgr-_SetLEDStatus] Settings the Power LED State to OFF \r\n");
1885 LOG(
"[PWRMgr-_SetLEDStatus] Settings the Power LED State to ON \r\n");
1889 LOG(
"Exception Caught during [PWRMgr - _SetLEDStatus]\r\n");
1895 static IARM_Bus_PWRMgr_PowerState_t _ConvertUIDevToIARMBusPowerState(UIDev_PowerState_t powerState)
1897 IARM_Bus_PWRMgr_PowerState_t ret = IARM_BUS_PWRMGR_POWERSTATE_ON;
1900 case UIDEV_POWERSTATE_OFF:
1901 ret = IARM_BUS_PWRMGR_POWERSTATE_OFF;
1903 case UIDEV_POWERSTATE_STANDBY:
1904 ret = IARM_BUS_PWRMGR_POWERSTATE_ON;
1910 int _SetAVPortsPowerState(IARM_Bus_PWRMgr_PowerState_t powerState)
1914 if( powerState != IARM_BUS_PWRMGR_POWERSTATE_ON ){
1915 if(IARM_BUS_PWRMGR_POWERSTATE_OFF != powerState)
1919 for (
size_t i = 0; i < videoPorts.
size(); i++)
1921 bool doEnable = get_video_port_standby_setting(videoPorts.at(i).
getName().c_str());
1922 LOG(
"Video port %s will be %s in standby mode.\n", videoPorts.at(i).
getName().c_str(), (doEnable?
"enabled" :
"disabled"));
1923 if(
false == doEnable)
1931 for (
size_t i = 0; i < videoPorts.
size(); i++)
1939 for (
size_t i = 0; i < audioPorts.
size(); i++)
1941 audioPorts.at(i).disable();
1949 for (
size_t i = 0; i < videoPorts.
size(); i++)
1951 videoPorts.at(i).
enable();
1954 for (
size_t i = 0; i < audioPorts.
size(); i++)
1957 bool isPortPersistenceValEnabled =
true;
1959 isPortPersistenceValEnabled = vPort.getEnablePersist();
1963 LOG(
"Audio Port Getting enable persist value failed. Proceeding with true\n");
1965 if(isPortPersistenceValEnabled)
1969 audioPorts.at(i).
enable();
1973 for (
size_t i = 0; i < videoPorts.
size(); i++)
1979 LOG(
"Setting Audio Mode-(STBY- ACTIVE) Port name: %s by persistence to [%s]\r\n",aPort.
getName().c_str(),aPort.
getStereoMode(
true).
getName().c_str());
1981 if(isEASInProgress == IARM_BUS_SYS_MODE_EAS)
1984 LOG(
"Force Stereo in EAS mode \r\n");
2003 LOG(
"Exception Caught during [_SetAVPortsPowerState]\r\n");
2023 IARM_Bus_CommonAPI_SysModeChange_Param_t *param = (IARM_Bus_CommonAPI_SysModeChange_Param_t *)arg;
2025 __TIMESTAMP();printf(
"[PwrMgr] Recvd Sysmode Change::New mode --> %d,Old mode --> %d",param->newMode,param->oldMode);
2027 if (param->newMode == IARM_BUS_SYS_MODE_EAS) {
2028 isEASInProgress = IARM_BUS_SYS_MODE_EAS;
2030 else if (param->newMode == IARM_BUS_SYS_MODE_NORMAL) {
2031 isEASInProgress = IARM_BUS_SYS_MODE_NORMAL;
2033 return IARM_RESULT_SUCCESS;
2036 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
2037 static void *_AsyncPowerTransition(
void *)
2042 pthread_mutex_lock(&powerStateMutex);
2043 if (pSettings->powerState != targetState) {
2047 _SetPowerState(¶m);
2051 pthread_cond_wait(&powerStateCond, &powerStateMutex);
2053 pthread_mutex_unlock(&powerStateMutex);
2058 static void _SetPowerStateAsync(IARM_Bus_PWRMgr_PowerState_t curState, IARM_Bus_PWRMgr_PowerState_t newState)
2062 IARM_Result_t retCode = IARM_RESULT_SUCCESS;
2064 if (asyncPowerThreadId == NULL)
2066 int err = pthread_create(&asyncPowerThreadId, NULL, _AsyncPowerTransition, NULL);
2068 LOG(
"_AsyncPowerTransition thread create failed \r\n");
2070 err = pthread_detach(asyncPowerThreadId);
2072 LOG(
"_AsyncPowerTransition thread detach failed \r\n");
2079 if (curState != newState) {
2081 LOG(
"PowerState Fast transitioning from %d to %d, while still in [%d]\r\n", curState, newState, pSettings->powerState);
2083 _SetLEDStatus(newState);
2084 transitionState = newState;
2085 pthread_mutex_lock(&powerStateMutex);
2086 if (targetState != newState) {
2087 targetState = newState;
2088 pthread_cond_signal(&powerStateCond);
2090 pthread_mutex_unlock(&powerStateMutex);
2093 LOG(
"Warning:PowerState is same as requested\r\n");
2101 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
2102 static void _ctrlmMessageHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
2104 if (eventId == CTRLM_RCU_IARM_EVENT_KEY_GHOST)
2106 ctrlm_rcu_iarm_event_key_ghost_t* ghostEvent = (ctrlm_rcu_iarm_event_key_ghost_t*)data;
2107 if (ghostEvent != NULL)
2109 if (ghostEvent->api_revision != CTRLM_RCU_IARM_BUS_API_REVISION)
2111 LOG(
"CTRLM ghost key event: ERROR - Wrong CTRLM API revision - expected %d, event is %d!!",
2112 CTRLM_RCU_IARM_BUS_API_REVISION, ghostEvent->api_revision);
2115 LOG(
"CTRLM ghost code event: network_id: %d, network_type: %d, controller_id: %d, ghost_code: %d.\n",
2116 ghostEvent->network_id, ghostEvent->network_type, ghostEvent->controller_id, ghostEvent->ghost_code);
2118 if ((ghostEvent->ghost_code == CTRLM_RCU_GHOST_CODE_POWER_OFF) ||
2119 (ghostEvent->ghost_code == CTRLM_RCU_GHOST_CODE_POWER_ON))
2122 param.
newState = IARM_BUS_PWRMGR_POWERSTATE_ON;
2123 LOG(
"CTRLM Setting Powerstate to ON.\n");
2124 _SetPowerState((
void *)¶m);
2129 LOG(
"CTRLM ghost code event: ERROR: NULL event data!!\n");
2134 LOG(
"CTRLM event handler: ERROR: bad event type %d!!\n", eventId);
2138 #ifdef RF4CE_GENMSO_API
2139 static void _rfMessageHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
2142 MSOBusAPI_Packet_t* busMsg;
2146 busMsg = (MSOBusAPI_Packet_t*)data;
2148 if(len != (busMsg->length +
sizeof(MSOBusAPI_Packet_t) -
sizeof(MSOBusAPI_Msg_t)))
2150 LOG(
"BusTestApplication: %i MsgIndication with wrong length rec:%d exp:%d\n",eventId,
2151 len, (busMsg->length +
sizeof(MSOBusAPI_Packet_t) -
sizeof(MSOBusAPI_Msg_t)));
2155 switch(busMsg->msgId)
2157 case MSOBusAPI_MsgId_GhostCommand:
2159 LOG(
"BusTestApplication: command code : id:%d\n", busMsg->msg.UserCommand.commandCode);
2160 if (busMsg->msg.UserCommand.commandCode == 1 || busMsg->msg.UserCommand.commandCode == 2)
2162 param.
newState = IARM_BUS_PWRMGR_POWERSTATE_ON;
2164 _SetPowerState((
void *)¶m);
2176 #elif defined(RF4CE_API)
2177 static void _rf4ceMessageHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
2180 rf4ce_Packet_t* busMsg;
2184 busMsg = (rf4ce_Packet_t*)data;
2186 __TIMESTAMP();LOG(
"pwrMgr: RF4CE Msg indication event handler, msgId: 0x%X\n", (
unsigned)busMsg->msgId);
2187 if (busMsg->msgId == rf4ce_MsgId_GhostCommand) {
2188 __TIMESTAMP();LOG(
"pwrMgr: RF4CE Ghost Command, msgId: 0x%X\n", (
unsigned)busMsg->msg.UserCommand.commandCode);
2191 if(len != (busMsg->length +
sizeof(rf4ce_Packet_t) -
sizeof(rf4ce_Msg_t)))
2193 LOG(
"BusTestApplication: %i MsgIndication with wrong length rec:%d exp:%d\n",eventId,
2194 len, (busMsg->length +
sizeof(rf4ce_Packet_t) -
sizeof(rf4ce_Msg_t)));
2198 switch(busMsg->msgId)
2200 case rf4ce_MsgId_GhostCommand:
2202 LOG(
"BusTestApplication: command code : id:%d\n", busMsg->msg.UserCommand.commandCode);
2203 if (busMsg->msg.UserCommand.commandCode == 1 || busMsg->msg.UserCommand.commandCode == 2)
2205 param.
newState = IARM_BUS_PWRMGR_POWERSTATE_ON;
2207 _SetPowerState((
void *)¶m);
2218 #elif defined(RF4CE_GPMSO_API)
2219 static void _gpMessageHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
2222 gpMSOBusAPI_Packet_t* busMsg;
2226 busMsg = (gpMSOBusAPI_Packet_t*)data;
2228 if(len != (busMsg->length +
sizeof(gpMSOBusAPI_Packet_t) -
sizeof(gpMSOBusAPI_Msg_t)))
2230 LOG(
"BusTestApplication: %i MsgIndication with wrong length rec:%d exp:%d\n",eventId,
2231 len, (busMsg->length +
sizeof(gpMSOBusAPI_Packet_t) -
sizeof(gpMSOBusAPI_Msg_t)));
2235 switch(busMsg->msgId)
2237 case gpMSOBusAPI_MsgId_GhostCommand:
2239 LOG(
"BusTestApplication: command code : id:%d\n", busMsg->msg.UserCommand.commandCode);
2240 if (busMsg->msg.UserCommand.commandCode == 1 || busMsg->msg.UserCommand.commandCode == 2)
2242 param.
newState = IARM_BUS_PWRMGR_POWERSTATE_ON;
2244 _SetPowerState((
void *)¶m);
2256 #warning "No RF4CE API defined"
2261 static void _controlEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
2267 __TIMESTAMP();LOG(
"pwrMgr: Control event handler, key: 0x%X, src: 0x%X\n",
2268 (
unsigned)irEventData->data.irkey.keyCode, (
unsigned)irEventData->data.irkey.keySrc);
2270 _GetPowerState((
void *)&powerState);
2271 if (powerState.
curState != IARM_BUS_PWRMGR_POWERSTATE_ON) {
2272 int keySrc = irEventData->data.irkey.keySrc;
2273 switch(irEventData->data.irkey.keyCode) {
2275 case KED_VOLUMEDOWN:
2285 case KED_PUSH_TO_TALK:
2286 case KED_VOLUME_OPTIMIZE:
2293 irEventData->data.irkey.keyCode = KED_POWER;
2294 irEventData->data.irkey.keyType = KET_KEYUP;
2295 _irEventHandler(owner,eventId,(
void*)irEventData,len);
2301 static void _speechEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
2304 _GetPowerState((
void *)&powerState);
2305 __TIMESTAMP();LOG(
"pwrMgr: Voice event handler, eventId: %d.\n", (
int)eventId);
2306 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
2307 if(powerState.
curState != IARM_BUS_PWRMGR_POWERSTATE_ON &&
2308 (eventId == CTRLM_VOICE_IARM_EVENT_SESSION_BEGIN ||
2309 eventId == CTRLM_VOICE_IARM_EVENT_SESSION_ABORT ||
2310 eventId == CTRLM_VOICE_IARM_EVENT_SESSION_SHORT) )
2312 #ifdef USE_UNIFIED_RF4CE_MGR_API_4
2313 if(powerState.
curState != IARM_BUS_PWRMGR_POWERSTATE_ON &&
2314 (eventId == VREX_MGR_IARM_EVENT_VOICE_BEGIN ||
2315 eventId == VREX_MGR_IARM_EVENT_VOICE_SESSION_ABORT ||
2316 eventId == VREX_MGR_IARM_EVENT_VOICE_SESSION_SHORT) )
2321 if(eventId == IARM_BUS_VREXMGR_EVENT_SPEECH && sEvent->type == IARM_BUS_VREXMGR_SPEECH_BEGIN && powerState.
curState != IARM_BUS_PWRMGR_POWERSTATE_ON)
2326 irEventData.data.irkey.keyCode = KED_POWER;
2327 irEventData.data.irkey.keyType = KET_KEYUP;
2328 _irEventHandler(owner,eventId,(
void*)&irEventData,len);
2333 #ifdef ENABLE_DEEP_SLEEP
2334 static IARM_Result_t _SetDeepSleepTimeOut(
void *arg)
2340 __TIMESTAMP();LOG(
"Deep sleep timeout set to : %d\r\n", param->
timeout);
2341 deep_sleep_wakeup_timeout_sec = param->
timeout;
2342 m_settings.deep_sleep_timeout = param->
timeout;
2343 IsWakeupTimerSet = 1;
2344 _WriteSettings(m_settingsFile);
2345 return IARM_RESULT_SUCCESS;
2347 return IARM_RESULT_IPCCORE_FAIL;
2349 static void handleDeepsleepTimeoutWakeup (
void * arg)
2351 __TIMESTAMP();LOG(
"Entering %s \r\n", __FUNCTION__);
2353 param.
timeout = deep_sleep_wakeup_timeout_sec;
2356 #if !defined (_DISABLE_SCHD_REBOOT_AT_DEEPSLEEP)
2357 __TIMESTAMP();LOG(
"Reboot the box due to Deep Sleep Timer Expiry : %d \r\n", param.timeout);
2362 __TIMESTAMP();LOG(
"deep_sleep_wakeup_fn: Set Device to light sleep on Deep Sleep timer expiry..\r\n");
2363 pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP;
2364 paramSetPwr.
newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP;
2365 _SetPowerState((
void *)¶mSetPwr);
2369 static void* deepsleepTimeoutWakeupThread (
void * arg)
2371 __TIMESTAMP();LOG(
"Entering %s \r\n", __FUNCTION__);
2372 handleDeepsleepTimeoutWakeup(arg);
2376 static IARM_Result_t _handleDeepsleepTimeoutWakeup (
void *arg)
2378 IARM_Result_t retCode = IARM_RESULT_SUCCESS;
2380 pthread_t asyncDeepsleepTimeoutThreadId = 0;
2381 int err = pthread_create(&asyncDeepsleepTimeoutThreadId, NULL, deepsleepTimeoutWakeupThread, NULL);
2383 __TIMESTAMP();LOG(
"handleDeepsleepTimeoutWakeup thread create failed \r\n");
2385 err = pthread_detach(asyncDeepsleepTimeoutThreadId);
2387 __TIMESTAMP();LOG(
"handleDeepsleepTimeoutWakeup thread detach failed \r\n");
2396 static gboolean deep_sleep_wakeup_fn(gpointer data)
2398 uint32_t timeout = (uint32_t) difftime(time(NULL),timeAtDeepSleep);
2400 __TIMESTAMP();LOG(
"Sec Elapsed Since Deep Sleep : %d \r\n",timeout);
2402 IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
2405 (
char *)
"GetDeepSleepStatus",
2412 handleDeepsleepTimeoutWakeup (NULL);
2422 static gboolean invoke_deep_sleep_on_bootup_timeout(gpointer data)
2427 __TIMESTAMP();LOG(
"deep_sleep_thread : Set Device to Deep Sleep on Bootip Timer Expiry.. \r\n");
2430 pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
2431 param.
newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP;
2432 _SetPowerState((
void *)¶m);
2441 typedef enum _tzValue {
2457 static std::map<std::string, tzValue> _maptzValues;
2458 static void InitializeTimeZone();
2459 static uint32_t getTZDiffInSec()
2461 uint32_t _TZDiffTime = 6*3600;
2462 IARM_Result_t iResult = IARM_RESULT_SUCCESS;
2463 tzValue value=tzCST06;
2466 InitializeTimeZone();
2471 if(iResult == IARM_RESULT_SUCCESS)
2473 if (param.time_zone_available.error)
2475 __TIMESTAMP();LOG(
"Failed to get the Time Zone Information from SysMgr \r\n");
2477 else if (param.time_zone_available.state == 2)
2479 if (strlen(param.time_zone_available.payload) > 1)
2481 __TIMESTAMP();LOG(
"TZ Payload - %s",param.time_zone_available.payload);
2482 value = _maptzValues[param.time_zone_available.payload];
2483 _TZDiffTime = value * 3600;
2485 __TIMESTAMP();LOG(
"TZ value = %d\r\n",value);
2486 __TIMESTAMP();LOG(
"Time Zone in Sec = %d \r\n",_TZDiffTime);
2496 static void InitializeTimeZone()
2498 _maptzValues[
"HST11"] = tzHST11;
2499 _maptzValues[
"HST11HDT,M3.2.0,M11.1.0"] = tzHST11HDT;
2500 _maptzValues[
"AKST"] = tzAKST;
2501 _maptzValues[
"AKST09AKDT,M3.2.0,M11.1.0"] = tzAKST09AKDT;
2502 _maptzValues[
"PST08"] = tzPST08;
2503 _maptzValues[
"PST08PDT,M3.2.0,M11.1.0"] = tzPST08PDT;
2504 _maptzValues[
"MST07"] = tzMST07;
2505 _maptzValues[
"MST07MDT,M3.2.0,M11.1.0"] = tzMST07MDT;
2506 _maptzValues[
"CST06"] = tzCST06;
2507 _maptzValues[
"CST06CDT,M3.2.0,M11.1.0"] = tzCST06CDT;
2508 _maptzValues[
"EST05"] = tzEST05;
2509 _maptzValues[
"EST05EDT,M3.2.0,M11.1.0"] = tzEST05EDT;
2517 static uint32_t getWakeupTime()
2520 struct tm wakeupTime;
2521 uint32_t wakeupTimeInSec = 0,getTZDiffTime = 0;
2522 uint32_t wakeupTimeInMin = 5;
2527 fpWT = fopen(
"/tmp/deepSleepWakeupTimer",
"r");
2530 if(0 > fscanf(fpWT,
"%d",&wakeupTimeInMin))
2532 __TIMESTAMP();LOG(
"Error: fscanf on wakeupTimeInSec failed");
2536 wakeupTimeInSec = wakeupTimeInMin * 60 ;
2538 __TIMESTAMP();LOG(
" /tmp/ override Deep Sleep Wakeup Time is %d \r\n",wakeupTimeInSec);
2539 return wakeupTimeInSec;
2549 wakeupTime = *localtime (&wakeup);
2551 if (wakeupTime.tm_hour >=0 && wakeupTime.tm_hour < 2)
2554 wakeupTime.tm_hour = 2;
2555 wakeupTime.tm_min = 0;
2556 wakeupTime.tm_sec = 0;
2557 wakeupTimeInSec = difftime(mktime(&wakeupTime),now);
2563 wakeupTime.tm_hour = 23;
2564 wakeupTime.tm_min = 59;
2565 wakeupTime.tm_sec = 60;
2566 wakeupTimeInSec = difftime(mktime(&wakeupTime),now);
2567 wakeupTimeInSec = wakeupTimeInSec + 7200;
2574 uint32_t randTimeInSec = (uint32_t)rand()%(3600) + 0;
2575 wakeupTimeInSec = wakeupTimeInSec + randTimeInSec;
2578 __TIMESTAMP();LOG(
"Calculated Deep Sleep Wakeup Time Before TZ setting is %d Sec \r\n", wakeupTimeInSec);
2579 getTZDiffTime = getTZDiffInSec();
2580 wakeupTimeInSec = wakeupTimeInSec + getTZDiffTime;
2581 __TIMESTAMP();LOG(
"Calculated Deep Sleep Wakeup Time After TZ setting is %d Sec \r\n", wakeupTimeInSec);
2583 return wakeupTimeInSec;
2587 static IARM_Result_t _SetNetworkStandbyMode(
void *arg)
2590 uint32_t uiTimeout = 3;
2593 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
2594 LOG(
"Setting network standbyMode: %s \r\n", param->
bStandbyMode?(
"Enabled"):(
"Disabled"));
2597 _WriteSettings(m_settingsFile);
2600 _eventData.data.bNetworkStandbyMode = m_settings.nwStandbyMode;
2605 LOG (
"\nError _SetNetworkStandbyMode not implemented. standbyMode: %s", param->
bStandbyMode?(
"Enabled"):(
"Disabled"));
2607 return IARM_RESULT_SUCCESS;
2609 return IARM_RESULT_IPCCORE_FAIL;
2612 static IARM_Result_t _GetNetworkStandbyMode(
void *arg)
2618 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
2620 LOG(
"Network standbyMode is: %s \r\n", param->
bStandbyMode?(
"Enabled"):(
"Disabled"));
2622 LOG (
"\nError _GetNetworkStandbyMode not implemented.");
2624 return IARM_RESULT_SUCCESS;
2626 return IARM_RESULT_IPCCORE_FAIL;