DSP volume/mute control now fully working. Resolved ESC-305 issues with command queueing

This commit is contained in:
Neil Dorin
2017-03-22 16:02:36 -06:00
parent 667606562e
commit 061505706d
7 changed files with 92 additions and 54 deletions

View File

@@ -70,7 +70,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
}
else
{
#warning Need to deal with this poll string
//#warning Need to deal with this poll string
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 120000, 120000, 300000, "SESSION get aliases\x0d\x0a");
}
@@ -130,7 +130,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
level.Value.Subscribe();
}
if (!CommandQueue.IsEmpty)
if (!CommandQueueInProgress)
SendNextQueuedCommand();
ResetSubscriptionTimer();
@@ -162,6 +162,8 @@ namespace PepperDash.Essentials.Devices.Common.DSP
Debug.Console(2, this, "RX: '{0}'",
ShowHexResponse ? ComTextHelper.GetEscapedText(args.Text) : args.Text);
Debug.Console(1, this, "RX: '{0}'", args.Text);
try
{
if (args.Text.IndexOf("Welcome to the Tesira Text Protocol Server...") > -1)
@@ -221,23 +223,22 @@ namespace PepperDash.Essentials.Devices.Common.DSP
if (CommandQueue.Peek() is QueuedCommand)
{
// Expected response belongs to a child class
QueuedCommand tempCommand = (QueuedCommand)CommandQueue.Dequeue();
Debug.Console(2, this, "Command Dequeued. CommandQueue Size: {0}", CommandQueue.Count);
QueuedCommand tempCommand = (QueuedCommand)CommandQueue.TryToDequeue();
Debug.Console(1, this, "Command Dequeued. CommandQueue Size: {0}", CommandQueue.Count);
tempCommand.ControlPoint.ParseGetMessage(tempCommand.AttributeCode, args.Text);
}
else
{
// Expected response belongs to this class
string temp = (string)CommandQueue.Dequeue();
Debug.Console(2, this, "Command Dequeued. CommandQueue Size: {0}", CommandQueue.Count);
string temp = (string)CommandQueue.TryToDequeue();
Debug.Console(1, this, "Command Dequeued. CommandQueue Size: {0}", CommandQueue.Count);
}
//if (CommandQueue.IsEmpty)
// CommandQueueInProgress = false;
//else
if (CommandQueue.IsEmpty)
CommandQueueInProgress = false;
else
SendNextQueuedCommand();
}
@@ -248,14 +249,18 @@ namespace PepperDash.Essentials.Devices.Common.DSP
{
// Error response
if (args.Text == "-ERR ALREADY_SUBSCRIBED")
switch (args.Text)
{
// Subscription still valid
ResetSubscriptionTimer();
}
else
{
SubscribeToAttributes();
case "-ERR ALREADY_SUBSCRIBED":
{
ResetSubscriptionTimer();
break;
}
default:
{
Debug.Console(0, this, "Error From DSP: '{0}'", args.Text);
break;
}
}
}
@@ -274,7 +279,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
/// <param name="s">Command to send</param>
public void SendLine(string s)
{
Debug.Console(2, this, "TX: '{0}'", s);
Debug.Console(1, this, "TX: '{0}'", s);
Communication.SendText(s + "\x0a");
}
@@ -285,7 +290,10 @@ namespace PepperDash.Essentials.Devices.Common.DSP
public void EnqueueCommand(QueuedCommand commandToEnqueue)
{
CommandQueue.Enqueue(commandToEnqueue);
SendNextQueuedCommand();
Debug.Console(1, this, "Command (QueuedCommand) Enqueued '{0}'. CommandQueue has '{1}' Elements.", commandToEnqueue.Command, CommandQueue.Count);
if(!CommandQueueInProgress)
SendNextQueuedCommand();
}
/// <summary>
@@ -295,7 +303,10 @@ namespace PepperDash.Essentials.Devices.Common.DSP
public void EnqueueCommand(string command)
{
CommandQueue.Enqueue(command);
SendNextQueuedCommand();
Debug.Console(1, this, "Command (string) Enqueued '{0}'. CommandQueue has '{1}' Elements.", command, CommandQueue.Count);
if (!CommandQueueInProgress)
SendNextQueuedCommand();
}
/// <summary>
@@ -304,24 +315,25 @@ namespace PepperDash.Essentials.Devices.Common.DSP
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);
//if (CommandQueue.IsEmpty)
// CommandQueueInProgress = false;
Debug.Console(1, this, "CommandQueue has {0} Elements:\n", CommandQueue.Count);
foreach (object o in CommandQueue)
{
if (o is string)
Debug.Console(2, this, "{0}", o);
Debug.Console(1, this, "{0}", o);
else if(o is QueuedCommand)
{
var item = (QueuedCommand)o;
Debug.Console(2, this, "{0}", item.Command);
Debug.Console(1, this, "{0}", item.Command);
}
}
Debug.Console(1, this, "End of CommandQueue");
if (Communication.IsConnected && !CommandQueue.IsEmpty)
{
CommandQueueInProgress = true;
@@ -341,7 +353,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
SendLine(nextCommand);
}
}
}
}
/// <summary>

View File

@@ -192,7 +192,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
var _value = Double.Parse(value);
_VolumeLevel = (ushort)Scale(_value, MinLevel, MaxLevel, 0, 65536);
_VolumeLevel = (ushort)Scale(_value, MinLevel, MaxLevel, 0, 65535);
LevelIsSubscribed = true;
@@ -220,7 +220,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
string value = match.Groups[1].Value;
Debug.Console(2, this, "{0} is {1}", attributeCode, value);
//Debug.Console(1, this, "{0} is {1}", attributeCode, value);
if (message.IndexOf("\"value\":") > -1)
{
@@ -230,12 +230,16 @@ namespace PepperDash.Essentials.Devices.Common.DSP
{
MinLevel = Double.Parse(value);
Debug.Console(1, this, "MinLevel is '{0}'", MinLevel);
break;
}
case "maxLevel":
{
MaxLevel = Double.Parse(value);
Debug.Console(1, this, "MaxLevel is '{0}'", MinLevel);
break;
}
default:
@@ -277,7 +281,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
/// <param name="level"></param>
public void SetVolume(ushort level)
{
Debug.Console(2, this, "volume: {0}", level);
Debug.Console(1, this, "volume: {0}", level);
// Unmute volume if new level is higher than existing
if (level > _VolumeLevel && AutomaticUnmuteOnVolumeUp)
if(!_IsMuted)
@@ -285,7 +289,7 @@ namespace PepperDash.Essentials.Devices.Common.DSP
double volumeLevel = Scale(level, 0, 65535, MinLevel, MaxLevel);
SendFullCommand("set", "level", volumeLevel.ToString());
SendFullCommand("set", "level", string.Format("{0:0.000000}", volumeLevel));
}
/// <summary>
@@ -318,25 +322,29 @@ namespace PepperDash.Essentials.Devices.Common.DSP
MuteOff();
}
/// <summary>
/// Scales the input from the input range to the output range
/// </summary>
/// <param name="input"></param>
/// <param name="inMin"></param>
/// <param name="inMax"></param>
/// <param name="outMin"></param>
/// <param name="outMax"></param>
/// <returns></returns>
int Scale(int input, int inMin, int inMax, int outMin, int outMax)
{
int inputRange = inMax - inMin;
///// <summary>
///// Scales the input from the input range to the output range
///// </summary>
///// <param name="input"></param>
///// <param name="inMin"></param>
///// <param name="inMax"></param>
///// <param name="outMin"></param>
///// <param name="outMax"></param>
///// <returns></returns>
//int Scale(int input, int inMin, int inMax, int outMin, int outMax)
//{
// Debug.Console(1, this, "Scaling (int) input '{0}' with min '{1}'/max '{2}' to output range min '{3}'/max '{4}'", input, inMin, inMax, outMin, outMax);
int outputRange = outMax - outMin;
// int inputRange = inMax - inMin;
var output = (((input-inMin) * outputRange) / inputRange ) - outMin;
// int outputRange = outMax - outMin;
return output;
}
// var output = (((input-inMin) * outputRange) / inputRange ) - outMin;
// Debug.Console(1, this, "Scaled output '{0}'", output);
// return output;
//}
/// <summary>
/// Scales the input from the input range to the output range
@@ -349,11 +357,20 @@ namespace PepperDash.Essentials.Devices.Common.DSP
/// <returns></returns>
double Scale(double input, double inMin, double inMax, double outMin, double outMax)
{
Debug.Console(1, this, "Scaling (double) input '{0}' with min '{1}'/max '{2}' to output range min '{3}'/max '{4}'",input ,inMin ,inMax ,outMin, outMax);
double inputRange = inMax - inMin;
if (inputRange <= 0)
{
throw new ArithmeticException(string.Format("Invalid Input Range '{0}' for Scaling. Min '{1}' Max '{2}'.", inputRange, inMin, inMax));
}
double outputRange = outMax - outMin;
var output = (((input - inMin) * outputRange) / inputRange) - outMin;
var output = (((input - inMin) * outputRange) / inputRange) + outMin;
Debug.Console(1, this, "Scaled output '{0}'", output);
return output;
}

View File

@@ -72,8 +72,17 @@ namespace PepperDash.Essentials.Devices.Common.DSP
}
}
if (command == "get")
{
// This command will generate a return value response so it needs to be queued
Parent.EnqueueCommand(new BiampTesiraForteDsp.QueuedCommand{ Command = cmd, AttributeCode = attributeCode, ControlPoint = this });
}
else
{
// This command will generate a simple "+OK" response and doesn't need to be queued
Parent.SendLine(cmd);
}
Parent.EnqueueCommand(new BiampTesiraForteDsp.QueuedCommand{ Command = cmd, AttributeCode = attributeCode, ControlPoint = this });
}
virtual public void ParseGetMessage(string attributeCode, string message)