An easy way to manage your CAN network using a C++ OpenSource library.
Last year, I competed with a few teammates in the French Cup of Robotic, and our robot was extensively using CAN, because it’s a really robust and widespread network in embedded systems (and it’s true we didn’t had any trouble with it). The problem I was facing concerned how to manage all those ids and stuff in an efficient way.
I tried to find some solution on the Internet, but didn’t find any that would answer my problem without making me writing different code for the many few architectures we were using (PIC18F, dsPIC, ARM9 …).
So I wrote a small app, that used an XML file to “define” the network architecture (nodes, frames), that automatically generated IDs (using priority, node id and frame id) and exported them in a C Header using #define.
I rewrote it from scratch, implementing a lot of things that were not possible in the first version and improving the overall architecture.
This is now provided as a library under LGPL, with a few tools to exploit it easily.
So, if you have an existing CAN network, or a new one to design, and if you want to write not too static code for embedded systems, and analyze smartly the live feed of your network, CanArch might be helpful for you.
So here is an XML file, it’s the “base”:
There is two parts:
- Configuration (conf): Network name, bitrate, types definition and id generation infos
- Network tree (network): The network is a tree with nodes (devices on the network) which have frames
Hu ? Yeah, in that file you specify the nodes on your network, and the kind of frames that each node can emit.
Then the format of each frame is specified, using types like int or enum, with a bit size that you can specify.
Then you can generate IDs using the policy you specified in the definition file, and you can export it as a C Header like this one:
(well this is actually an export of that (basic.xml) definition file, which is more complex than the simple previous one)
And to handle all the import / export / visualization, there is a nice Qt4 app called NetworkView:
This project is fairly new, if you think you can help, I would be really glad if you do, so please contact me so we can talk about that.
There are lot of things that can be developed to improve this project, I’m thinking about a clean way to handle existing frames and interfaces (using socketcan on Linux for example).
Also, a better support for existing networks, and DeviceNet and other higher level networks based on CAN are ideas I’m thinking about, and I would be glad to share the work, cause I won’t be able to do all that while studying and with my internship coming this winter.
Download / Source
The project page on BitBucket is http://bitbucket.org/corfr/canarch/, you can download the sources from there.
EDIT: CanArch has been renamed from CanOE, since this is a trademark for the Vector CANoe software.