Hi,
The following patch file enables a user to perform the following:
Choose which device instance number you are going to get for a slcan port.
This is really handy if you have 4 or more 1mbit slcan interfaces that come and 
go asynchronously in a Linux system...

#Say you want to kick the CAN on /dev/TTYUSB9 as device can4
stty swtch 4 -F /dev/TTYUSB9
#now call slcand as normal
ifconfig can4 up


Presto, no hunting around to figure out which "slc" or "can" number the call to 
slcand came up on.

This patch uses the device prefix "can" instead of "slc".  A binary library we 
paid for has "can" hardcoded as the prefix of the CAN devicename; "slc" breaks 
it.
Just search for the edit at slcan.c line 753 in the patch and you will see 
where you can change can back to slc if you are really fond of the slc prefix 
for any reason.

If not, I would love for the default to be can instead of slc, to be compatible 
with other interfaces!

There is no reason to consider slcan a second class CAN port, we stream 
continuous 1mbit data on it no problem.
Yes people need to move away from the USB interrupt/HID style interface and use 
a bulk in/out endpoint to get
great performance. Otherwise slcan adapters thru USB ports appear to be limited 
in the packets per second.

-Steve

p.s. In case your worried about the overloaded use of the swtch flag to stty:

In article 
<cjjvri$mq...@new-usenet.uk.sun.com<mailto:cjjvri$mq...@new-usenet.uk.sun.com>>,
 and...@cucumber.demon.co.uk<mailto:and...@cucumber.demon.co.uk> (Andrew 
Gabriel) wrote:

> In article 
> <cjjtns$dg...@yin.interaccess.com<mailto:cjjtns$dg...@yin.interaccess.com>>,
> gaze...@yin.interaccess.com<mailto:gaze...@yin.interaccess.com> (Kenny 
> McCormack) writes:
> > When I do "stty", it shows something called "swtch" (in and among such
> > things as "intr" and "quit"). "man stty" mentions "swtch", but doesn't
> > explain it. I could find no other reference to it in the man pages (at
> > least those that I looked at).
> >
> > What is it?
>
> It's obsolete. It was the character for switching shells under
> shl - shell layers. When shells with job control came along,
> it became redundent.

And then when window systems and applications like "screen" came along,
it because *really* obsolete.
# delete everything above this line (and this line) to make a patch file
--- slcan.c    2010-04-07 12:03:58.000000000 -0700
+++ slcan.c.new 2010-04-07 12:04:07.000000000 -0700
@@ -124,7 +124,17 @@
  * to use the slcan driver with an existing kernel.
  */

+/*
+ * By default, do not turn on SLC_CHECK_TRANSMIT
+ * when a slcan device transmits into an unconnected network,
+ * the transmit timeout causes a kernel panic, this behaviour
+ * should be at the choice of the user.
+ */
+
+#if 0
 #define SLC_CHECK_TRANSMIT
+#endif
+
 #define SLCAN_MAGIC 0x53CA

 static int maxdev = 10;              /* MAX number of SLCAN channels;
@@ -670,7 +680,7 @@


 /* Find a free SLCAN channel, and link in this `tty' line. */
-static struct slcan *slc_alloc(dev_t line)
+static struct slcan *slc_alloc(dev_t line, char forcednum)
 {
        int i;
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
@@ -727,10 +737,18 @@
               }
        }

+  /* Check if the user specified an exact interface to use */
+  if (forcednum) {
+    sel = forcednum-'0';
+    score=0;
+    i=sel;
+    dev=slcan_devs[i];
+  }
+
        if (sel >= 0) {
               i = sel;
               dev = slcan_devs[i];
-              if (score > 1) {
+              if ((score > 1) && (dev)) {
                       sl = netdev_priv(dev);
                       sl->flags &= (1 << SLF_INUSE);
                       return sl;
@@ -753,7 +771,7 @@

        if (!dev) {
               char name[IFNAMSIZ];
-              sprintf(name, "slc%d", i);
+              sprintf(name, "can%d", i);

               dev = alloc_netdev(sizeof(*sl), name, slc_setup);
               if (!dev)
@@ -813,7 +831,20 @@

        /* OK.  Find a free SLCAN channel to use. */
        err = -ENFILE;
-       sl = slc_alloc(tty_devnum(tty));
+  /* Look to see if the user has requested a specific channel
+   * to be used (encoded as '0' plus the interface number requested in
+   * the otherwise unused swtch termios variable )
+   * stty swtch 'channel' device
+   *  where 'channel' is '0' to maxdevs (0)
+   *  where device is the name of the serial device (/dev/ttyUSB0)
+   */
+  if ((SWTC_CHAR(tty)>='0') && (SWTC_CHAR(tty)<'0'+maxdev)){
+    sl = slc_alloc(tty_devnum(tty),SWTC_CHAR(tty));
+  } else {
+       /* OK.  Find a free SLCAN channel to use. */
+         sl = slc_alloc(tty_devnum(tty),0);
+  }
+
        if (sl == NULL)
               goto err_exit;


_______________________________________________
Socketcan-users mailing list
Socketcan-users@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/socketcan-users

Reply via email to