From c37ffc2e8bc03d6600ec4defa8c547a5f7a7b395 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Fri, 1 Dec 2023 10:15:45 +0100 Subject: [PATCH] add proto getDegradedPointPosition --- .../ReportedPointPositionProtoConversion.cs | 46 ++++++++++++++----- src/Point/Services/PointService.cs | 10 ++++ src/ProtobufInterfaces/proto/point.proto | 12 +++++ 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs index 2ae254d..2345c54 100644 --- a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs +++ b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs @@ -1,26 +1,50 @@ -using EulynxLive.Point.Proto; +using ProtoDegradedPointPosition = EulynxLive.Point.Proto.PointDegradedPosition; +using ProtoPointPosition = EulynxLive.Point.Proto.PointPosition; using ReportedPointPosition = EulynxLive.Point.Interfaces.IPointToInterlockingConnection.PointPosition ; +using DegradedPointPosition = EulynxLive.Point.Interfaces.IPointToInterlockingConnection.DegradedPointPosition ; namespace Point.Services.Extensions { public static class ReportedPointPositionProtoConversion { - public static PointPosition ConvertToProtoMessage(this ReportedPointPosition reportedPointPosition) => reportedPointPosition switch + public static ProtoPointPosition ConvertToProtoMessage(this ReportedPointPosition reportedPointPosition) => reportedPointPosition switch { - ReportedPointPosition.Right => PointPosition.Right, - ReportedPointPosition.Left => PointPosition.Left, - ReportedPointPosition.NoEndposition => PointPosition.NoEndPosition, - ReportedPointPosition.UnintendetPosition => PointPosition.UnintendedPosition, + ReportedPointPosition.Right => ProtoPointPosition.Right, + ReportedPointPosition.Left => ProtoPointPosition.Left, + ReportedPointPosition.NoEndposition => ProtoPointPosition.NoEndPosition, + ReportedPointPosition.UnintendetPosition => ProtoPointPosition.UnintendedPosition, _ => throw new InvalidCastException($"Unable to convert reported point position {reportedPointPosition} to proto enum") }; - public static ReportedPointPosition ConvertToReportedPointPosition(this PointPosition pointPositionMessage) => pointPositionMessage switch + public static ReportedPointPosition ConvertToReportedPointPosition(this ProtoPointPosition pointPositionMessage) => pointPositionMessage switch { - PointPosition.Right => ReportedPointPosition.Right, - PointPosition.Left => ReportedPointPosition.Left, - PointPosition.NoEndPosition => ReportedPointPosition.NoEndposition, - PointPosition.UnintendedPosition => ReportedPointPosition.UnintendetPosition, + ProtoPointPosition.Right => ReportedPointPosition.Right, + ProtoPointPosition.Left => ReportedPointPosition.Left, + ProtoPointPosition.NoEndPosition => ReportedPointPosition.NoEndposition, + ProtoPointPosition.UnintendedPosition => ReportedPointPosition.UnintendetPosition, + _ => throw new InvalidCastException($"Unable to convert point position message {pointPositionMessage} to reported point position.") + }; + } + + + public static class DegradedPointPositionProtoConversion + { + public static ProtoDegradedPointPosition ConvertToProtoMessage(this DegradedPointPosition reportedPointPosition) => reportedPointPosition switch + { + DegradedPointPosition.DegradedRight => ProtoDegradedPointPosition.DegradedRight, + DegradedPointPosition.DegradedLeft => ProtoDegradedPointPosition.DegradedLeft, + DegradedPointPosition.NotDegraded => ProtoDegradedPointPosition.NotDegraded, + DegradedPointPosition.NotApplicable => ProtoDegradedPointPosition.NotApplicable, + _ => throw new InvalidCastException($"Unable to convert reported point position {reportedPointPosition} to proto enum") + }; + + public static DegradedPointPosition ConvertToReportedPointPosition(this ProtoDegradedPointPosition pointPositionMessage) => pointPositionMessage switch + { + ProtoDegradedPointPosition.DegradedRight => DegradedPointPosition.DegradedRight, + ProtoDegradedPointPosition.DegradedLeft => DegradedPointPosition.DegradedLeft, + ProtoDegradedPointPosition.NotDegraded => DegradedPointPosition.NotDegraded, + ProtoDegradedPointPosition.NotApplicable => DegradedPointPosition.NotApplicable, _ => throw new InvalidCastException($"Unable to convert point position message {pointPositionMessage} to reported point position.") }; } diff --git a/src/Point/Services/PointService.cs b/src/Point/Services/PointService.cs index 4311670..e002633 100644 --- a/src/Point/Services/PointService.cs +++ b/src/Point/Services/PointService.cs @@ -29,6 +29,16 @@ public override async Task PutInEndPosition(Empty request, ServerCallCont return new Empty(); } + public override Task GetDegradedPointPosition(Empty request, ServerCallContext context) + { + var response = new PointDegradedPositionMessage() + { + Position = _point.PointState.DegradedPointPosition.ConvertToProtoMessage() + }; + + return Task.FromResult(response); + } + public override Task GetPointPosition(Empty request, ServerCallContext context) { var response = new PointPositionMessage() diff --git a/src/ProtobufInterfaces/proto/point.proto b/src/ProtobufInterfaces/proto/point.proto index d02fd95..19a2c43 100644 --- a/src/ProtobufInterfaces/proto/point.proto +++ b/src/ProtobufInterfaces/proto/point.proto @@ -12,6 +12,13 @@ enum PointPosition { UnintendedPosition = 3; } +enum PointDegradedPosition { + DegradedRight = 0; + DegradedLeft = 1; + NotDegraded = 2; + NotApplicable = 3; +} + enum PreventedPosition { PreventedLeft = 0; PreventedRight = 1; @@ -23,6 +30,7 @@ service Point { rpc PreventEndPosition (PreventedPositionMessage) returns (google.protobuf.Empty) {} rpc PutInEndPosition (google.protobuf.Empty) returns (google.protobuf.Empty) {} rpc GetPointPosition (google.protobuf.Empty) returns (PointPositionMessage) {} + rpc GetDegradedPointPosition (google.protobuf.Empty) returns (PointDegradedPositionMessage) {} rpc EstablishPointMachineState (PointMachineStateMessage) returns (google.protobuf.Empty) {} rpc GetPointMachineState (google.protobuf.Empty) returns (PointMachineStateMessage) {} @@ -36,6 +44,10 @@ message PointPositionMessage { PointPosition position = 1; } +message PointDegradedPositionMessage { + PointDegradedPosition position = 1; +} + message PointMachineStateMessage { enum Target { Target_UNDEFINED = 0;