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/
41 #include "../lib/platform/os.h"
42 #include "../lib/implementations/CECCommandHandler.h"
46 using namespace PLATFORM
;
48 #define CEC_TEST_CLIENT_VERSION 1
50 #include <cecloader.h>
52 int g_cecLogLevel(CEC_LOG_ALL
);
54 bool g_bShortLog(false);
56 uint8_t g_iHDMIPort(CEC_DEFAULT_HDMI_PORT
);
57 cec_logical_address
g_iBaseDevice((cec_logical_address
)CEC_DEFAULT_BASE_DEVICE
);
58 cec_device_type_list g_typeList
;
59 bool g_bSingleCommand(false);
61 bool g_bHardExit(false);
63 ICECCallbacks g_callbacks
;
65 inline void PrintToStdOut(const char *strFormat
, ...)
70 va_start(argList
, strFormat
);
71 strLog
.FormatV(strFormat
, argList
);
74 CLockObject
lock(g_outputMutex
);
75 cout
<< strLog
<< endl
;
78 inline bool HexStrToInt(const std::string
& data
, uint8_t& value
)
81 if (sscanf(data
.c_str(), "%x", &iTmp
) == 1)
88 value
= (uint8_t) iTmp
;
96 //get the first word (separated by whitespace) from string data and place that in word
97 //then remove that word from string data
98 bool GetWord(string
& data
, string
& word
)
100 stringstream
datastream(data
);
104 if (datastream
.fail())
110 size_t pos
= data
.find(word
) + word
.length();
112 if (pos
>= data
.length())
118 data
= data
.substr(pos
);
121 datastream
.str(data
);
124 if (datastream
.fail())
130 int CecLogMessage(void *UNUSED(cbParam
), const cec_log_message
&message
)
132 if ((message
.level
& g_cecLogLevel
) == message
.level
)
135 switch (message
.level
)
138 strLevel
= "ERROR: ";
140 case CEC_LOG_WARNING
:
141 strLevel
= "WARNING: ";
144 strLevel
= "NOTICE: ";
146 case CEC_LOG_TRAFFIC
:
147 strLevel
= "TRAFFIC: ";
150 strLevel
= "DEBUG: ";
156 CStdString strFullLog
;
157 strFullLog
.Format("%s[%16lld]\t%s", strLevel
.c_str(), message
.time
, message
.message
);
158 PrintToStdOut(strFullLog
.c_str());
160 if (g_logOutput
.is_open())
163 g_logOutput
<< message
.message
<< endl
;
165 g_logOutput
<< strFullLog
.c_str() << endl
;
172 int CecKeyPress(void *UNUSED(cbParam
), const cec_keypress
&UNUSED(key
))
177 int CecCommand(void *UNUSED(cbParam
), const cec_command
&UNUSED(command
))
182 void EnableCallbacks(ICECAdapter
*adapter
)
184 g_callbacks
.CBCecLogMessage
= &CecLogMessage
;
185 g_callbacks
.CBCecKeyPress
= &CecKeyPress
;
186 g_callbacks
.CBCecCommand
= &CecCommand
;
187 adapter
->EnableCallbacks(NULL
, &g_callbacks
);
190 void ListDevices(ICECAdapter
*parser
)
192 cec_adapter
*devices
= new cec_adapter
[10];
193 uint8_t iDevicesFound
= parser
->FindAdapters(devices
, 10, NULL
);
194 if (iDevicesFound
<= 0)
196 PrintToStdOut("Found devices: NONE");
200 PrintToStdOut("Found devices: %d", iDevicesFound
);
201 for (unsigned int iDevicePtr
= 0; iDevicePtr
< iDevicesFound
; iDevicePtr
++)
202 PrintToStdOut("device: %d\npath: %s\ncom port: %s", iDevicePtr
+ 1, devices
[iDevicePtr
].path
, devices
[iDevicePtr
].comm
);
206 void ShowHelpCommandLine(const char* strExec
)
208 CLockObject
lock(g_outputMutex
);
210 strExec
<< " {-h|--help|-l|--list-devices|[COM PORT]}" << endl
<<
212 "parameters:" << endl
<<
213 " -h --help Shows this help text" << endl
<<
214 " -l --list-devices List all devices on this system" << endl
<<
215 " -t --type {p|r|t|a} The device type to use. More than one is possible." << endl
<<
216 " -p --port {int} The HDMI port to use as active source." << endl
<<
217 " -b --base {int} The logical address of the device to with this " << endl
<<
218 " adapter is connected." << endl
<<
219 " -f --log-file {file} Writes all libCEC log message to a file" << endl
<<
220 " -sf --short-log-file {file} Writes all libCEC log message without timestamps" << endl
<<
221 " and log levels to a file." << endl
<<
222 " -d --log-level {level} Sets the log level. See cectypes.h for values." << endl
<<
223 " -s --single-command Execute a single command and exit. Does not power" << endl
<<
224 " on devices on startup and power them off on exit." << endl
<<
225 " [COM PORT] The com port to connect to. If no COM" << endl
<<
226 " port is given, the client tries to connect to the" << endl
<<
227 " first device that is detected." << endl
<<
229 "Type 'h' or 'help' and press enter after starting the client to display all " << endl
<<
230 "available commands" << endl
;
233 ICECAdapter
*CreateParser(cec_device_type_list typeList
)
235 ICECAdapter
*parser
= LibCecInit("CECTester", typeList
);
236 if (!parser
|| parser
->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION
)
239 PrintToStdOut("Cannot load libcec.dll");
241 PrintToStdOut("Cannot load libcec.so");
246 PrintToStdOut("CEC Parser created - libcec version %d.%d", parser
->GetLibVersionMajor(), parser
->GetLibVersionMinor());
251 void ShowHelpConsole(void)
253 CLockObject
lock(g_outputMutex
);
255 "================================================================================" << endl
<<
256 "Available commands:" << endl
<<
258 "[tx] {bytes} transfer bytes over the CEC line." << endl
<<
259 "[txn] {bytes} transfer bytes but don't wait for transmission ACK." << endl
<<
260 "[on] {address} power on the device with the given logical address." << endl
<<
261 "[standby] {address} put the device with the given address in standby mode." << endl
<<
262 "[la] {logical address} change the logical address of the CEC adapter." << endl
<<
263 "[p] {device} {port} change the HDMI port number of the CEC adapter." << endl
<<
264 "[pa] {physical address} change the physical address of the CEC adapter." << endl
<<
265 "[as] make the CEC adapter the active source." << endl
<<
266 "[osd] {addr} {string} set OSD message on the specified device." << endl
<<
267 "[ver] {addr} get the CEC version of the specified device." << endl
<<
268 "[ven] {addr} get the vendor ID of the specified device." << endl
<<
269 "[lang] {addr} get the menu language of the specified device." << endl
<<
270 "[pow] {addr} get the power status of the specified device." << endl
<<
271 "[name] {addr} get the OSD name of the specified device." << endl
<<
272 "[poll] {addr} poll the specified device." << endl
<<
273 "[lad] lists active devices on the bus" << endl
<<
274 "[ad] {addr} checks whether the specified device is active." << endl
<<
275 "[at] {type} checks whether the specified device type is active." << endl
<<
276 "[volup] send a volume up command to the amp if present" << endl
<<
277 "[voldown] send a volume down command to the amp if present" << endl
<<
278 "[mute] send a mute/unmute command to the amp if present" << endl
<<
279 "[scan] scan the CEC bus and display device info" << endl
<<
280 "[mon] {1|0} enable or disable CEC bus monitoring." << endl
<<
281 "[log] {1 - 31} change the log level. see cectypes.h for values." << endl
<<
282 "[ping] send a ping command to the CEC adapter." << endl
<<
283 "[bl] to let the adapter enter the bootloader, to upgrade" << endl
<<
284 " the flash rom." << endl
<<
285 "[r] reconnect to the CEC adapter." << endl
<<
286 "[h] or [help] show this help." << endl
<<
287 "[q] or [quit] to quit the CEC test client and switch off all" << endl
<<
288 " connected CEC devices." << endl
<<
289 "================================================================================" << endl
;
292 bool ProcessCommandTX(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
294 if (command
== "tx" || command
== "txn")
301 while (GetWord(arguments
, strvalue
) && HexStrToInt(strvalue
, ivalue
))
302 bytes
.PushBack(ivalue
);
304 if (command
== "txn")
305 bytes
.transmit_timeout
= 0;
307 parser
->Transmit(bytes
);
315 bool ProcessCommandON(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
321 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
323 parser
->PowerOnDevices((cec_logical_address
) iValue
);
328 PrintToStdOut("invalid destination");
335 bool ProcessCommandSTANDBY(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
337 if (command
== "standby")
341 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
343 parser
->StandbyDevices((cec_logical_address
) iValue
);
348 PrintToStdOut("invalid destination");
355 bool ProcessCommandPOLL(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
357 if (command
== "poll")
361 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
363 if (parser
->PollDevice((cec_logical_address
) iValue
))
364 PrintToStdOut("POLL message sent");
366 PrintToStdOut("POLL message not sent");
371 PrintToStdOut("invalid destination");
378 bool ProcessCommandLA(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
383 if (GetWord(arguments
, strvalue
))
385 parser
->SetLogicalAddress((cec_logical_address
) atoi(strvalue
.c_str()));
393 bool ProcessCommandP(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
397 string strPort
, strDevice
;
398 if (GetWord(arguments
, strDevice
) && GetWord(arguments
, strPort
))
400 parser
->SetHDMIPort((cec_logical_address
)atoi(strDevice
.c_str()), (uint8_t)atoi(strPort
.c_str()));
408 bool ProcessCommandPA(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
414 if (GetWord(arguments
, strB1
) && HexStrToInt(strB1
, iB1
) &&
415 GetWord(arguments
, strB2
) && HexStrToInt(strB2
, iB2
))
417 uint16_t iPhysicalAddress
= ((uint16_t)iB1
<< 8) + iB2
;
418 parser
->SetPhysicalAddress(iPhysicalAddress
);
426 bool ProcessCommandOSD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
428 if (command
== "osd")
430 bool bFirstWord(false);
431 string strAddr
, strMessage
, strWord
;
433 if (GetWord(arguments
, strAddr
) && HexStrToInt(strAddr
, iAddr
) && iAddr
< 0xF)
435 while (GetWord(arguments
, strWord
))
440 strMessage
.append(" ");
442 strMessage
.append(strWord
);
444 parser
->SetOSDString((cec_logical_address
) iAddr
, CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME
, strMessage
.c_str());
452 bool ProcessCommandAS(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
456 parser
->SetActiveView();
464 bool ProcessCommandPING(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
466 if (command
== "ping")
468 parser
->PingAdapter();
475 bool ProcessCommandVOLUP(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
477 if (command
== "volup")
479 PrintToStdOut("volume up: %2X", parser
->VolumeUp());
486 bool ProcessCommandVOLDOWN(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
488 if (command
== "voldown")
490 PrintToStdOut("volume down: %2X", parser
->VolumeDown());
497 bool ProcessCommandMUTE(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
499 if (command
== "mute")
501 PrintToStdOut("mute: %2X", parser
->MuteAudio());
508 bool ProcessCommandMON(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
510 if (command
== "mon")
512 CStdString strEnable
;
513 if (GetWord(arguments
, strEnable
) && (strEnable
.Equals("0") || strEnable
.Equals("1")))
515 parser
->SwitchMonitoring(strEnable
.Equals("1"));
523 bool ProcessCommandBL(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
527 if (parser
->StartBootloader())
529 PrintToStdOut("entered bootloader mode. exiting cec-client");
539 bool ProcessCommandLANG(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
541 if (command
== "lang")
544 if (GetWord(arguments
, strDev
))
546 int iDev
= atoi(strDev
);
547 if (iDev
>= 0 && iDev
< 15)
550 cec_menu_language language
;
551 if (parser
->GetDeviceMenuLanguage((cec_logical_address
) iDev
, &language
))
552 strLog
.Format("menu language '%s'", language
.language
);
555 PrintToStdOut(strLog
);
564 bool ProcessCommandVEN(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
566 if (command
== "ven")
569 if (GetWord(arguments
, strDev
))
571 int iDev
= atoi(strDev
);
572 if (iDev
>= 0 && iDev
< 15)
574 uint64_t iVendor
= parser
->GetDeviceVendorId((cec_logical_address
) iDev
);
575 PrintToStdOut("vendor id: %06x", iVendor
);
584 bool ProcessCommandVER(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
586 if (command
== "ver")
589 if (GetWord(arguments
, strDev
))
591 int iDev
= atoi(strDev
);
592 if (iDev
>= 0 && iDev
< 15)
594 cec_version iVersion
= parser
->GetDeviceCecVersion((cec_logical_address
) iDev
);
595 PrintToStdOut("CEC version %s", parser
->ToString(iVersion
));
604 bool ProcessCommandPOW(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
606 if (command
== "pow")
609 if (GetWord(arguments
, strDev
))
611 int iDev
= atoi(strDev
);
612 if (iDev
>= 0 && iDev
< 15)
614 cec_power_status iPower
= parser
->GetDevicePowerStatus((cec_logical_address
) iDev
);
615 PrintToStdOut("power status: %s", parser
->ToString(iPower
));
624 bool ProcessCommandNAME(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
626 if (command
== "name")
629 if (GetWord(arguments
, strDev
))
631 int iDev
= atoi(strDev
);
632 if (iDev
>= 0 && iDev
< 15)
634 cec_osd_name name
= parser
->GetDeviceOSDName((cec_logical_address
)iDev
);
635 PrintToStdOut("OSD name of device %d is '%s'", iDev
, name
.name
);
644 bool ProcessCommandLAD(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
646 if (command
== "lad")
648 PrintToStdOut("listing active devices:");
649 cec_logical_addresses addresses
= parser
->GetActiveDevices();
650 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
653 PrintToStdOut("logical address %X", (int)iPtr
);
661 bool ProcessCommandAD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
666 if (GetWord(arguments
, strDev
))
668 int iDev
= atoi(strDev
);
669 if (iDev
>= 0 && iDev
< 15)
670 PrintToStdOut("logical address %X is %s", iDev
, (parser
->IsActiveDevice((cec_logical_address
)iDev
) ? "active" : "not active"));
677 bool ProcessCommandAT(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
682 if (GetWord(arguments
, strType
))
684 cec_device_type type
= CEC_DEVICE_TYPE_TV
;
685 if (strType
.Equals("a"))
686 type
= CEC_DEVICE_TYPE_AUDIO_SYSTEM
;
687 else if (strType
.Equals("p"))
688 type
= CEC_DEVICE_TYPE_PLAYBACK_DEVICE
;
689 else if (strType
.Equals("r"))
690 type
= CEC_DEVICE_TYPE_RECORDING_DEVICE
;
691 else if (strType
.Equals("t"))
692 type
= CEC_DEVICE_TYPE_TUNER
;
694 PrintToStdOut("device %d is %s", type
, (parser
->IsActiveDeviceType(type
) ? "active" : "not active"));
702 bool ProcessCommandR(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
706 PrintToStdOut("closing the connection");
709 PrintToStdOut("opening a new connection");
710 parser
->Open(g_strPort
.c_str());
712 PrintToStdOut("setting active source");
713 parser
->SetActiveSource();
720 bool ProcessCommandH(ICECAdapter
* UNUSED(parser
), const string
&command
, string
& UNUSED(arguments
))
722 if (command
== "h" || command
== "help")
731 bool ProcessCommandLOG(ICECAdapter
* UNUSED(parser
), const string
&command
, string
&arguments
)
733 if (command
== "log")
736 if (GetWord(arguments
, strLevel
))
738 int iNewLevel
= atoi(strLevel
);
739 if (iNewLevel
>= CEC_LOG_ERROR
&& iNewLevel
<= CEC_LOG_ALL
)
741 g_cecLogLevel
= iNewLevel
;
743 PrintToStdOut("log level changed to %s", strLevel
.c_str());
752 bool ProcessCommandSCAN(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
754 if (command
== "scan")
756 PrintToStdOut("CEC bus information");
757 PrintToStdOut("===================");
758 cec_logical_addresses addresses
= parser
->GetActiveDevices();
759 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
764 uint64_t iVendorId
= parser
->GetDeviceVendorId((cec_logical_address
)iPtr
);
765 bool bActive
= parser
->IsActiveSource((cec_logical_address
)iPtr
);
766 uint16_t iPhysicalAddress
= parser
->GetDevicePhysicalAddress((cec_logical_address
)iPtr
);
767 cec_version iCecVersion
= parser
->GetDeviceCecVersion((cec_logical_address
)iPtr
);
768 cec_power_status power
= parser
->GetDevicePowerStatus((cec_logical_address
)iPtr
);
769 cec_osd_name osdName
= parser
->GetDeviceOSDName((cec_logical_address
)iPtr
);
771 strAddr
.Format("%04x", iPhysicalAddress
);
772 cec_menu_language lang
;
773 lang
.device
= CECDEVICE_UNKNOWN
;
774 parser
->GetDeviceMenuLanguage((cec_logical_address
)iPtr
, &lang
);
776 strLog
.AppendFormat("device #%X: %s\n", (int)iPtr
, parser
->ToString((cec_logical_address
)iPtr
));
777 strLog
.AppendFormat("address: %s\n", strAddr
.c_str());
778 strLog
.AppendFormat("active source: %s\n", (bActive
? "yes" : "no"));
779 strLog
.AppendFormat("vendor: %s\n", parser
->ToString((cec_vendor_id
)iVendorId
));
780 strLog
.AppendFormat("osd string: %s\n", osdName
.name
);
781 strLog
.AppendFormat("CEC version: %s\n", parser
->ToString(iCecVersion
));
782 strLog
.AppendFormat("power status: %s\n", parser
->ToString(power
));
783 if ((uint8_t)lang
.device
== iPtr
)
784 strLog
.AppendFormat("language: %s\n", lang
.language
);
786 PrintToStdOut(strLog
);
795 bool ProcessConsoleCommand(ICECAdapter
*parser
, string
&input
)
800 if (GetWord(input
, command
))
802 if (command
== "q" || command
== "quit")
805 ProcessCommandTX(parser
, command
, input
) ||
806 ProcessCommandON(parser
, command
, input
) ||
807 ProcessCommandSTANDBY(parser
, command
, input
) ||
808 ProcessCommandPOLL(parser
, command
, input
) ||
809 ProcessCommandLA(parser
, command
, input
) ||
810 ProcessCommandP(parser
, command
, input
) ||
811 ProcessCommandPA(parser
, command
, input
) ||
812 ProcessCommandAS(parser
, command
, input
) ||
813 ProcessCommandOSD(parser
, command
, input
) ||
814 ProcessCommandPING(parser
, command
, input
) ||
815 ProcessCommandVOLUP(parser
, command
, input
) ||
816 ProcessCommandVOLDOWN(parser
, command
, input
) ||
817 ProcessCommandMUTE(parser
, command
, input
) ||
818 ProcessCommandMON(parser
, command
, input
) ||
819 ProcessCommandBL(parser
, command
, input
) ||
820 ProcessCommandLANG(parser
, command
, input
) ||
821 ProcessCommandVEN(parser
, command
, input
) ||
822 ProcessCommandVER(parser
, command
, input
) ||
823 ProcessCommandPOW(parser
, command
, input
) ||
824 ProcessCommandNAME(parser
, command
, input
) ||
825 ProcessCommandLAD(parser
, command
, input
) ||
826 ProcessCommandAD(parser
, command
, input
) ||
827 ProcessCommandAT(parser
, command
, input
) ||
828 ProcessCommandR(parser
, command
, input
) ||
829 ProcessCommandH(parser
, command
, input
) ||
830 ProcessCommandLOG(parser
, command
, input
) ||
831 ProcessCommandSCAN(parser
, command
, input
);
837 bool ProcessCommandLineArguments(int argc
, char *argv
[])
841 while (iArgPtr
< argc
&& bReturn
)
843 if (argc
>= iArgPtr
+ 1)
845 if (!strcmp(argv
[iArgPtr
], "-f") ||
846 !strcmp(argv
[iArgPtr
], "--log-file") ||
847 !strcmp(argv
[iArgPtr
], "-sf") ||
848 !strcmp(argv
[iArgPtr
], "--short-log-file"))
850 if (argc
>= iArgPtr
+ 2)
852 g_logOutput
.open(argv
[iArgPtr
+ 1]);
853 g_bShortLog
= (!strcmp(argv
[iArgPtr
], "-sf") || !strcmp(argv
[iArgPtr
], "--short-log-file"));
858 cout
<< "== skipped log-file parameter: no file given ==" << endl
;
862 else if (!strcmp(argv
[iArgPtr
], "-d") ||
863 !strcmp(argv
[iArgPtr
], "--log-level"))
865 if (argc
>= iArgPtr
+ 2)
867 int iNewLevel
= atoi(argv
[iArgPtr
+ 1]);
868 if (iNewLevel
>= CEC_LOG_ERROR
&& iNewLevel
<= CEC_LOG_ALL
)
870 g_cecLogLevel
= iNewLevel
;
871 if (!g_bSingleCommand
)
872 cout
<< "log level set to " << argv
[iArgPtr
+ 1] << endl
;
876 cout
<< "== skipped log-level parameter: invalid level '" << argv
[iArgPtr
+ 1] << "' ==" << endl
;
882 cout
<< "== skipped log-level parameter: no level given ==" << endl
;
886 else if (!strcmp(argv
[iArgPtr
], "-t") ||
887 !strcmp(argv
[iArgPtr
], "--type"))
889 if (argc
>= iArgPtr
+ 2)
891 if (!strcmp(argv
[iArgPtr
+ 1], "p"))
893 if (!g_bSingleCommand
)
894 cout
<< "== using device type 'playback device'" << endl
;
895 g_typeList
.add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
897 else if (!strcmp(argv
[iArgPtr
+ 1], "r"))
899 if (!g_bSingleCommand
)
900 cout
<< "== using device type 'recording device'" << endl
;
901 g_typeList
.add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
903 else if (!strcmp(argv
[iArgPtr
+ 1], "t"))
905 if (!g_bSingleCommand
)
906 cout
<< "== using device type 'tuner'" << endl
;
907 g_typeList
.add(CEC_DEVICE_TYPE_TUNER
);
909 else if (!strcmp(argv
[iArgPtr
+ 1], "a"))
911 if (!g_bSingleCommand
)
912 cout
<< "== using device type 'audio system'" << endl
;
913 g_typeList
.add(CEC_DEVICE_TYPE_AUDIO_SYSTEM
);
917 cout
<< "== skipped invalid device type '" << argv
[iArgPtr
+ 1] << "'" << endl
;
923 else if (!strcmp(argv
[iArgPtr
], "--list-devices") ||
924 !strcmp(argv
[iArgPtr
], "-l"))
926 ICECAdapter
*parser
= CreateParser(g_typeList
);
930 UnloadLibCec(parser
);
935 else if (!strcmp(argv
[iArgPtr
], "--single-command") ||
936 !strcmp(argv
[iArgPtr
], "-s"))
938 g_bSingleCommand
= true;
941 else if (!strcmp(argv
[iArgPtr
], "--help") ||
942 !strcmp(argv
[iArgPtr
], "-h"))
944 ShowHelpCommandLine(argv
[0]);
947 else if (!strcmp(argv
[iArgPtr
], "-b") ||
948 !strcmp(argv
[iArgPtr
], "--base"))
950 if (argc
>= iArgPtr
+ 2)
952 g_iBaseDevice
= (cec_logical_address
)atoi(argv
[iArgPtr
+ 1]);
953 cout
<< "using base device '" << (int)g_iBaseDevice
<< "'" << endl
;
958 else if (!strcmp(argv
[iArgPtr
], "-p") ||
959 !strcmp(argv
[iArgPtr
], "--port"))
961 if (argc
>= iArgPtr
+ 2)
963 g_iHDMIPort
= (int8_t)atoi(argv
[iArgPtr
+ 1]);
964 cout
<< "using HDMI port '" << (int)g_iHDMIPort
<< "'" << endl
;
971 g_strPort
= argv
[iArgPtr
++];
979 int main (int argc
, char *argv
[])
983 if (!ProcessCommandLineArguments(argc
, argv
))
986 if (g_typeList
.IsEmpty())
988 if (!g_bSingleCommand
)
989 cout
<< "No device type given. Using 'recording device'" << endl
;
990 g_typeList
.add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
993 ICECAdapter
*parser
= LibCecInit("CECTester", g_typeList
);
994 if (!parser
|| parser
->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION
)
997 cout
<< "Cannot load libcec.dll" << endl
;
999 cout
<< "Cannot load libcec.so" << endl
;
1003 UnloadLibCec(parser
);
1008 if (!g_bSingleCommand
)
1011 strLog
.Format("CEC Parser created - libcec version %d.%d", parser
->GetLibVersionMajor(), parser
->GetLibVersionMinor());
1012 cout
<< strLog
.c_str() << endl
;
1014 //make stdin non-blocking
1016 int flags
= fcntl(0, F_GETFL
, 0);
1017 flags
|= O_NONBLOCK
;
1018 fcntl(0, F_SETFL
, flags
);
1022 if (g_strPort
.IsEmpty())
1024 if (!g_bSingleCommand
)
1025 cout
<< "no serial port given. trying autodetect: ";
1026 cec_adapter devices
[10];
1027 uint8_t iDevicesFound
= parser
->FindAdapters(devices
, 10, NULL
);
1028 if (iDevicesFound
<= 0)
1030 if (g_bSingleCommand
)
1031 cout
<< "autodetect ";
1032 cout
<< "FAILED" << endl
;
1033 UnloadLibCec(parser
);
1038 if (!g_bSingleCommand
)
1040 cout
<< endl
<< " path: " << devices
[0].path
<< endl
<<
1041 " com port: " << devices
[0].comm
<< endl
<< endl
;
1043 g_strPort
= devices
[0].comm
;
1047 EnableCallbacks(parser
);
1049 parser
->SetHDMIPort(g_iBaseDevice
, g_iHDMIPort
);
1050 PrintToStdOut("opening a connection to the CEC adapter...");
1052 if (!parser
->Open(g_strPort
.c_str()))
1054 PrintToStdOut("unable to open the device on port %s", g_strPort
.c_str());
1055 UnloadLibCec(parser
);
1059 if (!g_bSingleCommand
)
1061 PrintToStdOut("cec device opened");
1063 parser
->PowerOnDevices(CECDEVICE_TV
);
1064 parser
->SetActiveSource();
1066 PrintToStdOut("waiting for input");
1069 while (!g_bExit
&& !g_bHardExit
)
1072 getline(cin
, input
);
1075 if (ProcessConsoleCommand(parser
, input
) && !g_bSingleCommand
&& !g_bExit
&& !g_bHardExit
)
1078 PrintToStdOut("waiting for input");
1083 if (!g_bExit
&& !g_bHardExit
)
1084 CCondition::Sleep(50);
1087 if (!g_bSingleCommand
&& !g_bHardExit
)
1088 parser
->StandbyDevices(CECDEVICE_BROADCAST
);
1091 UnloadLibCec(parser
);
1093 if (g_logOutput
.is_open())
1094 g_logOutput
.close();