fix: restrict tieline creation when signal types are invalid

This commit is contained in:
Andrew Welker 2026-04-02 15:22:17 -05:00
parent a82cf4f449
commit c20d49f430
2 changed files with 41 additions and 13 deletions

View file

@ -1,6 +1,6 @@
using Newtonsoft.Json; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
@ -21,24 +21,24 @@ namespace PepperDash.Essentials.Core
//public int InUseCount { get { return DestinationUsingThis.Count; } } //public int InUseCount { get { return DestinationUsingThis.Count; } }
/// <summary> /// <summary>
/// Gets the type of this tie line. Will either be the type of the destination port /// Gets the type of this tie line. Returns the intersection of signal types supported by both
/// or the type of OverrideType when it is set. /// the source and destination ports (what signals can actually travel through this tie line),
/// or the OverrideType when it is set.
/// </summary> /// </summary>
public eRoutingSignalType Type public eRoutingSignalType Type
{ {
get get
{ {
if (OverrideType.HasValue) return OverrideType.Value; if (OverrideType.HasValue) return OverrideType.Value;
return DestinationPort.Type; return SourcePort.Type & DestinationPort.Type;
} }
} }
/// <summary> /// <summary>
/// Use this to override the Type property for the destination port. For example, /// Use this to override the Type property. For example, when both ports support AudioVideo
/// when the tie line is type AudioVideo, and the signal flow should be limited to /// but the physical cable only carries Audio or Video, setting this will limit the signal
/// Audio-only or Video only, changing this type will alter the signal paths /// paths available to the routing algorithm without affecting the actual port types.
/// available to the routing algorithm without affecting the actual Type /// When set, this value is used instead of the calculated intersection of source and destination types.
/// of the destination port.
/// </summary> /// </summary>
public eRoutingSignalType? OverrideType { get; set; } public eRoutingSignalType? OverrideType { get; set; }
@ -79,7 +79,7 @@ namespace PepperDash.Essentials.Core
/// </summary> /// </summary>
/// <param name="sourcePort">The source output port.</param> /// <param name="sourcePort">The source output port.</param>
/// <param name="destinationPort">The destination input port.</param> /// <param name="destinationPort">The destination input port.</param>
/// <param name="overrideType">The signal type to limit the link to. Overrides DestinationPort.Type for routing calculations.</param> /// <param name="overrideType">The signal type to limit the link to. Overrides the calculated intersection of port types for routing calculations.</param>
public TieLine(RoutingOutputPort sourcePort, RoutingInputPort destinationPort, eRoutingSignalType? overrideType) : public TieLine(RoutingOutputPort sourcePort, RoutingInputPort destinationPort, eRoutingSignalType? overrideType) :
this(sourcePort, destinationPort) this(sourcePort, destinationPort)
{ {
@ -91,7 +91,7 @@ namespace PepperDash.Essentials.Core
/// </summary> /// </summary>
/// <param name="sourcePort">The source output port.</param> /// <param name="sourcePort">The source output port.</param>
/// <param name="destinationPort">The destination input port.</param> /// <param name="destinationPort">The destination input port.</param>
/// <param name="overrideType">The signal type to limit the link to. Overrides DestinationPort.Type for routing calculations.</param> /// <param name="overrideType">The signal type to limit the link to. Overrides the calculated intersection of port types for routing calculations.</param>
public TieLine(RoutingOutputPort sourcePort, RoutingInputPort destinationPort, eRoutingSignalType overrideType) : public TieLine(RoutingOutputPort sourcePort, RoutingInputPort destinationPort, eRoutingSignalType overrideType) :
this(sourcePort, destinationPort) this(sourcePort, destinationPort)
{ {

View file

@ -49,7 +49,9 @@ namespace PepperDash.Essentials.Core.Config
public string DestinationPort { get; set; } public string DestinationPort { get; set; }
/// <summary> /// <summary>
/// Optional override for the signal type of the tie line. If set, this overrides the destination port's type for routing calculations. /// Optional override for the signal type of the tie line. If set, this overrides the calculated
/// intersection of source and destination port types for routing calculations. Useful when the
/// physical cable supports fewer signal types than both ports are capable of.
/// </summary> /// </summary>
[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
@ -96,6 +98,32 @@ namespace PepperDash.Essentials.Core.Config
return null; return null;
} }
// Validate signal type compatibility
if (OverrideType.HasValue)
{
// When override type is specified, both ports must support it
if (!sourceOutputPort.Type.HasFlag(OverrideType.Value))
{
LogError($"Override type '{OverrideType.Value}' is not supported by source port '{SourcePort}' (type: {sourceOutputPort.Type})");
return null;
}
if (!destinationInputPort.Type.HasFlag(OverrideType.Value))
{
LogError($"Override type '{OverrideType.Value}' is not supported by destination port '{DestinationPort}' (type: {destinationInputPort.Type})");
return null;
}
}
else
{
// Without override type, ports must have at least one common signal type flag
if ((sourceOutputPort.Type & destinationInputPort.Type) == 0)
{
LogError($"Incompatible signal types: source port '{SourcePort}' (type: {sourceOutputPort.Type}) has no common signal types with destination port '{DestinationPort}' (type: {destinationInputPort.Type})");
return null;
}
}
return new TieLine(sourceOutputPort, destinationInputPort, OverrideType); return new TieLine(sourceOutputPort, destinationInputPort, OverrideType);
} }