public static void Search(string file, bool verbose, TextWriter w) { Lib lib = new Lib(file); if (lib.Open()) { if (verbose) { w.WriteLine("searching {0}...", file); } ArrayList todo = new ArrayList(); foreach (DictionaryEntry e in Symbols.refs) { if (lib.Exports((string)e.Key)) { todo.Add((string)e.Key); } } foreach (string name in todo) { if (verbose) { w.WriteLine(" found {0}", name); } Symbols.Extern(name, file); Symbols.Def(name); } lib.Close(); } else if (verbose) { illink.Warning("can't search '{0}'", file); } }
/// <summary> /// Closes the connection to libCEC /// </summary> public void Close() { Lib.DisableCallbacks(); Lib.StandbyDevices(CecLogicalAddress.Broadcast); Lib.Close(); _initialised = false; }
/// <summary> /// Closes the connection to libCEC /// </summary> public void Close() { SystemIdleMonitor.Instance.Suspended = true; lock (this) { if (Initialised && _started) { Lib.DisableCallbacks(); Lib.StandbyDevices(CecLogicalAddress.Broadcast); Lib.Close(); _started = false; } } }
public void MainLoop() { Lib.PowerOnDevices(CecLogicalAddress.Tv); FlushLog(); Lib.SetActiveSource(CecDeviceType.PlaybackDevice); FlushLog(); bool bContinue = true; string command; while (bContinue) { FlushLog(); Console.WriteLine("waiting for input"); command = Console.ReadLine(); if (command.Length == 0) { continue; } string[] splitCommand = command.Split(' '); if (splitCommand[0] == "tx" || splitCommand[0] == "txn") { CecCommand bytes = new CecCommand(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { bytes.PushBack(byte.Parse(splitCommand[iPtr], System.Globalization.NumberStyles.HexNumber)); } if (command == "txn") { bytes.TransmitTimeout = 0; } Lib.Transmit(bytes); } else if (splitCommand[0] == "on") { if (splitCommand.Length > 1) { Lib.PowerOnDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { Lib.PowerOnDevices(CecLogicalAddress.Broadcast); } } else if (splitCommand[0] == "standby") { if (splitCommand.Length > 1) { Lib.StandbyDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { Lib.StandbyDevices(CecLogicalAddress.Broadcast); } } else if (splitCommand[0] == "poll") { bool bSent = false; if (splitCommand.Length > 1) { bSent = Lib.PollDevice((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { bSent = Lib.PollDevice(CecLogicalAddress.Broadcast); } if (bSent) { Console.WriteLine("POLL message sent"); } else { Console.WriteLine("POLL message not sent"); } } else if (splitCommand[0] == "la") { if (splitCommand.Length > 1) { Lib.SetLogicalAddress((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "pa") { if (splitCommand.Length > 1) { Lib.SetPhysicalAddress(short.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "osd") { if (splitCommand.Length > 2) { StringBuilder osdString = new StringBuilder(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { osdString.Append(splitCommand[iPtr]); if (iPtr != splitCommand.Length - 1) { osdString.Append(" "); } } Lib.SetOSDString((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber), CecDisplayControl.DisplayForDefaultTime, osdString.ToString()); } } else if (splitCommand[0] == "ping") { Lib.PingAdapter(); } else if (splitCommand[0] == "mon") { bool enable = splitCommand.Length > 1 ? splitCommand[1] == "1" : false; Lib.SwitchMonitoring(enable); } else if (splitCommand[0] == "bl") { Lib.StartBootloader(); } else if (splitCommand[0] == "lang") { if (splitCommand.Length > 1) { string language = Lib.GetDeviceMenuLanguage((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("Menu language: " + language); } } else if (splitCommand[0] == "ven") { if (splitCommand.Length > 1) { CecVendorId vendor = Lib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("Vendor ID: " + Lib.ToString(vendor)); } } else if (splitCommand[0] == "ver") { if (splitCommand.Length > 1) { CecVersion version = Lib.GetDeviceCecVersion((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("CEC version: " + Lib.ToString(version)); } } else if (splitCommand[0] == "pow") { if (splitCommand.Length > 1) { CecPowerStatus power = Lib.GetDevicePowerStatus((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("power status: " + Lib.ToString(power)); } } else if (splitCommand[0] == "r") { Console.WriteLine("closing the connection"); Lib.Close(); FlushLog(); Console.WriteLine("opening a new connection"); Connect(10000); FlushLog(); Console.WriteLine("setting active source"); Lib.SetActiveSource(CecDeviceType.PlaybackDevice); } else if (splitCommand[0] == "scan") { Console.WriteLine("CEC bus information"); Console.WriteLine("==================="); CecLogicalAddresses addresses = Lib.GetActiveDevices(); for (int iPtr = 0; iPtr < addresses.Addresses.Count(); iPtr++) { CecLogicalAddress address = (CecLogicalAddress)iPtr; if (!addresses.IsSet(address)) { continue; } CecVendorId iVendorId = Lib.GetDeviceVendorId(address); bool bActive = Lib.IsActiveDevice(address); ushort iPhysicalAddress = Lib.GetDevicePhysicalAddress(address); string strAddr = string.Format("{0,4:X}", iPhysicalAddress); CecVersion iCecVersion = Lib.GetDeviceCecVersion(address); CecPowerStatus power = Lib.GetDevicePowerStatus(address); string osdName = Lib.GetDeviceOSDName(address); string lang = Lib.GetDeviceMenuLanguage(address); StringBuilder output = new StringBuilder(); output.AppendLine("device #" + iPtr + ": " + Lib.ToString(address)); output.AppendLine("address: " + strAddr); output.AppendLine("active source: " + (bActive ? "yes" : "no")); output.AppendLine("vendor: " + Lib.ToString(iVendorId)); output.AppendLine("osd string: " + osdName); output.AppendLine("CEC version: " + Lib.ToString(iCecVersion)); output.AppendLine("power status: " + Lib.ToString(power)); if (!string.IsNullOrEmpty(lang)) { output.AppendLine("language: " + lang); } Console.WriteLine(output.ToString()); } } else if (splitCommand[0] == "h" || splitCommand[0] == "help") { ShowConsoleHelp(); } else if (splitCommand[0] == "q" || splitCommand[0] == "quit") { bContinue = false; } else if (splitCommand[0] == "log" && splitCommand.Length > 1) { LogLevel = int.Parse(splitCommand[1]); } } }
public void Close() { Lib.Close(); }
public string SendCommand(string command) { if (command == null || command.Length == 0) { return("No command received"); } string[] splitCommand = command.Split(' '); if (splitCommand[0] == "tx" || splitCommand[0] == "txn") { CecCommand bytes = new CecCommand(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { bytes.PushBack(byte.Parse(splitCommand[iPtr], System.Globalization.NumberStyles.HexNumber)); } if (command == "txn") { bytes.TransmitTimeout = 0; } Lib.Transmit(bytes); } else if (splitCommand[0] == "default") { Lib.SetActiveSource(CecDeviceType.PlaybackDevice); return("Set default playback device as active"); } else if (splitCommand[0] == "rescan") { Lib.RescanActiveDevices(); return("Rescan active devices"); } else if (splitCommand[0] == "vol") { if (splitCommand[1] == "up") { Lib.VolumeUp(true); return("vol up"); } else if (splitCommand[1] == "down") { Lib.VolumeDown(true); return("vol down"); } else if (splitCommand[1] == "mute") { Lib.MuteAudio(true); return("Vol mute"); } return("Vol sub command not understood"); } else if (splitCommand[0] == "on") { if (splitCommand.Length > 1) { Lib.PowerOnDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("Signalled ON for device: " + splitCommand[1]); } else { Lib.PowerOnDevices(CecLogicalAddress.Broadcast); return("Signalled broadcast ON"); } } else if (splitCommand[0] == "standby") { if (splitCommand.Length > 1) { Lib.StandbyDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("Signalled STANDBY for device: " + splitCommand[1]); } else { Lib.StandbyDevices(CecLogicalAddress.Broadcast); return("Signalled broadcast STANDBY"); } } else if (splitCommand[0] == "setDeviceHDMIPort") { if (splitCommand.Length > 2) { if (splitCommand[1] == "Tv") { Lib.SetHDMIPort(CecLogicalAddress.Tv, byte.Parse(splitCommand[2])); return("Set device " + splitCommand[1] + " to HDMI port " + splitCommand[2]); } if (splitCommand[1] == "AudioSystem") { Lib.SetHDMIPort(CecLogicalAddress.AudioSystem, byte.Parse(splitCommand[2])); return("Set device " + splitCommand[1] + " to HDMI port " + splitCommand[2]); } } return("Incorrect use of setDeviceHDMIPort"); } else if (splitCommand[0] == "poll") { bool bSent = false; if (splitCommand.Length > 1) { bSent = Lib.PollDevice((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { bSent = Lib.PollDevice(CecLogicalAddress.Broadcast); } if (bSent) { Console.WriteLine("POLL message sent"); } else { Console.WriteLine("POLL message not sent"); } } else if (splitCommand[0] == "la") { if (splitCommand.Length > 1) { Lib.SetLogicalAddress((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "pa") { if (splitCommand.Length > 1) { Lib.SetPhysicalAddress(ushort.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "osd") { if (splitCommand.Length > 2) { StringBuilder osdString = new StringBuilder(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { osdString.Append(splitCommand[iPtr]); if (iPtr != splitCommand.Length - 1) { osdString.Append(" "); } } Lib.SetOSDString((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber), CecDisplayControl.DisplayForDefaultTime, osdString.ToString()); } } else if (splitCommand[0] == "ping") { return(Lib.PingAdapter().ToString()); } else if (splitCommand[0] == "mon") { bool enable = splitCommand.Length > 1 ? splitCommand[1] == "1" : false; Lib.SwitchMonitoring(enable); } else if (splitCommand[0] == "bl") { Lib.StartBootloader(); } else if (splitCommand[0] == "lang") { if (splitCommand.Length > 1) { string language = Lib.GetDeviceMenuLanguage((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("Menu language: " + language); } } else if (splitCommand[0] == "ven") { if (splitCommand.Length > 1) { CecVendorId vendor = Lib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("Vendor ID: " + Lib.ToString(vendor)); } } else if (splitCommand[0] == "ver") { if (splitCommand.Length > 1) { CecVersion version = Lib.GetDeviceCecVersion((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("CEC version: " + Lib.ToString(version)); } } else if (splitCommand[0] == "pow") { if (splitCommand.Length > 1) { CecPowerStatus power = Lib.GetDevicePowerStatus((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("power status: " + Lib.ToString(power)); } } else if (splitCommand[0] == "r") { Console.WriteLine("closing the connection"); Lib.Close(); Console.WriteLine("opening a new connection"); Connect(10000); Console.WriteLine("setting active source"); Lib.SetActiveSource(CecDeviceType.AudioSystem); } else if (splitCommand[0] == "setActiveSource") { if (splitCommand.Length > 1) { if (splitCommand[1] == "AudioSystem") { Lib.SetActiveSource(CecDeviceType.AudioSystem); return("setting active source to audio system"); } if (splitCommand[1] == "PlaybackDevice") { Lib.SetActiveSource(CecDeviceType.PlaybackDevice); return("setting active source to playback device"); } if (splitCommand[1] == "RecordingDevice") { Lib.SetActiveSource(CecDeviceType.RecordingDevice); return("setting active source to Recording device"); } if (splitCommand[1] == "Reserved") { Lib.SetActiveSource(CecDeviceType.Reserved); return("setting active source to Reserved device"); } if (splitCommand[1] == "Tuner") { Lib.SetActiveSource(CecDeviceType.Tuner); return("setting active source to Tuner"); } if (splitCommand[1] == "Tv") { Lib.SetActiveSource(CecDeviceType.Tv); return("setting active source to Tv"); } } return("incorrect use of setActiveSource"); } else if (splitCommand[0] == "scan") { StringBuilder output = new StringBuilder(); output.AppendLine("CEC bus information"); output.AppendLine("==================="); CecLogicalAddresses addresses = Lib.GetActiveDevices(); for (int iPtr = 0; iPtr < addresses.Addresses.Length; iPtr++) { CecLogicalAddress address = (CecLogicalAddress)iPtr; if (!addresses.IsSet(address)) { continue; } CecVendorId iVendorId = Lib.GetDeviceVendorId(address); bool bActive = Lib.IsActiveDevice(address); ushort iPhysicalAddress = Lib.GetDevicePhysicalAddress(address); string strAddr = Lib.PhysicalAddressToString(iPhysicalAddress); CecVersion iCecVersion = Lib.GetDeviceCecVersion(address); CecPowerStatus power = Lib.GetDevicePowerStatus(address); string osdName = Lib.GetDeviceOSDName(address); string lang = Lib.GetDeviceMenuLanguage(address); output.AppendLine("device #" + iPtr + ": " + Lib.ToString(address)); output.AppendLine("address: " + strAddr); output.AppendLine("active source: " + (bActive ? "yes" : "no")); output.AppendLine("vendor: " + Lib.ToString(iVendorId)); output.AppendLine("osd string: " + osdName); output.AppendLine("CEC version: " + Lib.ToString(iCecVersion)); output.AppendLine("power status: " + Lib.ToString(power)); if (!string.IsNullOrEmpty(lang)) { output.AppendLine("language: " + lang); } output.AppendLine(""); } return(output.ToString()); } return("CEC command not understood"); }
public void MainLoop() { Lib.PowerOnDevices(CecLogicalAddress.Tv); FlushLog(); Lib.SetActiveSource(CecDeviceType.PlaybackDevice); FlushLog(); bool bContinue = true; string command; while (bContinue) { Console.WriteLine("waiting for input"); command = Console.ReadLine(); if (command.Length == 0) { continue; } string[] splitCommand = command.Split(' '); if (splitCommand[0] == "tx" || splitCommand[0] == "txn") { CecCommand bytes = new CecCommand(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { bytes.PushBack(byte.Parse(splitCommand[iPtr], System.Globalization.NumberStyles.HexNumber)); } if (command == "txn") { bytes.TransmitTimeout = 0; } Lib.Transmit(bytes); } else if (splitCommand[0] == "on") { if (splitCommand.Length > 1) { Lib.PowerOnDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { Lib.PowerOnDevices(CecLogicalAddress.Broadcast); } } else if (splitCommand[0] == "standby") { if (splitCommand.Length > 1) { Lib.StandbyDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { Lib.StandbyDevices(CecLogicalAddress.Broadcast); } } else if (splitCommand[0] == "poll") { bool bSent = false; if (splitCommand.Length > 1) { bSent = Lib.PollDevice((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { bSent = Lib.PollDevice(CecLogicalAddress.Broadcast); } if (bSent) { Console.WriteLine("POLL message sent"); } else { Console.WriteLine("POLL message not sent"); } } else if (splitCommand[0] == "la") { if (splitCommand.Length > 1) { Lib.SetLogicalAddress((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "pa") { if (splitCommand.Length > 1) { Lib.SetPhysicalAddress(short.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "osd") { if (splitCommand.Length > 2) { StringBuilder osdString = new StringBuilder(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { osdString.Append(splitCommand[iPtr]); if (iPtr != splitCommand.Length - 1) { osdString.Append(" "); } } Lib.SetOSDString((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber), CecDisplayControl.DisplayForDefaultTime, osdString.ToString()); } } else if (splitCommand[0] == "ping") { Lib.PingAdapter(); } else if (splitCommand[0] == "mon") { bool enable = splitCommand.Length > 1 ? splitCommand[1] == "1" : false; Lib.SwitchMonitoring(enable); } else if (splitCommand[0] == "bl") { Lib.StartBootloader(); } else if (splitCommand[0] == "lang") { if (splitCommand.Length > 1) { string language = Lib.GetDeviceMenuLanguage((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("Menu language: " + language); } } else if (splitCommand[0] == "ven") { if (splitCommand.Length > 1) { ulong vendor = Lib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("Vendor ID: " + vendor); } } else if (splitCommand[0] == "ver") { if (splitCommand.Length > 1) { CecVersion version = Lib.GetDeviceCecVersion((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); switch (version) { case CecVersion.V1_2: Console.WriteLine("CEC version 1.2"); break; case CecVersion.V1_2A: Console.WriteLine("CEC version 1.2a"); break; case CecVersion.V1_3: Console.WriteLine("CEC version 1.3"); break; case CecVersion.V1_3A: Console.WriteLine("CEC version 1.3a"); break; case CecVersion.V1_4: Console.WriteLine("CEC version 1.4"); break; default: Console.WriteLine("unknown CEC version"); break; } } } else if (splitCommand[0] == "pow") { if (splitCommand.Length > 1) { CecPowerStatus power = Lib.GetDevicePowerStatus((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); switch (power) { case CecPowerStatus.On: Console.WriteLine("powered on"); break; case CecPowerStatus.InTransitionOnToStandby: Console.WriteLine("on -> standby"); break; case CecPowerStatus.InTransitionStandbyToOn: Console.WriteLine("standby -> on"); break; case CecPowerStatus.Standby: Console.WriteLine("standby"); break; default: Console.WriteLine("unknown power status"); break; } } } else if (splitCommand[0] == "r") { Console.WriteLine("closing the connection"); Lib.Close(); FlushLog(); Console.WriteLine("opening a new connection"); Connect(10000); FlushLog(); Console.WriteLine("setting active source"); Lib.SetActiveSource(CecDeviceType.PlaybackDevice); } else if (splitCommand[0] == "h" || splitCommand[0] == "help") { ShowConsoleHelp(); } else if (splitCommand[0] == "q" || splitCommand[0] == "quit") { bContinue = false; } else if (splitCommand[0] == "log" && splitCommand.Length > 1) { LogLevel = int.Parse(splitCommand[1]); } FlushLog(); } }