Skip to content

Commit

Permalink
fix: updates to plugin with processResponse methods during live devic…
Browse files Browse the repository at this point in the history
…e testing
  • Loading branch information
jkdevito committed Jun 2, 2022
1 parent 0f456f5 commit 28a3d25
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions src/SonyBraviaDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public SonyBraviaDevice(DeviceConfig config, IBasicCommunication comms)
else
{
_queueSimpleIp = new CrestronQueue<string>(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);
Expand All @@ -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 =>
Expand All @@ -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)
{
Expand All @@ -128,7 +126,6 @@ public SonyBraviaDevice(DeviceConfig config, IBasicCommunication comms)
try
{
_coms.Connect();

CommunicationMonitor.Start();
_pollTimer.Reset(5000, 15000);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -709,7 +698,7 @@ private object ProcessSimpleIpResponse(object _)
// *([A,C,E,N])(?<command>POWR|INPT|VOLU|AMUT)(?<parameters>.[Ff]+|\d+)
// *(?<type>[A,C,E,N]{1})(?<command>[A-Za-z]{4})(?<parameters>.\w+)
// - CPOWR0000000000000000\n
// - AINPT0000000000000001\n
// - AINPT0000000000000001\n
// - CVOLU0000000000000001\n
// - AAMUTFFFFFFFFFFFFFFFF\n
var expression = new Regex(@"(?<type>[A,C,E,N]{1})(?<command>[A-Za-z]{4})(?<parameters>.\w+)", RegexOptions.None);
Expand All @@ -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":
Expand All @@ -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<string> ?? parts.ToList();
var inputType = (SimpleIpCommands.InputTypes)Convert.ToInt16(inputParts.ElementAt(0));
Expand Down

0 comments on commit 28a3d25

Please sign in to comment.