From cfa53771510b7820e6d66651c1cd19501dff8a7d Mon Sep 17 00:00:00 2001 From: Benedikt Menne Date: Wed, 6 Dec 2023 08:58:23 +0100 Subject: [PATCH] Moved Util headers to fmi-ls-bus repo --- ls-bus-guide/4____network_abstraction.adoc | 18 +- .../demos/can-bus-simulation/PackFmu.py | 8 +- .../can-node-triggered-output/PackFmu.py | 8 +- ls-bus-guide/headers/fmi3LsBusUtil.h | 223 -------- ls-bus-guide/headers/fmi3LsBusUtilCan.h | 498 ------------------ 5 files changed, 15 insertions(+), 740 deletions(-) delete mode 100644 ls-bus-guide/headers/fmi3LsBusUtil.h delete mode 100644 ls-bus-guide/headers/fmi3LsBusUtilCan.h diff --git a/ls-bus-guide/4____network_abstraction.adoc b/ls-bus-guide/4____network_abstraction.adoc index 96a21b0..6905a69 100644 --- a/ls-bus-guide/4____network_abstraction.adoc +++ b/ls-bus-guide/4____network_abstraction.adoc @@ -8,15 +8,19 @@ This chapter contains details on CAN, CAN FD, CAN XL specific topics. This section shows the exemplary implementation in conjunction with the provided header files of the fmi-ls-bus layered standard. ===== Provided Header Files [[low-cut-can-getting-started-provided-header-files]] -The layered standard fmi-ls-bus not only contains a textual specification for bus support, but also provides header and utility functions as C code to make creation and use within FMUs as easy as possible. -The following header files are provided by the standard for this purpose, although their use is not mandatory but optional: +Besides the textual specification for FMUs with bus support, the fmi-ls-bus layered standard also provides a C API to make the creation of FMUs with bus support as easy and generalized as possible. +The standard differentiates between two groups of files within the C API: Mandatory and optional files. -* https://github.com/modelica/fmi-ls-bus/blob/main/headers/fmi3LsBus.h[fmi3LsBus.h] provides general functions and structures. -These header file applies to all supported bus types of the layered standard. -* https://github.com/modelica/fmi-ls-bus/blob/main/headers/fmi3LsBusCan.h[fmi3LsBusCan.h] provides functions and structures explicit for CAN, CAN FD and CAN XL. +* https://github.com/modelica/fmi-ls-bus/blob/main/headers/fmi3LsBus.h[fmi3LsBus.h] provides general macros, types and structures of common Bus Operations. +These header file applies to all supported bus types of the layered standard. +The usage of this file is mandatory. +* https://github.com/modelica/fmi-ls-bus/blob/main/headers/fmi3LsBusCan.h[fmi3LsBusCan.h] provides macros, types and structures of Bus Operations explicit for CAN, CAN FD and CAN XL. Primarily, structures are included here that allow the Bus Operations specified by the layered standard to be easily created and used. -* https://github.com/modelica/fmi-guides/blob/main/ls-bus-guide/headers/fmi3LsBusUtil.h[fmi3LsBusUtil.h] provides common utility functions and structures for all supported bus types. -* https://github.com/modelica/fmi-guides/blob/main/ls-bus-guide/headers/fmi3LsBusUtilCan.h[fmi3LsBusUtilCan.h] provides CAN, CAN FD and CAN XL explicit utility functions. +The usage of this file is mandatory. +* https://github.com/modelica/fmi-ls-bus/blob/main/headers/fmi3LsBusUtil.h[fmi3LsBusUtil.h] provides common utility macros and structures for all supported bus types. +The usage of this file is optional. +* https://github.com/modelica/fmi-ls-bus/blob/main/headers/fmi3LsBusUtilCan.h[fmi3LsBusUtilCan.h] provides CAN, CAN FD and CAN XL explicit utility macros. +The usage of this file is optional ===== General Aspects Bus Operations represent protocol units to be transmitted in the environment of the layered standard based on the https://modelica.github.io/fmi-ls-bus/main/#low-cut-layered-standard-bus-protocol[Layered Standard Bus Protocol]. diff --git a/ls-bus-guide/demos/can-bus-simulation/PackFmu.py b/ls-bus-guide/demos/can-bus-simulation/PackFmu.py index 097067b..2e5f9d6 100644 --- a/ls-bus-guide/demos/can-bus-simulation/PackFmu.py +++ b/ls-bus-guide/demos/can-bus-simulation/PackFmu.py @@ -9,8 +9,8 @@ # Repository to fetch the LS-BUS headers from LS_BUS_REPO = 'modelica/fmi-ls-bus' -LS_BUS_REV = '473bd5b80730c47373bf41f1c31d44f50de82dd0' -LS_BUS_HEADERS = [ 'fmi3LsBus.h', 'fmi3LsBusCan.h' ] +LS_BUS_REV = '4680d63c0705fbf9076f97128e913f464b442f53' +LS_BUS_HEADERS = [ 'fmi3LsBus.h', 'fmi3LsBusCan.h', 'fmi3LsBusUtil.h', 'fmi3LsBusUtilCan.h' ] def main(): @@ -23,10 +23,6 @@ def main(): with urllib.request.urlopen(f'https://raw.githubusercontent.com/{LS_BUS_REPO}/{LS_BUS_REV}/headers/{ls_bus_header}') as f: fmu.writestr(f'sources/{ls_bus_header}', f.read()) - # Add LS-BUS utility headers - for file in (demo_dir.parent.parent / 'headers').iterdir(): - fmu.write(file, f'sources/{file.name}') - # Add source files for file in (demo_dir / 'src').iterdir(): fmu.write(file, f'sources/{file.name}') diff --git a/ls-bus-guide/demos/can-node-triggered-output/PackFmu.py b/ls-bus-guide/demos/can-node-triggered-output/PackFmu.py index a08ada0..1814acb 100644 --- a/ls-bus-guide/demos/can-node-triggered-output/PackFmu.py +++ b/ls-bus-guide/demos/can-node-triggered-output/PackFmu.py @@ -9,8 +9,8 @@ # Repository to fetch the LS-BUS headers from LS_BUS_REPO = 'modelica/fmi-ls-bus' -LS_BUS_REV = '473bd5b80730c47373bf41f1c31d44f50de82dd0' -LS_BUS_HEADERS = [ 'fmi3LsBus.h', 'fmi3LsBusCan.h' ] +LS_BUS_REV = '4680d63c0705fbf9076f97128e913f464b442f53' +LS_BUS_HEADERS = [ 'fmi3LsBus.h', 'fmi3LsBusCan.h', 'fmi3LsBusUtil.h', 'fmi3LsBusUtilCan.h' ] def main(): @@ -23,10 +23,6 @@ def main(): with urllib.request.urlopen(f'https://raw.githubusercontent.com/{LS_BUS_REPO}/{LS_BUS_REV}/headers/{ls_bus_header}') as f: fmu.writestr(f'sources/{ls_bus_header}', f.read()) - # Add LS-BUS utility headers - for file in (demo_dir.parent.parent / 'headers').iterdir(): - fmu.write(file, f'sources/{file.name}') - # Add source files for file in (demo_dir / 'src').iterdir(): fmu.write(file, f'sources/{file.name}') diff --git a/ls-bus-guide/headers/fmi3LsBusUtil.h b/ls-bus-guide/headers/fmi3LsBusUtil.h deleted file mode 100644 index af6b158..0000000 --- a/ls-bus-guide/headers/fmi3LsBusUtil.h +++ /dev/null @@ -1,223 +0,0 @@ -#ifndef fmi3LsBusUtil_h -#define fmi3LsBusUtil_h - -/* - -This header file contains utility macros to read and write fmi-ls-bus -bus operations from\to dedicated buffer variables. - -This header can be used when creating Network FMUs. - -Copyright (C) 2023 Modelica Association Project "FMI" - All rights reserved. - -This file is licensed by the copyright holders under the 2-Clause BSD License -(https://opensource.org/licenses/BSD-2-Clause): - ----------------------------------------------------------------------------- -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -- Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -- Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- -*/ - -#include - -#include "fmi3LsBus.h" - - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** - * \brief This data type holds information to read and write bus operations to/from - * a buffer variable via utility macros such as \ref FMI3_LS_BUS_BUFFER_WRITE and - * \ref FMI3_LS_BUS_READ_NEXT_OPERATION. - * - * Variables of this type should be initialized using \ref FMI3_LS_BUS_BUFFER_INFO_INIT - * and reset with \ref FMI3_LS_BUS_BUFFER_INFO_RESET. - */ -typedef struct -{ - fmi3UInt8* start; /**< The start address of the buffer variable. */ - size_t size; /**< The size of the buffer variable. */ - fmi3UInt8* end; /**< The end address of the buffer variable. */ - fmi3UInt8* writePos; /**< The current write position. */ - fmi3UInt8* readPos; /**< The current read position. */ - fmi3Boolean status; /**< Holds the status (fmi3True\fmi3False) of the last macro call. */ -} fmi3LsBusUtilBufferInfo; - - -/** - * \brief Initializes a variable of type \ref fmi3LsBusUtilBufferInfo. - * - * This macro should be used to initialize variables of type \ref fmi3LsBusUtilBufferInfo. - * - * Example: - * \code - * fmi3UInt8 buffer[2048]; - * fmi3LsBusUtilBufferInfo bufferInfo; - * FMI3_LS_BUS_BUFFER_INFO_INIT(&bufferInfo, buffer, sizeof(buffer)); - * \endcode - * - * \param[in] BufferInfo Pointer to variable of type \ref fmi3LsBusUtilBufferInfo. - * \param[in] Buffer Pointer to buffer variable. - * \param[in] Size Size of the buffer variable. - */ -#define FMI3_LS_BUS_BUFFER_INFO_INIT(BufferInfo, Buffer, Size) \ - do \ - { \ - (BufferInfo)->start = (Buffer); \ - (BufferInfo)->size = (Size); \ - (BufferInfo)->end = (Buffer) + (Size); \ - (BufferInfo)->writePos = (BufferInfo)->start; \ - (BufferInfo)->readPos = (BufferInfo)->start; \ - (BufferInfo)->status = fmi3True; \ - } \ - while (0) - -/** - * \brief Resets a variable of type \ref fmi3LsBusUtilBufferInfo. - * - * This macro should be used to reset variables of type \ref fmi3LsBusUtilBufferInfo. - * Read and write positions are set to the buffer start address. - * The Variable must have been initialized using \ref FMI3_LS_BUS_BUFFER_INFO_INIT before. - * - * \param[in] BufferInfo Pointer to variable of type \ref fmi3LsBusUtilBufferInfo. - */ -#define FMI3_LS_BUS_BUFFER_INFO_RESET(BufferInfo) \ - do \ - { \ - (BufferInfo)->writePos = (BufferInfo)->start; \ - (BufferInfo)->readPos = (BufferInfo)->start; \ - (BufferInfo)->status = fmi3True; \ - } \ - while (0) - -/** - * \brief Checks whether the buffer variable is empty. - * - * \param[in] BufferInfo Pointer to variable of type \ref fmi3LsBusUtilBufferInfo. - */ -#define FMI3_LS_BUS_BUFFER_IS_EMPTY(BufferInfo) \ - ((BufferInfo)->writePos == (BufferInfo)->start ? fmi3True : fmi3False) - -/** - * \brief Returns the start address of the buffer variable. - * - * \param[in] BufferInfo Pointer to variable of type \ref fmi3LsBusUtilBufferInfo. - */ -#define FMI3_LS_BUS_BUFFER_START(BufferInfo) \ - ((BufferInfo)->start) - -/** - * \brief Returns the actual length of the buffer variable beginning from the start address. - * - * \param[in] BufferInfo Pointer to variable of type \ref fmi3LsBusUtilBufferInfo. - */ -#define FMI3_LS_BUS_BUFFER_LENGTH(BufferInfo) \ - ((BufferInfo)->writePos - (BufferInfo)->start) - -/** - * \brief Writes data to a buffer variable. Existing data will be overwritten. - * - * \param[in] BufferInfo Pointer to variable of type \ref fmi3LsBusUtilBufferInfo. - * \param[in] Data Pointer to data to be written. - * \param[in] DataLength Size of the data to be written. - */ -#define FMI3_LS_BUS_BUFFER_WRITE(BufferInfo, Data, DataLength) \ - do \ - { \ - if ((DataLength) <= (BufferInfo)->size) \ - { \ - memcpy((BufferInfo)->start, (Data), (DataLength)); \ - (BufferInfo)->writePos = (BufferInfo)->start + (DataLength); \ - (BufferInfo)->readPos = (BufferInfo)->start; \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Reads the next bus operation from a buffer. - * - * Example: - * \code - * fmi3LsBusOperationHeader* nextOperation; - * while (FMI3_LS_BUS_READ_NEXT_OPERATION(BufferInfo, nextOperation)) - * { - * ... - * } - * \endcode - * - * \param[in] BufferInfo Pointer to variable of type \ref fmi3LsBusUtilBufferInfo. - * \param[out] Operation Pointer of type \ref fmi3LsBusOperationHeader* set by the macro - * to the address where the next bus operation can be read from. - * \return fmi3True if a new operation is available, otherwise fmi3False. - */ -#define FMI3_LS_BUS_READ_NEXT_OPERATION(BufferInfo, Operation) \ - ((fmi3UInt32)((BufferInfo)->writePos - (BufferInfo)->readPos) >= sizeof(fmi3LsBusOperationHeader) && \ - (fmi3UInt32)((BufferInfo)->writePos - (BufferInfo)->readPos) >= ((fmi3LsBusOperationHeader*)(BufferInfo)->readPos)->length) \ - ? ((Operation) = (fmi3LsBusOperationHeader*)(BufferInfo)->readPos, (BufferInfo)->readPos += (Operation)->length), \ - fmi3True : fmi3False\ - - /** - * \brief Reads the next bus operation directly from a raw buffer. - * - * Example: - * \code - * fmi3SetBinary(..., const size_t valueSizes[], const fmi3Binary values[], ...) - * { - * fmi3LsBusOperationHeader* nextOperation; - * size_t readPos = 0; - * ... - * while (FMI3_LS_BUS_READ_NEXT_OPERATION_DIRECT(values[i], valueSizes[i], readPos, nextOperation)) - * { - * ... - * } - * } - * \endcode - * - * \param[in] Buffer Pointer to buffer variable of type fmi3Binary. - * \param[in] BufferLength The length of the data in the buffer. - * \param[in,out] ReadPos Variable to hold the current read position. - * \param[out] Operation Pointer of type \ref fmi3LsBusOperationHeader* set by the macro - * to the address where the next bus operation can be read from. - * \return fmi3True if a new operation is available, otherwise fmi3False. - */ -#define FMI3_LS_BUS_READ_NEXT_OPERATION_DIRECT(Buffer, BufferLength, ReadPos, Operation) \ - (((BufferLength) - (ReadPos)) >= sizeof(fmi3LsBusOperationHeader) && \ - ((BufferLength) - (ReadPos)) >= ((fmi3LsBusOperationHeader*)((Buffer) + (ReadPos)))->length) \ - ? ((Operation) = (fmi3LsBusOperationHeader*)((Buffer) + (ReadPos)), (ReadPos) += (Operation)->length), \ - fmi3True : fmi3False\ - - -#ifdef __cplusplus -} /* end of extern "C" { */ -#endif - -#endif /* fmi3LsBusUtil_h */ diff --git a/ls-bus-guide/headers/fmi3LsBusUtilCan.h b/ls-bus-guide/headers/fmi3LsBusUtilCan.h deleted file mode 100644 index b8ce6e5..0000000 --- a/ls-bus-guide/headers/fmi3LsBusUtilCan.h +++ /dev/null @@ -1,498 +0,0 @@ -#ifndef fmi3LsBusUtilCan_h -#define fmi3LsBusUtilCan_h - -/* -This header file contains utility macros to read and write fmi-ls-bus -CAN specific bus operations from\to dedicated buffer variables. - -This header file can be used when creating Network fmi-ls-bus FMUs with CAN busses. - -Copyright (C) 2023 Modelica Association Project "FMI" - All rights reserved. - -This file is licensed by the copyright holders under the 2-Clause BSD License -(https://opensource.org/licenses/BSD-2-Clause): - ----------------------------------------------------------------------------- -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -- Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -- Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- -*/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "fmi3LsBusCan.h" -#include "fmi3LsBusUtil.h" - -/** - * \brief Creates a CAN transmit operation. - * - * This macro can be used to create a CAN transmit operation. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - * \param[in] ID CAN message ID (\ref fmi3LsBusCanId). - * \param[in] Ide CAN message ID type (standard/extended) (\ref fmi3LsBusCanIde). - * \param[in] Rtr Remote Transmission Request (\ref fmi3LsBusCanRtr). - * \param[in] DataLength Message data length (\ref fmi3LsBusCanDataLength). - * \param[in] Data Message data (\ref fmi3LsBusCanDataLength). - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_CAN_TRANSMIT(BufferInfo, ID, Ide, Rtr, DataLength, Data) \ - do \ - { \ - fmi3LsBusCanOperationCanTransmit _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_CAN_TRANSMIT; \ - _op.header.length = sizeof(fmi3LsBusOperationHeader) + \ - sizeof(fmi3LsBusCanId) + \ - sizeof(fmi3LsBusCanIde) + \ - sizeof(fmi3LsBusCanRtr) + \ - sizeof(fmi3LsBusCanDataLength) + \ - (DataLength); \ - _op.id = (ID); \ - _op.ide = (Ide); \ - _op.rtr = (Rtr); \ - \ - _op.dataLength = (DataLength); \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length - (DataLength)); \ - (BufferInfo)->writePos += _op.header.length - (DataLength); \ - memcpy((BufferInfo)->writePos, (Data), (DataLength)); \ - (BufferInfo)->writePos += (DataLength); \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Creates a CAN FD transmit operation. - * - * This macro can be used to create a CAN FD transmit operation. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - * \param[in] ID CAN message ID (\ref fmi3LsBusCanId). - * \param[in] Ide CAN message ID type (standard\extended) (\ref fmi3LsBusCanIde). - * \param[in] Brs Bit Rate Switch (\ref fmi3LsBusCanBrs). - * \param[in] Esi Error State Indicator (\ref fmi3LsBusCanEsi). - * \param[in] DataLength Message data length (\ref fmi3LsBusCanDataLength). - * \param[in] Data Message data (\ref fmi3LsBusCanDataLength). - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_CAN_FD_TRANSMIT(BufferInfo, ID, Ide, Brs, Esi, DataLength, Data) \ - do \ - { \ - fmi3LsBusCanOperationCanFdTransmit _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_CANFD_TRANSMIT; \ - _op.header.length = sizeof(fmi3LsBusOperationHeader) + sizeof(fmi3LsBusCanId) + sizeof(fmi3LsBusCanIde) + \ - sizeof(fmi3LsBusCanBrs) + sizeof(fmi3LsBusCanEsi) + sizeof(fmi3LsBusCanDataLength) + \ - (DataLength); \ - _op.id = (ID); \ - _op.ide = (Ide); \ - _op.brs = (Brs); \ - _op.esi = (Esi); \ - \ - _op.dataLength = (DataLength); \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length - (DataLength)); \ - (BufferInfo)->writePos += _op.header.length - (DataLength); \ - memcpy((BufferInfo)->writePos, (Data), (DataLength)); \ - (BufferInfo)->writePos += (DataLength); \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Creates a CAN XL transmit operation. - * - * This macro can be used to create a CAN XL transmit operation. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - * \param[in] ID CAN message ID (\ref fmi3LsBusCanId). - * \param[in] Ide CAN message ID type (standard/extended) (\ref fmi3LsBusCanIde). - * \param[in] Sec Simple Extended Content (\ref fmi3LsBusCanSec). - * \param[in] Sdt Service Data Unit Type (\ref fmi3LsBusCanSdt). - * \param[in] VcId Virtual CAN Network ID (\ref fmi3LsBusCanVcId). - * \param[in] Af Acceptance Field (\ref fmi3LsBusCanAf). - * \param[in] DataLength Message data length (\ref fmi3LsBusCanDataLength). - * \param[in] Data Message data (\ref fmi3LsBusCanDataLength). - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_CAN_XL_TRANSMIT(BufferInfo, ID, Ide, Sec, Sdt, VcId, Af, DataLength, Data) \ - do \ - { \ - fmi3LsBusCanOperationCanXlTransmit _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_CANXL_TRANSMIT; \ - _op.header.length = sizeof(fmi3LsBusOperationHeader) + sizeof(fmi3LsBusCanId) + sizeof(fmi3LsBusCanIde) + \ - sizeof(fmi3LsBusCanSec) + sizeof(fmi3LsBusCanSdt) + sizeof(fmi3LsBusCanVcId) + \ - sizeof(fmi3LsBusCanAf) + sizeof(fmi3LsBusCanDataLength) + (DataLength); \ - _op.id = (ID); \ - _op.ide = (Ide); \ - _op.sec = (Sec); \ - _op.sdt = (Sdt); \ - _op.vcid = (VcId); \ - _op.af = (Af); \ - \ - _op.dataLength = (DataLength); \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length - (DataLength)); \ - (BufferInfo)->writePos += _op.header.length - (DataLength); \ - memcpy((BufferInfo)->writePos, (Data), (DataLength)); \ - (BufferInfo)->writePos += (DataLength); \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Creates a CAN confirm operation. - * - * This macro can be used to create a CAN confirm operation. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - * \param[in] ID CAN message ID (\ref fmi3LsBusCanId). - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_CONFIRM(BufferInfo, ID) \ - do \ - { \ - fmi3LsBusCanOperationConfirm _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_CONFIRM; \ - _op.header.length = sizeof(fmi3LsBusOperationHeader) + \ - sizeof(fmi3LsBusCanId); \ - _op.id = (ID); \ - \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length); \ - (BufferInfo)->writePos += _op.header.length; \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Creates a CAN configuration operation for the baud rate setting. - * - * This macro can be used to create a CAN configuration operation for the baud rate setting. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - * \param[in] BaudRate The baud rate (\ref fmi3LsBusCanBaudrate). - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_CONFIGURATION_CAN_BAUDRATE(BufferInfo, BaudRate) \ - do \ - { \ - fmi3LsBusCanOperationConfiguration _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_CONFIGURATION; \ - _op.header.length = sizeof(fmi3LsBusOperationHeader) + \ - sizeof(fmi3LsBusCanConfigParameterType) + \ - sizeof(fmi3LsBusCanBaudrate); \ - _op.parameterType = FMI3_LS_BUS_CAN_CONFIG_PARAM_TYPE_CAN_BAUDRATE; \ - _op.baudrate = (BaudRate); \ - \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length); \ - (BufferInfo)->writePos += _op.header.length; \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Creates a CAN configuration operation for the CAN FD baud rate setting. - * - * This macro can be used to create a CAN configuration operation for the CAN FD baud rate setting. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - * \param[in] BaudRate The baud rate (\ref fmi3LsBusCanBaudrate). - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_CONFIGURATION_CAN_FD_BAUDRATE(BufferInfo, BaudRate) \ - do \ - { \ - fmi3LsBusCanOperationConfiguration _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_CONFIGURATION; \ - _op.header.length = \ - sizeof(fmi3LsBusOperationHeader) + sizeof(fmi3LsBusCanConfigParameterType) + sizeof(fmi3LsBusCanBaudrate); \ - _op.parameterType = FMI3_LS_BUS_CAN_CONFIG_PARAM_TYPE_CANFD_BAUDRATE; \ - _op.baudrate = (BaudRate); \ - \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length); \ - (BufferInfo)->writePos += _op.header.length; \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Creates a CAN configuration operation for the CAN XL baud rate setting. - * - * This macro can be used to create a CAN configuration operation for the CAN XL baud rate setting. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - * \param[in] BaudRate The baud rate (\ref fmi3LsBusCanBaudrate). - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_CONFIGURATION_CAN_XL_BAUDRATE(BufferInfo, BaudRate) \ - do \ - { \ - fmi3LsBusCanOperationConfiguration _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_CONFIGURATION; \ - _op.header.length = \ - sizeof(fmi3LsBusOperationHeader) + sizeof(fmi3LsBusCanConfigParameterType) + sizeof(fmi3LsBusCanBaudrate); \ - _op.parameterType = FMI3_LS_BUS_CAN_CONFIG_PARAM_TYPE_CANXL_BAUDRATE; \ - _op.baudrate = (BaudRate); \ - \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length); \ - (BufferInfo)->writePos += _op.header.length; \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Creates a CAN configuration operation for the arbitration lost behavior setting. - * - * This macro can be used to create a CAN configuration operation for the arbitration lost behavior setting. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - * \param[in] ArbitrationLostBehavior The arbitration lost behavior (\ref fmi3LsBusCanArbitrationLostBehavior). - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_CONFIGURATION_ARBITRATION_LOST_BEHAVIOR(BufferInfo, ArbitrationLostBehavior) \ - do \ - { \ - fmi3LsBusCanOperationConfiguration _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_CONFIGURATION; \ - _op.header.length = \ - sizeof(fmi3LsBusOperationHeader) + sizeof(fmi3LsBusCanConfigParameterType) + sizeof(fmi3LsBusCanArbitrationLostBehavior); \ - _op.parameterType = FMI3_LS_BUS_CAN_CONFIG_PARAM_TYPE_ARBITRATION_LOST_BEHAVIOR; \ - _op.arbitrationLostBehavior = (ArbitrationLostBehavior); \ - \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length); \ - (BufferInfo)->writePos += _op.header.length; \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Creates a CAN arbitration lost operation. - * - * This macro can be used to create a CAN arbitration lost operation. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - * \param[in] ID CAN message ID (\ref fmi3LsBusCanId). - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_ARBITRATION_LOST(BufferInfo, ID) \ - do \ - { \ - fmi3LsBusCanOperationArbitrationLost _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_ARBITRATION_LOST; \ - _op.header.length = sizeof(fmi3LsBusOperationHeader) + sizeof(fmi3LsBusCanId); \ - _op.id = (ID); \ - \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length); \ - (BufferInfo)->writePos += _op.header.length; \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Creates a CAN bus error operation. - * - * This macro can be used to create a CAN bus error operation. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - * \param[in] ID CAN message ID (\ref fmi3LsBusCanId). - * \param[in] ErrorCode Error Code (\ref fmi3LsBusCanErrorCode). - * \param[in] ErrorFlag Error Flag (\ref fmi3LsBusCanErrorFlag). - * \param[in] IsSender Is Sender (\ref fmi3LsBusCanIsSender). - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_BUS_ERROR(BufferInfo, ID, ErrorCode, ErrorFlag, IsSender) \ - do \ - { \ - fmi3LsBusCanOperationBusError _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_BUS_ERROR; \ - _op.header.length = sizeof(fmi3LsBusOperationHeader) + sizeof(fmi3LsBusCanId) + \ - sizeof(fmi3LsBusCanErrorCode) + sizeof(fmi3LsBusCanErrorFlag) + \ - sizeof(fmi3LsBusCanIsSender); \ - _op.id = (ID); \ - _op.errorCode = (ErrorCode); \ - _op.errorFlag = (ErrorFlag); \ - _op.isSender = (IsSender); \ - \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length); \ - (BufferInfo)->writePos += _op.header.length; \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Creates a CAN status operation. - * - * This macro can be used to create a CAN status operation. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - * \param[in] Status Status Kind (\ref fmi3LsBusCanStatusKind). - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_STATUS(BufferInfo, Status) \ - do \ - { \ - fmi3LsBusCanOperationStatus _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_STATUS; \ - _op.header.length = sizeof(fmi3LsBusOperationHeader) + sizeof(fmi3LsBusCanStatusKind); \ - _op.status = (Status); \ - \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length); \ - (BufferInfo)->writePos += _op.header.length; \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -/** - * \brief Creates a CAN wakeup operation. - * - * This macro can be used to create a CAN wakeup operation. - * The arguments are serialized according to the fmi-ls-bus specification and written to the buffer - * described by the argument 'BufferInfo'. If there is no enough buffer space available, the 'status' - * variable of the argument 'BufferInfo' is set to fmi3False. - * - * \param[in] BufferInfo Pointer to \ref fmi3LsBusUtilBufferInfo. - */ -#define FMI3_LS_BUS_CAN_CREATE_OP_WAKEUP(BufferInfo) \ - do \ - { \ - fmi3LsBusCanOperationWakeup _op; \ - _op.header.type = FMI3_LS_BUS_CAN_OP_WAKEUP; \ - _op.header.length = sizeof(fmi3LsBusOperationHeader); \ - \ - if (_op.header.length <= (fmi3UInt32)((BufferInfo)->end - (BufferInfo)->writePos)) \ - { \ - memcpy((BufferInfo)->writePos, &_op, _op.header.length); \ - (BufferInfo)->writePos += _op.header.length; \ - (BufferInfo)->status = fmi3True; \ - } \ - else \ - { \ - (BufferInfo)->status = fmi3False; \ - } \ - } \ - while (0) - -#ifdef __cplusplus -} /* end of extern "C" { */ -#endif - - -#endif /* fmi3LsBusUtilCan_h */