Stephane@161: /* Stephane@161: * This file is part of the libCEC(R) library. Stephane@161: * Stephane@161: * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved. Stephane@161: * libCEC(R) is an original work, containing original code. Stephane@161: * Stephane@161: * libCEC(R) is a trademark of Pulse-Eight Limited. Stephane@161: * Stephane@161: * This program is dual-licensed; you can redistribute it and/or modify Stephane@161: * it under the terms of the GNU General Public License as published by Stephane@161: * the Free Software Foundation; either version 2 of the License, or Stephane@161: * (at your option) any later version. Stephane@161: * Stephane@161: * This program is distributed in the hope that it will be useful, Stephane@161: * but WITHOUT ANY WARRANTY; without even the implied warranty of Stephane@161: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Stephane@161: * GNU General Public License for more details. Stephane@161: * Stephane@161: * You should have received a copy of the GNU General Public License Stephane@161: * along with this program; if not, write to the Free Software Stephane@161: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Stephane@161: * Stephane@161: * Stephane@161: * Alternatively, you can license this library under a commercial license, Stephane@161: * please contact Pulse-Eight Licensing for more information. Stephane@161: * Stephane@161: * For more information contact: Stephane@161: * Pulse-Eight Licensing Stephane@161: * http://www.pulse-eight.com/ Stephane@161: * http://www.pulse-eight.net/ Stephane@161: */ Stephane@161: Stephane@161: using System; Stephane@161: using System.Text; Stephane@161: using CecSharp; Stephane@202: using System.Threading; Stephane@161: Stephane@161: namespace Cec Stephane@161: { Stephane@161: class Client : CecCallbackMethods Stephane@161: { StephaneLenclud@167: /// StephaneLenclud@214: /// Enable public static access StephaneLenclud@214: /// StephaneLenclud@214: public static Client Static; StephaneLenclud@214: StephaneLenclud@214: /// StephaneLenclud@206: /// Provide direct access to CEC library StephaneLenclud@206: /// StephaneLenclud@206: public LibCecSharp Lib StephaneLenclud@206: { StephaneLenclud@206: get StephaneLenclud@206: { StephaneLenclud@206: return iLib; StephaneLenclud@206: } StephaneLenclud@206: } StephaneLenclud@206: StephaneLenclud@206: /// StephaneLenclud@206: /// StephaneLenclud@206: /// StephaneLenclud@206: public int LogLevel = (int)CecLogLevel.Notice; StephaneLenclud@206: StephaneLenclud@206: /// StephaneLenclud@206: /// StephaneLenclud@206: /// StephaneLenclud@206: public bool FilterOutPollLogs = true; StephaneLenclud@206: StephaneLenclud@206: /// StephaneLenclud@206: /// StephaneLenclud@206: /// StephaneLenclud@206: private LibCecSharp iLib; StephaneLenclud@206: /// StephaneLenclud@206: /// StephaneLenclud@206: /// StephaneLenclud@206: private LibCECConfiguration Config; StephaneLenclud@206: StephaneLenclud@206: /// StephaneLenclud@206: /// StephaneLenclud@206: /// StephaneLenclud@206: private bool iConnected; StephaneLenclud@206: StephaneLenclud@206: /// StephaneLenclud@167: /// StephaneLenclud@167: /// StephaneLenclud@167: /// StephaneLenclud@167: /// StephaneLenclud@206: public Client(string aDeviceName, byte aHdmiPort, CecDeviceType aDeviceType = CecDeviceType.PlaybackDevice) Stephane@161: { Stephane@161: Config = new LibCECConfiguration(); Stephane@203: Config.DeviceTypes.Types[0] = aDeviceType; StephaneLenclud@167: Config.DeviceName = aDeviceName; StephaneLenclud@167: Config.HDMIPort = aHdmiPort; Stephane@161: //Config.ClientVersion = LibCECConfiguration.CurrentVersion; Stephane@161: Config.SetCallbacks(this); Stephane@161: StephaneLenclud@167: iLib = new LibCecSharp(Config); StephaneLenclud@167: iLib.InitVideoStandalone(); Stephane@161: StephaneLenclud@214: if (Static != null) StephaneLenclud@214: { StephaneLenclud@214: Console.WriteLine("WARNING: CEC client static already exists"); StephaneLenclud@214: } StephaneLenclud@214: else StephaneLenclud@214: { StephaneLenclud@214: Static = this; StephaneLenclud@214: } StephaneLenclud@214: StephaneLenclud@214: Stephane@161: //Console.WriteLine("CEC Parser created - libCEC version " + Lib.VersionToString(Config.ServerVersion)); StephaneLenclud@214: Console.WriteLine("INFO: CEC Parser created - libCEC version " + Config.ServerVersion); Stephane@161: } Stephane@161: Stephane@200: StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: /// Stephane@202: public override int ReceiveAlert(CecAlert alert, CecParameter data) Stephane@200: { StephaneLenclud@201: string log = "CEC alert: " + alert.ToString(); StephaneLenclud@201: if (data != null && data.Type == CecParameterType.ParameterTypeString) StephaneLenclud@201: { StephaneLenclud@201: log += " " + data.Data; StephaneLenclud@201: } StephaneLenclud@201: StephaneLenclud@201: Console.WriteLine(log); StephaneLenclud@201: StephaneLenclud@201: Close(); StephaneLenclud@201: //Try reconnect StephaneLenclud@214: Open(1000); Stephane@200: return 1; Stephane@200: } Stephane@200: StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: /// Stephane@202: public override int ReceiveMenuStateChange(CecMenuState newVal) Stephane@200: { StephaneLenclud@201: Console.WriteLine("CEC menu state changed to: " + iLib.ToString(newVal)); Stephane@200: return 1; Stephane@200: } Stephane@200: StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: /// Stephane@202: public override void SourceActivated(CecLogicalAddress logicalAddress, bool activated) Stephane@200: { StephaneLenclud@201: Console.WriteLine("CEC source activated: " + iLib.ToString(logicalAddress) + "/" + activated.ToString() ); Stephane@200: return; Stephane@200: } Stephane@200: Stephane@161: public override int ReceiveCommand(CecCommand command) Stephane@161: { Stephane@207: Console.WriteLine(string.Format("CEC command '{5}' from {0} to {1} - Ack: {2} Eom: {3} OpcodeSet: {4} Timeout: {6}", StephaneLenclud@201: iLib.ToString(command.Initiator), StephaneLenclud@201: iLib.ToString(command.Destination), StephaneLenclud@201: command.Ack.ToString(), StephaneLenclud@201: command.Eom.ToString(), StephaneLenclud@201: command.OpcodeSet.ToString(), StephaneLenclud@201: iLib.ToString(command.Opcode), StephaneLenclud@201: command.TransmitTimeout.ToString() StephaneLenclud@201: )); Stephane@161: return 1; Stephane@161: } Stephane@161: Stephane@161: public override int ReceiveKeypress(CecKeypress key) Stephane@161: { StephaneLenclud@201: Console.WriteLine(string.Format("CEC keypress: {0} Duration:{1} Empty: {2}", StephaneLenclud@201: key.Keycode.ToString(), key.Duration.ToString(), key.Empty.ToString())); Stephane@161: return 1; Stephane@161: } Stephane@161: Stephane@161: public override int ReceiveLogMessage(CecLogMessage message) Stephane@161: { Stephane@161: if (((int)message.Level & LogLevel) == (int)message.Level) Stephane@161: { Stephane@161: string strLevel = ""; Stephane@161: switch (message.Level) Stephane@161: { Stephane@161: case CecLogLevel.Error: Stephane@202: strLevel = "ERROR: "; Stephane@161: break; Stephane@161: case CecLogLevel.Warning: Stephane@161: strLevel = "WARNING: "; Stephane@161: break; Stephane@161: case CecLogLevel.Notice: Stephane@202: strLevel = "NOTICE: "; Stephane@161: break; Stephane@161: case CecLogLevel.Traffic: Stephane@161: strLevel = "TRAFFIC: "; Stephane@161: break; Stephane@161: case CecLogLevel.Debug: Stephane@202: strLevel = "DEBUG: "; StephaneLenclud@206: if (message.Message.IndexOf("POLL") != -1 && FilterOutPollLogs) StephaneLenclud@206: { StephaneLenclud@206: //We have an option to prevent spamming with poll debug logs StephaneLenclud@206: return 1; StephaneLenclud@206: } Stephane@161: break; Stephane@161: default: Stephane@161: break; Stephane@161: } Stephane@202: string strLog = string.Format("{0} {1} {2}", strLevel, message.Time, message.Message); Stephane@161: Console.WriteLine(strLog); StephaneLenclud@201: Stephane@161: } Stephane@161: return 1; Stephane@161: } Stephane@161: Stephane@161: /// Stephane@161: /// Stephane@161: /// Stephane@161: /// Stephane@161: /// StephaneLenclud@214: public bool Open(int timeout) Stephane@161: { StephaneLenclud@201: Close(); StephaneLenclud@167: CecAdapter[] adapters = iLib.FindAdapters(string.Empty); Stephane@161: if (adapters.Length > 0) StephaneLenclud@201: { StephaneLenclud@214: Open(adapters[0].ComPort, timeout); StephaneLenclud@201: } Stephane@161: else Stephane@161: { StephaneLenclud@201: Console.WriteLine("CEC did not find any adapters"); Stephane@161: } StephaneLenclud@201: StephaneLenclud@201: return iConnected; Stephane@161: } Stephane@161: StephaneLenclud@214: public bool Open(string port, int timeout) Stephane@161: { StephaneLenclud@201: Close(); StephaneLenclud@201: iConnected = iLib.Open(port, timeout); StephaneLenclud@201: return iConnected; Stephane@161: } Stephane@161: Stephane@161: public void Close() StephaneLenclud@201: { StephaneLenclud@167: iLib.Close(); StephaneLenclud@201: iConnected = false; Stephane@161: } Stephane@161: Stephane@202: Stephane@202: public void TestSendKey() Stephane@202: { Stephane@202: //SetupMenu: opens option menu Stephane@202: //RootMenu: opens Android home menu Stephane@202: //ContentsMenu: nop Stephane@202: //FavoriteMenu: nop Stephane@202: Stephane@202: //Philips TopMenu = 16 Stephane@202: //Philips PopupMenu = 17 Stephane@202: Stephane@202: //bool res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.DisplayInformation, true); Stephane@202: //Thread.Sleep(3000); //Wait few seconds for menu to open Stephane@202: //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.SetupMenu, true); Stephane@202: Stephane@202: for (int i = 0; i < 256; i++) Stephane@202: { Stephane@202: //Thread.Sleep(100); Stephane@202: //res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true); Stephane@202: //Thread.Sleep(100); Stephane@202: switch ((CecUserControlCode)i) Stephane@202: { Stephane@202: case CecUserControlCode.Power: Stephane@202: case CecUserControlCode.PowerOffFunction: Stephane@202: case CecUserControlCode.PowerOnFunction: Stephane@202: case CecUserControlCode.PowerToggleFunction: Stephane@202: case CecUserControlCode.ElectronicProgramGuide: Stephane@202: case CecUserControlCode.InputSelect: Stephane@202: case CecUserControlCode.RootMenu: Stephane@202: Stephane@202: break; Stephane@202: Stephane@202: default: Stephane@202: Console.WriteLine(i.ToString()); Stephane@202: Thread.Sleep(1000); Stephane@202: iLib.SendKeypress(CecLogicalAddress.Tv, (CecUserControlCode)i, true); Stephane@202: Stephane@202: break; Stephane@202: Stephane@202: } Stephane@202: Stephane@202: // Stephane@202: } Stephane@202: Stephane@202: Stephane@202: for (int i=0;i<7;i++) Stephane@202: { Stephane@202: //Thread.Sleep(100); Stephane@202: //res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true); Stephane@202: //Thread.Sleep(100); Stephane@202: //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Down, true); Stephane@202: // Stephane@202: } Stephane@202: Stephane@202: //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Select, true); Stephane@202: Stephane@202: //res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Select, true); Stephane@202: //res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true); Stephane@202: } Stephane@202: StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: /// StephaneLenclud@201: public void Scan() StephaneLenclud@201: { Stephane@207: string scanRes = ""; Stephane@207: scanRes += "CEC bus information\n"; Stephane@207: scanRes += "===================\n"; StephaneLenclud@201: CecLogicalAddresses addresses = Lib.GetActiveDevices(); StephaneLenclud@201: for (int iPtr = 0; iPtr < addresses.Addresses.Length; iPtr++) StephaneLenclud@201: { StephaneLenclud@201: CecLogicalAddress address = (CecLogicalAddress) iPtr; StephaneLenclud@201: if (!addresses.IsSet(address)) StephaneLenclud@201: continue; StephaneLenclud@201: StephaneLenclud@201: CecVendorId iVendorId = Lib.GetDeviceVendorId(address); StephaneLenclud@201: bool bActive = Lib.IsActiveDevice(address); StephaneLenclud@201: ushort iPhysicalAddress = Lib.GetDevicePhysicalAddress(address); StephaneLenclud@201: string strAddr = Lib.PhysicalAddressToString(iPhysicalAddress); StephaneLenclud@201: CecVersion iCecVersion = Lib.GetDeviceCecVersion(address); StephaneLenclud@201: CecPowerStatus power = Lib.GetDevicePowerStatus(address); StephaneLenclud@201: string osdName = Lib.GetDeviceOSDName(address); StephaneLenclud@201: string lang = Lib.GetDeviceMenuLanguage(address); StephaneLenclud@201: Stephane@207: scanRes += "device #" + iPtr + ": " + Lib.ToString(address) + "\n"; Stephane@207: scanRes += "address: " + strAddr + "\n"; Stephane@207: scanRes += "active source: " + (bActive ? "yes" : "no") + "\n"; Stephane@207: scanRes += "vendor: " + Lib.ToString(iVendorId) + "\n"; Stephane@207: scanRes += "osd string: " + osdName + "\n"; Stephane@207: scanRes += "CEC version: " + Lib.ToString(iCecVersion) + "\n"; Stephane@207: scanRes += "power status: " + Lib.ToString(power) + "\n"; StephaneLenclud@201: if (!string.IsNullOrEmpty(lang)) Stephane@207: scanRes += "language: " + lang + "\n"; Stephane@207: scanRes += "===================" + "\n"; StephaneLenclud@201: } Stephane@207: Stephane@207: Console.Write(scanRes); StephaneLenclud@201: } StephaneLenclud@201: StephaneLenclud@201: public void ListAdapters() Stephane@161: { Stephane@161: int iAdapter = 0; StephaneLenclud@167: foreach (CecAdapter adapter in iLib.FindAdapters(string.Empty)) Stephane@161: { Stephane@161: Console.WriteLine("Adapter: " + iAdapter++); Stephane@161: Console.WriteLine("Path: " + adapter.Path); Stephane@161: Console.WriteLine("Com port: " + adapter.ComPort); Stephane@161: } Stephane@161: } Stephane@161: Stephane@161: void ShowConsoleHelp() Stephane@161: { Stephane@161: Console.WriteLine( Stephane@161: "================================================================================" + Environment.NewLine + Stephane@161: "Available commands:" + Environment.NewLine + Stephane@161: Environment.NewLine + Stephane@161: "[tx] {bytes} transfer bytes over the CEC line." + Environment.NewLine + Stephane@161: "[txn] {bytes} transfer bytes but don't wait for transmission ACK." + Environment.NewLine + Stephane@161: "[on] {address} power on the device with the given logical address." + Environment.NewLine + Stephane@161: "[standby] {address} put the device with the given address in standby mode." + Environment.NewLine + Stephane@161: "[la] {logical_address} change the logical address of the CEC adapter." + Environment.NewLine + Stephane@161: "[pa] {physical_address} change the physical address of the CEC adapter." + Environment.NewLine + Stephane@161: "[osd] {addr} {string} set OSD message on the specified device." + Environment.NewLine + Stephane@161: "[ver] {addr} get the CEC version of the specified device." + Environment.NewLine + Stephane@161: "[ven] {addr} get the vendor ID of the specified device." + Environment.NewLine + Stephane@161: "[lang] {addr} get the menu language of the specified device." + Environment.NewLine + Stephane@161: "[pow] {addr} get the power status of the specified device." + Environment.NewLine + Stephane@161: "[poll] {addr} poll the specified device." + Environment.NewLine + Stephane@161: "[scan] scan the CEC bus and display device info" + Environment.NewLine + Stephane@161: "[mon] {1|0} enable or disable CEC bus monitoring." + Environment.NewLine + Stephane@161: "[log] {1 - 31} change the log level. see cectypes.h for values." + Environment.NewLine + Stephane@161: "[ping] send a ping command to the CEC adapter." + Environment.NewLine + Stephane@161: "[bl] to let the adapter enter the bootloader, to upgrade" + Environment.NewLine + Stephane@161: " the flash rom." + Environment.NewLine + Stephane@161: "[r] reconnect to the CEC adapter." + Environment.NewLine + Stephane@161: "[h] or [help] show this help." + Environment.NewLine + Stephane@161: "[q] or [quit] to quit the CEC test client and switch off all" + Environment.NewLine + Stephane@161: " connected CEC devices." + Environment.NewLine + Stephane@161: "================================================================================"); Stephane@161: } Stephane@161: Stephane@161: public void MainLoop() Stephane@161: { Stephane@161: bool bContinue = true; Stephane@161: string command; Stephane@161: while (bContinue) Stephane@161: { Stephane@161: Console.WriteLine("waiting for input"); Stephane@161: Stephane@161: command = Console.ReadLine(); Stephane@161: if (command != null && command.Length == 0) Stephane@161: continue; Stephane@161: string[] splitCommand = command.Split(' '); Stephane@161: if (splitCommand[0] == "tx" || splitCommand[0] == "txn") Stephane@161: { Stephane@161: CecCommand bytes = new CecCommand(); Stephane@161: for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) Stephane@161: { Stephane@161: bytes.PushBack(byte.Parse(splitCommand[iPtr], System.Globalization.NumberStyles.HexNumber)); Stephane@161: } Stephane@161: Stephane@161: if (command == "txn") Stephane@161: bytes.TransmitTimeout = 0; Stephane@161: StephaneLenclud@167: iLib.Transmit(bytes); Stephane@161: } Stephane@161: else if (splitCommand[0] == "on") Stephane@161: { Stephane@161: if (splitCommand.Length > 1) StephaneLenclud@167: iLib.PowerOnDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Stephane@161: else StephaneLenclud@167: iLib.PowerOnDevices(CecLogicalAddress.Broadcast); Stephane@161: } Stephane@161: else if (splitCommand[0] == "standby") Stephane@161: { Stephane@161: if (splitCommand.Length > 1) StephaneLenclud@167: iLib.StandbyDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Stephane@161: else StephaneLenclud@167: iLib.StandbyDevices(CecLogicalAddress.Broadcast); Stephane@161: } Stephane@161: else if (splitCommand[0] == "poll") Stephane@161: { Stephane@161: bool bSent = false; Stephane@161: if (splitCommand.Length > 1) StephaneLenclud@167: bSent = iLib.PollDevice((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Stephane@161: else StephaneLenclud@167: bSent = iLib.PollDevice(CecLogicalAddress.Broadcast); Stephane@161: if (bSent) Stephane@161: Console.WriteLine("POLL message sent"); Stephane@161: else Stephane@161: Console.WriteLine("POLL message not sent"); Stephane@161: } Stephane@161: else if (splitCommand[0] == "la") Stephane@161: { Stephane@161: if (splitCommand.Length > 1) StephaneLenclud@167: iLib.SetLogicalAddress((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Stephane@161: } Stephane@161: else if (splitCommand[0] == "pa") Stephane@161: { Stephane@161: if (splitCommand.Length > 1) StephaneLenclud@167: iLib.SetPhysicalAddress(ushort.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Stephane@161: } Stephane@161: else if (splitCommand[0] == "osd") Stephane@161: { Stephane@161: if (splitCommand.Length > 2) Stephane@161: { Stephane@161: StringBuilder osdString = new StringBuilder(); Stephane@161: for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) Stephane@161: { Stephane@161: osdString.Append(splitCommand[iPtr]); Stephane@161: if (iPtr != splitCommand.Length - 1) Stephane@161: osdString.Append(" "); Stephane@161: } StephaneLenclud@167: iLib.SetOSDString((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber), CecDisplayControl.DisplayForDefaultTime, osdString.ToString()); Stephane@161: } Stephane@161: } Stephane@161: else if (splitCommand[0] == "ping") Stephane@161: { StephaneLenclud@167: iLib.PingAdapter(); Stephane@161: } Stephane@161: else if (splitCommand[0] == "mon") Stephane@161: { Stephane@161: bool enable = splitCommand.Length > 1 ? splitCommand[1] == "1" : false; StephaneLenclud@167: iLib.SwitchMonitoring(enable); Stephane@161: } Stephane@161: else if (splitCommand[0] == "bl") Stephane@161: { StephaneLenclud@167: iLib.StartBootloader(); Stephane@161: } Stephane@161: else if (splitCommand[0] == "lang") Stephane@161: { Stephane@161: if (splitCommand.Length > 1) Stephane@161: { StephaneLenclud@167: string language = iLib.GetDeviceMenuLanguage((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Stephane@161: Console.WriteLine("Menu language: " + language); Stephane@161: } Stephane@161: } Stephane@161: else if (splitCommand[0] == "ven") Stephane@161: { Stephane@161: if (splitCommand.Length > 1) Stephane@161: { StephaneLenclud@167: CecVendorId vendor = iLib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); StephaneLenclud@167: Console.WriteLine("Vendor ID: " + iLib.ToString(vendor)); Stephane@161: } Stephane@161: } Stephane@161: else if (splitCommand[0] == "ver") Stephane@161: { Stephane@161: if (splitCommand.Length > 1) Stephane@161: { StephaneLenclud@167: CecVersion version = iLib.GetDeviceCecVersion((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); StephaneLenclud@167: Console.WriteLine("CEC version: " + iLib.ToString(version)); Stephane@161: } Stephane@161: } Stephane@161: else if (splitCommand[0] == "pow") Stephane@161: { Stephane@161: if (splitCommand.Length > 1) Stephane@161: { StephaneLenclud@167: CecPowerStatus power = iLib.GetDevicePowerStatus((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); StephaneLenclud@167: Console.WriteLine("power status: " + iLib.ToString(power)); Stephane@161: } Stephane@161: } Stephane@161: else if (splitCommand[0] == "r") Stephane@161: { Stephane@161: Console.WriteLine("closing the connection"); StephaneLenclud@167: iLib.Close(); Stephane@161: Stephane@161: Console.WriteLine("opening a new connection"); StephaneLenclud@214: Open(10000); Stephane@161: Stephane@161: Console.WriteLine("setting active source"); StephaneLenclud@167: iLib.SetActiveSource(CecDeviceType.PlaybackDevice); Stephane@161: } Stephane@161: else if (splitCommand[0] == "scan") Stephane@161: { Stephane@161: StringBuilder output = new StringBuilder(); Stephane@161: output.AppendLine("CEC bus information"); Stephane@161: output.AppendLine("==================="); StephaneLenclud@167: CecLogicalAddresses addresses = iLib.GetActiveDevices(); Stephane@161: for (int iPtr = 0; iPtr < addresses.Addresses.Length; iPtr++) Stephane@161: { Stephane@161: CecLogicalAddress address = (CecLogicalAddress)iPtr; Stephane@161: if (!addresses.IsSet(address)) Stephane@161: continue; Stephane@161: StephaneLenclud@167: CecVendorId iVendorId = iLib.GetDeviceVendorId(address); StephaneLenclud@167: bool bActive = iLib.IsActiveDevice(address); StephaneLenclud@167: ushort iPhysicalAddress = iLib.GetDevicePhysicalAddress(address); Stephane@161: string strAddr = "todo: fixme"; //Lib.PhysicalAddressToString(iPhysicalAddress); StephaneLenclud@167: CecVersion iCecVersion = iLib.GetDeviceCecVersion(address); StephaneLenclud@167: CecPowerStatus power = iLib.GetDevicePowerStatus(address); StephaneLenclud@167: string osdName = iLib.GetDeviceOSDName(address); StephaneLenclud@167: string lang = iLib.GetDeviceMenuLanguage(address); Stephane@161: StephaneLenclud@167: output.AppendLine("device #" + iPtr + ": " + iLib.ToString(address)); Stephane@161: output.AppendLine("address: " + strAddr); Stephane@161: output.AppendLine("active source: " + (bActive ? "yes" : "no")); StephaneLenclud@167: output.AppendLine("vendor: " + iLib.ToString(iVendorId)); Stephane@161: output.AppendLine("osd string: " + osdName); StephaneLenclud@167: output.AppendLine("CEC version: " + iLib.ToString(iCecVersion)); StephaneLenclud@167: output.AppendLine("power status: " + iLib.ToString(power)); Stephane@161: if (!string.IsNullOrEmpty(lang)) Stephane@161: output.AppendLine("language: " + lang); Stephane@161: output.AppendLine(""); Stephane@161: } Stephane@161: Console.WriteLine(output.ToString()); Stephane@161: } Stephane@161: else if (splitCommand[0] == "h" || splitCommand[0] == "help") Stephane@161: ShowConsoleHelp(); Stephane@161: else if (splitCommand[0] == "q" || splitCommand[0] == "quit") Stephane@161: bContinue = false; Stephane@161: else if (splitCommand[0] == "log" && splitCommand.Length > 1) Stephane@161: LogLevel = int.Parse(splitCommand[1]); Stephane@161: } Stephane@161: } Stephane@203: Stephane@161: Stephane@161: } Stephane@161: }