Skip to content

Commit

Permalink
Merge pull request #3 from timrulebosch/oct_update
Browse files Browse the repository at this point in the history
Build, Packaging and Register schema updates.
  • Loading branch information
timrulebosch authored Oct 29, 2021
2 parents ffb8d48 + 2acbfbb commit 3b6a2af
Show file tree
Hide file tree
Showing 13 changed files with 378 additions and 136 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
146 changes: 146 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion doc/register/can.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion doc/register/ethernet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion doc/register/flexray.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
116 changes: 44 additions & 72 deletions schemas/register/can.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -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.Register.Can;


/**
Expand All @@ -29,104 +29,76 @@ 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).
}


/**
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";
Loading

0 comments on commit 3b6a2af

Please sign in to comment.