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/threads.h"
42 #include "../lib/util/StdString.h"
43 #include "../lib/implementations/CECCommandHandler.h"
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);
62 inline bool HexStrToInt(const std::string
& data
, uint8_t& value
)
65 if (sscanf(data
.c_str(), "%x", &iTmp
) == 1)
72 value
= (uint8_t) iTmp
;
80 //get the first word (separated by whitespace) from string data and place that in word
81 //then remove that word from string data
82 bool GetWord(string
& data
, string
& word
)
84 stringstream
datastream(data
);
88 if (datastream
.fail())
94 size_t pos
= data
.find(word
) + word
.length();
96 if (pos
>= data
.length())
102 data
= data
.substr(pos
);
105 datastream
.str(data
);
108 if (datastream
.fail())
114 void FlushLog(ICECAdapter
*cecParser
)
116 cec_log_message message
;
117 while (cecParser
&& cecParser
->GetNextLogMessage(&message
))
119 if ((message
.level
& g_cecLogLevel
) == message
.level
)
122 switch (message
.level
)
125 strLevel
= "ERROR: ";
127 case CEC_LOG_WARNING
:
128 strLevel
= "WARNING: ";
131 strLevel
= "NOTICE: ";
133 case CEC_LOG_TRAFFIC
:
134 strLevel
= "TRAFFIC: ";
137 strLevel
= "DEBUG: ";
143 CStdString strFullLog
;
144 strFullLog
.Format("%s[%16lld]\t%s", strLevel
.c_str(), message
.time
, message
.message
);
145 cout
<< strFullLog
.c_str() << endl
;
147 if (g_logOutput
.is_open())
150 g_logOutput
<< message
.message
<< endl
;
152 g_logOutput
<< strFullLog
.c_str() << endl
;
158 void ListDevices(ICECAdapter
*parser
)
160 cec_adapter
*devices
= new cec_adapter
[10];
161 uint8_t iDevicesFound
= parser
->FindAdapters(devices
, 10, NULL
);
162 if (iDevicesFound
<= 0)
164 cout
<< "Found devices: NONE" << endl
;
169 strLog
.Format("Found devices: %d", iDevicesFound
);
170 cout
<< strLog
.c_str() << endl
;
171 for (unsigned int iDevicePtr
= 0; iDevicePtr
< iDevicesFound
; iDevicePtr
++)
173 CStdString strDevice
;
174 strDevice
.Format("device: %d\npath: %s\ncom port: %s", iDevicePtr
+ 1, devices
[iDevicePtr
].path
, devices
[iDevicePtr
].comm
);
175 cout
<< endl
<< strDevice
.c_str() << endl
;
180 void ShowHelpCommandLine(const char* strExec
)
183 strExec
<< " {-h|--help|-l|--list-devices|[COM PORT]}" << endl
<<
185 "parameters:" << endl
<<
186 " -h --help Shows this help text" << endl
<<
187 " -l --list-devices List all devices on this system" << endl
<<
188 " -t --type {p|r|t|a} The device type to use. More than one is possible." << endl
<<
189 " -p --port {int} The HDMI port to use as active source." << endl
<<
190 " -b --base {int} The logical address of the device to with this " << endl
<<
191 " adapter is connected." << endl
<<
192 " -f --log-file {file} Writes all libCEC log message to a file" << endl
<<
193 " -sf --short-log-file {file} Writes all libCEC log message without timestamps" << endl
<<
194 " and log levels to a file." << endl
<<
195 " -d --log-level {level} Sets the log level. See cectypes.h for values." << endl
<<
196 " -s --single-command Execute a single command and exit. Does not power" << endl
<<
197 " on devices on startup and power them off on exit." << endl
<<
198 " [COM PORT] The com port to connect to. If no COM" << endl
<<
199 " port is given, the client tries to connect to the" << endl
<<
200 " first device that is detected." << endl
<<
202 "Type 'h' or 'help' and press enter after starting the client to display all " << endl
<<
203 "available commands" << endl
;
206 ICECAdapter
*CreateParser(cec_device_type_list typeList
)
208 ICECAdapter
*parser
= LibCecInit("CECTester", typeList
);
209 if (!parser
|| parser
->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION
)
212 cout
<< "Cannot load libcec.dll" << endl
;
214 cout
<< "Cannot load libcec.so" << endl
;
220 strLog
.Format("CEC Parser created - libcec version %d.%d", parser
->GetLibVersionMajor(), parser
->GetLibVersionMinor());
221 cout
<< strLog
.c_str() << endl
;
226 void ShowHelpConsole(void)
229 "================================================================================" << endl
<<
230 "Available commands:" << endl
<<
232 "[tx] {bytes} transfer bytes over the CEC line." << endl
<<
233 "[txn] {bytes} transfer bytes but don't wait for transmission ACK." << endl
<<
234 "[on] {address} power on the device with the given logical address." << endl
<<
235 "[standby] {address} put the device with the given address in standby mode." << endl
<<
236 "[la] {logical address} change the logical address of the CEC adapter." << endl
<<
237 "[p] {device} {port} change the HDMI port number of the CEC adapter." << endl
<<
238 "[pa] {physical address} change the physical address of the CEC adapter." << endl
<<
239 "[osd] {addr} {string} set OSD message on the specified device." << endl
<<
240 "[ver] {addr} get the CEC version of the specified device." << endl
<<
241 "[ven] {addr} get the vendor ID of the specified device." << endl
<<
242 "[lang] {addr} get the menu language of the specified device." << endl
<<
243 "[pow] {addr} get the power status of the specified device." << endl
<<
244 "[name] {addr} get the OSD name of the specified device." << endl
<<
245 "[poll] {addr} poll the specified device." << endl
<<
246 "[lad] lists active devices on the bus" << endl
<<
247 "[ad] {addr} checks whether the specified device is active." << endl
<<
248 "[at] {type} checks whether the specified device type is active." << endl
<<
249 "[volup] send a volume up command to the amp if present" << endl
<<
250 "[voldown] send a volume down command to the amp if present" << endl
<<
251 "[mute] send a mute/unmute command to the amp if present" << endl
<<
252 "[scan] scan the CEC bus and display device info" << endl
<<
253 "[mon] {1|0} enable or disable CEC bus monitoring." << endl
<<
254 "[log] {1 - 31} change the log level. see cectypes.h for values." << endl
<<
255 "[ping] send a ping command to the CEC adapter." << endl
<<
256 "[bl] to let the adapter enter the bootloader, to upgrade" << endl
<<
257 " the flash rom." << endl
<<
258 "[r] reconnect to the CEC adapter." << endl
<<
259 "[h] or [help] show this help." << endl
<<
260 "[q] or [quit] to quit the CEC test client and switch off all" << endl
<<
261 " connected CEC devices." << endl
<<
262 "================================================================================" << endl
;
265 bool ProcessCommandTX(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
267 if (command
== "tx" || command
== "txn")
274 while (GetWord(arguments
, strvalue
) && HexStrToInt(strvalue
, ivalue
))
275 bytes
.PushBack(ivalue
);
277 if (command
== "txn")
278 bytes
.transmit_timeout
= 0;
280 parser
->Transmit(bytes
);
288 bool ProcessCommandON(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
294 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
296 parser
->PowerOnDevices((cec_logical_address
) iValue
);
301 cout
<< "invalid destination" << endl
;
308 bool ProcessCommandSTANDBY(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
310 if (command
== "standby")
314 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
316 parser
->StandbyDevices((cec_logical_address
) iValue
);
321 cout
<< "invalid destination" << endl
;
328 bool ProcessCommandPOLL(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
330 if (command
== "poll")
334 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
336 if (parser
->PollDevice((cec_logical_address
) iValue
))
337 cout
<< "POLL message sent" << endl
;
339 cout
<< "POLL message not sent" << endl
;
344 cout
<< "invalid destination" << endl
;
351 bool ProcessCommandLA(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
356 if (GetWord(arguments
, strvalue
))
358 parser
->SetLogicalAddress((cec_logical_address
) atoi(strvalue
.c_str()));
366 bool ProcessCommandP(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
370 string strPort
, strDevice
;
371 if (GetWord(arguments
, strDevice
) && GetWord(arguments
, strPort
))
373 parser
->SetHDMIPort((cec_logical_address
)atoi(strDevice
.c_str()), (uint8_t)atoi(strPort
.c_str()));
381 bool ProcessCommandPA(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
387 if (GetWord(arguments
, strB1
) && HexStrToInt(strB1
, iB1
) &&
388 GetWord(arguments
, strB2
) && HexStrToInt(strB2
, iB2
))
390 uint16_t iPhysicalAddress
= ((uint16_t)iB1
<< 8) + iB2
;
391 parser
->SetPhysicalAddress(iPhysicalAddress
);
399 bool ProcessCommandOSD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
401 if (command
== "osd")
403 bool bFirstWord(false);
404 string strAddr
, strMessage
, strWord
;
406 if (GetWord(arguments
, strAddr
) && HexStrToInt(strAddr
, iAddr
) && iAddr
< 0xF)
408 while (GetWord(arguments
, strWord
))
413 strMessage
.append(" ");
415 strMessage
.append(strWord
);
417 parser
->SetOSDString((cec_logical_address
) iAddr
, CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME
, strMessage
.c_str());
425 bool ProcessCommandPING(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
427 if (command
== "ping")
429 parser
->PingAdapter();
436 bool ProcessCommandVOLUP(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
438 if (command
== "volup")
441 strLog
.Format("volume up: %2X", parser
->VolumeUp());
442 cout
<< strLog
.c_str() << endl
;
449 bool ProcessCommandVOLDOWN(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
451 if (command
== "voldown")
454 strLog
.Format("volume up: %2X", parser
->VolumeDown());
455 cout
<< strLog
.c_str() << endl
;
462 bool ProcessCommandMUTE(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
464 if (command
== "mute")
467 strLog
.Format("mute: %2X", parser
->MuteAudio());
468 cout
<< strLog
.c_str() << endl
;
475 bool ProcessCommandMON(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
477 if (command
== "mon")
479 CStdString strEnable
;
480 if (GetWord(arguments
, strEnable
) && (strEnable
.Equals("0") || strEnable
.Equals("1")))
482 parser
->SwitchMonitoring(strEnable
.Equals("1"));
490 bool ProcessCommandBL(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
494 parser
->StartBootloader();
501 bool ProcessCommandLANG(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
503 if (command
== "lang")
506 if (GetWord(arguments
, strDev
))
508 int iDev
= atoi(strDev
);
509 if (iDev
>= 0 && iDev
< 15)
512 cec_menu_language language
;
513 if (parser
->GetDeviceMenuLanguage((cec_logical_address
) iDev
, &language
))
514 strLog
.Format("menu language '%s'", language
.language
);
517 cout
<< strLog
.c_str() << endl
;
526 bool ProcessCommandVEN(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
528 if (command
== "ven")
531 if (GetWord(arguments
, strDev
))
533 int iDev
= atoi(strDev
);
534 if (iDev
>= 0 && iDev
< 15)
536 uint64_t iVendor
= parser
->GetDeviceVendorId((cec_logical_address
) iDev
);
538 strLog
.Format("vendor id: %06x", iVendor
);
539 cout
<< strLog
.c_str() << endl
;
548 bool ProcessCommandVER(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
550 if (command
== "ver")
553 if (GetWord(arguments
, strDev
))
555 int iDev
= atoi(strDev
);
556 if (iDev
>= 0 && iDev
< 15)
558 cec_version iVersion
= parser
->GetDeviceCecVersion((cec_logical_address
) iDev
);
559 cout
<< "CEC version " << parser
->ToString(iVersion
) << endl
;
568 bool ProcessCommandPOW(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
570 if (command
== "pow")
573 if (GetWord(arguments
, strDev
))
575 int iDev
= atoi(strDev
);
576 if (iDev
>= 0 && iDev
< 15)
578 cec_power_status iPower
= parser
->GetDevicePowerStatus((cec_logical_address
) iDev
);
579 cout
<< "power status: " << parser
->ToString(iPower
) << endl
;
589 bool ProcessCommandNAME(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
591 if (command
== "name")
594 if (GetWord(arguments
, strDev
))
596 int iDev
= atoi(strDev
);
597 if (iDev
>= 0 && iDev
< 15)
599 cec_osd_name name
= parser
->GetDeviceOSDName((cec_logical_address
)iDev
);
600 cout
<< "OSD name of device " << iDev
<< " is '" << name
.name
<< "'" << endl
;
609 bool ProcessCommandLAD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
611 if (command
== "lad")
613 cout
<< "listing active devices:" << endl
;
614 cec_logical_addresses addresses
= parser
->GetActiveDevices();
615 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
617 cout
<< "logical address " << (int)iPtr
<< endl
;
624 bool ProcessCommandAD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
629 if (GetWord(arguments
, strDev
))
631 int iDev
= atoi(strDev
);
632 if (iDev
>= 0 && iDev
< 15)
633 cout
<< "logical address " << iDev
<< " is " << (parser
->IsActiveDevice((cec_logical_address
)iDev
) ? "active" : "not active") << endl
;
640 bool ProcessCommandAT(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
645 if (GetWord(arguments
, strType
))
647 cec_device_type type
= CEC_DEVICE_TYPE_TV
;
648 if (strType
.Equals("a"))
649 type
= CEC_DEVICE_TYPE_AUDIO_SYSTEM
;
650 else if (strType
.Equals("p"))
651 type
= CEC_DEVICE_TYPE_PLAYBACK_DEVICE
;
652 else if (strType
.Equals("r"))
653 type
= CEC_DEVICE_TYPE_RECORDING_DEVICE
;
654 else if (strType
.Equals("t"))
655 type
= CEC_DEVICE_TYPE_TUNER
;
656 cout
<< "device " << type
<< " is " << (parser
->IsActiveDeviceType(type
) ? "active" : "not active") << endl
;
664 bool ProcessCommandR(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
668 cout
<< "closing the connection" << endl
;
672 cout
<< "opening a new connection" << endl
;
673 parser
->Open(g_strPort
.c_str());
676 cout
<< "setting active source" << endl
;
677 parser
->SetActiveSource();
684 bool ProcessCommandH(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
686 if (command
== "h" || command
== "help")
695 bool ProcessCommandLOG(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
697 if (command
== "log")
700 if (GetWord(arguments
, strLevel
))
702 int iNewLevel
= atoi(strLevel
);
703 if (iNewLevel
>= CEC_LOG_ERROR
&& iNewLevel
<= CEC_LOG_ALL
)
705 g_cecLogLevel
= iNewLevel
;
706 cout
<< "log level changed to " << strLevel
.c_str() << endl
;
715 bool ProcessCommandSCAN(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
717 if (command
== "scan")
719 cout
<< "CEC bus information" << endl
;
720 cout
<< "===================" << endl
;
721 cec_logical_addresses addresses
= parser
->GetActiveDevices();
722 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
726 uint64_t iVendorId
= parser
->GetDeviceVendorId((cec_logical_address
)iPtr
);
727 bool bActive
= parser
->IsActiveSource((cec_logical_address
)iPtr
);
728 uint16_t iPhysicalAddress
= parser
->GetDevicePhysicalAddress((cec_logical_address
)iPtr
);
729 cec_version iCecVersion
= parser
->GetDeviceCecVersion((cec_logical_address
)iPtr
);
730 cec_power_status power
= parser
->GetDevicePowerStatus((cec_logical_address
)iPtr
);
731 cec_osd_name osdName
= parser
->GetDeviceOSDName((cec_logical_address
)iPtr
);
733 strAddr
.Format("%04x", iPhysicalAddress
);
734 cec_menu_language lang
;
735 lang
.device
= CECDEVICE_UNKNOWN
;
736 parser
->GetDeviceMenuLanguage((cec_logical_address
)iPtr
, &lang
);
738 cout
<< "device #" << (int)iPtr
<< ": " << parser
->ToString((cec_logical_address
)iPtr
) << endl
;
739 cout
<< "address: " << strAddr
.c_str() << endl
;
740 cout
<< "active source: " << (bActive
? "yes" : "no") << endl
;
741 cout
<< "vendor: " << parser
->ToString((cec_vendor_id
)iVendorId
) << endl
;
742 cout
<< "osd string: " << osdName
.name
<< endl
;
743 cout
<< "CEC version: " << parser
->ToString(iCecVersion
) << endl
;
744 cout
<< "power status: " << parser
->ToString(power
) << endl
;
745 if ((uint8_t)lang
.device
== iPtr
)
746 cout
<< "language: " << lang
.language
<< endl
;
756 bool ProcessConsoleCommand(ICECAdapter
*parser
, string
&input
)
761 if (GetWord(input
, command
))
763 if (command
== "q" || command
== "quit")
766 ProcessCommandTX(parser
, command
, input
) ||
767 ProcessCommandON(parser
, command
, input
) ||
768 ProcessCommandSTANDBY(parser
, command
, input
) ||
769 ProcessCommandPOLL(parser
, command
, input
) ||
770 ProcessCommandLA(parser
, command
, input
) ||
771 ProcessCommandP(parser
, command
, input
) ||
772 ProcessCommandPA(parser
, command
, input
) ||
773 ProcessCommandOSD(parser
, command
, input
) ||
774 ProcessCommandPING(parser
, command
, input
) ||
775 ProcessCommandVOLUP(parser
, command
, input
) ||
776 ProcessCommandVOLDOWN(parser
, command
, input
) ||
777 ProcessCommandMUTE(parser
, command
, input
) ||
778 ProcessCommandMON(parser
, command
, input
) ||
779 ProcessCommandBL(parser
, command
, input
) ||
780 ProcessCommandLANG(parser
, command
, input
) ||
781 ProcessCommandVEN(parser
, command
, input
) ||
782 ProcessCommandVER(parser
, command
, input
) ||
783 ProcessCommandPOW(parser
, command
, input
) ||
784 ProcessCommandNAME(parser
, command
, input
) ||
785 ProcessCommandLAD(parser
, command
, input
) ||
786 ProcessCommandAD(parser
, command
, input
) ||
787 ProcessCommandAT(parser
, command
, input
) ||
788 ProcessCommandR(parser
, command
, input
) ||
789 ProcessCommandH(parser
, command
, input
) ||
790 ProcessCommandLOG(parser
, command
, input
) ||
791 ProcessCommandSCAN(parser
, command
, input
);
797 bool ProcessCommandLineArguments(int argc
, char *argv
[])
801 while (iArgPtr
< argc
&& bReturn
)
803 if (argc
>= iArgPtr
+ 1)
805 if (!strcmp(argv
[iArgPtr
], "-f") ||
806 !strcmp(argv
[iArgPtr
], "--log-file") ||
807 !strcmp(argv
[iArgPtr
], "-sf") ||
808 !strcmp(argv
[iArgPtr
], "--short-log-file"))
810 if (argc
>= iArgPtr
+ 2)
812 g_logOutput
.open(argv
[iArgPtr
+ 1]);
813 g_bShortLog
= (!strcmp(argv
[iArgPtr
], "-sf") || !strcmp(argv
[iArgPtr
], "--short-log-file"));
818 cout
<< "== skipped log-file parameter: no file given ==" << endl
;
822 else if (!strcmp(argv
[iArgPtr
], "-d") ||
823 !strcmp(argv
[iArgPtr
], "--log-level"))
825 if (argc
>= iArgPtr
+ 2)
827 int iNewLevel
= atoi(argv
[iArgPtr
+ 1]);
828 if (iNewLevel
>= CEC_LOG_ERROR
&& iNewLevel
<= CEC_LOG_ALL
)
830 g_cecLogLevel
= iNewLevel
;
831 if (!g_bSingleCommand
)
832 cout
<< "log level set to " << argv
[iArgPtr
+ 1] << endl
;
836 cout
<< "== skipped log-level parameter: invalid level '" << argv
[iArgPtr
+ 1] << "' ==" << endl
;
842 cout
<< "== skipped log-level parameter: no level given ==" << endl
;
846 else if (!strcmp(argv
[iArgPtr
], "-t") ||
847 !strcmp(argv
[iArgPtr
], "--type"))
849 if (argc
>= iArgPtr
+ 2)
851 if (!strcmp(argv
[iArgPtr
+ 1], "p"))
853 if (!g_bSingleCommand
)
854 cout
<< "== using device type 'playback device'" << endl
;
855 g_typeList
.add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
857 else if (!strcmp(argv
[iArgPtr
+ 1], "r"))
859 if (!g_bSingleCommand
)
860 cout
<< "== using device type 'recording device'" << endl
;
861 g_typeList
.add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
863 else if (!strcmp(argv
[iArgPtr
+ 1], "t"))
865 if (!g_bSingleCommand
)
866 cout
<< "== using device type 'tuner'" << endl
;
867 g_typeList
.add(CEC_DEVICE_TYPE_TUNER
);
869 else if (!strcmp(argv
[iArgPtr
+ 1], "a"))
871 if (!g_bSingleCommand
)
872 cout
<< "== using device type 'audio system'" << endl
;
873 g_typeList
.add(CEC_DEVICE_TYPE_AUDIO_SYSTEM
);
877 cout
<< "== skipped invalid device type '" << argv
[iArgPtr
+ 1] << "'" << endl
;
883 else if (!strcmp(argv
[iArgPtr
], "--list-devices") ||
884 !strcmp(argv
[iArgPtr
], "-l"))
886 ICECAdapter
*parser
= CreateParser(g_typeList
);
890 UnloadLibCec(parser
);
895 else if (!strcmp(argv
[iArgPtr
], "--single-command") ||
896 !strcmp(argv
[iArgPtr
], "-s"))
898 g_bSingleCommand
= true;
901 else if (!strcmp(argv
[iArgPtr
], "--help") ||
902 !strcmp(argv
[iArgPtr
], "-h"))
904 ShowHelpCommandLine(argv
[0]);
907 else if (!strcmp(argv
[iArgPtr
], "-b") ||
908 !strcmp(argv
[iArgPtr
], "--base"))
910 if (argc
>= iArgPtr
+ 2)
912 g_iBaseDevice
= (cec_logical_address
)atoi(argv
[iArgPtr
+ 1]);
913 cout
<< "using base device '" << (int)g_iBaseDevice
<< "'" << endl
;
918 else if (!strcmp(argv
[iArgPtr
], "-p") ||
919 !strcmp(argv
[iArgPtr
], "--port"))
921 if (argc
>= iArgPtr
+ 2)
923 g_iHDMIPort
= (int8_t)atoi(argv
[iArgPtr
+ 1]);
924 cout
<< "using HDMI port '" << (int)g_iHDMIPort
<< "'" << endl
;
931 g_strPort
= argv
[iArgPtr
++];
939 int main (int argc
, char *argv
[])
943 if (!ProcessCommandLineArguments(argc
, argv
))
946 if (g_typeList
.IsEmpty())
948 if (!g_bSingleCommand
)
949 cout
<< "No device type given. Using 'recording device'" << endl
;
950 g_typeList
.add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
953 ICECAdapter
*parser
= LibCecInit("CECTester", g_typeList
);
954 if (!parser
|| parser
->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION
)
957 cout
<< "Cannot load libcec.dll" << endl
;
959 cout
<< "Cannot load libcec.so" << endl
;
964 if (!g_bSingleCommand
)
967 strLog
.Format("CEC Parser created - libcec version %d.%d", parser
->GetLibVersionMajor(), parser
->GetLibVersionMinor());
968 cout
<< strLog
.c_str() << endl
;
970 //make stdin non-blocking
972 int flags
= fcntl(0, F_GETFL
, 0);
974 fcntl(0, F_SETFL
, flags
);
978 if (g_strPort
.IsEmpty())
980 if (!g_bSingleCommand
)
981 cout
<< "no serial port given. trying autodetect: ";
982 cec_adapter devices
[10];
983 uint8_t iDevicesFound
= parser
->FindAdapters(devices
, 10, NULL
);
984 if (iDevicesFound
<= 0)
986 if (g_bSingleCommand
)
987 cout
<< "autodetect ";
988 cout
<< "FAILED" << endl
;
989 UnloadLibCec(parser
);
994 if (!g_bSingleCommand
)
996 cout
<< endl
<< " path: " << devices
[0].path
<< endl
<<
997 " com port: " << devices
[0].comm
<< endl
<< endl
;
999 g_strPort
= devices
[0].comm
;
1003 parser
->SetHDMIPort(g_iBaseDevice
, g_iHDMIPort
);
1004 cout
<< "opening a connection to the CEC adapter..." << endl
;
1006 if (!parser
->Open(g_strPort
.c_str()))
1008 cout
<< "unable to open the device on port " << g_strPort
<< endl
;
1010 UnloadLibCec(parser
);
1014 if (!g_bSingleCommand
)
1017 cout
<< "cec device opened" << endl
;
1019 parser
->PowerOnDevices(CECDEVICE_TV
);
1022 parser
->SetActiveSource();
1025 cout
<< "waiting for input" << endl
;
1028 bool bContinue(true);
1033 /* just ignore the command buffer and clear it */
1035 while (parser
&& parser
->GetNextCommand(&dummy
)) {}
1038 getline(cin
, input
);
1041 if (ProcessConsoleCommand(parser
, input
) && !g_bSingleCommand
)
1044 cout
<< "waiting for input" << endl
;
1050 CCondition::Sleep(50);
1053 if (!g_bSingleCommand
)
1054 parser
->StandbyDevices(CECDEVICE_BROADCAST
);
1058 UnloadLibCec(parser
);
1060 if (g_logOutput
.is_open())
1061 g_logOutput
.close();