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

View File

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

View File

@@ -70,10 +70,19 @@ namespace PepperDash.Essentials.Devices.Common.DSP
{ {
cmd = string.Format("{0} {1} {2}", InstanceTag, command, attributeCode); cmd = string.Format("{0} {1} {2}", InstanceTag, command, attributeCode);
} }
}
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) virtual public void ParseGetMessage(string attributeCode, string message)