+ return false;
+}
+
+
+bool ProcessCommandPING(ICECAdapter *parser, const string &command, string & UNUSED(arguments))
+{
+ if (command == "ping")
+ {
+ parser->PingAdapter();
+ return true;
+ }
+
+ return false;
+}
+
+bool ProcessCommandVOLUP(ICECAdapter *parser, const string &command, string & UNUSED(arguments))
+{
+ if (command == "volup")
+ {
+ PrintToStdOut("volume up: %2X", parser->VolumeUp());
+ return true;
+ }
+
+ return false;
+}
+
+bool ProcessCommandVOLDOWN(ICECAdapter *parser, const string &command, string & UNUSED(arguments))
+{
+ if (command == "voldown")
+ {
+ PrintToStdOut("volume down: %2X", parser->VolumeDown());
+ return true;
+ }
+
+ return false;
+}
+
+bool ProcessCommandMUTE(ICECAdapter *parser, const string &command, string & UNUSED(arguments))
+{
+ if (command == "mute")
+ {
+ PrintToStdOut("mute: %2X", parser->MuteAudio());
+ return true;
+ }
+
+ return false;
+}
+
+bool ProcessCommandMON(ICECAdapter *parser, const string &command, string &arguments)
+{
+ if (command == "mon")
+ {
+ CStdString strEnable;
+ if (GetWord(arguments, strEnable) && (strEnable.Equals("0") || strEnable.Equals("1")))
+ {
+ parser->SwitchMonitoring(strEnable.Equals("1"));
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool ProcessCommandBL(ICECAdapter *parser, const string &command, string & UNUSED(arguments))
+{
+ if (command == "bl")
+ {
+ if (parser->StartBootloader())
+ {
+ PrintToStdOut("entered bootloader mode. exiting cec-client");
+ g_bExit = true;
+ g_bHardExit = true;
+ }
+ return true;
+ }
+
+ return false;
+}
+
+bool ProcessCommandLANG(ICECAdapter *parser, const string &command, string &arguments)
+{
+ if (command == "lang")
+ {
+ CStdString strDev;
+ if (GetWord(arguments, strDev))
+ {
+ int iDev = atoi(strDev);
+ if (iDev >= 0 && iDev < 15)
+ {
+ CStdString strLog;
+ cec_menu_language language;
+ if (parser->GetDeviceMenuLanguage((cec_logical_address) iDev, &language))
+ strLog.Format("menu language '%s'", language.language);
+ else
+ strLog = "failed!";
+ PrintToStdOut(strLog);
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool ProcessCommandVEN(ICECAdapter *parser, const string &command, string &arguments)
+{
+ if (command == "ven")
+ {
+ CStdString strDev;
+ if (GetWord(arguments, strDev))
+ {
+ int iDev = atoi(strDev);
+ if (iDev >= 0 && iDev < 15)
+ {
+ uint64_t iVendor = parser->GetDeviceVendorId((cec_logical_address) iDev);
+ PrintToStdOut("vendor id: %06x", iVendor);
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool ProcessCommandVER(ICECAdapter *parser, const string &command, string &arguments)
+{
+ if (command == "ver")
+ {
+ CStdString strDev;
+ if (GetWord(arguments, strDev))
+ {
+ int iDev = atoi(strDev);
+ if (iDev >= 0 && iDev < 15)
+ {
+ cec_version iVersion = parser->GetDeviceCecVersion((cec_logical_address) iDev);
+ PrintToStdOut("CEC version %s", parser->ToString(iVersion));
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool ProcessCommandPOW(ICECAdapter *parser, const string &command, string &arguments)
+{
+ if (command == "pow")
+ {
+ CStdString strDev;
+ if (GetWord(arguments, strDev))
+ {
+ int iDev = atoi(strDev);
+ if (iDev >= 0 && iDev < 15)
+ {
+ cec_power_status iPower = parser->GetDevicePowerStatus((cec_logical_address) iDev);
+ PrintToStdOut("power status: %s", parser->ToString(iPower));
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool ProcessCommandNAME(ICECAdapter *parser, const string &command, string &arguments)
+{
+ if (command == "name")
+ {
+ CStdString strDev;
+ if (GetWord(arguments, strDev))
+ {
+ int iDev = atoi(strDev);
+ if (iDev >= 0 && iDev < 15)
+ {
+ cec_osd_name name = parser->GetDeviceOSDName((cec_logical_address)iDev);
+ PrintToStdOut("OSD name of device %d is '%s'", iDev, name.name);
+ }
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool ProcessCommandLAD(ICECAdapter *parser, const string &command, string & UNUSED(arguments))
+{
+ if (command == "lad")
+ {
+ PrintToStdOut("listing active devices:");
+ cec_logical_addresses addresses = parser->GetActiveDevices();
+ for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
+ if (addresses[iPtr])
+ {
+ PrintToStdOut("logical address %X", (int)iPtr);
+ }
+ return true;
+ }
+
+ return false;
+}
+
+bool ProcessCommandAD(ICECAdapter *parser, const string &command, string &arguments)
+{
+ if (command == "ad")
+ {
+ CStdString strDev;
+ if (GetWord(arguments, strDev))
+ {
+ int iDev = atoi(strDev);
+ if (iDev >= 0 && iDev < 15)
+ PrintToStdOut("logical address %X is %s", iDev, (parser->IsActiveDevice((cec_logical_address)iDev) ? "active" : "not active"));
+ }
+ }
+
+ return false;
+}
+
+bool ProcessCommandAT(ICECAdapter *parser, const string &command, string &arguments)
+{
+ if (command == "at")
+ {
+ CStdString strType;
+ if (GetWord(arguments, strType))
+ {
+ cec_device_type type = CEC_DEVICE_TYPE_TV;
+ if (strType.Equals("a"))
+ type = CEC_DEVICE_TYPE_AUDIO_SYSTEM;
+ else if (strType.Equals("p"))
+ type = CEC_DEVICE_TYPE_PLAYBACK_DEVICE;
+ else if (strType.Equals("r"))
+ type = CEC_DEVICE_TYPE_RECORDING_DEVICE;
+ else if (strType.Equals("t"))
+ type = CEC_DEVICE_TYPE_TUNER;
+
+ PrintToStdOut("device %d is %s", type, (parser->IsActiveDeviceType(type) ? "active" : "not active"));
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool ProcessCommandR(ICECAdapter *parser, const string &command, string & UNUSED(arguments))
+{
+ if (command == "r")
+ {
+ bool bReactivate = parser->IsLibCECActiveSource();
+
+ PrintToStdOut("closing the connection");
+ parser->Close();
+
+ PrintToStdOut("opening a new connection");
+ parser->Open(g_strPort.c_str());
+
+ if (bReactivate)
+ {
+ PrintToStdOut("setting active source");
+ parser->SetActiveSource();
+ }
+ return true;
+ }
+
+ return false;
+}
+
+bool ProcessCommandH(ICECAdapter * UNUSED(parser), const string &command, string & UNUSED(arguments))
+{
+ if (command == "h" || command == "help")
+ {
+ ShowHelpConsole();
+ return true;
+ }
+
+ return false;
+}
+
+bool ProcessCommandLOG(ICECAdapter * UNUSED(parser), const string &command, string &arguments)
+{
+ if (command == "log")
+ {
+ CStdString strLevel;
+ if (GetWord(arguments, strLevel))
+ {
+ int iNewLevel = atoi(strLevel);
+ if (iNewLevel >= CEC_LOG_ERROR && iNewLevel <= CEC_LOG_ALL)
+ {
+ g_cecLogLevel = iNewLevel;
+
+ PrintToStdOut("log level changed to %s", strLevel.c_str());
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool ProcessCommandSCAN(ICECAdapter *parser, const string &command, string & UNUSED(arguments))
+{
+ if (command == "scan")
+ {
+ CStdString strLog;
+ PrintToStdOut("requesting CEC bus information ...");
+
+ strLog.append("CEC bus information\n===================\n");
+ cec_logical_addresses addresses = parser->GetActiveDevices();
+ for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+ {
+ if (addresses[iPtr])
+ {
+ uint64_t iVendorId = parser->GetDeviceVendorId((cec_logical_address)iPtr);
+ bool bActive = parser->IsActiveSource((cec_logical_address)iPtr);
+ uint16_t iPhysicalAddress = parser->GetDevicePhysicalAddress((cec_logical_address)iPtr);
+ cec_version iCecVersion = parser->GetDeviceCecVersion((cec_logical_address)iPtr);
+ cec_power_status power = parser->GetDevicePowerStatus((cec_logical_address)iPtr);
+ cec_osd_name osdName = parser->GetDeviceOSDName((cec_logical_address)iPtr);
+ CStdString strAddr;
+ strAddr.Format("%04x", iPhysicalAddress);
+ cec_menu_language lang;
+ lang.device = CECDEVICE_UNKNOWN;
+ parser->GetDeviceMenuLanguage((cec_logical_address)iPtr, &lang);
+
+ strLog.AppendFormat("device #%X: %s\n", (int)iPtr, parser->ToString((cec_logical_address)iPtr));
+ strLog.AppendFormat("address: %s\n", strAddr.c_str());
+ strLog.AppendFormat("active source: %s\n", (bActive ? "yes" : "no"));
+ strLog.AppendFormat("vendor: %s\n", parser->ToString((cec_vendor_id)iVendorId));
+ strLog.AppendFormat("osd string: %s\n", osdName.name);
+ strLog.AppendFormat("CEC version: %s\n", parser->ToString(iCecVersion));
+ strLog.AppendFormat("power status: %s\n", parser->ToString(power));
+ if ((uint8_t)lang.device == iPtr)
+ strLog.AppendFormat("language: %s\n", lang.language);
+ strLog.append("\n\n");
+ }
+ }
+
+ cec_logical_address activeSource = parser->GetActiveSource();
+ strLog.AppendFormat("currently active source: %s (%d)", parser->ToString(activeSource), (int)activeSource);
+
+ PrintToStdOut(strLog);
+ return true;
+ }
+
+ return false;
+}
+
+bool ProcessConsoleCommand(ICECAdapter *parser, string &input)
+{
+ if (!input.empty())
+ {
+ string command;
+ if (GetWord(input, command))
+ {
+ if (command == "q" || command == "quit")
+ return false;
+
+ ProcessCommandTX(parser, command, input) ||
+ ProcessCommandON(parser, command, input) ||
+ ProcessCommandSTANDBY(parser, command, input) ||
+ ProcessCommandPOLL(parser, command, input) ||
+ ProcessCommandLA(parser, command, input) ||
+ ProcessCommandP(parser, command, input) ||
+ ProcessCommandPA(parser, command, input) ||
+ ProcessCommandAS(parser, command, input) ||
+ ProcessCommandOSD(parser, command, input) ||
+ ProcessCommandPING(parser, command, input) ||
+ ProcessCommandVOLUP(parser, command, input) ||
+ ProcessCommandVOLDOWN(parser, command, input) ||
+ ProcessCommandMUTE(parser, command, input) ||
+ ProcessCommandMON(parser, command, input) ||
+ ProcessCommandBL(parser, command, input) ||
+ ProcessCommandLANG(parser, command, input) ||
+ ProcessCommandVEN(parser, command, input) ||
+ ProcessCommandVER(parser, command, input) ||
+ ProcessCommandPOW(parser, command, input) ||
+ ProcessCommandNAME(parser, command, input) ||
+ ProcessCommandLAD(parser, command, input) ||
+ ProcessCommandAD(parser, command, input) ||
+ ProcessCommandAT(parser, command, input) ||
+ ProcessCommandR(parser, command, input) ||
+ ProcessCommandH(parser, command, input) ||
+ ProcessCommandLOG(parser, command, input) ||
+ ProcessCommandSCAN(parser, command, input) ||
+ ProcessCommandSP(parser, command, input) ||
+ ProcessCommandSPL(parser, command, input) ||
+ ProcessCommandSELF(parser, command, input);
+ }
+ }
+ return true;
+}
+
+bool ProcessCommandLineArguments(int argc, char *argv[])
+{
+ bool bReturn(true);
+ int iArgPtr = 1;
+ while (iArgPtr < argc && bReturn)
+ {
+ if (argc >= iArgPtr + 1)
+ {
+ if (!strcmp(argv[iArgPtr], "-f") ||
+ !strcmp(argv[iArgPtr], "--log-file") ||
+ !strcmp(argv[iArgPtr], "-sf") ||
+ !strcmp(argv[iArgPtr], "--short-log-file"))
+ {
+ if (argc >= iArgPtr + 2)