Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ _build
# Coverage info file
lcov.info
test_coverage/

# cmake cache.
.cache/
build/
build-*/
config.h
67 changes: 67 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
cmake_minimum_required(VERSION 3.11)

# Detect ESP-IDF build
if(ESP_PLATFORM OR DEFINED ENV{IDF_PATH})
file(GLOB_RECURSE SRC src/*.cpp)
idf_component_register(
SRCS ${SRC}
INCLUDE_DIRS src
REQUIRES esp_timer
)
else()
include(FetchContent)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

project(DCCEXProtocol LANGUAGES CXX)

option(DCCEX_BUILD_TESTS "Build native GoogleTest test target" ON)

file(GLOB_RECURSE SRC src/*.cpp)
add_library(DCCEXProtocol STATIC ${SRC})
add_library(DCCEX::Protocol ALIAS DCCEXProtocol)

# Stuck at C++11
target_compile_options(DCCEXProtocol PRIVATE -std=c++11)

# Don't bother users with warnings by setting 'SYSTEM'
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
target_include_directories(DCCEXProtocol PUBLIC src)
else()
target_include_directories(DCCEXProtocol SYSTEM PUBLIC src)
endif()

foreach(FILE ${SRC})
message(${FILE})
endforeach()

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SRC})

if(DCCEX_BUILD_TESTS)
enable_testing()

FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip
DOWNLOAD_EXTRACT_TIMESTAMP true
)
FetchContent_MakeAvailable(googletest)

file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS test/*.cpp)
add_executable(DCCEXProtocolTests ${TEST_SOURCES})

target_compile_definitions(DCCEXProtocolTests PRIVATE NATIVE_TESTING)
target_include_directories(DCCEXProtocolTests PRIVATE test/mocks test/setup)
target_link_libraries(DCCEXProtocolTests PRIVATE DCCEXProtocol GTest::gtest GTest::gmock)

include(GoogleTest)
gtest_discover_tests(DCCEXProtocolTests)

add_custom_target(check
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
DEPENDS DCCEXProtocolTests
USES_TERMINAL
)

add_custom_target(run-tests DEPENDS check)
endif()
endif()
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@ The implementation of this library is tested on ESP32 based devices running the

There has also been limited testing on STM32F103C8 Bluepill.

## Cross-platform millis support

The library now uses a platform-neutral time macro internally. By default it uses Arduino millis(), and it can be overridden for non-Arduino targets without changing library source code.

Built-in defaults are provided in src/DCCMillisWrappers.h for:

- Arduino (millis)
- ESP-IDF (esp_timer_get_time()/1000)
- Pico SDK (to_ms_since_boot(get_absolute_time()))

If your target is not covered, define DCCEX_MILLIS() in your build flags or before including DCCEXProtocol.h.

Examples:

- Arduino: no change required.
- ESP-IDF:

add_compile_definitions(DCCEX_MILLIS()=dccex_esp_idf_millis())

- Pico SDK:

add_compile_definitions(DCCEX_MILLIS()=dccex_pico_millis())

- Custom platform function:

-DDCCEX_MILLIS()=my_platform_millis()

## Basic Design Principles

First of all, this library implements the DCC-EX Native protocol in a non-blocking fashion. After creating a DCCEXProtocol object, you set up various necessities such as the network connection and a debug console (see [Dependency Injection][depinj]).
Expand Down
24 changes: 24 additions & 0 deletions examples/DCCEXProtocol_Basic/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; PlatformIO config for the DCCEXProtocol Basic example
;
; Usage from this folder:
; pio run
; pio run -t upload
; pio device monitor

[platformio]
default_envs = esp32dev
src_dir = .

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Pick your serial port if auto-detection does not work
; upload_port = /dev/ttyUSB0

monitor_speed = 115200
upload_speed = 921600

; Make the library in the repository root available to this example
lib_extra_dirs = ../../
24 changes: 24 additions & 0 deletions examples/DCCEXProtocol_CSConsist_Control/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; PlatformIO config for the DCCEXProtocol Basic example
;
; Usage from this folder:
; pio run
; pio run -t upload
; pio device monitor

[platformio]
default_envs = esp32dev
src_dir = .

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Pick your serial port if auto-detection does not work
; upload_port = /dev/ttyUSB0

monitor_speed = 115200
upload_speed = 921600

; Make the library in the repository root available to this example
lib_extra_dirs = ../../
24 changes: 24 additions & 0 deletions examples/DCCEXProtocol_Consist_Control/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; PlatformIO config for the DCCEXProtocol Basic example
;
; Usage from this folder:
; pio run
; pio run -t upload
; pio device monitor

[platformio]
default_envs = esp32dev
src_dir = .

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Pick your serial port if auto-detection does not work
; upload_port = /dev/ttyUSB0

monitor_speed = 115200
upload_speed = 921600

; Make the library in the repository root available to this example
lib_extra_dirs = ../../
24 changes: 24 additions & 0 deletions examples/DCCEXProtocol_Delegate/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; PlatformIO config for the DCCEXProtocol Basic example
;
; Usage from this folder:
; pio run
; pio run -t upload
; pio device monitor

[platformio]
default_envs = esp32dev
src_dir = .

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Pick your serial port if auto-detection does not work
; upload_port = /dev/ttyUSB0

monitor_speed = 115200
upload_speed = 921600

; Make the library in the repository root available to this example
lib_extra_dirs = ../../
24 changes: 24 additions & 0 deletions examples/DCCEXProtocol_Loco_Control/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; PlatformIO config for the DCCEXProtocol Basic example
;
; Usage from this folder:
; pio run
; pio run -t upload
; pio device monitor

[platformio]
default_envs = esp32dev
src_dir = .

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Pick your serial port if auto-detection does not work
; upload_port = /dev/ttyUSB0

monitor_speed = 115200
upload_speed = 921600

; Make the library in the repository root available to this example
lib_extra_dirs = ../../
24 changes: 24 additions & 0 deletions examples/DCCEXProtocol_Multi_Throttle_Control/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; PlatformIO config for the DCCEXProtocol Basic example
;
; Usage from this folder:
; pio run
; pio run -t upload
; pio device monitor

[platformio]
default_envs = esp32dev
src_dir = .

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Pick your serial port if auto-detection does not work
; upload_port = /dev/ttyUSB0

monitor_speed = 115200
upload_speed = 921600

; Make the library in the repository root available to this example
lib_extra_dirs = ../../
24 changes: 24 additions & 0 deletions examples/DCCEXProtocol_Roster_etc/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; PlatformIO config for the DCCEXProtocol Basic example
;
; Usage from this folder:
; pio run
; pio run -t upload
; pio device monitor

[platformio]
default_envs = esp32dev
src_dir = .

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Pick your serial port if auto-detection does not work
; upload_port = /dev/ttyUSB0

monitor_speed = 115200
upload_speed = 921600

; Make the library in the repository root available to this example
lib_extra_dirs = ../../
24 changes: 24 additions & 0 deletions examples/DCCEXProtocol_SSID/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; PlatformIO config for the DCCEXProtocol Basic example
;
; Usage from this folder:
; pio run
; pio run -t upload
; pio device monitor

[platformio]
default_envs = esp32dev
src_dir = .

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Pick your serial port if auto-detection does not work
; upload_port = /dev/ttyUSB0

monitor_speed = 115200
upload_speed = 921600

; Make the library in the repository root available to this example
lib_extra_dirs = ../../
24 changes: 24 additions & 0 deletions examples/DCCEXProtocol_Serial/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; PlatformIO config for the DCCEXProtocol Basic example
;
; Usage from this folder:
; pio run
; pio run -t upload
; pio device monitor

[platformio]
default_envs = esp32dev
src_dir = .

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Pick your serial port if auto-detection does not work
; upload_port = /dev/ttyUSB0

monitor_speed = 115200
upload_speed = 921600

; Make the library in the repository root available to this example
lib_extra_dirs = ../../
24 changes: 24 additions & 0 deletions examples/DCCEXProtocol_Track_type/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; PlatformIO config for the DCCEXProtocol Basic example
;
; Usage from this folder:
; pio run
; pio run -t upload
; pio device monitor

[platformio]
default_envs = esp32dev
src_dir = .

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Pick your serial port if auto-detection does not work
; upload_port = /dev/ttyUSB0

monitor_speed = 115200
upload_speed = 921600

; Make the library in the repository root available to this example
lib_extra_dirs = ../../
24 changes: 24 additions & 0 deletions examples/DCCEXProtocol_Turnout_Control/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; PlatformIO config for the DCCEXProtocol Basic example
;
; Usage from this folder:
; pio run
; pio run -t upload
; pio device monitor

[platformio]
default_envs = esp32dev
src_dir = .

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Pick your serial port if auto-detection does not work
; upload_port = /dev/ttyUSB0

monitor_speed = 115200
upload_speed = 921600

; Make the library in the repository root available to this example
lib_extra_dirs = ../../
Loading
Loading