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 ICECCallbacks g_callbacks
;
63 inline void PrintToStdOut(const char *strOut
)
65 CLockObject
lock(g_outputMutex
);
66 cout
<< strOut
<< endl
;
69 inline void PrintToStdOut(const CStdString
&strOut
)
71 PrintToStdOut(strOut
.c_str());
74 inline bool HexStrToInt(const std::string
& data
, uint8_t& value
)
77 if (sscanf(data
.c_str(), "%x", &iTmp
) == 1)
84 value
= (uint8_t) iTmp
;
92 //get the first word (separated by whitespace) from string data and place that in word
93 //then remove that word from string data
94 bool GetWord(string
& data
, string
& word
)
96 stringstream
datastream(data
);
100 if (datastream
.fail())
106 size_t pos
= data
.find(word
) + word
.length();
108 if (pos
>= data
.length())
114 data
= data
.substr(pos
);
117 datastream
.str(data
);
120 if (datastream
.fail())
126 int CecLogMessage(void *UNUSED(cbParam
), const cec_log_message
&message
)
128 if ((message
.level
& g_cecLogLevel
) == message
.level
)
131 switch (message
.level
)
134 strLevel
= "ERROR: ";
136 case CEC_LOG_WARNING
:
137 strLevel
= "WARNING: ";
140 strLevel
= "NOTICE: ";
142 case CEC_LOG_TRAFFIC
:
143 strLevel
= "TRAFFIC: ";
146 strLevel
= "DEBUG: ";
152 CStdString strFullLog
;
153 strFullLog
.Format("%s[%16lld]\t%s", strLevel
.c_str(), message
.time
, message
.message
);
154 PrintToStdOut(strFullLog
);
156 if (g_logOutput
.is_open())
159 g_logOutput
<< message
.message
<< endl
;
161 g_logOutput
<< strFullLog
.c_str() << endl
;
168 int CecKeyPress(void *UNUSED(cbParam
), const cec_keypress
&UNUSED(key
))
173 int CecCommand(void *UNUSED(cbParam
), const cec_command
&UNUSED(command
))
178 void EnableCallbacks(ICECAdapter
*adapter
)
180 g_callbacks
.CBCecLogMessage
= &CecLogMessage
;
181 g_callbacks
.CBCecKeyPress
= &CecKeyPress
;
182 g_callbacks
.CBCecCommand
= &CecCommand
;
183 adapter
->EnableCallbacks(NULL
, &g_callbacks
);
186 void ListDevices(ICECAdapter
*parser
)
188 cec_adapter
*devices
= new cec_adapter
[10];
189 uint8_t iDevicesFound
= parser
->FindAdapters(devices
, 10, NULL
);
190 if (iDevicesFound
<= 0)
192 PrintToStdOut("Found devices: NONE");
197 strLog
.Format("Found devices: %d", iDevicesFound
);
198 PrintToStdOut(strLog
);
199 for (unsigned int iDevicePtr
= 0; iDevicePtr
< iDevicesFound
; iDevicePtr
++)
201 CStdString strDevice
;
202 strDevice
.Format("device: %d\npath: %s\ncom port: %s", iDevicePtr
+ 1, devices
[iDevicePtr
].path
, devices
[iDevicePtr
].comm
);
203 PrintToStdOut(strDevice
);
208 void ShowHelpCommandLine(const char* strExec
)
210 CLockObject
lock(g_outputMutex
);
212 strExec
<< " {-h|--help|-l|--list-devices|[COM PORT]}" << endl
<<
214 "parameters:" << endl
<<
215 " -h --help Shows this help text" << endl
<<
216 " -l --list-devices List all devices on this system" << endl
<<
217 " -t --type {p|r|t|a} The device type to use. More than one is possible." << endl
<<
218 " -p --port {int} The HDMI port to use as active source." << endl
<<
219 " -b --base {int} The logical address of the device to with this " << endl
<<
220 " adapter is connected." << endl
<<
221 " -f --log-file {file} Writes all libCEC log message to a file" << endl
<<
222 " -sf --short-log-file {file} Writes all libCEC log message without timestamps" << endl
<<
223 " and log levels to a file." << endl
<<
224 " -d --log-level {level} Sets the log level. See cectypes.h for values." << endl
<<
225 " -s --single-command Execute a single command and exit. Does not power" << endl
<<
226 " on devices on startup and power them off on exit." << endl
<<
227 " [COM PORT] The com port to connect to. If no COM" << endl
<<
228 " port is given, the client tries to connect to the" << endl
<<
229 " first device that is detected." << endl
<<
231 "Type 'h' or 'help' and press enter after starting the client to display all " << endl
<<
232 "available commands" << endl
;
235 ICECAdapter
*CreateParser(cec_device_type_list typeList
)
237 ICECAdapter
*parser
= LibCecInit("CECTester", typeList
);
238 if (!parser
|| parser
->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION
)
241 PrintToStdOut("Cannot load libcec.dll");
243 PrintToStdOut("Cannot load libcec.so");
249 strLog
.Format("CEC Parser created - libcec version %d.%d", parser
->GetLibVersionMajor(), parser
->GetLibVersionMinor());
250 PrintToStdOut(strLog
.c_str());
255 void ShowHelpConsole(void)
257 CLockObject
lock(g_outputMutex
);
259 "================================================================================" << endl
<<
260 "Available commands:" << endl
<<
262 "[tx] {bytes} transfer bytes over the CEC line." << endl
<<
263 "[txn] {bytes} transfer bytes but don't wait for transmission ACK." << endl
<<
264 "[on] {address} power on the device with the given logical address." << endl
<<
265 "[standby] {address} put the device with the given address in standby mode." << endl
<<
266 "[la] {logical address} change the logical address of the CEC adapter." << endl
<<
267 "[p] {device} {port} change the HDMI port number of the CEC adapter." << endl
<<
268 "[pa] {physical address} change the physical address of the CEC adapter." << endl
<<
269 "[as] make the CEC adapter the active source." << endl
<<
270 "[osd] {addr} {string} set OSD message on the specified device." << endl
<<
271 "[ver] {addr} get the CEC version of the specified device." << endl
<<
272 "[ven] {addr} get the vendor ID of the specified device." << endl
<<
273 "[lang] {addr} get the menu language of the specified device." << endl
<<
274 "[pow] {addr} get the power status of the specified device." << endl
<<
275 "[name] {addr} get the OSD name of the specified device." << endl
<<
276 "[poll] {addr} poll the specified device." << endl
<<
277 "[lad] lists active devices on the bus" << endl
<<
278 "[ad] {addr} checks whether the specified device is active." << endl
<<
279 "[at] {type} checks whether the specified device type is active." << endl
<<
280 "[volup] send a volume up command to the amp if present" << endl
<<
281 "[voldown] send a volume down command to the amp if present" << endl
<<
282 "[mute] send a mute/unmute command to the amp if present" << endl
<<
283 "[scan] scan the CEC bus and display device info" << endl
<<
284 "[mon] {1|0} enable or disable CEC bus monitoring." << endl
<<
285 "[log] {1 - 31} change the log level. see cectypes.h for values." << endl
<<
286 "[ping] send a ping command to the CEC adapter." << endl
<<
287 "[bl] to let the adapter enter the bootloader, to upgrade" << endl
<<
288 " the flash rom." << endl
<<
289 "[r] reconnect to the CEC adapter." << endl
<<
290 "[h] or [help] show this help." << endl
<<
291 "[q] or [quit] to quit the CEC test client and switch off all" << endl
<<
292 " connected CEC devices." << endl
<<
293 "================================================================================" << endl
;
296 bool ProcessCommandTX(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
298 if (command
== "tx" || command
== "txn")
305 while (GetWord(arguments
, strvalue
) && HexStrToInt(strvalue
, ivalue
))
306 bytes
.PushBack(ivalue
);
308 if (command
== "txn")
309 bytes
.transmit_timeout
= 0;
311 parser
->Transmit(bytes
);
319 bool ProcessCommandON(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
325 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
327 parser
->PowerOnDevices((cec_logical_address
) iValue
);
332 PrintToStdOut("invalid destination");
339 bool ProcessCommandSTANDBY(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
341 if (command
== "standby")
345 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
347 parser
->StandbyDevices((cec_logical_address
) iValue
);
352 PrintToStdOut("invalid destination");
359 bool ProcessCommandPOLL(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
361 if (command
== "poll")
365 if (GetWord(arguments
, strValue
) && HexStrToInt(strValue
, iValue
) && iValue
<= 0xF)
367 if (parser
->PollDevice((cec_logical_address
) iValue
))
368 PrintToStdOut("POLL message sent");
370 PrintToStdOut("POLL message not sent");
375 PrintToStdOut("invalid destination");
382 bool ProcessCommandLA(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
387 if (GetWord(arguments
, strvalue
))
389 parser
->SetLogicalAddress((cec_logical_address
) atoi(strvalue
.c_str()));
397 bool ProcessCommandP(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
401 string strPort
, strDevice
;
402 if (GetWord(arguments
, strDevice
) && GetWord(arguments
, strPort
))
404 parser
->SetHDMIPort((cec_logical_address
)atoi(strDevice
.c_str()), (uint8_t)atoi(strPort
.c_str()));
412 bool ProcessCommandPA(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
418 if (GetWord(arguments
, strB1
) && HexStrToInt(strB1
, iB1
) &&
419 GetWord(arguments
, strB2
) && HexStrToInt(strB2
, iB2
))
421 uint16_t iPhysicalAddress
= ((uint16_t)iB1
<< 8) + iB2
;
422 parser
->SetPhysicalAddress(iPhysicalAddress
);
430 bool ProcessCommandOSD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
432 if (command
== "osd")
434 bool bFirstWord(false);
435 string strAddr
, strMessage
, strWord
;
437 if (GetWord(arguments
, strAddr
) && HexStrToInt(strAddr
, iAddr
) && iAddr
< 0xF)
439 while (GetWord(arguments
, strWord
))
444 strMessage
.append(" ");
446 strMessage
.append(strWord
);
448 parser
->SetOSDString((cec_logical_address
) iAddr
, CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME
, strMessage
.c_str());
456 bool ProcessCommandAS(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
460 parser
->SetActiveView();
468 bool ProcessCommandPING(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
470 if (command
== "ping")
472 parser
->PingAdapter();
479 bool ProcessCommandVOLUP(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
481 if (command
== "volup")
484 strLog
.Format("volume up: %2X", parser
->VolumeUp());
485 PrintToStdOut(strLog
);
492 bool ProcessCommandVOLDOWN(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
494 if (command
== "voldown")
497 strLog
.Format("volume down: %2X", parser
->VolumeDown());
498 PrintToStdOut(strLog
);
505 bool ProcessCommandMUTE(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
507 if (command
== "mute")
510 strLog
.Format("mute: %2X", parser
->MuteAudio());
511 PrintToStdOut(strLog
);
518 bool ProcessCommandMON(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
520 if (command
== "mon")
522 CStdString strEnable
;
523 if (GetWord(arguments
, strEnable
) && (strEnable
.Equals("0") || strEnable
.Equals("1")))
525 parser
->SwitchMonitoring(strEnable
.Equals("1"));
533 bool ProcessCommandBL(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
537 parser
->StartBootloader();
544 bool ProcessCommandLANG(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
546 if (command
== "lang")
549 if (GetWord(arguments
, strDev
))
551 int iDev
= atoi(strDev
);
552 if (iDev
>= 0 && iDev
< 15)
555 cec_menu_language language
;
556 if (parser
->GetDeviceMenuLanguage((cec_logical_address
) iDev
, &language
))
557 strLog
.Format("menu language '%s'", language
.language
);
560 PrintToStdOut(strLog
);
569 bool ProcessCommandVEN(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
571 if (command
== "ven")
574 if (GetWord(arguments
, strDev
))
576 int iDev
= atoi(strDev
);
577 if (iDev
>= 0 && iDev
< 15)
579 uint64_t iVendor
= parser
->GetDeviceVendorId((cec_logical_address
) iDev
);
581 strLog
.Format("vendor id: %06x", iVendor
);
582 PrintToStdOut(strLog
);
591 bool ProcessCommandVER(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
593 if (command
== "ver")
596 if (GetWord(arguments
, strDev
))
598 int iDev
= atoi(strDev
);
599 if (iDev
>= 0 && iDev
< 15)
601 cec_version iVersion
= parser
->GetDeviceCecVersion((cec_logical_address
) iDev
);
603 strLog
.Format("CEC version %s", parser
->ToString(iVersion
));
604 PrintToStdOut(strLog
);
613 bool ProcessCommandPOW(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
615 if (command
== "pow")
618 if (GetWord(arguments
, strDev
))
620 int iDev
= atoi(strDev
);
621 if (iDev
>= 0 && iDev
< 15)
623 cec_power_status iPower
= parser
->GetDevicePowerStatus((cec_logical_address
) iDev
);
625 strLog
.Format("power status: %s", parser
->ToString(iPower
));
626 PrintToStdOut(strLog
);
635 bool ProcessCommandNAME(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
637 if (command
== "name")
640 if (GetWord(arguments
, strDev
))
642 int iDev
= atoi(strDev
);
643 if (iDev
>= 0 && iDev
< 15)
645 cec_osd_name name
= parser
->GetDeviceOSDName((cec_logical_address
)iDev
);
647 strLog
.Format("OSD name of device %d is '%s'", iDev
, name
.name
);
648 PrintToStdOut(strLog
);
657 bool ProcessCommandLAD(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
659 if (command
== "lad")
662 PrintToStdOut("listing active devices:");
663 cec_logical_addresses addresses
= parser
->GetActiveDevices();
664 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
667 strLog
.Format("logical address %X", (int)iPtr
);
668 PrintToStdOut(strLog
);
676 bool ProcessCommandAD(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
681 if (GetWord(arguments
, strDev
))
683 int iDev
= atoi(strDev
);
684 if (iDev
>= 0 && iDev
< 15)
687 strLog
.Format("logical address %X is %s", iDev
, (parser
->IsActiveDevice((cec_logical_address
)iDev
) ? "active" : "not active"));
688 PrintToStdOut(strLog
);
696 bool ProcessCommandAT(ICECAdapter
*parser
, const string
&command
, string
&arguments
)
701 if (GetWord(arguments
, strType
))
703 cec_device_type type
= CEC_DEVICE_TYPE_TV
;
704 if (strType
.Equals("a"))
705 type
= CEC_DEVICE_TYPE_AUDIO_SYSTEM
;
706 else if (strType
.Equals("p"))
707 type
= CEC_DEVICE_TYPE_PLAYBACK_DEVICE
;
708 else if (strType
.Equals("r"))
709 type
= CEC_DEVICE_TYPE_RECORDING_DEVICE
;
710 else if (strType
.Equals("t"))
711 type
= CEC_DEVICE_TYPE_TUNER
;
713 strLog
.Format("device %d is %s", type
, (parser
->IsActiveDeviceType(type
) ? "active" : "not active"));
714 PrintToStdOut(strLog
);
722 bool ProcessCommandR(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
726 PrintToStdOut("closing the connection");
729 PrintToStdOut("opening a new connection");
730 parser
->Open(g_strPort
.c_str());
732 PrintToStdOut("setting active source");
733 parser
->SetActiveSource();
740 bool ProcessCommandH(ICECAdapter
* UNUSED(parser
), const string
&command
, string
& UNUSED(arguments
))
742 if (command
== "h" || command
== "help")
751 bool ProcessCommandLOG(ICECAdapter
* UNUSED(parser
), const string
&command
, string
&arguments
)
753 if (command
== "log")
756 if (GetWord(arguments
, strLevel
))
758 int iNewLevel
= atoi(strLevel
);
759 if (iNewLevel
>= CEC_LOG_ERROR
&& iNewLevel
<= CEC_LOG_ALL
)
761 g_cecLogLevel
= iNewLevel
;
763 strLog
.Format("log level changed to %s", strLevel
.c_str());
764 PrintToStdOut(strLog
);
773 bool ProcessCommandSCAN(ICECAdapter
*parser
, const string
&command
, string
& UNUSED(arguments
))
775 if (command
== "scan")
777 PrintToStdOut("CEC bus information");
778 PrintToStdOut("===================");
779 cec_logical_addresses addresses
= parser
->GetActiveDevices();
780 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
785 uint64_t iVendorId
= parser
->GetDeviceVendorId((cec_logical_address
)iPtr
);
786 bool bActive
= parser
->IsActiveSource((cec_logical_address
)iPtr
);
787 uint16_t iPhysicalAddress
= parser
->GetDevicePhysicalAddress((cec_logical_address
)iPtr
);
788 cec_version iCecVersion
= parser
->GetDeviceCecVersion((cec_logical_address
)iPtr
);
789 cec_power_status power
= parser
->GetDevicePowerStatus((cec_logical_address
)iPtr
);
790 cec_osd_name osdName
= parser
->GetDeviceOSDName((cec_logical_address
)iPtr
);
792 strAddr
.Format("%04x", iPhysicalAddress
);
793 cec_menu_language lang
;
794 lang
.device
= CECDEVICE_UNKNOWN
;
795 parser
->GetDeviceMenuLanguage((cec_logical_address
)iPtr
, &lang
);
797 strLog
.AppendFormat("device #%X: %s\n", (int)iPtr
, parser
->ToString((cec_logical_address
)iPtr
));
798 strLog
.AppendFormat("address: %s\n", strAddr
.c_str());
799 strLog
.AppendFormat("active source: %s\n", (bActive
? "yes" : "no"));
800 strLog
.AppendFormat("vendor: %s\n", parser
->ToString((cec_vendor_id
)iVendorId
));
801 strLog
.AppendFormat("osd string: %s\n", osdName
.name
);
802 strLog
.AppendFormat("CEC version: %s\n", parser
->ToString(iCecVersion
));
803 strLog
.AppendFormat("power status: %s\n", parser
->ToString(power
));
804 if ((uint8_t)lang
.device
== iPtr
)
805 strLog
.AppendFormat("language: %s\n", lang
.language
);
807 PrintToStdOut(strLog
);
816 bool ProcessConsoleCommand(ICECAdapter
*parser
, string
&input
)
821 if (GetWord(input
, command
))
823 if (command
== "q" || command
== "quit")
826 ProcessCommandTX(parser
, command
, input
) ||
827 ProcessCommandON(parser
, command
, input
) ||
828 ProcessCommandSTANDBY(parser
, command
, input
) ||
829 ProcessCommandPOLL(parser
, command
, input
) ||
830 ProcessCommandLA(parser
, command
, input
) ||
831 ProcessCommandP(parser
, command
, input
) ||
832 ProcessCommandPA(parser
, command
, input
) ||
833 ProcessCommandAS(parser
, command
, input
) ||
834 ProcessCommandOSD(parser
, command
, input
) ||
835 ProcessCommandPING(parser
, command
, input
) ||
836 ProcessCommandVOLUP(parser
, command
, input
) ||
837 ProcessCommandVOLDOWN(parser
, command
, input
) ||
838 ProcessCommandMUTE(parser
, command
, input
) ||
839 ProcessCommandMON(parser
, command
, input
) ||
840 ProcessCommandBL(parser
, command
, input
) ||
841 ProcessCommandLANG(parser
, command
, input
) ||
842 ProcessCommandVEN(parser
, command
, input
) ||
843 ProcessCommandVER(parser
, command
, input
) ||
844 ProcessCommandPOW(parser
, command
, input
) ||
845 ProcessCommandNAME(parser
, command
, input
) ||
846 ProcessCommandLAD(parser
, command
, input
) ||
847 ProcessCommandAD(parser
, command
, input
) ||
848 ProcessCommandAT(parser
, command
, input
) ||
849 ProcessCommandR(parser
, command
, input
) ||
850 ProcessCommandH(parser
, command
, input
) ||
851 ProcessCommandLOG(parser
, command
, input
) ||
852 ProcessCommandSCAN(parser
, command
, input
);
858 bool ProcessCommandLineArguments(int argc
, char *argv
[])
862 while (iArgPtr
< argc
&& bReturn
)
864 if (argc
>= iArgPtr
+ 1)
866 if (!strcmp(argv
[iArgPtr
], "-f") ||
867 !strcmp(argv
[iArgPtr
], "--log-file") ||
868 !strcmp(argv
[iArgPtr
], "-sf") ||
869 !strcmp(argv
[iArgPtr
], "--short-log-file"))
871 if (argc
>= iArgPtr
+ 2)
873 g_logOutput
.open(argv
[iArgPtr
+ 1]);
874 g_bShortLog
= (!strcmp(argv
[iArgPtr
], "-sf") || !strcmp(argv
[iArgPtr
], "--short-log-file"));
879 cout
<< "== skipped log-file parameter: no file given ==" << endl
;
883 else if (!strcmp(argv
[iArgPtr
], "-d") ||
884 !strcmp(argv
[iArgPtr
], "--log-level"))
886 if (argc
>= iArgPtr
+ 2)
888 int iNewLevel
= atoi(argv
[iArgPtr
+ 1]);
889 if (iNewLevel
>= CEC_LOG_ERROR
&& iNewLevel
<= CEC_LOG_ALL
)
891 g_cecLogLevel
= iNewLevel
;
892 if (!g_bSingleCommand
)
893 cout
<< "log level set to " << argv
[iArgPtr
+ 1] << endl
;
897 cout
<< "== skipped log-level parameter: invalid level '" << argv
[iArgPtr
+ 1] << "' ==" << endl
;
903 cout
<< "== skipped log-level parameter: no level given ==" << endl
;
907 else if (!strcmp(argv
[iArgPtr
], "-t") ||
908 !strcmp(argv
[iArgPtr
], "--type"))
910 if (argc
>= iArgPtr
+ 2)
912 if (!strcmp(argv
[iArgPtr
+ 1], "p"))
914 if (!g_bSingleCommand
)
915 cout
<< "== using device type 'playback device'" << endl
;
916 g_typeList
.add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
918 else if (!strcmp(argv
[iArgPtr
+ 1], "r"))
920 if (!g_bSingleCommand
)
921 cout
<< "== using device type 'recording device'" << endl
;
922 g_typeList
.add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
924 else if (!strcmp(argv
[iArgPtr
+ 1], "t"))
926 if (!g_bSingleCommand
)
927 cout
<< "== using device type 'tuner'" << endl
;
928 g_typeList
.add(CEC_DEVICE_TYPE_TUNER
);
930 else if (!strcmp(argv
[iArgPtr
+ 1], "a"))
932 if (!g_bSingleCommand
)
933 cout
<< "== using device type 'audio system'" << endl
;
934 g_typeList
.add(CEC_DEVICE_TYPE_AUDIO_SYSTEM
);
938 cout
<< "== skipped invalid device type '" << argv
[iArgPtr
+ 1] << "'" << endl
;
944 else if (!strcmp(argv
[iArgPtr
], "--list-devices") ||
945 !strcmp(argv
[iArgPtr
], "-l"))
947 ICECAdapter
*parser
= CreateParser(g_typeList
);
951 UnloadLibCec(parser
);
956 else if (!strcmp(argv
[iArgPtr
], "--single-command") ||
957 !strcmp(argv
[iArgPtr
], "-s"))
959 g_bSingleCommand
= true;
962 else if (!strcmp(argv
[iArgPtr
], "--help") ||
963 !strcmp(argv
[iArgPtr
], "-h"))
965 ShowHelpCommandLine(argv
[0]);
968 else if (!strcmp(argv
[iArgPtr
], "-b") ||
969 !strcmp(argv
[iArgPtr
], "--base"))
971 if (argc
>= iArgPtr
+ 2)
973 g_iBaseDevice
= (cec_logical_address
)atoi(argv
[iArgPtr
+ 1]);
974 cout
<< "using base device '" << (int)g_iBaseDevice
<< "'" << endl
;
979 else if (!strcmp(argv
[iArgPtr
], "-p") ||
980 !strcmp(argv
[iArgPtr
], "--port"))
982 if (argc
>= iArgPtr
+ 2)
984 g_iHDMIPort
= (int8_t)atoi(argv
[iArgPtr
+ 1]);
985 cout
<< "using HDMI port '" << (int)g_iHDMIPort
<< "'" << endl
;
992 g_strPort
= argv
[iArgPtr
++];
1000 int main (int argc
, char *argv
[])
1004 if (!ProcessCommandLineArguments(argc
, argv
))
1007 if (g_typeList
.IsEmpty())
1009 if (!g_bSingleCommand
)
1010 cout
<< "No device type given. Using 'recording device'" << endl
;
1011 g_typeList
.add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
1014 ICECAdapter
*parser
= LibCecInit("CECTester", g_typeList
);
1015 if (!parser
|| parser
->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION
)
1018 cout
<< "Cannot load libcec.dll" << endl
;
1020 cout
<< "Cannot load libcec.so" << endl
;
1024 UnloadLibCec(parser
);
1029 if (!g_bSingleCommand
)
1032 strLog
.Format("CEC Parser created - libcec version %d.%d", parser
->GetLibVersionMajor(), parser
->GetLibVersionMinor());
1033 cout
<< strLog
.c_str() << endl
;
1035 //make stdin non-blocking
1037 int flags
= fcntl(0, F_GETFL
, 0);
1038 flags
|= O_NONBLOCK
;
1039 fcntl(0, F_SETFL
, flags
);
1043 if (g_strPort
.IsEmpty())
1045 if (!g_bSingleCommand
)
1046 cout
<< "no serial port given. trying autodetect: ";
1047 cec_adapter devices
[10];
1048 uint8_t iDevicesFound
= parser
->FindAdapters(devices
, 10, NULL
);
1049 if (iDevicesFound
<= 0)
1051 if (g_bSingleCommand
)
1052 cout
<< "autodetect ";
1053 cout
<< "FAILED" << endl
;
1054 UnloadLibCec(parser
);
1059 if (!g_bSingleCommand
)
1061 cout
<< endl
<< " path: " << devices
[0].path
<< endl
<<
1062 " com port: " << devices
[0].comm
<< endl
<< endl
;
1064 g_strPort
= devices
[0].comm
;
1068 EnableCallbacks(parser
);
1070 parser
->SetHDMIPort(g_iBaseDevice
, g_iHDMIPort
);
1071 PrintToStdOut("opening a connection to the CEC adapter...");
1073 if (!parser
->Open(g_strPort
.c_str()))
1076 strLog
.Format("unable to open the device on port %s");
1077 PrintToStdOut(strLog
);
1078 UnloadLibCec(parser
);
1082 if (!g_bSingleCommand
)
1084 PrintToStdOut("cec device opened");
1086 parser
->PowerOnDevices(CECDEVICE_TV
);
1087 parser
->SetActiveSource();
1089 PrintToStdOut("waiting for input");
1092 bool bContinue(true);
1096 getline(cin
, input
);
1099 if (ProcessConsoleCommand(parser
, input
) && !g_bSingleCommand
)
1102 PrintToStdOut("waiting for input");
1108 CCondition::Sleep(50);
1111 if (!g_bSingleCommand
)
1112 parser
->StandbyDevices(CECDEVICE_BROADCAST
);
1115 UnloadLibCec(parser
);
1117 if (g_logOutput
.is_open())
1118 g_logOutput
.close();