Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rs22 committed Jan 14, 2024
1 parent f9fc471 commit c0a0f9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/Point/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public async Task SendSciMessage(SciMessage message)
public void EnableInitializationTimeout(bool enableInitializationTimeout)
{
if (Connection == null) throw new InvalidOperationException("Connection is null. Did you call Connect()?");
_logger.LogInformation("Reset and Timeout on next initialization handshake enabled.");
_logger.LogInformation("Timeout on next initialization handshake enabled: {}.", enableInitializationTimeout ? "yes" : "no");
_simulatedPointState = _simulatedPointState with
{
SimulateInitializationTimeout = enableInitializationTimeout
Expand Down Expand Up @@ -347,9 +347,11 @@ private async Task HandleCommandedPointPosition(GenericPointPosition commandedPo
if (Connection == null) throw new InvalidOperationException("Connection is null. Did you call Connect()?");
_logger.LogDebug("Moving to {}.", commandedPointPosition);

if (PointState.PointPosition != GenericPointPosition.NoEndPosition)
var notDegradedPosition = AllPointMachinesCrucial ? GenericDegradedPointPosition.NotApplicable : GenericDegradedPointPosition.NotDegraded;

if (PointState.PointPosition != GenericPointPosition.NoEndPosition || PointState.DegradedPointPosition != notDegradedPosition)
{
SetPointState(GenericPointPosition.NoEndPosition, RespectAllPointMachinesCrucial(PointState.DegradedPointPosition));
SetPointState(GenericPointPosition.NoEndPosition, notDegradedPosition);
await Connection.SendPointPosition(PointState);
}

Expand All @@ -368,24 +370,29 @@ private async Task HandleCommandedPointPosition(GenericPointPosition commandedPo
await Connection.SendTimeoutMessage();

var (pointPosition, degradedPointPosition) = HandlePreventedPointPosition(commandedPointPosition, simulatedState);
var sendPointPosition = pointPosition != PointState.PointPosition || degradedPointPosition != PointState.DegradedPointPosition;

SetPointState(pointPosition, degradedPointPosition);

await Connection.SendPointPosition(PointState);
if (sendPointPosition)
await Connection.SendPointPosition(PointState);
_logger.LogInformation("Prevented left end position: {} {}.", PointState.PointPosition, PointState.DegradedPointPosition);
}
else if (commandedPointPosition == GenericPointPosition.Right && simulatedState.PreventedPositionRight != PreventedPosition.DoNotPrevent)
{
await Connection.SendTimeoutMessage();

var (pointPosition, degradedPointPosition) = HandlePreventedPointPosition(commandedPointPosition, simulatedState);
var sendPointPosition = pointPosition != PointState.PointPosition || degradedPointPosition != PointState.DegradedPointPosition;

SetPointState(pointPosition, degradedPointPosition);

await Connection.SendPointPosition(PointState);
if (sendPointPosition)
await Connection.SendPointPosition(PointState);
_logger.LogInformation("Prevented right end position: {} {}.", PointState.PointPosition, PointState.DegradedPointPosition);
}
else
{
var notDegradedPosition = AllPointMachinesCrucial ? GenericDegradedPointPosition.NotApplicable : GenericDegradedPointPosition.NotDegraded;
SetPointState(commandedPointPosition, notDegradedPosition);

_logger.LogInformation("End position reached.");
Expand Down
4 changes: 2 additions & 2 deletions src/Point/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
{ "--initial-point-position", "PointSettings:InitialPointPosition" },
{ "--initial-degraded-point-position", "PointSettings:InitialDegradedPointPosition" },
{ "--initial-ability-to-move", "PointSettings:InitialAbilityToMove" },
{ "--pdi-version", "PointSettings:PDIVersion"},
{ "--pdi-checksum", "PointSettings:PDIChecksum"}
{ "--pdi-version", "PointSettings:PDIVersion" },
{ "--pdi-checksum", "PointSettings:PDIChecksum" }
};
webBuilder
.ConfigureAppConfiguration((hostingContext, config) =>
Expand Down

0 comments on commit c0a0f9e

Please sign in to comment.