* Setting bitrate from user-space application
@ 2015-11-25 14:02 Guillaume Picquet
2015-11-25 14:24 ` Misra Pankaj Kumar (RBEI/EEA2)
2015-11-25 14:58 ` Marc Kleine-Budde
0 siblings, 2 replies; 10+ messages in thread
From: Guillaume Picquet @ 2015-11-25 14:02 UTC (permalink / raw)
To: linux-can
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: Setting bitrate from user-space application
2015-11-25 14:02 Setting bitrate from user-space application Guillaume Picquet
@ 2015-11-25 14:24 ` Misra Pankaj Kumar (RBEI/EEA2)
2015-11-25 14:58 ` Marc Kleine-Budde
1 sibling, 0 replies; 10+ messages in thread
From: Misra Pankaj Kumar (RBEI/EEA2) @ 2015-11-25 14:24 UTC (permalink / raw)
To: Guillaume Picquet; +Cc: linux-can@vger.kernel.org
Hi Picquet,
You can use can-utils.
Best regards
Pankaj Kumar Misra
RBEI/EEA2
Tel. +91(80)6783-6643
-----Original Message-----
From: linux-can-owner@vger.kernel.org [mailto:linux-can-owner@vger.kernel.org] On Behalf Of Guillaume Picquet
Sent: Wednesday, November 25, 2015 3:02 PM
To: linux-can@vger.kernel.org
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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Setting bitrate from user-space application
2015-11-25 14:02 Setting bitrate from user-space application Guillaume Picquet
2015-11-25 14:24 ` Misra Pankaj Kumar (RBEI/EEA2)
@ 2015-11-25 14:58 ` Marc Kleine-Budde
2015-11-25 16:04 ` Oliver Hartkopp
1 sibling, 1 reply; 10+ messages in thread
From: Marc Kleine-Budde @ 2015-11-25 14:58 UTC (permalink / raw)
To: Guillaume Picquet, linux-can
[-- Attachment #1: Type: text/plain, Size: 691 bytes --]
On 11/25/2015 03:02 PM, Guillaume Picquet wrote:
> 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
> If no shall I use netlink ?
No - netlink parsing makes your brain hurt :D
Marc
--
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 |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Setting bitrate from user-space application
2015-11-25 14:58 ` Marc Kleine-Budde
@ 2015-11-25 16:04 ` Oliver Hartkopp
2015-11-25 16:10 ` Marc Kleine-Budde
2015-11-25 16:17 ` Guillaume Picquet
0 siblings, 2 replies; 10+ messages in thread
From: Oliver Hartkopp @ 2015-11-25 16:04 UTC (permalink / raw)
To: Marc Kleine-Budde, Guillaume Picquet, linux-can
Hi Guillaume,
On 11/25/2015 03:58 PM, Marc Kleine-Budde wrote:
> On 11/25/2015 03:02 PM, Guillaume Picquet wrote:
>> 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
>
>> 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Setting bitrate from user-space application
2015-11-25 16:04 ` Oliver Hartkopp
@ 2015-11-25 16:10 ` Marc Kleine-Budde
2015-11-25 16:17 ` Guillaume Picquet
1 sibling, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2015-11-25 16:10 UTC (permalink / raw)
To: Oliver Hartkopp, Guillaume Picquet, linux-can
[-- Attachment #1: Type: text/plain, Size: 948 bytes --]
On 11/25/2015 05:04 PM, Oliver Hartkopp wrote:
> 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
'seems we need systemd-networkd support for CAN.
Marc
--
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 |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Setting bitrate from user-space application
2015-11-25 16:04 ` Oliver Hartkopp
2015-11-25 16:10 ` Marc Kleine-Budde
@ 2015-11-25 16:17 ` Guillaume Picquet
2015-11-28 2:28 ` Tom Evans
2015-12-23 14:03 ` Guillaume Picquet
1 sibling, 2 replies; 10+ messages in thread
From: Guillaume Picquet @ 2015-11-25 16:17 UTC (permalink / raw)
To: Oliver Hartkopp, Marc Kleine-Budde, linux-can
Le 25/11/2015 17:04, Oliver Hartkopp a écrit :
> Hi Guillaume,
>
> On 11/25/2015 03:58 PM, Marc Kleine-Budde wrote:
>> On 11/25/2015 03:02 PM, Guillaume Picquet wrote:
>>> 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
>>
>>> 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.
>
> 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
>
> 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Setting bitrate from user-space application
2015-11-25 16:17 ` Guillaume Picquet
@ 2015-11-28 2:28 ` Tom Evans
2015-12-23 12:07 ` Holger Schurig
2015-12-23 14:03 ` Guillaume Picquet
1 sibling, 1 reply; 10+ messages in thread
From: Tom Evans @ 2015-11-28 2:28 UTC (permalink / raw)
To: Guillaume Picquet, Oliver Hartkopp, Marc Kleine-Budde, linux-can
On 26/11/2015 3:17 AM, Guillaume Picquet wrote:
> Le 25/11/2015 17:04, Oliver Hartkopp a écrit :
>> Hi Guillaume,
>>
>> On 11/25/2015 03:58 PM, Marc Kleine-Budde wrote:
>>> On 11/25/2015 03:02 PM, Guillaume Picquet wrote:
>>>> 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Setting bitrate from user-space application
2015-11-28 2:28 ` Tom Evans
@ 2015-12-23 12:07 ` Holger Schurig
0 siblings, 0 replies; 10+ messages in thread
From: Holger Schurig @ 2015-12-23 12:07 UTC (permalink / raw)
To: Tom Evans
Cc: Guillaume Picquet, Oliver Hartkopp, Marc Kleine-Budde, linux-can
> 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" :-)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Setting bitrate from user-space application
2015-11-25 16:17 ` Guillaume Picquet
2015-11-28 2:28 ` Tom Evans
@ 2015-12-23 14:03 ` Guillaume Picquet
2015-12-23 14:10 ` Marc Kleine-Budde
1 sibling, 1 reply; 10+ messages in thread
From: Guillaume Picquet @ 2015-12-23 14:03 UTC (permalink / raw)
To: Oliver Hartkopp, Marc Kleine-Budde, linux-can
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.
Le 25/11/2015 17:17, Guillaume Picquet a écrit :
>
>
> Le 25/11/2015 17:04, Oliver Hartkopp a écrit :
>> Hi Guillaume,
>>
>> On 11/25/2015 03:58 PM, Marc Kleine-Budde wrote:
>>> On 11/25/2015 03:02 PM, Guillaume Picquet wrote:
>>>> 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
>>>
>>>
>>>> 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.
>
>>
>> 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
>>
>> 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
> --
> To unsubscribe from this list: send the line "unsubscribe linux-can" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Setting bitrate from user-space application
2015-12-23 14:03 ` Guillaume Picquet
@ 2015-12-23 14:10 ` Marc Kleine-Budde
0 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2015-12-23 14:10 UTC (permalink / raw)
To: Guillaume Picquet, Oliver Hartkopp, linux-can
[-- Attachment #1: Type: text/plain, Size: 1013 bytes --]
On 12/23/2015 03:03 PM, Guillaume Picquet wrote:
> A status update, thanks to libsocketcan I am able to get and set bitrate.
\o/
> 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.
> 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
--
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 |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2015-12-23 14:11 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-25 14:02 Setting bitrate from user-space application Guillaume Picquet
2015-11-25 14:24 ` Misra Pankaj Kumar (RBEI/EEA2)
2015-11-25 14:58 ` Marc Kleine-Budde
2015-11-25 16:04 ` Oliver Hartkopp
2015-11-25 16:10 ` Marc Kleine-Budde
2015-11-25 16:17 ` Guillaume Picquet
2015-11-28 2:28 ` Tom Evans
2015-12-23 12:07 ` Holger Schurig
2015-12-23 14:03 ` Guillaume Picquet
2015-12-23 14:10 ` Marc Kleine-Budde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).