Skip to content

Commit 083709f

Browse files
Feature: Add Event-Driven Callback Support (#51)
* feat(cb): add support for transmission and receive complete callback * Fixed typo. * Added .clang-format to force styles * Fixed style issues. * Fixed formatting * Fixed and updated formatting. * Fixed language mode * Apparently VS Code doesn't like not having C as the language name.. * Clang format now doesn't indent access modifiers (which caused C structs to be indented with a width of 8). * Minor updates to styling * Reformatted header. * Added feature option to CMakeLists.txt * Added cool file header :) * Added cool file header 😄 * Added cool file header 😄 * Added cool file header 😄 * Changed language to C * Updated workflows * Added cmake target * Updated README * Fixed Makefile * Fixed broken message call. * Bumped up version --------- Co-authored-by: Simon Cahill <s.cahill@procyon-systems.de>
1 parent 6e67da1 commit 083709f

14 files changed

+782
-335
lines changed

.clang-format

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
AlignConsecutiveAssignments: AcrossEmptyLines
2+
AlignConsecutiveBitFields: AcrossEmptyLines
3+
AlignConsecutiveDeclarations: AcrossEmptyLines
4+
AlignConsecutiveShortCaseStatements:
5+
Enabled: true
6+
AcrossComments: true
7+
AcrossEmptyLines: false
8+
AlignCaseColons: false
9+
AlignOperands: true
10+
AlignTrailingComments:
11+
Kind: Always
12+
OverEmptyLines: 1
13+
AllowShortBlocksOnASingleLine: Always
14+
AllowShortCaseLabelsOnASingleLine: true
15+
AllowShortEnumsOnASingleLine: true
16+
AllowShortFunctionsOnASingleLine: true
17+
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
18+
AllowShortLambdasOnASingleLine: All
19+
AllowShortLoopsOnASingleLine: true
20+
AlwaysBreakTemplateDeclarations: Yes
21+
BasedOnStyle: Google
22+
BitFieldColonSpacing: Both
23+
BreakAfterAttributes: Leave
24+
BreakBeforeBinaryOperators: None
25+
BreakBeforeBraces: Attach
26+
BreakBeforeTernaryOperators: true
27+
BreakConstructorInitializers: AfterColon
28+
BreakInheritanceList: AfterColon
29+
ColumnLimit: 160
30+
CompactNamespaces: true
31+
Cpp11BracedListStyle: true
32+
DerivePointerAlignment: false
33+
FixNamespaceComments: true
34+
IncludeBlocks: Preserve
35+
IndentAccessModifiers: false
36+
IndentCaseLabels: true
37+
IndentGotoLabels: false
38+
IndentPPDirectives: BeforeHash
39+
IndentWidth: 4
40+
InsertBraces: true
41+
Language: Cpp
42+
MaxEmptyLinesToKeep: 1
43+
NamespaceIndentation: All
44+
PackConstructorInitializers: NextLine
45+
PointerAlignment: Left
46+
SortIncludes: true
47+
SortUsingDeclarations: true
48+
SpaceAfterCStyleCast: false
49+
SpaceAfterLogicalNot: false
50+
SpaceAfterTemplateKeyword: false
51+
SpaceBeforeAssignmentOperators: true
52+
SpaceBeforeCpp11BracedList: false
53+
SpaceBeforeCtorInitializerColon: false
54+
SpaceBeforeInheritanceColon: false
55+
SpaceBeforeParens: ControlStatements
56+
SpaceBeforeRangeBasedForLoopColon: true
57+
SpaceInEmptyBlock: true
58+
SpaceInEmptyParentheses: false
59+
SpacesBeforeTrailingComments: 1
60+
SpacesInAngles: false
61+
SpacesInContainerLiterals: true
62+
SpacesInCStyleCastParentheses: false
63+
SpacesInParentheses: false
64+
SpacesInSquareBrackets: false
65+
Standard: Auto
66+
TabWidth: 4
67+
UseTab: Never

.github/workflows/build-msvc.yml

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# .github/workflows/windows-msvc-cmake.yml
21
name: Windows MSVC Build
32

43
on:
@@ -8,7 +7,7 @@ on:
87
branches: [ "master" ]
98

109
jobs:
11-
build:
10+
build_standard:
1211
name: Build with MSVC via CMake
1312
runs-on: windows-latest
1413

@@ -28,3 +27,70 @@ jobs:
2827
run: |
2928
cd build
3029
ctest --output-on-failure --timeout 120
30+
31+
build_w_custom_can_arg:
32+
name: Build with MSVC via CMake; enabled user-CAN-arg
33+
runs-on: windows-latest
34+
35+
steps:
36+
- name: Check out repository
37+
uses: actions/checkout@v3
38+
39+
- name: Configure CMake
40+
run: |
41+
cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -Disotpc_ENABLE_CAN_SEND_ARG=ON
42+
43+
- name: Build (Release)
44+
run: cmake --build build --config Release -- /m
45+
46+
- name: Run unit tests
47+
if: always()
48+
run: |
49+
cd build
50+
ctest --output-on-failure --timeout 120
51+
52+
53+
build_standard_w_events:
54+
name: Build with MSVC via CMake
55+
runs-on: windows-latest
56+
57+
steps:
58+
- name: Check out repository
59+
uses: actions/checkout@v3
60+
61+
- name: Configure CMake
62+
run: |
63+
cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -Disotpc_ENABLE_TRANSCEIVE_EVENTS=ON
64+
65+
- name: Build (Release)
66+
run: cmake --build build --config Release -- /m
67+
68+
- name: Run unit tests
69+
if: always()
70+
run: |
71+
cd build
72+
ctest --output-on-failure --timeout 120
73+
74+
75+
76+
build_w_custom_can_arg_w_events:
77+
name: Build with MSVC via CMake; enabled user-CAN-arg
78+
runs-on: windows-latest
79+
80+
steps:
81+
- name: Check out repository
82+
uses: actions/checkout@v3
83+
84+
- name: Configure CMake
85+
run: |
86+
cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -Disotpc_ENABLE_CAN_SEND_ARG=ON -Disotpc_ENABLE_TRANSCEIVE_EVENTS=ON
87+
88+
- name: Build (Release)
89+
run: cmake --build build --config Release -- /m
90+
91+
- name: Run unit tests
92+
if: always()
93+
run: |
94+
cd build
95+
ctest --output-on-failure --timeout 120
96+

.github/workflows/build-w-opt-can-arg.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
BUILD_TYPE: Release
1212

1313
jobs:
14-
build:
14+
build_w_custom_can_arg:
1515
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
1616
# You can convert this to a matrix build if you need cross-platform coverage.
1717
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
@@ -38,3 +38,31 @@ jobs:
3838
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
3939
run: ctest -C ${{env.BUILD_TYPE}}
4040

41+
42+
build_w_custom_can_arg_enable_events:
43+
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
44+
# You can convert this to a matrix build if you need cross-platform coverage.
45+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- uses: actions/checkout@v3
50+
51+
- name: Checkout Submodules
52+
run: git submodule update --init --recursive
53+
54+
- name: Configure CMake
55+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
56+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
57+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Disotp_ENABLE_CAN_SEND_ARG=ON -Disotpc_ENABLE_TRANSCEIVE_EVENTS=ON
58+
59+
- name: Build
60+
# Build your program with the given configuration
61+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
62+
63+
- name: Test
64+
working-directory: ${{github.workspace}}/build
65+
# Execute tests defined by the CMake configuration.
66+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
67+
run: ctest -C ${{env.BUILD_TYPE}}
68+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build with classic Makefile
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
env:
10+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
11+
BUILD_TYPE: Release
12+
13+
jobs:
14+
build:
15+
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
16+
# You can convert this to a matrix build if you need cross-platform coverage.
17+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Checkout Submodules
24+
run: git submodule update --init --recursive
25+
26+
- name: Run Makefile
27+
run: make all
28+
29+
# Check if bin directory was created
30+
- name: Check build
31+
run: |
32+
if [ ! -d "bin" ]; then
33+
echo "Build failed: bin directory not found"
34+
exit 1
35+
fi
36+
37+
if [ ! -l "bin/libisotp.so" ]; then
38+
echo "Build failed: libisotp.so not found"
39+
exit 2
40+
fi
41+

.github/workflows/cmake.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CMake
1+
name: Build with CMake
22

33
on:
44
push:

CMakeLists.txt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ cmake_minimum_required(VERSION 3.10)
33
###
44
# Project definition
55
###
6-
project(isotp LANGUAGES C VERSION 1.5.1 DESCRIPTION "A platform-agnostic ISOTP implementation in C for embedded devices.")
6+
project(isotp LANGUAGES C VERSION 1.6.0 DESCRIPTION "A platform-agnostic ISOTP implementation in C for embedded devices.")
77

88
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)
99
option(isotpc_STATIC_LIBRARY "Compile libisotpc as a static library, instead of a shared library." OFF)
1010
option(isotpc_STATIC_LIBRARY_PIC "Make use of position independent code (PIC), when compiling as a static library (enabled automatically when building shared libraries)." OFF)
1111
option(isotpc_PAD_CAN_FRAMES "Pad CAN frames to their full size." ON)
1212
set(isotpc_CAN_FRAME_PAD_VALUE "0xAA" CACHE STRING "Padding byte value to be used in CAN frames if enabled")
1313
option(isotpc_ENABLE_CAN_SEND_ARG "Adds an extra argument to isotp_user_send_can to better support multiple CAN interfaces." OFF)
14+
option(isotpc_ENABLE_TRANSCEIVE_EVENTS "Enable events/callbacks for transmission and reception complete." OFF)
15+
option(isotpc_ENABLE_TRANSMIT_COMPLETE_CALLBACK "Enable transmit complete callback." ON) # These can be disabled separately, as they are controlled by the main event option
16+
option(isotpc_ENABLE_RECEIVE_COMPLETE_CALLBACK "Enable receive complete callback." ON) # These can be disabled separately, as they are controlled by the main event option
17+
# option(isotpc_ENABLE_TESTING "Enable building of test suite." OFF)
1418

1519
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1620

@@ -61,6 +65,20 @@ if (isotpc_ENABLE_CAN_SEND_ARG)
6165
target_compile_options(isotp PRIVATE -DISO_TP_USER_SEND_CAN_ARG)
6266
endif()
6367

68+
###
69+
# Add support for options added in #51
70+
###
71+
if (isotpc_ENABLE_TRANSCEIVE_EVENTS)
72+
message(STATUS "[isotp-c] Enabling ISOTP events; backwards compatibility may BREAK!")
73+
if (isotpc_ENABLE_TRANSMIT_COMPLETE_CALLBACK)
74+
target_compile_definitions(isotp PRIVATE -DISO_TP_TRANSMIT_COMPLETE_CALLBACK)
75+
endif()
76+
77+
if (isotpc_ENABLE_RECEIVE_COMPLETE_CALLBACK)
78+
target_compile_definitions(isotp PRIVATE -DISO_TP_RECEIVE_COMPLETE_CALLBACK)
79+
endif()
80+
endif()
81+
6482
###
6583
# Check for debug builds
6684
###
@@ -91,3 +109,11 @@ add_library(isotp_c ALIAS isotp)
91109
add_library(simon_cahill::isotp ALIAS isotp)
92110
add_library(simon_cahill::isotpc ALIAS isotp)
93111
add_library(simon_cahill::isotp_c ALIAS isotp)
112+
113+
###
114+
# Enable testing
115+
###
116+
# if (isotpc_ENABLE_TESTING)
117+
# enable_testing()
118+
# add_subdirectory(test)
119+
# endif()

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CFLAGS := -Wall -g -ggdb $(STD)
44
LDFLAGS := -shared
55
BIN := ./bin
66

7-
.PHONY: all clean fPIC no_opt $(BIN)/$(LIB_NAME) $(BIN)/$(LIB_NAME).$(MAJOR_VER) $(BIN)/$(LIB_NAME).$(MAJOR_VER).$(MINOR_VER).$(REVISION) travis
7+
.PHONY: all clean fPIC no_opt $(BIN)/$(LIB_NAME) $(BIN)/$(LIB_NAME).$(MAJOR_VER) $(BIN)/$(LIB_NAME).$(MAJOR_VER).$(MINOR_VER).$(REVISION)
88

99
###
1010
# BEGIN TARGETS
@@ -17,8 +17,6 @@ all: $(BIN)/$(LIB_NAME)
1717
@printf "########## BUILT $^ ##########\n\n\n"
1818

1919
fPIC: CFLAGS += "-fPIC"
20-
21-
travis: fPIC all
2220

2321
###
2422
# Builds all targets w/o optimisations enabled
@@ -45,21 +43,27 @@ $(BIN)/$(LIB_NAME).$(MAJOR_VER): $(BIN)/$(LIB_NAME).$(MAJOR_VER).$(MINOR_VER).$(
4543
-ln -s $^ $@
4644
@printf "Linked $^ --> $@...\n"
4745

48-
$(BIN)/$(LIB_NAME).$(MAJOR_VER).$(MINOR_VER).$(REVISION): libisotp.o
49-
if [ ! -d $(BIN) ]; then mkdir $(BIN); fi;
46+
$(BIN)/$(LIB_NAME).$(MAJOR_VER).$(MINOR_VER).$(REVISION): $(BIN)/libisotp.o
47+
@if [ ! -d $(BIN) ]; then mkdir $(BIN); fi;
5048
${COMP} $^ -o $@ ${LDFLAGS}
5149

5250
###
5351
# Compiles the isotp.c TU to an object file.
5452
###
55-
libisotp.o: isotp.c
53+
$(BIN)/libisotp.o: isotp.c
54+
@mkdir -p $(BIN)
5655
${COMP} -c $^ -o $@ ${CFLAGS} -DISO_TP_FRAME_PADDING
5756

5857
install: all
5958
@printf "Installing $(LIB_NAME) to $(INSTALL_DIR)...\n"
6059
cp $(BIN)/$(LIB_NAME)* $(INSTALL_DIR)
6160
@printf "Library was installed...\n"
6261

62+
cmake:
63+
@mkdir -p build
64+
@cmake -B build -DCMAKE_BUILD_TYPE=Release
65+
@cmake --build build --config Release
66+
6367
###
6468
# END TARGETS
6569
###

0 commit comments

Comments
 (0)