Skip to content

Commit

Permalink
Merge pull request #24 from pgreenland/padding_byte_value
Browse files Browse the repository at this point in the history
Allow padding byte value to be set
  • Loading branch information
SimonCahill committed Feb 20, 2024
2 parents 34fa61a + 36d4f0f commit 8c25e8c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
###
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions isotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions isotp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

0 comments on commit 8c25e8c

Please sign in to comment.