Wolfgang Grandegger wrote:
> Hi Fu,
> 
> Luotao Fu wrote:
>> Hi folks,
>>
>> I was trying to integrate socketcan control in an application the last days 
>> and
>> spent quite a lot of time getting clear how to deal with the netlink 
>> interface.
> 
> I can image. Such a library is on my to-do list since a long time, but
> so far I didn't find enough time to implement it. Thanks for the effort.
> 
>> Besides I just couldn't remember the correct order of parameter when using 
>> the
>> iproute tool for can ;-). So I stripped some code from the iproute package 
>> and
>> put them with some own stuffs together in a library to access can 
>> configuration
>> functions with netlink, which I call libsocketcan-nl. (nl stand for netlink, 
>> not
>> netherland ;-)). The library provides some simple APIs to do common CAN 
>> stuffs,
>> lacking of a proper documentation I'll start here with the content of the 
>> header
>> file:
>> int scan_set_restart(const char *name);
> 
> scan_do_restart() would be more appropriate.
> 
>> int scan_set_bitrate(const char *name, __u32 bitrate);
>> int scan_set_restart_ms(const char *name, __u32 restart_ms);
>> int scan_set_ctrlmode(const char *name, __u32 mode, __u32 flags);
>>
>> int scan_get_state(const char *name, int *state);
>> int scan_get_restart_ms(const char *name, __u32 *restart_ms);
>> int scan_get_bittiming(const char *name, struct can_bittiming *bt);
>> int scan_get_ctrlmode(const char *name, struct can_ctrlmode *cm);
>>
>> Usage is quite straight forward. The functions await simply the name of the 
>> can
>> interface and, if any, configuration values and return 0 for success and -1 
>> if
>> something went wrong.
>>
>> This library provides some benefits, which the hookup code in iproute 
>> doesn't do:
>> * more clear error messages and takes care of special cases, e.g. restarting 
>> a
>> device can only be done while the interface is in BUS_OFF. Neither kernel nor
> 
> Hm, you cannot restart the device when it's not bus-off. The driver does
> not allow that. See:
> 
> http://lxr.linux.no/#linux+v2.6.31/drivers/net/can/dev.c#L376
> 
>> the iproute tool provides some useful hint if restarting failed.
>> * simple portabilty
>> * API for use in own applications.
>>
>> I updated the canutils tool to make use of this library. Now we can finally
>> again use the canconfig tool with really simple parameters:
>>
>> r...@target:~ canconfig can0
>> can0 bitrate: 250000
>> can0 state: ACTIVE
>> can0 restart_ms: 1000
>> can0 mode: loopback[OFF], listen-only[OFF], tripple-sampling[OFF]
>>
>> Setting works as well, usage is just like in the older versions:
>>
>> r...@target:~ canconfig can0 bitrate 125000
>> can0 bitrate: 125000
>> r...@target:~ canconfig can0 mode loopback on
>> can0 mode: loopback[ON], listen-only[OFF], tripple-sampling[OFF]
>>
>> and so on.
>>
>> The repository of the library can be obtained at
>> git://git.pengutronix.de/git/tools/libsocketcan-nl.git
>> Repo of Canutils can be found at
>> git://git.pengutronix.de/git/tools/canutils.git
>>
>> Additionally I put the recent version of the library and the tool in our ftp
>> server. They might stay there only as long as as I don't have a proper 
>> webspace
>> for the stuff:
>> ftp://ftp.pengutronix.de/pub/socketcan/
>>
>> The library is still not complete. For example there's still no documentation
>> for this, also we are only able to set the bitrate, but not the bittimings. I
>> will add these stuffs later.
>>
>> Comments, tests and reviews are highly welcome.
> 
> That's great news for the CAN users, especially if they want to do a
> manual restart of the CAN devices from their application. We should add
> the libsocketcan and canconfig to the SVN trunk a.s.a.p., or some more
> appropriate place, e.g. GIT at BerliOS (or kernel.org). I will do some
> testing when time permits.

please don't add it to a svn, IMHO a seperate git is a good place.

cheers,

Marc
-- 
Pengutronix e.K.                         | Marc Kleine-Budde           |
Linux Solutions for Science and Industry | Phone: +49-231-2826-924     |
Vertretung West/Dortmund                 | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686         | http://www.pengutronix.de   |

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Socketcan-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users

Reply via email to