RDK Documentation (Open Sourced RDK Components)
BasicTest.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 
29 #include <stdio.h>
30 #include <unistd.h>
31 #include "libIBus.h"
32 
33 #include "ccec/Messages.hpp"
34 #include "ccec/Assert.hpp"
35 #include "ccec/Connection.hpp"
36 #include "ccec/host/RDK.hpp"
37 #include "ccec/MessageEncoder.hpp"
38 #include "ccec/LibCCEC.hpp"
39 
40 
41 int main(int argc, char *argv[])
42 {
43 
44  IARM_Bus_Init("CECClient");
46 
48  Connection conn(LogicalAddress::UNREGISTERED, false);;
49  conn.open();
50 
51  try{
52  int logicalAddress;
53  logicalAddress = LibCCEC::getInstance().getLogicalAddress(3);
54  printf("Got logical Address here logicalAddress : %d !!\n", logicalAddress);
55  }
56  catch (const std::exception e) {
57  printf("getLogicalAddress caught exception %s \r\n",e.what());
58  }
59 
61  IARM_Result_t ret = IARM_RESULT_SUCCESS;
63  PhysicalAddress phy(1, 0, 0, 0);
64 
65  unsigned int option,i,j = 20;
66  printf("\n Enter test option : \n 1 - Connected Device Test \n 2 - Logical Address Test \n 3 - Default test\n");
67  scanf("%d", &option);
68 
69  switch(option)
70  {
71 
72  case 1:
73  param1.status = true;
74  IARM_Bus_Call(IARM_BUS_CECHOST_NAME,IARM_BUS_CEC_HOST_EnableDevMgr,(void *)&param1,sizeof(param1));
75 
76  while(j)
77  {
78  try
79  {
80  ret = IARM_Bus_Call(IARM_BUS_CECHOST_NAME, IARM_BUS_CEC_HOST_GetDevStatus, (void*)&param, sizeof(param));
81  if (ret != IARM_RESULT_SUCCESS )
82  {
83  printf("%s :: IARM_BUS_CEC_HOST_GetDevStatus failes \n",__FUNCTION__);
84  }
85  printf("Connected Devices : \n");
86  for (i = 0; i < 14; i++)
87  {
88  if (0 != param.devices[i].isConnected)
89  {
90  printf("Logical Address : %d \n", param.devices[i].logicalAddress);
91  }
92  }
93  }
94  catch (const std::exception e) {
95  printf("%s failed \n", __FUNCTION__);
96  }
97  sleep(5);
98 
99  j--;
100  }
101  break;
102  case 2:
103  while(j)
104  {
105  /*Can try hdmi hot plug events during this test*/
106  try{
107  int logicalAddress;
108  logicalAddress = LibCCEC::getInstance().getLogicalAddress(3);
109  printf("Got logical Address here logicalAddress : %d !!\n", logicalAddress);
110  }
111  catch (const std::exception e) {
112  printf("getLogicalAddress caught exception %s \r\n",e.what());
113  }
114 
115  sleep(5);
116  j--;
117  }
118  break;
119 
120  case 3:
121  {
122  conn.sendTo(LogicalAddress::TV, MessageEncoder().encode(ActiveSource(phy)));
123  printf("Send ActiveSource completed\r\n");
124  }
125 
126  sleep(1);
127  {
128  conn.sendTo(LogicalAddress::TV, MessageEncoder().encode(ImageViewOn()));
129  printf("===================Sending ImageViewOn completed\r\n");
130  }
131  sleep(1);
132  {
133  conn.sendTo(LogicalAddress::TV, MessageEncoder().encode(TextViewOn()));
134  printf("===================Sending TextViewOn completed\r\n");
135  }
136  sleep(15);
137  {
138  conn.sendTo(LogicalAddress::TV, MessageEncoder().encode(InActiveSource(phy)));
139  printf("===================Sending Standby completed...\r\n");
140  }
141  sleep(25);
142  break;
143  default:
144  break;
145  }
146 
147  conn.close();
148 
150 
152  IARM_Bus_Term();
153 }
154 //Note: To enable yocto build for the test app, please add the folder name 'tests' in the
155 //SUBDIRS & DIST_SUBDIRS parameters in /hdmicec/Makefile.am
156 
157 
158 /** @} */
159 /** @} */
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
TextViewOn
Definition: Messages.hpp:119
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
PhysicalAddress
Definition: Operands.hpp:314
IARM_Bus_Disconnect
IARM_Result_t IARM_Bus_Disconnect(void)
This API disconnect Application from IARM Bus so the application will not receive any IARM event or R...
_IARM_Bus_CECHost_EnableDevMgr_Param_t
Definition: RDK.hpp:51
libIBus.h
RDK IARM-Bus API Declarations.
MessageEncoder
High-level messages are encoded by the MessageEncoder into raw bytes and placed in a CECFrame.
Definition: MessageEncoder.hpp:46
ActiveSource
The Message API allows the application to send or receive high-level CEC message construct instead of...
Definition: Messages.hpp:88
LibCCEC::getLogicalAddress
int getLogicalAddress(int devType)
This function is used to get CEC device logical address starting the connection.
Definition: LibCCEC.cpp:152
InActiveSource
Definition: Messages.hpp:125
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
ImageViewOn
Definition: Messages.hpp:112
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
_IARM_Bus_CECHost_GetDeviceStatus_Param_t
Definition: RDK.hpp:67