Skip to content

Commit

Permalink
IOconfInput/Output: Refactored GetExpandedSensorNames and GetExpanded…
Browse files Browse the repository at this point in the history
…Conf. (#365)
  • Loading branch information
LarsWithCA authored Mar 3, 2025
1 parent 79d3826 commit 04b4ddc
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CA_DataUploaderLib/IOconf/IOconfFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ IEnumerable<string> GetBoardStateNamesForSensors(IEnumerable<string> sensors, Ha
sensorsChecked.UnionWith(sensors);
foreach (var input in GetEntries<IOconfRow>().Where(e => e is IIOconfRowWithBoardState))
{
if (newSensors.Intersect(input.GetExpandedSensorNames(this)).Any())
if (newSensors.Intersect(input.GetExpandedSensorNames()).Any())
yield return ((IIOconfRowWithBoardState)input).BoardStateName;
}

Expand Down
2 changes: 1 addition & 1 deletion CA_DataUploaderLib/IOconf/IOconfFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public IOconfFilter(string row, int lineNum) : base(row, lineNum, "Filter")
public static List<LegacyFilter> LegacyFilters(IEnumerable<IOconfFilter> filters) => filters.Select(f => f._legacyFilter).OfType<LegacyFilter>().ToList();
public static List<DecisionFilter> DecisionFilters(IEnumerable<IOconfFilter> filters) => filters.Select(f => f._decisionFilter).OfType<DecisionFilter>().ToList();

public override IEnumerable<string> GetExpandedSensorNames(IIOconf ioconf)
public override IEnumerable<string> GetExpandedSensorNames()
{
yield return NameInVector;
}
Expand Down
11 changes: 5 additions & 6 deletions CA_DataUploaderLib/IOconf/IOconfInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void ValidateDependencies(IIOconf ioconf)
Map = GetMap(ioconf, BoxName, _boardSettings, Skip);
}

public override IEnumerable<string> GetExpandedSensorNames(IIOconf ioconf)
public override IEnumerable<string> GetExpandedSensorNames()
{
yield return Name;
}
Expand Down Expand Up @@ -107,12 +107,11 @@ public override void ValidateDependencies(IIOconf ioconf)
Map = GetMap(ioconf, BoxName, _boardSettings, false);
}

public virtual IEnumerable<IOconfInput> GetExpandedConf() => [];

public override IEnumerable<string> GetExpandedSensorNames(IIOconf ioconf)
public virtual IEnumerable<IOconfInput> GetExpandedConf()
{
foreach (var input in GetExpandedConf())
yield return input.Name;
var portNumber = PortNumber;
foreach (var input in GetExpandedSensorNames())
yield return NewInput(input, portNumber++);
}

public string BoxName { get; }
Expand Down
6 changes: 3 additions & 3 deletions CA_DataUploaderLib/IOconf/IOconfMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace CA_DataUploaderLib.IOconf
{
public class IOconfMath : IOconfRow
{
/// <summary>gets the sources (other vector values) listed explicitely in the math expression</summary>
/// <summary>gets the sources (other vector values) listed explicitly in the math expression</summary>
/// <remarks>
/// Note the sources may include the math expression itself, which is the expression refering to its value in the previous cycle.
/// Note the sources may include the math expression itself, which is the expression referring to its value in the previous cycle.
/// Also note that the sources returned may also refer to the math expression.
/// </remarks>
public List<string> SourceNames { get; }
Expand Down Expand Up @@ -42,7 +42,7 @@ public static (LogicalExpression expression, List<string> sources) CompileExpres
return (compiledExpression, sourceNames);
}

public override IEnumerable<string> GetExpandedSensorNames(IIOconf ioconf)
public override IEnumerable<string> GetExpandedSensorNames()
{
yield return Name;
}
Expand Down
11 changes: 6 additions & 5 deletions CA_DataUploaderLib/IOconf/IOconfOut230Vac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ public IOconfOut230Vac(string row, int lineNum, string type) : base(row, lineNum

public string CurrentSensorName { get; }
public bool IsSwitchboardControllerOutput { get; }
public override IEnumerable<IOconfInput> GetExpandedInputConf()
{ // note "_onoff" is not included as its not an input but the current expected on/off state as seen by the control loop.
yield return NewPortInput(CurrentSensorName, 0 + PortNumber);

public override IEnumerable<string> GetExpandedSensorNames()
{
yield return CurrentSensorName;
}

public override IEnumerable<string> GetExpandedSensorNames(IIOconf ioconf)
public override IEnumerable<string> GetExpandedNames(IIOconf ioconf)
{
yield return Name;
foreach (var name in base.GetExpandedSensorNames(ioconf))
foreach (var name in base.GetExpandedNames(ioconf))
yield return name;
}

Expand Down
11 changes: 4 additions & 7 deletions CA_DataUploaderLib/IOconf/IOconfOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ public IOconfOutput(string row, int lineNum, string type, bool parsePort, BoardS
if (PortNumber < 1) throw new Exception($"{type}: port numbers must start at 1 {row}");
}

public virtual IEnumerable<IOconfInput> GetExpandedInputConf() => [];
protected IEnumerable<IOconfInput> GetExpandedInputConf(IEnumerable<string> suffixes) =>
suffixes.Select((s, i) => NewPortInput($"{Name}_{s}", PortNumber + i));

public override IEnumerable<string> GetExpandedSensorNames(IIOconf ioconf)
public virtual IEnumerable<IOconfInput> GetExpandedInputConf()
{
foreach (var input in GetExpandedInputConf())
yield return input.Name;
var portNumber = PortNumber;
foreach (var input in GetExpandedSensorNames())
yield return NewPortInput(input, portNumber++);
}

public override void ValidateDependencies(IIOconf ioconf)
Expand Down
7 changes: 2 additions & 5 deletions CA_DataUploaderLib/IOconf/IOconfRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,14 @@ protected virtual void ValidateName(string name)
/// <summary>
/// Returns the list of expanded vector field names from this class.
/// </summary>
public virtual IEnumerable<string> GetExpandedSensorNames(IIOconf ioconf)
{
return [];
}
public virtual IEnumerable<string> GetExpandedSensorNames() => [];

/// <summary>
/// Returns the full list of expanded vector field names from this class and it's associated decisions.
/// </summary>
public virtual IEnumerable<string> GetExpandedNames(IIOconf ioconf)
{
foreach (var name in GetExpandedSensorNames(ioconf))
foreach (var name in GetExpandedSensorNames())
yield return name;
if (this is IIOconfRowWithDecision entryWithDecision)
{
Expand Down
4 changes: 3 additions & 1 deletion CA_DataUploaderLib/Redundancy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class IOconfRedundant : IOconfRow
{
protected IOconfRedundant(string row, int lineNum, string type) : base(row, lineNum, type) { }

public override IEnumerable<string> GetExpandedSensorNames() => [Name];

public static IEnumerable<Decision.Config> ToDecisionConfigs(IEnumerable<IOconfRedundant> redundants, IIOconf ioconf)
{
var invalidValueDelay = redundants.OfType<IOconfRedundantInvalidValueDelay>().SingleOrDefault()?.InvalidValueDelay ?? 0;
Expand Down Expand Up @@ -63,7 +65,7 @@ public IOconfRedundantSensors(string row, int lineNum) : base(row, lineNum, RowT
public override void ValidateDependencies(IIOconf ioconf)
{
foreach (var sensor in Sensors)
if (!ioconf.GetEntries<IOconfRow>().Any(e => e.GetExpandedSensorNames(ioconf).Contains(sensor)))
if (!ioconf.GetEntries<IOconfRow>().Any(e => e.GetExpandedSensorNames().Contains(sensor)))
throw new FormatException($"Failed to find {sensor} for {RowType}: {Row}");
}

Expand Down

0 comments on commit 04b4ddc

Please sign in to comment.