RDK Documentation (Open Sourced RDK Components)
CECCmdTest.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 /**
22 * @defgroup hdmicec
23 * @{
24 * @defgroup tests
25 * @{
26 **/
27 
28 #include <iostream>
29 #include <string>
30 
31 #include "libIBus.h"
32 #include "ccec/Messages.hpp"
33 #include "ccec/Assert.hpp"
34 #include "ccec/Connection.hpp"
35 #include "ccec/host/RDK.hpp"
36 #include "ccec/MessageEncoder.hpp"
37 #include "ccec/LibCCEC.hpp"
38 #include "ccec/drivers/iarmbus/CecIARMBusMgr.h"
39 
40 using namespace std;
41 
42 
43 int main(int argc, char *argv[])
44 {
45  int i = 0, j = 0;
46  string command;
47  size_t pos = 0;
48  std::string token;
49  string delimiter = ":";
50  bool running = true;
51  bool inited = false;
52 
53  Connection *testConnection = NULL;
54  IARM_Bus_Init("CECClient");
56 
57  IARM_Result_t ret = IARM_RESULT_SUCCESS;
59  memset(&dataToSend, 0, sizeof(dataToSend));
60 
61  cout << "********Entered CECCmd tool***********\n";
62  cout << "Options : " << endl;
63  cout << "1 - To enable CEC\n2 - To disable CEC\n";
64  cout << "3 - Send CEC Command\n4 - Exit test application \n";
65  while(running)
66  {
67  cout << "Please enter your selection : \n";
68  if (!(cin >> j)) {
69  cout << "Please enter numbers only." << endl;
70  cin.clear();
71  cin.ignore(10000,'\n');
72  continue;
73  }
74 
75  switch (j)
76  {
77  case 1:
78  if(false == inited)
79  {
80  cout << "LibCCEC init....................\n";
82  inited = true;
83  }
84  break;
85  case 2:
86  if(true == inited)
87  {
88  cout << "LibCCEC term....................\n";
90  inited = false;
91  }
92  break;
93  case 3:
94  cout << "Please enter your CEC Command - eg: 3F:82:10:00" << endl;
95  cin >> command;
96  cout << "Command is : " << command << endl;
97  i = 0;
98  while ((pos = command.find(delimiter)) != string::npos) {
99  token = command.substr(0, pos);
100  dataToSend.data[i++] = (int) strtol(token.c_str(), NULL, 16);
101  command.erase(0, pos + delimiter.length());
102  }
103  dataToSend.data[i++] = (int) strtol(command.c_str(), NULL, 16);
104  dataToSend.length = i;
105  ret = IARM_Bus_Call(IARM_BUS_CECMGR_NAME,IARM_BUS_CECMGR_API_Send,(void *)&dataToSend, sizeof(dataToSend));
106  if( IARM_RESULT_SUCCESS != ret)
107  {
108  cout << "Iarm call failed retval " << ret << endl;
109  }
110  break;
111  case 4:
112  if(inited != false)
114 
115  running = false;
116  break;
117  default:
118  cout << "Invalid Entry" << endl;
119  j = 0;
120  break;
121  }
122  }
123 
125  IARM_Bus_Term();
126 }
127 //Note: To enable yocto build for the test app, please add the folder name 'tests' in the
128 //SUBDIRS & DIST_SUBDIRS parameters in /hdmicec/Makefile.am
129 
130 
131 /** @} */
132 /** @} */
IARM_Bus_Term
IARM_Result_t IARM_Bus_Term(void)
This API is used to terminate the IARM-Bus library.
LibCCEC::getInstance
static LibCCEC & getInstance(void)
This function is used to create the instance for CEC.
Definition: LibCCEC.cpp:61
IARM_Bus_Call
IARM_Result_t IARM_Bus_Call(const char *ownerName, const char *methodName, void *arg, size_t argLen)
This API is used to Invoke RPC method by its application name and method name.
Definition: iarm_bus.c:57
LibCCEC::init
void init(const char *name=0)
This function is used to initialize CEC by starting the driver and doing host-specific initialization...
Definition: LibCCEC.cpp:84
Connection
The connection class provides APIs that allows the application to access CEC Bus. A connection is a t...
Definition: Connection.hpp:57
IARM_BUS_CECMGR_NAME
#define IARM_BUS_CECMGR_NAME
Definition: CecIARMBusMgr.h:41
IARM_Bus_Disconnect
IARM_Result_t IARM_Bus_Disconnect(void)
This API disconnect Application from IARM Bus so the application will not receive any IARM event or R...
libIBus.h
RDK IARM-Bus API Declarations.
IARM_Bus_Connect
IARM_Result_t IARM_Bus_Connect(void)
This API is used to connect application to the IARM bus daemon. After connected, the application can ...
Definition: iarmMgrMocks.cpp:33
_IARM_Bus_CECMgr_Send_Param_t
Definition: CecIARMBusMgr.h:71
LibCCEC::term
void term(void)
This function is used to stop CEC by terminating the connection and stoping the driver.
Definition: LibCCEC.cpp:111
IARM_Bus_Init
IARM_Result_t IARM_Bus_Init(const char *name)
This API is used to initialize the IARM-Bus library.
Definition: iarmMgrMocks.cpp:38