2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
33 #include "../../include/CECExports.h"
34 #include "../lib/util/threads.h"
35 #include "../lib/util/misc.h"
36 #include "../lib/util/StdString.h"
45 #define CEC_TEST_CLIENT_VERSION 1
47 void flush_log(ICECDevice
*cecParser
)
49 cec_log_message message
;
50 while (cecParser
&& cecParser
->GetNextLogMessage(&message
))
52 switch (message
.level
)
55 cout
<< "ERROR: " << message
.message
.c_str() << endl
;
58 cout
<< "WARNING: " << message
.message
.c_str() << endl
;
61 cout
<< "NOTICE: " << message
.message
.c_str() << endl
;
64 cout
<< "DEBUG: " << message
.message
.c_str() << endl
;
70 void list_devices(ICECDevice
*parser
)
72 cout
<< "Found devices: ";
73 vector
<cec_device
> devices
;
74 int iDevicesFound
= parser
->FindDevices(devices
);
75 if (iDevicesFound
<= 0)
78 cout
<< "Not supported yet, sorry!" << endl
;
80 cout
<< "NONE" << endl
;
85 cout
<< devices
.size() << endl
;
86 for (unsigned int iDevicePtr
= 0; iDevicePtr
< devices
.size(); iDevicePtr
++)
89 strDevice
.Format("device: %d\npath: %s\ncom port: %s", iDevicePtr
, devices
[iDevicePtr
].path
.c_str(), devices
[0].comm
.c_str());
90 cout
<< endl
<< strDevice
.c_str() << endl
;
95 void show_help(const char* strExec
)
98 strExec
<< " {-h|--help|-l|--list-devices|[COM PORT]}" << endl
<<
100 "parameters:" << endl
<<
101 "\t-h --help Shows this help text" << endl
<<
102 "\t-l --list-devices List all devices on this system" << endl
<<
103 "\t[COM PORT] The com port to connect to. If no COM port is given, the client tries to connect to the first device that is detected" << endl
;
106 int main (int argc
, char *argv
[])
108 ICECDevice
*parser
= LoadLibCec("CEC Tester");
109 if (!parser
&& parser
->GetMinVersion() > CEC_TEST_CLIENT_VERSION
)
111 cout
<< "Unable to create parser. Is libcec.dll present?" << endl
;
115 strLog
.Format("CEC Parser created - libcec version %d", parser
->GetLibVersion());
116 cout
<< strLog
.c_str() << endl
;
118 //make stdin non-blocking
120 int flags
= fcntl(0, F_GETFL
, 0);
122 fcntl(0, F_SETFL
, flags
);
128 cout
<< "no serial port given. trying autodetect: ";
129 vector
<cec_device
> devices
;
130 int iDevicesFound
= parser
->FindDevices(devices
);
131 if (iDevicesFound
<= 0)
133 cout
<< "FAILED" << endl
;
134 UnloadLibCec(parser
);
139 cout
<< endl
<< " path: " << devices
[0].path
<< endl
<<
140 " com port: " << devices
[0].comm
<< endl
<< endl
;
141 strPort
= devices
[0].comm
;
144 else if (!strcmp(argv
[1], "--list-devices") || !strcmp(argv
[1], "-l"))
146 list_devices(parser
);
147 UnloadLibCec(parser
);
150 else if (!strcmp(argv
[1], "--help") || !strcmp(argv
[1], "-h"))
160 if (!parser
->Open(strPort
.c_str()))
162 cout
<< "unable to open the device on port " << strPort
<< endl
;
164 UnloadLibCec(parser
);
168 cout
<< "cec device opened" << endl
;
169 usleep(CEC_SETTLE_DOWN_TIME
);
171 parser
->PowerOnDevices();
174 parser
->SetActiveView();
177 bool bContinue(true);
178 cout
<< "waiting for input" << endl
;
190 if (GetWord(input
, command
))
196 vector
<uint8_t> bytes
;
197 while (GetWord(input
, strvalue
) && HexStrToInt(strvalue
, ivalue
))
198 bytes
.push_back(ivalue
);
200 parser
->Transmit(bytes
);
202 else if (command
== "am")
206 vector
<uint8_t> bytes
;
207 if (GetWord(input
, strvalue
) && HexStrToInt(strvalue
, ackmask
))
209 parser
->SetAckMask((cec_logical_address
) ackmask
);
212 else if (command
== "ping")
216 else if (command
== "bl")
218 parser
->StartBootloader();
220 else if (command
== "q" || command
== "quit")
226 cout
<< "waiting for input" << endl
;
228 CCondition::Sleep(50);
231 parser
->PowerOffDevices();
233 UnloadLibCec(parser
);