Setting bitrate from user-space application
Hi all,
I prefer to ask first to those who know.
What is the 'normal' way of setting CAN bitrate from user-space application ? Is there a library for that ?
If no shall I use netlink ?
if yes Can I use libnl ?
Thanks in advance for showing me where to dig internet.
regards.
Hi Picquet,
You can use can-utils.
Best regards
Pankaj Kumar Misra
RBEI/EEA2
Tel. +91(80)6783-6643
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Guillaume Picquet
Sent: Wednesday, November 25, 2015 3:02 PM
To: [email protected]
Subject: Setting bitrate from user-space application
Hi all,
I prefer to ask first to those who know.
What is the 'normal' way of setting CAN bitrate from user-space application ?
Is there a library for that ?
If no shall I use netlink ?
if yes Can I use libnl ?
Thanks in advance for showing me where to dig internet.
regards.
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde
maintainerQuoted 7 lines · Guillaume Picquet
Hi all,
I prefer to ask first to those who know.
What is the 'normal' way of setting CAN bitrate from user-space application ?
Is there a library for that ?
Yes -
http://www.pengutronix.de/software/libsocketcan/download/libsocketcan-0.0.10.tar.bz2
Quoted 1 line
If no shall I use netlink ?
No - netlink parsing makes your brain hurt :D
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Hi Guillaume,
Quoted 9 lines · Marc Kleine-Budde
Quoted 7 lines · Guillaume Picquet
Hi all,
I prefer to ask first to those who know.
What is the 'normal' way of setting CAN bitrate from user-space application ?
Is there a library for that ?
Quoted 7 lines
Yes -
http://www.pengutronix.de/software/libsocketcan/download/libsocketcan-0.0.10.tar.bz2Quoted 1 line
If no shall I use netlink ?
No - netlink parsing makes your brain hurt :D
Using libsocketcan is the way to control the interfaces by an application (which internally uses netlink).
The usual way to configure the interfaces system wide is the 'ip' tool from the iproute2 package which comes with your preferred Linux distribution.
The way to configure CAN interfaces with 'ip' is described here:
https://www.kernel.org/doc/Documentation/networking/can.txt (see chapter 6.5)
E.g. you can use this script in Debian/Ubuntu setups then:
https://github.com/linux-can/can-misc/blob/master/etc/can_if
Regards,
Oliver
Marc Kleine-Budde
maintainerQuoted 6 lines · Oliver Hartkopp
Using libsocketcan is the way to control the interfaces by an application (which internally uses netlink).
The usual way to configure the interfaces system wide is the 'ip' tool from the iproute2 package which comes with your preferred Linux distribution.
Quoted 7 lines
The way to configure CAN interfaces with 'ip' is described here:
https://www.kernel.org/doc/Documentation/networking/can.txt (see chapter 6.5)
E.g. you can use this script in Debian/Ubuntu setups then:
https://github.com/linux-can/can-misc/blob/master/etc/can_if
'seems we need systemd-networkd support for CAN.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Quoted 11 lines · Oliver Hartkopp
Hi Guillaume,
Quoted 8 lines · Marc Kleine-Budde
Quoted 7 lines · Guillaume Picquet
Hi all,
I prefer to ask first to those who know.
What is the 'normal' way of setting CAN bitrate from user-space application ?
Is there a library for that ?
Quoted 8 lines
Quoted 6 lines
Yes -
http://www.pengutronix.de/software/libsocketcan/download/libsocketcan-0.0.10.tar.bz2Quoted 1 line
If no shall I use netlink ?
No - netlink parsing makes your brain hurt :D
Using libsocketcan is the way to control the interfaces by an application (which internally uses netlink).
I've downloaded it, cross-compile it and made a test program. I read bitrate successfully.
Quoted 3 lines
The usual way to configure the interfaces system wide is the 'ip' tool from the iproute2 package which comes with your preferred Linux distribution.
On the platform I'am working it's done in a rc script at start-up
Quoted 11 lines
The way to configure CAN interfaces with 'ip' is described here:
https://www.kernel.org/doc/Documentation/networking/can.txt (see chapter 6.5)
E.g. you can use this script in Debian/Ubuntu setups then:
https://github.com/linux-can/can-misc/blob/master/etc/can_if
Regards,
Oliver
Regards,
guillaume
Quoted 11 lines · Guillaume Picquet
Quoted 10 lines · Oliver Hartkopp
Hi Guillaume,
Quoted 7 lines · Marc Kleine-Budde
Quoted 6 lines · Guillaume Picquet
Hi all,
I prefer to ask first to those who know.
What is the 'normal' way of setting CAN bitrate from user-space application ?
The "abnormal" way I do it is basically:
char *pName = (a_eDevice == CAN_BUS_CAN_0) ? "can0" : "can1"; sprintf(vBuf,
"/usr/local/sbin/canconfig %s stop > /dev/null ; " "/usr/local/sbin/canconfig %s bitrate %d > /dev/null ; " "/usr/local/sbin/canconfig %s start > /dev/null\n", pName, pName, a_nKbaud * 1000, pName);
nRc = system(vBuf);
Or if using Freescale's 2.6.35 driver, "ifconfig can0 down/up" and
"echo 500000 > /sys/class/devices/platform/FlexCAN.0/bitrate" in the above "system()" call.
I realise the above may be horrible, but I'd like some more information on why it might be bad.
Tom
Quoted 6 lines
Or if using Freescale's 2.6.35 driver, "ifconfig can0 down/up" and "echo 500000 >
/sys/class/devices/platform/FlexCAN.0/bitrate" in the above "system()" call.I realise the above may be horrible, but I'd like some more information on why it might be bad.
a) it will only work with this specific FlexCAN driver from this proprietary kernel
b) if you ever are forced to upgrade to, say, 4.4, it won't work
Whereas "ip link set can0 type can bitrate 500000" will work with any card (even USB dongles that you might use as test equipment), and with any kernel.
As an added bonus, it can even set things like "restart-ms" :-)
Hi all!
A status update, thanks to libsocketcan I am able to get and set bitrate.
remarks:
Before setting bitrate a stop must be performed.
I use poll() on CAN socket and it returns and set errno to ENETDOWN during the stop but sockets stay valid. (no need to close and reopen). I Suppose it is normal behaviour, right ?
Thanks for support.
Regards.
Quoted 48 lines · Guillaume Picquet
Quoted 15 lines · Oliver Hartkopp
Hi Guillaume,
Quoted 12 lines · Marc Kleine-Budde
Quoted 7 lines · Guillaume Picquet
Hi all,
I prefer to ask first to those who know.
What is the 'normal' way of setting CAN bitrate from user-space application ?
Is there a library for that ?Yes -
http://www.pengutronix.de/software/libsocketcan/download/libsocketcan-0.0.10.tar.bz2Quoted 5 lines
Quoted 3 lines
Quoted 1 line
If no shall I use netlink ?
No - netlink parsing makes your brain hurt :D
Using libsocketcan is the way to control the interfaces by an application (which internally uses netlink).
I've downloaded it, cross-compile it and made a test program. I read bitrate successfully.
Quoted 3 lines
The usual way to configure the interfaces system wide is the 'ip' tool from the iproute2 package which comes with your preferred Linux distribution.
On the platform I'am working it's done in a rc script at start-up
Quoted 11 lines
The way to configure CAN interfaces with 'ip' is described here:
https://www.kernel.org/doc/Documentation/networking/can.txt (see chapter 6.5)
E.g. you can use this script in Debian/Ubuntu setups then:
https://github.com/linux-can/can-misc/blob/master/etc/can_if
Regards,
OliverRegards,
guillaume
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde
maintainerQuoted 1 line · Guillaume Picquet
A status update, thanks to libsocketcan I am able to get and set bitrate.
\o/
Quoted 2 lines
remarks:
Before setting bitrate a stop must be performed.
Yes - this way you can be sure that the new frames are send with the new bitrate. Also think of a multi application CAN environment.
Quoted 3 lines
I use
poll()on CAN socket and it returns and set errno to ENETDOWN during the stop but sockets stay valid. (no need to close and reopen). I Suppose it is normal behaviour, right ?
ENETDOWN is expected behaviour. That you don't need to close and reopen the socket is.....nice, isn't it :) Let's say it's implementation defined behaviour. Better close and reopen the socket.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |