Compare commits

..

4 Commits

Author SHA1 Message Date
Oleksij Rempel aca13487c6
Merge 2638b3965c into 2b8c7c5f4b 2025-02-16 22:12:06 +00:00
Oleksij Rempel 2638b3965c j1939-vehicle-position-srv: Introduce J1939 and NMEA 2000 Vehicle Position Server
This patch adds `j1939-vehicle-position-srv`, a server for sending
vehicle position data over CAN using J1939 or NMEA 2000 protocols. It
retrieves GPS data from gpsd or simulates data if gpsd is unavailable.
By default, it operates in J1939 profile but can switch to NMEA 2000
with the `-p nmea2000` option.

Usage Examples:
1. With gpsd:
   j1939acd -r 64-95 -c /tmp/1122334455667789.jacd 1122334455667789 vcan0 &
   j1939-vehicle-position-srv -i vcan0 -n 0x1122334455667789

2. In simulation mode without gpsd:
   j1939-vehicle-position-srv -i vcan0 -s -p nmea2000

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
2024-12-29 12:03:18 +01:00
Marc Kleine-Budde 93e7b02236 github-actions: install libgps-dev 2024-12-28 11:26:20 +01:00
Oleksij Rempel 590b8df5a8 libj1939: Add function to connect a socket
Introduce `libj1939_connect_socket` function to handle socket
connections.

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
2024-12-28 11:08:09 +01:00
3 changed files with 24 additions and 31 deletions

View File

@ -50,21 +50,21 @@ jobs:
env: env:
cc: gcc cc: gcc
run: | run: |
podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=${cc} -DENABLE_WERROR=ON -DENABLE_GPS=ON -B build-${cc} podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=${cc} -DENABLE_WERROR=ON -B build-${cc}
podman exec -i stable cmake --build build-${cc} podman exec -i stable cmake --build build-${cc}
- name: Configure & Build with clang - name: Configure & Build with clang
env: env:
cc: clang cc: clang
run: | run: |
podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=${cc} -DENABLE_WERROR=ON -DENABLE_GPS=ON -B build-${cc} podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=${cc} -DENABLE_WERROR=ON -B build-${cc}
podman exec -i stable cmake --build build-${cc} podman exec -i stable cmake --build build-${cc}
- name: Configure & Build with arm-linux-gnueabihf-gcc - name: Configure & Build with arm-linux-gnueabihf-gcc
env: env:
toolchain: arm-linux-gnueabihf-gcc toolchain: arm-linux-gnueabihf-gcc
run: | run: |
podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/${toolchain}.cmake -DENABLE_WERROR=ON -DENABLE_GPS=ON -B build-${toolchain} podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/${toolchain}.cmake -DENABLE_WERROR=ON -B build-${toolchain}
podman exec -i stable cmake --build build-${toolchain} podman exec -i stable cmake --build build-${toolchain}
- name: Configure & Build with arm-linux-gnueabihf-clang - name: Configure & Build with arm-linux-gnueabihf-clang
@ -73,14 +73,14 @@ jobs:
env: env:
toolchain: arm-linux-gnueabihf-clang toolchain: arm-linux-gnueabihf-clang
run: | run: |
podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/${toolchain}.cmake -DENABLE_WERROR=ON -DENABLE_GPS=ON -B build-${toolchain} podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/${toolchain}.cmake -DENABLE_WERROR=ON -B build-${toolchain}
podman exec -i stable cmake --build build-${toolchain} podman exec -i stable cmake --build build-${toolchain}
- name: Configure & Build with aarch64-linux-gnu-gcc - name: Configure & Build with aarch64-linux-gnu-gcc
env: env:
toolchain: aarch64-linux-gnu-gcc toolchain: aarch64-linux-gnu-gcc
run: | run: |
podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/${toolchain}.cmake -DENABLE_WERROR=ON -DENABLE_GPS=ON -B build-${toolchain} podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/${toolchain}.cmake -DENABLE_WERROR=ON -B build-${toolchain}
podman exec -i stable cmake --build build-${toolchain} podman exec -i stable cmake --build build-${toolchain}
- name: Configure & Build with aarch64-linux-gnu-clang - name: Configure & Build with aarch64-linux-gnu-clang
@ -89,7 +89,7 @@ jobs:
env: env:
toolchain: aarch64-linux-gnu-clang toolchain: aarch64-linux-gnu-clang
run: | run: |
podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/${toolchain}.cmake -DENABLE_WERROR=ON -DENABLE_GPS=ON -B build-${toolchain} podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/${toolchain}.cmake -DENABLE_WERROR=ON -B build-${toolchain}
podman exec -i stable cmake --build build-${toolchain} podman exec -i stable cmake --build build-${toolchain}
- name: Configure & Build with mips-linux-gnu-gcc - name: Configure & Build with mips-linux-gnu-gcc

1
.gitignore vendored
View File

@ -6,6 +6,7 @@
.ccls-cache .ccls-cache
CMakeCache.txt CMakeCache.txt
CMakeFiles/ CMakeFiles/
Makefile
cmake_install.cmake cmake_install.cmake
compile_commands.json compile_commands.json
tags tags

View File

@ -4,9 +4,9 @@ project(can-utils LANGUAGES C)
message(STATUS "CMake version: ${CMAKE_VERSION}") message(STATUS "CMake version: ${CMAKE_VERSION}")
include(CheckFunctionExists) include (CheckFunctionExists)
include(CheckSymbolExists) include (CheckSymbolExists)
include(GNUInstallDirs) include (GNUInstallDirs)
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)
@ -14,12 +14,6 @@ endif()
# Add an option to enable treating warnings as errors # Add an option to enable treating warnings as errors
option(ENABLE_WERROR "Treat all compiler warnings as errors" OFF) option(ENABLE_WERROR "Treat all compiler warnings as errors" OFF)
option(ENABLE_GPS "Enable GPS support" OFF)
find_package(PkgConfig REQUIRED)
if(ENABLE_GPS)
pkg_check_modules(GPS REQUIRED libgps)
endif()
if(ENABLE_WERROR) if(ENABLE_WERROR)
add_compile_options(-Werror) add_compile_options(-Werror)
@ -38,8 +32,8 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCLOCK_TAI=11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSO_TXTIME=61") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSO_TXTIME=61")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSCM_TXTIME=SO_TXTIME") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSCM_TXTIME=SO_TXTIME")
include_directories(.) include_directories (.)
include_directories(./include) include_directories (./include)
check_function_exists(fork HAVE_FORK) check_function_exists(fork HAVE_FORK)
@ -201,23 +195,21 @@ if(NOT ANDROID)
j1939-timedate-srv j1939-timedate-srv
DESTINATION ${CMAKE_INSTALL_BINDIR}) DESTINATION ${CMAKE_INSTALL_BINDIR})
if(ENABLE_GPS) set(PUBLIC_HEADER_J1939_VEHICLE_POSITION
set(PUBLIC_HEADER_J1939_VEHICLE_POSITION j1939_vehicle_position/j1939_vehicle_position_cmn.h
j1939_vehicle_position/j1939_vehicle_position_cmn.h )
)
add_executable(j1939-vehicle-position-srv add_executable(j1939-vehicle-position-srv
j1939_vehicle_position/j1939_vehicle_position_srv.c j1939_vehicle_position/j1939_vehicle_position_srv.c
) )
target_link_libraries(j1939-vehicle-position-srv target_link_libraries(j1939-vehicle-position-srv
PRIVATE can j1939 ${GPS_LIBRARIES} PRIVATE can j1939 gps
) )
install(TARGETS install(TARGETS
j1939-vehicle-position-srv j1939-vehicle-position-srv
DESTINATION ${CMAKE_INSTALL_BINDIR}) DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
endif() endif()