From 95e33c93ba988e64e8558028ac712d9f9d37a34e Mon Sep 17 00:00:00 2001 From: "Rule Timothy (CC/EMT2)" Date: Fri, 1 Oct 2021 08:39:17 +0200 Subject: [PATCH 1/7] Slightly refine the MIME Type for register interfaces. Simply lowercase the type parameter. Signed-off-by: Rule Timothy (CC/EMT2) --- doc/register/can.md | 2 +- doc/register/ethernet.md | 2 +- doc/register/flexray.md | 2 +- schemas/register/can.fbs | 4 ++-- schemas/register/ethernet.fbs | 2 +- schemas/register/flexray.fbs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/register/can.md b/doc/register/can.md index fb4bd6b..7cf3c84 100644 --- a/doc/register/can.md +++ b/doc/register/can.md @@ -13,7 +13,7 @@ Schema | Register Interface CAN :---|:---   | [Schema File](../../schemas/register/can.fbs) -MIME Type | application/x-automotive-bus; interface=register; type=CAN; +MIME Type | application/x-automotive-bus; interface=register; type=can; Data Stream | 4 byte Message Length followed by FlatBuffers Message. Repeating. FlatBuffers File Identifier | RICA diff --git a/doc/register/ethernet.md b/doc/register/ethernet.md index 5be779f..e3c1df4 100644 --- a/doc/register/ethernet.md +++ b/doc/register/ethernet.md @@ -12,7 +12,7 @@ Schema | Register Interface Ethernet :---|:---   | [Schema File](../../schemas/register/ethernet.fbs) -MIME Type | application/x-automotive-bus; interface=register; type=Ethernet; +MIME Type | application/x-automotive-bus; interface=register; type=ethernet; Data Stream | 4 byte Message Length followed by FlatBuffers Message. Repeating. FlatBuffers File Identifier | RIEN diff --git a/doc/register/flexray.md b/doc/register/flexray.md index 71ba5b1..b80482c 100644 --- a/doc/register/flexray.md +++ b/doc/register/flexray.md @@ -13,7 +13,7 @@ Schema | Register Interface FlexRay :---|:---   | [Schema File](../../schemas/register/flexray.fbs) -MIME Type | application/x-automotive-bus; interface=register; type=FlexRay; +MIME Type | application/x-automotive-bus; interface=register; type=flexray; Data Stream | 4 byte Message Length followed by FlatBuffers Message. Repeating. FlatBuffers File Identifier | RIFR diff --git a/schemas/register/can.fbs b/schemas/register/can.fbs index 603cab7..1f1aa6e 100644 --- a/schemas/register/can.fbs +++ b/schemas/register/can.fbs @@ -11,12 +11,12 @@ IDL for Automotive Bus - Register Interface - CAN ================================================= - MIME Type : application/x-automotive-bus; interface=register; type=CAN; + MIME Type : application/x-automotive-bus; interface=register; type=can; Flatbuffers file identifier : RICA */ -namespace AutomotiveBus.RegisterInterface.CAN; +namespace AutomotiveBus.RegisterInterface.Can; /** diff --git a/schemas/register/ethernet.fbs b/schemas/register/ethernet.fbs index f54c807..754d5c2 100644 --- a/schemas/register/ethernet.fbs +++ b/schemas/register/ethernet.fbs @@ -11,7 +11,7 @@ IDL for Automotive Bus - Register Interface - Ethernet ====================================================== - MIME Type : application/x-automotive-bus; interface=register; type=Ethernet; + MIME Type : application/x-automotive-bus; interface=register; type=ethernet; Flatbuffers file identifier : RIEN */ diff --git a/schemas/register/flexray.fbs b/schemas/register/flexray.fbs index 1a8a316..b9db3b1 100644 --- a/schemas/register/flexray.fbs +++ b/schemas/register/flexray.fbs @@ -11,7 +11,7 @@ IDL for Automotive Bus - Register Interface - FlexRay ===================================================== - MIME Type : application/x-automotive-bus; interface=register; type=FlexRay; + MIME Type : application/x-automotive-bus; interface=register; type=flexray; Flatbuffers file identifier : RIFR */ From 885669c466d876320ba8d80231196270a8886db0 Mon Sep 17 00:00:00 2001 From: "Rule Timothy (CC/EMT2)" Date: Fri, 1 Oct 2021 12:58:18 +0200 Subject: [PATCH 2/7] Flatten the Signal Schema file layout. Signed-off-by: Rule Timothy (CC/EMT2) --- schemas/signal/{flatbuffers => }/channel.fbs | 0 schemas/signal/{msgpack => }/data_payloads.yaml | 2 +- schemas/signal/{flatbuffers => }/encoder.fbs | 0 schemas/signal/{flatbuffers => }/parameter.fbs | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename schemas/signal/{flatbuffers => }/channel.fbs (100%) rename schemas/signal/{msgpack => }/data_payloads.yaml (98%) rename schemas/signal/{flatbuffers => }/encoder.fbs (100%) rename schemas/signal/{flatbuffers => }/parameter.fbs (100%) diff --git a/schemas/signal/flatbuffers/channel.fbs b/schemas/signal/channel.fbs similarity index 100% rename from schemas/signal/flatbuffers/channel.fbs rename to schemas/signal/channel.fbs diff --git a/schemas/signal/msgpack/data_payloads.yaml b/schemas/signal/data_payloads.yaml similarity index 98% rename from schemas/signal/msgpack/data_payloads.yaml rename to schemas/signal/data_payloads.yaml index e107e97..38bf3a2 100644 --- a/schemas/signal/msgpack/data_payloads.yaml +++ b/schemas/signal/data_payloads.yaml @@ -31,7 +31,7 @@ components: items: description: Signal UID type: integer - format: int32 + format: uint32 minimum: 0 type: array items: diff --git a/schemas/signal/flatbuffers/encoder.fbs b/schemas/signal/encoder.fbs similarity index 100% rename from schemas/signal/flatbuffers/encoder.fbs rename to schemas/signal/encoder.fbs diff --git a/schemas/signal/flatbuffers/parameter.fbs b/schemas/signal/parameter.fbs similarity index 100% rename from schemas/signal/flatbuffers/parameter.fbs rename to schemas/signal/parameter.fbs From d9d7fb73bcebf9f05ccf0872d96251f903f19465 Mon Sep 17 00:00:00 2001 From: "Rule Timothy (CC/EMT2)" Date: Fri, 1 Oct 2021 13:07:46 +0200 Subject: [PATCH 3/7] Fix a small issue with the Signal Data Payload Schema. Signed-off-by: Rule Timothy (CC/EMT2) --- schemas/signal/data_payloads.yaml | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/schemas/signal/data_payloads.yaml b/schemas/signal/data_payloads.yaml index 38bf3a2..0f4033d 100644 --- a/schemas/signal/data_payloads.yaml +++ b/schemas/signal/data_payloads.yaml @@ -19,6 +19,21 @@ info: version: 1.0 components: schemas: + SignalUidList: + description: Signal UID List + type: array + items: + description: Signal UID + anyOf: + - type: integer + - type: number + SignalValueList: + description: Signal Value List + type: array + items: + description: Signal Value + type: integer + format: uint32 SignalData: description: MsgPack encoded Signal Data. Number of elements in each nested array should be identical. example: Data = [[0..N],[0..N]] @@ -26,19 +41,9 @@ components: minItems: 1 maxItems: 2 items: - type: array - required: true - items: - description: Signal UID - type: integer - format: uint32 - minimum: 0 - type: array - items: - description: Signal Value - can be omitted for SignalRead. - anyOf: - - type: integer - - type: number + oneOf: + - $ref: '#/components/schemas/SignalUidList' + - $ref: '#/components/schemas/SignalValueList' ParameterData: description: MsgPack encoded Parameter Data. type: object From 4eddd6c46583f39466c8b4233a2583e6609a1635 Mon Sep 17 00:00:00 2001 From: "Rule Timothy (CC/EMT2)" Date: Tue, 19 Oct 2021 16:24:48 +0200 Subject: [PATCH 4/7] Updates to Register Schemas. * Refinements to FlexRay and Ethernet schemas. * Addition of additional Message Timing tables. * Restrucure of Frame/MetaFrames. * Changes to adhere to Flatbuffers coding style. * Remove redundant defaults. * Remove use of _required_ keyword to improve forwards/backward compatability. Signed-off-by: Rule Timothy (CC/EMT2) --- schemas/register/can.fbs | 112 +++++++++++++--------------------- schemas/register/ethernet.fbs | 74 ++++++++++++---------- schemas/register/flexray.fbs | 74 +++++++++++++++++++--- 3 files changed, 149 insertions(+), 111 deletions(-) diff --git a/schemas/register/can.fbs b/schemas/register/can.fbs index 1f1aa6e..319ce8b 100644 --- a/schemas/register/can.fbs +++ b/schemas/register/can.fbs @@ -29,8 +29,21 @@ enum BusState:byte { Idle = 1, Sync = 2 } + table CanStatus { - sync:BusState; + sync:BusState = Idle; +} + +struct TimeSpec { + // Used for timestamps and simulation time. + psec10:long; // Number of tens of picoseconds (resolution 1e-11 second). +} + +struct MessageTiming { + // Set of timestamps describing the entire timing of a message. + send_request:TimeSpec; // Timestamp of send request (virtual time). + arbitration:TimeSpec; // /imestamp of message arbitration (virtual time). + reception:TimeSpec; // Timestamp of message reception (virtual time). } @@ -38,95 +51,54 @@ table CanStatus { L3 CAN Bus Model ================ */ -struct TimeSpec { - // Holds data from clock system call. Used for timestamps and simulation time. - sec:long; - nsec:long; -} enum BufferDirection:byte { - // Direction (of a CAN Buffer), None is disabled. - None = 0, - Tx = 1, - Rx = 2 + // Direction of a CAN Buffer. + Tx = 0, + Rx = 1 } + enum BufferStatus:byte { // Status of a CAN Buffer. None = 0, - TxDone = 1, - RxDone = 2, - TxError = 11, - RxError = 12 + RxError = 1 } -table LinkProtocolDataUnit { - // Link Protocol Data Unit (L-PDU). - frame_id:long; // CAN Message ID. - // Tx - Frame ID - // Rx - Filtering schema - payload:[ubyte]; // LPDU Payload. Expected to be allocated at the - // maximum LPDU length (i.e. 256 bytes). - length:ubyte; // Length of payload content (not the size of the payload vector). +enum FrameType:byte{ + StandardFrame = 0, // Classicall CAN, payload up to 8 bytes. + ExtendedFrame = 1 // CAN FD, payload up to 64 bytes. } -table CanBuffer { - // CAN Buffer, representation of a single CAN Tx/Rx Buffer. - // - // Buffer/Register - index:ubyte (key); // Buffer Index, maps to a Register File position (0..n). - direction:BufferDirection = None; // None, Tx, Rx - status:BufferStatus = None; // None, TxDone, RxDone, TxError, RxError - - // Frame Signals - rtr:bool = 0; // Remote Frame request. - - // LPDU - lpdu:LinkProtocolDataUnit; // LPDU Frame. +table Frame { + // CAN Frame. + frame_id:uint; // CAN Message ID. + payload:[ubyte]; // Payload of the CAN frame, covered by DLC. Can be + // longer than the payload length specified by DLC, but + // must not be shorter. + length:ubyte; // Length of payload content posssible values as + // defined by CAN DLC spec: 0...8,12,16,20,24,32,48,64. + rtr:bool; // Indicates a Remote Frame request. + frame_type:FrameType = StandardFrame; +} - // Simulation Environment - The following values are injected/modified by - // the simulation environment and for FMU's are information only. - timestamp:TimeSpec (required); // Time since Linux epoch, in uSec. - simulation_time:TimeSpec (required); // Simulation time, in uSec. +table MetaFrame { + // Frame + meta information from/to interface. + status:BufferStatus; + direction:BufferDirection = Tx; + can_fd_enabled:bool; // CanFD enabled. + frame:Frame; // The frame itself. + timing:MessageTiming; // Timing of the message. } /** CAN Register File ================= - - Different CAN Transceivers will have different number of Buffers in their - Register File. The "index" of each Buffer should be initialized (depending on - the mode of operation, a partial Register File might be sent, in which case - the buffer.index would be needed to marshal data to correct locations). */ -enum BufferMode:byte { - // Indicate how the buffers are operating. - Register = 0, - Fifo = 1 -} - table RegisterFile { - status:CanStatus; // L2 Bus Status. - buffer:[CanBuffer]; // L3 Buffers for CAN Messages. - mode:[BufferMode]; // Buffers operate in Register or FIFO mode. - - // Registers, error monitoring. - // TEC or REC greater than 127 and lesser than 255 - Passive Error frame sent. - // TEC and REC lesser than 128 - Active Error frame sent. - // TEC is greater than 255 - no frames sent, node BusState set to BusOff - rec:int = 0; // REC receive error counter. - tec:int = 0; // TEC Transmit error counter. - active_error:bool = 0; // Signal to send an Active Error frame. - passive_error:bool = 0; // Signal to send an Passive Error frame. - overload:bool = 0; // Signal to send an Overload frame. - - // The following values are injected/modified by the simulation environment - // and for FMU's are information only. - ecu_id:int = 0; // UID for this ECU within the stimulation. - timestamp:TimeSpec; // Time since Linux epoch, in uSec. - simulation_time:TimeSpec; // Simulation time, in uSec. + // The register file is expected to operate in FIFO mode. + buffer:[MetaFrame]; // Buffer of MetaFrames. } - root_type RegisterFile; file_identifier "RICA"; file_extension "can"; diff --git a/schemas/register/ethernet.fbs b/schemas/register/ethernet.fbs index 754d5c2..eeddb81 100644 --- a/schemas/register/ethernet.fbs +++ b/schemas/register/ethernet.fbs @@ -27,53 +27,63 @@ enum BusSync:byte { NoSync = 0, Sync = 1 } + table EthernetStatus { sync:BusSync; } struct TimeSpec { - // Holds data from clock system call. Used for timestamps and simulation time. - sec:long; - nsec:long; + // Used for timestamps and simulation time. + psec10:long; // Number of tens of picoseconds (resolution 1e-11 second). +} + +struct MessageTiming { + // Set of timestamps describing the entire timing of a message. + send_request:TimeSpec; // Timestamp of send request (virtual time). + arbitration:TimeSpec; // /imestamp of message arbitration (virtual time). + reception:TimeSpec; // Timestamp of message reception (virtual time). } enum BufferDirection:byte { - // Direction (of an Ethernet Buffer), None is disabled. - None = 0, - Tx = 1, - Rx = 2 + // Direction, None is disabled. + Tx = 0, + Rx = 1 } enum BufferStatus:byte { // Status of an Ethernet Buffer. None = 0, - TxDone = 1, - RxDone = 2, - TxError = 11, - RxError = 12 + RxError = 1 } -table EthernetFrame { - dest_mac:[ubyte]; // Destination MAC address, 6 bytes - src_mac:[ubyte]; // Source MAC address, 6 bytes - vlan_tag:[ubyte]; // VLAN tag, 4 bytes - type:[ubyte]; // Type, 2 bytes - data:[ubyte]; // Payload, 42 - 1497 bytes - length:ushort; // Length of data payload. -} - -table EthernetBuffer { - index:ubyte; - direction:BufferDirection = None; - status:BufferStatus = None; - // Frame - frame:EthernetFrame; // Ethernet Frame. +table Frame { + // Ethernet Frame. + // Original Ethernet frames without IEEE 802.3q VLAN extension are NOT supported! + dest_mac:[ubyte]; // Destination MAC address, 6 bytes. + src_mac:[ubyte]; // Source MAC address, 6 bytes. + vlan_tag:ulong; // VLAN tag, 4 bytes, Little Endian: + // TPID: 16 bits:31...16 (0x8100 for IEEE 802.3q + // Ethernet with VLAN extension) + // PCP: 3 bits: 15...13 + // DEI: 1 bit: 12 + // VID: 12 bits: 11...0 + ether_type:ushort; // EtherType, 2 bytes, Little Endian: e.g. 0x0800 + // for IPv4 (LE 1st byte: 0x00, 2nd byte: 0x80). + data:[ubyte]; // Payload, 42 - 1497 bytes. + length:ushort; // Length of payload in bytes. If the total length + // of header+payload is less than 64 bytes then + // the interface implementation must add padding + // bytes to meet the requirement about minimal + // frame length. +} - // Simulation Environment - The following values are injected/modified by - // the simulation environment and for FMU's are information only. - timestamp:TimeSpec (required); // Time since Linux epoch, in uSec. - simulation_time:TimeSpec (required); // Simulation time, in uSec. +table MetaFrame { + // Frame + meta information from/to interface. + status:BufferStatus; + direction:BufferDirection = Tx; + frame:Frame; // The frame itself. + timing:MessageTiming; // Timing of the message. } @@ -82,8 +92,8 @@ table EthernetBuffer { ====================== */ table RegisterFile { - status:EthernetStatus; // L1/2 Bus Status. - buffer:[EthernetBuffer]; // Buffers for Ethernet Messages. + // The register file is expected to operate in FIFO mode. + buffer:[MetaFrame]; // Buffer of MetaFrames. } diff --git a/schemas/register/flexray.fbs b/schemas/register/flexray.fbs index b9db3b1..20d38ad 100644 --- a/schemas/register/flexray.fbs +++ b/schemas/register/flexray.fbs @@ -27,8 +27,21 @@ enum BusSync:byte { NoSync = 0, Sync = 1 } + table FlexrayStatus { - sync:BusSync; + sync:BusSync = NoSync; +} + +struct TimeSpec { + // Used for timestamps and simulation time. + psec10:long; // Number of tens of picoseconds (resolution 1e-11 second). +} + +struct MessageTiming { + // Set of timestamps describing the entire timing of a message. + send_request:TimeSpec; // Timestamp of send request (virtual time). + arbitration:TimeSpec; // /imestamp of message arbitration (virtual time). + reception:TimeSpec; // Timestamp of message reception (virtual time). } @@ -36,12 +49,55 @@ table FlexrayStatus { L3 FlexRay Bus Model ==================== */ -table FlexrayBuffer { - index:ubyte; - frame_id:ushort; - payload:[ubyte]; // LPDU Payload. Expected to be allocated at the - // maximum LPDU length (i.e. 256 bytes). - length:ubyte; // Length of payload content (not the size of the payload vector). +enum BufferDirection:byte { + // Direction, None is disabled. + Tx = 0, + Rx = 1 +} + +enum BufferStatus:byte { + // Status of an FlexRay Buffer. + None = 0, + RxError = 1 +} + +enum FrameChannel:byte { + // Frames to be sent can be ChA, ChB or Both. + // Frames received can be ChA or ChB but not Both! + // Reason: if the sender says Both then the receiver will receive two + // copies of the frame, the first with ChA and the second with ChB. + None = 0, + ChA = 1, + ChB = 2, + Both = 3 +} + +enum FrameIndicatorBits:ubyte { + // Indicator bits of the frame. + Startup = 1, + Sync = 2, + NotNull = 4, + Payload = 8, + Reserved = 16 +} + +table Frame { + // FlexRay Frame. + frame_id:ushort = 1; // Frame ID, must be 1 or higher. + indicators:ubyte = 12; // Combination of frame indicator bits (see FrameIndicatorBits). + length:ubyte = 1; // Length of data payload in 16 bit words (!), must be 0-127. + data:[ubyte]; // Payload, 0 to 254 bytes. +} + +table MetaFrame { + // Frame + meta information from/to interface. + status:BufferStatus; + direction:BufferDirection = Tx; + channel_mask:ubyte = 1; // Channel information. + cycle_period:ubyte = 1; // Can be 1,2,4,8,16,32 or 64. + cycle_offset:ubyte = 0; // Can be 0 to cycle_period-1. + frame:Frame; // The frame itself. + timing:MessageTiming; // Timing of the message. } @@ -50,8 +106,8 @@ table FlexrayBuffer { ===================== */ table RegisterFile { - status:FlexrayStatus; // L2 Bus Status. - buffer:[FlexrayBuffer]; // L3 Buffers for FlexRay Messages. + // The register file is expected to operate in FIFO mode. + buffer:[MetaFrame]; // Buffer of MetaFrames. } From 238096516ea9e7c134c4cc942ef93b92f8108f2a Mon Sep 17 00:00:00 2001 From: "Rule Timothy (CC/EMT2)" Date: Tue, 19 Oct 2021 16:25:24 +0200 Subject: [PATCH 5/7] Remove redundant "Interface" from Flatbuffer namespaces. Signed-off-by: Rule Timothy (CC/EMT2) --- schemas/register/can.fbs | 2 +- schemas/register/ethernet.fbs | 2 +- schemas/register/flexray.fbs | 2 +- schemas/signal/channel.fbs | 2 +- schemas/signal/encoder.fbs | 2 +- schemas/signal/parameter.fbs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/schemas/register/can.fbs b/schemas/register/can.fbs index 319ce8b..7966296 100644 --- a/schemas/register/can.fbs +++ b/schemas/register/can.fbs @@ -16,7 +16,7 @@ */ -namespace AutomotiveBus.RegisterInterface.Can; +namespace AutomotiveBus.Register.Can; /** diff --git a/schemas/register/ethernet.fbs b/schemas/register/ethernet.fbs index eeddb81..c8ed949 100644 --- a/schemas/register/ethernet.fbs +++ b/schemas/register/ethernet.fbs @@ -16,7 +16,7 @@ */ -namespace AutomotiveBus.RegisterInterface.Ethernet; +namespace AutomotiveBus.Register.Ethernet; /** diff --git a/schemas/register/flexray.fbs b/schemas/register/flexray.fbs index 20d38ad..f4d8757 100644 --- a/schemas/register/flexray.fbs +++ b/schemas/register/flexray.fbs @@ -16,7 +16,7 @@ */ -namespace AutomotiveBus.RegisterInterface.FlexRay; +namespace AutomotiveBus.Register.FlexRay; /** diff --git a/schemas/signal/channel.fbs b/schemas/signal/channel.fbs index 237245e..4dcb957 100644 --- a/schemas/signal/channel.fbs +++ b/schemas/signal/channel.fbs @@ -27,7 +27,7 @@ include "parameter.fbs"; -namespace AutomotiveBus.SignalInterface.Channel; +namespace AutomotiveBus.Signal.Channel; /** diff --git a/schemas/signal/encoder.fbs b/schemas/signal/encoder.fbs index ece5e0c..5fd90f3 100644 --- a/schemas/signal/encoder.fbs +++ b/schemas/signal/encoder.fbs @@ -18,7 +18,7 @@ */ -namespace AutomotiveBus.SignalInterface.Encoder; +namespace AutomotiveBus.Signal.Encoder; /** diff --git a/schemas/signal/parameter.fbs b/schemas/signal/parameter.fbs index ce3fb54..4742223 100644 --- a/schemas/signal/parameter.fbs +++ b/schemas/signal/parameter.fbs @@ -21,7 +21,7 @@ */ -namespace AutomotiveBus.SignalInterface.Parameter; +namespace AutomotiveBus.Signal.Parameter; /** From 89a22f195b2a921260fcc68d772b2cc81025f7f1 Mon Sep 17 00:00:00 2001 From: "Rule Timothy (CC/EMT2)" Date: Fri, 1 Oct 2021 17:58:18 +0200 Subject: [PATCH 6/7] Add a Makefile for building the schemas. Produce a distribution package. Signed-off-by: Rule Timothy (CC/EMT2) --- .gitignore | 1 + Makefile | 146 ++++++++++++++++++++++++++++++++++++++ templates/python/setup.py | 52 ++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 templates/python/setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..849ddff --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..81917e0 --- /dev/null +++ b/Makefile @@ -0,0 +1,146 @@ +#*************************************************************************** +# Copyright (c) 2021 for information on the respective copyright owner +# see the NOTICE file and/or the following repository: +# https://github.com/boschglobal/automotive-bus-schema +# +# SPDX-License-Identifier: Apache-2.0 +#*************************************************************************** + + +############### +## Builder Images +BUILDER_DOCKER_IMAGES = flatc-builder python-builder +FLATC_BUILDER_IMAGE ?= flatc-builder:latest +PYTHON_BUILDER_IMAGE ?= python-builder:latest + + +############### +## Build parameters. +PLATFORM = linux64 +DIST_DIR = $(shell pwd -P)/dist +OUT_DIR = $(shell pwd -P)/dist/$(PACKAGE_NAME) +# Flatbuffers +FBS_OUT_DIR = $(OUT_DIR)/flatbuffers +FBS_SCHEMA_DIR = $(shell pwd -P)/schemas +FBS_SCHEMA_SOURCES = $(shell ls $(FBS_SCHEMA_DIR)/**/*.fbs) +# FlatC +FLATC = flatc +FLATC_OPTIONS = +FLATCC = flatcc +# FlatCC +FLATCC_SRC_RUNTIME_DIR = /usr/local/src/flatcc/src/runtime +FLATCC_SRC_INCLUDE_DIR = /usr/local/include/flatcc +FLATCC_SRC_LICENSE_DIR = /usr/local/src/flatcc +FLATCC_DIST_RUNTIME_DIR = $(FBS_OUT_DIR)/c/src/flatcc +FLATCC_DIST_INCLUDE_DIR = $(FBS_OUT_DIR)/c/include/flatcc +# MsgPack +MPK_OUT_DIR = $(OUT_DIR)/msgpack +MPK_SCHEMA_DIR = $(shell pwd -P)/schemas +MPK_SCHEMA_SOURCES = $(shell ls $(MPK_SCHEMA_DIR)/**/*.yaml) +# Python (for creating a Python Package) +PYTHON_SRC_DIR = $(FBS_OUT_DIR)/python +PYTHON_DIST_DIR = $(DIST_DIR)/python + + +############### +## Packaging. +PACKAGE_NAME = automotive-bus-schema +PACKAGE_FILENAME = $(PACKAGE_NAME).tar.gz +PACKAGE_VERSION ?= devel + + +default: build + + +builders: + for d in $(BUILDER_DOCKER_IMAGES) ;\ + do \ + docker build -f docker/$$d/Dockerfile \ + --tag $$d:latest ./docker/$$d ;\ + done; + +build: + docker run -it --rm \ + --volume $$(pwd):/tmp/repo \ + --env PACKAGE_VERSION=$(PACKAGE_VERSION) \ + --workdir /tmp/repo \ + $(FLATC_BUILDER_IMAGE) \ + /bin/bash -c "make fbs" + docker run -it --rm \ + --volume $$(pwd):/tmp/repo \ + --env PIP_EXTRA_INDEX_URL=$(PIP_EXTRA_INDEX_URL) \ + --env PACKAGE_VERSION=$(PACKAGE_VERSION) \ + --workdir /tmp/repo \ + $(PYTHON_BUILDER_IMAGE) \ + /bin/bash -c "make python; make msgpack" + + @echo "" + @echo "Generated files:" + @echo "---------------" + @ls -R $(FBS_OUT_DIR) + @ls -R $(MPK_OUT_DIR) + +$(FBS_SCHEMA_SOURCES): + @echo $@ + # Setup the directory structure. + mkdir -p $(FBS_OUT_DIR)/c/$$(basename $$(dirname $@)) + mkdir -p $(FBS_OUT_DIR)/cpp/$$(basename $$(dirname $@)) + mkdir -p $(FBS_OUT_DIR)/fbs/$$(basename $$(dirname $@)) + mkdir -p $(FBS_OUT_DIR)/fbs/$$(basename $$(dirname $@)) + mkdir -p $(FBS_OUT_DIR)/fbs/$$(basename $$(dirname $@)) + # Generate Flatbuffers code. + $(FLATCC) -a $(FLATC_OPTIONS) -o $(FBS_OUT_DIR)/c/$$(basename $$(dirname $@)) $@ + $(FLATC) --cpp $(FLATC_OPTIONS) --filename-suffix '' -o $(FBS_OUT_DIR)/cpp/$$(basename $$(dirname $@)) $@ + $(FLATC) --python $(FLATC_OPTIONS) -o $(FBS_OUT_DIR)/python $@ + $(FLATC) --lua $(FLATC_OPTIONS) -o $(FBS_OUT_DIR)/lua $@ + # Copy over the original Flatbuffer schemas. + cp $@ $(FBS_OUT_DIR)/fbs/$$(basename $$(dirname $@)) + +fbs: $(FBS_SCHEMA_SOURCES) + mkdir -p $(FLATCC_DIST_RUNTIME_DIR) + cp $(FLATCC_SRC_RUNTIME_DIR)/builder.c $(FLATCC_DIST_RUNTIME_DIR) + cp $(FLATCC_SRC_RUNTIME_DIR)/emitter.c $(FLATCC_DIST_RUNTIME_DIR) + cp $(FLATCC_SRC_RUNTIME_DIR)/refmap.c $(FLATCC_DIST_RUNTIME_DIR) + cp $(FLATCC_SRC_LICENSE_DIR)/LICENSE $(FLATCC_DIST_RUNTIME_DIR) + mkdir -p $(FLATCC_DIST_INCLUDE_DIR) + cp -r $(FLATCC_SRC_INCLUDE_DIR)/* $(FLATCC_DIST_INCLUDE_DIR) + +$(MPK_SCHEMA_SOURCES): + @echo $@ + mkdir -p $(MPK_OUT_DIR)/$$(basename $$(dirname $@)) + cp $@ $(MPK_OUT_DIR)/$$(basename $$(dirname $@)) + +msgpack: $(MPK_SCHEMA_SOURCES) + +python: + mkdir -p $(PYTHON_DIST_DIR) + cp -r $(PYTHON_SRC_DIR)/* $(PYTHON_DIST_DIR) + cp -r templates/python/* $(PYTHON_DIST_DIR) + cd $(PYTHON_DIST_DIR) && python3 setup.py sdist bdist_wheel + +dist_package: + mkdir -p $(DIST_DIR) + mkdir -p $(OUT_DIR) + echo $(PACKAGE_VERSION) > $(OUT_DIR)/VERSION + + tar -czvf $(DIST_DIR)/$(PACKAGE_FILENAME) -C $(DIST_DIR) $(PACKAGE_NAME) + +dist: + docker run -it --rm \ + --volume $$(pwd):/tmp/repo \ + --env PIP_EXTRA_INDEX_URL=$(PIP_EXTRA_INDEX_URL) \ + --env PACKAGE_VERSION=$(PACKAGE_VERSION) \ + --workdir /tmp/repo \ + $(PYTHON_BUILDER_IMAGE) \ + /bin/bash -c "make dist_package" + + @echo "" + @echo "Distribution package files:" + @echo "--------------------------" + @ls -1sh $(DIST_DIR)/*.* + @ls -1sh $(PYTHON_DIST_DIR)/dist/*.* + +clean: + -@rm -rf $(DIST_DIR) + +.PHONY: default build fbs msgpack python dist dist_package builders clean $(FBS_SCHEMA_SOURCES) $(MPK_SCHEMA_SOURCES) diff --git a/templates/python/setup.py b/templates/python/setup.py new file mode 100644 index 0000000..4159e32 --- /dev/null +++ b/templates/python/setup.py @@ -0,0 +1,52 @@ +#*************************************************************************** +# Copyright (c) 2021 for information on the respective copyright owner +# see the NOTICE file and/or the following repository: +# https://github.com/boschglobal/automotive-bus-schema +# +# SPDX-License-Identifier: Apache-2.0 +#*************************************************************************** + +import os +from setuptools import setup, find_packages + + +install_requires = [ + 'flatbuffers', +] + +PACKAGE_NAME = "automotivebus" + +DESCRIPTION = """ +Automotive Bus Schema +===================== + +Generated Python Package containing generated code from the Automotive Bus Schema. +""" + +setup( + name = PACKAGE_NAME, + version = os.getenv('PACKAGE_VERSION', 'devel'), + author = "Timothy Rule", + author_email = "Timothy.Rule@de.bosch.com", + description = 'Automotive Bus Schema', + long_description = DESCRIPTION, + long_description_content_type = 'text/markdown', + url = "https://github.com/boschglobal/automotive-bus-schema.git", + license = "Apache-2.0", + + packages=find_packages(), + include_package_data=True, + + python_requires='>=3.8', + install_requires=install_requires, + setup_requires=[], + zip_safe=False, + + classifiers=[ + "License :: Apache-2.0", + "Natural Language :: English", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3.8", + "Topic :: Software Development :: Simulation", + ], +) From 2acbfbb0ed7f85facdd6fa7333924f781fa6fec8 Mon Sep 17 00:00:00 2001 From: Timothy Rule <90191439+timrulebosch@users.noreply.github.com> Date: Mon, 18 Oct 2021 22:23:47 +0200 Subject: [PATCH 7/7] Update README.md Signed-off-by: Rule Timothy (CC/EMT2) --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 18f9957..f0c76d4 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ Currently buffer representations of CAN, FlexRay, Ethernet and Encoded Signals a L- docs Documentation L- schemas Schemas of the Standard L- docker Supporting build environments - ```