diff --git a/GNUmakefile.am b/GNUmakefile.am index 703b9179..dc1b73b2 100644 --- a/GNUmakefile.am +++ b/GNUmakefile.am @@ -66,10 +66,14 @@ bin_PROGRAMS = \ slcanpty \ testj1939 +sbin_PROGRAMS = \ + canconfig + jacd_LDADD = libj1939.la jspy_LDADD = libj1939.la jsr_LDADD = libj1939.la testj1939_LDADD = libj1939.la +canconfig_LDADD = $(libsocketcan_LIBS) EXTRA_DIST = \ .travis.yml \ diff --git a/canconfig.c b/canconfig.c new file mode 100644 index 00000000..3fddbde0 --- /dev/null +++ b/canconfig.c @@ -0,0 +1,581 @@ +/* + * canutils/canconfig.c + * + * Copyright (C) 2005, 2008 Marc Kleine-Budde , Pengutronix + * Copyright (C) 2007 Juergen Beisert , Pengutronix + * Copyright (C) 2009 Luotao Fu , Pengutronix + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#ifndef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + +const char *can_states[CAN_STATE_MAX] = { + "ERROR-ACTIVE", + "ERROR-WARNING", + "ERROR-PASSIVE", + "BUS-OFF", + "STOPPED", + "SLEEPING" +}; + +const char *config_keywords[] = { + "baudrate", "bitrate", "bittiming", "ctrlmode", "restart", + "start", "stop", "restart-ms", "state", "clockfreq", + "bittiming-const", "berr-counter"}; + +/* this is shamelessly stolen from iproute and slightly modified */ +#define NEXT_ARG() \ + do { \ + argv++; \ + if (--argc < 0) { \ + fprintf(stderr, "missing parameter for %s\n", *argv); \ + exit(EXIT_FAILURE);\ + }\ + } while(0) + +static inline int find_str(const char** haystack, unsigned int stack_size, + const char* needle) +{ + int i, found = 0; + + for (i = 0; i < stack_size; i++) { + if (!strcmp(needle, haystack[i])) { + found = 1; + break; + } + } + + return found; +} + +static void help(void) +{ + fprintf(stderr, "usage:\n\t" + "canconfig bitrate { BR } [sample-point { SP }]\n\t\t" + "BR := \n\t\t" + "SP := (optional)\n\t" + "canconfig bittiming [ VALs ]\n\t\t" + "VALs := \n\t\t" + "tq