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. 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); 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 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. Cheers Luotao Fu -- Pengutronix e.K. | Dipl.-Ing. Luotao Fu | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ Socketcan-users mailing list [email protected] https://lists.berlios.de/mailman/listinfo/socketcan-users
