Skip to content

Commit

Permalink
add proto getDegradedPointPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
Scretch9 committed Dec 1, 2023
1 parent 55fb688 commit c37ffc2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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.")
};
}
Expand Down
10 changes: 10 additions & 0 deletions src/Point/Services/PointService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public override async Task<Empty> PutInEndPosition(Empty request, ServerCallCont
return new Empty();
}

public override Task<PointDegradedPositionMessage> GetDegradedPointPosition(Empty request, ServerCallContext context)
{
var response = new PointDegradedPositionMessage()
{
Position = _point.PointState.DegradedPointPosition.ConvertToProtoMessage()
};

return Task.FromResult(response);
}

public override Task<PointPositionMessage> GetPointPosition(Empty request, ServerCallContext context)
{
var response = new PointPositionMessage()
Expand Down
12 changes: 12 additions & 0 deletions src/ProtobufInterfaces/proto/point.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ enum PointPosition {
UnintendedPosition = 3;
}

enum PointDegradedPosition {
DegradedRight = 0;
DegradedLeft = 1;
NotDegraded = 2;
NotApplicable = 3;
}

enum PreventedPosition {
PreventedLeft = 0;
PreventedRight = 1;
Expand All @@ -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) {}
Expand All @@ -36,6 +44,10 @@ message PointPositionMessage {
PointPosition position = 1;
}

message PointDegradedPositionMessage {
PointDegradedPosition position = 1;
}

message PointMachineStateMessage {
enum Target {
Target_UNDEFINED = 0;
Expand Down

0 comments on commit c37ffc2

Please sign in to comment.