From efb21ded1510c24120ec2a2ad2a4a643d1eb5d70 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Tue, 14 Nov 2023 15:30:50 +0100 Subject: [PATCH 01/14] update .Net --- src/Point/Point.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Point/Point.csproj b/src/Point/Point.csproj index 48dadac..a9e9a16 100644 --- a/src/Point/Point.csproj +++ b/src/Point/Point.csproj @@ -1,7 +1,7 @@ - net6.0 + net7.0 true latest false From 43f922f8439c35c15df24e4d1a5dc79c42f85ee3 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Tue, 14 Nov 2023 15:31:49 +0100 Subject: [PATCH 02/14] update proto files --- .../src/proto/PointServiceClientPb.ts | 258 +++++ .../rasta-point-web/src/proto/point_pb.d.ts | 142 +++ .../rasta-point-web/src/proto/point_pb.js | 977 ++++++++++++++++++ src/ProtobufInterfaces/Readme.md | 12 + src/ProtobufInterfaces/proto/point.proto | 5 + 5 files changed, 1394 insertions(+) create mode 100644 src/Point/rasta-point-web/src/proto/PointServiceClientPb.ts create mode 100644 src/Point/rasta-point-web/src/proto/point_pb.d.ts create mode 100644 src/Point/rasta-point-web/src/proto/point_pb.js create mode 100644 src/ProtobufInterfaces/Readme.md diff --git a/src/Point/rasta-point-web/src/proto/PointServiceClientPb.ts b/src/Point/rasta-point-web/src/proto/PointServiceClientPb.ts new file mode 100644 index 0000000..9f5ecdc --- /dev/null +++ b/src/Point/rasta-point-web/src/proto/PointServiceClientPb.ts @@ -0,0 +1,258 @@ +/** + * @fileoverview gRPC-Web generated client stub for point + * @enhanceable + * @public + */ + +// Code generated by protoc-gen-grpc-web. DO NOT EDIT. +// versions: +// protoc-gen-grpc-web v1.4.2 +// protoc v4.25.0 +// source: point.proto + + +/* eslint-disable */ +// @ts-nocheck + + +import * as grpcWeb from 'grpc-web'; + +import * as point_pb from './point_pb'; + + +export class PointClient { + client_: grpcWeb.AbstractClientBase; + hostname_: string; + credentials_: null | { [index: string]: string; }; + options_: null | { [index: string]: any; }; + + constructor (hostname: string, + credentials?: null | { [index: string]: string; }, + options?: null | { [index: string]: any; }) { + if (!options) options = {}; + if (!credentials) credentials = {}; + options['format'] = 'text'; + + this.client_ = new grpcWeb.GrpcWebClientBase(options); + this.hostname_ = hostname.replace(/\/+$/, ''); + this.credentials_ = credentials; + this.options_ = options; + } + + methodDescriptorSimulateTrailed = new grpcWeb.MethodDescriptor( + '/point.Point/SimulateTrailed', + grpcWeb.MethodType.UNARY, + point_pb.Nothing, + point_pb.Nothing, + (request: point_pb.Nothing) => { + return request.serializeBinary(); + }, + point_pb.Nothing.deserializeBinary + ); + + simulateTrailed( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null): Promise; + + simulateTrailed( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null, + callback: (err: grpcWeb.RpcError, + response: point_pb.Nothing) => void): grpcWeb.ClientReadableStream; + + simulateTrailed( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null, + callback?: (err: grpcWeb.RpcError, + response: point_pb.Nothing) => void) { + if (callback !== undefined) { + return this.client_.rpcCall( + this.hostname_ + + '/point.Point/SimulateTrailed', + request, + metadata || {}, + this.methodDescriptorSimulateTrailed, + callback); + } + return this.client_.unaryCall( + this.hostname_ + + '/point.Point/SimulateTrailed', + request, + metadata || {}, + this.methodDescriptorSimulateTrailed); + } + + methodDescriptorSetDegraded = new grpcWeb.MethodDescriptor( + '/point.Point/SetDegraded', + grpcWeb.MethodType.UNARY, + point_pb.PointDegradedMessage, + point_pb.Nothing, + (request: point_pb.PointDegradedMessage) => { + return request.serializeBinary(); + }, + point_pb.Nothing.deserializeBinary + ); + + setDegraded( + request: point_pb.PointDegradedMessage, + metadata: grpcWeb.Metadata | null): Promise; + + setDegraded( + request: point_pb.PointDegradedMessage, + metadata: grpcWeb.Metadata | null, + callback: (err: grpcWeb.RpcError, + response: point_pb.Nothing) => void): grpcWeb.ClientReadableStream; + + setDegraded( + request: point_pb.PointDegradedMessage, + metadata: grpcWeb.Metadata | null, + callback?: (err: grpcWeb.RpcError, + response: point_pb.Nothing) => void) { + if (callback !== undefined) { + return this.client_.rpcCall( + this.hostname_ + + '/point.Point/SetDegraded', + request, + metadata || {}, + this.methodDescriptorSetDegraded, + callback); + } + return this.client_.unaryCall( + this.hostname_ + + '/point.Point/SetDegraded', + request, + metadata || {}, + this.methodDescriptorSetDegraded); + } + + methodDescriptorGetPointPosition = new grpcWeb.MethodDescriptor( + '/point.Point/GetPointPosition', + grpcWeb.MethodType.UNARY, + point_pb.Nothing, + point_pb.PointPositionMessage, + (request: point_pb.Nothing) => { + return request.serializeBinary(); + }, + point_pb.PointPositionMessage.deserializeBinary + ); + + getPointPosition( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null): Promise; + + getPointPosition( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null, + callback: (err: grpcWeb.RpcError, + response: point_pb.PointPositionMessage) => void): grpcWeb.ClientReadableStream; + + getPointPosition( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null, + callback?: (err: grpcWeb.RpcError, + response: point_pb.PointPositionMessage) => void) { + if (callback !== undefined) { + return this.client_.rpcCall( + this.hostname_ + + '/point.Point/GetPointPosition', + request, + metadata || {}, + this.methodDescriptorGetPointPosition, + callback); + } + return this.client_.unaryCall( + this.hostname_ + + '/point.Point/GetPointPosition', + request, + metadata || {}, + this.methodDescriptorGetPointPosition); + } + + methodDescriptorSetPointMachineState = new grpcWeb.MethodDescriptor( + '/point.Point/SetPointMachineState', + grpcWeb.MethodType.UNARY, + point_pb.PointMachineStateMessage, + point_pb.SetPointMachineStateResponse, + (request: point_pb.PointMachineStateMessage) => { + return request.serializeBinary(); + }, + point_pb.SetPointMachineStateResponse.deserializeBinary + ); + + setPointMachineState( + request: point_pb.PointMachineStateMessage, + metadata: grpcWeb.Metadata | null): Promise; + + setPointMachineState( + request: point_pb.PointMachineStateMessage, + metadata: grpcWeb.Metadata | null, + callback: (err: grpcWeb.RpcError, + response: point_pb.SetPointMachineStateResponse) => void): grpcWeb.ClientReadableStream; + + setPointMachineState( + request: point_pb.PointMachineStateMessage, + metadata: grpcWeb.Metadata | null, + callback?: (err: grpcWeb.RpcError, + response: point_pb.SetPointMachineStateResponse) => void) { + if (callback !== undefined) { + return this.client_.rpcCall( + this.hostname_ + + '/point.Point/SetPointMachineState', + request, + metadata || {}, + this.methodDescriptorSetPointMachineState, + callback); + } + return this.client_.unaryCall( + this.hostname_ + + '/point.Point/SetPointMachineState', + request, + metadata || {}, + this.methodDescriptorSetPointMachineState); + } + + methodDescriptorGetPointMachineState = new grpcWeb.MethodDescriptor( + '/point.Point/GetPointMachineState', + grpcWeb.MethodType.UNARY, + point_pb.Nothing, + point_pb.PointMachineStateMessage, + (request: point_pb.Nothing) => { + return request.serializeBinary(); + }, + point_pb.PointMachineStateMessage.deserializeBinary + ); + + getPointMachineState( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null): Promise; + + getPointMachineState( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null, + callback: (err: grpcWeb.RpcError, + response: point_pb.PointMachineStateMessage) => void): grpcWeb.ClientReadableStream; + + getPointMachineState( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null, + callback?: (err: grpcWeb.RpcError, + response: point_pb.PointMachineStateMessage) => void) { + if (callback !== undefined) { + return this.client_.rpcCall( + this.hostname_ + + '/point.Point/GetPointMachineState', + request, + metadata || {}, + this.methodDescriptorGetPointMachineState, + callback); + } + return this.client_.unaryCall( + this.hostname_ + + '/point.Point/GetPointMachineState', + request, + metadata || {}, + this.methodDescriptorGetPointMachineState); + } + +} + diff --git a/src/Point/rasta-point-web/src/proto/point_pb.d.ts b/src/Point/rasta-point-web/src/proto/point_pb.d.ts new file mode 100644 index 0000000..65e98c8 --- /dev/null +++ b/src/Point/rasta-point-web/src/proto/point_pb.d.ts @@ -0,0 +1,142 @@ +import * as jspb from 'google-protobuf' + + + +export class PointDegradedMessage extends jspb.Message { + getPosition(): PointPosition; + setPosition(value: PointPosition): PointDegradedMessage; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): PointDegradedMessage.AsObject; + static toObject(includeInstance: boolean, msg: PointDegradedMessage): PointDegradedMessage.AsObject; + static serializeBinaryToWriter(message: PointDegradedMessage, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): PointDegradedMessage; + static deserializeBinaryFromReader(message: PointDegradedMessage, reader: jspb.BinaryReader): PointDegradedMessage; +} + +export namespace PointDegradedMessage { + export type AsObject = { + position: PointPosition, + } +} + +export class PointPositionMessage extends jspb.Message { + getPosition(): PointPosition; + setPosition(value: PointPosition): PointPositionMessage; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): PointPositionMessage.AsObject; + static toObject(includeInstance: boolean, msg: PointPositionMessage): PointPositionMessage.AsObject; + static serializeBinaryToWriter(message: PointPositionMessage, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): PointPositionMessage; + static deserializeBinaryFromReader(message: PointPositionMessage, reader: jspb.BinaryReader): PointPositionMessage; +} + +export namespace PointPositionMessage { + export type AsObject = { + position: PointPosition, + } +} + +export class PointMachineStateMessage extends jspb.Message { + getPointposition(): PointPosition; + setPointposition(value: PointPosition): PointMachineStateMessage; + + getTarget(): PointMachineStateMessage.Target; + setTarget(value: PointMachineStateMessage.Target): PointMachineStateMessage; + + getAbilitytomove(): PointMachineStateMessage.AbilityToMove; + setAbilitytomove(value: PointMachineStateMessage.AbilityToMove): PointMachineStateMessage; + + getLastpointposition(): PointMachineStateMessage.LastPointPosition; + setLastpointposition(value: PointMachineStateMessage.LastPointPosition): PointMachineStateMessage; + + getCrucial(): PointMachineStateMessage.Crucial; + setCrucial(value: PointMachineStateMessage.Crucial): PointMachineStateMessage; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): PointMachineStateMessage.AsObject; + static toObject(includeInstance: boolean, msg: PointMachineStateMessage): PointMachineStateMessage.AsObject; + static serializeBinaryToWriter(message: PointMachineStateMessage, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): PointMachineStateMessage; + static deserializeBinaryFromReader(message: PointMachineStateMessage, reader: jspb.BinaryReader): PointMachineStateMessage; +} + +export namespace PointMachineStateMessage { + export type AsObject = { + pointposition: PointPosition, + target: PointMachineStateMessage.Target, + abilitytomove: PointMachineStateMessage.AbilityToMove, + lastpointposition: PointMachineStateMessage.LastPointPosition, + crucial: PointMachineStateMessage.Crucial, + } + + export enum Target { + TARGET_UNDEFINED = 0, + TARGET_LEFT = 1, + TARGET_RIGHT = 2, + TARGET_NONE = 3, + } + + export enum AbilityToMove { + ABILITYTOMOVE_UNDEFINED = 0, + ABILITYTOMOVE_ABLE = 1, + ABILITYTOMOVE_UNABLE = 2, + } + + export enum LastPointPosition { + LASTPOINTPOSITION_UNDEFINED = 0, + LASTPOINTPOSITION_NONE = 1, + } + + export enum Crucial { + CRUCIAL_UNDEFINED = 0, + CRUCIAL_CRUCIAL = 1, + CRUCIAL_NONCRUCIAL = 2, + } +} + +export class SetPointMachineStateResponse extends jspb.Message { + getNewstate(): PointMachineStateMessage | undefined; + setNewstate(value?: PointMachineStateMessage): SetPointMachineStateResponse; + hasNewstate(): boolean; + clearNewstate(): SetPointMachineStateResponse; + + getSuccess(): boolean; + setSuccess(value: boolean): SetPointMachineStateResponse; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): SetPointMachineStateResponse.AsObject; + static toObject(includeInstance: boolean, msg: SetPointMachineStateResponse): SetPointMachineStateResponse.AsObject; + static serializeBinaryToWriter(message: SetPointMachineStateResponse, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): SetPointMachineStateResponse; + static deserializeBinaryFromReader(message: SetPointMachineStateResponse, reader: jspb.BinaryReader): SetPointMachineStateResponse; +} + +export namespace SetPointMachineStateResponse { + export type AsObject = { + newstate?: PointMachineStateMessage.AsObject, + success: boolean, + } +} + +export class Nothing extends jspb.Message { + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): Nothing.AsObject; + static toObject(includeInstance: boolean, msg: Nothing): Nothing.AsObject; + static serializeBinaryToWriter(message: Nothing, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): Nothing; + static deserializeBinaryFromReader(message: Nothing, reader: jspb.BinaryReader): Nothing; +} + +export namespace Nothing { + export type AsObject = { + } +} + +export enum PointPosition { + RIGHT = 0, + LEFT = 1, + NOENDPOSITION = 2, + TRAILED = 3, +} diff --git a/src/Point/rasta-point-web/src/proto/point_pb.js b/src/Point/rasta-point-web/src/proto/point_pb.js new file mode 100644 index 0000000..a823bcf --- /dev/null +++ b/src/Point/rasta-point-web/src/proto/point_pb.js @@ -0,0 +1,977 @@ +// source: point.proto +/** + * @fileoverview + * @enhanceable + * @suppress {missingRequire} reports error on implicit type usages. + * @suppress {messageConventions} JS Compiler reports an error if a variable or + * field starts with 'MSG_' and isn't a translatable message. + * @public + */ +// GENERATED CODE -- DO NOT EDIT! +/* eslint-disable */ +// @ts-nocheck + +var jspb = require('google-protobuf'); +var goog = jspb; +var global = + (typeof globalThis !== 'undefined' && globalThis) || + (typeof window !== 'undefined' && window) || + (typeof global !== 'undefined' && global) || + (typeof self !== 'undefined' && self) || + (function () { return this; }).call(null) || + Function('return this')(); + +goog.exportSymbol('proto.point.Nothing', null, global); +goog.exportSymbol('proto.point.PointDegradedMessage', null, global); +goog.exportSymbol('proto.point.PointMachineStateMessage', null, global); +goog.exportSymbol('proto.point.PointMachineStateMessage.AbilityToMove', null, global); +goog.exportSymbol('proto.point.PointMachineStateMessage.Crucial', null, global); +goog.exportSymbol('proto.point.PointMachineStateMessage.LastPointPosition', null, global); +goog.exportSymbol('proto.point.PointMachineStateMessage.Target', null, global); +goog.exportSymbol('proto.point.PointPosition', null, global); +goog.exportSymbol('proto.point.PointPositionMessage', null, global); +goog.exportSymbol('proto.point.SetPointMachineStateResponse', null, global); +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.point.PointDegradedMessage = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.point.PointDegradedMessage, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.point.PointDegradedMessage.displayName = 'proto.point.PointDegradedMessage'; +} +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.point.PointPositionMessage = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.point.PointPositionMessage, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.point.PointPositionMessage.displayName = 'proto.point.PointPositionMessage'; +} +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.point.PointMachineStateMessage = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.point.PointMachineStateMessage, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.point.PointMachineStateMessage.displayName = 'proto.point.PointMachineStateMessage'; +} +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.point.SetPointMachineStateResponse = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.point.SetPointMachineStateResponse, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.point.SetPointMachineStateResponse.displayName = 'proto.point.SetPointMachineStateResponse'; +} +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.point.Nothing = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.point.Nothing, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.point.Nothing.displayName = 'proto.point.Nothing'; +} + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.point.PointDegradedMessage.prototype.toObject = function(opt_includeInstance) { + return proto.point.PointDegradedMessage.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.point.PointDegradedMessage} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.point.PointDegradedMessage.toObject = function(includeInstance, msg) { + var f, obj = { + position: jspb.Message.getFieldWithDefault(msg, 1, 0) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.point.PointDegradedMessage} + */ +proto.point.PointDegradedMessage.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.point.PointDegradedMessage; + return proto.point.PointDegradedMessage.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.point.PointDegradedMessage} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.point.PointDegradedMessage} + */ +proto.point.PointDegradedMessage.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {!proto.point.PointPosition} */ (reader.readEnum()); + msg.setPosition(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.point.PointDegradedMessage.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.point.PointDegradedMessage.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.point.PointDegradedMessage} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.point.PointDegradedMessage.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getPosition(); + if (f !== 0.0) { + writer.writeEnum( + 1, + f + ); + } +}; + + +/** + * optional PointPosition position = 1; + * @return {!proto.point.PointPosition} + */ +proto.point.PointDegradedMessage.prototype.getPosition = function() { + return /** @type {!proto.point.PointPosition} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); +}; + + +/** + * @param {!proto.point.PointPosition} value + * @return {!proto.point.PointDegradedMessage} returns this + */ +proto.point.PointDegradedMessage.prototype.setPosition = function(value) { + return jspb.Message.setProto3EnumField(this, 1, value); +}; + + + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.point.PointPositionMessage.prototype.toObject = function(opt_includeInstance) { + return proto.point.PointPositionMessage.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.point.PointPositionMessage} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.point.PointPositionMessage.toObject = function(includeInstance, msg) { + var f, obj = { + position: jspb.Message.getFieldWithDefault(msg, 1, 0) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.point.PointPositionMessage} + */ +proto.point.PointPositionMessage.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.point.PointPositionMessage; + return proto.point.PointPositionMessage.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.point.PointPositionMessage} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.point.PointPositionMessage} + */ +proto.point.PointPositionMessage.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {!proto.point.PointPosition} */ (reader.readEnum()); + msg.setPosition(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.point.PointPositionMessage.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.point.PointPositionMessage.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.point.PointPositionMessage} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.point.PointPositionMessage.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getPosition(); + if (f !== 0.0) { + writer.writeEnum( + 1, + f + ); + } +}; + + +/** + * optional PointPosition position = 1; + * @return {!proto.point.PointPosition} + */ +proto.point.PointPositionMessage.prototype.getPosition = function() { + return /** @type {!proto.point.PointPosition} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); +}; + + +/** + * @param {!proto.point.PointPosition} value + * @return {!proto.point.PointPositionMessage} returns this + */ +proto.point.PointPositionMessage.prototype.setPosition = function(value) { + return jspb.Message.setProto3EnumField(this, 1, value); +}; + + + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.point.PointMachineStateMessage.prototype.toObject = function(opt_includeInstance) { + return proto.point.PointMachineStateMessage.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.point.PointMachineStateMessage} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.point.PointMachineStateMessage.toObject = function(includeInstance, msg) { + var f, obj = { + pointposition: jspb.Message.getFieldWithDefault(msg, 1, 0), + target: jspb.Message.getFieldWithDefault(msg, 2, 0), + abilitytomove: jspb.Message.getFieldWithDefault(msg, 3, 0), + lastpointposition: jspb.Message.getFieldWithDefault(msg, 4, 0), + crucial: jspb.Message.getFieldWithDefault(msg, 5, 0) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.point.PointMachineStateMessage} + */ +proto.point.PointMachineStateMessage.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.point.PointMachineStateMessage; + return proto.point.PointMachineStateMessage.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.point.PointMachineStateMessage} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.point.PointMachineStateMessage} + */ +proto.point.PointMachineStateMessage.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {!proto.point.PointPosition} */ (reader.readEnum()); + msg.setPointposition(value); + break; + case 2: + var value = /** @type {!proto.point.PointMachineStateMessage.Target} */ (reader.readEnum()); + msg.setTarget(value); + break; + case 3: + var value = /** @type {!proto.point.PointMachineStateMessage.AbilityToMove} */ (reader.readEnum()); + msg.setAbilitytomove(value); + break; + case 4: + var value = /** @type {!proto.point.PointMachineStateMessage.LastPointPosition} */ (reader.readEnum()); + msg.setLastpointposition(value); + break; + case 5: + var value = /** @type {!proto.point.PointMachineStateMessage.Crucial} */ (reader.readEnum()); + msg.setCrucial(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.point.PointMachineStateMessage.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.point.PointMachineStateMessage.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.point.PointMachineStateMessage} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.point.PointMachineStateMessage.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getPointposition(); + if (f !== 0.0) { + writer.writeEnum( + 1, + f + ); + } + f = message.getTarget(); + if (f !== 0.0) { + writer.writeEnum( + 2, + f + ); + } + f = message.getAbilitytomove(); + if (f !== 0.0) { + writer.writeEnum( + 3, + f + ); + } + f = message.getLastpointposition(); + if (f !== 0.0) { + writer.writeEnum( + 4, + f + ); + } + f = message.getCrucial(); + if (f !== 0.0) { + writer.writeEnum( + 5, + f + ); + } +}; + + +/** + * @enum {number} + */ +proto.point.PointMachineStateMessage.Target = { + TARGET_UNDEFINED: 0, + TARGET_LEFT: 1, + TARGET_RIGHT: 2, + TARGET_NONE: 3 +}; + +/** + * @enum {number} + */ +proto.point.PointMachineStateMessage.AbilityToMove = { + ABILITYTOMOVE_UNDEFINED: 0, + ABILITYTOMOVE_ABLE: 1, + ABILITYTOMOVE_UNABLE: 2 +}; + +/** + * @enum {number} + */ +proto.point.PointMachineStateMessage.LastPointPosition = { + LASTPOINTPOSITION_UNDEFINED: 0, + LASTPOINTPOSITION_NONE: 1 +}; + +/** + * @enum {number} + */ +proto.point.PointMachineStateMessage.Crucial = { + CRUCIAL_UNDEFINED: 0, + CRUCIAL_CRUCIAL: 1, + CRUCIAL_NONCRUCIAL: 2 +}; + +/** + * optional PointPosition pointPosition = 1; + * @return {!proto.point.PointPosition} + */ +proto.point.PointMachineStateMessage.prototype.getPointposition = function() { + return /** @type {!proto.point.PointPosition} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); +}; + + +/** + * @param {!proto.point.PointPosition} value + * @return {!proto.point.PointMachineStateMessage} returns this + */ +proto.point.PointMachineStateMessage.prototype.setPointposition = function(value) { + return jspb.Message.setProto3EnumField(this, 1, value); +}; + + +/** + * optional Target target = 2; + * @return {!proto.point.PointMachineStateMessage.Target} + */ +proto.point.PointMachineStateMessage.prototype.getTarget = function() { + return /** @type {!proto.point.PointMachineStateMessage.Target} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); +}; + + +/** + * @param {!proto.point.PointMachineStateMessage.Target} value + * @return {!proto.point.PointMachineStateMessage} returns this + */ +proto.point.PointMachineStateMessage.prototype.setTarget = function(value) { + return jspb.Message.setProto3EnumField(this, 2, value); +}; + + +/** + * optional AbilityToMove abilityToMove = 3; + * @return {!proto.point.PointMachineStateMessage.AbilityToMove} + */ +proto.point.PointMachineStateMessage.prototype.getAbilitytomove = function() { + return /** @type {!proto.point.PointMachineStateMessage.AbilityToMove} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); +}; + + +/** + * @param {!proto.point.PointMachineStateMessage.AbilityToMove} value + * @return {!proto.point.PointMachineStateMessage} returns this + */ +proto.point.PointMachineStateMessage.prototype.setAbilitytomove = function(value) { + return jspb.Message.setProto3EnumField(this, 3, value); +}; + + +/** + * optional LastPointPosition lastPointPosition = 4; + * @return {!proto.point.PointMachineStateMessage.LastPointPosition} + */ +proto.point.PointMachineStateMessage.prototype.getLastpointposition = function() { + return /** @type {!proto.point.PointMachineStateMessage.LastPointPosition} */ (jspb.Message.getFieldWithDefault(this, 4, 0)); +}; + + +/** + * @param {!proto.point.PointMachineStateMessage.LastPointPosition} value + * @return {!proto.point.PointMachineStateMessage} returns this + */ +proto.point.PointMachineStateMessage.prototype.setLastpointposition = function(value) { + return jspb.Message.setProto3EnumField(this, 4, value); +}; + + +/** + * optional Crucial crucial = 5; + * @return {!proto.point.PointMachineStateMessage.Crucial} + */ +proto.point.PointMachineStateMessage.prototype.getCrucial = function() { + return /** @type {!proto.point.PointMachineStateMessage.Crucial} */ (jspb.Message.getFieldWithDefault(this, 5, 0)); +}; + + +/** + * @param {!proto.point.PointMachineStateMessage.Crucial} value + * @return {!proto.point.PointMachineStateMessage} returns this + */ +proto.point.PointMachineStateMessage.prototype.setCrucial = function(value) { + return jspb.Message.setProto3EnumField(this, 5, value); +}; + + + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.point.SetPointMachineStateResponse.prototype.toObject = function(opt_includeInstance) { + return proto.point.SetPointMachineStateResponse.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.point.SetPointMachineStateResponse} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.point.SetPointMachineStateResponse.toObject = function(includeInstance, msg) { + var f, obj = { + newstate: (f = msg.getNewstate()) && proto.point.PointMachineStateMessage.toObject(includeInstance, f), + success: jspb.Message.getBooleanFieldWithDefault(msg, 2, false) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.point.SetPointMachineStateResponse} + */ +proto.point.SetPointMachineStateResponse.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.point.SetPointMachineStateResponse; + return proto.point.SetPointMachineStateResponse.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.point.SetPointMachineStateResponse} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.point.SetPointMachineStateResponse} + */ +proto.point.SetPointMachineStateResponse.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = new proto.point.PointMachineStateMessage; + reader.readMessage(value,proto.point.PointMachineStateMessage.deserializeBinaryFromReader); + msg.setNewstate(value); + break; + case 2: + var value = /** @type {boolean} */ (reader.readBool()); + msg.setSuccess(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.point.SetPointMachineStateResponse.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.point.SetPointMachineStateResponse.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.point.SetPointMachineStateResponse} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.point.SetPointMachineStateResponse.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getNewstate(); + if (f != null) { + writer.writeMessage( + 1, + f, + proto.point.PointMachineStateMessage.serializeBinaryToWriter + ); + } + f = message.getSuccess(); + if (f) { + writer.writeBool( + 2, + f + ); + } +}; + + +/** + * optional PointMachineStateMessage newState = 1; + * @return {?proto.point.PointMachineStateMessage} + */ +proto.point.SetPointMachineStateResponse.prototype.getNewstate = function() { + return /** @type{?proto.point.PointMachineStateMessage} */ ( + jspb.Message.getWrapperField(this, proto.point.PointMachineStateMessage, 1)); +}; + + +/** + * @param {?proto.point.PointMachineStateMessage|undefined} value + * @return {!proto.point.SetPointMachineStateResponse} returns this +*/ +proto.point.SetPointMachineStateResponse.prototype.setNewstate = function(value) { + return jspb.Message.setWrapperField(this, 1, value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.point.SetPointMachineStateResponse} returns this + */ +proto.point.SetPointMachineStateResponse.prototype.clearNewstate = function() { + return this.setNewstate(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.point.SetPointMachineStateResponse.prototype.hasNewstate = function() { + return jspb.Message.getField(this, 1) != null; +}; + + +/** + * optional bool success = 2; + * @return {boolean} + */ +proto.point.SetPointMachineStateResponse.prototype.getSuccess = function() { + return /** @type {boolean} */ (jspb.Message.getBooleanFieldWithDefault(this, 2, false)); +}; + + +/** + * @param {boolean} value + * @return {!proto.point.SetPointMachineStateResponse} returns this + */ +proto.point.SetPointMachineStateResponse.prototype.setSuccess = function(value) { + return jspb.Message.setProto3BooleanField(this, 2, value); +}; + + + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.point.Nothing.prototype.toObject = function(opt_includeInstance) { + return proto.point.Nothing.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.point.Nothing} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.point.Nothing.toObject = function(includeInstance, msg) { + var f, obj = { + + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.point.Nothing} + */ +proto.point.Nothing.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.point.Nothing; + return proto.point.Nothing.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.point.Nothing} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.point.Nothing} + */ +proto.point.Nothing.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.point.Nothing.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.point.Nothing.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.point.Nothing} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.point.Nothing.serializeBinaryToWriter = function(message, writer) { + var f = undefined; +}; + + +/** + * @enum {number} + */ +proto.point.PointPosition = { + RIGHT: 0, + LEFT: 1, + NOENDPOSITION: 2, + TRAILED: 3 +}; + +goog.object.extend(exports, proto.point); diff --git a/src/ProtobufInterfaces/Readme.md b/src/ProtobufInterfaces/Readme.md new file mode 100644 index 0000000..00f829d --- /dev/null +++ b/src/ProtobufInterfaces/Readme.md @@ -0,0 +1,12 @@ +### Generating ts/js grpc files: +Requires the packages installed: +```console +npm i protoc-gen-grpc-web protoc-gen-js +``` +Generating: +```console +protoc -I=./proto .proto \ + --js_out=import_style=commonjs:. \ + --grpc-web_out=import_style=typescript,mode=grpcwebtext:. + +``` diff --git a/src/ProtobufInterfaces/proto/point.proto b/src/ProtobufInterfaces/proto/point.proto index 98b8026..d352119 100644 --- a/src/ProtobufInterfaces/proto/point.proto +++ b/src/ProtobufInterfaces/proto/point.proto @@ -14,12 +14,17 @@ enum PointPosition { service Point { rpc SimulateTrailed (Nothing) returns (Nothing) {} + rpc SetDegraded (PointDegradedMessage) returns (Nothing) {} rpc GetPointPosition (Nothing) returns (PointPositionMessage) {} rpc SetPointMachineState (PointMachineStateMessage) returns (SetPointMachineStateResponse) {} rpc GetPointMachineState (Nothing) returns (PointMachineStateMessage) {} } +message PointDegradedMessage { + PointPosition position = 1; +} + message PointPositionMessage { PointPosition position = 1; } From 16ffa149f802a19e51910a63486dfbacd54d978e Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Tue, 14 Nov 2023 15:35:48 +0100 Subject: [PATCH 03/14] add SetDegraded methods --- .../PointMachine/PointMachineState.cs | 4 +- src/Point/Point.cs | 65 +++++++++++++++++-- src/Point/Services/PointService.cs | 6 ++ src/Point/appsettings.json | 3 + src/Point/rasta-point-web/src/Point.tsx | 16 +++++ 5 files changed, 88 insertions(+), 6 deletions(-) diff --git a/src/Point/Components/PointMachine/PointMachineState.cs b/src/Point/Components/PointMachine/PointMachineState.cs index f848234..f6f049b 100644 --- a/src/Point/Components/PointMachine/PointMachineState.cs +++ b/src/Point/Components/PointMachine/PointMachineState.cs @@ -1,4 +1,5 @@ using ReportedPointPosition = EulynxLive.Messages.Baseline4R1.PointPointPositionMessageReportedPointPosition; +using ReportedDegradedPointPosition = EulynxLive.Messages.Baseline4R1.PointPointPositionMessageReportedDegradedPointPosition; using PointMachineStateMessage = EulynxLive.Point.Proto.PointMachineStateMessage.Types; namespace EulynxLive.Point.Components @@ -6,9 +7,10 @@ namespace EulynxLive.Point.Components public class PointMachineState { public ReportedPointPosition PointPosition { get; set; } + public ReportedDegradedPointPosition DegradedPointPosition { get; set; } public PointMachineStateMessage.Target Target { get; set; } public PointMachineStateMessage.AbilityToMove AbilityToMove { get; set; } public PointMachineStateMessage.LastPointPosition LastPointPosition { get; set; } public PointMachineStateMessage.Crucial Crucial { get; set; } } -} \ No newline at end of file +} diff --git a/src/Point/Point.cs b/src/Point/Point.cs index f9f5778..d252a42 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -18,6 +18,7 @@ using Grpc.Net.Client; using EulynxLive.Point.Components; using System; +using EulynxLive.Point.Proto; namespace EulynxLive.Point { @@ -31,6 +32,7 @@ public class Point : BackgroundService private string _remoteId; private string _remoteEndpoint; private readonly Random _random; + private bool _hasNoNonCrucialPointMachines = false; private bool _initialized; AsyncDuplexStreamingCall _currentConnection; @@ -48,6 +50,7 @@ public Point(ILogger logger, IConfiguration configuration, PointMachineSt _pointState = pointState; _pointState.PointPosition = ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition; + _hasNoNonCrucialPointMachines = configuration.GetValue("PointSettings:_hasNoNonCrucialPointMachines"); } public async Task HandleWebSocket(WebSocket webSocket) @@ -81,13 +84,64 @@ public async Task SimulateTrailed() if (_currentConnection != null) { - var occupancyStatus = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, ReportedDegradedPointPosition.PointIsNotInADegradedPosition); + var occupancyStatus = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(occupancyStatus.ToByteArray()) }); } await UpdateConnectedWebClients(); } + private ReportedDegradedPointPosition? GetReportedDegradedPointPosition(ReportedPointPosition position) => position switch + { + ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition + => ReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition, + ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition + => ReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition, + ReportedPointPosition.PointIsInNoEndPosition + => null, + ReportedPointPosition.PointIsTrailed + => null, + _ => null, + }; + + private ReportedPointPosition? GetReportedPointPosition(PointPosition pointPosition) => pointPosition switch + { + PointPosition.NoEndPosition => ReportedPointPosition.PointIsInNoEndPosition, + PointPosition.Trailed => ReportedPointPosition.PointIsTrailed, + _ => null, + }; + + private void UpdatePointState(ReportedPointPosition reportedPointPosition, ReportedDegradedPointPosition reportedDegradedPointPosition) { + _pointState.PointPosition = reportedPointPosition; + _pointState.DegradedPointPosition = reportedDegradedPointPosition; + } + + public async Task SetDegraded(PointDegradedMessage message) + { + var previousPosition = _pointState.PointPosition; + _pointState.PointPosition = ReportedPointPosition.PointIsInNoEndPosition; + + if (_currentConnection != null) + { + ReportedDegradedPointPosition? reportedDegradedPointPosition = _hasNoNonCrucialPointMachines ? + ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : + GetReportedDegradedPointPosition(previousPosition); + + if (reportedDegradedPointPosition != null) + { + ReportedPointPosition? reportedPointPosition = GetReportedPointPosition(message.Position); + if (reportedPointPosition != null) + { + UpdatePointState((ReportedPointPosition)reportedPointPosition, (ReportedDegradedPointPosition)reportedDegradedPointPosition); + var occupancyStatus = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(occupancyStatus.ToByteArray()) }); + } + } + } + + await UpdateConnectedWebClients(); + } + protected override async Task ExecuteAsync(CancellationToken stoppingToken) { // Command line argument parsing. @@ -154,7 +208,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) var startInitialization = new PointStartInitialisationMessage(_localId, _remoteId); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(startInitialization.ToByteArray()) }); - var initialPosition = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, ReportedDegradedPointPosition.PointIsNotInADegradedPosition); + var initialPosition = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(initialPosition.ToByteArray()) }); _initialized = true; @@ -177,12 +231,13 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) if ((movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving && _pointState.PointPosition == ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition) || (movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsALeftHandPointMoving && _pointState.PointPosition == ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition)) { - var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, ReportedDegradedPointPosition.PointIsNotInADegradedPosition); + var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); continue; } _pointState.PointPosition = ReportedPointPosition.PointIsInNoEndPosition; + _pointState.DegradedPointPosition = ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable; await UpdateConnectedWebClients(); // Simulate point movement @@ -205,7 +260,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) await UpdateConnectedWebClients(); _logger.LogDebug("End position reached."); - var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, ReportedDegradedPointPosition.PointIsNotInADegradedPosition); + var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); } else @@ -227,7 +282,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) await UpdateConnectedWebClients(); _logger.LogDebug("End position reached."); - var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, ReportedDegradedPointPosition.PointIsNotInADegradedPosition); + var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); } } diff --git a/src/Point/Services/PointService.cs b/src/Point/Services/PointService.cs index 0cbdc85..93977ac 100644 --- a/src/Point/Services/PointService.cs +++ b/src/Point/Services/PointService.cs @@ -21,6 +21,12 @@ public override async Task SimulateTrailed(Nothing request, ServerCallC return new Nothing(); } + public override async Task SetDegraded(PointDegradedMessage request, ServerCallContext context) + { + await _point.SetDegraded(request); + return new Nothing(); + } + public override Task GetPointPosition(Nothing request, ServerCallContext context) { var response = new Proto.PointPositionMessage() diff --git a/src/Point/appsettings.json b/src/Point/appsettings.json index dea06e6..56cc7c6 100644 --- a/src/Point/appsettings.json +++ b/src/Point/appsettings.json @@ -7,6 +7,9 @@ } }, "AllowedHosts": "*", + "PointSettings": { + "_hasNoNonCrucialPointMachines": true + }, "Kestrel": { "EndPoints": { "Http2": { diff --git a/src/Point/rasta-point-web/src/Point.tsx b/src/Point/rasta-point-web/src/Point.tsx index 6209d86..d292b78 100644 --- a/src/Point/rasta-point-web/src/Point.tsx +++ b/src/Point/rasta-point-web/src/Point.tsx @@ -1,6 +1,8 @@ import React, { Component } from 'react'; import './Point.css'; import { SimulatorState } from './SimulatorState'; +import { PointClient } from './proto/PointServiceClientPb'; +import { Nothing, PointDegradedMessage, PointPosition } from './proto/point_pb'; interface PointState { webSocket: WebSocket | null, @@ -71,6 +73,9 @@ class Point extends Component<{}, PointState> { } render() { + const url = window.location.protocol + '//' + window.location.host + (window.location.pathname.endsWith('/') ? window.location.pathname.slice(0, -1) : window.location.pathname); + const client = new PointClient(url); + return (

EULYNX Point Simulator

@@ -78,6 +83,17 @@ class Point extends Component<{}, PointState> {

{this.state.connected ? 'connected' : 'disconnected'}

Position

{this.state.position}

+ +

{this.state.position}

+
); } From 8e0f295d718f454fae4aa8216db589dab1435fc1 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Thu, 16 Nov 2023 09:13:09 +0100 Subject: [PATCH 04/14] update point web --- src/Point/Services/PointService.cs | 6 +++ src/Point/rasta-point-web/package-lock.json | 22 ++++++++++ src/Point/rasta-point-web/package.json | 2 + src/Point/rasta-point-web/src/Point.tsx | 6 ++- .../src/proto/PointServiceClientPb.ts | 43 +++++++++++++++++++ src/ProtobufInterfaces/proto/point.proto | 1 + 6 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/Point/Services/PointService.cs b/src/Point/Services/PointService.cs index 93977ac..13e45b2 100644 --- a/src/Point/Services/PointService.cs +++ b/src/Point/Services/PointService.cs @@ -27,6 +27,12 @@ public override async Task SetDegraded(PointDegradedMessage request, Se return new Nothing(); } + public override async Task FinalizePosition(Nothing request, ServerCallContext context) + { + await _point.FinalizePosition(); + return new Nothing(); + } + public override Task GetPointPosition(Nothing request, ServerCallContext context) { var response = new Proto.PointPositionMessage() diff --git a/src/Point/rasta-point-web/package-lock.json b/src/Point/rasta-point-web/package-lock.json index 5b04d5d..de0a70c 100644 --- a/src/Point/rasta-point-web/package-lock.json +++ b/src/Point/rasta-point-web/package-lock.json @@ -11,6 +11,8 @@ "@types/node": "^16.11.64", "@types/react": "^17.0.50", "@types/react-dom": "^17.0.17", + "google-protobuf": "^3.18.0-rc.1", + "grpc-web": "^1.2.1", "react": "^17.0.2", "react-dom": "^17.0.2", "typescript": "^4.8.4" @@ -8581,6 +8583,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/google-protobuf": { + "version": "3.21.2", + "resolved": "https://registry.npmjs.org/google-protobuf/-/google-protobuf-3.21.2.tgz", + "integrity": "sha512-3MSOYFO5U9mPGikIYCzK0SaThypfGgS6bHqrUGXG3DPHCrb+txNqeEcns1W0lkGfk0rCyNXm7xB9rMxnCiZOoA==" + }, "node_modules/graceful-fs": { "version": "4.2.10", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", @@ -8593,6 +8600,11 @@ "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", "dev": true }, + "node_modules/grpc-web": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/grpc-web/-/grpc-web-1.5.0.tgz", + "integrity": "sha512-y1tS3BBIoiVSzKTDF3Hm7E8hV2n7YY7pO0Uo7depfWJqKzWE+SKr0jvHNIJsJJYILQlpYShpi/DRJJMbosgDMQ==" + }, "node_modules/gzip-size": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-6.0.0.tgz", @@ -24006,6 +24018,11 @@ "slash": "^3.0.0" } }, + "google-protobuf": { + "version": "3.21.2", + "resolved": "https://registry.npmjs.org/google-protobuf/-/google-protobuf-3.21.2.tgz", + "integrity": "sha512-3MSOYFO5U9mPGikIYCzK0SaThypfGgS6bHqrUGXG3DPHCrb+txNqeEcns1W0lkGfk0rCyNXm7xB9rMxnCiZOoA==" + }, "graceful-fs": { "version": "4.2.10", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", @@ -24018,6 +24035,11 @@ "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", "dev": true }, + "grpc-web": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/grpc-web/-/grpc-web-1.5.0.tgz", + "integrity": "sha512-y1tS3BBIoiVSzKTDF3Hm7E8hV2n7YY7pO0Uo7depfWJqKzWE+SKr0jvHNIJsJJYILQlpYShpi/DRJJMbosgDMQ==" + }, "gzip-size": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-6.0.0.tgz", diff --git a/src/Point/rasta-point-web/package.json b/src/Point/rasta-point-web/package.json index 12312c0..9544e0a 100644 --- a/src/Point/rasta-point-web/package.json +++ b/src/Point/rasta-point-web/package.json @@ -7,6 +7,8 @@ "@types/node": "^16.11.64", "@types/react": "^17.0.50", "@types/react-dom": "^17.0.17", + "google-protobuf": "^3.18.0-rc.1", + "grpc-web": "^1.2.1", "react": "^17.0.2", "react-dom": "^17.0.2", "typescript": "^4.8.4" diff --git a/src/Point/rasta-point-web/src/Point.tsx b/src/Point/rasta-point-web/src/Point.tsx index d292b78..fb0cbdd 100644 --- a/src/Point/rasta-point-web/src/Point.tsx +++ b/src/Point/rasta-point-web/src/Point.tsx @@ -88,12 +88,16 @@ class Point extends Component<{}, PointState> { request.setPosition(PointPosition.NOENDPOSITION); await client.setDegraded(request, null); }}>Set degraded (no endposition) -

{this.state.position}

+

+

+ ); } diff --git a/src/Point/rasta-point-web/src/proto/PointServiceClientPb.ts b/src/Point/rasta-point-web/src/proto/PointServiceClientPb.ts index 9f5ecdc..3ac5e26 100644 --- a/src/Point/rasta-point-web/src/proto/PointServiceClientPb.ts +++ b/src/Point/rasta-point-web/src/proto/PointServiceClientPb.ts @@ -125,6 +125,49 @@ export class PointClient { this.methodDescriptorSetDegraded); } + methodDescriptorFinalizePosition = new grpcWeb.MethodDescriptor( + '/point.Point/FinalizePosition', + grpcWeb.MethodType.UNARY, + point_pb.Nothing, + point_pb.Nothing, + (request: point_pb.Nothing) => { + return request.serializeBinary(); + }, + point_pb.Nothing.deserializeBinary + ); + + finalizePosition( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null): Promise; + + finalizePosition( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null, + callback: (err: grpcWeb.RpcError, + response: point_pb.Nothing) => void): grpcWeb.ClientReadableStream; + + finalizePosition( + request: point_pb.Nothing, + metadata: grpcWeb.Metadata | null, + callback?: (err: grpcWeb.RpcError, + response: point_pb.Nothing) => void) { + if (callback !== undefined) { + return this.client_.rpcCall( + this.hostname_ + + '/point.Point/FinalizePosition', + request, + metadata || {}, + this.methodDescriptorFinalizePosition, + callback); + } + return this.client_.unaryCall( + this.hostname_ + + '/point.Point/FinalizePosition', + request, + metadata || {}, + this.methodDescriptorFinalizePosition); + } + methodDescriptorGetPointPosition = new grpcWeb.MethodDescriptor( '/point.Point/GetPointPosition', grpcWeb.MethodType.UNARY, diff --git a/src/ProtobufInterfaces/proto/point.proto b/src/ProtobufInterfaces/proto/point.proto index d352119..cddef21 100644 --- a/src/ProtobufInterfaces/proto/point.proto +++ b/src/ProtobufInterfaces/proto/point.proto @@ -15,6 +15,7 @@ enum PointPosition { service Point { rpc SimulateTrailed (Nothing) returns (Nothing) {} rpc SetDegraded (PointDegradedMessage) returns (Nothing) {} + rpc FinalizePosition (Nothing) returns (Nothing) {} rpc GetPointPosition (Nothing) returns (PointPositionMessage) {} rpc SetPointMachineState (PointMachineStateMessage) returns (SetPointMachineStateResponse) {} rpc GetPointMachineState (Nothing) returns (PointMachineStateMessage) {} From 7f68be6690b44517e376a0fb258dfd90a6001771 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Thu, 16 Nov 2023 09:13:54 +0100 Subject: [PATCH 05/14] update dockerfile .Net version --- docker/Point/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Point/Dockerfile b/docker/Point/Dockerfile index 049ca6b..ff0becf 100644 --- a/docker/Point/Dockerfile +++ b/docker/Point/Dockerfile @@ -1,6 +1,6 @@ -FROM mcr.microsoft.com/dotnet/aspnet:6.0 +FROM mcr.microsoft.com/dotnet/aspnet:7.0 -COPY src/Point/bin/Release/net6.0/publish/ app/ +COPY src/Point/bin/Release/net7.0/publish/ app/ WORKDIR /app From c5d4748c0778c22a731aaa64059f7743d6566704 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Thu, 16 Nov 2023 10:47:30 +0100 Subject: [PATCH 06/14] update Point --- .../PointMachine/PointMachineState.cs | 1 + src/Point/Point.cs | 75 +++++++++++++++---- 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/src/Point/Components/PointMachine/PointMachineState.cs b/src/Point/Components/PointMachine/PointMachineState.cs index f6f049b..397cdcb 100644 --- a/src/Point/Components/PointMachine/PointMachineState.cs +++ b/src/Point/Components/PointMachine/PointMachineState.cs @@ -6,6 +6,7 @@ namespace EulynxLive.Point.Components { public class PointMachineState { + public ReportedPointPosition LatestFinalPointPosition { get; set; } public ReportedPointPosition PointPosition { get; set; } public ReportedDegradedPointPosition DegradedPointPosition { get; set; } public PointMachineStateMessage.Target Target { get; set; } diff --git a/src/Point/Point.cs b/src/Point/Point.cs index d252a42..55ae096 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -32,13 +32,15 @@ public class Point : BackgroundService private string _remoteId; private string _remoteEndpoint; private readonly Random _random; - private bool _hasNoNonCrucialPointMachines = false; + private bool _hasNoNonCrucialPointMachines; private bool _initialized; AsyncDuplexStreamingCall _currentConnection; private PointMachineState _pointState; public PointMachineState PointState { get { return _pointState; } } + public record PointConfiguration(bool hasNoNonCrucialPointMachines); + public Point(ILogger logger, IConfiguration configuration, PointMachineState pointState) { @@ -50,7 +52,7 @@ public Point(ILogger logger, IConfiguration configuration, PointMachineSt _pointState = pointState; _pointState.PointPosition = ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition; - _hasNoNonCrucialPointMachines = configuration.GetValue("PointSettings:_hasNoNonCrucialPointMachines"); + _pointState.LatestFinalPointPosition = _pointState.PointPosition; } public async Task HandleWebSocket(WebSocket webSocket) @@ -91,10 +93,10 @@ public async Task SimulateTrailed() await UpdateConnectedWebClients(); } - private ReportedDegradedPointPosition? GetReportedDegradedPointPosition(ReportedPointPosition position) => position switch + private ReportedDegradedPointPosition? GetReportedDegradedPointPosition(ReportedPointPosition previousReportedPosition) => previousReportedPosition switch { ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition - => ReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition, + => ReportedDegradedPointPosition.PointIsInADegradedRightHandPosition, ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition => ReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition, ReportedPointPosition.PointIsInNoEndPosition @@ -104,7 +106,7 @@ public async Task SimulateTrailed() _ => null, }; - private ReportedPointPosition? GetReportedPointPosition(PointPosition pointPosition) => pointPosition switch + private ReportedPointPosition? GetReportedPointPositionDegraded(PointPosition pointPosition) => pointPosition switch { PointPosition.NoEndPosition => ReportedPointPosition.PointIsInNoEndPosition, PointPosition.Trailed => ReportedPointPosition.PointIsTrailed, @@ -112,24 +114,42 @@ public async Task SimulateTrailed() }; private void UpdatePointState(ReportedPointPosition reportedPointPosition, ReportedDegradedPointPosition reportedDegradedPointPosition) { - _pointState.PointPosition = reportedPointPosition; + UpdatePointState(reportedPointPosition); _pointState.DegradedPointPosition = reportedDegradedPointPosition; } + private void UpdatePointState(ReportedPointPosition reportedPointPosition) { + _pointState.PointPosition = reportedPointPosition; + SetLatestFinalPointPosition(reportedPointPosition); + } + + private void SetLatestFinalPointPosition(ReportedPointPosition reportedPointPosition) { + _pointState.LatestFinalPointPosition = reportedPointPosition switch + { + ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition => reportedPointPosition, + ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition => reportedPointPosition, + _ => _pointState.LatestFinalPointPosition, + }; + } + + /// + /// Sets the point into a degraded state. + /// ReportedPointPosition the PointDegradedMessage. + /// + /// public async Task SetDegraded(PointDegradedMessage message) { - var previousPosition = _pointState.PointPosition; _pointState.PointPosition = ReportedPointPosition.PointIsInNoEndPosition; if (_currentConnection != null) { ReportedDegradedPointPosition? reportedDegradedPointPosition = _hasNoNonCrucialPointMachines ? ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : - GetReportedDegradedPointPosition(previousPosition); + GetReportedDegradedPointPosition(_pointState.LatestFinalPointPosition); if (reportedDegradedPointPosition != null) { - ReportedPointPosition? reportedPointPosition = GetReportedPointPosition(message.Position); + ReportedPointPosition? reportedPointPosition = GetReportedPointPositionDegraded(message.Position); if (reportedPointPosition != null) { UpdatePointState((ReportedPointPosition)reportedPointPosition, (ReportedDegradedPointPosition)reportedDegradedPointPosition); @@ -142,8 +162,31 @@ public async Task SetDegraded(PointDegradedMessage message) await UpdateConnectedWebClients(); } + /// + /// Sets the ReportedPointPosition to the latest final position (left/right). + /// + /// + public async Task FinalizePosition(){ + + if (_currentConnection != null) + { + if (_pointState.PointPosition != ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition && + _pointState.PointPosition != ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition) { + ReportedDegradedPointPosition reportedDegradedPointPosition = _hasNoNonCrucialPointMachines ? + ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : ReportedDegradedPointPosition.PointIsNotInADegradedPosition; + + UpdatePointState(_pointState.LatestFinalPointPosition, reportedDegradedPointPosition); + + var occupancyStatus = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(occupancyStatus.ToByteArray()) }); + } + } + await UpdateConnectedWebClients(); + } + protected override async Task ExecuteAsync(CancellationToken stoppingToken) { + _hasNoNonCrucialPointMachines = _configuration.GetSection("PointSettings").Get()?.hasNoNonCrucialPointMachines ?? false; // Command line argument parsing. _localId = _configuration["local-id"]; if (_localId == null) @@ -236,8 +279,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) continue; } - _pointState.PointPosition = ReportedPointPosition.PointIsInNoEndPosition; - _pointState.DegradedPointPosition = ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable; + UpdatePointState(ReportedPointPosition.PointIsInNoEndPosition, ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable); + await UpdateConnectedWebClients(); // Simulate point movement @@ -252,10 +295,11 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) if (await Task.WhenAny(transitioningTask, Task.Delay(timeout)) == transitioningTask) { // transition completed within timeout - _pointState.PointPosition = + UpdatePointState( movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving ? ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition - : ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition; + : ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition + ); await UpdateConnectedWebClients(); @@ -274,10 +318,11 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) else { await transitioningTask; - _pointState.PointPosition = + UpdatePointState( movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving ? ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition - : ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition; + : ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition + ); await UpdateConnectedWebClients(); From bd85c5be78484b8f0fc6839368e3548a56f630b2 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Thu, 16 Nov 2023 11:06:09 +0100 Subject: [PATCH 07/14] update point settings and configuration --- src/Point/Point.cs | 9 +++++++++ src/Point/appsettings.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Point/Point.cs b/src/Point/Point.cs index 55ae096..d047d4d 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -187,6 +187,15 @@ public async Task FinalizePosition(){ protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _hasNoNonCrucialPointMachines = _configuration.GetSection("PointSettings").Get()?.hasNoNonCrucialPointMachines ?? false; + var tmp_hasNoNonCrucialPointMachines = _configuration["crucial-point-machines"]; + if (tmp_hasNoNonCrucialPointMachines == null) + { + _logger.LogInformation($"Missing --crucial-point-machines command line parameter. Using value {_hasNoNonCrucialPointMachines}."); + } else + { + _hasNoNonCrucialPointMachines = bool.Parse(tmp_hasNoNonCrucialPointMachines); + } + // Command line argument parsing. _localId = _configuration["local-id"]; if (_localId == null) diff --git a/src/Point/appsettings.json b/src/Point/appsettings.json index 56cc7c6..863e6c8 100644 --- a/src/Point/appsettings.json +++ b/src/Point/appsettings.json @@ -8,7 +8,7 @@ }, "AllowedHosts": "*", "PointSettings": { - "_hasNoNonCrucialPointMachines": true + "hasNoNonCrucialPointMachines": false }, "Kestrel": { "EndPoints": { From f92669ad7d351acdf104cd1f4efa79bf1e0edf16 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Thu, 16 Nov 2023 16:34:30 +0100 Subject: [PATCH 08/14] resolve comments --- .../PointMachine/PointMachineState.cs | 1 - src/Point/Point.cs | 58 +++++++++---------- src/Point/appsettings.json | 2 +- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/Point/Components/PointMachine/PointMachineState.cs b/src/Point/Components/PointMachine/PointMachineState.cs index 397cdcb..f6f049b 100644 --- a/src/Point/Components/PointMachine/PointMachineState.cs +++ b/src/Point/Components/PointMachine/PointMachineState.cs @@ -6,7 +6,6 @@ namespace EulynxLive.Point.Components { public class PointMachineState { - public ReportedPointPosition LatestFinalPointPosition { get; set; } public ReportedPointPosition PointPosition { get; set; } public ReportedDegradedPointPosition DegradedPointPosition { get; set; } public PointMachineStateMessage.Target Target { get; set; } diff --git a/src/Point/Point.cs b/src/Point/Point.cs index d047d4d..bcb5137 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -32,14 +32,14 @@ public class Point : BackgroundService private string _remoteId; private string _remoteEndpoint; private readonly Random _random; - private bool _hasNoNonCrucialPointMachines; + private bool allPointMachinesCrucial; private bool _initialized; AsyncDuplexStreamingCall _currentConnection; private PointMachineState _pointState; public PointMachineState PointState { get { return _pointState; } } - public record PointConfiguration(bool hasNoNonCrucialPointMachines); + public record PointConfiguration(bool allPointMachinesCrucial); public Point(ILogger logger, IConfiguration configuration, PointMachineState pointState) @@ -52,7 +52,7 @@ public Point(ILogger logger, IConfiguration configuration, PointMachineSt _pointState = pointState; _pointState.PointPosition = ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition; - _pointState.LatestFinalPointPosition = _pointState.PointPosition; + _pointState.DegradedPointPosition = allPointMachinesCrucial? ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : ReportedDegradedPointPosition.PointIsNotInADegradedPosition; } public async Task HandleWebSocket(WebSocket webSocket) @@ -113,22 +113,12 @@ public async Task SimulateTrailed() _ => null, }; - private void UpdatePointState(ReportedPointPosition reportedPointPosition, ReportedDegradedPointPosition reportedDegradedPointPosition) { - UpdatePointState(reportedPointPosition); - _pointState.DegradedPointPosition = reportedDegradedPointPosition; + private void UpdatePointState(ReportedPointPosition pointPosition, ReportedDegradedPointPosition degradedPointPosition) { + UpdatePointState(pointPosition); + _pointState.DegradedPointPosition = degradedPointPosition; } - private void UpdatePointState(ReportedPointPosition reportedPointPosition) { - _pointState.PointPosition = reportedPointPosition; - SetLatestFinalPointPosition(reportedPointPosition); - } - - private void SetLatestFinalPointPosition(ReportedPointPosition reportedPointPosition) { - _pointState.LatestFinalPointPosition = reportedPointPosition switch - { - ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition => reportedPointPosition, - ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition => reportedPointPosition, - _ => _pointState.LatestFinalPointPosition, - }; + private void UpdatePointState(ReportedPointPosition pointPosition) { + _pointState.PointPosition = pointPosition; } @@ -143,13 +133,13 @@ public async Task SetDegraded(PointDegradedMessage message) if (_currentConnection != null) { - ReportedDegradedPointPosition? reportedDegradedPointPosition = _hasNoNonCrucialPointMachines ? + ReportedDegradedPointPosition? reportedDegradedPointPosition = allPointMachinesCrucial ? ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : - GetReportedDegradedPointPosition(_pointState.LatestFinalPointPosition); + GetReportedDegradedPointPosition(_pointState.PointPosition); if (reportedDegradedPointPosition != null) { - ReportedPointPosition? reportedPointPosition = GetReportedPointPositionDegraded(message.Position); + var reportedPointPosition = GetReportedPointPositionDegraded(message.Position); if (reportedPointPosition != null) { UpdatePointState((ReportedPointPosition)reportedPointPosition, (ReportedDegradedPointPosition)reportedDegradedPointPosition); @@ -172,13 +162,23 @@ public async Task FinalizePosition(){ { if (_pointState.PointPosition != ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition && _pointState.PointPosition != ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition) { - ReportedDegradedPointPosition reportedDegradedPointPosition = _hasNoNonCrucialPointMachines ? + var reportedDegradedPointPosition = allPointMachinesCrucial ? ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : ReportedDegradedPointPosition.PointIsNotInADegradedPosition; - - UpdatePointState(_pointState.LatestFinalPointPosition, reportedDegradedPointPosition); - var occupancyStatus = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(occupancyStatus.ToByteArray()) }); + ReportedPointPosition? finalPosition = _pointState.DegradedPointPosition switch + { + ReportedDegradedPointPosition.PointIsInADegradedRightHandPosition => ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, + ReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition => ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition, + ReportedDegradedPointPosition.PointIsNotInADegradedPosition => null, + ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable => null, + _ => null, + }; + if (finalPosition != null) + { + UpdatePointState((ReportedPointPosition)finalPosition, reportedDegradedPointPosition); + var positionMessage = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(positionMessage.ToByteArray()) }); + } } } await UpdateConnectedWebClients(); @@ -186,14 +186,14 @@ public async Task FinalizePosition(){ protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - _hasNoNonCrucialPointMachines = _configuration.GetSection("PointSettings").Get()?.hasNoNonCrucialPointMachines ?? false; + allPointMachinesCrucial = _configuration.GetSection("PointSettings").Get()?.allPointMachinesCrucial ?? false; var tmp_hasNoNonCrucialPointMachines = _configuration["crucial-point-machines"]; if (tmp_hasNoNonCrucialPointMachines == null) { - _logger.LogInformation($"Missing --crucial-point-machines command line parameter. Using value {_hasNoNonCrucialPointMachines}."); + _logger.LogInformation($"Missing --crucial-point-machines command line parameter. Using value {allPointMachinesCrucial}."); } else { - _hasNoNonCrucialPointMachines = bool.Parse(tmp_hasNoNonCrucialPointMachines); + allPointMachinesCrucial = bool.Parse(tmp_hasNoNonCrucialPointMachines); } // Command line argument parsing. diff --git a/src/Point/appsettings.json b/src/Point/appsettings.json index 863e6c8..1454f1b 100644 --- a/src/Point/appsettings.json +++ b/src/Point/appsettings.json @@ -8,7 +8,7 @@ }, "AllowedHosts": "*", "PointSettings": { - "hasNoNonCrucialPointMachines": false + "allPointMachinesCrucial": false }, "Kestrel": { "EndPoints": { From 2e709bd322e43de3f96a943a757e79b98d68d6be Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Thu, 16 Nov 2023 17:12:35 +0100 Subject: [PATCH 09/14] update configuration --- src/Point/Point.cs | 64 +++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/src/Point/Point.cs b/src/Point/Point.cs index bcb5137..d044787 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -32,14 +32,22 @@ public class Point : BackgroundService private string _remoteId; private string _remoteEndpoint; private readonly Random _random; - private bool allPointMachinesCrucial; + private bool _allPointMachinesCrucial; + private bool _simulateRandomTimeouts; private bool _initialized; AsyncDuplexStreamingCall _currentConnection; private PointMachineState _pointState; public PointMachineState PointState { get { return _pointState; } } - public record PointConfiguration(bool allPointMachinesCrucial); + public record PointConfiguration( + string LocalId, + int LocalRastaId, + string RemoteId, + string RemoteEndpoint, + bool? allPointMachinesCrucial = null, + bool? SimulateRandomTimeouts = null + ); public Point(ILogger logger, IConfiguration configuration, PointMachineState pointState) @@ -52,7 +60,7 @@ public Point(ILogger logger, IConfiguration configuration, PointMachineSt _pointState = pointState; _pointState.PointPosition = ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition; - _pointState.DegradedPointPosition = allPointMachinesCrucial? ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : ReportedDegradedPointPosition.PointIsNotInADegradedPosition; + _pointState.DegradedPointPosition = _allPointMachinesCrucial? ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : ReportedDegradedPointPosition.PointIsNotInADegradedPosition; } public async Task HandleWebSocket(WebSocket webSocket) @@ -133,7 +141,7 @@ public async Task SetDegraded(PointDegradedMessage message) if (_currentConnection != null) { - ReportedDegradedPointPosition? reportedDegradedPointPosition = allPointMachinesCrucial ? + ReportedDegradedPointPosition? reportedDegradedPointPosition = _allPointMachinesCrucial ? ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : GetReportedDegradedPointPosition(_pointState.PointPosition); @@ -162,7 +170,7 @@ public async Task FinalizePosition(){ { if (_pointState.PointPosition != ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition && _pointState.PointPosition != ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition) { - var reportedDegradedPointPosition = allPointMachinesCrucial ? + var reportedDegradedPointPosition = _allPointMachinesCrucial ? ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : ReportedDegradedPointPosition.PointIsNotInADegradedPosition; ReportedPointPosition? finalPosition = _pointState.DegradedPointPosition switch @@ -186,42 +194,28 @@ public async Task FinalizePosition(){ protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - allPointMachinesCrucial = _configuration.GetSection("PointSettings").Get()?.allPointMachinesCrucial ?? false; - var tmp_hasNoNonCrucialPointMachines = _configuration["crucial-point-machines"]; - if (tmp_hasNoNonCrucialPointMachines == null) - { - _logger.LogInformation($"Missing --crucial-point-machines command line parameter. Using value {allPointMachinesCrucial}."); - } else - { - allPointMachinesCrucial = bool.Parse(tmp_hasNoNonCrucialPointMachines); - } - - // Command line argument parsing. - _localId = _configuration["local-id"]; - if (_localId == null) + try { - throw new Exception("Missing --local-id command line parameter."); - } + var config = _configuration.GetSection("PointSettings").Get(); + if (config.allPointMachinesCrucial == null) + { + _logger.LogInformation("Assuming all point machines are critical"); + } - _localRastaId = _configuration["local-rasta-id"]; - if (_localRastaId == null) - { - throw new Exception("Missing --local-rasta-id command line parameter."); + _allPointMachinesCrucial = config.allPointMachinesCrucial ?? false; + _localId = config.LocalId; + _localRastaId = config.LocalRastaId.ToString(); + _remoteId = config.RemoteId; + _remoteEndpoint = config.RemoteEndpoint; + _simulateRandomTimeouts = config.SimulateRandomTimeouts ?? false; } - - _remoteId = _configuration["remote-id"]; - if (_remoteId == null) + catch (Exception e) { - throw new Exception("Missing --remote-id command line parameter."); - } + _logger.LogError($"Usage: --PointSettings:LocalId=<> --PointSettings:LocalRastaId=<> --PointSettings:RemoteId=<> --PointSettings:RemoteEndpoint=<>. \n {e.Message}"); - _remoteEndpoint = _configuration["remote-endpoint"]; - if (_remoteEndpoint == null) - { - throw new Exception("Missing --remote-endpoint command line parameter."); + throw; } - var simulateRandomTimeouts = _configuration["simulate-timeouts"]; // Main loop. @@ -299,7 +293,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) _logger.LogDebug("Moving to {}.", movePointCommand.CommandedPointPosition); - if (simulateRandomTimeouts != null) + if (_simulateRandomTimeouts != null) { if (await Task.WhenAny(transitioningTask, Task.Delay(timeout)) == transitioningTask) { From 9bdbedded88d857e67df9788aa8cc14823cf0e13 Mon Sep 17 00:00:00 2001 From: Robert Schmid Date: Fri, 17 Nov 2023 22:52:54 +0100 Subject: [PATCH 10/14] Cleanup and rename a few things --- .../PointMachine/PointMachineState.cs | 1 - src/Point/Point.cs | 218 ++++++++---------- src/Point/Point.csproj | 2 + src/Point/PointConfiguration.cs | 10 + .../ReportedPointPositionProtoConversion.cs | 6 +- src/Point/Services/PointService.cs | 40 ++-- src/Point/Startup.cs | 12 +- src/Point/appsettings.Development.json | 10 +- src/Point/appsettings.json | 2 +- src/ProtobufInterfaces/proto/point.proto | 30 +-- 10 files changed, 168 insertions(+), 163 deletions(-) create mode 100644 src/Point/PointConfiguration.cs diff --git a/src/Point/Components/PointMachine/PointMachineState.cs b/src/Point/Components/PointMachine/PointMachineState.cs index f6f049b..81f5220 100644 --- a/src/Point/Components/PointMachine/PointMachineState.cs +++ b/src/Point/Components/PointMachine/PointMachineState.cs @@ -11,6 +11,5 @@ public class PointMachineState public PointMachineStateMessage.Target Target { get; set; } public PointMachineStateMessage.AbilityToMove AbilityToMove { get; set; } public PointMachineStateMessage.LastPointPosition LastPointPosition { get; set; } - public PointMachineStateMessage.Crucial Crucial { get; set; } } } diff --git a/src/Point/Point.cs b/src/Point/Point.cs index d044787..80fa9db 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -11,8 +11,8 @@ using Microsoft.Extensions.Logging; using Sci; using EulynxLive.Messages.Baseline4R1; -using ReportedPointPosition = EulynxLive.Messages.Baseline4R1.PointPointPositionMessageReportedPointPosition; -using ReportedDegradedPointPosition = EulynxLive.Messages.Baseline4R1.PointPointPositionMessageReportedDegradedPointPosition; +using PointPosition = EulynxLive.Messages.Baseline4R1.PointPointPositionMessageReportedPointPosition; +using DegradedPointPosition = EulynxLive.Messages.Baseline4R1.PointPointPositionMessageReportedDegradedPointPosition; using static Sci.Rasta; using System.Text; using Grpc.Net.Client; @@ -24,43 +24,44 @@ namespace EulynxLive.Point { public class Point : BackgroundService { + public bool AllPointMachinesCrucial { get; } + private readonly ILogger _logger; - private readonly IConfiguration _configuration; private readonly List _webSockets; - private string _localId; - private string _localRastaId; - private string _remoteId; - private string _remoteEndpoint; + private readonly string _localId; + private readonly string _localRastaId; + private readonly string _remoteId; + private readonly string _remoteEndpoint; private readonly Random _random; - private bool _allPointMachinesCrucial; - private bool _simulateRandomTimeouts; - + private readonly bool _simulateRandomTimeouts; private bool _initialized; - AsyncDuplexStreamingCall _currentConnection; - private PointMachineState _pointState; + AsyncDuplexStreamingCall? _currentConnection; + private readonly PointMachineState _pointState; public PointMachineState PointState { get { return _pointState; } } - public record PointConfiguration( - string LocalId, - int LocalRastaId, - string RemoteId, - string RemoteEndpoint, - bool? allPointMachinesCrucial = null, - bool? SimulateRandomTimeouts = null - ); - - public Point(ILogger logger, IConfiguration configuration, PointMachineState pointState) { _logger = logger; - _configuration = configuration; _webSockets = new List(); _currentConnection = null; _random = new Random(); + var config = configuration.GetSection("PointSettings").Get() ?? throw new Exception("No configuration provided"); + if (config.AllPointMachinesCrucial == null) + { + _logger.LogInformation("Assuming all point machines are crucial."); + } + + AllPointMachinesCrucial = config.AllPointMachinesCrucial ?? false; + _localId = config.LocalId; + _localRastaId = config.LocalRastaId.ToString(); + _remoteId = config.RemoteId; + _remoteEndpoint = config.RemoteEndpoint; + _simulateRandomTimeouts = config.SimulateRandomTimeouts ?? false; + _pointState = pointState; - _pointState.PointPosition = ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition; - _pointState.DegradedPointPosition = _allPointMachinesCrucial? ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : ReportedDegradedPointPosition.PointIsNotInADegradedPosition; + _pointState.PointPosition = PointPosition.PointIsInARightHandPositionDefinedEndPosition; + _pointState.DegradedPointPosition = AllPointMachinesCrucial ? DegradedPointPosition.DegradedPointPositionIsNotApplicable : DegradedPointPosition.PointIsNotInADegradedPosition; } public async Task HandleWebSocket(WebSocket webSocket) @@ -73,7 +74,7 @@ public async Task HandleWebSocket(WebSocket webSocket) while (true) { byte[] messageBuffer = new byte[1024]; - ArraySegment buffer = new ArraySegment(messageBuffer); + var buffer = new ArraySegment(messageBuffer); var result = await webSocket.ReceiveAsync(buffer, CancellationToken.None); if (result.CloseStatus.HasValue) { @@ -88,9 +89,9 @@ public async Task HandleWebSocket(WebSocket webSocket) _webSockets.Remove(webSocket); } - public async Task SimulateTrailed() + public async Task SimulateUnintendedPosition() { - _pointState.PointPosition = ReportedPointPosition.PointIsTrailed; + _pointState.PointPosition = PointPosition.PointIsTrailed; if (_currentConnection != null) { @@ -101,56 +102,55 @@ public async Task SimulateTrailed() await UpdateConnectedWebClients(); } - private ReportedDegradedPointPosition? GetReportedDegradedPointPosition(ReportedPointPosition previousReportedPosition) => previousReportedPosition switch - { - ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition - => ReportedDegradedPointPosition.PointIsInADegradedRightHandPosition, - ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition - => ReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition, - ReportedPointPosition.PointIsInNoEndPosition + private static DegradedPointPosition? GetDegradedPointPosition(PointPosition previousReportedPosition) + => previousReportedPosition switch { + PointPosition.PointIsInARightHandPositionDefinedEndPosition + => DegradedPointPosition.PointIsInADegradedRightHandPosition, + PointPosition.PointIsInALeftHandPositionDefinedEndPosition + => DegradedPointPosition.PointIsInADegradedLeftHandPosition, + PointPosition.PointIsInNoEndPosition => null, - ReportedPointPosition.PointIsTrailed + PointPosition.PointIsTrailed => null, _ => null, }; - private ReportedPointPosition? GetReportedPointPositionDegraded(PointPosition pointPosition) => pointPosition switch + private static PointPosition? GetPointPositionDegraded(Proto.PointPosition pointPosition) => pointPosition switch { - PointPosition.NoEndPosition => ReportedPointPosition.PointIsInNoEndPosition, - PointPosition.Trailed => ReportedPointPosition.PointIsTrailed, + Proto.PointPosition.NoEndPosition => PointPosition.PointIsInNoEndPosition, + Proto.PointPosition.UnintendedPosition => PointPosition.PointIsTrailed, _ => null, }; - private void UpdatePointState(ReportedPointPosition pointPosition, ReportedDegradedPointPosition degradedPointPosition) { + private void UpdatePointState(PointPosition pointPosition, DegradedPointPosition degradedPointPosition) { UpdatePointState(pointPosition); _pointState.DegradedPointPosition = degradedPointPosition; } - private void UpdatePointState(ReportedPointPosition pointPosition) { + + private void UpdatePointState(PointPosition pointPosition) { _pointState.PointPosition = pointPosition; } - /// - /// Sets the point into a degraded state. + /// Sets the point into a degraded state. /// ReportedPointPosition the PointDegradedMessage. /// /// public async Task SetDegraded(PointDegradedMessage message) { - _pointState.PointPosition = ReportedPointPosition.PointIsInNoEndPosition; + _pointState.PointPosition = PointPosition.PointIsInNoEndPosition; if (_currentConnection != null) { - ReportedDegradedPointPosition? reportedDegradedPointPosition = _allPointMachinesCrucial ? - ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : - GetReportedDegradedPointPosition(_pointState.PointPosition); + var degradedPointPosition = AllPointMachinesCrucial ? + DegradedPointPosition.DegradedPointPositionIsNotApplicable : GetDegradedPointPosition(_pointState.PointPosition); - if (reportedDegradedPointPosition != null) + if (degradedPointPosition != null) { - var reportedPointPosition = GetReportedPointPositionDegraded(message.Position); - if (reportedPointPosition != null) + var pointPosition = GetPointPositionDegraded(message.Position); + if (pointPosition != null) { - UpdatePointState((ReportedPointPosition)reportedPointPosition, (ReportedDegradedPointPosition)reportedDegradedPointPosition); + UpdatePointState(pointPosition.Value, degradedPointPosition.Value); var occupancyStatus = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(occupancyStatus.ToByteArray()) }); } @@ -164,29 +164,29 @@ public async Task SetDegraded(PointDegradedMessage message) /// Sets the ReportedPointPosition to the latest final position (left/right). /// /// - public async Task FinalizePosition(){ - + public async Task PutInEndPosition(){ + if (_currentConnection != null) { - if (_pointState.PointPosition != ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition && - _pointState.PointPosition != ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition) { - var reportedDegradedPointPosition = _allPointMachinesCrucial ? - ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable : ReportedDegradedPointPosition.PointIsNotInADegradedPosition; + if (_pointState.PointPosition != PointPosition.PointIsInARightHandPositionDefinedEndPosition && + _pointState.PointPosition != PointPosition.PointIsInALeftHandPositionDefinedEndPosition) { + var reportedDegradedPointPosition = AllPointMachinesCrucial ? + DegradedPointPosition.DegradedPointPositionIsNotApplicable : DegradedPointPosition.PointIsNotInADegradedPosition; - ReportedPointPosition? finalPosition = _pointState.DegradedPointPosition switch + PointPosition? finalPosition = _pointState.DegradedPointPosition switch { - ReportedDegradedPointPosition.PointIsInADegradedRightHandPosition => ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, - ReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition => ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition, - ReportedDegradedPointPosition.PointIsNotInADegradedPosition => null, - ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable => null, + DegradedPointPosition.PointIsInADegradedRightHandPosition => PointPosition.PointIsInARightHandPositionDefinedEndPosition, + DegradedPointPosition.PointIsInADegradedLeftHandPosition => PointPosition.PointIsInALeftHandPositionDefinedEndPosition, + DegradedPointPosition.PointIsNotInADegradedPosition => null, + DegradedPointPosition.DegradedPointPositionIsNotApplicable => null, _ => null, }; - if (finalPosition != null) + if (finalPosition != null) { - UpdatePointState((ReportedPointPosition)finalPosition, reportedDegradedPointPosition); + UpdatePointState((PointPosition)finalPosition, reportedDegradedPointPosition); var positionMessage = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(positionMessage.ToByteArray()) }); - } + } } } await UpdateConnectedWebClients(); @@ -194,29 +194,6 @@ public async Task FinalizePosition(){ protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - try - { - var config = _configuration.GetSection("PointSettings").Get(); - if (config.allPointMachinesCrucial == null) - { - _logger.LogInformation("Assuming all point machines are critical"); - } - - _allPointMachinesCrucial = config.allPointMachinesCrucial ?? false; - _localId = config.LocalId; - _localRastaId = config.LocalRastaId.ToString(); - _remoteId = config.RemoteId; - _remoteEndpoint = config.RemoteEndpoint; - _simulateRandomTimeouts = config.SimulateRandomTimeouts ?? false; - } - catch (Exception e) - { - _logger.LogError($"Usage: --PointSettings:LocalId=<> --PointSettings:LocalRastaId=<> --PointSettings:RemoteId=<> --PointSettings:RemoteEndpoint=<>. \n {e.Message}"); - - throw; - } - - // Main loop. while (true) @@ -227,15 +204,15 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) var channel = GrpcChannel.ForAddress(_remoteEndpoint); var client = new RastaClient(channel); _logger.LogTrace("Connecting..."); - var cancellationTokenSource = new CancellationTokenSource(); - cancellationTokenSource.CancelAfter(10000); + var timeout = new CancellationTokenSource(); + timeout.CancelAfter(10000); var metadata = new Metadata { { "rasta-id", _localRastaId } }; - using (_currentConnection = client.Stream(metadata)) + using (_currentConnection = client.Stream(metadata, cancellationToken: timeout.Token)) { _logger.LogTrace("Connected. Waiting for request..."); - if (!await _currentConnection.ResponseStream.MoveNext(cancellationTokenSource.Token) - || !(Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is PointPdiVersionCheckCommand)) + if (!await _currentConnection.ResponseStream.MoveNext(timeout.Token) + || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointPdiVersionCheckCommand) { _logger.LogError("Unexpected message."); break; @@ -244,8 +221,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) var versionCheckResponse = new PointPdiVersionCheckMessage(_localId, _remoteId, PointPdiVersionCheckMessageResultPdiVersionCheck.PDIVersionsFromReceiverAndSenderDoMatch, /* TODO */ 0, 0, new byte[] { }); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(versionCheckResponse.ToByteArray()) }); - if (!await _currentConnection.ResponseStream.MoveNext(cancellationTokenSource.Token) - || !(Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is PointInitialisationRequestCommand)) + if (!await _currentConnection.ResponseStream.MoveNext(timeout.Token) + || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointInitialisationRequestCommand) { _logger.LogError("Unexpected message."); break; @@ -274,46 +251,46 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) if (message is PointMovePointCommand movePointCommand) { - if ((movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving && _pointState.PointPosition == ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition) - || (movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsALeftHandPointMoving && _pointState.PointPosition == ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition)) + if ((movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving && _pointState.PointPosition == PointPosition.PointIsInARightHandPositionDefinedEndPosition) + || (movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsALeftHandPointMoving && _pointState.PointPosition == PointPosition.PointIsInALeftHandPositionDefinedEndPosition)) { var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); continue; } - UpdatePointState(ReportedPointPosition.PointIsInNoEndPosition, ReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable); - + UpdatePointState(PointPosition.PointIsInNoEndPosition, DegradedPointPosition.DegradedPointPositionIsNotApplicable); + await UpdateConnectedWebClients(); // Simulate point movement var transitioningTime = _random.Next(1, 5); var transitioningTask = Task.Delay(transitioningTime * 1000); - var timeout = 3; + var pointMovementTimeout = 3 * 1000; _logger.LogDebug("Moving to {}.", movePointCommand.CommandedPointPosition); - if (_simulateRandomTimeouts != null) + if (_simulateRandomTimeouts) { - if (await Task.WhenAny(transitioningTask, Task.Delay(timeout)) == transitioningTask) + if (await Task.WhenAny(transitioningTask, Task.Delay(pointMovementTimeout)) == transitioningTask) { // transition completed within timeout UpdatePointState( movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving - ? ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition - : ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition + ? PointPosition.PointIsInARightHandPositionDefinedEndPosition + : PointPosition.PointIsInALeftHandPositionDefinedEndPosition ); await UpdateConnectedWebClients(); - _logger.LogDebug("End position reached."); + _logger.LogInformation("End position reached."); var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); } else { // timeout - _logger.LogDebug("Timeout"); + _logger.LogInformation("Timeout"); var response = new PointTimeoutMessage(_localId, _remoteId); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); } @@ -323,29 +300,36 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) await transitioningTask; UpdatePointState( movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving - ? ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition - : ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition + ? PointPosition.PointIsInARightHandPositionDefinedEndPosition + : PointPosition.PointIsInALeftHandPositionDefinedEndPosition ); await UpdateConnectedWebClients(); - _logger.LogDebug("End position reached."); + _logger.LogInformation("End position reached."); var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); } } else { - _logger.LogInformation($"Received unknown message {message.GetType().ToString()}"); + _logger.LogInformation("Received unknown message {}", message.GetType()); } } } } + catch (RpcException) + { + _logger.LogWarning("Could not communicate with remote endpoint."); + } catch (Exception ex) { - _logger.LogWarning(ex, "Exception during simulation. Resetting."); + _logger.LogWarning(ex, "Exception during simulation."); + } + finally + { await Reset(); - await Task.Delay(1000); + await Task.Delay(1000, stoppingToken); } } } @@ -371,11 +355,11 @@ private async Task UpdateConnectedWebClients() private async Task UpdateWebClient(WebSocket webSocket) { - var positions = new Dictionary { - {ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, "right"}, - {ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition, "left"}, - {ReportedPointPosition.PointIsInNoEndPosition, "noEndPosition"}, - {ReportedPointPosition.PointIsTrailed, "trailed"}, + var positions = new Dictionary { + {PointPosition.PointIsInARightHandPositionDefinedEndPosition, "right"}, + {PointPosition.PointIsInALeftHandPositionDefinedEndPosition, "left"}, + {PointPosition.PointIsInNoEndPosition, "noEndPosition"}, + {PointPosition.PointIsTrailed, "trailed"}, }; var options = new JsonSerializerOptions { WriteIndented = true }; var serializedState = JsonSerializer.Serialize(new diff --git a/src/Point/Point.csproj b/src/Point/Point.csproj index a9e9a16..cbf924f 100644 --- a/src/Point/Point.csproj +++ b/src/Point/Point.csproj @@ -2,6 +2,8 @@ net7.0 + enable + enable true latest false diff --git a/src/Point/PointConfiguration.cs b/src/Point/PointConfiguration.cs new file mode 100644 index 0000000..7f753a4 --- /dev/null +++ b/src/Point/PointConfiguration.cs @@ -0,0 +1,10 @@ +namespace EulynxLive.Point; + +public record PointConfiguration( + string LocalId, + int LocalRastaId, + string RemoteId, + string RemoteEndpoint, + bool? AllPointMachinesCrucial = null, + bool? SimulateRandomTimeouts = null +); diff --git a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs index b84bd11..5d00fcb 100644 --- a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs +++ b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs @@ -11,7 +11,7 @@ public static class ReportedPointPositionProtoConversion ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition => PointPosition.Right, ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition => PointPosition.Left, ReportedPointPosition.PointIsInNoEndPosition => PointPosition.NoEndPosition, - ReportedPointPosition.PointIsTrailed => PointPosition.Trailed, + ReportedPointPosition.PointIsTrailed => PointPosition.UnintendedPosition, _ => throw new InvalidCastException($"Unable to convert reported point position {reportedPointPosition} to proto enum") }; @@ -20,8 +20,8 @@ public static class ReportedPointPositionProtoConversion PointPosition.Right => ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, PointPosition.Left => ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition, PointPosition.NoEndPosition => ReportedPointPosition.PointIsInNoEndPosition, - PointPosition.Trailed => ReportedPointPosition.PointIsTrailed, + PointPosition.UnintendedPosition => ReportedPointPosition.PointIsTrailed, _ => throw new InvalidCastException($"Unable to convert point position message {pointPositionMessage} to reported point position.") }; } -} \ No newline at end of file +} diff --git a/src/Point/Services/PointService.cs b/src/Point/Services/PointService.cs index 13e45b2..b60a458 100644 --- a/src/Point/Services/PointService.cs +++ b/src/Point/Services/PointService.cs @@ -3,6 +3,8 @@ using static EulynxLive.Point.Proto.Point; using EulynxLive.Point.Proto; using Point.Services.Extensions; +using Google.Protobuf.WellKnownTypes; +using System; namespace EulynxLive.Point.Services { @@ -15,27 +17,27 @@ public PointService(Point point) _point = point; } - public override async Task SimulateTrailed(Nothing request, ServerCallContext context) + public override async Task SimulateUnintendedPosition(Empty request, ServerCallContext context) { - await _point.SimulateTrailed(); - return new Nothing(); + await _point.SimulateUnintendedPosition(); + return new Empty(); } - public override async Task SetDegraded(PointDegradedMessage request, ServerCallContext context) + public override async Task SetToDegradedPosition(PointDegradedMessage request, ServerCallContext context) { await _point.SetDegraded(request); - return new Nothing(); + return new Empty(); } - public override async Task FinalizePosition(Nothing request, ServerCallContext context) + public override async Task PutInEndPosition(Empty request, ServerCallContext context) { - await _point.FinalizePosition(); - return new Nothing(); + await _point.PutInEndPosition(); + return new Empty(); } - public override Task GetPointPosition(Nothing request, ServerCallContext context) + public override Task GetPointPosition(Empty request, ServerCallContext context) { - var response = new Proto.PointPositionMessage() + var response = new PointPositionMessage() { Position = _point.PointState.PointPosition.ConvertToProtoMessage() }; @@ -43,27 +45,27 @@ public override async Task FinalizePosition(Nothing request, ServerCall return Task.FromResult(response); } - public override Task SetPointMachineState(PointMachineStateMessage request, ServerCallContext context) + public override Task EstablishPointMachineState(PointMachineStateMessage request, ServerCallContext context) { + // Perform validation + if (request.Crucial == PointMachineStateMessage.Types.Crucial.Crucial && !_point.AllPointMachinesCrucial) { + throw new InvalidOperationException("Point has only crucial point machines"); + } + _point.PointState.AbilityToMove = request.AbilityToMove; - _point.PointState.Crucial = request.Crucial; _point.PointState.LastPointPosition = request.LastPointPosition; _point.PointState.PointPosition = request.PointPosition.ConvertToReportedPointPosition(); _point.PointState.Target = request.Target; - return Task.FromResult(new SetPointMachineStateResponse() - { - NewState = request, - Success = true, - }); + return Task.FromResult(new Empty()); } - public override Task GetPointMachineState(Nothing request, ServerCallContext context) + public override Task GetPointMachineState(Empty request, ServerCallContext context) { return Task.FromResult(new PointMachineStateMessage() { AbilityToMove = _point.PointState.AbilityToMove, - Crucial = _point.PointState.Crucial, + Crucial = _point.AllPointMachinesCrucial ? PointMachineStateMessage.Types.Crucial.Crucial : PointMachineStateMessage.Types.Crucial.NonCrucial, LastPointPosition = _point.PointState.LastPointPosition, PointPosition = _point.PointState.PointPosition.ConvertToProtoMessage(), Target = _point.PointState.Target, diff --git a/src/Point/Startup.cs b/src/Point/Startup.cs index 7559e3d..aa0a876 100644 --- a/src/Point/Startup.cs +++ b/src/Point/Startup.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Hosting; using EulynxLive.Point.Services; using EulynxLive.Point.Components; +using System; namespace EulynxLive.Point { @@ -30,9 +31,16 @@ public void ConfigureServices(IServiceCollection services) { configuration.RootPath = "rasta-point-web/build"; }); - services.AddSingleton(); + + try { + services.AddSingleton(); + } catch (Exception e) { + Console.WriteLine($"Usage: --PointSettings:LocalId=<> --PointSettings:LocalRastaId=<> --PointSettings:RemoteId=<> --PointSettings:RemoteEndpoint=<>. {e.Message}"); + Environment.Exit(1); + } + services.AddSingleton(); - services.AddHostedService(provider => provider.GetService()); + _ = services.AddHostedService(provider => provider.GetService()); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/src/Point/appsettings.Development.json b/src/Point/appsettings.Development.json index 5784615..03deedf 100644 --- a/src/Point/appsettings.Development.json +++ b/src/Point/appsettings.Development.json @@ -6,5 +6,13 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "PointSettings": { + "LocalId": "99W1", + "LocalRastaId": 100, + "RemoteId": "INTERLOCKING", + "RemoteEndpoint": "http://localhost:50051", + "AllPointMachinesCrucial": true, + "SimulateRandomTimeouts": true + } } diff --git a/src/Point/appsettings.json b/src/Point/appsettings.json index 1454f1b..149bd3f 100644 --- a/src/Point/appsettings.json +++ b/src/Point/appsettings.json @@ -8,7 +8,7 @@ }, "AllowedHosts": "*", "PointSettings": { - "allPointMachinesCrucial": false + "AllPointMachinesCrucial": true }, "Kestrel": { "EndPoints": { diff --git a/src/ProtobufInterfaces/proto/point.proto b/src/ProtobufInterfaces/proto/point.proto index cddef21..8e05fc1 100644 --- a/src/ProtobufInterfaces/proto/point.proto +++ b/src/ProtobufInterfaces/proto/point.proto @@ -2,24 +2,25 @@ syntax = "proto3"; option csharp_namespace = "EulynxLive.Point.Proto"; +import "google/protobuf/empty.proto"; package point; enum PointPosition { Right = 0; Left = 1; NoEndPosition = 2; - Trailed = 3; + UnintendedPosition = 3; } service Point { - rpc SimulateTrailed (Nothing) returns (Nothing) {} - rpc SetDegraded (PointDegradedMessage) returns (Nothing) {} - rpc FinalizePosition (Nothing) returns (Nothing) {} - rpc GetPointPosition (Nothing) returns (PointPositionMessage) {} - rpc SetPointMachineState (PointMachineStateMessage) returns (SetPointMachineStateResponse) {} - rpc GetPointMachineState (Nothing) returns (PointMachineStateMessage) {} + rpc SimulateUnintendedPosition (google.protobuf.Empty) returns (google.protobuf.Empty) {} + rpc SetToDegradedPosition (PointDegradedMessage) returns (google.protobuf.Empty) {} + rpc PutInEndPosition (google.protobuf.Empty) returns (google.protobuf.Empty) {} + rpc GetPointPosition (google.protobuf.Empty) returns (PointPositionMessage) {} + rpc EstablishPointMachineState (PointMachineStateMessage) returns (google.protobuf.Empty) {} + rpc GetPointMachineState (google.protobuf.Empty) returns (PointMachineStateMessage) {} } message PointDegradedMessage { @@ -37,18 +38,18 @@ message PointMachineStateMessage { Target_Right = 2; Target_None = 3; } - + enum AbilityToMove { AbilityToMove_UNDEFINED = 0; AbilityToMove_Able = 1; AbilityToMove_Unable = 2; } - + enum LastPointPosition { LastPointPosition_UNDEFINED = 0; LastPointPosition_None = 1; } - + enum Crucial { Crucial_UNDEFINED = 0; Crucial_Crucial = 1; @@ -61,12 +62,3 @@ message PointMachineStateMessage { LastPointPosition lastPointPosition = 4; Crucial crucial = 5; } - -message SetPointMachineStateResponse { - PointMachineStateMessage newState = 1; - bool success = 2; -} - -message Nothing { -} - From b1978f4e2063e4138a6f942e9ef4a74b97fc6056 Mon Sep 17 00:00:00 2001 From: Robert Schmid Date: Mon, 20 Nov 2023 10:36:27 +0100 Subject: [PATCH 11/14] Add a test --- Subsystems.sln | 7 +++++ .../FieldElementSubsystems.Test.csproj | 30 ++++++++++++++++++ .../GlobalUsings.cs | 1 + .../Point/PointTest.cs | 31 +++++++++++++++++++ src/Point/Point.cs | 14 ++------- src/Point/Startup.cs | 3 +- 6 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 src/FieldElementSubsystems.Test/FieldElementSubsystems.Test.csproj create mode 100644 src/FieldElementSubsystems.Test/GlobalUsings.cs create mode 100644 src/FieldElementSubsystems.Test/Point/PointTest.cs diff --git a/Subsystems.sln b/Subsystems.sln index ac2ba8d..e288bcc 100644 --- a/Subsystems.sln +++ b/Subsystems.sln @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrainDetectionSystem", "src EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtobufInterfaces", "src\ProtobufInterfaces\ProtobufInterfaces.csproj", "{965CC255-F89B-4FB5-9E21-3740C0CEDEE6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FieldElementSubsystems.Test", "src\FieldElementSubsystems.Test\FieldElementSubsystems.Test.csproj", "{8585AF02-898B-4D21-94EA-17EB71EF3ADD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -50,6 +52,10 @@ Global {965CC255-F89B-4FB5-9E21-3740C0CEDEE6}.Debug|Any CPU.Build.0 = Debug|Any CPU {965CC255-F89B-4FB5-9E21-3740C0CEDEE6}.Release|Any CPU.ActiveCfg = Release|Any CPU {965CC255-F89B-4FB5-9E21-3740C0CEDEE6}.Release|Any CPU.Build.0 = Release|Any CPU + {8585AF02-898B-4D21-94EA-17EB71EF3ADD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8585AF02-898B-4D21-94EA-17EB71EF3ADD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8585AF02-898B-4D21-94EA-17EB71EF3ADD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8585AF02-898B-4D21-94EA-17EB71EF3ADD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {BCBCDBD2-4E04-4C1D-A79E-40C4B6ED38DE} = {1146C126-94F3-476E-BADE-E40B22C98FA5} @@ -58,5 +64,6 @@ Global {01B16178-39DD-4279-B7AF-C74D816619E7} = {1146C126-94F3-476E-BADE-E40B22C98FA5} {767D8926-579F-4508-9CBC-3B46AA0ACE3D} = {1146C126-94F3-476E-BADE-E40B22C98FA5} {965CC255-F89B-4FB5-9E21-3740C0CEDEE6} = {1146C126-94F3-476E-BADE-E40B22C98FA5} + {8585AF02-898B-4D21-94EA-17EB71EF3ADD} = {1146C126-94F3-476E-BADE-E40B22C98FA5} EndGlobalSection EndGlobal diff --git a/src/FieldElementSubsystems.Test/FieldElementSubsystems.Test.csproj b/src/FieldElementSubsystems.Test/FieldElementSubsystems.Test.csproj new file mode 100644 index 0000000..65b70e1 --- /dev/null +++ b/src/FieldElementSubsystems.Test/FieldElementSubsystems.Test.csproj @@ -0,0 +1,30 @@ + + + + net7.0 + enable + enable + + false + true + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/src/FieldElementSubsystems.Test/GlobalUsings.cs b/src/FieldElementSubsystems.Test/GlobalUsings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/src/FieldElementSubsystems.Test/GlobalUsings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/src/FieldElementSubsystems.Test/Point/PointTest.cs b/src/FieldElementSubsystems.Test/Point/PointTest.cs new file mode 100644 index 0000000..b3d0ac1 --- /dev/null +++ b/src/FieldElementSubsystems.Test/Point/PointTest.cs @@ -0,0 +1,31 @@ +using Castle.Core.Logging; +using EulynxLive.Messages.Baseline4R1; +using EulynxLive.Point; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Moq; +namespace FieldElementSubsystems.Test; + +public class PointTest +{ + [Fact] + public void PointShouldParseConfiguration() + { + var testSettings = new Dictionary { + {"PointSettings:LocalId", "99W1" }, + {"PointSettings:LocalRastaId", "100" }, + {"PointSettings:RemoteId", "INTERLOCKING" }, + {"PointSettings:RemoteEndpoint", "http://localhost:50051" }, + {"PointSettings:AllPointMachinesCrucial", "true" }, + {"PointSettings:SimulateRandomTimeouts", "true" }, + }; + + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(testSettings) + .Build(); + + var point = new EulynxLive.Point.Point(Mock.Of>(), configuration); + + Assert.True(point.AllPointMachinesCrucial); + } +} diff --git a/src/Point/Point.cs b/src/Point/Point.cs index 80fa9db..d46ad2a 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -1,14 +1,7 @@ -using System.Linq; -using System.Collections.Generic; -using System.Net.WebSockets; +using System.Net.WebSockets; using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; using Google.Protobuf; using Grpc.Core; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using Sci; using EulynxLive.Messages.Baseline4R1; using PointPosition = EulynxLive.Messages.Baseline4R1.PointPointPositionMessageReportedPointPosition; @@ -17,7 +10,6 @@ using System.Text; using Grpc.Net.Client; using EulynxLive.Point.Components; -using System; using EulynxLive.Point.Proto; namespace EulynxLive.Point @@ -39,7 +31,7 @@ public class Point : BackgroundService private readonly PointMachineState _pointState; public PointMachineState PointState { get { return _pointState; } } - public Point(ILogger logger, IConfiguration configuration, PointMachineState pointState) + public Point(ILogger logger, IConfiguration configuration) { _logger = logger; _webSockets = new List(); @@ -59,7 +51,7 @@ public Point(ILogger logger, IConfiguration configuration, PointMachineSt _remoteEndpoint = config.RemoteEndpoint; _simulateRandomTimeouts = config.SimulateRandomTimeouts ?? false; - _pointState = pointState; + _pointState = new PointMachineState(); _pointState.PointPosition = PointPosition.PointIsInARightHandPositionDefinedEndPosition; _pointState.DegradedPointPosition = AllPointMachinesCrucial ? DegradedPointPosition.DegradedPointPositionIsNotApplicable : DegradedPointPosition.PointIsNotInADegradedPosition; } diff --git a/src/Point/Startup.cs b/src/Point/Startup.cs index aa0a876..4fb6601 100644 --- a/src/Point/Startup.cs +++ b/src/Point/Startup.cs @@ -39,8 +39,7 @@ public void ConfigureServices(IServiceCollection services) Environment.Exit(1); } - services.AddSingleton(); - _ = services.AddHostedService(provider => provider.GetService()); + _ = services.AddHostedService(provider => provider.GetRequiredService()); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. From c56888d82eb5302da319f890226d3aaeeefe5e1d Mon Sep 17 00:00:00 2001 From: Robert Schmid Date: Mon, 20 Nov 2023 10:38:10 +0100 Subject: [PATCH 12/14] Run test in CI --- .github/workflows/docker-images.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-images.yml b/.github/workflows/docker-images.yml index 9b2925c..2fd4bb4 100644 --- a/.github/workflows/docker-images.yml +++ b/.github/workflows/docker-images.yml @@ -38,10 +38,15 @@ jobs: with: dotnet-version: 6.0.x - name: Restore dependencies - run: dotnet restore src/${{ matrix.subsystem }} + run: | + dotnet restore src/${{ matrix.subsystem }} + dotnet restore FieldElementSubsystems.Test - name: Build run: dotnet publish -c Release --no-restore src/${{ matrix.subsystem }} + - name: Test + run: dotnet test --no-restore FieldElementSubsystems.Test + - name: Set up QEMU uses: docker/setup-qemu-action@v2 From 2e5bd2891dfe9d6a37fa7ebfcccaf237a9728330 Mon Sep 17 00:00:00 2001 From: Robert Schmid Date: Mon, 20 Nov 2023 10:39:06 +0100 Subject: [PATCH 13/14] Revert "Run test in CI" This reverts commit c56888d82eb5302da319f890226d3aaeeefe5e1d. --- .github/workflows/docker-images.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/docker-images.yml b/.github/workflows/docker-images.yml index 2fd4bb4..9b2925c 100644 --- a/.github/workflows/docker-images.yml +++ b/.github/workflows/docker-images.yml @@ -38,15 +38,10 @@ jobs: with: dotnet-version: 6.0.x - name: Restore dependencies - run: | - dotnet restore src/${{ matrix.subsystem }} - dotnet restore FieldElementSubsystems.Test + run: dotnet restore src/${{ matrix.subsystem }} - name: Build run: dotnet publish -c Release --no-restore src/${{ matrix.subsystem }} - - name: Test - run: dotnet test --no-restore FieldElementSubsystems.Test - - name: Set up QEMU uses: docker/setup-qemu-action@v2 From 89d2e0e6336b89e1ccf2f4d4b36da04e3e2b0b05 Mon Sep 17 00:00:00 2001 From: Robert Schmid Date: Mon, 20 Nov 2023 10:41:49 +0100 Subject: [PATCH 14/14] Add separate dotnet test workflow --- .github/workflows/docker-images.yml | 2 +- .github/workflows/dotnet-test.yml | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/dotnet-test.yml diff --git a/.github/workflows/docker-images.yml b/.github/workflows/docker-images.yml index 9b2925c..c888c6c 100644 --- a/.github/workflows/docker-images.yml +++ b/.github/workflows/docker-images.yml @@ -36,7 +36,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v2 with: - dotnet-version: 6.0.x + dotnet-version: 7.0.x - name: Restore dependencies run: dotnet restore src/${{ matrix.subsystem }} - name: Build diff --git a/.github/workflows/dotnet-test.yml b/.github/workflows/dotnet-test.yml new file mode 100644 index 0000000..127ab21 --- /dev/null +++ b/.github/workflows/dotnet-test.yml @@ -0,0 +1,19 @@ +name: dotnet test + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 7.0.x + - name: Restore dependencies + run: dotnet restore src/FieldElementSubsystems.Test + - name: Test + run: dotnet test --no-restore src/FieldElementSubsystems.Test