diff --git a/CMakeLists.txt b/CMakeLists.txt index cd13284..3324654 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,8 @@ project(isotp LANGUAGES C VERSION 1.0.1 DESCRIPTION "A platform-agnostic ISOTP i option(isotpc_USE_INCLUDE_DIR "Copy header files to separate include directory in current binary dir for better separation of header files to combat potential naming conflicts." OFF) option(isotpc_STATIC_LIBRARY "Compile libisotpc as a static library, instead of a shared library." OFF) +option(isotpc_PAD_CAN_FRAMES "Pad CAN frames to their full size." ON) +set(isotpc_CAN_FRAME_PAD_VALUE "0xAA" CACHE STRING "Padding byte value to be used in CAN frames if enabled") if (isotpc_STATIC_LIBRARY) add_library(isotp STATIC ${CMAKE_CURRENT_SOURCE_DIR}/isotp.c) @@ -25,6 +27,13 @@ target_compile_options( -Wno-unknown-pragmas # ignore unknown pragmas, such as #pragma region ) +### +# Provide padding configuration +### +if (isotpc_PAD_CAN_FRAMES) + target_compile_definitions(isotp PRIVATE -DISO_TP_FRAME_PADDING -DISO_TP_FRAME_PADDING_VALUE=${isotpc_CAN_FRAME_PAD_VALUE}) +endif() + ### # Check for debug builds ### diff --git a/Makefile b/Makefile index bd65906..35bdf28 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ $(BIN)/$(LIB_NAME).$(MAJOR_VER).$(MINOR_VER).$(REVISION): libisotp.o # Compiles the isotp.c TU to an object file. ### libisotp.o: isotp.c - ${COMP} -c $^ -o $@ ${CFLAGS} + ${COMP} -c $^ -o $@ ${CFLAGS} -DISO_TP_FRAME_PADDING install: all @printf "Installing $(LIB_NAME) to $(INSTALL_DIR)...\n" diff --git a/isotp.c b/isotp.c index b1f4807..1936b21 100644 --- a/isotp.c +++ b/isotp.c @@ -39,9 +39,9 @@ static int isotp_send_flow_control(IsoTpLink* link, uint8_t flow_status, uint8_t /* send message */ #ifdef ISO_TP_FRAME_PADDING - (void) memset(message.as.flow_control.reserve, 0, sizeof(message.as.flow_control.reserve)); + (void) memset(message.as.flow_control.reserve, ISO_TP_FRAME_PADDING_VALUE, sizeof(message.as.flow_control.reserve)); ret = isotp_user_send_can(link->send_arbitration_id, message.as.data_array.ptr, sizeof(message)); -#else +#else ret = isotp_user_send_can(link->send_arbitration_id, message.as.data_array.ptr, 3); @@ -65,7 +65,7 @@ static int isotp_send_single_frame(IsoTpLink* link, uint32_t id) { /* send message */ #ifdef ISO_TP_FRAME_PADDING - (void) memset(message.as.single_frame.data + link->send_size, 0, sizeof(message.as.single_frame.data) - link->send_size); + (void) memset(message.as.single_frame.data + link->send_size, ISO_TP_FRAME_PADDING_VALUE, sizeof(message.as.single_frame.data) - link->send_size); ret = isotp_user_send_can(id, message.as.data_array.ptr, sizeof(message)); #else ret = isotp_user_send_can(id, @@ -120,7 +120,7 @@ static int isotp_send_consecutive_frame(IsoTpLink* link) { /* send message */ #ifdef ISO_TP_FRAME_PADDING - (void) memset(message.as.consecutive_frame.data + data_length, 0, sizeof(message.as.consecutive_frame.data) - data_length); + (void) memset(message.as.consecutive_frame.data + data_length, ISO_TP_FRAME_PADDING_VALUE, sizeof(message.as.consecutive_frame.data) - data_length); ret = isotp_user_send_can(link->send_arbitration_id, message.as.data_array.ptr, sizeof(message)); #else ret = isotp_user_send_can(link->send_arbitration_id, diff --git a/isotp_config.h b/isotp_config.h index 637682b..cda4bbb 100644 --- a/isotp_config.h +++ b/isotp_config.h @@ -2,7 +2,7 @@ #define __ISOTP_CONFIG__ /* Max number of messages the receiver can receive at one time, this value - * is affectied by can driver queue length + * is affected by can driver queue length */ #define ISO_TP_DEFAULT_BLOCK_SIZE 8 @@ -23,7 +23,13 @@ /* Private: Determines if by default, padding is added to ISO-TP message frames. */ -#define ISO_TP_FRAME_PADDING +//#define ISO_TP_FRAME_PADDING 0xAA + +/* Private: Value to use when padding frames if enabled by ISO_TP_FRAME_PADDING + */ +#ifndef ISO_TP_FRAME_PADDING_VALUE +#define ISO_TP_FRAME_PADDING_VALUE 0xAA +#endif #endif