From 51e338749ab29471d10b8db3ba89db8d44339ca1 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 9 Nov 2020 12:11:39 -0700 Subject: [PATCH] Implement IDeviceInfoProvider on DGE100 --- .../Endpoints/DGEs/Dge100Controller.cs | 102 ++++++++++++++++-- 1 file changed, 95 insertions(+), 7 deletions(-) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/DGEs/Dge100Controller.cs b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/DGEs/Dge100Controller.cs index dd07f696..46692912 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/DGEs/Dge100Controller.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/DGEs/Dge100Controller.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; -using System.Linq; +using System.Linq; +using System.Net.Sockets; using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharpPro; @@ -14,15 +15,19 @@ using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; -using Crestron.SimplSharpPro.DeviceSupport; - +using Crestron.SimplSharpPro.DeviceSupport; +using PepperDash.Essentials.Core.DeviceInfo; + namespace PepperDash.Essentials.DM.Endpoints.DGEs { [Description("Wrapper class for DGE-100")] - public class Dge100Controller : CrestronGenericBaseDevice, IComPorts, IIROutputPorts, IHasBasicTriListWithSmartObject, ICec + public class Dge100Controller : CrestronGenericBaseDevice, IComPorts, IIROutputPorts, IHasBasicTriListWithSmartObject, ICec, IDeviceInfoProvider { + private const int CtpPort = 41795; private readonly Dge100 _dge; + private readonly TsxCcsUcCodec100EthernetReservedSigs _dgeEthernetInfo; + public BasicTriListWithSmartObject Panel { get { return _dge; } } private DeviceConfig _dc; @@ -32,7 +37,12 @@ namespace PepperDash.Essentials.DM.Endpoints.DGEs public Dge100Controller(string key, string name, Dge100 device, DeviceConfig dc, CrestronTouchpanelPropertiesConfig props) :base(key, name, device) { - _dge = device; + _dge = device; + _dgeEthernetInfo = _dge.ExtenderEthernetReservedSigs; + _dgeEthernetInfo.DeviceExtenderSigChange += (extender, args) => UpdateDeviceInfo(); + _dgeEthernetInfo.Use(); + + DeviceInfo = new DeviceInfo(); _dc = dc; @@ -69,8 +79,86 @@ namespace PepperDash.Essentials.DM.Endpoints.DGEs #region ICec Members public Cec StreamCec { get { return _dge.HdmiOut.StreamCec; } } - #endregion - + #endregion + + #region Implementation of IDeviceInfoProvider + + public DeviceInfo DeviceInfo { get; private set; } + + public event EventHandler DeviceInfoChanged; + + public void UpdateDeviceInfo() + { + DeviceInfo.IpAddress = _dgeEthernetInfo.IpAddressFeedback.StringValue; + DeviceInfo.MacAddress = _dgeEthernetInfo.MacAddressFeedback.StringValue; + + GetFirmwareAndSerialInfo(); + + OnDeviceInfoChange(); + } + + private void GetFirmwareAndSerialInfo() + { + if (String.IsNullOrEmpty(_dgeEthernetInfo.IpAddressFeedback.StringValue)) + { + Debug.Console(1, this, "IP Address information not yet received. No device is online"); + return; + } + + var tcpClient = new GenericTcpIpClient("", _dgeEthernetInfo.IpAddressFeedback.StringValue, CtpPort, 1024); + + var gather = new CommunicationGather(tcpClient, "\r\n\r\n"); + + tcpClient.ConnectionChange += (sender, args) => + { + if (!args.Client.IsConnected) + { + return; + } + + args.Client.SendText("ver\r\n"); + }; + + gather.LineReceived += (sender, args) => + { + if (args.Text.ToLower().Contains("host")) + { + DeviceInfo.HostName = args.Text.Split(';')[1].Trim(); + + tcpClient.Disconnect(); + return; + } + + //ignore console prompt + if (args.Text.ToLower().Contains(">")) + { + return; + } + + if (!args.Text.ToLower().Contains("dge")) + { + return; + } + + DeviceInfo.SerialNumber = args.Text.Split('[')[1].Split(' ')[4].Replace("#", ""); + DeviceInfo.FirmwareVersion = args.Text.Split('[')[1].Split(' ')[1]; + + tcpClient.SendText("host\r\n"); + }; + + tcpClient.Connect(); + } + + private void OnDeviceInfoChange() + { + var handler = DeviceInfoChanged; + + if (handler == null) return; + + handler(this, new DeviceInfoEventArgs(DeviceInfo)); + } + + #endregion } public class Dge100ControllerFactory : EssentialsDeviceFactory