# HG changeset patch # User StephaneLenclud # Date 1468600277 -7200 # Node ID 6213f42f1983d21389cdc8141c0a36a6bd07265e # Parent 663c1ef0de590b514385038ad995a45752c674d8 Adding CEC logs and basic reconnect logic. diff -r 663c1ef0de59 -r 6213f42f1983 Server/CecClient.cs --- a/Server/CecClient.cs Thu Jul 14 19:25:52 2016 +0200 +++ b/Server/CecClient.cs Fri Jul 15 18:31:17 2016 +0200 @@ -61,29 +61,68 @@ } - + /// + /// + /// + /// + /// + /// public virtual int ReceiveAlert(CecAlert alert, CecParameter data) { + string log = "CEC alert: " + alert.ToString(); + if (data != null && data.Type == CecParameterType.ParameterTypeString) + { + log += " " + data.Data; + } + + Console.WriteLine(log); + + Close(); + //Try reconnect + Connect(1000); return 1; } + /// + /// + /// + /// + /// public virtual int ReceiveMenuStateChange(CecMenuState newVal) { + Console.WriteLine("CEC menu state changed to: " + iLib.ToString(newVal)); return 1; } + /// + /// + /// + /// + /// public virtual void SourceActivated(CecLogicalAddress logicalAddress, bool activated) { + Console.WriteLine("CEC source activated: " + iLib.ToString(logicalAddress) + "/" + activated.ToString() ); return; } public override int ReceiveCommand(CecCommand command) { + Console.WriteLine(string.Format("CEC command Src:{0} Dst:{1} Ack: {2} Eom: {3} OpcodeSet: {4} Opcode: {5} Timeout: {6}", + iLib.ToString(command.Initiator), + iLib.ToString(command.Destination), + command.Ack.ToString(), + command.Eom.ToString(), + command.OpcodeSet.ToString(), + iLib.ToString(command.Opcode), + command.TransmitTimeout.ToString() + )); return 1; } public override int ReceiveKeypress(CecKeypress key) { + Console.WriteLine(string.Format("CEC keypress: {0} Duration:{1} Empty: {2}", + key.Keycode.ToString(), key.Duration.ToString(), key.Empty.ToString())); return 1; } @@ -114,6 +153,7 @@ } string strLog = string.Format("{0} {1,16} {2}", strLevel, message.Time, message.Message); Console.WriteLine(strLog); + } return 1; } @@ -125,27 +165,74 @@ /// public bool Connect(int timeout) { + Close(); CecAdapter[] adapters = iLib.FindAdapters(string.Empty); if (adapters.Length > 0) - return Connect(adapters[0].ComPort, timeout); + { + Connect(adapters[0].ComPort, timeout); + } else { - Console.WriteLine("Did not find any CEC adapters"); - return false; + Console.WriteLine("CEC did not find any adapters"); } + + return iConnected; } public bool Connect(string port, int timeout) { - return iLib.Open(port, timeout); + Close(); + iConnected = iLib.Open(port, timeout); + if (iConnected) + { + Scan(); + } + return iConnected; } public void Close() - { + { iLib.Close(); + iConnected = false; } - public void ListDevices() + /// + /// + /// + public void Scan() + { + Console.WriteLine("CEC bus information"); + Console.WriteLine("==================="); + 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); + + Console.WriteLine("device #" + iPtr + ": " + Lib.ToString(address)); + Console.WriteLine("address: " + strAddr); + Console.WriteLine("active source: " + (bActive ? "yes" : "no")); + Console.WriteLine("vendor: " + Lib.ToString(iVendorId)); + Console.WriteLine("osd string: " + osdName); + Console.WriteLine("CEC version: " + Lib.ToString(iCecVersion)); + Console.WriteLine("power status: " + Lib.ToString(power)); + if (!string.IsNullOrEmpty(lang)) + Console.WriteLine("language: " + lang); + Console.WriteLine(""); + } + } + + public void ListAdapters() { int iAdapter = 0; foreach (CecAdapter adapter in iLib.FindAdapters(string.Empty)) @@ -398,5 +485,10 @@ /// /// private LibCECConfiguration Config; + + /// + /// + /// + private bool iConnected; } } diff -r 663c1ef0de59 -r 6213f42f1983 Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Thu Jul 14 19:25:52 2016 +0200 +++ b/Server/MainForm.Designer.cs Fri Jul 15 18:31:17 2016 +0200 @@ -113,6 +113,8 @@ this.labelFontHeight = new System.Windows.Forms.Label(); this.toolTip = new System.Windows.Forms.ToolTip(this.components); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.tabPageLogs = new System.Windows.Forms.TabPage(); + this.richTextBoxLogs = new System.Windows.Forms.RichTextBox(); this.panelDisplay.SuspendLayout(); this.iTableLayoutPanel.SuspendLayout(); this.statusStrip.SuspendLayout(); @@ -127,6 +129,7 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGreenStart)).BeginInit(); this.tabPageCec.SuspendLayout(); this.tabPageApp.SuspendLayout(); + this.tabPageLogs.SuspendLayout(); this.SuspendLayout(); // // panelDisplay @@ -552,6 +555,7 @@ this.tabControl.Controls.Add(this.tabPageInput); this.tabControl.Controls.Add(this.tabPageCec); this.tabControl.Controls.Add(this.tabPageApp); + this.tabControl.Controls.Add(this.tabPageLogs); this.tabControl.Location = new System.Drawing.Point(12, 139); this.tabControl.Name = "tabControl"; this.tabControl.SelectedIndex = 0; @@ -958,6 +962,33 @@ // this.openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*"; // + // tabPageLogs + // + this.tabPageLogs.Controls.Add(this.richTextBoxLogs); + this.tabPageLogs.Location = new System.Drawing.Point(4, 22); + this.tabPageLogs.Name = "tabPageLogs"; + this.tabPageLogs.Padding = new System.Windows.Forms.Padding(3); + this.tabPageLogs.Size = new System.Drawing.Size(592, 242); + this.tabPageLogs.TabIndex = 8; + this.tabPageLogs.Text = "Logs"; + this.tabPageLogs.UseVisualStyleBackColor = true; + // + // richTextBoxLogs + // + this.richTextBoxLogs.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.richTextBoxLogs.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.richTextBoxLogs.DetectUrls = false; + this.richTextBoxLogs.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.richTextBoxLogs.Location = new System.Drawing.Point(6, 6); + this.richTextBoxLogs.Name = "richTextBoxLogs"; + this.richTextBoxLogs.ReadOnly = true; + this.richTextBoxLogs.Size = new System.Drawing.Size(580, 230); + this.richTextBoxLogs.TabIndex = 1; + this.richTextBoxLogs.Text = ""; + this.richTextBoxLogs.WordWrap = false; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1000,6 +1031,7 @@ this.tabPageCec.PerformLayout(); this.tabPageApp.ResumeLayout(false); this.tabPageApp.PerformLayout(); + this.tabPageLogs.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -1081,6 +1113,8 @@ private System.Windows.Forms.CheckBox checkBoxCecMonitorOff; private System.Windows.Forms.Button iButtonStartIdleClient; private System.Windows.Forms.CheckBox iCheckBoxStartIdleClient; + private System.Windows.Forms.TabPage tabPageLogs; + private System.Windows.Forms.RichTextBox richTextBoxLogs; } } diff -r 663c1ef0de59 -r 6213f42f1983 Server/MainForm.cs --- a/Server/MainForm.cs Thu Jul 14 19:25:52 2016 +0200 +++ b/Server/MainForm.cs Fri Jul 15 18:31:17 2016 +0200 @@ -141,8 +141,12 @@ //Have our designer initialize its controls InitializeComponent(); - //Populate device types - PopulateDeviceTypes(); + //Redirect console output + RichTextBoxTextWriter writer = new RichTextBoxTextWriter(richTextBoxLogs); + Console.SetOut(writer); + + //Populate device types + PopulateDeviceTypes(); //Populate optical drives PopulateOpticalDrives(); diff -r 663c1ef0de59 -r 6213f42f1983 Server/Program.cs --- a/Server/Program.cs Thu Jul 14 19:25:52 2016 +0200 +++ b/Server/Program.cs Fri Jul 15 18:31:17 2016 +0200 @@ -40,7 +40,7 @@ static void Main() { - /* + /* if (!IsRunAsAdministrator()) { var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase); @@ -65,9 +65,8 @@ return; //Application.Current.Shutdown(); }*/ - - - Application.ApplicationExit += new EventHandler(OnApplicationExit); + + Application.ApplicationExit += new EventHandler(OnApplicationExit); // Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); diff -r 663c1ef0de59 -r 6213f42f1983 Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Thu Jul 14 19:25:52 2016 +0200 +++ b/Server/SharpDisplayManager.csproj Fri Jul 15 18:31:17 2016 +0200 @@ -185,6 +185,7 @@ ProgressForm.cs +