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 "[as] make the CEC adapter the active source." << endl
<<
240 "[osd] {addr} {string} set OSD message on the specified device." << endl
<<
241 "[ver] {addr} get the CEC version of the specified device." << endl
<<
242 "[ven] {addr} get the vendor ID of the specified device." << endl
<<
243 "[lang] {addr} get the menu language of the specified device." << endl
<<
244 "[pow] {addr} get the power status of the specified device." << endl
<<
245 "[name] {addr} get the OSD name of the specified device." << endl
<<
246 "[poll] {addr} poll the specified device." << endl
<<
247 "[lad] lists active devices on the bus" << endl
<<
248 "[ad] {addr} checks whether the specified device is active." << endl
<<
249 "[at] {type} checks whether the specified device type is active." << endl
<<
250 "[volup] send a volume up command to the amp if present" << endl
<<
251 "[voldown] send a volume down command to the amp if present" << endl
<<
252 "[mute] send a mute/unmute command to the amp if present" << endl
<<
253 "[scan] scan the CEC bus and display device info" << endl
<<
254 "[mon] {1|0} enable or disable CEC bus monitoring." << endl
<<
255 "[log] {1 - 31} change the log level. see cectypes.h for values." << endl
<<
256 "[ping] send a ping command to the CEC adapter." << endl
<<
257 "[bl] to let the adapter enter the bootloader, to upgrade" << endl
<<
258 " the flash rom." << endl
<<
259 "[r] reconnect to the CEC adapter." << endl
<<
260 "[h] or [help] show this help." << endl
<<
261 "[q] or [quit] to quit the CEC test client and switch off all" << endl
<<
262 " connected CEC devices." << endl
<<
263 "================================================================================" << endl
;
266 bool ProcessCommandTX(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
268 if (command
== "tx" || command
== "txn")
275 while (GetWord(arguments
, strvalue
) && HexStrToInt(strvalue
, ivalue
))
276 bytes
.PushBack(ivalue
);
278 if (command
== "txn")
279 bytes
.transmit_timeout
= 0;
281 parser
->Transmit(bytes
);
289 bool ProcessCommandON(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
295 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
297 parser
->PowerOnDevices((cec_logical_address
) iValue
);
302 cout
<< "invalid destination" << endl
;
309 bool ProcessCommandSTANDBY(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
311 if (command
== "standby")
315 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
317 parser
->StandbyDevices((cec_logical_address
) iValue
);
322 cout
<< "invalid destination" << endl
;
329 bool ProcessCommandPOLL(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
331 if (command
== "poll")
335 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
337 if (parser
->PollDevice((cec_logical_address
) iValue
))
338 cout
<< "POLL message sent" << endl
;
340 cout
<< "POLL message not sent" << endl
;
345 cout
<< "invalid destination" << endl
;
352 bool ProcessCommandLA(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
357 if (GetWord(arguments
, strvalue
))
359 parser
->SetLogicalAddress((cec_logical_address
) atoi(strvalue
.c_str()));
367 bool ProcessCommandP(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
371 string strPort
, strDevice
;
372 if (GetWord(arguments
, strDevice
) && GetWord(arguments
, strPort
))
374 parser
->SetHDMIPort((cec_logical_address
)atoi(strDevice
.c_str()), (uint8_t)atoi(strPort
.c_str()));
382 bool ProcessCommandPA(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
388 if (GetWord(arguments
, strB1
) && HexStrToInt(strB1
, iB1
) &&
389 GetWord(arguments
, strB2
) && HexStrToInt(strB2
, iB2
))
391 uint16_t iPhysicalAddress
= ((uint16_t)iB1
<< 8) + iB2
;
392 parser
->SetPhysicalAddress(iPhysicalAddress
);
400 bool ProcessCommandOSD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
402 if (command
== "osd")
404 bool bFirstWord(false);
405 string strAddr
, strMessage
, strWord
;
407 if (GetWord(arguments
, strAddr
) && HexStrToInt(strAddr
, iAddr
) && iAddr
< 0xF)
409 while (GetWord(arguments
, strWord
))
414 strMessage
.append(" ");
416 strMessage
.append(strWord
);
418 parser
->SetOSDString((cec_logical_address
) iAddr
, CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME
, strMessage
.c_str());
426 bool ProcessCommandAS(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
430 parser
->SetActiveView();
438 bool ProcessCommandPING(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
440 if (command
== "ping")
442 parser
->PingAdapter();
449 bool ProcessCommandVOLUP(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
451 if (command
== "volup")
454 strLog
.Format("volume up: %2X", parser
->VolumeUp());
455 cout
<< strLog
.c_str() << endl
;
462 bool ProcessCommandVOLDOWN(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
464 if (command
== "voldown")
467 strLog
.Format("volume up: %2X", parser
->VolumeDown());
468 cout
<< strLog
.c_str() << endl
;
475 bool ProcessCommandMUTE(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
477 if (command
== "mute")
480 strLog
.Format("mute: %2X", parser
->MuteAudio());
481 cout
<< strLog
.c_str() << endl
;
488 bool ProcessCommandMON(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
490 if (command
== "mon")
492 CStdString strEnable
;
493 if (GetWord(arguments
, strEnable
) && (strEnable
.Equals("0") || strEnable
.Equals("1")))
495 parser
->SwitchMonitoring(strEnable
.Equals("1"));
503 bool ProcessCommandBL(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
507 parser
->StartBootloader();
514 bool ProcessCommandLANG(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
516 if (command
== "lang")
519 if (GetWord(arguments
, strDev
))
521 int iDev
= atoi(strDev
);
522 if (iDev
>= 0 && iDev
< 15)
525 cec_menu_language language
;
526 if (parser
->GetDeviceMenuLanguage((cec_logical_address
) iDev
, &language
))
527 strLog
.Format("menu language '%s'", language
.language
);
530 cout
<< strLog
.c_str() << endl
;
539 bool ProcessCommandVEN(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
541 if (command
== "ven")
544 if (GetWord(arguments
, strDev
))
546 int iDev
= atoi(strDev
);
547 if (iDev
>= 0 && iDev
< 15)
549 uint64_t iVendor
= parser
->GetDeviceVendorId((cec_logical_address
) iDev
);
551 strLog
.Format("vendor id: %06x", iVendor
);
552 cout
<< strLog
.c_str() << endl
;
561 bool ProcessCommandVER(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
563 if (command
== "ver")
566 if (GetWord(arguments
, strDev
))
568 int iDev
= atoi(strDev
);
569 if (iDev
>= 0 && iDev
< 15)
571 cec_version iVersion
= parser
->GetDeviceCecVersion((cec_logical_address
) iDev
);
572 cout
<< "CEC version " << parser
->ToString(iVersion
) << endl
;
581 bool ProcessCommandPOW(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
583 if (command
== "pow")
586 if (GetWord(arguments
, strDev
))
588 int iDev
= atoi(strDev
);
589 if (iDev
>= 0 && iDev
< 15)
591 cec_power_status iPower
= parser
->GetDevicePowerStatus((cec_logical_address
) iDev
);
592 cout
<< "power status: " << parser
->ToString(iPower
) << endl
;
602 bool ProcessCommandNAME(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
604 if (command
== "name")
607 if (GetWord(arguments
, strDev
))
609 int iDev
= atoi(strDev
);
610 if (iDev
>= 0 && iDev
< 15)
612 cec_osd_name name
= parser
->GetDeviceOSDName((cec_logical_address
)iDev
);
613 cout
<< "OSD name of device " << iDev
<< " is '" << name
.name
<< "'" << endl
;
622 bool ProcessCommandLAD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
624 if (command
== "lad")
626 cout
<< "listing active devices:" << endl
;
627 cec_logical_addresses addresses
= parser
->GetActiveDevices();
628 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
630 cout
<< "logical address " << (int)iPtr
<< endl
;
637 bool ProcessCommandAD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
642 if (GetWord(arguments
, strDev
))
644 int iDev
= atoi(strDev
);
645 if (iDev
>= 0 && iDev
< 15)
646 cout
<< "logical address " << iDev
<< " is " << (parser
->IsActiveDevice((cec_logical_address
)iDev
) ? "active" : "not active") << endl
;
653 bool ProcessCommandAT(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
658 if (GetWord(arguments
, strType
))
660 cec_device_type type
= CEC_DEVICE_TYPE_TV
;
661 if (strType
.Equals("a"))
662 type
= CEC_DEVICE_TYPE_AUDIO_SYSTEM
;
663 else if (strType
.Equals("p"))
664 type
= CEC_DEVICE_TYPE_PLAYBACK_DEVICE
;
665 else if (strType
.Equals("r"))
666 type
= CEC_DEVICE_TYPE_RECORDING_DEVICE
;
667 else if (strType
.Equals("t"))
668 type
= CEC_DEVICE_TYPE_TUNER
;
669 cout
<< "device " << type
<< " is " << (parser
->IsActiveDeviceType(type
) ? "active" : "not active") << endl
;
677 bool ProcessCommandR(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
681 cout
<< "closing the connection" << endl
;
685 cout
<< "opening a new connection" << endl
;
686 parser
->Open(g_strPort
.c_str());
689 cout
<< "setting active source" << endl
;
690 parser
->SetActiveSource();
697 bool ProcessCommandH(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
699 if (command
== "h" || command
== "help")
708 bool ProcessCommandLOG(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
710 if (command
== "log")
713 if (GetWord(arguments
, strLevel
))
715 int iNewLevel
= atoi(strLevel
);
716 if (iNewLevel
>= CEC_LOG_ERROR
&& iNewLevel
<= CEC_LOG_ALL
)
718 g_cecLogLevel
= iNewLevel
;
719 cout
<< "log level changed to " << strLevel
.c_str() << endl
;
728 bool ProcessCommandSCAN(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
730 if (command
== "scan")
732 cout
<< "CEC bus information" << endl
;
733 cout
<< "===================" << endl
;
734 cec_logical_addresses addresses
= parser
->GetActiveDevices();
735 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
739 uint64_t iVendorId
= parser
->GetDeviceVendorId((cec_logical_address
)iPtr
);
740 bool bActive
= parser
->IsActiveSource((cec_logical_address
)iPtr
);
741 uint16_t iPhysicalAddress
= parser
->GetDevicePhysicalAddress((cec_logical_address
)iPtr
);
742 cec_version iCecVersion
= parser
->GetDeviceCecVersion((cec_logical_address
)iPtr
);
743 cec_power_status power
= parser
->GetDevicePowerStatus((cec_logical_address
)iPtr
);
744 cec_osd_name osdName
= parser
->GetDeviceOSDName((cec_logical_address
)iPtr
);
746 strAddr
.Format("%04x", iPhysicalAddress
);
747 cec_menu_language lang
;
748 lang
.device
= CECDEVICE_UNKNOWN
;
749 parser
->GetDeviceMenuLanguage((cec_logical_address
)iPtr
, &lang
);
751 cout
<< "device #" << (int)iPtr
<< ": " << parser
->ToString((cec_logical_address
)iPtr
) << endl
;
752 cout
<< "address: " << strAddr
.c_str() << endl
;
753 cout
<< "active source: " << (bActive
? "yes" : "no") << endl
;
754 cout
<< "vendor: " << parser
->ToString((cec_vendor_id
)iVendorId
) << endl
;
755 cout
<< "osd string: " << osdName
.name
<< endl
;
756 cout
<< "CEC version: " << parser
->ToString(iCecVersion
) << endl
;
757 cout
<< "power status: " << parser
->ToString(power
) << endl
;
758 if ((uint8_t)lang
.device
== iPtr
)
759 cout
<< "language: " << lang
.language
<< endl
;
769 bool ProcessConsoleCommand(ICECAdapter
*parser
, string
&input
)
774 if (GetWord(input
, command
))
776 if (command
== "q" || command
== "quit")
779 ProcessCommandTX(parser
, command
, input
) ||
780 ProcessCommandON(parser
, command
, input
) ||
781 ProcessCommandSTANDBY(parser
, command
, input
) ||
782 ProcessCommandPOLL(parser
, command
, input
) ||
783 ProcessCommandLA(parser
, command
, input
) ||
784 ProcessCommandP(parser
, command
, input
) ||
785 ProcessCommandPA(parser
, command
, input
) ||
786 ProcessCommandAS(parser
, command
, input
) ||
787 ProcessCommandOSD(parser
, command
, input
) ||
788 ProcessCommandPING(parser
, command
, input
) ||
789 ProcessCommandVOLUP(parser
, command
, input
) ||
790 ProcessCommandVOLDOWN(parser
, command
, input
) ||
791 ProcessCommandMUTE(parser
, command
, input
) ||
792 ProcessCommandMON(parser
, command
, input
) ||
793 ProcessCommandBL(parser
, command
, input
) ||
794 ProcessCommandLANG(parser
, command
, input
) ||
795 ProcessCommandVEN(parser
, command
, input
) ||
796 ProcessCommandVER(parser
, command
, input
) ||
797 ProcessCommandPOW(parser
, command
, input
) ||
798 ProcessCommandNAME(parser
, command
, input
) ||
799 ProcessCommandLAD(parser
, command
, input
) ||
800 ProcessCommandAD(parser
, command
, input
) ||
801 ProcessCommandAT(parser
, command
, input
) ||
802 ProcessCommandR(parser
, command
, input
) ||
803 ProcessCommandH(parser
, command
, input
) ||
804 ProcessCommandLOG(parser
, command
, input
) ||
805 ProcessCommandSCAN(parser
, command
, input
);
811 bool ProcessCommandLineArguments(int argc
, char *argv
[])
815 while (iArgPtr
< argc
&& bReturn
)
817 if (argc
>= iArgPtr
+ 1)
819 if (!strcmp(argv
[iArgPtr
], "-f") ||
820 !strcmp(argv
[iArgPtr
], "--log-file") ||
821 !strcmp(argv
[iArgPtr
], "-sf") ||
822 !strcmp(argv
[iArgPtr
], "--short-log-file"))
824 if (argc
>= iArgPtr
+ 2)
826 g_logOutput
.open(argv
[iArgPtr
+ 1]);
827 g_bShortLog
= (!strcmp(argv
[iArgPtr
], "-sf") || !strcmp(argv
[iArgPtr
], "--short-log-file"));
832 cout
<< "== skipped log-file parameter: no file given ==" << endl
;
836 else if (!strcmp(argv
[iArgPtr
], "-d") ||
837 !strcmp(argv
[iArgPtr
], "--log-level"))
839 if (argc
>= iArgPtr
+ 2)
841 int iNewLevel
= atoi(argv
[iArgPtr
+ 1]);
842 if (iNewLevel
>= CEC_LOG_ERROR
&& iNewLevel
<= CEC_LOG_ALL
)
844 g_cecLogLevel
= iNewLevel
;
845 if (!g_bSingleCommand
)
846 cout
<< "log level set to " << argv
[iArgPtr
+ 1] << endl
;
850 cout
<< "== skipped log-level parameter: invalid level '" << argv
[iArgPtr
+ 1] << "' ==" << endl
;
856 cout
<< "== skipped log-level parameter: no level given ==" << endl
;
860 else if (!strcmp(argv
[iArgPtr
], "-t") ||
861 !strcmp(argv
[iArgPtr
], "--type"))
863 if (argc
>= iArgPtr
+ 2)
865 if (!strcmp(argv
[iArgPtr
+ 1], "p"))
867 if (!g_bSingleCommand
)
868 cout
<< "== using device type 'playback device'" << endl
;
869 g_typeList
.add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
871 else if (!strcmp(argv
[iArgPtr
+ 1], "r"))
873 if (!g_bSingleCommand
)
874 cout
<< "== using device type 'recording device'" << endl
;
875 g_typeList
.add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
877 else if (!strcmp(argv
[iArgPtr
+ 1], "t"))
879 if (!g_bSingleCommand
)
880 cout
<< "== using device type 'tuner'" << endl
;
881 g_typeList
.add(CEC_DEVICE_TYPE_TUNER
);
883 else if (!strcmp(argv
[iArgPtr
+ 1], "a"))
885 if (!g_bSingleCommand
)
886 cout
<< "== using device type 'audio system'" << endl
;
887 g_typeList
.add(CEC_DEVICE_TYPE_AUDIO_SYSTEM
);
891 cout
<< "== skipped invalid device type '" << argv
[iArgPtr
+ 1] << "'" << endl
;
897 else if (!strcmp(argv
[iArgPtr
], "--list-devices") ||
898 !strcmp(argv
[iArgPtr
], "-l"))
900 ICECAdapter
*parser
= CreateParser(g_typeList
);
904 UnloadLibCec(parser
);
909 else if (!strcmp(argv
[iArgPtr
], "--single-command") ||
910 !strcmp(argv
[iArgPtr
], "-s"))
912 g_bSingleCommand
= true;
915 else if (!strcmp(argv
[iArgPtr
], "--help") ||
916 !strcmp(argv
[iArgPtr
], "-h"))
918 ShowHelpCommandLine(argv
[0]);
921 else if (!strcmp(argv
[iArgPtr
], "-b") ||
922 !strcmp(argv
[iArgPtr
], "--base"))
924 if (argc
>= iArgPtr
+ 2)
926 g_iBaseDevice
= (cec_logical_address
)atoi(argv
[iArgPtr
+ 1]);
927 cout
<< "using base device '" << (int)g_iBaseDevice
<< "'" << endl
;
932 else if (!strcmp(argv
[iArgPtr
], "-p") ||
933 !strcmp(argv
[iArgPtr
], "--port"))
935 if (argc
>= iArgPtr
+ 2)
937 g_iHDMIPort
= (int8_t)atoi(argv
[iArgPtr
+ 1]);
938 cout
<< "using HDMI port '" << (int)g_iHDMIPort
<< "'" << endl
;
945 g_strPort
= argv
[iArgPtr
++];
953 int main (int argc
, char *argv
[])
957 if (!ProcessCommandLineArguments(argc
, argv
))
960 if (g_typeList
.IsEmpty())
962 if (!g_bSingleCommand
)
963 cout
<< "No device type given. Using 'recording device'" << endl
;
964 g_typeList
.add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
967 ICECAdapter
*parser
= LibCecInit("CECTester", g_typeList
);
968 if (!parser
|| parser
->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION
)
971 cout
<< "Cannot load libcec.dll" << endl
;
973 cout
<< "Cannot load libcec.so" << endl
;
978 if (!g_bSingleCommand
)
981 strLog
.Format("CEC Parser created - libcec version %d.%d", parser
->GetLibVersionMajor(), parser
->GetLibVersionMinor());
982 cout
<< strLog
.c_str() << endl
;
984 //make stdin non-blocking
986 int flags
= fcntl(0, F_GETFL
, 0);
988 fcntl(0, F_SETFL
, flags
);
992 if (g_strPort
.IsEmpty())
994 if (!g_bSingleCommand
)
995 cout
<< "no serial port given. trying autodetect: ";
996 cec_adapter devices
[10];
997 uint8_t iDevicesFound
= parser
->FindAdapters(devices
, 10, NULL
);
998 if (iDevicesFound
<= 0)
1000 if (g_bSingleCommand
)
1001 cout
<< "autodetect ";
1002 cout
<< "FAILED" << endl
;
1003 UnloadLibCec(parser
);
1008 if (!g_bSingleCommand
)
1010 cout
<< endl
<< " path: " << devices
[0].path
<< endl
<<
1011 " com port: " << devices
[0].comm
<< endl
<< endl
;
1013 g_strPort
= devices
[0].comm
;
1017 parser
->SetHDMIPort(g_iBaseDevice
, g_iHDMIPort
);
1018 cout
<< "opening a connection to the CEC adapter..." << endl
;
1020 if (!parser
->Open(g_strPort
.c_str()))
1022 cout
<< "unable to open the device on port " << g_strPort
<< endl
;
1024 UnloadLibCec(parser
);
1028 if (!g_bSingleCommand
)
1031 cout
<< "cec device opened" << endl
;
1033 parser
->PowerOnDevices(CECDEVICE_TV
);
1036 parser
->SetActiveSource();
1039 cout
<< "waiting for input" << endl
;
1042 bool bContinue(true);
1047 /* just ignore the command buffer and clear it */
1049 while (parser
&& parser
->GetNextCommand(&dummy
)) {}
1052 getline(cin
, input
);
1055 if (ProcessConsoleCommand(parser
, input
) && !g_bSingleCommand
)
1058 cout
<< "waiting for input" << endl
;
1064 CCondition::Sleep(50);
1067 if (!g_bSingleCommand
)
1068 parser
->StandbyDevices(CECDEVICE_BROADCAST
);
1072 UnloadLibCec(parser
);
1074 if (g_logOutput
.is_open())
1075 g_logOutput
.close();