RDK Documentation (Open Sourced RDK Components)
CECMonitor.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 "ccec/Connection.hpp"
32 #include "ccec/CECFrame.hpp"
33 #include "libIBus.h"
34 #include "ccec/Messages.hpp"
35 #include "ccec/MessageDecoder.hpp"
36 #include "ccec/MessageProcessor.hpp"
37 
38 
39 static int libcecInitStatus;
41 {
42 public:
43  TestFrameListener(MessageProcessor &processor) : processor(processor) {}
44  void notify(const CECFrame &in) const {
45  const uint8_t *buf = NULL;
46  size_t len = 0;
47 
48  printf("\n==================================================\n");
49  printf("Received CEC Frame: \n");
50  in.getBuffer(&buf, &len);
51 
52  for (int i = 0; i < len; i++) {
53  printf("%02X ", (int) *(buf + i));
54  }
55  printf("\n");
56  MessageDecoder(processor).decode(in);
57  printf("==================================================\n");
58  }
59  ~TestFrameListener() {}
60 private:
61  MessageProcessor &processor;
62 };
63 
65 {
66 public:
67  TestCecProcessor(Connection &conn) : conn(conn) {}
68  void process (const ActiveSource &msg, const Header &header)
69  {
70  printHeader(header);
71  printf("Command: ActiveSource\n");
72  printf("%s : %s : %s \n",GetOpName(msg.opCode()),msg.physicalAddress.name().c_str(),msg.physicalAddress.toString().c_str());
73  }
74  void process (const InActiveSource &msg, const Header &header)
75  {
76  printHeader(header);
77  printf("Command: InActiveSource\n");
78  printf("%s : %s : %s \n",GetOpName(msg.opCode()),msg.physicalAddress.name().c_str(),msg.physicalAddress.toString().c_str());
79  }
80  void process (const ImageViewOn &msg, const Header &header)
81  {
82  printHeader(header);
83  printf("Command: ImageViewOn \n");
84  }
85  void process (const TextViewOn &msg, const Header &header)
86  {
87  printHeader(header);
88  printf("Command: TextViewOn\n");
89  }
90  void process (const RequestActiveSource &msg, const Header &header)
91  {
92  printHeader(header);
93  printf("Command: RequestActiveSource\n");
94  }
95  void process (const Standby &msg, const Header &header)
96  {
97  printHeader(header);
98  printf("Command: Standby\n");
99  }
100  void process (const GetCECVersion &msg, const Header &header)
101  {
102  printHeader(header);
103  printf("Command: GetCECVersion\n");
104  }
105  void process (const CECVersion &msg, const Header &header)
106  {
107  printHeader(header);
108  printf("Command: CECVersion\n");
109  printf("Version : %s \n",msg.version.toString().c_str());
110  }
111  void process (const SetMenuLanguage &msg, const Header &header)
112  {
113  printHeader(header);
114  printf("Command: SetMenuLanguage\n");
115  printf("Language : %s \n",msg.language.toString().c_str());
116  }
117  void process (const GiveOSDName &msg, const Header &header)
118  {
119  printHeader(header);
120  printf("Command: GiveOSDName\n");
121  }
122  void process (const GivePhysicalAddress &msg, const Header &header)
123  {
124  printHeader(header);
125  printf("Command: GivePhysicalAddress\n");
126  }
127  void process (const GiveDeviceVendorID &msg, const Header &header)
128  {
129  printHeader(header);
130  printf("Command: GiveDeviceVendorID\n");
131  }
132  void process (const SetOSDString &msg, const Header &header)
133  {
134  printHeader(header);
135  printf("Command: SetOSDString\n");
136  printf("OSDString : %s\n",msg.osdString.toString().c_str());
137  }
138  void process (const SetOSDName &msg, const Header &header)
139  {
140  printHeader(header);
141  printf("Command: SetOSDName\n");
142  printf("OSDName : %s\n",msg.osdName.toString().c_str());
143  }
144  void process (const RoutingChange &msg, const Header &header)
145  {
146  printHeader(header);
147  printf("Command: RoutingChange\n");
148  printf("Routing Change From : %s\n",msg.from.toString().c_str());
149  printf("Routing Change to : %s\n",msg.to.toString().c_str());
150  }
151  void process (const RoutingInformation &msg, const Header &header)
152  {
153  printHeader(header);
154  printf("Command: RoutingInformation\n");
155  printf("Routing Information to Sink : %s\n",msg.toSink.toString().c_str());
156  }
157  void process (const SetStreamPath &msg, const Header &header)
158  {
159  printHeader(header);
160  printf("Command: SetStreamPath\n");
161  printf("Set Stream Path to Sink : %s\n",msg.toSink.toString().c_str());
162  }
163  void process (const GetMenuLanguage &msg, const Header &header)
164  {
165  printHeader(header);
166  printf("Command: GetMenuLanguage\n");
167  }
168  void process (const ReportPhysicalAddress &msg, const Header &header)
169  {
170  printHeader(header);
171  printf("Command: ReportPhysicalAddress\n");
172  }
173  void process (const DeviceVendorID &msg, const Header &header)
174  {
175  printHeader(header);
176  printf("Command: DeviceVendorID\n");
177  printf("VendorID : %s\n",msg.vendorId.toString().c_str());
178  }
179 
180  //virtual void process (const UserControlReleased &msg, const Header &header) {header.print();msg.print();}
181  //virtual void process (const UserControlPressed &msg, const Header &header) {header.print();msg.print();}
182  void process (const GiveDevicePowerStatus &msg, const Header &header)
183  {
184  printHeader(header);
185  printf("Command: GiveDevicePowerStatus\n");
186  }
187  void process (const ReportPowerStatus &msg, const Header &header)
188  {
189  printHeader(header);
190  printf("Command: ReportPowerStatus\n");
191  printf("Power Status: %s\n",msg.status.toString().c_str());
192  }
193  void process (const FeatureAbort &msg, const Header &header)
194  {
195  printHeader(header);
196  printf("Command: FeatureAbort\n");
197  }
198  void process (const Abort &msg, const Header &header)
199  {
200  printHeader(header);
201  printf("Command: Abort\n");
202  }
203  void process (const Polling &msg, const Header &header) {
204  printHeader(header);
205  printf("Command: Polling\n");
206  }
207 private:
208  Connection conn;
209  void printHeader(const Header &header)
210  {
211  printf("Header : From : %s \n", header.from.toString().c_str());
212  printf("Header : to : %s \n", header.to.toString().c_str());
213  }
214 
215 };
216 
217 
218 
219 int main()
220 {
221  char test_status = 'r';
222  IARM_Bus_Init("CECMonitorClient");
224  if(0 == libcecInitStatus)
225  {
226  try
227  {
229  libcecInitStatus++;
230  }
231  catch (const std::exception e)
232  {
233  printf("Caught LibCCEC exception");
234  }
235  }
236  Connection testConnection(LogicalAddress::UNREGISTERED,false, "CEC Monitor connection");
237  testConnection.open();
238  TestCecProcessor proc(testConnection);
239  TestFrameListener frameListener(proc);
240  testConnection.addFrameListener(&frameListener);
241 
242  while(test_status != 'q')
243  {
244  printf("CECMonitor Test App Started.Please enter 'q' to quit the test app \n");
245  test_status = getchar();
246  }
247 
248 
249  testConnection.close();
250 
251  if(1 == libcecInitStatus)
252  {
254  }
255  libcecInitStatus--;
256 
258  IARM_Bus_Term();
259 
260  return 1;
261 }
262 
263 //Note: To enable yocto build for the test app, please add the folder name 'tests' in the
264 //SUBDIRS & DIST_SUBDIRS parameters in /hdmicec/Makefile.am
265 
266 
267 /** @} */
268 /** @} */
FeatureAbort
Definition: Messages.hpp:369
IARM_Bus_Term
IARM_Result_t IARM_Bus_Term(void)
This API is used to terminate the IARM-Bus library.
MessageProcessor
The MessageProcessor class implements a set of overloaded process() methods, with each handling a spe...
Definition: MessageProcessor.hpp:58
GetCECVersion
Definition: Messages.hpp:161
SetOSDString
Definition: Messages.hpp:249
LibCCEC::getInstance
static LibCCEC & getInstance(void)
This function is used to create the instance for CEC.
Definition: LibCCEC.cpp:61
GiveOSDName
Definition: Messages.hpp:220
TextViewOn
Definition: Messages.hpp:119
GiveDevicePowerStatus
Definition: Messages.hpp:334
FrameListener
Definition: FrameListener.hpp:39
SetOSDName
Definition: Messages.hpp:226
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
DeviceVendorID
Definition: Messages.hpp:311
GivePhysicalAddress
Definition: Messages.hpp:272
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...
TestFrameListener
Definition: CECMonitor.cpp:40
Header
Definition: Header.hpp:41
Polling
Definition: Messages.hpp:649
libIBus.h
RDK IARM-Bus API Declarations.
SetMenuLanguage
Definition: Messages.hpp:190
Standby
Definition: Messages.hpp:155
MessageDecoder
When receiving the message, the raw bytes arrived in a CECFrame are converted to the corresponding Hi...
Definition: MessageDecoder.hpp:45
RoutingInformation
Definition: Messages.hpp:419
ActiveSource
The Message API allows the application to send or receive high-level CEC message construct instead of...
Definition: Messages.hpp:88
GetMenuLanguage
Definition: Messages.hpp:214
SetStreamPath
Definition: Messages.hpp:443
TestCecProcessor
Definition: CECMonitor.cpp:64
GiveDeviceVendorID
Definition: Messages.hpp:305
ReportPhysicalAddress
Definition: Messages.hpp:278
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
RequestActiveSource
Definition: Messages.hpp:149
RoutingChange
Definition: Messages.hpp:394
ImageViewOn
Definition: Messages.hpp:112
ReportPowerStatus
Definition: Messages.hpp:340
CECFrame
Definition: CECFrame.hpp:40
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
CECVersion
Definition: Messages.hpp:167
Abort
Definition: Messages.hpp:363