I'm using PCAN-USB FD and/or X6 devices on my Linux machine. On OS side I'm using Linux kernel 4.15 and the mainline peak_usb driver. In my application I'm then using the standard socketcan API to send and receive CAN messages.
In order to implement a timesync mechanism, I do need to know the TX timestamp of some messages as exact as possible. After some investigation I came up with following solution.
- Open a socket that receives its own sent messages (see 4.1.4)
- Enable SOF_TIMESTAMPING_TX_SOFTWARE for this socket
- Send a sync message using the write or sendmsg function
- Receive the sync message using the recvmsg function (similar to candump.c)
- Obtain the TX timestamp from the ancillary data provided in the control message block of the received message header (similar to candump.c)
Also I'm not able to get any HW TX timestamp using the method described. Is this not supported by the mainline driver?
Thanks a lot for any help/advise/etc.
Cheers,
Markus