Working through queued command and the syncronous comms method in the BiampTesiraForteDsp class

This commit is contained in:
Neil Dorin
2017-03-21 16:53:14 -06:00
parent 5625d7e545
commit 667606562e
10 changed files with 1063 additions and 1003 deletions

View File

@@ -69,7 +69,7 @@
<Reference Include="mscorlib" />
<Reference Include="PepperDash_Core, Version=1.0.0.16459, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll</HintPath>
<HintPath>..\..\..\PepperDash.Core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll</HintPath>
</Reference>
<Reference Include="SimplSharpCustomAttributesInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

View File

@@ -57,7 +57,7 @@
<Reference Include="mscorlib" />
<Reference Include="PepperDash_Core, Version=1.0.0.15153, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll</HintPath>
<HintPath>..\..\..\PepperDash.Core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll</HintPath>
</Reference>
<Reference Include="PepperDash_Essentials_Core, Version=1.0.0.14500, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

View File

@@ -31,8 +31,12 @@ namespace PepperDash.Essentials.Devices.Common.DSP
public bool isSubscribed;
private CTimer SubscriptionTimer;
CrestronQueue CommandQueue;
bool CommandQueueInProgress = false;
//new public Dictionary<string, DspControlPoint> DialerControlPoints { get; private set; }
//new public Dictionary<string, DspControlPoint> SwitcherControlPoints { get; private set; }
@@ -45,7 +49,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
public BiampTesiraForteDsp(string key, string name, IBasicCommunication comm, BiampTesiraFortePropertiesConfig props) :
base(key, name)
{
CommandQueue = new CrestronQueue(20);
CommandQueue = new CrestronQueue(100);
Communication = comm;
var socket = comm as ISocketStatus;
@@ -58,7 +62,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
{
// This instance uses RS-232 control
}
PortGather = new CommunicationGather(Communication, '\x0a');
PortGather = new CommunicationGather(Communication, "\x0d\x0a");
PortGather.LineReceived += this.Port_LineReceived;
if (props.CommunicationMonitorProperties != null)
{
@@ -67,14 +71,14 @@ namespace PepperDash.Essentials.Devices.Common.DSP
else
{
#warning Need to deal with this poll string
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 120000, 120000, 300000, "");
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 120000, 120000, 300000, "SESSION get aliases\x0d\x0a");
}
LevelControlPoints = new Dictionary<string, TesiraForteLevelControl>();
foreach (KeyValuePair<string, BiampTesiraForteLevelControlBlockConfig> block in props.LevelControlBlocks)
{
this.LevelControlPoints.Add(block.Key, new TesiraForteLevelControl(block.Value, this));
this.LevelControlPoints.Add(block.Key, new TesiraForteLevelControl(block.Key, block.Value, this));
}
}
@@ -92,10 +96,25 @@ namespace PepperDash.Essentials.Devices.Common.DSP
void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e)
{
Debug.Console(2, this, "Socket Status Change: {0}", e.Client.ClientStatus.ToString());
if (e.Client.IsConnected)
{
Debug.Console(2, this, "Socket Status Change: {0}", e.Client.ClientStatus.ToString());
// Maybe wait for message indicating valid TTP session
// Tasks on connect
}
else
{
// Cleanup items from this session
if (SubscriptionTimer != null)
{
SubscriptionTimer.Stop();
SubscriptionTimer = null;
}
isSubscribed = false;
CommandQueue.Clear();
CommandQueueInProgress = false;
}
}
@@ -104,25 +123,32 @@ namespace PepperDash.Essentials.Devices.Common.DSP
/// </summary>
void SubscribeToAttributes()
{
EnqueueCommand("SESSION set verbose true");
SendLine("SESSION set verbose true");
foreach (KeyValuePair<string, TesiraForteLevelControl> level in LevelControlPoints)
{
level.Value.Subscribe();
}
if (!CommandQueue.IsEmpty)
SendNextQueuedCommand();
ResetSubscriptionTimer();
}
/// <summary>
/// Resets or Sets the subscription timer
/// </summary>
void ResetSubscriptionTimer()
{
#warning Add code to create/reset a CTimer to periodically check for subscribtion status
isSubscribed = true;
//CTimer SubscribtionTimer = new CTimer(
if (SubscriptionTimer != null)
{
SubscriptionTimer = new CTimer(o => SubscribeToAttributes(), 30000);
SubscriptionTimer.Reset();
}
}
/// <summary>
@@ -185,7 +211,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
}
else if (args.Text.IndexOf("+OK") > -1)
{
if (args.Text.Length > 4) // Check for a simple "+OK" only 'ack' repsonse
if (args.Text == "+OK" || args.Text.IndexOf("list\":") > -1 ) // Check for a simple "+OK" only 'ack' repsonse or a list response and ignore
return;
// response is not from a subscribed attribute. From a get/set/toggle/increment/decrement command
@@ -196,6 +222,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
{
// Expected response belongs to a child class
QueuedCommand tempCommand = (QueuedCommand)CommandQueue.Dequeue();
Debug.Console(2, this, "Command Dequeued. CommandQueue Size: {0}", CommandQueue.Count);
tempCommand.ControlPoint.ParseGetMessage(tempCommand.AttributeCode, args.Text);
}
@@ -203,9 +230,14 @@ namespace PepperDash.Essentials.Devices.Common.DSP
{
// Expected response belongs to this class
string temp = (string)CommandQueue.Dequeue();
Debug.Console(2, this, "Command Dequeued. CommandQueue Size: {0}", CommandQueue.Count);
}
//if (CommandQueue.IsEmpty)
// CommandQueueInProgress = false;
//else
SendNextQueuedCommand();
}
@@ -253,6 +285,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
public void EnqueueCommand(QueuedCommand commandToEnqueue)
{
CommandQueue.Enqueue(commandToEnqueue);
SendNextQueuedCommand();
}
/// <summary>
@@ -262,6 +295,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
public void EnqueueCommand(string command)
{
CommandQueue.Enqueue(command);
SendNextQueuedCommand();
}
/// <summary>
@@ -269,6 +303,29 @@ namespace PepperDash.Essentials.Devices.Common.DSP
/// </summary>
void SendNextQueuedCommand()
{
Debug.Console(2, this, "Attempting to send next queued command. CommandQueueInProgress: {0} Communication isConnected: {1}", CommandQueueInProgress, Communication.IsConnected);
if (!CommandQueueInProgress)
{
if (CommandQueue.IsEmpty)
CommandQueueInProgress = false;
Debug.Console(2, this, "CommandQueue has {0} Elements", CommandQueue.Count);
foreach (object o in CommandQueue)
{
if (o is string)
Debug.Console(2, this, "{0}", o);
else if(o is QueuedCommand)
{
var item = (QueuedCommand)o;
Debug.Console(2, this, "{0}", item.Command);
}
}
if (Communication.IsConnected && !CommandQueue.IsEmpty)
{
CommandQueueInProgress = true;
if (CommandQueue.Peek() is QueuedCommand)
{
QueuedCommand nextCommand = new QueuedCommand();
@@ -284,6 +341,8 @@ namespace PepperDash.Essentials.Devices.Common.DSP
SendLine(nextCommand);
}
}
}
}
/// <summary>
/// Sends a command to execute a preset

View File

@@ -84,25 +84,25 @@ namespace PepperDash.Essentials.Devices.Common.DSP
bool LevelIsSubscribed;
public TesiraForteLevelControl(string label, string id, int index1, int index2, bool hasMute, bool hasLevel, BiampTesiraForteDsp parent)
: base(id, index1, index2, parent)
{
Initialize(label, hasMute, hasLevel);
}
//public TesiraForteLevelControl(string label, string id, int index1, int index2, bool hasMute, bool hasLevel, BiampTesiraForteDsp parent)
// : base(id, index1, index2, parent)
//{
// Initialize(label, hasMute, hasLevel);
//}
public TesiraForteLevelControl(BiampTesiraForteLevelControlBlockConfig config, BiampTesiraForteDsp parent)
public TesiraForteLevelControl(string key, BiampTesiraForteLevelControlBlockConfig config, BiampTesiraForteDsp parent)
: base(config.InstanceTag, config.Index1, config.Index2, parent)
{
Initialize(config.Label, config.HasMute, config.HasLevel);
Initialize(key, config.Label, config.HasMute, config.HasLevel);
}
/// <summary>
/// Initializes this attribute based on config values and generates subscriptions commands and adds commands to the parent's queue.
/// </summary>
public void Initialize(string label, bool hasMute, bool hasLevel)
public void Initialize(string key, string label, bool hasMute, bool hasLevel)
{
Key = string.Format("{0}-{1}", Parent.Key, label);
Key = string.Format("{0}--{1}", Parent.Key, key);
DeviceManager.AddDevice(this);
@@ -210,20 +210,20 @@ namespace PepperDash.Essentials.Devices.Common.DSP
{
try
{
// Parse a "+OK" message
string pattern = "+OK \"value\":(.*)";
// Parse an "+OK" message
string pattern = @"\+OK ""value"":(.*)";
Match match = Regex.Match(message, pattern);
if (match.Success)
{
string value;
string value = match.Groups[1].Value;
Debug.Console(2, this, "{0} is {1}", attributeCode, value);
if (message.IndexOf("\"value\":") > -1)
{
value = message.Substring(message.IndexOf(":"), message.Length - message.IndexOf(":"));
switch (attributeCode)
{
case "minLevel":
@@ -277,6 +277,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
/// <param name="level"></param>
public void SetVolume(ushort level)
{
Debug.Console(2, this, "volume: {0}", level);
// Unmute volume if new level is higher than existing
if (level > _VolumeLevel && AutomaticUnmuteOnVolumeUp)
if(!_IsMuted)
@@ -284,7 +285,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
double volumeLevel = Scale(level, 0, 65535, MinLevel, MaxLevel);
SendFullCommand("Set", "level", volumeLevel.ToString());
SendFullCommand("set", "level", volumeLevel.ToString());
}
/// <summary>

View File

@@ -77,11 +77,11 @@
<Reference Include="mscorlib" />
<Reference Include="PepperDashCorePortalSync, Version=1.0.0.27069, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\pepperdash-portal-sync\PepperDashCorePortalSync\PepperDashPortalSync\bin\PepperDashCorePortalSync.dll</HintPath>
<HintPath>..\..\..\pepperdash-portal-sync\SspPortalSync\SspPortalSync\bin\PepperDashCorePortalSync.dll</HintPath>
</Reference>
<Reference Include="PepperDash_Core, Version=1.0.0.18868, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll</HintPath>
<HintPath>..\..\..\PepperDash.Core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll</HintPath>
</Reference>
<Reference Include="PepperDash_Essentials_Core, Version=1.0.0.12925, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>