Skip to content

Commit

Permalink
update proto & UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Scretch9 committed Jan 4, 2024
1 parent 49c803d commit 29fe204
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 46 deletions.
6 changes: 3 additions & 3 deletions src/FieldElementSubsystems.Test/Point/PointTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ public async Task Test_AbilityToMove(AbilityToMove simulatedAbilityToMove, Gener

connection
.SetupSequence(m => m.ReceiveMovePointCommand(It.IsAny<CancellationToken>()))
.Returns(() =>
.Returns(async () =>
{
var message = new AbilityToMoveMessage
{
Ability = simulatedAbilityToMove
};
point.SetAbilityToMove(message);
return Task.FromResult(GenericPointPosition.Left);
await point.SetAbilityToMove(message);
return GenericPointPosition.Left;
})
.Returns(() =>
{
Expand Down
1 change: 1 addition & 0 deletions src/Point/IPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IPoint {

void EnableTimeoutLeft(bool enableMovementFailed);
void EnableTimeoutRight(bool enableMovementFailed);
void EnableInitializationTimeout(bool enableInitializationFailed);
void PreventLeftEndPosition(PreventedPositionMessage request);
void PreventRightEndPosition(PreventedPositionMessage request);
Task PutIntoUnintendedPosition(DegradedPositionMessage request);
Expand Down
9 changes: 4 additions & 5 deletions src/Point/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Point(ILogger<Point> logger, IConfiguration configuration, IPointToInterl
DegradedPositionRight: false,
SimulateTimeoutLeft: false,
SimulateTimeoutRight: false,
SimulateInitialisationTimeout: false
SimulateInitializationTimeout: false
);

Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>(h => PropertyChanged += h, h => PropertyChanged -= h)
Expand All @@ -100,16 +100,15 @@ public async Task SendSciMessage(SciMessage message)
}

/// <summary>
/// Sets the timeout flag for the next move left command.
/// Sets the sets the initialization timeout flag for the next initialization.
/// </summary>
public void EnableInitializationTimeout(bool enableInitialisationTimeout)
{
_logger.LogInformation("Reset and Timeout on next initialisation handshake enabled.");
_simulatedPointState = _simulatedPointState with
{
SimulateInitialisationTimeout = enableInitialisationTimeout
SimulateInitializationTimeout = enableInitialisationTimeout
};
Reset();
}

/// <summary>
Expand Down Expand Up @@ -268,7 +267,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

try
{
var success = await Connection.InitializeConnection(PointState, _config.ObserveAbilityToMove, _simulatedPointState.SimulateInitialisationTimeout, _resetTokenSource.Token);
var success = await Connection.InitializeConnection(PointState, _config.ObserveAbilityToMove, _simulatedPointState.SimulateInitializationTimeout, _resetTokenSource.Token);
if (!success)
{
throw new Exception("Unable to initialize connection");
Expand Down
6 changes: 6 additions & 0 deletions src/Point/Services/PointService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public override async Task<Empty> OverrideSciMessage(SciMessage request, ServerC
return new Empty();
}

public override Task<Empty> ScheduleInitializationTimeout(EnableInitializationFailedMessage request, ServerCallContext context)
{
_point.EnableInitializationTimeout(request.EnableInitializationFailed);
return Task.FromResult(new Empty());
}

public override Task<Empty> SchedulePreventLeftEndPosition(PreventedPositionMessage request, ServerCallContext context)
{
_point.PreventLeftEndPosition(request);
Expand Down
2 changes: 1 addition & 1 deletion src/Point/SimulatedPointState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public record SimulatedPointState(
bool DegradedPositionRight,
bool SimulateTimeoutLeft,
bool SimulateTimeoutRight,
bool SimulateInitialisationTimeout
bool SimulateInitializationTimeout
);
}
3 changes: 2 additions & 1 deletion src/Point/rasta-point-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export type SimulatedPointState = {
'degradedPositionLeft': boolean,
'degradedPositionRight': boolean,
'simulateTimeoutLeft': boolean,
'simulateTimeoutRight': boolean
'simulateTimeoutRight': boolean,
'simulateInitializationTimeout': boolean
};

export type SimulatorConfiguration = {
Expand Down
26 changes: 19 additions & 7 deletions src/Point/rasta-point-web/src/Point.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PointClient } from './proto/PointServiceClientPb';

import {
PreventedPosition, AbilityToMoveMessage, AbilityToMove, PreventedPositionMessage, DegradedPositionMessage, EnableMovementFailedMessage,
EnableInitializationFailedMessage,
} from './proto/point_pb';
import { PointState, SimulatedPointState, SimulatorConfiguration } from './App';

Expand Down Expand Up @@ -345,14 +346,25 @@ function Point({
<SemiBoldPropertyLabel>
Connectivity
</SemiBoldPropertyLabel>
<button
type="button"
onClick={() => sendCommand((client) => client.reset(new google_protobuf_empty_pb.Empty(), null))}
className="m-3 btn dark:bg-slate-800 border-slate-200 dark:border-slate-700 hover:border-slate-300 dark:hover:border-slate-600 text-rose-500"
>
Reset RaSTA Connection
<div className="grid grid-flow-col">
<button
type="button"
onClick={() => sendCommand((client) => client.reset(new google_protobuf_empty_pb.Empty(), null))}
className="m-3 btn dark:bg-slate-800 border-slate-200 dark:border-slate-700 hover:border-slate-300 dark:hover:border-slate-600 text-rose-500"
>
Reset RaSTA Connection

</button>
</button>
<div>
<Toggle
label="Enable Initialization Timeout"
active={simulatedPointState?.simulateInitializationTimeout || false}
onChange={
(enable) => sendCommand((client) => client.scheduleInitializationTimeout(new EnableInitializationFailedMessage().setEnableinitializationfailed(enable), null))
}
/>
</div>
</div>
</div>
</div>

Expand Down
Loading

0 comments on commit 29fe204

Please sign in to comment.