From 28a3d2587fab4f2717b831d289d6733de4d30a87 Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Thu, 2 Jun 2022 12:57:56 -0500 Subject: [PATCH] fix: updates to plugin with processResponse methods during live device testing --- src/SonyBraviaDevice.cs | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/SonyBraviaDevice.cs b/src/SonyBraviaDevice.cs index c378c66..a04329d 100644 --- a/src/SonyBraviaDevice.cs +++ b/src/SonyBraviaDevice.cs @@ -77,7 +77,7 @@ public SonyBraviaDevice(DeviceConfig config, IBasicCommunication comms) else { _queueSimpleIp = new CrestronQueue(50); - var comsGather = new CommunicationGather(_coms, '\x0A'); + var comsGather = new CommunicationGather(_coms, "\x0A"); comsGather.LineReceived += (sender, args) => _queueSimpleIp.Enqueue(args.Text); _powerOnCommand = SimpleIpCommands.GetControlCommand(_coms, "POWR", 1); @@ -96,7 +96,10 @@ public SonyBraviaDevice(DeviceConfig config, IBasicCommunication comms) BuildInputRoutingPorts(); - var worker = new Thread(ProcessResponseQueue, null); + var worker = _comsIsRs232 + ? new Thread(ProcessRs232Response, null) + : new Thread(ProcessSimpleIpResponse, null); + _pollTimer = new CTimer(Poll, new[] { powerQuery, inputQuery }, Timeout.Infinite); CrestronEnvironment.ProgramStatusEventHandler += type => @@ -106,15 +109,10 @@ public SonyBraviaDevice(DeviceConfig config, IBasicCommunication comms) if (type != eProgramStatusEventType.Stopping) return; + worker.Abort(); + _pollTimer.Stop(); _pollTimer.Dispose(); - - if (_comsIsRs232) - _queueRs232.Enqueue(null); - else - _queueSimpleIp.Enqueue(null); - - worker.Join(); } catch (Exception ex) { @@ -128,7 +126,6 @@ public SonyBraviaDevice(DeviceConfig config, IBasicCommunication comms) try { _coms.Connect(); - CommunicationMonitor.Start(); _pollTimer.Reset(5000, 15000); } @@ -530,14 +527,6 @@ public override void ExecuteSwitch(object selector) } } - private object ProcessResponseQueue(object _) - { - if (_ != null) return _comsIsRs232 ? ProcessRs232Response(_) : ProcessSimpleIpResponse(_); - - Debug.Console(DebugLevels.ErrorLevel, this, "ProcessResponseQueue: object was null"); - return null; - } - private object ProcessRs232Response(object _) { var seperator = new string('-', 50); @@ -550,7 +539,7 @@ private object ProcessRs232Response(object _) var bytes = _queueRs232.Dequeue(); if (bytes == null) { - Debug.Console(DebugLevels.ErrorLevel, this, "ProcessRs232Response: _queueRs232.Dequeue failed, object was null"); + Debug.Console(DebugLevels.ErrorLevel, this, "ProcessRs232Response: _queueRs232.Dequeue failed, object was null"); return null; } @@ -709,7 +698,7 @@ private object ProcessSimpleIpResponse(object _) // *([A,C,E,N])(?POWR|INPT|VOLU|AMUT)(?.[Ff]+|\d+) // *(?[A,C,E,N]{1})(?[A-Za-z]{4})(?.\w+) // - CPOWR0000000000000000\n - // - AINPT0000000000000001\n + // - AINPT0000000000000001\n // - CVOLU0000000000000001\n // - AAMUTFFFFFFFFFFFFFFFF\n var expression = new Regex(@"(?[A,C,E,N]{1})(?[A-Za-z]{4})(?.\w+)", RegexOptions.None); @@ -721,12 +710,17 @@ private object ProcessSimpleIpResponse(object _) return null; } - var type = matches.Groups["types"].Value; + var type = matches.Groups["type"].Value; var command = matches.Groups["command"].Value; var parameters = matches.Groups["parameters"].Value; Debug.Console(DebugLevels.ErrorLevel, this, "ProcessSimpleIpResponse: type-'{0}' | command-'{1}' | parameters-'{2}'", type, command, parameters); + // display off input response: + // - '*SAINPTFFFFFFFFFFFFFFFF' + // - '*SAINPTNNNNNNNNNNNNNNNN' + if (parameters.Contains('F') || parameters.Contains('N')) continue; + switch (command) { case "POWR": @@ -735,8 +729,11 @@ private object ProcessSimpleIpResponse(object _) Debug.Console(DebugLevels.ErrorLevel, this, "ProcessSimpleIpResponse: PowerIsOn == '{0}'", PowerIsOn.ToString()); break; } - case "INPUT": + case "INPT": { + // display on response: + // - '*SAINPT0000000100000001' (hdmi 1) + // - '*SAINPT0000000400000001' (component 1) var parts = parameters.SplitInParts(8); var inputParts = parts as IList ?? parts.ToList(); var inputType = (SimpleIpCommands.InputTypes)Convert.ToInt16(inputParts.ElementAt(0));