Compare commits

..

12 Commits

Author SHA1 Message Date
Rikus Wessels 81dd2ff511 Autodetect us or ns logfiles 2025-07-12 22:31:03 +02:00
Rikus Wessels f69fccd528 Optional nanosecond timestamp logging 2025-07-12 21:12:19 +02:00
Oliver Hartkopp 6b46063eee cangen: add CAN XL RRS bit generation
Allow to generate Remote Request Substitution bit content.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-06-24 19:48:14 +02:00
Marc Kleine-Budde 93a7b2dfd3
Merge pull request #596 from inomotech-foss/master
Allow more fine-grained control over CMake targets
2025-05-22 10:22:19 +02:00
Simon Berger af09afb734
Update CMakeLists.txt
Co-authored-by: Marc Kleine-Budde <mkl@blackshift.org>
2025-05-22 10:14:39 +02:00
Simon Berger 69efecc428
Allow more fine-grained control over CMake targets 2025-05-21 16:40:24 +00:00
Marc Kleine-Budde 3698814740
Merge pull request #595 from marckleinebudde/can-calc-bittiming-more-data-bitrates
can-calc-bit-timing: common_data_bitrates: add some slower bitrates
2025-05-03 15:02:56 +02:00
Marc Kleine-Budde 6ed0f0ea7f can-calc-bit-timing: common_data_bitrates: add some slower bitrates
There are real world use cases for CAN-FD data bitrates below 1
MBit/s. Add some to the common_data_bitrates array.

Link: https://lore.kernel.org/79BCE02A-D4EC-4362-B0D3-3FE76FB17B78@vpprocess.com
2025-05-03 14:53:54 +02:00
Marc Kleine-Budde 287469245c
Merge pull request #123 from twasilczyk/slcand-android
Don't fail when it wasn't possible to fetch the interface name.
2025-04-06 10:11:38 +02:00
Tomasz Wasilczyk 7a318636e7 slcand: Don't fail when it wasn't possible to fetch the interface name.
On some systems SIOCGIFNAME may fail with ENOTTY, but the actual
slcanX interface gets properly configured. Instead of crashing hard on
such case, let's gracefuly degrade and just not display the interface
name.
2025-04-06 10:03:36 +02:00
Marc Kleine-Budde 7fb81e6779
Merge pull request #593 from yegorich/static-libs
CMakeLists.txt: add an option to control shared library creation
2025-03-12 09:27:14 +01:00
Yegor Yefremov a904183b4e CMakeLists.txt: add an option to control shared library creation
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2025-03-11 18:19:08 +01:00
9 changed files with 205 additions and 155 deletions

View File

@ -19,6 +19,26 @@ endif()
# Add an option to enable treating warnings as errors
option(ENABLE_WERROR "Treat all compiler warnings as errors" OFF)
option(ENABLE_GPS "Enable GPS support" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
# Options for controlling targets. These groups correspond to the README.
option(ENABLE_BASIC_TOOLS "Build basic tools" ON)
option(ENABLE_IP_SERVER "Build tools providing CAN access via IP sockets" ON)
option(ENABLE_GATEWAY "Build in-kernel gateway configuration tools" ON)
option(ENABLE_MEASUREMENT "Build measurement tools" ON)
option(ENABLE_ISOTP "Build isotp tools" ON)
option(ENABLE_LOG_FILE "Build log file converter tools" ON)
option(ENABLE_SLCAN "Build slcan tools" ON)
option(ENABLE_MCP251XFD "Build MCP251XFD tools" ON)
# cmake_dependent_option is only available in CMake 3.22 and later.
if(ANDROID)
set(ENABLE_J1939 OFF)
set(ENABLE_ISOBUSFS OFF)
else()
option(ENABLE_J1939 "Build J1939 tools" ON)
option(ENABLE_ISOBUSFS "Build ISOBUS tools" ON)
endif()
find_package(PkgConfig REQUIRED)
if(ENABLE_GPS)
@ -47,24 +67,64 @@ include_directories(./include)
check_function_exists(fork HAVE_FORK)
set(PROGRAMS_CANLIB
asc2log
canbusload
# List of all programs to be built.
# Each program is expected to have a corresponding source file with the same name.
set(PROGRAMS)
# List of programs to link against can.
set(PROGRAMS_CANLIB)
# List of programs to link against j1939 and can.
set(PROGRAMS_J1939)
if(ENABLE_BASIC_TOOLS)
list(APPEND PROGRAMS cansniffer)
list(APPEND PROGRAMS_CANLIB
candump
cangen
canplayer
cansend
cangen
cansequence
log2asc
log2long
slcanpty
)
endif()
if(HAVE_FORK)
if(ENABLE_IP_SERVER AND HAVE_FORK)
list(APPEND PROGRAMS bcmserver)
list(APPEND PROGRAMS_CANLIB canlogserver)
endif()
set(PROGRAMS_J1939
if(ENABLE_GATEWAY)
list(APPEND PROGRAMS cangw)
endif()
if(ENABLE_MEASUREMENT)
list(APPEND PROGRAMS
canfdtest
canerrsim
)
list(APPEND PROGRAMS_CANLIB canbusload)
add_executable(can-calc-bit-timing
calc-bit-timing/can-calc-bit-timing.c
)
install(TARGETS can-calc-bit-timing DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(ENABLE_ISOTP)
list(APPEND PROGRAMS
isotpdump
isotpperf
isotprecv
isotpsend
isotpsniffer
isotptun
)
if(HAVE_FORK)
list(APPEND PROGRAMS isotpserver)
endif()
endif()
if(ENABLE_J1939)
list(APPEND PROGRAMS_J1939
j1939acd
j1939cat
j1939spy
@ -72,78 +132,46 @@ set(PROGRAMS_J1939
testj1939
)
set(PROGRAMS_J1939_TIMEDATE
j1939-timedate-srv
j1939-timedate-cli
add_executable(j1939-timedate-cli
j1939_timedate/j1939_timedate_cli.c
)
set(PROGRAMS_J1939_VEHICLE_POSITION
j1939-vehicle-position-srv
target_link_libraries(j1939-timedate-cli
PRIVATE can j1939
)
install(TARGETS j1939-timedate-cli DESTINATION ${CMAKE_INSTALL_BINDIR})
set(PROGRAMS_ISOBUSFS
isobusfs-srv
isobusfs-cli
add_executable(j1939-timedate-srv
j1939_timedate/j1939_timedate_srv.c
)
set(PROGRAMS
${PROGRAMS_CANLIB}
canerrsim
canfdtest
cangw
cansniffer
isotpdump
isotpperf
isotprecv
isotpsend
isotpsniffer
isotptun
slcan_attach
slcand
target_link_libraries(j1939-timedate-srv
PRIVATE can j1939
)
if(HAVE_FORK)
list(APPEND PROGRAMS bcmserver)
list(APPEND PROGRAMS isotpserver)
install(TARGETS j1939-timedate-srv DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
add_executable(can-calc-bit-timing
calc-bit-timing/can-calc-bit-timing.c
if(ENABLE_J1939 AND ENABLE_GPS)
add_executable(j1939-vehicle-position-srv
j1939_vehicle_position/j1939_vehicle_position_srv.c
)
add_executable(mcp251xfd-dump
mcp251xfd/mcp251xfd-dev-coredump.c
mcp251xfd/mcp251xfd-dump.c
mcp251xfd/mcp251xfd-main.c
mcp251xfd/mcp251xfd-regmap.c
target_link_libraries(j1939-vehicle-position-srv
PRIVATE can j1939 ${GPS_LIBRARIES}
)
install(TARGETS j1939-vehicle-position-srv DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(NOT ANDROID)
list(APPEND PROGRAMS ${PROGRAMS_J1939})
add_library(j1939 STATIC
libj1939.c
)
target_link_libraries(j1939
PRIVATE can
)
add_library(isobusfs SHARED
if(ENABLE_ISOBUSFS)
add_library(isobusfs EXCLUDE_FROM_ALL
isobusfs/isobusfs_cmn.c
isobusfs/isobusfs_cmn_dh.c
)
set(PUBLIC_HEADER_ISOBUSFS
isobusfs/isobusfs_cmn.h
isobusfs/isobusfs_cmn_cm.h
)
set_target_properties(isobusfs PROPERTIES
PUBLIC_HEADER "${PUBLIC_HEADER_ISOBUSFS}"
SOVERSION 0
)
install(TARGETS isobusfs
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
@ -157,10 +185,10 @@ if(NOT ANDROID)
isobusfs/isobusfs_cli_selftests.c
isobusfs/isobusfs_cli_int.c
)
target_link_libraries(isobusfs-cli
PRIVATE isobusfs can j1939
)
install(TARGETS isobusfs-cli DESTINATION ${CMAKE_INSTALL_BINDIR})
add_executable(isobusfs-srv
isobusfs/isobusfs_srv.c
@ -171,66 +199,55 @@ if(NOT ANDROID)
isobusfs/isobusfs_srv_fh.c
isobusfs/isobusfs_srv_vh.c
)
target_link_libraries(isobusfs-srv
PRIVATE isobusfs can j1939
)
install(TARGETS
isobusfs-cli
isobusfs-srv
DESTINATION ${CMAKE_INSTALL_BINDIR})
set(PUBLIC_HEADER_j1939_TIMEDATE
j1939_timedate/j1939_timedate_cmn.h
)
add_executable(j1939-timedate-cli
j1939_timedate/j1939_timedate_cli.c
)
target_link_libraries(j1939-timedate-cli
PRIVATE can j1939
)
add_executable(j1939-timedate-srv
j1939_timedate/j1939_timedate_srv.c
)
target_link_libraries(j1939-timedate-srv
PRIVATE can j1939
)
install(TARGETS
j1939-timedate-cli
j1939-timedate-srv
DESTINATION ${CMAKE_INSTALL_BINDIR})
if(ENABLE_GPS)
set(PUBLIC_HEADER_J1939_VEHICLE_POSITION
j1939_vehicle_position/j1939_vehicle_position_cmn.h
)
add_executable(j1939-vehicle-position-srv
j1939_vehicle_position/j1939_vehicle_position_srv.c
)
target_link_libraries(j1939-vehicle-position-srv
PRIVATE can j1939 ${GPS_LIBRARIES}
)
install(TARGETS
j1939-vehicle-position-srv
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS isobusfs-srv DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(ENABLE_LOG_FILE)
list(APPEND PROGRAMS_CANLIB
asc2log
log2asc
log2long
)
endif()
add_library(can STATIC
if(ENABLE_SLCAN)
list(APPEND PROGRAMS
slcan_attach
slcand
)
list(APPEND PROGRAMS_CANLIB slcanpty)
endif()
if(ENABLE_MCP251XFD)
add_executable(mcp251xfd-dump
mcp251xfd/mcp251xfd-dev-coredump.c
mcp251xfd/mcp251xfd-dump.c
mcp251xfd/mcp251xfd-main.c
mcp251xfd/mcp251xfd-regmap.c
)
install(TARGETS mcp251xfd-dump DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
list(APPEND PROGRAMS
${PROGRAMS_CANLIB}
${PROGRAMS_J1939}
)
add_library(can STATIC EXCLUDE_FROM_ALL
lib.c
canframelen.c
)
add_library(j1939 STATIC EXCLUDE_FROM_ALL
libj1939.c
)
target_link_libraries(j1939
PRIVATE can
)
foreach(name ${PROGRAMS})
add_executable(${name} ${name}.c)
@ -247,12 +264,6 @@ foreach(name ${PROGRAMS})
install(TARGETS ${name} DESTINATION ${CMAKE_INSTALL_BINDIR})
endforeach()
install(TARGETS
can-calc-bit-timing
mcp251xfd-dump
DESTINATION ${CMAKE_INSTALL_BINDIR}
)
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/cmake/make_uninstall.cmake"
COMMENT "Add uninstall target"

View File

@ -50,6 +50,10 @@ subsystem (aka SocketCAN):
Follow the link to see examples on how this tools can be used:
[Kickstart guide to can-j1939 on linux](https://github.com/linux-can/can-utils/blob/master/can-j1939-kickstart.md)
#### ISOBus File server tools
* isobusfs-cli : ISOBus file client
* isobusfs-srv : ISOBus file server
#### Log file converters
* asc2log : convert ASC logfile to compact CAN frame logfile
* log2asc : convert compact CAN frame logfile to ASC logfile

View File

@ -1121,6 +1121,11 @@ static const unsigned int common_data_bitrates[] = {
4000000,
2000000,
1000000,
800000,
500000,
250000,
125000,
100000,
0
};

View File

@ -221,7 +221,7 @@ static int idx2dindex(int ifidx, int socket)
return i;
}
static int sprint_timestamp(char *ts_buffer, const char timestamp, unsigned char use_ns,
static int sprint_timestamp(char *ts_buffer, const char timestamp, const char use_ns,
const struct timespec *ts, struct timespec *const last_ts)
{
int numchars = 0;
@ -857,11 +857,9 @@ int main(int argc, char **argv)
/* build common log format output */
if ((log) || ((logfrmt) && (silent == SILENT_OFF))) {
alen = sprint_timestamp(afrbuf, logtimestamp, use_ns,
&ts, &last_ts);
alen = sprint_timestamp(afrbuf, logtimestamp, use_ns, &ts, &last_ts);
alen += sprintf(afrbuf + alen, "%*s ",
max_devname_len, devname[idx]);
alen += sprintf(afrbuf + alen, "%*s ", max_devname_len, devname[idx]);
alen += snprintf_canframe(afrbuf + alen, sizeof(afrbuf) - alen, &cu, 0);
}

View File

@ -987,12 +987,12 @@ int main(int argc, char **argv)
rnd = random();
if (xl_flags_mode == MODE_RANDOM) {
cu.xl.flags = rnd & CANXL_SEC;
cu.xl.flags = rnd & (CANXL_SEC | CANXL_RRS);
} else if (xl_flags_mode == MODE_FIX) {
cu.xl.flags = xl_flags;
} else if (xl_flags_mode == MODE_INCREMENT) {
xl_flags ^= CANXL_SEC;
cu.xl.flags = (xl_flags & CANXL_SEC);
xl_flags++;
cu.xl.flags = (xl_flags & (CANXL_SEC | CANXL_RRS));
}
/* mark CAN XL frame */

View File

@ -452,14 +452,20 @@ int main(int argc, char **argv)
return 1;
}
log_tv.tv_sec = sec;
log_tv.tv_usec = usec;
/*
* ensure the fractions of seconds are 6 decimal places long to catch
* ensure the fractions of seconds are 6 or 9 decimal places long to catch
* 3rd party or handcrafted logfiles that treat the timestamp as float
*/
if (strchr(buf, ')') - strchr(buf, '.') != 7) {
fprintf(stderr, "timestamp format in logfile requires 6 decimal places\n");
switch (strchr(buf, ')') - strchr(buf, '.')) {
case 7: //6
log_tv.tv_usec = usec;
break;
case 10: //9
log_tv.tv_usec = usec / 1000;
break;
default:
fprintf(stderr, "timestamp format in logfile requires 6 or 9 decimal places\n");
return 1;
}
@ -541,19 +547,25 @@ int main(int argc, char **argv)
break;
}
if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, device, afrbuf) != 4) {
if (sscanf(buf, "(%llu.%llu) %21s %6299s", &sec, &usec, device, afrbuf) != 4) {
fprintf(stderr, "incorrect line format in logfile\n");
return 1;
}
log_tv.tv_sec = sec;
log_tv.tv_usec = usec;
/*
* ensure the fractions of seconds are 6 decimal places long to catch
* ensure the fractions of seconds are 6 or 9 decimal places long to catch
* 3rd party or handcrafted logfiles that treat the timestamp as float
*/
if (strchr(buf, ')') - strchr(buf, '.') != 7) {
fprintf(stderr, "timestamp format in logfile requires 6 decimal places\n");
switch (strchr(buf, ')') - strchr(buf, '.')) {
case 7: //6
log_tv.tv_usec = usec;
break;
case 10: //9
log_tv.tv_usec = usec / 1000;
break;
default:
fprintf(stderr, "timestamp format in logfile requires 6 or 9 decimal places\n");
return 1;
}

View File

@ -407,7 +407,22 @@ int main(int argc, char **argv)
}
}
tv.tv_sec = sec;
/*
* ensure the fractions of seconds are 6 or 9 decimal places long to catch
* 3rd party or handcrafted logfiles that treat the timestamp as float
*/
switch (strchr(buf, ')') - strchr(buf, '.')) {
case 7: //6
tv.tv_usec = usec;
break;
case 10: //9
tv.tv_usec = usec / 1000;
break;
default:
fprintf(stderr, "timestamp format in logfile requires 6 or 9 decimal places\n");
return 1;
}
if (print_banner) { /* print banner */
print_banner = 0;

View File

@ -51,7 +51,7 @@
#include "lib.h"
#define DEVSZ 22
#define TIMESZ 22 /* sizeof("(1345212884.318850) ") */
#define TIMESZ 25 /* sizeof("(1345212884.318850123) ") */
#define BUFSZ (DEVSZ + AFRSZ + TIMESZ)
/* adapt sscanf() functions below on error */
@ -61,7 +61,7 @@
#if (DEVSZ != 22)
#error "DEVSZ value does not fit sscanf restrictions!"
#endif
#if (TIMESZ != 22)
#if (TIMESZ != 25)
#error "TIMESZ value does not fit sscanf restrictions!"
#endif
@ -78,7 +78,7 @@ int main(void)
return 1;
}
if (sscanf(buf, "%21s %21s %6299s", timestamp, device, afrbuf) != 3)
if (sscanf(buf, "%24s %21s %6299s", timestamp, device, afrbuf) != 3)
return 1;
mtu = parse_canframe(afrbuf, &cu);

View File

@ -370,8 +370,13 @@ int main(int argc, char *argv[])
/* retrieve the name of the created CAN netdevice */
if (ioctl(fd, SIOCGIFNAME, ifr.ifr_name) < 0) {
if (name) {
perror("ioctl SIOCGIFNAME");
exit(EXIT_FAILURE);
} else {
/* Graceful degradation: we only needed the name for display. */
snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "<unknown>");
}
}
syslogger(LOG_NOTICE, "attached TTY %s to netdevice %s\n", ttypath, ifr.ifr_name);