Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/bouyer-socketcan]: src/sbin/canconfig Implement listenonly and loopback ...



details:   https://anonhg.NetBSD.org/src/rev/7e9cf1128a2f
branches:  bouyer-socketcan
changeset: 820894:7e9cf1128a2f
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Thu Apr 20 12:59:54 2017 +0000

description:
Implement listenonly and loopback flags.
Fix do_canflag()

diffstat:

 sbin/canconfig/canconfig.8 |  12 +++++++++++-
 sbin/canconfig/canconfig.c |  39 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 45 insertions(+), 6 deletions(-)

diffs (125 lines):

diff -r fb6cab84853f -r 7e9cf1128a2f sbin/canconfig/canconfig.8
--- a/sbin/canconfig/canconfig.8        Thu Apr 20 12:59:11 2017 +0000
+++ b/sbin/canconfig/canconfig.8        Thu Apr 20 12:59:54 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: canconfig.8,v 1.1.2.1 2017/04/17 20:48:36 bouyer Exp $
+.\"    $NetBSD: canconfig.8,v 1.1.2.2 2017/04/20 12:59:54 bouyer Exp $
 .\"
 .\" Copyright (c) 2017 Manuel Bouyer.
  *
@@ -100,6 +100,16 @@
 enables triple-sampling.
 .It Cm -3samples
 disables triple-sampling.
+.It Cm listenonly
+enables listenonly mode. In this mode the controller is passive, and
+doesn't send ACKs on the bus.
+.It Cm -listenonly
+disables listenonly mode.
+.It Cm loopback
+enables loopback mode. In this mode, the controller doens't expect ACK from
+the bus.
+.It Cm -loopback
+disables loopback mode.
 .El
 .Sh EXAMPLES
 TODO
diff -r fb6cab84853f -r 7e9cf1128a2f sbin/canconfig/canconfig.c
--- a/sbin/canconfig/canconfig.c        Thu Apr 20 12:59:11 2017 +0000
+++ b/sbin/canconfig/canconfig.c        Thu Apr 20 12:59:54 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: canconfig.c,v 1.1.2.2 2017/04/19 17:51:16 bouyer Exp $ */
+/*     $NetBSD: canconfig.c,v 1.1.2.3 2017/04/20 12:59:54 bouyer Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -38,7 +38,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: canconfig.c,v 1.1.2.2 2017/04/19 17:51:16 bouyer Exp $");
+__RCSID("$NetBSD: canconfig.c,v 1.1.2.3 2017/04/20 12:59:54 bouyer Exp $");
 #endif
 
 
@@ -77,6 +77,8 @@
 static void    cmd_phase_seg2(const struct command *, int, const char *, char **);
 static void    cmd_sjw(const struct command *, int, const char *, char **);
 static void    cmd_3samples(const struct command *, int, const char *, char **);
+static void    cmd_listenonly(const struct command *, int, const char *, char **);
+static void    cmd_loopback(const struct command *, int, const char *, char **);
 
 static const struct command command_table[] = {
        { "up",                 0,      0,              cmd_up },
@@ -91,6 +93,12 @@
        { "3samples",           0,      0,              cmd_3samples },
        { "-3samples",          0,      CMD_INVERT,     cmd_3samples },
 
+       { "listenonly",         0,      0,              cmd_listenonly },
+       { "-listenonly",        0,      CMD_INVERT,     cmd_listenonly },
+
+       { "loopback",           0,      0,              cmd_loopback },
+       { "-loopback",          0,      CMD_INVERT,     cmd_loopback },
+
        { NULL,                 0,      0,              NULL },
 };
 
@@ -225,6 +233,8 @@
                "<canif> phase_seg2 <value>",
                "<canif> sjw <value>",
                "<canif> 3samples | -3samples",
+               "<canif> listenonly | -listenonly",
+               "<canif> loopback | -loopback",
                NULL,
        };
        extern const char *__progname;
@@ -353,7 +363,7 @@
        printb("capabilities", cltc.cltc_linkmode_caps, CAN_IFFBITS);
        printf("\n");
        printf("%soperational timings:\n", prefix);
-       printf("%s  brp %d prop_seg %d, phase_seg1 %d, phase_seg2 %d, sjw %d\n",
+       printf("%s  brp %d, prop_seg %d, phase_seg1 %d, phase_seg2 %d, sjw %d\n",
            prefix,
            clt.clt_brp, clt.clt_prop, clt.clt_ps1, clt.clt_ps2, clt.clt_sjw);
        printf("%s  ", prefix);
@@ -418,7 +428,7 @@
                cmd = CANSLINKMODE;
        else
                cmd = CANCLINKMODE;
-       return do_cmd(sock, canifname, cmd, &flag, sizeof(flag), set);
+       return do_cmd(sock, canifname, cmd, &flag, sizeof(flag), 1);
 }
 
 static void
@@ -506,7 +516,6 @@
        g_clt.clt_sjw = val;
        g_clt_updated=1;
 }
-
 static void
 cmd_3samples(const struct command *cmd, int sock, const char *canifname,
     char **argv)
@@ -516,3 +525,23 @@
                err(1, "%s", cmd->cmd_keyword);
 
 }
+
+static void
+cmd_listenonly(const struct command *cmd, int sock, const char *canifname,
+    char **argv)
+{
+        if (do_canflag(sock, canifname, CAN_LINKMODE_LISTENONLY,
+           (cmd->cmd_flags & CMD_INVERT) ? 0 : 1) < 0)
+               err(1, "%s", cmd->cmd_keyword);
+
+}
+
+static void
+cmd_loopback(const struct command *cmd, int sock, const char *canifname,
+    char **argv)
+{
+        if (do_canflag(sock, canifname, CAN_LINKMODE_LOOPBACK,
+           (cmd->cmd_flags & CMD_INVERT) ? 0 : 1) < 0)
+               err(1, "%s", cmd->cmd_keyword);
+
+}



Home | Main Index | Thread Index | Old Index