From 4e2b20ad5d708bd6ecc56709ac46400a9d090bc9 Mon Sep 17 00:00:00 2001 From: Uwe McVogt Date: Fri, 28 Feb 2025 22:37:49 +0100 Subject: [PATCH 1/4] Rearrange folder layout Relates to [MACCAN-231] --- Utilities/Makefile | 12 +-- Utilities/build_no.sh | 4 +- Utilities/can_moni/Makefile | 33 +++---- Utilities/can_moni/main.c | 79 ++++++++++------- Utilities/can_test/Makefile | 33 +++---- Utilities/can_test/main.c | 87 +++++++++++-------- .../linux/pcanbasic}/LICENSE.lgpl | 0 .../linux/pcanbasic}/PCANBasic.h | 0 .../linux/pcanbasic}/README.txt | 0 .../{macOS => include/mac/pcbusb}/LICENSE | 0 .../{macOS => include/mac/pcbusb}/PCBUSB.h | 0 .../{macOS => include/mac/pcbusb}/README | 0 Utilities/{macOS => misc}/PCBUSB.c | 0 13 files changed, 142 insertions(+), 106 deletions(-) rename Utilities/{Linux => include/linux/pcanbasic}/LICENSE.lgpl (100%) rename Utilities/{Linux => include/linux/pcanbasic}/PCANBasic.h (100%) rename Utilities/{Linux => include/linux/pcanbasic}/README.txt (100%) rename Utilities/{macOS => include/mac/pcbusb}/LICENSE (100%) rename Utilities/{macOS => include/mac/pcbusb}/PCBUSB.h (100%) rename Utilities/{macOS => include/mac/pcbusb}/README (100%) rename Utilities/{macOS => misc}/PCBUSB.c (100%) diff --git a/Utilities/Makefile b/Utilities/Makefile index 19c99c0..da8622b 100644 --- a/Utilities/Makefile +++ b/Utilities/Makefile @@ -1,12 +1,12 @@ # # CAN Utilities for PEAK-System PCAN USB Interfaces (macOS, x86_64 & arm64) # -# Copyright (c) 2007-2010 Uwe Vogt, UV Software, Friedrichshafen -# Copyright (c) 2012-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +# Copyright (c) 2005-2010 Uwe Vogt, UV Software, Friedrichshafen +# Copyright (c) 2012-2025 Uwe Vogt, UV Software, Berlin (info@mac-can.com) # -# These utilities are free software: you can redistribute it and/or modify +# These utilities are free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or +# the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # These utilities is distributed in the hope that it will be useful, @@ -14,8 +14,8 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with these utilities. If not, see . +# You should have received a copy of the GNU General Public License along +# with these utilities; if not, see . # all: @rm -r build_no.h 2> /dev/null || true diff --git a/Utilities/build_no.sh b/Utilities/build_no.sh index facccfc..7884815 100755 --- a/Utilities/build_no.sh +++ b/Utilities/build_no.sh @@ -2,9 +2,9 @@ echo "/* -- Do not commit this file --" > ./build_no.h echo " *" >> ./build_no.h echo " * project : CAN - Controller Area Network" >> ./build_no.h echo " *" >> ./build_no.h -echo " * purpose : CAN Tester (based on macOS Library for PCAN-USB Interfaces)" >> ./build_no.h +echo " * purpose : CAN Utilities (based on macOS Library for PCAN-USB Interfaces)" >> ./build_no.h echo " *" >> ./build_no.h -echo " * copyright : (C) 2019,2023 UV Software, Berlin" >> ./build_no.h +echo " * copyright : (C) 2005-2025 UV Software, Berlin" >> ./build_no.h echo " *" >> ./build_no.h echo " * author(s) : Uwe Vogt, UV Software" >> ./build_no.h echo " *" >> ./build_no.h diff --git a/Utilities/can_moni/Makefile b/Utilities/can_moni/Makefile index b088075..2873b9f 100644 --- a/Utilities/can_moni/Makefile +++ b/Utilities/can_moni/Makefile @@ -32,7 +32,7 @@ MAIN_DIR = . MISC_DIR = $(HOME_DIR)/misc DRIVER_DIR = $(HOME_DIR)/driver -WRAPPER_DIR = $(HOME_DIR)/macOS +INCLUDE_DIR = $(HOME_DIR)/include OBJECTS = $(OUTDIR)/main.o $(OUTDIR)/bitrates.o $(OUTDIR)/timer.o $(OUTDIR)/printmsg.o @@ -47,7 +47,7 @@ ifeq ($(current_OS),Darwin) # macOS - libPCBUSB.dylib ifneq ($(VARIANT),STANDALONE) DEFINES += -DOPTION_PCBUSB_STANDALONE=0 - HEADERS += -I$(HOME_DIR)/macOS + HEADERS += -I$(INCLUDE_DIR)/mac/pcbusb OBJECTS += $(OUTDIR)/PCBUSB.o @@ -55,7 +55,7 @@ ifneq ($(VARIANT),STANDALONE) else DEFINES += -DOPTION_PCBUSB_STANDALONE=1 - HEADERS += -I$(HOME_DIR)/macOS -I$(DRIVER_DIR) + HEADERS += -I$(INCLUDE_DIR)/mac/pcbusb -I$(DRIVER_DIR) OBJECTS += $(OUTDIR)/pcan_api.o \ $(OUTDIR)/pcan_drv.o \ @@ -79,13 +79,7 @@ CXXFLAGS += -O2 -g -Wall -Wextra -pthread \ $(DEFINES) \ $(HEADERS) -LDFLAGS += -rpath /usr/local/lib - -LIBRARIES = -lpthread - -ifeq ($(VARIANT),STANDALONE) - LDFLAGS += -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation -endif +LDFLAGS += -rpath /usr/local/lib ifeq ($(BINARY),UNIVERSAL) CFLAGS += -arch arm64 -arch x86_64 @@ -93,6 +87,12 @@ CXXFLAGS += -arch arm64 -arch x86_64 LDFLAGS += -arch arm64 -arch x86_64 endif +ifeq ($(VARIANT),STANDALONE) +LDFLAGS += -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation +endif + +LIBRARIES = -lpthread + CXX = clang++ CC = clang LD = clang @@ -102,7 +102,7 @@ ifeq ($(current_OS),Linux) # linux - libpcanbasic.so DEFINES += -HEADERS += -I$(HOME_DIR)/Linux +HEADERS += -I$(INCLUDE_DIR)/linux/pcanbasic OBJECTS += $(OUTDIR)/PCBUSB.o @@ -131,6 +131,7 @@ CP = cp -f CHECKER = warning,information IGNORE = -i tester.c -i dosopt.c +LEVEL = exhaustive # normal or exhaustive OUTDIR = .objects BINDIR = $(BIN_DIR) @@ -155,7 +156,7 @@ incdir: @mkdir -p $(INCDIR) check: - cppcheck --enable=$(CHECKER) --suppressions-list=$(HOME_DIR)/suppress.txt \ + cppcheck --enable=$(CHECKER) --check-level=$(LEVEL) --suppressions-list=$(HOME_DIR)/suppress.txt \ -D__APPLE__ $(DEFINES) $(HEADERS) $(IGNORE) $(MAIN_DIR) $(MISC_DIR) clean: @@ -167,13 +168,14 @@ pristine: install: @echo "Copying binary file..." - @-$(CP) $(TARGET) $(INSTALL) + @mkdir -p $(INSTALL) + $(CP) $(TARGET) $(INSTALL) $(OUTDIR)/main.o: $(MAIN_DIR)/main.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< -$(OUTDIR)/PCBUSB.o: $(WRAPPER_DIR)/PCBUSB.c +$(OUTDIR)/PCBUSB.o: $(MISC_DIR)/PCBUSB.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< $(OUTDIR)/bitrates.o: $(MISC_DIR)/bitrates.c @@ -215,8 +217,9 @@ $(OUTDIR)/pcan_log.o: $(DRIVER_DIR)/pcan_log.c $(TARGET): $(OBJECTS) $(LD) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBRARIES) - $(CP) $(TARGET) $(BINDIR) ifeq ($(current_OS),Darwin) @lipo -archs $@ endif + @mkdir -p $(BINDIR) + $(CP) $(TARGET) $(BINDIR) @echo "\033[1mTarget '"$@"' successfully build\033[0m" diff --git a/Utilities/can_moni/main.c b/Utilities/can_moni/main.c index 869b5b9..c6c7263 100644 --- a/Utilities/can_moni/main.c +++ b/Utilities/can_moni/main.c @@ -7,7 +7,7 @@ * copyright : (c) 2007,2012 by UV Software, Friedrichshafen * (c) 2013-2025 by UV Software, Berlin * - * revision : $Rev: 2065 $ of $Date: 2024-12-30 16:48:19 +0100 (Mo, 30 Dez 2024) $ + * revision : $Rev: 2084 $ of $Date: 2025-02-28 22:33:11 +0100 (Fr, 28 Feb 2025) $ * * author(s) : Uwe Vogt, UV Software * @@ -19,26 +19,28 @@ * CAN Monitor (based on macOS Library for PCAN USB Interfaces) * * (1) Standalone version with compiled PCBUSB sources - * + * * This program is freeware without any warranty or support! * Please note the copyright and license agreements. * + * Note: This version does not require the libPCBUSB to be installed. + * * (2) Open-source version with libPCBUSB support - * - * This program is free software: you can redistribute it and/or modify + * + * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or + * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . * - * Note: The libPCBUSB is licensed under a freeware license without any + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + * + * Note: The libPCBUSB is licensed under a freeware license without any * warranty or support. The libPCBUSB is not part of this program. * It can be downloaded from . * @@ -49,14 +51,14 @@ #if (OPTION_PCBUSB_STANDALONE != 0) #define VERSION_MAJOR 0 #define VERSION_MINOR 6 -#define VERSION_PATCH 1 +#define VERSION_PATCH 99 #else #define VERSION_MAJOR 1 -#define VERSION_MINOR 0 +#define VERSION_MINOR 1 #define VERSION_PATCH 99 #endif #define VERSION_BUILD BUILD_NO -#define VERSION_STRING TOSTRING(VERSION_MAJOR)"." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")" +#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")" #if defined(__APPLE__) #define PLATFORM "macOS" #elif defined(__linux__) @@ -65,19 +67,16 @@ #error Unsupported platform #endif #if defined(__APPLE__) -static const char APPLICATION[] = "CAN Monitor for PEAK-System PCAN USB Interfaces, Version "VERSION_STRING; -#else -static const char APPLICATION[] = "CAN Monitor for PEAK-System PCAN Interfaces, Version "VERSION_STRING; -#endif +static const char APPLICATION[] = "CAN Monitor for PEAK-System PCAN USB Interfaces, Version " VERSION_STRING; static const char COPYRIGHT[] = "Copyright (c) 2007,2012-2025 by Uwe Vogt, UV Software, Berlin"; #if (OPTION_PCBUSB_STANDALONE != 0) static const char WARRANTY[] = "This program is freeware without any warranty or support!"; static const char LICENSE[] = "This program is freeware without any warranty or support!\n\n" \ "Note: This program does not require the libPCBUSB to be installed."; #else -static const char WARRANTY[] = "CAN Monitor comes with ABSOLUTELY NO WARRANTY; for details type `--version'.\n\n" \ +static const char WARRANTY[] = "This program comes with ABSOLUTELY NO WARRANTY!\n\n" \ "This is free software, and you are welcome to redistribute it\n" \ - "under certain conditions; type `--version' for details."; + "under certain conditions; type `can_moni --version' for details."; static const char LICENSE[] = "This program is free software; you can redistribute it and/or modify\n" \ "it under the terms of the GNU General Public License as published by\n" \ "the Free Software Foundation; either version 2 of the License, or\n" \ @@ -92,6 +91,21 @@ static const char LICENSE[] = "This program is free software; you can redist "warranty or support. The libPCBUSB is not part of this program.\n" \ "It can be downloaded from ."; #endif +#else +static const char APPLICATION[] = "CAN Monitor for PEAK-System PCAN Interfaces, Version " VERSION_STRING; +static const char COPYRIGHT[] = "Copyright (c) 2007,2012-2025 by Uwe Vogt, UV Software, Berlin"; +static const char WARRANTY[] = "This program comes with ABSOLUTELY NO WARRANTY!\n\n" \ + "This is free software, and you are welcome to redistribute it\n" \ + "under certain conditions; type `can_moni --version' for details."; +static const char LICENSE[] = "This program is free software; you can redistribute it and/or modify\n" \ + "it under the terms of the GNU General Public License as published by\n" \ + "the Free Software Foundation; either version 2 of the License, or\n" \ + "(at your option) any later version.\n\n" \ + "This program is distributed in the hope that it will be useful,\n" \ + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \ + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \ + "GNU General Public License for more details."; +#endif /* ----------- includes ----------------------------------------------- */ @@ -242,7 +256,6 @@ int main(int argc, char *argv[]) {"bitrate", required_argument, 0, 'B'}, {"verbose", no_argument, 0, 'v'}, {"mode", required_argument, 0, 'm'}, - {"shared", no_argument, 0, 'S'}, {"listen-only", no_argument, 0, 'M'}, {"no-status-frames", no_argument, 0, 'S'}, {"no-remote-frames", no_argument, 0, 'R'}, @@ -278,7 +291,7 @@ int main(int argc, char *argv[]) return errno; } /* scan command-line */ - while ((opt = getopt_long(argc, (char * const *)argv, "b:vm:t:i:d:a:x:s:y:lLTh", long_options, &i)) != -1) { + while ((opt = getopt_long(argc, (char * const *)argv, "b:vm:t:i:d:a:x:lLTh", long_options, &i)) != -1) { switch (opt) { /* option '--baudrate=' (-b) */ case 'b': @@ -327,14 +340,15 @@ int main(int argc, char *argv[]) } verbose = 1; break; - /* option '--mode=(2.0|FDF[+BRS])' (-m)*/ + /* option '--mode=(2.0|FDF[+BRS])' (-m) */ case 'm': if (op++) { fprintf(stderr, "%s: duplicated option `--mode' (%c)\n", basename(argv[0]), opt); return 1; } - if (!strcasecmp(optarg, "default") || !strcasecmp(optarg, "classic") || - !strcasecmp(optarg, "CAN2.0") || !strcasecmp(optarg, "CAN20") || !strcasecmp(optarg, "2.0")) + if (!strcasecmp(optarg, "DEFAULT") || !strcasecmp(optarg, "CLASIC") || !strcasecmp(optarg, "CLASICAL") || + !strcasecmp(optarg, "CAN2.0") || !strcasecmp(optarg, "CAN20") || !strcasecmp(optarg, "2.0") || + !strcasecmp(optarg, "CANCC") || !strcasecmp(optarg, "CCF") || !strcasecmp(optarg, "CC")) op_mode = PCAN_MESSAGE_STANDARD; else if (!strcasecmp(optarg, "CANFD") || !strcasecmp(optarg, "FDF") || !strcasecmp(optarg, "FD")) op_mode = PCAN_MESSAGE_FD; @@ -525,17 +539,18 @@ int main(int argc, char *argv[]) return 1; } break; - /* option '--list-bitrates' */ + /* option '--list-bitrates[=(2.0|FDF[+BRS])]' */ case 'l': fprintf(stdout, "%s\n%s\n\n%s\n\n", APPLICATION, COPYRIGHT, WARRANTY); /* list bit-rates (depending on operation mode) */ if (optarg != NULL) { - if (op != 0) { + if (op++) { fprintf(stderr, "%s: option `--list-bitrates' - operation mode already set'\n", basename(argv[0])); return 1; } if (!strcasecmp(optarg, "default") || !strcasecmp(optarg, "classic") || - !strcasecmp(optarg, "CAN2.0") || !strcasecmp(optarg, "CAN20") || !strcasecmp(optarg, "2.0")) + !strcasecmp(optarg, "CAN2.0") || !strcasecmp(optarg, "CAN20") || !strcasecmp(optarg, "2.0") || + !strcasecmp(optarg, "CANCC") || !strcasecmp(optarg, "CCF") || !strcasecmp(optarg, "CC")) op_mode = PCAN_MESSAGE_STANDARD; else if (!strcasecmp(optarg, "CANFD") || !strcasecmp(optarg, "FDF") || !strcasecmp(optarg, "FD")) op_mode = PCAN_MESSAGE_FD; @@ -1113,13 +1128,13 @@ static void usage(FILE *stream, const char *program) fprintf(stream, " --xtd-code= acceptance code for 29-bit IDs (default=0x%08X)\n", CODE_29BIT); fprintf(stream, " --xtd-mask= acceptance mask for 29-bit IDs (default=0x%08X)\n", MASK_29BIT); fprintf(stream, " -m, --mode=(2.0|FDF[+BRS]) CAN operation mode: CAN 2.0 or CAN FD format\n"); - fprintf(stream, " --listen-only monitor mode (transmitter is off)\n"); + fprintf(stream, " --listen-only monitor mode (isten-only mode)\n"); fprintf(stream, " --no-status-frames suppress reception of status frames\n"); fprintf(stream, " --no-remote-frames suppress reception of remote frames\n"); - fprintf(stream, " -b, --baudrate= CAN 2.0 bit timing in kbps (default=250)\n"); - fprintf(stream, " --bitrate= CAN FD bit rate (as a string)\n"); - fprintf(stream, " -v, --verbose show detailed bit rate settings\n"); - fprintf(stream, " -y, --trace=(ON|OFF) write a trace file (default=OFF)\n"); + fprintf(stream, " -b, --baudrate= CAN bit-timing in kbps (default=250)\n"); + fprintf(stream, " --bitrate= CAN bit-rate settings (as key/value list)\n"); + fprintf(stream, " -v, --verbose show detailed bit-rate settings\n"); + fprintf(stream, " --trace=(ON|OFF) write a trace file (default=OFF)\n"); fprintf(stream, " --list-bitrates[=] list standard bit-rate settings and exit\n"); fprintf(stream, " -L, --list-boards list all supported CAN interfaces and exit\n"); fprintf(stream, " -T, --test-boards list all available CAN interfaces and exit\n"); diff --git a/Utilities/can_test/Makefile b/Utilities/can_test/Makefile index 32125e0..9b88ad4 100644 --- a/Utilities/can_test/Makefile +++ b/Utilities/can_test/Makefile @@ -32,7 +32,7 @@ MAIN_DIR = . MISC_DIR = $(HOME_DIR)/misc DRIVER_DIR = $(HOME_DIR)/driver -WRAPPER_DIR = $(HOME_DIR)/macOS +INCLUDE_DIR = $(HOME_DIR)/include OBJECTS = $(OUTDIR)/main.o $(OUTDIR)/bitrates.o $(OUTDIR)/timer.o @@ -47,7 +47,7 @@ ifeq ($(current_OS),Darwin) # macOS - libPCBUSB.dylib ifneq ($(VARIANT),STANDALONE) DEFINES += -DOPTION_PCBUSB_STANDALONE=0 - HEADERS += -I$(HOME_DIR)/macOS + HEADERS += -I$(INCLUDE_DIR)/mac/pcbusb OBJECTS += $(OUTDIR)/PCBUSB.o @@ -55,7 +55,7 @@ ifneq ($(VARIANT),STANDALONE) else DEFINES += -DOPTION_PCBUSB_STANDALONE=1 - HEADERS += -I$(HOME_DIR)/macOS -I$(DRIVER_DIR) + HEADERS += -I$(INCLUDE_DIR)/mac/pcbusb -I$(DRIVER_DIR) OBJECTS += $(OUTDIR)/pcan_api.o \ $(OUTDIR)/pcan_drv.o \ @@ -79,13 +79,7 @@ CXXFLAGS += -O2 -g -Wall -Wextra -pthread \ $(DEFINES) \ $(HEADERS) -LDFLAGS += -rpath /usr/local/lib - -LIBRARIES = -lpthread - -ifeq ($(VARIANT),STANDALONE) - LDFLAGS += -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation -endif +LDFLAGS += -rpath /usr/local/lib ifeq ($(BINARY),UNIVERSAL) CFLAGS += -arch arm64 -arch x86_64 @@ -93,6 +87,12 @@ CXXFLAGS += -arch arm64 -arch x86_64 LDFLAGS += -arch arm64 -arch x86_64 endif +ifeq ($(VARIANT),STANDALONE) +LDFLAGS += -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation +endif + +LIBRARIES = -lpthread + CXX = clang++ CC = clang LD = clang @@ -102,7 +102,7 @@ ifeq ($(current_OS),Linux) # linux - libpcanbasic.so DEFINES += -HEADERS += -I$(HOME_DIR)/Linux +HEADERS += -I$(INCLUDE_DIR)/linux/pcanbasic OBJECTS += $(OUTDIR)/PCBUSB.o @@ -131,6 +131,7 @@ CP = cp -f CHECKER = warning,information IGNORE = -i tester.c -i dosopt.c +LEVEL = exhaustive # normal or exhaustive OUTDIR = .objects BINDIR = $(BIN_DIR) @@ -155,7 +156,7 @@ incdir: @mkdir -p $(INCDIR) check: - cppcheck --enable=$(CHECKER) --suppressions-list=$(HOME_DIR)/suppress.txt \ + cppcheck --enable=$(CHECKER) --check-level=$(LEVEL) --suppressions-list=$(HOME_DIR)/suppress.txt \ -D__APPLE__ $(DEFINES) $(HEADERS) $(IGNORE) $(MAIN_DIR) $(MISC_DIR) clean: @@ -167,13 +168,14 @@ pristine: install: @echo "Copying binary file..." - @-$(CP) $(TARGET) $(INSTALL) + @mkdir -p $(INSTALL) + $(CP) $(TARGET) $(INSTALL) $(OUTDIR)/main.o: $(MAIN_DIR)/main.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< -$(OUTDIR)/PCBUSB.o: $(WRAPPER_DIR)/PCBUSB.c +$(OUTDIR)/PCBUSB.o: $(MISC_DIR)/PCBUSB.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< $(OUTDIR)/bitrates.o: $(MISC_DIR)/bitrates.c @@ -212,8 +214,9 @@ $(OUTDIR)/pcan_log.o: $(DRIVER_DIR)/pcan_log.c $(TARGET): $(OBJECTS) $(LD) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBRARIES) - $(CP) $(TARGET) $(BINDIR) ifeq ($(current_OS),Darwin) @lipo -archs $@ endif + @mkdir -p $(BINDIR) + $(CP) $(TARGET) $(BINDIR) @echo "\033[1mTarget '"$@"' successfully build\033[0m" diff --git a/Utilities/can_test/main.c b/Utilities/can_test/main.c index 5aee1dd..39c97d8 100644 --- a/Utilities/can_test/main.c +++ b/Utilities/can_test/main.c @@ -7,7 +7,7 @@ * copyright : (c) 2005-2012 by UV Software, Friedrichshafen * (c) 2013-2025 by UV Software, Berlin * - * revision : $Rev: 2065 $ of $Date: 2024-12-30 16:48:19 +0100 (Mo, 30 Dez 2024) $ + * revision : $Rev: 2084 $ of $Date: 2025-02-28 22:33:11 +0100 (Fr, 28 Feb 2025) $ * * author(s) : Uwe Vogt, UV Software * @@ -19,28 +19,28 @@ * CAN Tester (based on macOS Library for PCAN USB Interfaces) * * (1) Standalone version with compiled PCBUSB sources - * + * * This program is freeware without any warranty or support! * Please note the copyright and license agreements. * * Note: This version does not require the libPCBUSB to be installed. * * (2) Open-source version with libPCBUSB support - * - * This program is free software: you can redistribute it and/or modify + * + * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or + * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . * - * Note: The libPCBUSB is licensed under a freeware license without any + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + * + * Note: The libPCBUSB is licensed under a freeware license without any * warranty or support. The libPCBUSB is not part of this program. * It can be downloaded from . * @@ -51,14 +51,14 @@ #if (OPTION_PCBUSB_STANDALONE != 0) #define VERSION_MAJOR 0 #define VERSION_MINOR 6 -#define VERSION_PATCH 1 +#define VERSION_PATCH 99 #else #define VERSION_MAJOR 1 -#define VERSION_MINOR 0 +#define VERSION_MINOR 1 #define VERSION_PATCH 99 #endif #define VERSION_BUILD BUILD_NO -#define VERSION_STRING TOSTRING(VERSION_MAJOR)"." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")" +#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")" #if defined(__APPLE__) #define PLATFORM "macOS" #elif defined(__linux__) @@ -67,19 +67,16 @@ #error Unsupported platform #endif #if defined(__APPLE__) -static const char APPLICATION[] = "CAN Tester for PEAK-System PCAN USB Interfaces, Version "VERSION_STRING; -#else -static const char APPLICATION[] = "CAN Tester for PEAK-System PCAN Interfaces, Version "VERSION_STRING; -#endif -static const char COPYRIGHT[] = "Copyright (c) 2007,2012-2025 by Uwe Vogt, UV Software, Berlin"; +static const char APPLICATION[] = "CAN Tester for PEAK-System PCAN USB Interfaces, Version " VERSION_STRING; +static const char COPYRIGHT[] = "Copyright (c) 2005-2010,2012-2025 by Uwe Vogt, UV Software, Berlin"; #if (OPTION_PCBUSB_STANDALONE != 0) static const char WARRANTY[] = "This program is freeware without any warranty or support!"; static const char LICENSE[] = "This program is freeware without any warranty or support!\n\n" \ "Note: This program does not require the libPCBUSB to be installed."; #else -static const char WARRANTY[] = "CAN Tester comes with ABSOLUTELY NO WARRANTY; for details type `--version'.\n\n" \ +static const char WARRANTY[] = "This program comes with ABSOLUTELY NO WARRANTY!\n\n" \ "This is free software, and you are welcome to redistribute it\n" \ - "under certain conditions; type `--version' for details."; + "under certain conditions; type `can_test --version' for details."; static const char LICENSE[] = "This program is free software; you can redistribute it and/or modify\n" \ "it under the terms of the GNU General Public License as published by\n" \ "the Free Software Foundation; either version 2 of the License, or\n" \ @@ -94,6 +91,21 @@ static const char LICENSE[] = "This program is free software; you can redist "warranty or support. The libPCBUSB is not part of this program.\n" \ "It can be downloaded from ."; #endif +#else +static const char APPLICATION[] = "CAN Tester for PEAK-System PCAN Interfaces, Version " VERSION_STRING; +static const char COPYRIGHT[] = "Copyright (c) 2005-2010,2012-2025 by Uwe Vogt, UV Software, Berlin"; +static const char WARRANTY[] = "This program comes with ABSOLUTELY NO WARRANTY!\n\n" \ + "This is free software, and you are welcome to redistribute it\n" \ + "under certain conditions; type `can_test --version' for details."; +static const char LICENSE[] = "This program is free software; you can redistribute it and/or modify\n" \ + "it under the terms of the GNU General Public License as published by\n" \ + "the Free Software Foundation; either version 2 of the License, or\n" \ + "(at your option) any later version.\n\n" \ + "This program is distributed in the hope that it will be useful,\n" \ + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \ + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \ + "GNU General Public License for more details."; +#endif /* ----------- includes ----------------------------------------------- */ @@ -224,7 +236,6 @@ int main(int argc, char *argv[]) {"bitrate", required_argument, 0, 'B'}, {"verbose", no_argument, 0, 'v'}, {"mode", required_argument, 0, 'm'}, - {"shared", no_argument, 0, 'S'}, {"listen-only", no_argument, 0, 'M'}, {"no-status-frames", no_argument, 0, 'S'}, {"no-remote-frames", no_argument, 0, 'R'}, @@ -262,7 +273,7 @@ int main(int argc, char *argv[]) return errno; } /* scan command-line */ - while ((opt = getopt_long(argc, (char * const *)argv, "b:vm:rn:st:f:R:c:u:d:i:y:laLTvh", long_options, NULL)) != -1) { + while ((opt = getopt_long(argc, (char * const *)argv, "b:vm:rn:st:f:F:c:u:d:i:laLTvh", long_options, NULL)) != -1) { switch (opt) { /* option '--baudrate=' (-b) */ case 'b': @@ -311,14 +322,15 @@ int main(int argc, char *argv[]) } verbose = 1; break; - /* option '--mode=(2.0|FDF[+BRS])' (-m)*/ + /* option '--mode=(2.0|FDF[+BRS])' (-m) */ case 'm': if (op++) { fprintf(stderr, "%s: duplicated option `--mode' (%c)\n", basename(argv[0]), opt); return 1; } - if (!strcasecmp(optarg, "default") || !strcasecmp(optarg, "classic") || - !strcasecmp(optarg, "CAN2.0") || !strcasecmp(optarg, "CAN20") || !strcasecmp(optarg, "2.0")) + if (!strcasecmp(optarg, "DEFAULT") || !strcasecmp(optarg, "CLASIC") || !strcasecmp(optarg, "CLASICAL") || + !strcasecmp(optarg, "CAN2.0") || !strcasecmp(optarg, "CAN20") || !strcasecmp(optarg, "2.0") || + !strcasecmp(optarg, "CANCC") || !strcasecmp(optarg, "CCF") || !strcasecmp(optarg, "CC")) op_mode = PCAN_MESSAGE_STANDARD; else if (!strcasecmp(optarg, "CANFD") || !strcasecmp(optarg, "FDF") || !strcasecmp(optarg, "FD")) op_mode = PCAN_MESSAGE_FD; @@ -500,17 +512,18 @@ int main(int argc, char *argv[]) return 1; } break; - /* option '--list-bitrates' */ + /* option '--list-bitrates[=(2.0|FDF[+BRS])]' */ case 'l': fprintf(stdout, "%s\n%s\n\n%s\n\n", APPLICATION, COPYRIGHT, WARRANTY); /* list bit-rates (depending on operation mode) */ if (optarg != NULL) { - if (op != 0) { + if (op++) { fprintf(stderr, "%s: option `--list-bitrates' - operation mode already set'\n", basename(argv[0])); return 1; } if (!strcasecmp(optarg, "default") || !strcasecmp(optarg, "classic") || - !strcasecmp(optarg, "CAN2.0") || !strcasecmp(optarg, "CAN20") || !strcasecmp(optarg, "2.0")) + !strcasecmp(optarg, "CAN2.0") || !strcasecmp(optarg, "CAN20") || !strcasecmp(optarg, "2.0") || + !strcasecmp(optarg, "CANCC") || !strcasecmp(optarg, "CCF") || !strcasecmp(optarg, "CC")) op_mode = PCAN_MESSAGE_STANDARD; else if (!strcasecmp(optarg, "CANFD") || !strcasecmp(optarg, "FDF") || !strcasecmp(optarg, "FD")) op_mode = PCAN_MESSAGE_FD; @@ -886,6 +899,7 @@ static uint64_t tx_random(TPCANHandle channel, BYTE mode, uint32_t can_id, uint8 fprintf(stderr, "\nPress ^C to abort.\n"); message.ID = (DWORD)can_id; + message.LEN = (BYTE)dlc; message.MSGTYPE = (TPCANMessageType)mode; fprintf(stdout, "\nTransmitting message(s)..."); fflush (stdout); @@ -1201,6 +1215,7 @@ static uint64_t tx_random_fd(TPCANHandle channel, BYTE mode, uint32_t can_id, ui fprintf(stderr, "\nPress ^C to abort.\n"); message.ID = (DWORD)can_id; + message.DLC = (BYTE)dlc; message.MSGTYPE = (TPCANMessageType)mode; fprintf(stdout, "\nTransmitting message(s)..."); fflush (stdout); @@ -1496,17 +1511,17 @@ static void usage(FILE *stream, const char *program) fprintf(stream, " -n, --number= check up-counting numbers starting with \n"); fprintf(stream, " -s, --stop stop on error (with option --number)\n"); fprintf(stream, " -m, --mode=(2.0|FDF[+BRS]) CAN operation mode: CAN 2.0 or CAN FD format\n"); - fprintf(stream, " --listen-only monitor mode (transmitter is off)\n"); + fprintf(stream, " --listen-only monitor mode (isten-only mode)\n"); fprintf(stream, " --no-status-frames suppress reception of status frames\n"); fprintf(stream, " --no-remote-frames suppress reception of remote frames\n"); // fprintf(stream, " --code= acceptance code for 11-bit IDs (default=0x%03X)\n", CODE_11BIT); // fprintf(stream, " --mask= acceptance mask for 11-bit IDs (default=0x%03X)\n", MASK_11BIT); // fprintf(stream, " --xtd-code= acceptance code for 29-bit IDs (default=0x%08X)\n", CODE_29BIT); // fprintf(stream, " --xtd-mask= acceptance mask for 29-bit IDs (default=0x%08X)\n", MASK_29BIT); - fprintf(stream, " -b, --baudrate= CAN 2.0 bit timing in kbps (default=250)\n"); - fprintf(stream, " --bitrate= CAN FD bit rate (as a string)\n"); - fprintf(stream, " -v, --verbose show detailed bit rate settings\n"); - fprintf(stream, " -y, --trace=(ON|OFF) write a trace file (default=OFF)\n"); + fprintf(stream, " -b, --baudrate= CAN bit-timing in kbps (default=250)\n"); + fprintf(stream, " --bitrate= CAN bit-rate settings (as key/value list)\n"); + fprintf(stream, " -v, --verbose show detailed bit-rate settings\n"); + fprintf(stream, " --trace=(ON|OFF) write a trace file (default=OFF)\n"); fprintf(stream, "Options for transmitter test:\n"); fprintf(stream, " -t, --transmit=