35 #include <sys/types.h>
40 #include "comcastIrKeyCodes.h"
51 #define MAX_KEY_REPEATS 6
52 #define LAST_KEY_NUM_SECONDS 2
53 #define MICRO_SECS_PER_SEC 1000000L
54 #define MICROSECS_PER_MILLISEC 1000L
57 #define LOG_TRANSLATE_EVENT(OLD_KEY,NEW_KEY) LOG("IR Key " #OLD_KEY "(0x%x) event is translated to " #NEW_KEY "(0x%x)\n", \
58 (unsigned int)OLD_KEY, (unsigned int)NEW_KEY)
60 static pthread_t eRepeatThreadID;
61 static pthread_mutex_t tLastKeyMutex;
62 static pthread_mutex_t tKeySeqMutex;
63 static pthread_mutex_t tMutexLock;
64 static pthread_cond_t tMutexCond;
65 static int gCurrentKeyCode = KED_UNDEFINEDKEY;
66 static int gCurrentKeySrcId = 0;
67 static const unsigned int gInitialWaitTimeout = 500;
68 static unsigned int gRepeatKeyInterval = 50;
69 static int numKeyRepeats = 0;
70 static int keyLogStatus = 1;
73 #ifdef RF4CE_GENMSO_API
74 clock_t Rf4ceAutoBindClock=0;
75 static pthread_t eRf4ceAutoBindOffThreadID;
76 static void* _Rf4ceAutoBindOffThreadFunc(
void *arg);
78 #elif defined(RF4CE_API)
79 clock_t Rf4ceAutoBindClock=0;
80 static pthread_t eRf4ceAutoBindOffThreadID;
81 static void* _Rf4ceAutoBindOffThreadFunc(
void *arg);
83 #elif defined(RF4CE_GPMSO_API)
84 clock_t Rf4ceAutoBindClock=0;
85 static pthread_t eRf4ceAutoBindOffThreadID;
86 static void* _Rf4ceAutoBindOffThreadFunc(
void *arg);
89 #warning "No RF4CE API defined"
94 static pthread_t eLASTKeyTimerThreadID;
95 static void* _LASTKeyTimerThreadFunc(
void *arg);
96 bool bLastKeyUpReceived =
false;
97 bool bLastTimerRunning =
false;
98 bool bIgnoreLastKeyup =
false;
100 int lastKeyNumMSecs = 1500;
101 static bool isCecLocalLogicEnabled =
false;
104 static bool bNeedRFKeyUp =
false;
107 #ifdef XMP_TAG_OWNER_SUPPORT
110 static void _IrKeyCallbackFrom(
PLAT_irKey_metadata *irKey,
int keySrc,
unsigned int keySrcId);
113 static void _IrKeyCallback(
int keyType,
int keyCode);
114 static void _IrKeyCallbackFrom(
int keyType,
int keyCode,
int keySrc,
unsigned int keySrcId);
117 static void _logEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
120 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
121 #include "ctrlm_ipc.h"
122 #include "ctrlm_ipc_rcu.h"
123 static void _ctrlmEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
125 #ifdef RF4CE_GENMSO_API
126 #include "rf4ceMgr.h"
127 static void _rfEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
128 #elif defined(RF4CE_API)
129 #include "rf4ceMgr.h"
130 static void _rf4ceEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
131 #elif defined(RF4CE_GPMSO_API)
132 #include "rf4ceMgr.h"
133 static void _gpEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
135 #warning "No RF4CE API defined"
137 #endif // USE_UNIFIED_CONTROL_MGR_API_1
143 static uinput_dispatcher_t udispatcher = NULL;
148 return IARM_RESULT_SUCCESS;
153 char *settingsFile = NULL;
155 if (argc == 2) settingsFile = argv[1];
157 LOG(
"Entering [%s] - [%s] - disabling io redirect buf\r\n", __FUNCTION__,
IARM_BUS_IRMGR_NAME);
158 setvbuf(stdout, NULL, _IOLBF, 0);
169 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
174 #ifdef RF4CE_GENMSO_API
176 #elif defined(RF4CE_API)
178 #elif defined(RF4CE_GPMSO_API)
181 #warning "No RF4CE API defined"
183 #endif // USE_UNIFIED_CONTROL_MGR_API_1
188 keyLogStatus = param.logStatus;
190 pthread_mutex_init (&tKeySeqMutex, NULL);
191 pthread_mutex_init (&tMutexLock, NULL);
192 pthread_mutex_init (&tLastKeyMutex, NULL);
193 pthread_cond_init (&tMutexCond, NULL);
196 #ifdef XMP_TAG_OWNER_SUPPORT
207 LOG(
"Exception Caught during [device::Manager::Initialize]\r\n");
210 RFC_ParamData_t rfcParam;
211 WDMP_STATUS status = getRFCParameter(
"TestComponent",
"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.CECLocalLogic.Enable", &rfcParam);
212 if(strncasecmp(rfcParam.value,
"true",4) == 0)
214 isCecLocalLogicEnabled=
true;
215 LOG(
"RFC CEC Local Logic feature enabled \r\n");
218 return IARM_RESULT_SUCCESS;
228 LOG(
"I-ARM IR Mgr: HeartBeat at %s\r\n", ctime(&curr));
231 return IARM_RESULT_SUCCESS;
238 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
242 #endif // USE_UNIFIED_CONTROL_MGR_API_1
250 LOG(
"Exception Caught during [device::Manager::DeInitialize]\r\n");
256 pthread_mutex_destroy (&tKeySeqMutex);
257 pthread_mutex_destroy (&tMutexLock);
258 pthread_mutex_destroy (&tLastKeyMutex);
259 pthread_cond_destroy (&tMutexCond);
261 return IARM_RESULT_SUCCESS;
282 __TIMESTAMP(); LOG (
"The timeout interval is set to %dms\n", param->
timeout);
283 gRepeatKeyInterval = param->
timeout;
284 return IARM_RESULT_SUCCESS;
305 __TIMESTAMP(); LOG (
"The timeout interval is set to %dms\n", gRepeatKeyInterval);
306 param->
timeout = gRepeatKeyInterval;
307 return IARM_RESULT_SUCCESS;
310 #ifndef XMP_TAG_OWNER_SUPPORT
311 static void _IrKeyCallback(
int keyType,
int keyCode)
320 __TIMESTAMP(); LOG(
"IR Key received (%x, %x, %x, %x)\n", irKey->
tag,
325 if (irKey->
tag != XMP_TAG_PLATCO)
327 __TIMESTAMP(); LOG(
"IR Key tag is invalid (%x != %x)\n", irKey->
tag, XMP_TAG_PLATCO);
332 switch (irKey->
owner)
334 case XMP_OWNER_NORMAL:
337 case XMP_OWNER_PAIRING:
338 _IrKeyPairing(irKey);
340 case XMP_OWNER_UNDEFINED:
342 __TIMESTAMP(); LOG(
"Unknown owner field %x\n", irKey->
owner);
347 bool tag_is_valid =
true;
348 bool owner_is_valid =
false;
350 switch (irKey->
owner)
352 case XMP_OWNER_NORMAL:
353 case XMP_OWNER_PAIRING:
354 owner_is_valid =
true;
356 case XMP_OWNER_UNDEFINED:
358 __TIMESTAMP(); LOG(
"Unknown owner field %x\n", irKey->
owner);
365 tag_is_valid =
false;
367 case XMP_TAG_COMCAST:
376 __TIMESTAMP(); LOG(
"Unknown tag field %x\n", irKey->
tag);
380 if (tag_is_valid && owner_is_valid) {
388 IARM_Result_t result;
389 ctrlm_main_iarm_call_status_t status;
390 ctrlm_iarm_call_StartPairWithCode_params_t pair_data;
392 if (irKey->
tag != XMP_TAG_PLATCO || irKey->
owner != XMP_OWNER_PAIRING)
397 memset(&status, 0,
sizeof(ctrlm_main_iarm_call_status_t));
398 memset(&pair_data, 0,
sizeof(ctrlm_iarm_call_StartPairWithCode_params_t));
399 status.api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
400 pair_data.api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
401 pair_data.pair_code = irKey->
code;
404 CTRLM_MAIN_IARM_CALL_STATUS_GET,
408 if (result != IARM_RESULT_SUCCESS)
410 __TIMESTAMP(); LOG(
"%s: Failed = %d\n", CTRLM_MAIN_IARM_CALL_STATUS_GET,
415 for (
int i = 0; i < status.network_qty; i++)
417 if (status.networks[i].type == CTRLM_NETWORK_TYPE_BLUETOOTH_LE)
419 pair_data.network_id = status.networks[i].id;
422 CTRLM_MAIN_IARM_CALL_START_PAIR_WITH_CODE,
424 sizeof(ctrlm_iarm_call_StartPairWithCode_params_t));
426 if (result != IARM_RESULT_SUCCESS)
428 __TIMESTAMP(); LOG(
"%s: Failed = %d\n", CTRLM_MAIN_IARM_CALL_START_PAIR_WITH_CODE,
436 #ifndef XMP_TAG_OWNER_SUPPORT
437 static void _IrKeyCallbackFrom(
int keyType,
int keyCode,
int keySrc,
unsigned int keySrcId)
442 #ifdef XMP_TAG_OWNER_SUPPORT
444 int keyCode = irKey->
code;
452 pthread_mutex_lock(&tMutexLock);
453 gCurrentKeyCode = keyCode;
454 gCurrentKeySrcId = keySrcId;
456 #ifndef XMP_TAG_OWNER_SUPPORT
461 pthread_cond_signal(&tMutexCond);
462 pthread_mutex_unlock(&tMutexLock);
466 pthread_mutex_lock(&tMutexLock);
467 gCurrentKeyCode = KED_UNDEFINEDKEY;
468 gCurrentKeySrcId = keySrcId;
470 #ifndef XMP_TAG_OWNER_SUPPORT
475 pthread_cond_signal(&tMutexCond);
476 pthread_mutex_unlock(&tMutexLock);
493 #ifndef XMP_TAG_OWNER_SUPPORT
500 #ifdef XMP_TAG_OWNER_SUPPORT
502 int keyCode = irKey->
code;
504 static bool xr15_or_newer_notify_call =
false;
506 if(0 != keyLogStatus)
507 LOG(
"COMCAST IR Key (%x, %x, %x) From Remote Device received\r\n",
keyType, keyCode, keySrcId);
511 #ifndef USE_UNIFIED_CONTROL_MGR_API_1
512 #ifdef RF4CE_GENMSO_API
514 if(keyCode==KED_RF_PAIR_GHOST &&
keyType == KET_KEYDOWN){
515 MSOBusAPI_Packet_t setPacket;
517 setPacket.msgId = MSOBusAPI_MsgId_AutoBind_LineOfSight;
519 setPacket.length = 1;
520 setPacket.msg.CheckStatus = 1;
522 int rc =
IARM_Bus_Call(IARM_BUS_RFMGR_NAME, IARM_BUS_RFMGR_MsgRequest, (
void *)&setPacket,
sizeof(setPacket));
525 if(Rf4ceAutoBindClock!=0)
528 Rf4ceAutoBindClock = getTimeMs();
531 Rf4ceAutoBindClock = getTimeMs();
532 pthread_create (&eRf4ceAutoBindOffThreadID, NULL, _Rf4ceAutoBindOffThreadFunc, NULL);
535 LOG(
"setting autoBind-LineOfSight successful\n");
539 LOG(
"failed setting autoBind-LineOfSight with %d\n",rc);
543 #elif defined(RF4CE_API)
544 if(keyCode==KED_RF_PAIR_GHOST &&
keyType == KET_KEYDOWN){
545 rf4ce_Packet_t setPacket;
547 setPacket.msgId = rf4ce_MsgId_AutoBind_LineOfSight;
549 setPacket.length = 1;
550 setPacket.msg.CheckStatus = 1;
552 int rc =
IARM_Bus_Call(IARM_BUS_RF4CEMGR_NAME, IARM_BUS_RF4CEMGR_MsgRequest, (
void *)&setPacket,
sizeof(setPacket));
555 if(Rf4ceAutoBindClock!=0)
558 Rf4ceAutoBindClock = getTimeMs();
561 Rf4ceAutoBindClock = getTimeMs();
562 pthread_create (&eRf4ceAutoBindOffThreadID, NULL, _Rf4ceAutoBindOffThreadFunc, NULL);
565 LOG(
"setting autoBind-LineOfSight successful\n");
569 LOG(
"failed setting autoBind-LineOfSight with %d\n",rc);
574 #elif defined(RF4CE_GPMSO_API)
576 if(keyCode==KED_RF_PAIR_GHOST &&
keyType == KET_KEYDOWN){
577 gpMSOBusAPI_Packet_t setPacket;
579 setPacket.msgId = gpMSOBusAPI_MsgId_AutoBind_LineOfSight;
581 setPacket.length = 1;
582 setPacket.msg.CheckStatus = 1;
584 int rc =
IARM_Bus_Call(IARM_BUS_GPMGR_NAME, IARM_BUS_GPMGR_API_MsgRequest, (
void *)&setPacket,
sizeof(setPacket));
587 if(Rf4ceAutoBindClock!=0)
590 Rf4ceAutoBindClock = getTimeMs();
593 Rf4ceAutoBindClock = getTimeMs();
594 pthread_create (&eRf4ceAutoBindOffThreadID, NULL, _Rf4ceAutoBindOffThreadFunc, NULL);
597 LOG(
"setting autoBind-LineOfSight successful\n");
601 LOG(
"failed setting autoBind-LineOfSight with %d\n",rc);
606 #warning "No RF4CE API defined"
608 #endif // USE_UNIFIED_CONTROL_MGR_API_1
614 case KED_RF_PAIR_GHOST:
615 #ifndef USE_UNIFIED_CONTROL_MGR_API_1
617 LOG(
"Auto-binding key. Don't pass on.\n");
621 case KED_VOLUME_OPTIMIZE:
622 case KED_XR11_NOTIFY:
623 case KED_XR15V1_NOTIFY:
624 case KED_XR16V1_NOTIFY:
625 case KED_SCREEN_BIND_NOTIFY:
631 case KED_PUSH_TO_TALK:
639 if (keyCode == KED_PUSH_TO_TALK && xr15_or_newer_notify_call ==
false)
641 #ifndef XMP_TAG_OWNER_SUPPORT
644 irKey->
type = KET_KEYDOWN;
645 irKey->
code = KED_XR11_NOTIFY;
650 LOG(
"IR Control Event: keyCode: 0x%x, keySrc: 0x%x.\n", keyCode, keySrc);
651 pthread_mutex_lock(&tKeySeqMutex);
653 eventData.data.irkey.keyType = KET_KEYDOWN;
654 eventData.data.irkey.keyCode = keyCode;
655 #ifdef XMP_TAG_OWNER_SUPPORT
656 eventData.data.irkey.keyTag = irKey->
tag;
657 eventData.data.irkey.keyOwner = irKey->
owner;
659 eventData.data.irkey.keyTag = XMP_TAG_UNDEFINED;
660 eventData.data.irkey.keyOwner = XMP_OWNER_UNDEFINED;
663 eventData.data.irkey.keySourceId = keySrcId;
665 pthread_mutex_unlock(&tKeySeqMutex);
675 pthread_mutex_lock(&tKeySeqMutex);
678 bLastKeyUpReceived =
false;
681 bIgnoreLastKeyup =
false;
687 if(bLastTimerRunning ==
false)
690 #ifndef XMP_TAG_OWNER_SUPPORT
691 pthread_create (&eLASTKeyTimerThreadID, NULL, _LASTKeyTimerThreadFunc, NULL);
693 pthread_create (&eLASTKeyTimerThreadID, NULL, _LASTKeyTimerThreadFunc, (
void *)irKey);
697 pthread_mutex_unlock(&tKeySeqMutex);
702 pthread_mutex_lock(&tKeySeqMutex);
705 bLastKeyUpReceived =
true;
708 if(bIgnoreLastKeyup ==
false)
711 LOG(
"Sending LAST key, not the EXIT key\n");
714 eventData.data.irkey.keyType = KET_KEYDOWN;
715 eventData.data.irkey.keyCode = KED_LAST;
716 #ifdef XMP_TAG_OWNER_SUPPORT
717 eventData.data.irkey.keyTag = irKey->
tag;
718 eventData.data.irkey.keyOwner = irKey->
owner;
720 eventData.data.irkey.keyTag = XMP_TAG_UNDEFINED;
721 eventData.data.irkey.keyOwner = XMP_OWNER_UNDEFINED;
723 eventData.data.irkey.isFP = 0;
725 eventData.data.irkey.keySourceId = keySrcId;
727 udispatcher(eventData.data.irkey.keyCode, eventData.data.irkey.keyType, eventData.data.irkey.keySrc);
732 eventData.data.irkey.keyType = KET_KEYUP;
734 udispatcher(eventData.data.irkey.keyCode, eventData.data.irkey.keyType, eventData.data.irkey.keySrc);
739 pthread_mutex_unlock(&tKeySeqMutex);
747 #ifndef XMP_TAG_OWNER_SUPPORT
750 irKey->
type = KET_KEYDOWN;
751 irKey->
code = KED_XR11_NOTIFY;
756 case KED_XR15V1_PUSH_TO_TALK:
757 LOG_TRANSLATE_EVENT(KED_XR15V1_PUSH_TO_TALK, KED_PUSH_TO_TALK);
760 xr15_or_newer_notify_call =
true;
761 #ifndef XMP_TAG_OWNER_SUPPORT
764 irKey->
type = KET_KEYDOWN;
765 irKey->
code = KED_XR15V1_NOTIFY;
768 gCurrentKeyCode = KED_PUSH_TO_TALK;
772 xr15_or_newer_notify_call =
false;
773 gCurrentKeyCode = KED_UNDEFINEDKEY;
775 #ifndef XMP_TAG_OWNER_SUPPORT
779 irKey->
code = KED_PUSH_TO_TALK;
783 case KED_XR15V1_SELECT:
784 LOG_TRANSLATE_EVENT(KED_XR15V1_SELECT, KED_SELECT);
787 xr15_or_newer_notify_call =
true;
788 #ifndef XMP_TAG_OWNER_SUPPORT
791 irKey->
type = KET_KEYDOWN;
792 irKey->
code = KED_XR15V1_NOTIFY;
795 gCurrentKeyCode = KED_SELECT;
799 xr15_or_newer_notify_call =
false;
800 gCurrentKeyCode = KED_UNDEFINEDKEY;
802 #ifndef XMP_TAG_OWNER_SUPPORT
806 irKey->
code = KED_SELECT;
810 case KED_XR16V1_PUSH_TO_TALK:
811 LOG_TRANSLATE_EVENT(KED_XR16V1_PUSH_TO_TALK, KED_PUSH_TO_TALK);
814 xr15_or_newer_notify_call =
true;
815 #ifndef XMP_TAG_OWNER_SUPPORT
818 irKey->
type = KET_KEYDOWN;
819 irKey->
code = KED_XR16V1_NOTIFY;
822 gCurrentKeyCode = KED_PUSH_TO_TALK;
826 xr15_or_newer_notify_call =
false;
827 gCurrentKeyCode = KED_UNDEFINEDKEY;
829 #ifndef XMP_TAG_OWNER_SUPPORT
833 irKey->
code = KED_PUSH_TO_TALK;
837 case KED_XR16V1_SELECT:
838 LOG_TRANSLATE_EVENT(KED_XR16V1_SELECT, KED_SELECT);
841 xr15_or_newer_notify_call =
true;
842 #ifndef XMP_TAG_OWNER_SUPPORT
845 irKey->
type = KET_KEYDOWN;
846 irKey->
code = KED_XR16V1_NOTIFY;
849 gCurrentKeyCode = KED_SELECT;
853 xr15_or_newer_notify_call =
false;
854 gCurrentKeyCode = KED_UNDEFINEDKEY;
856 #ifndef XMP_TAG_OWNER_SUPPORT
860 irKey->
code = KED_SELECT;
869 if (!(keyCode == KED_UNDEFINEDKEY))
871 pthread_mutex_lock(&tKeySeqMutex);
873 if ((keyCode != prevEventData.data.irkey.keyCode) &&
874 (
keyType == KET_KEYDOWN) && (prevEventData.data.irkey.keyType != KET_KEYUP))
876 eventData.data.irkey.keyType = KET_KEYUP;
877 eventData.data.irkey.keyCode = prevEventData.data.irkey.keyCode;
878 #ifdef XMP_TAG_OWNER_SUPPORT
879 eventData.data.irkey.keyTag = irKey->
tag;
880 eventData.data.irkey.keyOwner = irKey->
owner;
882 eventData.data.irkey.keyTag = XMP_TAG_UNDEFINED;
883 eventData.data.irkey.keyOwner = XMP_OWNER_UNDEFINED;
885 eventData.data.irkey.isFP = prevEventData.data.irkey.isFP;
886 eventData.data.irkey.keySrc = prevEventData.data.irkey.keySrc;
887 eventData.data.irkey.keySourceId = keySrcId;
889 udispatcher(keyCode,
keyType, keySrc);
893 eventData.data.irkey.keyType =
keyType;
894 eventData.data.irkey.keyCode = keyCode;
895 eventData.data.irkey.keySourceId = keySrcId;
896 eventData.data.irkey.isFP = (keyCode == KED_POWER) ? 1:0;
898 #ifdef XMP_TAG_OWNER_SUPPORT
899 eventData.data.irkey.keyTag = irKey->
tag;
900 eventData.data.irkey.keyOwner = irKey->
owner;
902 eventData.data.irkey.keyTag = XMP_TAG_UNDEFINED;
903 eventData.data.irkey.keyOwner = XMP_OWNER_UNDEFINED;
907 prevEventData.data.irkey.isFP = (keyCode == KED_POWER) ? 1:0;
909 prevEventData.data.irkey.keyType =
keyType;
910 prevEventData.data.irkey.keySourceId = keySrcId;
911 prevEventData.data.irkey.keyCode = keyCode;
912 #ifdef XMP_TAG_OWNER_SUPPORT
913 prevEventData.data.irkey.keyTag = irKey->
tag;
914 prevEventData.data.irkey.keyOwner = irKey->
owner;
916 eventData.data.irkey.keyTag = XMP_TAG_UNDEFINED;
917 eventData.data.irkey.keyOwner = XMP_OWNER_UNDEFINED;
920 #ifdef _DISABLE_KEY_POWEROFF //XITHREE-7832
921 bool broadcastEvent =
true;
922 static int prevKeyType =
keyType;
924 if(keyCode == KED_FP_POWER) {
927 if(prevKeyType == KET_KEYDOWN) {
931 broadcastEvent =
false;
936 if(prevKeyType != KET_KEYDOWN) {
937 broadcastEvent =
false;
947 eventData.data.irkey.keyType =
keyType;
948 if(!broadcastEvent) {
949 LOG(
"Discarding key event!!! keyCode: %x keyType: %x\n",keyCode,
keyType);
950 pthread_mutex_unlock(&tKeySeqMutex);
953 LOG(
"Broadcasting key event!!! keyCode: %x keyType: %x\n",eventData.data.irkey.keyCode,eventData.data.irkey.keyType);
956 udispatcher(keyCode,
keyType, keySrc);
959 pthread_mutex_unlock(&tKeySeqMutex);
978 gettimeofday(&tv, NULL);
981 tv.tv_sec += (tv.tv_usec + uTimeoutValue * 1000L ) / 1000000;
982 tv.tv_usec = (tv.tv_usec + uTimeoutValue * 1000L ) % 1000000;
985 ts.tv_sec = tv.tv_sec;
986 ts.tv_nsec = tv.tv_usec * 1000;
988 __TIMESTAMP(); LOG (
"Block for %dms & look for KEY RELEASE\n", uTimeoutValue);
989 ret = pthread_cond_timedwait(&tMutexCond, &tMutexLock, &ts);
992 if (ret == ETIMEDOUT)
994 __TIMESTAMP(); LOG (
"Key NOT released yet. Ready to post REPEAT keys\n");
999 __TIMESTAMP(); LOG (
"Key released..\n");
1005 #ifndef USE_UNIFIED_CONTROL_MGR_API_1
1006 #ifdef RF4CE_GENMSO_API
1016 static void* _Rf4ceAutoBindOffThreadFunc(
void *arg)
1018 if(Rf4ceAutoBindClock!=0){
1020 useconds_t usecondsToWait = 600000;
1022 LOG(
"sleeping for %d\n", usecondsToWait);
1023 usleep(usecondsToWait);
1024 LOG(
"OUT OF SLEEP\n");
1026 Rf4ceAutoBindClock=0;
1027 MSOBusAPI_Packet_t setPacket;
1029 setPacket.msgId = MSOBusAPI_MsgId_AutoBind_LineOfSight;
1030 setPacket.index = 0;
1031 setPacket.length = 1;
1032 setPacket.msg.CheckStatus = 0;
1034 int rc =
IARM_Bus_Call(IARM_BUS_RFMGR_NAME, IARM_BUS_RFMGR_MsgRequest, (
void *)&setPacket,
sizeof(setPacket));
1037 LOG(
"clearing autoBind-LineOfSight successful\n");
1041 LOG(
"failed clearing autoBind-LineOfSight with %d\n",rc);
1049 gettimeofday(&tm, NULL);
1050 return (tm.tv_sec) * 1000 + (tm.tv_usec) / 1000 ;
1052 #elif defined(RF4CE_API)
1062 static void* _Rf4ceAutoBindOffThreadFunc(
void *arg)
1064 if(Rf4ceAutoBindClock!=0){
1066 useconds_t usecondsToWait = 600000;
1068 LOG(
"sleeping for %d\n", usecondsToWait);
1069 usleep(usecondsToWait);
1070 LOG(
"OUT OF SLEEP\n");
1072 Rf4ceAutoBindClock=0;
1073 rf4ce_Packet_t setPacket;
1075 setPacket.msgId = rf4ce_MsgId_AutoBind_LineOfSight;
1076 setPacket.index = 0;
1077 setPacket.length = 1;
1078 setPacket.msg.CheckStatus = 0;
1080 int rc =
IARM_Bus_Call(IARM_BUS_RF4CEMGR_NAME, IARM_BUS_RF4CEMGR_MsgRequest, (
void *)&setPacket,
sizeof(setPacket));
1083 LOG(
"clearing autoBind-LineOfSight successful\n");
1087 LOG(
"failed clearing autoBind-LineOfSight with %d\n",rc);
1095 gettimeofday(&tm, NULL);
1096 return (tm.tv_sec) * 1000 + (tm.tv_usec) / 1000 ;
1098 #elif defined(RF4CE_GPMSO_API)
1108 static void* _Rf4ceAutoBindOffThreadFunc(
void *arg)
1110 if(Rf4ceAutoBindClock!=0){
1112 useconds_t usecondsToWait = 600000;
1114 LOG(
"sleeping for %d\n", usecondsToWait);
1115 usleep(usecondsToWait);
1116 LOG(
"OUT OF SLEEP\n");
1118 Rf4ceAutoBindClock=0;
1119 gpMSOBusAPI_Packet_t setPacket;
1121 setPacket.msgId = gpMSOBusAPI_MsgId_AutoBind_LineOfSight;
1122 setPacket.index = 0;
1123 setPacket.length = 1;
1124 setPacket.msg.CheckStatus = 0;
1126 int rc =
IARM_Bus_Call(IARM_BUS_GPMGR_NAME, IARM_BUS_GPMGR_API_MsgRequest, (
void *)&setPacket,
sizeof(setPacket));
1129 LOG(
"clearing autoBind-LineOfSight successful\n");
1133 LOG(
"failed clearing autoBind-LineOfSight with %d\n",rc);
1141 gettimeofday(&tm, NULL);
1142 return (tm.tv_sec) * 1000 + (tm.tv_usec) / 1000 ;
1145 #warning "No RF4CE API defined"
1147 #endif // USE_UNIFIED_CONTROL_MGR_API_1
1151 static void* _LASTKeyTimerThreadFunc(
void *arg)
1153 #ifdef XMP_TAG_OWNER_SUPPORT
1157 useconds_t usecondsToWait = 50000;
1158 bool bSendExitKey =
true;
1161 pthread_mutex_lock(&tKeySeqMutex);
1162 bLastTimerRunning =
true;
1163 pthread_mutex_unlock(&tKeySeqMutex);
1166 for (i=0; i<((lastKeyNumMSecs*MICROSECS_PER_MILLISEC) / usecondsToWait); i++)
1168 usleep(usecondsToWait);
1171 if(bLastKeyUpReceived ==
true)
1173 bSendExitKey =
false;
1178 pthread_mutex_lock(&tKeySeqMutex);
1181 bIgnoreLastKeyup =
true;
1184 if(bSendExitKey ==
true)
1189 LOG(
"Sending EXIT key instead of LAST\n");
1190 eventData.data.irkey.keyType = KET_KEYDOWN;
1191 eventData.data.irkey.keyCode = KED_EXIT;
1192 #ifdef XMP_TAG_OWNER_SUPPORT
1193 eventData.data.irkey.keyTag = irKey->
tag;
1194 eventData.data.irkey.keyOwner = irKey->
owner;
1196 eventData.data.irkey.keyTag = XMP_TAG_UNDEFINED;
1197 eventData.data.irkey.keyOwner = XMP_OWNER_UNDEFINED;
1199 eventData.data.irkey.isFP = 0;
1201 eventData.data.irkey.keySourceId = gCurrentKeySrcId;
1203 udispatcher(eventData.data.irkey.keyCode, eventData.data.irkey.keyType, eventData.data.irkey.keySrc);
1208 eventData.data.irkey.keyType = KET_KEYUP;
1210 udispatcher(eventData.data.irkey.keyCode, eventData.data.irkey.keyType, eventData.data.irkey.keySrc);
1216 bLastTimerRunning =
false;
1217 pthread_mutex_unlock(&tKeySeqMutex);
1232 bool isTimedout =
false;
1237 pthread_mutex_lock(&tMutexLock);
1243 __TIMESTAMP(); LOG (
"Block unconditionally & look for KEY PRESS\n");
1244 pthread_cond_wait(&tMutexCond, &tMutexLock);
1256 pthread_mutex_unlock(&tMutexLock);
1265 #ifndef XMP_TAG_OWNER_SUPPORT
1278 if (gRepeatKeyInterval != 0)
1283 __TIMESTAMP(); LOG (
"Key pressed.. Do not post Repeat key...\n");
1287 if (KED_UNDEFINEDKEY != gCurrentKeyCode)
1299 if(numKeyRepeats > MAX_KEY_REPEATS)
1301 __TIMESTAMP(); LOG (
"******** Lost connection to rf4ceMgr. Sending Up key...\n");
1302 #ifndef XMP_TAG_OWNER_SUPPORT
1308 gCurrentKeyCode = KED_UNDEFINEDKEY;
1310 bNeedRFKeyUp =
false;
1315 __TIMESTAMP(); LOG (
"Post Repeat RF key...\n");
1316 #ifndef XMP_TAG_OWNER_SUPPORT
1327 __TIMESTAMP(); LOG (
"Post Repeat key...\n");
1328 #ifndef XMP_TAG_OWNER_SUPPORT
1342 pthread_mutex_unlock(&tMutexLock);
1358 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
1359 static void _ctrlmEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
1363 unsigned int remoteId = 0;
1365 if (eventId == CTRLM_RCU_IARM_EVENT_KEY_PRESS) {
1366 ctrlm_rcu_iarm_event_key_press_t* keyEvent = (ctrlm_rcu_iarm_event_key_press_t*)data;
1367 if (keyEvent != NULL) {
1368 if (keyEvent->api_revision != CTRLM_RCU_IARM_BUS_API_REVISION) {
1369 LOG(
"CTRLM key event: ERROR - Wrong CTRLM API revision - expected %d, event is %d!!",
1370 CTRLM_RCU_IARM_BUS_API_REVISION, keyEvent->api_revision);
1374 if(0 != keyLogStatus)
1376 LOG(
"CTRLM key event: network_id: %d, network_type: %d, controller_id: %d, key_status: %d, key_code: 0x%02X.\n",
1377 keyEvent->network_id, keyEvent->network_type, keyEvent->controller_id, keyEvent->key_status, keyEvent->key_code);
1380 if (keyEvent->key_status != CTRLM_KEY_STATUS_INVALID) {
1381 remoteId = keyEvent->controller_id;
1383 switch (keyEvent->key_status) {
1384 case CTRLM_KEY_STATUS_DOWN:
keyType = KET_KEYDOWN;
break;
1385 case CTRLM_KEY_STATUS_UP:
keyType = KET_KEYUP;
break;
1386 case CTRLM_KEY_STATUS_REPEAT:
keyType = KET_KEYREPEAT;
break;
1389 switch (keyEvent->key_code) {
1390 case CTRLM_KEY_CODE_OK: keyCode = KED_SELECT;
break;
1392 case CTRLM_KEY_CODE_UP_ARROW: keyCode = KED_ARROWUP;
break;
1393 case CTRLM_KEY_CODE_DOWN_ARROW: keyCode = KED_ARROWDOWN;
break;
1394 case CTRLM_KEY_CODE_LEFT_ARROW: keyCode = KED_ARROWLEFT;
break;
1395 case CTRLM_KEY_CODE_RIGHT_ARROW: keyCode = KED_ARROWRIGHT;
break;
1397 case CTRLM_KEY_CODE_MENU: keyCode = KED_MENU;
break;
1398 case CTRLM_KEY_CODE_DVR: keyCode = KED_MYDVR;
break;
1399 case CTRLM_KEY_CODE_FAV: keyCode = KED_FAVORITE;
break;
1400 case CTRLM_KEY_CODE_EXIT: keyCode = KED_EXIT;
break;
1403 case CTRLM_KEY_CODE_DIGIT_0: keyCode = KED_DIGIT0;
break;
1404 case CTRLM_KEY_CODE_DIGIT_1: keyCode = KED_DIGIT1;
break;
1405 case CTRLM_KEY_CODE_DIGIT_2: keyCode = KED_DIGIT2;
break;
1406 case CTRLM_KEY_CODE_DIGIT_3: keyCode = KED_DIGIT3;
break;
1407 case CTRLM_KEY_CODE_DIGIT_4: keyCode = KED_DIGIT4;
break;
1408 case CTRLM_KEY_CODE_DIGIT_5: keyCode = KED_DIGIT5;
break;
1409 case CTRLM_KEY_CODE_DIGIT_6: keyCode = KED_DIGIT6;
break;
1410 case CTRLM_KEY_CODE_DIGIT_7: keyCode = KED_DIGIT7;
break;
1411 case CTRLM_KEY_CODE_DIGIT_8: keyCode = KED_DIGIT8;
break;
1412 case CTRLM_KEY_CODE_DIGIT_9: keyCode = KED_DIGIT9;
break;
1413 case CTRLM_KEY_CODE_PERIOD: keyCode = KED_PERIOD;
break;
1415 case CTRLM_KEY_CODE_RETURN: keyCode = KED_ENTER;
break;
1416 case CTRLM_KEY_CODE_CH_UP: keyCode = KED_CHANNELUP;
break;
1417 case CTRLM_KEY_CODE_CH_DOWN: keyCode = KED_CHANNELDOWN;
break;
1418 case CTRLM_KEY_CODE_LAST: keyCode = KED_LAST;
break;
1419 case CTRLM_KEY_CODE_LANG: keyCode = KED_LANGUAGE;
break;
1420 case CTRLM_KEY_CODE_INPUT_SELECT: keyCode = KED_INPUTKEY;
break;
1421 case CTRLM_KEY_CODE_INFO: keyCode = KED_INFO;
break;
1422 case CTRLM_KEY_CODE_HELP: keyCode = KED_HELP;
break;
1423 case CTRLM_KEY_CODE_PAGE_UP: keyCode = KED_PAGEUP;
break;
1424 case CTRLM_KEY_CODE_PAGE_DOWN: keyCode = KED_PAGEDOWN;
break;
1426 case CTRLM_KEY_CODE_SEARCH: keyCode = KED_SEARCH;
break;
1427 case CTRLM_KEY_CODE_LIVE: keyCode = KED_LIVE;
break;
1431 case CTRLM_KEY_CODE_TV_POWER: keyCode = KED_TVPOWER;
break;
1432 case CTRLM_KEY_CODE_VOL_UP: keyCode = KED_VOLUMEUP;
break;
1433 case CTRLM_KEY_CODE_VOL_DOWN: keyCode = KED_VOLUMEDOWN;
break;
1434 case CTRLM_KEY_CODE_MUTE: keyCode = KED_MUTE;
break;
1435 case CTRLM_KEY_CODE_PLAY: keyCode = KED_PLAY;
break;
1436 case CTRLM_KEY_CODE_STOP: keyCode = KED_STOP;
break;
1437 case CTRLM_KEY_CODE_PAUSE: keyCode = KED_PAUSE;
break;
1438 case CTRLM_KEY_CODE_RECORD: keyCode = KED_RECORD;
break;
1439 case CTRLM_KEY_CODE_REWIND: keyCode = KED_REWIND;
break;
1440 case CTRLM_KEY_CODE_FAST_FORWARD: keyCode = KED_FASTFORWARD;
break;
1442 case CTRLM_KEY_CODE_REPLAY: keyCode = KED_REPLAY;
break;
1444 case CTRLM_KEY_CODE_SWAP: keyCode = KED_DISPLAY_SWAP;
break;
1445 case CTRLM_KEY_CODE_ON_DEMAND: keyCode = KED_ONDEMAND;
break;
1446 case CTRLM_KEY_CODE_GUIDE: keyCode = KED_GUIDE;
break;
1447 case CTRLM_KEY_CODE_PUSH_TO_TALK: keyCode = KED_PUSH_TO_TALK;
break;
1449 case CTRLM_KEY_CODE_PIP_ON_OFF: keyCode = KED_PINP_TOGGLE;
break;
1450 case CTRLM_KEY_CODE_PIP_MOVE: keyCode = KED_PINP_MOVE;
break;
1451 case CTRLM_KEY_CODE_PIP_CH_UP: keyCode = KED_PINP_CHUP;
break;
1452 case CTRLM_KEY_CODE_PIP_CH_DOWN: keyCode = KED_PINP_CHDOWN;
break;
1457 case CTRLM_KEY_CODE_PLAY_PAUSE: keyCode = KED_PLAY;
break;
1461 case CTRLM_KEY_CODE_POWER_TOGGLE: keyCode = KED_RF_POWER;
break;
1462 case CTRLM_KEY_CODE_POWER_OFF: keyCode = KED_DISCRETE_POWER_STANDBY;
break;
1463 case CTRLM_KEY_CODE_POWER_ON: keyCode = KED_DISCRETE_POWER_ON;
break;
1465 case CTRLM_KEY_CODE_OCAP_B: keyCode = KED_KEYB;
break;
1466 case CTRLM_KEY_CODE_OCAP_C: keyCode = KED_KEYC;
break;
1467 case CTRLM_KEY_CODE_OCAP_D: keyCode = KED_KEYD;
break;
1468 case CTRLM_KEY_CODE_OCAP_A: keyCode = KED_KEYA;
break;
1470 case CTRLM_KEY_CODE_CC: keyCode = KED_CLOSED_CAPTIONING;
break;
1479 case CTRLM_KEY_CODE_BACKSPACE: keyCode = KED_DELETE;
break;
1543 case CTRLM_KEY_CODE_POUND: keyCode = KED_POUND;
break;
1547 case CTRLM_KEY_CODE_ASTERISK: keyCode = KED_PROGRAM;
break;
1561 case CTRLM_KEY_CODE_INVALID: keyCode = KED_UNDEFINEDKEY;
break;
1563 default: keyCode = KED_UNDEFINEDKEY;
break;
1566 LOG(
"CTRLM key event: ERROR: INVALID key status!!\n");
1570 LOG(
"CTRLM key event: ERROR: NULL event data!!\n");
1573 }
else if (eventId == CTRLM_RCU_IARM_EVENT_KEY_GHOST) {
1574 ctrlm_rcu_iarm_event_key_ghost_t* ghostEvent = (ctrlm_rcu_iarm_event_key_ghost_t*)data;
1575 if (ghostEvent != NULL) {
1576 if (ghostEvent->api_revision != CTRLM_RCU_IARM_BUS_API_REVISION) {
1577 LOG(
"CTRLM ghost key event: ERROR - Wrong CTRLM API revision - expected %d, event is %d!!",
1578 CTRLM_RCU_IARM_BUS_API_REVISION, ghostEvent->api_revision);
1581 LOG(
"CTRLM ghost code event: network_id: %d, network_type: %d, controller_id: %d, ghost_code: %d.\n",
1582 ghostEvent->network_id, ghostEvent->network_type, ghostEvent->controller_id, ghostEvent->ghost_code);
1584 remoteId = ghostEvent->controller_id;
1585 switch (ghostEvent->ghost_code) {
1586 case CTRLM_RCU_GHOST_CODE_VOLUME_UNITY_GAIN:
1588 keyCode = KED_VOLUME_OPTIMIZE;
1596 LOG(
"CTRLM ghost code event: ERROR: NULL event data!!\n");
1599 }
else if (eventId == CTRLM_RCU_IARM_EVENT_FUNCTION) {
1600 ctrlm_rcu_iarm_event_function_t* functionEvent = (ctrlm_rcu_iarm_event_function_t*)data;
1601 if (functionEvent != NULL) {
1602 if (functionEvent->api_revision != CTRLM_RCU_IARM_BUS_API_REVISION) {
1603 LOG(
"CTRLM function event: ERROR - Wrong CTRLM API revision - expected %d, event is %d!!",
1604 CTRLM_RCU_IARM_BUS_API_REVISION, functionEvent->api_revision);
1607 LOG(
"CTRLM rcu function event: network_id: %d, network_type: %d, controller_id: %d, function: %d, value: 0x%08X.\n",
1608 functionEvent->network_id, functionEvent->network_type, functionEvent->controller_id, functionEvent->function, functionEvent->value);
1612 LOG(
"CTRLM rcu function event: ERROR: NULL event data!!\n");
1616 LOG(
"CTRLM key event: ERROR: bad event type %d!!\n", eventId);
1624 if (keyCode == KED_POWER)
1626 keyCode = KED_RF_POWER;
1634 bNeedRFKeyUp =
false;
1636 bNeedRFKeyUp =
true;
1638 #ifndef XMP_TAG_OWNER_SUPPORT
1647 #ifdef RF4CE_GENMSO_API
1648 static void _rfEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
1650 LOG(
"BusTestApplication: %d> UserControlIndication 0x%lx\n",((MSOBusAPI_Packet_t*)data)->msg.UserCommand.remoteId,
1651 ((MSOBusAPI_Packet_t*)data)->msg.UserCommand.keyStatus);
1653 int keyCode = ((MSOBusAPI_Packet_t*)data)->msg.UserCommand.commandCode;
1654 int keyType = ((MSOBusAPI_Packet_t*)data)->msg.UserCommand.keyStatus;
1655 unsigned char remoteId = ((MSOBusAPI_UserCommand_t*)data)->remoteId;
1662 if (keyCode == KED_POWER)
1664 keyCode = KED_RF_POWER;
1672 bNeedRFKeyUp =
false;
1674 bNeedRFKeyUp =
true;
1676 #ifndef XMP_TAG_OWNER_SUPPORT
1683 #elif defined(RF4CE_API)
1684 static void _rf4ceEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
1687 LOG(
"BusTestApplication: %d> UserControlIndication 0x%lx\n",((rf4ce_UserCommand_t*)data)->remoteId,
1688 ((rf4ce_UserCommand_t*)data)->keyStatus);
1690 int keyCode = ((rf4ce_UserCommand_t*)data)->commandCode;
1691 int keyType = ((rf4ce_UserCommand_t*)data)->keyStatus;
1692 unsigned int remoteId = ((rf4ce_UserCommand_t*)data)->remoteId;
1699 if (keyCode == KED_POWER)
1701 keyCode = KED_RF_POWER;
1709 bNeedRFKeyUp =
false;
1711 bNeedRFKeyUp =
true;
1713 #ifndef XMP_TAG_OWNER_SUPPORT
1721 #elif defined(RF4CE_GPMSO_API)
1722 static void _gpEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
1725 LOG(
"BusTestApplication: %d> UserControlIndication 0x%lx\n",((gpMSOBusAPI_UserCommand_t*)data)->remoteId,
1726 ((gpMSOBusAPI_UserCommand_t*)data)->keyStatus);
1728 int keyCode = ((gpMSOBusAPI_UserCommand_t*)data)->commandCode;
1729 int keyType = ((gpMSOBusAPI_UserCommand_t*)data)->keyStatus;
1730 unsigned char remoteId = ((gpMSOBusAPI_UserCommand_t*)data)->remoteId;
1737 if (keyCode == KED_POWER)
1739 keyCode = KED_RF_POWER;
1747 bNeedRFKeyUp =
false;
1749 bNeedRFKeyUp =
true;
1751 #ifndef XMP_TAG_OWNER_SUPPORT
1760 #warning "No RF4CE API defined"
1762 #endif // USE_UNIFIED_CONTROL_MGR_API_1
1769 static void _logEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
1771 unsigned long messageLength=0;
1774 LOG(
"Received Keycodelogging event with log status: %d \n", eventData->data.keyCodeLogData.logStatus);
1775 keyLogStatus = eventData->data.keyCodeLogData.logStatus;