From 0f44700486d12bc9e222e8b067da9d77ddb2406e Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Wed, 2 Feb 2022 09:12:58 -0500 Subject: [PATCH] Fixes issue where if DMPS audio min and max levels were set to the same value, a divide by zero exception would occur. Adds try-catch to output card constructor so single output card failing won't break all routing. --- .../Chassis/DmpsAudioOutputController.cs | 17 ++- .../Chassis/DmpsRoutingController.cs | 119 +++++++++--------- 2 files changed, 76 insertions(+), 60 deletions(-) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsAudioOutputController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsAudioOutputController.cs index 751c1a5a..aa839873 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsAudioOutputController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsAudioOutputController.cs @@ -411,10 +411,13 @@ namespace PepperDash.Essentials.DM public void SetVolumeScaled(ushort level) { Debug.Console(2, Debug.ErrorLogLevel.None, "Scaling DMPS volume:{0} level:{1} min:{2} max:{3}", Output.Name, level.ToString(), MinLevel.ToString(), MaxLevel.ToString()); - VolumeLevelInput = (ushort)(level * (MaxLevel - MinLevel) / ushort.MaxValue + MinLevel); - if (EnableVolumeSend == true) + if (ushort.MaxValue + MinLevel != 0) { - Level.UShortValue = VolumeLevelInput; + VolumeLevelInput = (ushort)(level * (MaxLevel - MinLevel) / ushort.MaxValue + MinLevel); + if (EnableVolumeSend == true) + { + Level.UShortValue = VolumeLevelInput; + } } } @@ -422,7 +425,13 @@ namespace PepperDash.Essentials.DM { short signedLevel = (short)level; Debug.Console(2, Debug.ErrorLogLevel.None, "Scaling DMPS volume:{0} feedback:{1} min:{2} max:{3}", Output.Name, signedLevel.ToString(), MinLevel.ToString(), MaxLevel.ToString()); - return (ushort)((signedLevel - MinLevel) * ushort.MaxValue / (MaxLevel - MinLevel)); + + if (MaxLevel - MinLevel != 0) + { + return (ushort)((signedLevel - MinLevel) * ushort.MaxValue / (MaxLevel - MinLevel)); + } + else + return (ushort)MinLevel; } public void SendScaledVolume(bool pressRelease) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsRoutingController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsRoutingController.cs index f6592699..4bdee5df 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsRoutingController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsRoutingController.cs @@ -481,69 +481,76 @@ namespace PepperDash.Essentials.DM { foreach (var card in Dmps.SwitcherOutputs) { - Debug.Console(1, this, "Output Card Type: {0}", card.CardInputOutputType); - - var outputCard = card as DMOutput; - - if (outputCard == null) + try { - Debug.Console(1, this, "Output card {0} is not a DMOutput", card.CardInputOutputType); - continue; - } + Debug.Console(1, this, "Output Card Type: {0}", card.CardInputOutputType); - Debug.Console(1, this, "Adding Output Card Number {0} Type: {1}", outputCard.Number, outputCard.CardInputOutputType.ToString()); - VideoOutputFeedbacks[outputCard.Number] = new IntFeedback(() => - { - if (outputCard.VideoOutFeedback != null) { return (ushort)outputCard.VideoOutFeedback.Number; } - return 0; - ; - }); - AudioOutputFeedbacks[outputCard.Number] = new IntFeedback(() => - { - try + var outputCard = card as DMOutput; + + if (outputCard == null) { - if (outputCard.AudioOutFeedback != null) - { - return (ushort) outputCard.AudioOutFeedback.Number; - } + Debug.Console(1, this, "Output card {0} is not a DMOutput", card.CardInputOutputType); + continue; + } + + Debug.Console(1, this, "Adding Output Card Number {0} Type: {1}", outputCard.Number, outputCard.CardInputOutputType.ToString()); + VideoOutputFeedbacks[outputCard.Number] = new IntFeedback(() => + { + if (outputCard.VideoOutFeedback != null) { return (ushort)outputCard.VideoOutFeedback.Number; } return 0; - } - catch (NotSupportedException) + ; + }); + AudioOutputFeedbacks[outputCard.Number] = new IntFeedback(() => { - return (ushort) outputCard.AudioOutSourceFeedback; - } - }); + try + { + if (outputCard.AudioOutFeedback != null) + { + return (ushort)outputCard.AudioOutFeedback.Number; + } + return 0; + } + catch (NotSupportedException) + { + return (ushort)outputCard.AudioOutSourceFeedback; + } + }); - OutputNameFeedbacks[outputCard.Number] = new StringFeedback(() => + OutputNameFeedbacks[outputCard.Number] = new StringFeedback(() => + { + if (outputCard.NameFeedback != null && outputCard.NameFeedback != CrestronControlSystem.NullStringOutputSig && !string.IsNullOrEmpty(outputCard.NameFeedback.StringValue)) + { + Debug.Console(2, this, "Output Card {0} Name: {1}", outputCard.Number, outputCard.NameFeedback.StringValue); + return outputCard.NameFeedback.StringValue; + } + return ""; + }); + + OutputVideoRouteNameFeedbacks[outputCard.Number] = new StringFeedback(() => + { + if (outputCard.VideoOutFeedback != null && outputCard.VideoOutFeedback.NameFeedback != null) + { + return outputCard.VideoOutFeedback.NameFeedback.StringValue; + } + return NoRouteText; + }); + OutputAudioRouteNameFeedbacks[outputCard.Number] = new StringFeedback(() => + { + if (outputCard.AudioOutFeedback != null && outputCard.AudioOutFeedback.NameFeedback != null) + { + return outputCard.AudioOutFeedback.NameFeedback.StringValue; + } + return NoRouteText; + }); + + OutputEndpointOnlineFeedbacks[outputCard.Number] = new BoolFeedback(() => outputCard.EndpointOnlineFeedback); + + AddOutputCard(outputCard.Number, outputCard); + } + catch (Exception ex) { - if (outputCard.NameFeedback != null && outputCard.NameFeedback != CrestronControlSystem.NullStringOutputSig && !string.IsNullOrEmpty(outputCard.NameFeedback.StringValue)) - { - Debug.Console(2, this, "Output Card {0} Name: {1}", outputCard.Number, outputCard.NameFeedback.StringValue); - return outputCard.NameFeedback.StringValue; - } - return ""; - }); - - OutputVideoRouteNameFeedbacks[outputCard.Number] = new StringFeedback(() => - { - if (outputCard.VideoOutFeedback != null && outputCard.VideoOutFeedback.NameFeedback != null) - { - return outputCard.VideoOutFeedback.NameFeedback.StringValue; - } - return NoRouteText; - }); - OutputAudioRouteNameFeedbacks[outputCard.Number] = new StringFeedback(() => - { - if (outputCard.AudioOutFeedback != null && outputCard.AudioOutFeedback.NameFeedback != null) - { - return outputCard.AudioOutFeedback.NameFeedback.StringValue; - } - return NoRouteText; - }); - - OutputEndpointOnlineFeedbacks[outputCard.Number] = new BoolFeedback(() => outputCard.EndpointOnlineFeedback); - - AddOutputCard(outputCard.Number, outputCard); + Debug.LogError(Debug.ErrorLogLevel.Error, string.Format("DMPS Controller exception creating output card: {0}", ex)); + } } }