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 int8_t g_iHDMIPort(-1);
57 cec_device_type_list g_typeList
;
58 bool g_bSingleCommand(false);
61 inline bool HexStrToInt(const std::string
& data
, uint8_t& value
)
64 if (sscanf(data
.c_str(), "%x", &iTmp
) == 1)
71 value
= (uint8_t) iTmp
;
79 //get the first word (separated by whitespace) from string data and place that in word
80 //then remove that word from string data
81 bool GetWord(string
& data
, string
& word
)
83 stringstream
datastream(data
);
87 if (datastream
.fail())
93 size_t pos
= data
.find(word
) + word
.length();
95 if (pos
>= data
.length())
101 data
= data
.substr(pos
);
104 datastream
.str(data
);
107 if (datastream
.fail())
113 void FlushLog(ICECAdapter
*cecParser
)
115 cec_log_message message
;
116 while (cecParser
&& cecParser
->GetNextLogMessage(&message
))
118 if ((message
.level
& g_cecLogLevel
) == message
.level
)
121 switch (message
.level
)
124 strLevel
= "ERROR: ";
126 case CEC_LOG_WARNING
:
127 strLevel
= "WARNING: ";
130 strLevel
= "NOTICE: ";
132 case CEC_LOG_TRAFFIC
:
133 strLevel
= "TRAFFIC: ";
136 strLevel
= "DEBUG: ";
142 CStdString strFullLog
;
143 strFullLog
.Format("%s[%16lld]\t%s", strLevel
.c_str(), message
.time
, message
.message
);
144 cout
<< strFullLog
.c_str() << endl
;
146 if (g_logOutput
.is_open())
149 g_logOutput
<< message
.message
<< endl
;
151 g_logOutput
<< strFullLog
.c_str() << endl
;
157 void ListDevices(ICECAdapter
*parser
)
159 cec_adapter
*devices
= new cec_adapter
[10];
160 uint8_t iDevicesFound
= parser
->FindAdapters(devices
, 10, NULL
);
161 if (iDevicesFound
<= 0)
163 cout
<< "Found devices: NONE" << endl
;
168 strLog
.Format("Found devices: %d", iDevicesFound
);
169 cout
<< strLog
.c_str() << endl
;
170 for (unsigned int iDevicePtr
= 0; iDevicePtr
< iDevicesFound
; iDevicePtr
++)
172 CStdString strDevice
;
173 strDevice
.Format("device: %d\npath: %s\ncom port: %s", iDevicePtr
+ 1, devices
[iDevicePtr
].path
, devices
[iDevicePtr
].comm
);
174 cout
<< endl
<< strDevice
.c_str() << endl
;
179 void ShowHelpCommandLine(const char* strExec
)
182 strExec
<< " {-h|--help|-l|--list-devices|[COM PORT]}" << endl
<<
184 "parameters:" << endl
<<
185 " -h --help Shows this help text" << endl
<<
186 " -l --list-devices List all devices on this system" << endl
<<
187 " -t --type {p|r|t|a} The device type to use. More than one is possible." << endl
<<
188 " -p --port {int} The HDMI port to use as active source." << endl
<<
189 " -f --log-file {file} Writes all libCEC log message to a file" << endl
<<
190 " -sf --short-log-file {file} Writes all libCEC log message without timestamps" << endl
<<
191 " and log levels to a file." << endl
<<
192 " -d --log-level {level} Sets the log level. See cectypes.h for values." << endl
<<
193 " -s --single-command Execute a single command and exit. Does not power" << endl
<<
194 " on devices on startup and power them off on exit." << endl
<<
195 " [COM PORT] The com port to connect to. If no COM" << endl
<<
196 " port is given, the client tries to connect to the" << endl
<<
197 " first device that is detected." << endl
<<
199 "Type 'h' or 'help' and press enter after starting the client to display all " << endl
<<
200 "available commands" << endl
;
203 ICECAdapter
*CreateParser(cec_device_type_list typeList
)
205 ICECAdapter
*parser
= LibCecInit("CECTester", typeList
);
206 if (!parser
|| parser
->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION
)
209 cout
<< "Cannot load libcec.dll" << endl
;
211 cout
<< "Cannot load libcec.so" << endl
;
217 strLog
.Format("CEC Parser created - libcec version %d.%d", parser
->GetLibVersionMajor(), parser
->GetLibVersionMinor());
218 cout
<< strLog
.c_str() << endl
;
223 void ShowHelpConsole(void)
226 "================================================================================" << endl
<<
227 "Available commands:" << endl
<<
229 "[tx] {bytes} transfer bytes over the CEC line." << endl
<<
230 "[txn] {bytes} transfer bytes but don't wait for transmission ACK." << endl
<<
231 "[on] {address} power on the device with the given logical address." << endl
<<
232 "[standby] {address} put the device with the given address in standby mode." << endl
<<
233 "[la] {logical address} change the logical address of the CEC adapter." << endl
<<
234 "[p] {device} {port} change the HDMI port number of the CEC adapter." << endl
<<
235 "[pa] {physical address} change the physical address of the CEC adapter." << endl
<<
236 "[osd] {addr} {string} set OSD message on the specified device." << endl
<<
237 "[ver] {addr} get the CEC version of the specified device." << endl
<<
238 "[ven] {addr} get the vendor ID of the specified device." << endl
<<
239 "[lang] {addr} get the menu language of the specified device." << endl
<<
240 "[pow] {addr} get the power status of the specified device." << endl
<<
241 "[name] {addr} get the OSD name of the specified device." << endl
<<
242 "[poll] {addr} poll the specified device." << endl
<<
243 "[lad] lists active devices on the bus" << endl
<<
244 "[ad] {addr} checks whether the specified device is active." << endl
<<
245 "[at] {type} checks whether the specified device type is active." << endl
<<
246 "[volup] send a volume up command to the amp if present" << endl
<<
247 "[voldown] send a volume down command to the amp if present" << endl
<<
248 "[mute] send a mute/unmute command to the amp if present" << endl
<<
249 "[scan] scan the CEC bus and display device info" << endl
<<
250 "[mon] {1|0} enable or disable CEC bus monitoring." << endl
<<
251 "[log] {1 - 31} change the log level. see cectypes.h for values." << endl
<<
252 "[ping] send a ping command to the CEC adapter." << endl
<<
253 "[bl] to let the adapter enter the bootloader, to upgrade" << endl
<<
254 " the flash rom." << endl
<<
255 "[r] reconnect to the CEC adapter." << endl
<<
256 "[h] or [help] show this help." << endl
<<
257 "[q] or [quit] to quit the CEC test client and switch off all" << endl
<<
258 " connected CEC devices." << endl
<<
259 "================================================================================" << endl
;
262 bool ProcessCommandTX(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
264 if (command
== "tx" || command
== "txn")
271 while (GetWord(arguments
, strvalue
) && HexStrToInt(strvalue
, ivalue
))
272 bytes
.PushBack(ivalue
);
274 if (command
== "txn")
275 bytes
.transmit_timeout
= 0;
277 parser
->Transmit(bytes
);
285 bool ProcessCommandON(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
291 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
293 parser
->PowerOnDevices((cec_logical_address
) iValue
);
298 cout
<< "invalid destination" << endl
;
305 bool ProcessCommandSTANDBY(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
307 if (command
== "standby")
311 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
313 parser
->StandbyDevices((cec_logical_address
) iValue
);
318 cout
<< "invalid destination" << endl
;
325 bool ProcessCommandPOLL(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
327 if (command
== "poll")
331 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
333 if (parser
->PollDevice((cec_logical_address
) iValue
))
334 cout
<< "POLL message sent" << endl
;
336 cout
<< "POLL message not sent" << endl
;
341 cout
<< "invalid destination" << endl
;
348 bool ProcessCommandLA(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
353 if (GetWord(arguments
, strvalue
))
355 parser
->SetLogicalAddress((cec_logical_address
) atoi(strvalue
.c_str()));
363 bool ProcessCommandP(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
367 string strPort
, strDevice
;
368 if (GetWord(arguments
, strDevice
) && GetWord(arguments
, strPort
))
370 parser
->SetHDMIPort((cec_logical_address
)atoi(strDevice
.c_str()), (uint8_t)atoi(strPort
.c_str()));
378 bool ProcessCommandPA(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
384 if (GetWord(arguments
, strB1
) && HexStrToInt(strB1
, iB1
) &&
385 GetWord(arguments
, strB2
) && HexStrToInt(strB2
, iB2
))
387 uint16_t iPhysicalAddress
= ((uint16_t)iB1
<< 8) + iB2
;
388 parser
->SetPhysicalAddress(iPhysicalAddress
);
396 bool ProcessCommandOSD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
398 if (command
== "osd")
400 bool bFirstWord(false);
401 string strAddr
, strMessage
, strWord
;
403 if (GetWord(arguments
, strAddr
) && HexStrToInt(strAddr
, iAddr
) && iAddr
< 0xF)
405 while (GetWord(arguments
, strWord
))
410 strMessage
.append(" ");
412 strMessage
.append(strWord
);
414 parser
->SetOSDString((cec_logical_address
) iAddr
, CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME
, strMessage
.c_str());
422 bool ProcessCommandPING(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
424 if (command
== "ping")
426 parser
->PingAdapter();
433 bool ProcessCommandVOLUP(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
435 if (command
== "volup")
438 strLog
.Format("volume up: %2X", parser
->VolumeUp());
439 cout
<< strLog
.c_str() << endl
;
446 bool ProcessCommandVOLDOWN(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
448 if (command
== "voldown")
451 strLog
.Format("volume up: %2X", parser
->VolumeDown());
452 cout
<< strLog
.c_str() << endl
;
459 bool ProcessCommandMUTE(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
461 if (command
== "mute")
464 strLog
.Format("mute: %2X", parser
->MuteAudio());
465 cout
<< strLog
.c_str() << endl
;
472 bool ProcessCommandMON(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
474 if (command
== "mon")
476 CStdString strEnable
;
477 if (GetWord(arguments
, strEnable
) && (strEnable
.Equals("0") || strEnable
.Equals("1")))
479 parser
->SwitchMonitoring(strEnable
.Equals("1"));
487 bool ProcessCommandBL(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
491 parser
->StartBootloader();
498 bool ProcessCommandLANG(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
500 if (command
== "lang")
503 if (GetWord(arguments
, strDev
))
505 int iDev
= atoi(strDev
);
506 if (iDev
>= 0 && iDev
< 15)
509 cec_menu_language language
;
510 if (parser
->GetDeviceMenuLanguage((cec_logical_address
) iDev
, &language
))
511 strLog
.Format("menu language '%s'", language
.language
);
514 cout
<< strLog
.c_str() << endl
;
523 bool ProcessCommandVEN(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
525 if (command
== "ven")
528 if (GetWord(arguments
, strDev
))
530 int iDev
= atoi(strDev
);
531 if (iDev
>= 0 && iDev
< 15)
533 uint64_t iVendor
= parser
->GetDeviceVendorId((cec_logical_address
) iDev
);
535 strLog
.Format("vendor id: %06x", iVendor
);
536 cout
<< strLog
.c_str() << endl
;
545 bool ProcessCommandVER(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
547 if (command
== "ver")
550 if (GetWord(arguments
, strDev
))
552 int iDev
= atoi(strDev
);
553 if (iDev
>= 0 && iDev
< 15)
555 cec_version iVersion
= parser
->GetDeviceCecVersion((cec_logical_address
) iDev
);
556 cout
<< "CEC version " << parser
->ToString(iVersion
) << endl
;
565 bool ProcessCommandPOW(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
567 if (command
== "pow")
570 if (GetWord(arguments
, strDev
))
572 int iDev
= atoi(strDev
);
573 if (iDev
>= 0 && iDev
< 15)
575 cec_power_status iPower
= parser
->GetDevicePowerStatus((cec_logical_address
) iDev
);
576 cout
<< "power status: " << parser
->ToString(iPower
) << endl
;
586 bool ProcessCommandNAME(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
588 if (command
== "name")
591 if (GetWord(arguments
, strDev
))
593 int iDev
= atoi(strDev
);
594 if (iDev
>= 0 && iDev
< 15)
596 cec_osd_name name
= parser
->GetOSDName((cec_logical_address
)iDev
);
597 cout
<< "OSD name of device " << iDev
<< " is '" << name
.name
<< "'" << endl
;
606 bool ProcessCommandLAD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
608 if (command
== "lad")
610 cout
<< "listing active devices:" << endl
;
611 cec_logical_addresses addresses
= parser
->GetActiveDevices();
612 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
614 cout
<< "logical address " << (int)iPtr
<< endl
;
621 bool ProcessCommandAD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
626 if (GetWord(arguments
, strDev
))
628 int iDev
= atoi(strDev
);
629 if (iDev
>= 0 && iDev
< 15)
630 cout
<< "logical address " << iDev
<< " is " << (parser
->IsActiveDevice((cec_logical_address
)iDev
) ? "active" : "not active") << endl
;
637 bool ProcessCommandAT(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
642 if (GetWord(arguments
, strType
))
644 cec_device_type type
= CEC_DEVICE_TYPE_TV
;
645 if (strType
.Equals("a"))
646 type
= CEC_DEVICE_TYPE_AUDIO_SYSTEM
;
647 else if (strType
.Equals("p"))
648 type
= CEC_DEVICE_TYPE_PLAYBACK_DEVICE
;
649 else if (strType
.Equals("r"))
650 type
= CEC_DEVICE_TYPE_RECORDING_DEVICE
;
651 else if (strType
.Equals("t"))
652 type
= CEC_DEVICE_TYPE_TUNER
;
653 cout
<< "device " << type
<< " is " << (parser
->IsActiveDeviceType(type
) ? "active" : "not active") << endl
;
661 bool ProcessCommandR(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
665 cout
<< "closing the connection" << endl
;
669 cout
<< "opening a new connection" << endl
;
670 parser
->Open(g_strPort
.c_str());
673 cout
<< "setting active source" << endl
;
674 parser
->SetActiveSource();
681 bool ProcessCommandH(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
683 if (command
== "h" || command
== "help")
692 bool ProcessCommandLOG(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
694 if (command
== "log")
697 if (GetWord(arguments
, strLevel
))
699 int iNewLevel
= atoi(strLevel
);
700 if (iNewLevel
>= CEC_LOG_ERROR
&& iNewLevel
<= CEC_LOG_ALL
)
702 g_cecLogLevel
= iNewLevel
;
703 cout
<< "log level changed to " << strLevel
.c_str() << endl
;
712 bool ProcessCommandSCAN(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
714 if (command
== "scan")
716 cout
<< "CEC bus information" << endl
;
717 cout
<< "===================" << endl
;
718 cec_logical_addresses addresses
= parser
->GetActiveDevices();
719 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
723 uint64_t iVendorId
= parser
->GetDeviceVendorId((cec_logical_address
)iPtr
);
724 cec_version iCecVersion
= parser
->GetDeviceCecVersion((cec_logical_address
)iPtr
);
725 cec_power_status power
= parser
->GetDevicePowerStatus((cec_logical_address
)iPtr
);
726 cec_osd_name osdName
= parser
->GetOSDName((cec_logical_address
)iPtr
);
727 cec_menu_language lang
;
728 lang
.device
= CECDEVICE_UNKNOWN
;
729 parser
->GetDeviceMenuLanguage((cec_logical_address
)iPtr
, &lang
);
731 cout
<< "device #" << (int)iPtr
<< ": " << parser
->ToString((cec_logical_address
)iPtr
) << endl
;
732 cout
<< "vendor: " << parser
->ToString((cec_vendor_id
)iVendorId
) << endl
;
733 cout
<< "osd string: " << osdName
.name
<< endl
;
734 cout
<< "CEC version: " << parser
->ToString(iCecVersion
) << endl
;
735 cout
<< "power status: " << parser
->ToString(power
) << endl
;
736 if ((uint8_t)lang
.device
== iPtr
)
737 cout
<< "language: " << lang
.language
<< endl
;
747 bool ProcessConsoleCommand(ICECAdapter
*parser
, string
&input
)
752 if (GetWord(input
, command
))
754 if (command
== "q" || command
== "quit")
757 ProcessCommandTX(parser
, command
, input
) ||
758 ProcessCommandON(parser
, command
, input
) ||
759 ProcessCommandSTANDBY(parser
, command
, input
) ||
760 ProcessCommandPOLL(parser
, command
, input
) ||
761 ProcessCommandLA(parser
, command
, input
) ||
762 ProcessCommandP(parser
, command
, input
) ||
763 ProcessCommandPA(parser
, command
, input
) ||
764 ProcessCommandOSD(parser
, command
, input
) ||
765 ProcessCommandPING(parser
, command
, input
) ||
766 ProcessCommandVOLUP(parser
, command
, input
) ||
767 ProcessCommandVOLDOWN(parser
, command
, input
) ||
768 ProcessCommandMUTE(parser
, command
, input
) ||
769 ProcessCommandMON(parser
, command
, input
) ||
770 ProcessCommandBL(parser
, command
, input
) ||
771 ProcessCommandLANG(parser
, command
, input
) ||
772 ProcessCommandVEN(parser
, command
, input
) ||
773 ProcessCommandVER(parser
, command
, input
) ||
774 ProcessCommandPOW(parser
, command
, input
) ||
775 ProcessCommandNAME(parser
, command
, input
) ||
776 ProcessCommandLAD(parser
, command
, input
) ||
777 ProcessCommandAD(parser
, command
, input
) ||
778 ProcessCommandAT(parser
, command
, input
) ||
779 ProcessCommandR(parser
, command
, input
) ||
780 ProcessCommandH(parser
, command
, input
) ||
781 ProcessCommandLOG(parser
, command
, input
) ||
782 ProcessCommandSCAN(parser
, command
, input
);
788 bool ProcessCommandLineArguments(int argc
, char *argv
[])
792 while (iArgPtr
< argc
)
794 if (argc
>= iArgPtr
+ 1)
796 if (!strcmp(argv
[iArgPtr
], "-f") ||
797 !strcmp(argv
[iArgPtr
], "--log-file") ||
798 !strcmp(argv
[iArgPtr
], "-sf") ||
799 !strcmp(argv
[iArgPtr
], "--short-log-file"))
801 if (argc
>= iArgPtr
+ 2)
803 g_logOutput
.open(argv
[iArgPtr
+ 1]);
804 g_bShortLog
= (!strcmp(argv
[iArgPtr
], "-sf") || !strcmp(argv
[iArgPtr
], "--short-log-file"));
809 cout
<< "== skipped log-file parameter: no file given ==" << endl
;
813 else if (!strcmp(argv
[iArgPtr
], "-d") ||
814 !strcmp(argv
[iArgPtr
], "--log-level"))
816 if (argc
>= iArgPtr
+ 2)
818 int iNewLevel
= atoi(argv
[iArgPtr
+ 1]);
819 if (iNewLevel
>= CEC_LOG_ERROR
&& iNewLevel
<= CEC_LOG_ALL
)
821 g_cecLogLevel
= iNewLevel
;
822 if (!g_bSingleCommand
)
823 cout
<< "log level set to " << argv
[iArgPtr
+ 1] << endl
;
827 cout
<< "== skipped log-level parameter: invalid level '" << argv
[iArgPtr
+ 1] << "' ==" << endl
;
833 cout
<< "== skipped log-level parameter: no level given ==" << endl
;
837 else if (!strcmp(argv
[iArgPtr
], "-t") ||
838 !strcmp(argv
[iArgPtr
], "--type"))
840 if (argc
>= iArgPtr
+ 2)
842 if (!strcmp(argv
[iArgPtr
+ 1], "p"))
844 if (!g_bSingleCommand
)
845 cout
<< "== using device type 'playback device'" << endl
;
846 g_typeList
.add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
848 else if (!strcmp(argv
[iArgPtr
+ 1], "r"))
850 if (!g_bSingleCommand
)
851 cout
<< "== using device type 'recording device'" << endl
;
852 g_typeList
.add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
854 else if (!strcmp(argv
[iArgPtr
+ 1], "t"))
856 if (!g_bSingleCommand
)
857 cout
<< "== using device type 'tuner'" << endl
;
858 g_typeList
.add(CEC_DEVICE_TYPE_TUNER
);
860 else if (!strcmp(argv
[iArgPtr
+ 1], "a"))
862 if (!g_bSingleCommand
)
863 cout
<< "== using device type 'audio system'" << endl
;
864 g_typeList
.add(CEC_DEVICE_TYPE_AUDIO_SYSTEM
);
868 cout
<< "== skipped invalid device type '" << argv
[iArgPtr
+ 1] << "'" << endl
;
874 else if (!strcmp(argv
[iArgPtr
], "--list-devices") ||
875 !strcmp(argv
[iArgPtr
], "-l"))
877 ICECAdapter
*parser
= CreateParser(g_typeList
);
881 UnloadLibCec(parser
);
885 else if (!strcmp(argv
[iArgPtr
], "--single-command") ||
886 !strcmp(argv
[iArgPtr
], "-s"))
888 g_bSingleCommand
= true;
891 else if (!strcmp(argv
[iArgPtr
], "--help") ||
892 !strcmp(argv
[iArgPtr
], "-h"))
894 ShowHelpCommandLine(argv
[0]);
897 else if (!strcmp(argv
[iArgPtr
], "-p") ||
898 !strcmp(argv
[iArgPtr
], "--port"))
900 if (argc
>= iArgPtr
+ 2)
902 g_iHDMIPort
= (int8_t)atoi(argv
[iArgPtr
+ 1]);
903 cout
<< "using HDMI port '" << g_iHDMIPort
<< "'" << endl
;
910 g_strPort
= argv
[iArgPtr
++];
918 int main (int argc
, char *argv
[])
922 if (!ProcessCommandLineArguments(argc
, argv
))
925 if (g_typeList
.IsEmpty())
927 if (!g_bSingleCommand
)
928 cout
<< "No device type given. Using 'recording device'" << endl
;
929 g_typeList
.add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
932 ICECAdapter
*parser
= LibCecInit("CECTester", g_typeList
);
933 if (!parser
|| parser
->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION
)
936 cout
<< "Cannot load libcec.dll" << endl
;
938 cout
<< "Cannot load libcec.so" << endl
;
943 if (!g_bSingleCommand
)
946 strLog
.Format("CEC Parser created - libcec version %d.%d", parser
->GetLibVersionMajor(), parser
->GetLibVersionMinor());
947 cout
<< strLog
.c_str() << endl
;
949 //make stdin non-blocking
951 int flags
= fcntl(0, F_GETFL
, 0);
953 fcntl(0, F_SETFL
, flags
);
957 if (g_strPort
.IsEmpty())
959 if (!g_bSingleCommand
)
960 cout
<< "no serial port given. trying autodetect: ";
961 cec_adapter devices
[10];
962 uint8_t iDevicesFound
= parser
->FindAdapters(devices
, 10, NULL
);
963 if (iDevicesFound
<= 0)
965 if (g_bSingleCommand
)
966 cout
<< "autodetect ";
967 cout
<< "FAILED" << endl
;
968 UnloadLibCec(parser
);
973 if (!g_bSingleCommand
)
975 cout
<< endl
<< " path: " << devices
[0].path
<< endl
<<
976 " com port: " << devices
[0].comm
<< endl
<< endl
;
978 g_strPort
= devices
[0].comm
;
984 parser
->SetHDMIPort((cec_logical_address
)CEC_DEFAULT_BASE_DEVICE
, (uint8_t)g_iHDMIPort
);
988 cout
<< "scanning the CEC bus..." << endl
;
990 if (!parser
->Open(g_strPort
.c_str()))
992 cout
<< "unable to open the device on port " << g_strPort
<< endl
;
994 UnloadLibCec(parser
);
998 if (!g_bSingleCommand
)
1000 cout
<< "cec device opened" << endl
;
1002 parser
->PowerOnDevices(CECDEVICE_TV
);
1005 parser
->SetActiveSource();
1008 cout
<< "waiting for input" << endl
;
1011 bool bContinue(true);
1016 /* just ignore the command buffer and clear it */
1018 while (parser
&& parser
->GetNextCommand(&dummy
)) {}
1021 getline(cin
, input
);
1024 if (ProcessConsoleCommand(parser
, input
) && !g_bSingleCommand
)
1027 cout
<< "waiting for input" << endl
;
1033 CCondition::Sleep(50);
1036 if (!g_bSingleCommand
)
1037 parser
->StandbyDevices(CECDEVICE_BROADCAST
);
1041 UnloadLibCec(parser
);
1043 if (g_logOutput
.is_open())
1044 g_logOutput
.close();