From 0ca6d555aa4bae683098ff757307bf0718721e7a Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Sun, 24 Dec 2023 12:41:41 +0100 Subject: [PATCH 01/18] Add ecal2val.py --- ecal2val/ecal2val.py | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 ecal2val/ecal2val.py diff --git a/ecal2val/ecal2val.py b/ecal2val/ecal2val.py new file mode 100644 index 00000000..fc789465 --- /dev/null +++ b/ecal2val/ecal2val.py @@ -0,0 +1,63 @@ +#! /usr/bin/env python3 + +######################################################################## +# Copyright (c) 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License 2.0 which is available at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +######################################################################## + +''' +Subscriber subscribing topics through ECAL communication and sending to KUKSA.val +''' + +import sys +import time + +import ecal.core.core as ecal_core +from ecal.core.subscriber import ProtoSubscriber + +import proto_struct.vss_data_pb2 as vss_data_pb2 + +from kuksa_client.grpc import VSSClient +from kuksa_client.grpc import Datapoint + + +ecal_core.initialize(sys.argv, "Python Protobuf") + +sub = ProtoSubscriber("vss_data_python_protobuf_topic", vss_data_pb2.VssData) + + +'''This callback function subscribes topics + and writes the date in the protobuf + to the data broker through the client.''' + + +def callback(topic_name, vss_data_proto_msg, time): + with VSSClient('127.0.0.1', 55555) as client: + if vss_data_proto_msg.data_int != 0: + client.set_current_values({ + vss_data_proto_msg.description: Datapoint(vss_data_proto_msg.data_int), + }) + elif vss_data_proto_msg.data_float != 0: + client.set_current_values({ + vss_data_proto_msg.description: Datapoint(vss_data_proto_msg.data_float), + }) + else: + client.set_current_values({ + vss_data_proto_msg.description: Datapoint(0), + }) + + +sub.set_callback(callback) + +while ecal_core.ok(): + time.sleep(1) + +ecal_core.finalize() From c144f969c2348b76657caca41c923f647af5f6c2 Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Sun, 24 Dec 2023 12:42:52 +0100 Subject: [PATCH 02/18] Add mock data publisher --- ecal2val/mock_publisher.py | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 ecal2val/mock_publisher.py diff --git a/ecal2val/mock_publisher.py b/ecal2val/mock_publisher.py new file mode 100644 index 00000000..a41ec111 --- /dev/null +++ b/ecal2val/mock_publisher.py @@ -0,0 +1,55 @@ +#! /usr/bin/env python3 + +######################################################################## +# Copyright (c) 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License 2.0 which is available at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +######################################################################## + +''' +Publisher publishing topics via protobuf message through eCAL communication. +''' + +import sys +import time + +import ecal.core.core as ecal_core +from ecal.core.publisher import ProtoPublisher + +import proto_struct.vss_data_pb2 as vss_data_pb2 + + +ecal_core.initialize(sys.argv, "Python Protobuf") + +pub = ProtoPublisher("vss_data_python_protobuf_topic", vss_data_pb2.VssData) + +'''Reads arbitrary data from 'mock_data.txt' + and publishes it in the form of a protobuf message.''' +while ecal_core.ok(): + with open("mock_data.txt", 'r', encoding='utf-8') as file: + for line in file: + description, data = line.rstrip().split() + + protobuf_message = vss_data_pb2.VssData() + protobuf_message.description = description + protobuf_message.data_int = 0 + protobuf_message.data_float = 0 + + try: + protobuf_message.data_int = int(data) + except ValueError: + protobuf_message.data_float = float(data) + + pub.send(protobuf_message) + print("{} published".format(description)) + + time.sleep(1) + +ecal_core.finalize() From ded317b5630ff5f9c645706b250a8be4a3631e94 Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Sun, 24 Dec 2023 12:43:17 +0100 Subject: [PATCH 03/18] Add mock data --- ecal2val/mock_data.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ecal2val/mock_data.txt diff --git a/ecal2val/mock_data.txt b/ecal2val/mock_data.txt new file mode 100644 index 00000000..dd20ee11 --- /dev/null +++ b/ecal2val/mock_data.txt @@ -0,0 +1,20 @@ +Vehicle.Speed 1.0 +Vehicle.Chassis.SteeringWheel.Angle -40 +Vehicle.Speed 1.2 +Vehicle.Chassis.SteeringWheel.Angle -30 +Vehicle.Speed 1.4 +Vehicle.Chassis.SteeringWheel.Angle -20 +Vehicle.Speed 1.6 +Vehicle.Chassis.SteeringWheel.Angle -10 +Vehicle.Speed 1.8 +Vehicle.Chassis.SteeringWheel.Angle 0 +Vehicle.Speed 2.0 +Vehicle.Chassis.SteeringWheel.Angle 10 +Vehicle.Speed 2.2 +Vehicle.Chassis.SteeringWheel.Angle 20 +Vehicle.Speed 2.4 +Vehicle.Chassis.SteeringWheel.Angle 30 +Vehicle.Speed 2.6 +Vehicle.Chassis.SteeringWheel.Angle 40 +Vehicle.Speed 2.8 +Vehicle.Chassis.SteeringWheel.Angle 50 From 119a0d528545c94030a4c1607d136d4dc09e4602 Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Sun, 24 Dec 2023 12:43:56 +0100 Subject: [PATCH 04/18] Add proto struct --- ecal2val/proto_struct/vss_data.proto | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 ecal2val/proto_struct/vss_data.proto diff --git a/ecal2val/proto_struct/vss_data.proto b/ecal2val/proto_struct/vss_data.proto new file mode 100644 index 00000000..12c5ed60 --- /dev/null +++ b/ecal2val/proto_struct/vss_data.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package proto_struct; + +message VssData +{ + string description = 1; + int32 data_int = 2; + float data_float = 3; +} From 6c5c0d3872d99ee275b0495484d49f90a669dc88 Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Sun, 24 Dec 2023 12:45:24 +0100 Subject: [PATCH 05/18] Add description of ecal2val --- ecal2val/README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ecal2val/README.md diff --git a/ecal2val/README.md b/ecal2val/README.md new file mode 100644 index 00000000..27b229c8 --- /dev/null +++ b/ecal2val/README.md @@ -0,0 +1,42 @@ +# eCAL Feeder +The purpose of this implementation is to input data received via `eCAL` into a `KUKSA.val` databroker. The topics transmitted by eCAL are in the form of protobuf, and based on the VSS description and data outlined in this format, it is possible to provide data to the data broker via the kuksa_client. + +## Usage +1. Install Python requirements for both eCAL and KUKSA.val + +``` +sudo add-apt-repository ppa:ecal/ecal-5.12 +sudo apt-get update +sudo apt-get install ecal +sudo apt install python3-ecal5 + +pip install kuksa-client +``` + +2. Generate vss_data_pb2.py in proto_struct directory with following method + +``` +sudo apt-get install protobuf-compiler + +protoc --python_out=. vss_data.proto +``` + +3. Use the following command to run the ecal2val.py + +``` +export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + +python3 ecal2val.py +``` + +This assumes a running `KUKSA.val` databroker at `127.0.0.1:55555`. + +4. For testing, run the mock_publisher.py + +``` +export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + +python3 mock_publisher.py +``` + +This was successfully tested on Ubuntu 20.04 and eCAL 5.12 From 23730840a8c714aecca1b2ff34d98e9f33606e7b Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Tue, 9 Jan 2024 16:53:41 +0100 Subject: [PATCH 06/18] Add license to proto file --- ecal2val/proto_struct/vss_data.proto | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ecal2val/proto_struct/vss_data.proto b/ecal2val/proto_struct/vss_data.proto index 12c5ed60..febb50cf 100644 --- a/ecal2val/proto_struct/vss_data.proto +++ b/ecal2val/proto_struct/vss_data.proto @@ -1,3 +1,17 @@ +######################################################################## +# Copyright (c) 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License 2.0 which is available at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +######################################################################## + + syntax = "proto3"; package proto_struct; From 55220250475c109f183488fa7c06561b0f42fb6f Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Tue, 9 Jan 2024 18:16:12 +0100 Subject: [PATCH 07/18] Edit license in proto file --- ecal2val/proto_struct/vss_data.proto | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ecal2val/proto_struct/vss_data.proto b/ecal2val/proto_struct/vss_data.proto index febb50cf..b75d89f0 100644 --- a/ecal2val/proto_struct/vss_data.proto +++ b/ecal2val/proto_struct/vss_data.proto @@ -1,16 +1,15 @@ -######################################################################## -# Copyright (c) 2023 Contributors to the Eclipse Foundation -# -# See the NOTICE file(s) distributed with this work for additional -# information regarding copyright ownership. -# -# This program and the accompanying materials are made available under the -# terms of the Apache License 2.0 which is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# -# SPDX-License-Identifier: Apache-2.0 -######################################################################## - +/******************************************************************************** + * Copyright (c) 2022 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License 2.0 which is available at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ syntax = "proto3"; From ee81683757d3057c35e49d9c5aeebdeed6fc5567 Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Tue, 9 Jan 2024 18:34:18 +0100 Subject: [PATCH 08/18] Remove proto_struct directory --- ecal2val/proto_struct/vss_data.proto | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 ecal2val/proto_struct/vss_data.proto diff --git a/ecal2val/proto_struct/vss_data.proto b/ecal2val/proto_struct/vss_data.proto deleted file mode 100644 index b75d89f0..00000000 --- a/ecal2val/proto_struct/vss_data.proto +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License 2.0 which is available at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -syntax = "proto3"; - -package proto_struct; - -message VssData -{ - string description = 1; - int32 data_int = 2; - float data_float = 3; -} From ded6021d4124c31aa12d88cdb4daeed47360034f Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Tue, 9 Jan 2024 18:38:47 +0100 Subject: [PATCH 09/18] Replace proto file from kuksa.val.v1 protobuf API --- ecal2val/proto/types.proto | 288 +++++++++++++++++++++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 ecal2val/proto/types.proto diff --git a/ecal2val/proto/types.proto b/ecal2val/proto/types.proto new file mode 100644 index 00000000..d3014bc2 --- /dev/null +++ b/ecal2val/proto/types.proto @@ -0,0 +1,288 @@ +/******************************************************************************** + * Copyright (c) 2022 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License 2.0 which is available at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +syntax = "proto3"; + +// I added V1 as in databroker. Is this good practice? +package kuksa.val.v1; +import "google/protobuf/timestamp.proto"; + +option go_package = "kuksa/val/v1"; + +// Describes a VSS entry +// When requesting an entry, the amount of information returned can +// be controlled by specifying either a `View` or a set of `Field`s. +message DataEntry { + // Defines the full VSS path of the entry. + string path = 1; // [field: FIELD_PATH] + + // The value (datapoint) + Datapoint value = 2; // [field: FIELD_VALUE] + + // Actuator target (only used if the entry is an actuator) + Datapoint actuator_target = 3; // [field: FIELD_ACTUATOR_TARGET] + + // Metadata for this entry + Metadata metadata = 10; // [field: FIELD_METADATA] +} + +message Datapoint { + google.protobuf.Timestamp timestamp = 1; + + oneof value { + string string = 11; + bool bool = 12; + sint32 int32 = 13; + sint64 int64 = 14; + uint32 uint32 = 15; + uint64 uint64 = 16; + float float = 17; + double double = 18; + StringArray string_array = 21; + BoolArray bool_array = 22; + Int32Array int32_array = 23; + Int64Array int64_array = 24; + Uint32Array uint32_array = 25; + Uint64Array uint64_array = 26; + FloatArray float_array = 27; + DoubleArray double_array = 28; + } +} + +message Metadata { + // Data type + // The VSS data type of the entry (i.e. the value, min, max etc). + // + // NOTE: protobuf doesn't have int8, int16, uint8 or uint16 which means + // that these values must be serialized as int32 and uint32 respectively. + DataType data_type = 11; // [field: FIELD_METADATA_DATA_TYPE] + + // Entry type + EntryType entry_type = 12; // [field: FIELD_METADATA_ENTRY_TYPE] + + // Description + // Describes the meaning and content of the entry. + string description = 13; // [field: FIELD_METADATA_DESCRIPTION] + + // Comment [optional] + // A comment can be used to provide additional informal information + // on a entry. + string comment = 14; // [field: FIELD_METADATA_COMMENT] + + // Deprecation [optional] + // Whether this entry is deprecated. Can contain recommendations of what + // to use instead. + string deprecation = 15; // [field: FIELD_METADATA_DEPRECATION] + + // Unit [optional] + // The unit of measurement + string unit = 16; // [field: FIELD_METADATA_UNIT] + + // Value restrictions [optional] + // Restrict which values are allowed. + // Only restrictions matching the DataType {datatype} above are valid. + ValueRestriction value_restriction = 17; // [field: FIELD_METADATA_VALUE_RESTRICTION] + + // Entry type specific metadata + oneof entry_specific { + Actuator actuator = 20; // [field: FIELD_METADATA_ACTUATOR] + Sensor sensor = 30; // [field: FIELD_METADATA_SENSOR] + Attribute attribute = 40; // [field: FIELD_METADATA_ATTRIBUTE] + } +} + +/////////////////////// +// Actuator specific fields +message Actuator { + // Nothing for now +} + +//////////////////////// +// Sensor specific +message Sensor { + // Nothing for now +} + +//////////////////////// +// Attribute specific +message Attribute { + // Nothing for now. +} + +// Value restriction +// +// One ValueRestriction{type} for each type, since +// they don't make sense unless the types match +// +message ValueRestriction { + oneof type { + ValueRestrictionString string = 21; + // For signed VSS integers + ValueRestrictionInt signed = 22; + // For unsigned VSS integers + ValueRestrictionUint unsigned = 23; + // For floating point VSS values (float and double) + ValueRestrictionFloat floating_point = 24; + } +} + +message ValueRestrictionInt { + sint64 min = 1; + sint64 max = 2; + repeated sint64 allowed_values = 3; +} + +message ValueRestrictionUint { + uint64 min = 1; + uint64 max = 2; + repeated uint64 allowed_values = 3; +} + +message ValueRestrictionFloat { + double min = 1; + double max = 2; + + // allowed for doubles/floats not recommended + repeated double allowed_values = 3; +} + +// min, max doesn't make much sense for a string +message ValueRestrictionString { + repeated string allowed_values = 3; +} + +// VSS Data type of a signal +// +// Protobuf doesn't support int8, int16, uint8 or uint16. +// These are mapped to int32 and uint32 respectively. +// +enum DataType { + DATA_TYPE_UNSPECIFIED = 0; + DATA_TYPE_STRING = 1; + DATA_TYPE_BOOLEAN = 2; + DATA_TYPE_INT8 = 3; + DATA_TYPE_INT16 = 4; + DATA_TYPE_INT32 = 5; + DATA_TYPE_INT64 = 6; + DATA_TYPE_UINT8 = 7; + DATA_TYPE_UINT16 = 8; + DATA_TYPE_UINT32 = 9; + DATA_TYPE_UINT64 = 10; + DATA_TYPE_FLOAT = 11; + DATA_TYPE_DOUBLE = 12; + DATA_TYPE_TIMESTAMP = 13; + DATA_TYPE_STRING_ARRAY = 20; + DATA_TYPE_BOOLEAN_ARRAY = 21; + DATA_TYPE_INT8_ARRAY = 22; + DATA_TYPE_INT16_ARRAY = 23; + DATA_TYPE_INT32_ARRAY = 24; + DATA_TYPE_INT64_ARRAY = 25; + DATA_TYPE_UINT8_ARRAY = 26; + DATA_TYPE_UINT16_ARRAY = 27; + DATA_TYPE_UINT32_ARRAY = 28; + DATA_TYPE_UINT64_ARRAY = 29; + DATA_TYPE_FLOAT_ARRAY = 30; + DATA_TYPE_DOUBLE_ARRAY = 31; + DATA_TYPE_TIMESTAMP_ARRAY = 32; +} + +// Entry type +enum EntryType { + ENTRY_TYPE_UNSPECIFIED = 0; + ENTRY_TYPE_ATTRIBUTE = 1; + ENTRY_TYPE_SENSOR = 2; + ENTRY_TYPE_ACTUATOR = 3; +} + +// A `View` specifies a set of fields which should +// be populated in a `DataEntry` (in a response message) +enum View { + VIEW_UNSPECIFIED = 0; // Unspecified. Equivalent to VIEW_CURRENT_VALUE unless `fields` are explicitly set. + VIEW_CURRENT_VALUE = 1; // Populate DataEntry with value. + VIEW_TARGET_VALUE = 2; // Populate DataEntry with actuator target. + VIEW_METADATA = 3; // Populate DataEntry with metadata. + VIEW_FIELDS = 10; // Populate DataEntry only with requested fields. + VIEW_ALL = 20; // Populate DataEntry with everything. +} + +// A `Field` corresponds to a specific field of a `DataEntry`. +// +// It can be used to: +// * populate only specific fields of a `DataEntry` response. +// * specify which fields of a `DataEntry` should be set as +// part of a `Set` request. +// * subscribe to only specific fields of a data entry. +// * convey which fields of an updated `DataEntry` have changed. +enum Field { + FIELD_UNSPECIFIED = 0; // "*" i.e. everything + FIELD_PATH = 1; // path + FIELD_VALUE = 2; // value + FIELD_ACTUATOR_TARGET = 3; // actuator_target + FIELD_METADATA = 10; // metadata.* + FIELD_METADATA_DATA_TYPE = 11; // metadata.data_type + FIELD_METADATA_DESCRIPTION = 12; // metadata.description + FIELD_METADATA_ENTRY_TYPE = 13; // metadata.entry_type + FIELD_METADATA_COMMENT = 14; // metadata.comment + FIELD_METADATA_DEPRECATION = 15; // metadata.deprecation + FIELD_METADATA_UNIT = 16; // metadata.unit + FIELD_METADATA_VALUE_RESTRICTION = 17; // metadata.value_restriction.* + FIELD_METADATA_ACTUATOR = 20; // metadata.actuator.* + FIELD_METADATA_SENSOR = 30; // metadata.sensor.* + FIELD_METADATA_ATTRIBUTE = 40; // metadata.attribute.* +} + +// Error response shall be an HTTP-like code. +// Should follow https://www.w3.org/TR/viss2-transport/#status-codes. +message Error { + uint32 code = 1; + string reason = 2; + string message = 3; +} + +// Used in get/set requests to report errors for specific entries +message DataEntryError { + string path = 1; // vss path + Error error = 2; +} + +message StringArray { + repeated string values = 1; +} + +message BoolArray { + repeated bool values = 1; +} + +message Int32Array { + repeated sint32 values = 1; +} + +message Int64Array { + repeated sint64 values = 1; +} + +message Uint32Array { + repeated uint32 values = 1; +} + +message Uint64Array { + repeated uint64 values = 1; +} + +message FloatArray { + repeated float values = 1; +} + +message DoubleArray { + repeated double values = 1; +} \ No newline at end of file From 08580c5578ee1c4f711b1df29dbdd7bc1ed46a7b Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Wed, 10 Jan 2024 16:55:06 +0100 Subject: [PATCH 10/18] Replace mock data file with data type --- ecal2val/mock_data.txt | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ecal2val/mock_data.txt b/ecal2val/mock_data.txt index dd20ee11..52bf4c2f 100644 --- a/ecal2val/mock_data.txt +++ b/ecal2val/mock_data.txt @@ -1,20 +1,20 @@ -Vehicle.Speed 1.0 -Vehicle.Chassis.SteeringWheel.Angle -40 -Vehicle.Speed 1.2 -Vehicle.Chassis.SteeringWheel.Angle -30 -Vehicle.Speed 1.4 -Vehicle.Chassis.SteeringWheel.Angle -20 -Vehicle.Speed 1.6 -Vehicle.Chassis.SteeringWheel.Angle -10 -Vehicle.Speed 1.8 -Vehicle.Chassis.SteeringWheel.Angle 0 -Vehicle.Speed 2.0 -Vehicle.Chassis.SteeringWheel.Angle 10 -Vehicle.Speed 2.2 -Vehicle.Chassis.SteeringWheel.Angle 20 -Vehicle.Speed 2.4 -Vehicle.Chassis.SteeringWheel.Angle 30 -Vehicle.Speed 2.6 -Vehicle.Chassis.SteeringWheel.Angle 40 -Vehicle.Speed 2.8 -Vehicle.Chassis.SteeringWheel.Angle 50 +Vehicle.Speed 1.0 float +Vehicle.Chassis.SteeringWheel.Angle -40 int32 +Vehicle.Speed 1.2 float +Vehicle.Chassis.SteeringWheel.Angle -30 int32 +Vehicle.Speed 1.4 float +Vehicle.Chassis.SteeringWheel.Angle -20 int32 +Vehicle.Speed 1.6 float +Vehicle.Chassis.SteeringWheel.Angle -10 int32 +Vehicle.Speed 1.8 float +Vehicle.Chassis.SteeringWheel.Angle 0 int32 +Vehicle.Speed 2.0 float +Vehicle.Chassis.SteeringWheel.Angle 10 int32 +Vehicle.Speed 2.2 float +Vehicle.Chassis.SteeringWheel.Angle 20 int32 +Vehicle.Speed 2.4 float +Vehicle.Chassis.SteeringWheel.Angle 30 int32 +Vehicle.Speed 2.6 float +Vehicle.Chassis.SteeringWheel.Angle 40 int32 +Vehicle.Speed 2.8 float +Vehicle.Chassis.SteeringWheel.Angle 50 int32 \ No newline at end of file From 9048d21ea2771f15afdfe1e8a03f4b054e63c8a2 Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Wed, 10 Jan 2024 16:57:39 +0100 Subject: [PATCH 11/18] Update publisher to use data entry --- ecal2val/mock_publisher.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/ecal2val/mock_publisher.py b/ecal2val/mock_publisher.py index a41ec111..3466a89b 100644 --- a/ecal2val/mock_publisher.py +++ b/ecal2val/mock_publisher.py @@ -14,7 +14,7 @@ ######################################################################## ''' -Publisher publishing topics via protobuf message through eCAL communication. +Publisher publishing vss topics via eCAL communication. ''' import sys @@ -23,32 +23,32 @@ import ecal.core.core as ecal_core from ecal.core.publisher import ProtoPublisher -import proto_struct.vss_data_pb2 as vss_data_pb2 +import proto.proto_struct_pb2 as proto_struct_pb2 +from cast_func import * -ecal_core.initialize(sys.argv, "Python Protobuf") -pub = ProtoPublisher("vss_data_python_protobuf_topic", vss_data_pb2.VssData) +ecal_core.initialize(sys.argv, "ecal2val") + +pub = ProtoPublisher("vss_topic", proto_struct_pb2.DataEntry) + +''' +Reads arbitrary data from 'mock_data.txt' +and publishes it in the form of a protobuf message. +''' -'''Reads arbitrary data from 'mock_data.txt' - and publishes it in the form of a protobuf message.''' while ecal_core.ok(): with open("mock_data.txt", 'r', encoding='utf-8') as file: for line in file: - description, data = line.rstrip().split() - - protobuf_message = vss_data_pb2.VssData() - protobuf_message.description = description - protobuf_message.data_int = 0 - protobuf_message.data_float = 0 + path, value, data_type = line.split() - try: - protobuf_message.data_int = int(data) - except ValueError: - protobuf_message.data_float = float(data) + entry = proto_struct_pb2.DataEntry() + entry.path = path + exec(f"entry.value.{data_type} = {data_type}(value)") + entry.data_type = data_type - pub.send(protobuf_message) - print("{} published".format(description)) + pub.send(entry) + print(f"{path} published") time.sleep(1) From aba00f953ddad7ab5d141387a588175af47c1b1e Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Wed, 10 Jan 2024 17:00:06 +0100 Subject: [PATCH 12/18] Replace customized proto file --- ecal2val/proto/proto_struct.proto | 35 ++++ ecal2val/proto/types.proto | 288 ------------------------------ 2 files changed, 35 insertions(+), 288 deletions(-) create mode 100644 ecal2val/proto/proto_struct.proto delete mode 100644 ecal2val/proto/types.proto diff --git a/ecal2val/proto/proto_struct.proto b/ecal2val/proto/proto_struct.proto new file mode 100644 index 00000000..151e305b --- /dev/null +++ b/ecal2val/proto/proto_struct.proto @@ -0,0 +1,35 @@ +/******************************************************************************** + * Copyright (c) 2022 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License 2.0 which is available at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +syntax = "proto3"; + +package proto_struct; + +message DataEntry { + string path = 1; + DataPoint value = 2; + string data_type = 3; +} + +message DataPoint { + oneof value { + string string = 1; + bool bool = 2; + sint32 int32 = 3; + sint64 int64 = 4; + uint32 uint32 = 5; + uint64 uint64 = 6; + float float = 7; + double double = 8; + } +} diff --git a/ecal2val/proto/types.proto b/ecal2val/proto/types.proto deleted file mode 100644 index d3014bc2..00000000 --- a/ecal2val/proto/types.proto +++ /dev/null @@ -1,288 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License 2.0 which is available at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -syntax = "proto3"; - -// I added V1 as in databroker. Is this good practice? -package kuksa.val.v1; -import "google/protobuf/timestamp.proto"; - -option go_package = "kuksa/val/v1"; - -// Describes a VSS entry -// When requesting an entry, the amount of information returned can -// be controlled by specifying either a `View` or a set of `Field`s. -message DataEntry { - // Defines the full VSS path of the entry. - string path = 1; // [field: FIELD_PATH] - - // The value (datapoint) - Datapoint value = 2; // [field: FIELD_VALUE] - - // Actuator target (only used if the entry is an actuator) - Datapoint actuator_target = 3; // [field: FIELD_ACTUATOR_TARGET] - - // Metadata for this entry - Metadata metadata = 10; // [field: FIELD_METADATA] -} - -message Datapoint { - google.protobuf.Timestamp timestamp = 1; - - oneof value { - string string = 11; - bool bool = 12; - sint32 int32 = 13; - sint64 int64 = 14; - uint32 uint32 = 15; - uint64 uint64 = 16; - float float = 17; - double double = 18; - StringArray string_array = 21; - BoolArray bool_array = 22; - Int32Array int32_array = 23; - Int64Array int64_array = 24; - Uint32Array uint32_array = 25; - Uint64Array uint64_array = 26; - FloatArray float_array = 27; - DoubleArray double_array = 28; - } -} - -message Metadata { - // Data type - // The VSS data type of the entry (i.e. the value, min, max etc). - // - // NOTE: protobuf doesn't have int8, int16, uint8 or uint16 which means - // that these values must be serialized as int32 and uint32 respectively. - DataType data_type = 11; // [field: FIELD_METADATA_DATA_TYPE] - - // Entry type - EntryType entry_type = 12; // [field: FIELD_METADATA_ENTRY_TYPE] - - // Description - // Describes the meaning and content of the entry. - string description = 13; // [field: FIELD_METADATA_DESCRIPTION] - - // Comment [optional] - // A comment can be used to provide additional informal information - // on a entry. - string comment = 14; // [field: FIELD_METADATA_COMMENT] - - // Deprecation [optional] - // Whether this entry is deprecated. Can contain recommendations of what - // to use instead. - string deprecation = 15; // [field: FIELD_METADATA_DEPRECATION] - - // Unit [optional] - // The unit of measurement - string unit = 16; // [field: FIELD_METADATA_UNIT] - - // Value restrictions [optional] - // Restrict which values are allowed. - // Only restrictions matching the DataType {datatype} above are valid. - ValueRestriction value_restriction = 17; // [field: FIELD_METADATA_VALUE_RESTRICTION] - - // Entry type specific metadata - oneof entry_specific { - Actuator actuator = 20; // [field: FIELD_METADATA_ACTUATOR] - Sensor sensor = 30; // [field: FIELD_METADATA_SENSOR] - Attribute attribute = 40; // [field: FIELD_METADATA_ATTRIBUTE] - } -} - -/////////////////////// -// Actuator specific fields -message Actuator { - // Nothing for now -} - -//////////////////////// -// Sensor specific -message Sensor { - // Nothing for now -} - -//////////////////////// -// Attribute specific -message Attribute { - // Nothing for now. -} - -// Value restriction -// -// One ValueRestriction{type} for each type, since -// they don't make sense unless the types match -// -message ValueRestriction { - oneof type { - ValueRestrictionString string = 21; - // For signed VSS integers - ValueRestrictionInt signed = 22; - // For unsigned VSS integers - ValueRestrictionUint unsigned = 23; - // For floating point VSS values (float and double) - ValueRestrictionFloat floating_point = 24; - } -} - -message ValueRestrictionInt { - sint64 min = 1; - sint64 max = 2; - repeated sint64 allowed_values = 3; -} - -message ValueRestrictionUint { - uint64 min = 1; - uint64 max = 2; - repeated uint64 allowed_values = 3; -} - -message ValueRestrictionFloat { - double min = 1; - double max = 2; - - // allowed for doubles/floats not recommended - repeated double allowed_values = 3; -} - -// min, max doesn't make much sense for a string -message ValueRestrictionString { - repeated string allowed_values = 3; -} - -// VSS Data type of a signal -// -// Protobuf doesn't support int8, int16, uint8 or uint16. -// These are mapped to int32 and uint32 respectively. -// -enum DataType { - DATA_TYPE_UNSPECIFIED = 0; - DATA_TYPE_STRING = 1; - DATA_TYPE_BOOLEAN = 2; - DATA_TYPE_INT8 = 3; - DATA_TYPE_INT16 = 4; - DATA_TYPE_INT32 = 5; - DATA_TYPE_INT64 = 6; - DATA_TYPE_UINT8 = 7; - DATA_TYPE_UINT16 = 8; - DATA_TYPE_UINT32 = 9; - DATA_TYPE_UINT64 = 10; - DATA_TYPE_FLOAT = 11; - DATA_TYPE_DOUBLE = 12; - DATA_TYPE_TIMESTAMP = 13; - DATA_TYPE_STRING_ARRAY = 20; - DATA_TYPE_BOOLEAN_ARRAY = 21; - DATA_TYPE_INT8_ARRAY = 22; - DATA_TYPE_INT16_ARRAY = 23; - DATA_TYPE_INT32_ARRAY = 24; - DATA_TYPE_INT64_ARRAY = 25; - DATA_TYPE_UINT8_ARRAY = 26; - DATA_TYPE_UINT16_ARRAY = 27; - DATA_TYPE_UINT32_ARRAY = 28; - DATA_TYPE_UINT64_ARRAY = 29; - DATA_TYPE_FLOAT_ARRAY = 30; - DATA_TYPE_DOUBLE_ARRAY = 31; - DATA_TYPE_TIMESTAMP_ARRAY = 32; -} - -// Entry type -enum EntryType { - ENTRY_TYPE_UNSPECIFIED = 0; - ENTRY_TYPE_ATTRIBUTE = 1; - ENTRY_TYPE_SENSOR = 2; - ENTRY_TYPE_ACTUATOR = 3; -} - -// A `View` specifies a set of fields which should -// be populated in a `DataEntry` (in a response message) -enum View { - VIEW_UNSPECIFIED = 0; // Unspecified. Equivalent to VIEW_CURRENT_VALUE unless `fields` are explicitly set. - VIEW_CURRENT_VALUE = 1; // Populate DataEntry with value. - VIEW_TARGET_VALUE = 2; // Populate DataEntry with actuator target. - VIEW_METADATA = 3; // Populate DataEntry with metadata. - VIEW_FIELDS = 10; // Populate DataEntry only with requested fields. - VIEW_ALL = 20; // Populate DataEntry with everything. -} - -// A `Field` corresponds to a specific field of a `DataEntry`. -// -// It can be used to: -// * populate only specific fields of a `DataEntry` response. -// * specify which fields of a `DataEntry` should be set as -// part of a `Set` request. -// * subscribe to only specific fields of a data entry. -// * convey which fields of an updated `DataEntry` have changed. -enum Field { - FIELD_UNSPECIFIED = 0; // "*" i.e. everything - FIELD_PATH = 1; // path - FIELD_VALUE = 2; // value - FIELD_ACTUATOR_TARGET = 3; // actuator_target - FIELD_METADATA = 10; // metadata.* - FIELD_METADATA_DATA_TYPE = 11; // metadata.data_type - FIELD_METADATA_DESCRIPTION = 12; // metadata.description - FIELD_METADATA_ENTRY_TYPE = 13; // metadata.entry_type - FIELD_METADATA_COMMENT = 14; // metadata.comment - FIELD_METADATA_DEPRECATION = 15; // metadata.deprecation - FIELD_METADATA_UNIT = 16; // metadata.unit - FIELD_METADATA_VALUE_RESTRICTION = 17; // metadata.value_restriction.* - FIELD_METADATA_ACTUATOR = 20; // metadata.actuator.* - FIELD_METADATA_SENSOR = 30; // metadata.sensor.* - FIELD_METADATA_ATTRIBUTE = 40; // metadata.attribute.* -} - -// Error response shall be an HTTP-like code. -// Should follow https://www.w3.org/TR/viss2-transport/#status-codes. -message Error { - uint32 code = 1; - string reason = 2; - string message = 3; -} - -// Used in get/set requests to report errors for specific entries -message DataEntryError { - string path = 1; // vss path - Error error = 2; -} - -message StringArray { - repeated string values = 1; -} - -message BoolArray { - repeated bool values = 1; -} - -message Int32Array { - repeated sint32 values = 1; -} - -message Int64Array { - repeated sint64 values = 1; -} - -message Uint32Array { - repeated uint32 values = 1; -} - -message Uint64Array { - repeated uint64 values = 1; -} - -message FloatArray { - repeated float values = 1; -} - -message DoubleArray { - repeated double values = 1; -} \ No newline at end of file From 5a5839b0e528b0789200a6866fea0ddf69810551 Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Wed, 10 Jan 2024 17:03:24 +0100 Subject: [PATCH 13/18] Update feeder to use data entry --- ecal2val/ecal2val.py | 45 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/ecal2val/ecal2val.py b/ecal2val/ecal2val.py index fc789465..dc9a7db9 100644 --- a/ecal2val/ecal2val.py +++ b/ecal2val/ecal2val.py @@ -14,7 +14,8 @@ ######################################################################## ''' -Subscriber subscribing topics through ECAL communication and sending to KUKSA.val +Subscriber subscribing vss topics via ECAL communication +and sending it to KUKSA.val databroker. ''' import sys @@ -23,36 +24,36 @@ import ecal.core.core as ecal_core from ecal.core.subscriber import ProtoSubscriber -import proto_struct.vss_data_pb2 as vss_data_pb2 +import proto.proto_struct_pb2 as proto_struct_pb2 -from kuksa_client.grpc import VSSClient from kuksa_client.grpc import Datapoint +from kuksa_client.grpc import DataEntry +from kuksa_client.grpc import EntryUpdate +from kuksa_client.grpc import Field +from kuksa_client.grpc import VSSClient -ecal_core.initialize(sys.argv, "Python Protobuf") - -sub = ProtoSubscriber("vss_data_python_protobuf_topic", vss_data_pb2.VssData) +ecal_core.initialize(sys.argv, "ecal2val") +sub = ProtoSubscriber("vss_topic", proto_struct_pb2.DataEntry) -'''This callback function subscribes topics - and writes the date in the protobuf - to the data broker through the client.''' +''' +This callback function subscribes topics +and writes the data to the databroker. +''' -def callback(topic_name, vss_data_proto_msg, time): +def callback(topic_name, msg, time): with VSSClient('127.0.0.1', 55555) as client: - if vss_data_proto_msg.data_int != 0: - client.set_current_values({ - vss_data_proto_msg.description: Datapoint(vss_data_proto_msg.data_int), - }) - elif vss_data_proto_msg.data_float != 0: - client.set_current_values({ - vss_data_proto_msg.description: Datapoint(vss_data_proto_msg.data_float), - }) - else: - client.set_current_values({ - vss_data_proto_msg.description: Datapoint(0), - }) + entry = DataEntry( + path = msg.path, + value = Datapoint(value = eval(f"msg.value.{msg.data_type}")), + ) + updates = (EntryUpdate(entry, (Field.VALUE,)),) + + client.set(updates=updates) + + print(f'{msg.path} subscribed & written') sub.set_callback(callback) From 181ed0ed5a326f1275cbf0a2b477afc5044b837a Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Wed, 10 Jan 2024 17:04:22 +0100 Subject: [PATCH 14/18] Add type casting function definition --- ecal2val/cast_func.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ecal2val/cast_func.py diff --git a/ecal2val/cast_func.py b/ecal2val/cast_func.py new file mode 100644 index 00000000..cad74cc7 --- /dev/null +++ b/ecal2val/cast_func.py @@ -0,0 +1,22 @@ +def string(value): + return str(value) + + +def int32(value): + return int(value) + + +def int64(value): + return int(value) + + +def uint32(value): + return int(value) + + +def uint64(value): + return int(value) + + +def double(value): + return float(value) From 3f29b5c7d3338453434599caaeda6e16cd49b68d Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Wed, 10 Jan 2024 17:18:46 +0100 Subject: [PATCH 15/18] Update README --- ecal2val/README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ecal2val/README.md b/ecal2val/README.md index 27b229c8..0ff7f329 100644 --- a/ecal2val/README.md +++ b/ecal2val/README.md @@ -1,5 +1,5 @@ # eCAL Feeder -The purpose of this implementation is to input data received via `eCAL` into a `KUKSA.val` databroker. The topics transmitted by eCAL are in the form of protobuf, and based on the VSS description and data outlined in this format, it is possible to provide data to the data broker via the kuksa_client. +The purpose of this implementation is to input data received via `eCAL` into a `KUKSA.val` databroker. The topics transmitted by eCAL are in the form of protobuf, and based on the VSS description and data outlined in this format, it is possible to provide data to the databroker via kuksa_client. ## Usage 1. Install Python requirements for both eCAL and KUKSA.val @@ -11,14 +11,16 @@ sudo apt-get install ecal sudo apt install python3-ecal5 pip install kuksa-client + ``` -2. Generate vss_data_pb2.py in proto_struct directory with following method +2. Generate proto_struct_pb2.py in proto directory with following method ``` sudo apt-get install protobuf-compiler -protoc --python_out=. vss_data.proto +protoc --python_out=. proto_struct.proto + ``` 3. Use the following command to run the ecal2val.py @@ -27,6 +29,7 @@ protoc --python_out=. vss_data.proto export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python python3 ecal2val.py + ``` This assumes a running `KUKSA.val` databroker at `127.0.0.1:55555`. @@ -37,6 +40,9 @@ This assumes a running `KUKSA.val` databroker at `127.0.0.1:55555`. export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python python3 mock_publisher.py + ``` -This was successfully tested on Ubuntu 20.04 and eCAL 5.12 +Modify proto file to utilize more specific information. + +This was successfully tested on Ubuntu 20.04 and eCAL 5.12. From 6b2e6879f96df4e7ffef81e52ce5c01cfb82bfff Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Wed, 10 Jan 2024 17:57:26 +0100 Subject: [PATCH 16/18] Update license --- ecal2val/cast_func.py | 14 ++++++++++++++ ecal2val/ecal2val.py | 2 +- ecal2val/mock_publisher.py | 2 +- ecal2val/proto/proto_struct.proto | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ecal2val/cast_func.py b/ecal2val/cast_func.py index cad74cc7..b6434cba 100644 --- a/ecal2val/cast_func.py +++ b/ecal2val/cast_func.py @@ -1,3 +1,17 @@ +######################################################################## +# Copyright (c) 2024 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License 2.0 which is available at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +######################################################################## + + def string(value): return str(value) diff --git a/ecal2val/ecal2val.py b/ecal2val/ecal2val.py index dc9a7db9..05289e85 100644 --- a/ecal2val/ecal2val.py +++ b/ecal2val/ecal2val.py @@ -1,7 +1,7 @@ #! /usr/bin/env python3 ######################################################################## -# Copyright (c) 2023 Contributors to the Eclipse Foundation +# Copyright (c) 2024 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. diff --git a/ecal2val/mock_publisher.py b/ecal2val/mock_publisher.py index 3466a89b..8304e7cf 100644 --- a/ecal2val/mock_publisher.py +++ b/ecal2val/mock_publisher.py @@ -1,7 +1,7 @@ #! /usr/bin/env python3 ######################################################################## -# Copyright (c) 2023 Contributors to the Eclipse Foundation +# Copyright (c) 2024 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. diff --git a/ecal2val/proto/proto_struct.proto b/ecal2val/proto/proto_struct.proto index 151e305b..f7b71f01 100644 --- a/ecal2val/proto/proto_struct.proto +++ b/ecal2val/proto/proto_struct.proto @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. From f6ec7e3af7539f72d5b52c047eb97b37b61749c2 Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Fri, 12 Jan 2024 18:16:45 +0100 Subject: [PATCH 17/18] Remove ecal2val for pre-commit --- ecal2val/README.md | 48 ----------------------- ecal2val/cast_func.py | 36 ----------------- ecal2val/ecal2val.py | 64 ------------------------------- ecal2val/mock_data.txt | 20 ---------- ecal2val/mock_publisher.py | 55 -------------------------- ecal2val/proto/proto_struct.proto | 35 ----------------- 6 files changed, 258 deletions(-) delete mode 100644 ecal2val/README.md delete mode 100644 ecal2val/cast_func.py delete mode 100644 ecal2val/ecal2val.py delete mode 100644 ecal2val/mock_data.txt delete mode 100644 ecal2val/mock_publisher.py delete mode 100644 ecal2val/proto/proto_struct.proto diff --git a/ecal2val/README.md b/ecal2val/README.md deleted file mode 100644 index 0ff7f329..00000000 --- a/ecal2val/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# eCAL Feeder -The purpose of this implementation is to input data received via `eCAL` into a `KUKSA.val` databroker. The topics transmitted by eCAL are in the form of protobuf, and based on the VSS description and data outlined in this format, it is possible to provide data to the databroker via kuksa_client. - -## Usage -1. Install Python requirements for both eCAL and KUKSA.val - -``` -sudo add-apt-repository ppa:ecal/ecal-5.12 -sudo apt-get update -sudo apt-get install ecal -sudo apt install python3-ecal5 - -pip install kuksa-client - -``` - -2. Generate proto_struct_pb2.py in proto directory with following method - -``` -sudo apt-get install protobuf-compiler - -protoc --python_out=. proto_struct.proto - -``` - -3. Use the following command to run the ecal2val.py - -``` -export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python - -python3 ecal2val.py - -``` - -This assumes a running `KUKSA.val` databroker at `127.0.0.1:55555`. - -4. For testing, run the mock_publisher.py - -``` -export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python - -python3 mock_publisher.py - -``` - -Modify proto file to utilize more specific information. - -This was successfully tested on Ubuntu 20.04 and eCAL 5.12. diff --git a/ecal2val/cast_func.py b/ecal2val/cast_func.py deleted file mode 100644 index b6434cba..00000000 --- a/ecal2val/cast_func.py +++ /dev/null @@ -1,36 +0,0 @@ -######################################################################## -# Copyright (c) 2024 Contributors to the Eclipse Foundation -# -# See the NOTICE file(s) distributed with this work for additional -# information regarding copyright ownership. -# -# This program and the accompanying materials are made available under the -# terms of the Apache License 2.0 which is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# -# SPDX-License-Identifier: Apache-2.0 -######################################################################## - - -def string(value): - return str(value) - - -def int32(value): - return int(value) - - -def int64(value): - return int(value) - - -def uint32(value): - return int(value) - - -def uint64(value): - return int(value) - - -def double(value): - return float(value) diff --git a/ecal2val/ecal2val.py b/ecal2val/ecal2val.py deleted file mode 100644 index 05289e85..00000000 --- a/ecal2val/ecal2val.py +++ /dev/null @@ -1,64 +0,0 @@ -#! /usr/bin/env python3 - -######################################################################## -# Copyright (c) 2024 Contributors to the Eclipse Foundation -# -# See the NOTICE file(s) distributed with this work for additional -# information regarding copyright ownership. -# -# This program and the accompanying materials are made available under the -# terms of the Apache License 2.0 which is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# -# SPDX-License-Identifier: Apache-2.0 -######################################################################## - -''' -Subscriber subscribing vss topics via ECAL communication -and sending it to KUKSA.val databroker. -''' - -import sys -import time - -import ecal.core.core as ecal_core -from ecal.core.subscriber import ProtoSubscriber - -import proto.proto_struct_pb2 as proto_struct_pb2 - -from kuksa_client.grpc import Datapoint -from kuksa_client.grpc import DataEntry -from kuksa_client.grpc import EntryUpdate -from kuksa_client.grpc import Field -from kuksa_client.grpc import VSSClient - - -ecal_core.initialize(sys.argv, "ecal2val") - -sub = ProtoSubscriber("vss_topic", proto_struct_pb2.DataEntry) - -''' -This callback function subscribes topics -and writes the data to the databroker. -''' - - -def callback(topic_name, msg, time): - with VSSClient('127.0.0.1', 55555) as client: - entry = DataEntry( - path = msg.path, - value = Datapoint(value = eval(f"msg.value.{msg.data_type}")), - ) - updates = (EntryUpdate(entry, (Field.VALUE,)),) - - client.set(updates=updates) - - print(f'{msg.path} subscribed & written') - - -sub.set_callback(callback) - -while ecal_core.ok(): - time.sleep(1) - -ecal_core.finalize() diff --git a/ecal2val/mock_data.txt b/ecal2val/mock_data.txt deleted file mode 100644 index 52bf4c2f..00000000 --- a/ecal2val/mock_data.txt +++ /dev/null @@ -1,20 +0,0 @@ -Vehicle.Speed 1.0 float -Vehicle.Chassis.SteeringWheel.Angle -40 int32 -Vehicle.Speed 1.2 float -Vehicle.Chassis.SteeringWheel.Angle -30 int32 -Vehicle.Speed 1.4 float -Vehicle.Chassis.SteeringWheel.Angle -20 int32 -Vehicle.Speed 1.6 float -Vehicle.Chassis.SteeringWheel.Angle -10 int32 -Vehicle.Speed 1.8 float -Vehicle.Chassis.SteeringWheel.Angle 0 int32 -Vehicle.Speed 2.0 float -Vehicle.Chassis.SteeringWheel.Angle 10 int32 -Vehicle.Speed 2.2 float -Vehicle.Chassis.SteeringWheel.Angle 20 int32 -Vehicle.Speed 2.4 float -Vehicle.Chassis.SteeringWheel.Angle 30 int32 -Vehicle.Speed 2.6 float -Vehicle.Chassis.SteeringWheel.Angle 40 int32 -Vehicle.Speed 2.8 float -Vehicle.Chassis.SteeringWheel.Angle 50 int32 \ No newline at end of file diff --git a/ecal2val/mock_publisher.py b/ecal2val/mock_publisher.py deleted file mode 100644 index 8304e7cf..00000000 --- a/ecal2val/mock_publisher.py +++ /dev/null @@ -1,55 +0,0 @@ -#! /usr/bin/env python3 - -######################################################################## -# Copyright (c) 2024 Contributors to the Eclipse Foundation -# -# See the NOTICE file(s) distributed with this work for additional -# information regarding copyright ownership. -# -# This program and the accompanying materials are made available under the -# terms of the Apache License 2.0 which is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# -# SPDX-License-Identifier: Apache-2.0 -######################################################################## - -''' -Publisher publishing vss topics via eCAL communication. -''' - -import sys -import time - -import ecal.core.core as ecal_core -from ecal.core.publisher import ProtoPublisher - -import proto.proto_struct_pb2 as proto_struct_pb2 - -from cast_func import * - - -ecal_core.initialize(sys.argv, "ecal2val") - -pub = ProtoPublisher("vss_topic", proto_struct_pb2.DataEntry) - -''' -Reads arbitrary data from 'mock_data.txt' -and publishes it in the form of a protobuf message. -''' - -while ecal_core.ok(): - with open("mock_data.txt", 'r', encoding='utf-8') as file: - for line in file: - path, value, data_type = line.split() - - entry = proto_struct_pb2.DataEntry() - entry.path = path - exec(f"entry.value.{data_type} = {data_type}(value)") - entry.data_type = data_type - - pub.send(entry) - print(f"{path} published") - - time.sleep(1) - -ecal_core.finalize() diff --git a/ecal2val/proto/proto_struct.proto b/ecal2val/proto/proto_struct.proto deleted file mode 100644 index f7b71f01..00000000 --- a/ecal2val/proto/proto_struct.proto +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License 2.0 which is available at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -syntax = "proto3"; - -package proto_struct; - -message DataEntry { - string path = 1; - DataPoint value = 2; - string data_type = 3; -} - -message DataPoint { - oneof value { - string string = 1; - bool bool = 2; - sint32 int32 = 3; - sint64 int64 = 4; - uint32 uint32 = 5; - uint64 uint64 = 6; - float float = 7; - double double = 8; - } -} From f390968eff5eb5b02a19440a42d25ec59f33af3f Mon Sep 17 00:00:00 2001 From: lalywr2000 <12190450@inha.edu> Date: Fri, 12 Jan 2024 18:21:40 +0100 Subject: [PATCH 18/18] Upload ecal2val for pre-commit check --- ecal2val/README.md | 48 +++++++++++++++++++ ecal2val/ecal2val.py | 64 +++++++++++++++++++++++++ ecal2val/mock_data.txt | 20 ++++++++ ecal2val/mock_publisher.py | 77 +++++++++++++++++++++++++++++++ ecal2val/proto/proto_struct.proto | 35 ++++++++++++++ 5 files changed, 244 insertions(+) create mode 100644 ecal2val/README.md create mode 100644 ecal2val/ecal2val.py create mode 100644 ecal2val/mock_data.txt create mode 100644 ecal2val/mock_publisher.py create mode 100644 ecal2val/proto/proto_struct.proto diff --git a/ecal2val/README.md b/ecal2val/README.md new file mode 100644 index 00000000..b83777a6 --- /dev/null +++ b/ecal2val/README.md @@ -0,0 +1,48 @@ +# eCAL Feeder +The purpose of this implementation is to input data received via `eCAL` into a `KUKSA.val` databroker. The topics transmitted by eCAL are in the form of protobuf, and based on the VSS description and data outlined in this format, it is possible to provide data to the databroker via kuksa_client. + +## Usage +1. Install Python requirements for both eCAL and KUKSA.val + +``` +sudo add-apt-repository ppa:ecal/ecal-5.12 +sudo apt-get update +sudo apt-get install ecal +sudo apt install python3-ecal5 + +pip install kuksa-client + +``` + +2. Generate proto_struct_pb2.py in proto directory with following method + +``` +sudo apt-get install protobuf-compiler + +protoc --python_out=. proto_struct.proto + +``` + +3. Use the following command to run the ecal2val.py + +``` +export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + +python3 ecal2val.py + +``` + +This assumes a running `KUKSA.val` databroker at `127.0.0.1:55555`. + +4. For testing, run the mock_publisher.py + +``` +export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + +python3 mock_publisher.py + +``` + +Modify proto file to utilize more specific information. + +This was successfully tested on Ubuntu 20.04 and eCAL 5.12. diff --git a/ecal2val/ecal2val.py b/ecal2val/ecal2val.py new file mode 100644 index 00000000..6d2ad128 --- /dev/null +++ b/ecal2val/ecal2val.py @@ -0,0 +1,64 @@ +#! /usr/bin/env python3 + +######################################################################## +# Copyright (c) 2024 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License 2.0 which is available at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +######################################################################## + +''' +Subscriber subscribing vss topics via ECAL communication +and sending it to KUKSA.val databroker. +''' + +import sys +import time + +import ecal.core.core as ecal_core +from ecal.core.subscriber import ProtoSubscriber + +import proto.proto_struct_pb2 as proto_struct_pb2 + +from kuksa_client.grpc import Datapoint +from kuksa_client.grpc import DataEntry +from kuksa_client.grpc import EntryUpdate +from kuksa_client.grpc import Field +from kuksa_client.grpc import VSSClient + + +ecal_core.initialize(sys.argv, "ecal2val") + +sub = ProtoSubscriber("vss_topic", proto_struct_pb2.DataEntry) + +''' +This callback function subscribes topics +and writes the data to the databroker. +''' + + +def callback(topic_name, msg, time): + with VSSClient('127.0.0.1', 55555) as client: + entry = DataEntry( + path=msg.path, + value=Datapoint(value=eval(f"msg.value.{msg.data_type}")), + ) + updates = (EntryUpdate(entry, (Field.VALUE,)),) + + client.set(updates=updates) + + print(f'{msg.path} subscribed & written') + + +sub.set_callback(callback) + +while ecal_core.ok(): + time.sleep(1) + +ecal_core.finalize() diff --git a/ecal2val/mock_data.txt b/ecal2val/mock_data.txt new file mode 100644 index 00000000..9bf00def --- /dev/null +++ b/ecal2val/mock_data.txt @@ -0,0 +1,20 @@ +Vehicle.Speed 1.0 float +Vehicle.Chassis.SteeringWheel.Angle -40 int32 +Vehicle.Speed 1.2 float +Vehicle.Chassis.SteeringWheel.Angle -30 int32 +Vehicle.Speed 1.4 float +Vehicle.Chassis.SteeringWheel.Angle -20 int32 +Vehicle.Speed 1.6 float +Vehicle.Chassis.SteeringWheel.Angle -10 int32 +Vehicle.Speed 1.8 float +Vehicle.Chassis.SteeringWheel.Angle 0 int32 +Vehicle.Speed 2.0 float +Vehicle.Chassis.SteeringWheel.Angle 10 int32 +Vehicle.Speed 2.2 float +Vehicle.Chassis.SteeringWheel.Angle 20 int32 +Vehicle.Speed 2.4 float +Vehicle.Chassis.SteeringWheel.Angle 30 int32 +Vehicle.Speed 2.6 float +Vehicle.Chassis.SteeringWheel.Angle 40 int32 +Vehicle.Speed 2.8 float +Vehicle.Chassis.SteeringWheel.Angle 50 int32 diff --git a/ecal2val/mock_publisher.py b/ecal2val/mock_publisher.py new file mode 100644 index 00000000..803b34be --- /dev/null +++ b/ecal2val/mock_publisher.py @@ -0,0 +1,77 @@ +#! /usr/bin/env python3 + +######################################################################## +# Copyright (c) 2024 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License 2.0 which is available at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +######################################################################## + +''' +Publisher publishing vss topics via eCAL communication. +''' + +import sys +import time + +import ecal.core.core as ecal_core +from ecal.core.publisher import ProtoPublisher + +import proto.proto_struct_pb2 as proto_struct_pb2 + + +def string(value): + return str(value) + + +def int32(value): + return int(value) + + +def int64(value): + return int(value) + + +def uint32(value): + return int(value) + + +def uint64(value): + return int(value) + + +def double(value): + return float(value) + + +ecal_core.initialize(sys.argv, "ecal2val") + +pub = ProtoPublisher("vss_topic", proto_struct_pb2.DataEntry) + +''' +Reads arbitrary data from 'mock_data.txt' +and publishes it in the form of a protobuf message. +''' + +while ecal_core.ok(): + with open("mock_data.txt", 'r', encoding='utf-8') as file: + for line in file: + path, value, data_type = line.split() + + entry = proto_struct_pb2.DataEntry() + entry.path = path + exec(f"entry.value.{data_type} = {data_type}(value)") + entry.data_type = data_type + + pub.send(entry) + print(f"{path} published") + + time.sleep(1) + +ecal_core.finalize() diff --git a/ecal2val/proto/proto_struct.proto b/ecal2val/proto/proto_struct.proto new file mode 100644 index 00000000..f7b71f01 --- /dev/null +++ b/ecal2val/proto/proto_struct.proto @@ -0,0 +1,35 @@ +/******************************************************************************** + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License 2.0 which is available at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +syntax = "proto3"; + +package proto_struct; + +message DataEntry { + string path = 1; + DataPoint value = 2; + string data_type = 3; +} + +message DataPoint { + oneof value { + string string = 1; + bool bool = 2; + sint32 int32 = 3; + sint64 int64 = 4; + uint32 uint32 = 5; + uint64 uint64 = 6; + float float = 7; + double double = 8; + } +}