I am playing around with can on Linux and I can send and receive frames using cansend: https://github.com/linux-can/can-utils/blob/master/cansend.c
I was wondering if there is a mechanism to prioritize certain Messages on TX using socketcan?
For Example in CanOpen it is common practice to have two tx message buffers one high priority for emergency and sync and one for all the other traffic. Most Can Controllers can configure multiple tx message buffers which work like a ringbuffer.
The goal is that when the low priority queue is filled up and you implement a sync producer the sync frame gets on the bus as fast as possible. Meaning when there are 20 frames in the non priority queue and a packet is written to the priority queue the controller finishes transmitting the current loaded frame and continues sending the prioritized queue until its empty and then continues pulling packets from the non prioritized queue.
Thanks to @Hasturkun
This is exactly the mechanism to do this.
The only confusion i had was that: Some where was mentioned the priority is 0 to 7. 0 means best and 7 means lowest. This is not the priority meant to put in SO_PRIORITY. There is a Priority map:
So according to this map it is read like this:
So this is how i configured my can Interface:
Here is an example code that worked to illustrate that the high_fd is prioretised over the low_fd:
This is the output on the Bus when prio_low is 2 => 2 and prio_high is 0 => 1
This is the output if prio low is 7 => 0 and prio high is 0 => 1: