38 #include <sys/types.h>
47 #include <curl/curl.h>
52 #include "jsonParser.h"
53 #include "vrexSession.h"
54 #include "vrexMgrInternal.h"
57 #include "safec_lib.h"
61 #include "comcastIrKeyCodes.h"
65 #define VERSION_TXT_FILE "/version.txt"
66 #define VERSION_TXT_IMAGENAME "imagename:"
68 static pthread_mutex_t tMutexLock;
69 static void _vrexEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
70 static void _pairEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
71 static void _keyEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
72 static bool _sessionExists(
unsigned char remoteId);
73 static void _updateSessionTimeout(
unsigned char remoteId);
74 static bool _loadReceiverId();
75 static bool _getSTBName();
76 static void _configureRemotesToWatch();
77 static void _loadConfiguration();
78 static int currentPowerMode = 0;
79 static bool is_powered_on(
void);
83 #ifdef RF4CE_GENMSO_API
84 static VREXSession& _findOrNewSession(
unsigned char remoteId, MSOBusAPI_RfStatus_t *rfStatus = NULL,
int bindRemotesIndex = 0);
85 #elif defined(RF4CE_API)
86 static VREXSession& _findOrNewSession(
unsigned char remoteId, rf4ce_RfStatus_t *rfStatus = NULL,
int bindRemotesIndex = 0);
87 #elif defined(RF4CE_GPMSO_API)
88 static VREXSession& _findOrNewSession(
unsigned char remoteId, gpMSOBusAPI_RfStatus_t *rfStatus = NULL,
int bindRemotesIndex = 0);
90 #warning "No RF4CE API defined"
93 static volatile int initialized = 0;
94 static volatile bool bVoiceControl=
true;
95 string guideLanguage=
"";
96 string aspect_ratio=
"";
100 map<unsigned char, VREXSession> remotes;
102 static string receiverId;
103 static string stbName;
104 static string defaultRemoteName =
"XR11-20";
105 static string defaultRoute =
"https://vrex.g.comcast.net/vsp/v1/";
106 static int defaultConversationLength = 180;
107 static int defaultExpirationWindow = 60;
108 static pthread_mutex_t power_save_mutex;
110 IARM_Result_t VREXMgr_Start()
113 char *list[] = {
"XR2-",
"XR5-",
"XR11-",
"XR13-" };
116 IARM_Result_t status = IARM_RESULT_SUCCESS;
119 setvbuf(stdout, NULL, _IOLBF, 0);
122 LOG(
"I-ARM VREX Mgr: %d\r\n", __LINE__);
124 pthread_mutex_init (&tMutexLock, NULL);
125 pthread_mutex_lock(&tMutexLock);
130 if (status == IARM_RESULT_SUCCESS)
133 if (status == IARM_RESULT_SUCCESS) {
142 #ifdef RF4CE_GENMSO_API
145 #elif defined(RF4CE_API)
148 #elif defined(RF4CE_GPMSO_API)
152 #warning "No RF4CE API defined"
167 #ifdef RF4CE_GENMSO_API
168 MSOBusAPI_Packet_t expectedRemotesPacket;
169 expectedRemotesPacket.msgId = MSOBusAPI_MsgId_ExpectedRemotes;
170 expectedRemotesPacket.index = 0;
171 expectedRemotesPacket.length =
sizeof(MSOBusAPI_ExpectedRemoteList_t);
172 #elif defined(RF4CE_API)
173 rf4ce_Packet_t expectedRemotesPacket;
174 expectedRemotesPacket.msgId = rf4ce_MsgId_ExpectedRemotes;
175 expectedRemotesPacket.index = 0;
176 expectedRemotesPacket.length =
sizeof(rf4ce_ExpectedRemoteList_t);
177 #elif defined(RF4CE_GPMSO_API)
178 gpMSOBusAPI_Packet_t expectedRemotesPacket;
179 expectedRemotesPacket.msgId = gpMSOBusAPI_MsgId_ExpectedRemotes;
180 expectedRemotesPacket.index = 0;
181 expectedRemotesPacket.length =
sizeof(gpMSOBusAPI_ExpectedRemoteList_t);
183 #warning "No RF4CE API defined"
185 expectedRemotesPacket.msg.ExpectedRemoteList.numOfRemotes = 4;
187 for (i = 0 ; i < 4 ; ++i)
189 expectedRemotesPacket.msg.ExpectedRemoteList.remotes[i].weight = 6;
190 rc = strcpy_s(expectedRemotesPacket.msg.ExpectedRemoteList.remotes[i].expectedString,
sizeof(expectedRemotesPacket.msg.ExpectedRemoteList.remotes[i].expectedString), list[i]);
199 #ifdef RF4CE_GENMSO_API
200 IARM_Bus_Call(IARM_BUS_RFMGR_NAME, IARM_BUS_RFMGR_MsgRequest, (
void *)&expectedRemotesPacket,
sizeof(expectedRemotesPacket));
201 #elif defined(RF4CE_API)
202 IARM_Bus_Call(IARM_BUS_RF4CEMGR_NAME, IARM_BUS_RF4CEMGR_MsgRequest, (
void *)&expectedRemotesPacket,
sizeof(expectedRemotesPacket));
203 #elif defined(RF4CE_GPMSO_API)
204 IARM_Bus_Call(IARM_BUS_GPMGR_NAME, IARM_BUS_GPMGR_API_MsgRequest, (
void *)&expectedRemotesPacket,
sizeof(expectedRemotesPacket));
206 #warning "No RF4CE API defined"
217 if(status==IARM_RESULT_SUCCESS){
218 currentPowerMode=param.curState;
224 __TIMESTAMP(); LOG(
"_vrexEventHandler startup in power mode %d\n", currentPowerMode);
227 while (!_loadReceiverId()) {
228 LOG(
"I-ARM VREX Mgr:BAD DEVICE ID:Waiting 1 second to try again! \n");
234 if(!_loadReceiverId()){
235 LOG(
"I-ARM VREX Mgr:DEVICE ID READ FAILED - ABORTING");
241 LOG(
"I-ARM VREX Mgr: stbName is: %s\n", stbName.c_str());
243 LOG(
"I-ARM VREX Mgr: FAILED in getSTBName()!\n");
247 _loadConfiguration();
251 _configureRemotesToWatch();
256 pthread_mutex_unlock(&tMutexLock);
257 LOG(
"I-ARM VREX Mgr: %d\r\n", __LINE__);
260 LOG(
"I-ARM VREX Mgr Error case: %d\r\n", __LINE__);
261 status = IARM_RESULT_INVALID_STATE;
275 LOG(
"I-ARM VREX Mgr: HeartBeat at %s\r\n", ctime(&curr));
281 return IARM_RESULT_SUCCESS;
288 pthread_mutex_lock(&tMutexLock);
292 #ifdef RF4CE_GENMSO_API
295 #elif defined(RF4CE_API)
298 #elif defined(RF4CE_GPMSO_API)
302 #warning "No RF4CE API defined"
306 pthread_mutex_unlock(&tMutexLock);
307 pthread_mutex_destroy (&tMutexLock);
308 pthread_mutex_destroy(&power_save_mutex);
311 return IARM_RESULT_SUCCESS;
314 return IARM_RESULT_INVALID_STATE;
318 static bool _fileExists(
string fileName)
321 return (stat(fileName.c_str(), &buffer) == 0);
325 void _keyEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
329 #ifdef RF4CE_GENMSO_API
332 ((MSOBusAPI_UserCommand_t*)data)->keyStatus,((MSOBusAPI_UserCommand_t*)data)->commandCode);
334 if (((MSOBusAPI_UserCommand_t*)data)->keyStatus == KET_KEYUP && _sessionExists(((MSOBusAPI_UserCommand_t*)data)->remoteId)) {
336 _updateSessionTimeout(((MSOBusAPI_UserCommand_t*)data)->remoteId);
338 #elif defined(RF4CE_API)
341 ((rf4ce_UserCommand_t*)data)->keyStatus,((rf4ce_UserCommand_t*)data)->commandCode);
343 if (((rf4ce_UserCommand_t*)data)->keyStatus == KET_KEYUP && _sessionExists(((rf4ce_UserCommand_t*)data)->remoteId)) {
345 _updateSessionTimeout(((rf4ce_UserCommand_t*)data)->remoteId);
347 #elif defined(RF4CE_GPMSO_API)
350 ((gpMSOBusAPI_UserCommand_t*)data)->keyStatus,((gpMSOBusAPI_UserCommand_t*)data)->commandCode);
352 if (((gpMSOBusAPI_UserCommand_t*)data)->keyStatus == KET_KEYUP && _sessionExists(((gpMSOBusAPI_UserCommand_t*)data)->remoteId)) {
354 _updateSessionTimeout(((gpMSOBusAPI_UserCommand_t*)data)->remoteId);
357 #warning "No RF4CE API defined"
362 void _pairEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
365 #ifdef RF4CE_GENMSO_API
366 MSOBusAPI_Packet_t* busMsg;
367 busMsg = (MSOBusAPI_Packet_t*)data;
369 if(len != (busMsg->length +
sizeof(MSOBusAPI_Packet_t) -
sizeof(MSOBusAPI_Msg_t)))
371 LOG(
"I-ARM VREX Mgr: %i pairEventHandler with wrong length rec:%d exp:%d\r\n",eventId, len, (busMsg->length +
sizeof(MSOBusAPI_Packet_t) -
sizeof(MSOBusAPI_Msg_t)));
375 switch(busMsg->msgId)
377 case MSOBusAPI_MsgId_ValidationComplete:
379 switch(busMsg->msg.ValidationStatus.status)
381 case MSOBusAPI_ValidationResult_Success:
383 LOG(
"I-ARM VREX Mgr: New remote paired successfully <%d>", busMsg->msg.UserCommand.remoteId);
386 _configureRemotesToWatch();
397 #elif defined(RF4CE_API)
398 rf4ce_Packet_t* busMsg;
399 busMsg = (rf4ce_Packet_t*)data;
401 if(len != (busMsg->length +
sizeof(rf4ce_Packet_t) -
sizeof(rf4ce_Msg_t)))
403 LOG(
"I-ARM VREX Mgr: %i pairEventHandler with wrong length rec:%d exp:%d\r\n",eventId, len, (busMsg->length +
sizeof(rf4ce_Packet_t) -
sizeof(rf4ce_Msg_t)));
407 switch(busMsg->msgId)
409 case rf4ce_MsgId_ValidationComplete:
411 switch(busMsg->msg.ValidationStatus.status)
413 case rf4ce_ValidationResult_Success:
415 LOG(
"I-ARM VREX Mgr: New remote paired successfully <%d>", busMsg->msg.UserCommand.remoteId);
418 _configureRemotesToWatch();
429 #elif defined(RF4CE_GPMSO_API)
430 gpMSOBusAPI_Packet_t* busMsg;
431 busMsg = (gpMSOBusAPI_Packet_t*)data;
433 if(len != (busMsg->length +
sizeof(gpMSOBusAPI_Packet_t) -
sizeof(gpMSOBusAPI_Msg_t)))
435 LOG(
"I-ARM VREX Mgr: %i pairEventHandler with wrong length rec:%d exp:%d\r\n",eventId, len, (busMsg->length +
sizeof(gpMSOBusAPI_Packet_t) -
sizeof(gpMSOBusAPI_Msg_t)));
439 switch(busMsg->msgId)
441 case gpMSOBusAPI_MsgId_ValidationComplete:
443 switch(busMsg->msg.ValidationStatus.status)
445 case gpMSOBusAPI_ValidationResult_Success:
447 LOG(
"I-ARM VREX Mgr: New remote paired successfully <%d>", busMsg->msg.UserCommand.remoteId);
450 _configureRemotesToWatch();
462 #warning "No RF4CE API defined"
467 static void _updateSessionTimeout(
unsigned char remoteId)
469 VREXSession &vrSession = _findOrNewSession(remoteId);
470 vrSession.updateExpiration(defaultExpirationWindow);
474 #ifdef RF4CE_GENMSO_API
475 static bool _isVoiceRemote(MSOBusAPI_BindRemote_t boundRemote)
478 if (defaultRemoteName == boundRemote.Type)
483 #elif defined(RF4CE_API)
484 static bool _isVoiceRemote(rf4ce_BindRemote_t boundRemote)
487 if (defaultRemoteName == boundRemote.Type)
492 #elif defined(RF4CE_GPMSO_API)
493 static bool _isVoiceRemote(gpMSOBusAPI_BindRemote_t boundRemote)
496 if (defaultRemoteName == boundRemote.Type)
502 #warning "No RF4CE API defined"
505 static void _configureRemotesToWatch()
508 #ifdef RF4CE_GENMSO_API
509 MSOBusAPI_Packet_t getRequest;
510 getRequest.msgId = MSOBusAPI_MsgId_GetRfStatus;
511 getRequest.length =
sizeof(MSOBusAPI_RfStatus_t);
512 getRequest.index = 0;
514 IARM_Bus_Call(IARM_BUS_RFMGR_NAME, IARM_BUS_RFMGR_MsgRequest, (
void *)&getRequest,
sizeof(getRequest));
516 MSOBusAPI_Packet_t* dbusMsg = &getRequest;
517 MSOBusAPI_Msg_t* av = &(dbusMsg->msg);
518 #elif defined(RF4CE_API)
519 rf4ce_Packet_t getRequest;
520 getRequest.msgId = rf4ce_MsgId_GetRfStatus;
521 getRequest.length =
sizeof(rf4ce_RfStatus_t);
522 getRequest.index = 0;
524 IARM_Bus_Call(IARM_BUS_RF4CEMGR_NAME, IARM_BUS_RF4CEMGR_MsgRequest, (
void *)&getRequest,
sizeof(getRequest));
526 rf4ce_Packet_t* dbusMsg = &getRequest;
527 rf4ce_Msg_t* av = &(dbusMsg->msg);
528 #elif defined(RF4CE_GPMSO_API)
529 gpMSOBusAPI_Packet_t getRequest;
530 getRequest.msgId = gpMSOBusAPI_MsgId_GetRfStatus;
531 getRequest.length =
sizeof(gpMSOBusAPI_RfStatus_t);
532 getRequest.index = 0;
534 IARM_Bus_Call(IARM_BUS_GPMGR_NAME, IARM_BUS_GPMGR_API_MsgRequest, (
void *)&getRequest,
sizeof(getRequest));
536 gpMSOBusAPI_Packet_t* dbusMsg = &getRequest;
537 gpMSOBusAPI_Msg_t* av = &(dbusMsg->msg);
539 #warning "No RF4CE API defined"
541 switch(dbusMsg->msgId)
544 #ifdef RF4CE_GENMSO_API
545 case MSOBusAPI_MsgId_GetRfStatus:
546 #elif defined(RF4CE_API)
547 case rf4ce_MsgId_GetRfStatus:
548 #elif defined(RF4CE_GPMSO_API)
549 case gpMSOBusAPI_MsgId_GetRfStatus:
551 #warning "No RF4CE API defined"
564 #ifdef RF4CE_GENMSO_API
565 for(i=0; i < MSO_BUS_API_MAX_BINDED_REMOTES-1; i++)
566 #elif defined(RF4CE_API)
567 for(i=0; i < RF4CE_MAX_BINDED_REMOTES-1; i++)
568 #elif defined(RF4CE_GPMSO_API)
569 for(i=0; i < GP_MSO_BUS_API_MAX_BINDED_REMOTES-1; i++)
571 #warning
"No RF4CE API defined"
575 if(av->RfStatus.bindRemotes[i].ShortAddress != 0xFFFF) {
577 if (_isVoiceRemote(av->RfStatus.bindRemotes[i])) {
579 VREXSession &vrSession = _findOrNewSession(av->RfStatus.bindRemotes[i].remoteId, &(av->RfStatus), i);
580 LOG(
"Remote %d, remoteId <%d> remote_controller_type %s is voice enabled!\n", i, (
int)av->RfStatus.bindRemotes[i].remoteId, av->RfStatus.bindRemotes[i].Type);
583 LOG(
"Remote %d, remoteId <%d> remote_controller_type %s is *not* voice enabled!\n", i, (
int)av->RfStatus.bindRemotes[i].remoteId, av->RfStatus.bindRemotes[i].Type);
589 if(av->RfStatus.bindRemotes[i].ShortAddress != 0xFFFF)
591 LOG(
"Remote %d remote_fw_version %d.%d.%d.%d\n",i ,av->RfStatus.bindRemotes[i].VersionInfoSw[0], \
592 av->RfStatus.bindRemotes[i].VersionInfoSw[1], \
593 av->RfStatus.bindRemotes[i].VersionInfoSw[2], \
594 av->RfStatus.bindRemotes[i].VersionInfoSw[3]);
595 LOG(
"Remote %d remote_hw_revision %d.%d.%d.%d\n",i \
596 ,av->RfStatus.bindRemotes[i].VersionInfoHw.manufacturer, \
597 av->RfStatus.bindRemotes[i].VersionInfoHw.model, \
598 av->RfStatus.bindRemotes[i].VersionInfoHw.hwRevision, \
599 av->RfStatus.bindRemotes[i].VersionInfoHw.lotCode);
601 LOG(
"Remote %d remote_battery_voltage %i.%i V\n", i, (UInt16)((av->RfStatus.bindRemotes[i].BatteryLevelLoaded >> 6) & 0x03), (UInt16)(((av->RfStatus.bindRemotes[i].BatteryLevelLoaded & 0x3F)*100) >> 6));
602 LOG(
"Remote %d remoteId <%d> remote_controller_type %s\n", i, av->RfStatus.bindRemotes[i].remoteId, av->RfStatus.bindRemotes[i].Type);
614 static void _loadConfiguration()
618 string confName =
"vrexPrefs.json";
622 filePath =
"/opt/" + confName;
624 if (!_fileExists(filePath)) {
625 filePath =
"/mnt/nfs/env/" + confName;
628 if (!_fileExists(filePath)) {
629 LOG(
"I-ARM VREX Mgr: Configuration error. Configuration file(s) missing, using defaults\n");
631 else if ((fp = fopen(filePath.c_str(),
"r")) != NULL) {
632 LOG(
"I-ARM VREX Mgr: Reading configuration from <%s>\n", filePath.c_str());
637 while (!feof(fp) && confData.length() < 65535) {
638 memset(buf, 0,
sizeof(buf));
639 if(0 >= fread(buf, 1,
sizeof(buf)-1, fp))
641 LOG(
"Error: fread returned Negative or Zero value");
645 confData.append(buf);
652 LOG(
"I-ARM VREX Mgr: Configuration Read <%s>\n", confData.c_str());
655 map<string, JSONParser::varVal *> configuration;
657 configuration = parser.parse((
const unsigned char *)confData.c_str());
659 if (configuration[
"remoteName"]!=NULL) {
660 LOG(
"I-ARM VREX Mgr: Found remote name from config\n");
661 defaultRemoteName = configuration[
"remoteName"]->str;
664 LOG(
"I-ARM VREX Mgr: No valid remoteName from config using coded default\n");
666 if (configuration[
"route"]!=NULL) {
667 LOG(
"I-ARM VREX Mgr: Found ROUTE from config\n");
668 defaultRoute = configuration[
"route"]->str;
671 LOG(
"I-ARM VREX Mgr: No valid ROUTE from config using coded default\n");
673 if (configuration[
"defaultConversationLength"]!=NULL) {
674 LOG(
"I-ARM VREX Mgr: Found defaultConversationLength from config\n");
675 defaultConversationLength = atoi(configuration[
"defaultConversationLength"]->str.c_str());
678 LOG(
"I-ARM VREX Mgr: No valid defaultConversationLength from config using coded default\n");
680 if (configuration[
"defaultExpirationWindow"]!=NULL) {
681 LOG(
"I-ARM VREX Mgr: Found defaultExpirationWindow from config\n");
682 defaultExpirationWindow = atoi(configuration[
"defaultExpirationWindow"]->str.c_str());
685 LOG(
"I-ARM VREX Mgr: No valid defaultExpirationWindow from config using coded default\n");
688 LOG(
"I-ARM VREX Mgr: default route is: <%s>\n", defaultRoute.c_str());
689 LOG(
"I-ARM VREX Mgr: default conversation length is: <%d> seconds\n", defaultConversationLength);
690 LOG(
"I-ARM VREX Mgr: default expiration window is: <%d> seconds\n", defaultExpirationWindow);
691 LOG(
"I-ARM VREX Mgr: default remote name is: <%s>\n", defaultRemoteName.c_str());
694 static bool _loadReceiverId()
702 if ((fp = fopen(
"/opt/www/authService/deviceid.dat",
"r")) != NULL ||
703 (fp = fopen(
"/opt/www/whitebox/wbdevice.dat",
"r")) != NULL) {
704 bytesRead = fread(&buffer[0], 1,
sizeof(buffer)-1, fp);
705 receiverId.assign(buffer, bytesRead);
706 LOG(
"I-ARM VREX Mgr:Device ID %s\n", receiverId.c_str());
711 LOG(
"I-ARM VREX Mgr: Could not find device id file! \n");
721 static bool _getSTBName()
725 FILE* fp = fopen(VERSION_TXT_FILE,
"r");
728 unsigned char* buffer = NULL;
729 size_t imageNameLength = strlen(VERSION_TXT_IMAGENAME);
731 fseek(fp, 0L, SEEK_END);
732 filesize = ftell(fp);
733 if (filesize > (
long)imageNameLength) {
734 fseek(fp, 0L, SEEK_SET);
735 buffer =
new unsigned char[filesize + 1];
736 if (buffer != NULL) {
737 memset((
void*)buffer, 0, filesize + 1);
738 if (fread(buffer, filesize, 1, fp) > 0) {
739 buffer[filesize] = 0;
740 std::string contents((
const char*)buffer);
741 size_t startpos = contents.find(VERSION_TXT_IMAGENAME);
742 if (startpos != std::string::npos) {
744 contents = contents.substr(startpos + imageNameLength);
745 endpos = contents.find_first_of(
"_\r\n");
746 if (endpos != std::string::npos) {
747 stbName = contents.substr(0, endpos);
750 LOG(
"I-ARM VREX Mgr: getSTBName: Could not find value of %s!\n", VERSION_TXT_IMAGENAME);
753 LOG(
"I-ARM VREX Mgr: getSTBName: Could not find %s in file!\n", VERSION_TXT_IMAGENAME);
757 LOG(
"I-ARM VREX Mgr: getSTBName: Could not read from file!\n");
760 LOG(
"I-ARM VREX Mgr: getSTBName: Could not allocate buffer of size %ld!\n", filesize);
763 LOG(
"I-ARM VREX Mgr: getSTBName: File size of %ld is too small!\n", filesize);
768 LOG(
"I-ARM VREX Mgr: getSTBName: Could not open file %s!\n", VERSION_TXT_FILE);
778 static bool _sessionExists(
unsigned char remoteId)
780 return remotes.count(remoteId) == 0 ? false :
true;
784 #ifdef RF4CE_GENMSO_API
785 static VREXSession& _findOrNewSession(
unsigned char remoteId, MSOBusAPI_RfStatus_t *rfStatus,
int bindRemotesIndex)
787 if (remotes.count(remoteId) == 0) {
789 VREXSession newSession(remoteId, receiverId, defaultConversationLength, defaultRoute,aspect_ratio, guideLanguage, rfStatus, bindRemotesIndex, stbName);
790 remotes[remoteId] = newSession;
792 return remotes[remoteId];
794 #elif defined(RF4CE_API)
795 static VREXSession& _findOrNewSession(
unsigned char remoteId, rf4ce_RfStatus_t *rfStatus,
int bindRemotesIndex)
797 if (remotes.count(remoteId) == 0) {
799 VREXSession newSession(remoteId, receiverId, defaultConversationLength, defaultRoute, aspect_ratio, guideLanguage, rfStatus, bindRemotesIndex, stbName);
800 remotes[remoteId] = newSession;
802 return remotes[remoteId];
804 #elif defined(RF4CE_GPMSO_API)
805 static VREXSession& _findOrNewSession(
unsigned char remoteId, gpMSOBusAPI_RfStatus_t *rfStatus,
int bindRemotesIndex)
807 if (remotes.count(remoteId) == 0) {
809 VREXSession newSession(remoteId, receiverId, defaultConversationLength, defaultRoute, aspect_ratio, guideLanguage, rfStatus, bindRemotesIndex, stbName);
810 remotes[remoteId] = newSession;
812 return remotes[remoteId];
815 #warning "No RF4CE API defined"
818 static void handleSettingsFromServer(
const char *jsonData){
820 string paramData=jsonData;
821 map<string, JSONParser::varVal *> settings;
822 settings = parser.parse((
const unsigned char *) jsonData);
824 if(settings[
"VoiceControlOptIn"]!=NULL)
826 __TIMESTAMP();LOG(
"got VoiceControlOptIn %i",settings[
"VoiceControlOptIn"]->
boolean);
827 bVoiceControl=settings[
"VoiceControlOptIn"]->boolean;
829 if(settings[
"parameters"]!=NULL){
831 settings = parser.parse((
const unsigned char *) settings[
"parameters"]->str.c_str());
833 int start=paramData.find(
"{",2);
834 int end=paramData.find(
"}",2);
835 paramData=paramData.substr(start,end);
837 settings = parser.parse((
const unsigned char *) paramData.c_str());
841 if(settings[
"vrexURL"]!=NULL)
843 __TIMESTAMP();LOG(
"got vrexURL %s",settings[
"vrexURL"]->str.c_str());
844 defaultRoute=settings[
"vrexURL"]->str;
847 if(settings[
"GuideLanguage"]!=NULL)
849 __TIMESTAMP();LOG(
"got GuideLanguage %s",settings[
"GuideLanguage"]->str.c_str());
850 guideLanguage=settings[
"GuideLanguage"]->str;
853 if(settings[
"aspect_ratio"]!=NULL)
855 __TIMESTAMP();LOG(
"got aspect_ratio %s",settings[
"aspect_ratio"]->str.c_str());
856 aspect_ratio=settings[
"aspect_ratio"]->str;
859 typedef std::map<unsigned char, VREXSession>::iterator it_type;
860 for(it_type iterator = remotes.begin(); iterator != remotes.end(); iterator++) {
861 iterator->second.changeServerDetails(defaultRoute, aspect_ratio,guideLanguage);
866 static void _vrexEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
868 __TIMESTAMP(); LOG(
"_vrexEventHandler event - %d", eventId);
877 pthread_mutex_lock(&tMutexLock);
880 unsigned char remoteId = vrexEventData->
remoteId;
884 if (is_powered_on()==
false){
885 __TIMESTAMP(); LOG(
"_vrexEventHandler standyby mode - No Action");
903 pthread_mutex_unlock(&tMutexLock);
908 case IARM_BUS_VREXMGR_EVENT_SETTINGS:
909 __TIMESTAMP();LOG(
"got IARM_BUS_VREXMGR_EVENT_SETTINGS:%s",vrexEventData->data.jsonEvent.jsonData);
911 handleSettingsFromServer((
const char *)(vrexEventData->data.jsonEvent.jsonData));
914 case IARM_BUS_VREXMGR_EVENT_MOTION:
916 if (bVoiceControl==
false){
917 __TIMESTAMP(); LOG(
"_vrexEventHandler voice disabled - No Action");
918 pthread_mutex_unlock(&tMutexLock);
923 __TIMESTAMP();LOG(
"_vrexEventHandler Motion Event x=%lf, y=%lf, z=%lf", mEvent->
x, mEvent->y, mEvent->z);
924 MotionInfo motion = { mEvent->
x, mEvent->y, mEvent->z };
925 VREXSession &vrSession = _findOrNewSession(remoteId);
926 if(!vrSession.onMotion(motion)) {
927 __TIMESTAMP();LOG(
"Error attempting Knock Knock request!\n");
931 case IARM_BUS_VREXMGR_EVENT_SPEECH:
933 if (bVoiceControl==
false){
934 __TIMESTAMP(); LOG(
"_vrexEventHandler voice disabled - No Action");
935 pthread_mutex_unlock(&tMutexLock);
939 switch(sEvent->type) {
940 case IARM_BUS_VREXMGR_SPEECH_BEGIN:
942 __TIMESTAMP();LOG(
"_vrexEventHandler Speech Begin Event");
943 VREXSession &vrSession = _findOrNewSession(remoteId);
946 audioInfo.mimeType = (
char *)sEvent->data.begin.mimeType;
947 audioInfo.subType = (
char *)sEvent->data.begin.subType;
948 audioInfo.language = (
char *)sEvent->data.begin.language;
951 if (audioInfo.language.empty()) audioInfo.language =
"en";
953 __TIMESTAMP();LOG(
"AudioInfo: mime: <%s>, subType: <%s>, language: <%s> ",
954 audioInfo.mimeType.c_str(), audioInfo.subType.c_str(), audioInfo.language.c_str());
955 if(vrSession.onStreamStart(audioInfo)) {
956 vrSession.sendState(BeginRecording);
959 __TIMESTAMP();LOG(
"_vrexEventHandler onStreamStart failed");
960 vrSession.sendState(FinishedRecordingWithErrors);
964 case IARM_BUS_VREXMGR_SPEECH_FRAGMENT:
966 if (bVoiceControl==
false){
967 __TIMESTAMP(); LOG(
"_vrexEventHandler voice disabled - No Action");
968 pthread_mutex_unlock(&tMutexLock);
971 VREXSession &vrSession = _findOrNewSession(remoteId);
972 vrSession.onStreamData(&(sEvent->data.fragment.fragment[0]), sEvent->data.fragment.length);
973 __TIMESTAMP();LOG(
"_vrexEventHandler Speech Fragment Event \n");
976 case IARM_BUS_VREXMGR_SPEECH_END:
978 if (bVoiceControl==
false){
979 __TIMESTAMP(); LOG(
"_vrexEventHandler voice disabled - No Action");
980 pthread_mutex_unlock(&tMutexLock);
983 __TIMESTAMP();LOG(
"_vrexEventHandler Speech End Event \n");
984 VREXSession &vrSession = _findOrNewSession(remoteId);
985 vrSession.onStreamEnd((AudioStreamEndReason)sEvent->data.end.reason);
986 vrSession.sendState(FinishedRecording);
990 __TIMESTAMP();LOG(
"_vrexEventHandler Error, Unknown Speech Event \n");
996 __TIMESTAMP();LOG(
"_vrexEventHandler unknown event type \n");
1000 pthread_mutex_unlock(&tMutexLock);
1003 __TIMESTAMP();LOG(
"_vrexEventHandler event type not meant for me <%s>...\n", owner);
1007 static bool is_powered_on(
void)
1009 if(currentPowerMode==-1)
1014 if(status==IARM_RESULT_SUCCESS){
1015 currentPowerMode=param.curState;
1018 currentPowerMode=-1;
1021 return currentPowerMode;
1029 IARM_Bus_CommonAPI_PowerPreChange_Param_t *param = (IARM_Bus_CommonAPI_PowerPreChange_Param_t *) arg;
1030 IARM_Result_t result = IARM_RESULT_SUCCESS;
1032 __TIMESTAMP(); STATUS_LOG(
"PowerPreChange state to %d (STANDBY %d ::ON %d)\n", param->newState, IARM_BUS_PWRMGR_POWERSTATE_STANDBY,
1033 IARM_BUS_PWRMGR_POWERSTATE_ON);
1035 pthread_mutex_lock(&power_save_mutex);
1036 currentPowerMode = param->newState;
1038 pthread_mutex_unlock(&power_save_mutex);
1039 __TIMESTAMP(); STATUS_LOG(
"PowerPreChange set state to %d \n", currentPowerMode);