How to properly obtain TX timestamps

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
Markus.Sigg
Posts: 2
Joined: Thu 23. Jan 2020, 10:41

How to properly obtain TX timestamps

Post by Markus.Sigg » Wed 29. Jan 2020, 11:16

Hello,
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.
  1. Open a socket that receives its own sent messages (see 4.1.4)
  2. Enable SOF_TIMESTAMPING_TX_SOFTWARE for this socket
  3. Send a sync message using the write or sendmsg function
  4. Receive the sync message using the recvmsg function (similar to candump.c)
  5. Obtain the TX timestamp from the ancillary data provided in the control message block of the received message header (similar to candump.c)
My question is now, if this is the proper way to obtain TX timestamps. In my opinion this is a bit fuzzy. As I read in this post, PCAN-Basic does not provide this functionality at all and PCAN-Developer 4 seems not to be available for Linux.
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

User avatar
S.Grosjean
Software Development
Software Development
Posts: 352
Joined: Wed 4. Jul 2012, 17:02

Re: How to properly obtain TX timestamps

Post by S.Grosjean » Wed 29. Jan 2020, 14:06

Hello Markus,

AFAIK there is no other way to get a TX timestamp than the one you've described with the socket-CAN API.

Those hw tx timestamps are not supported by the peak_usb driver: your socket-can application will receive "local software" TX timestamps only, corresponding roughly to the time the CAN frame has been given to the USB core of the kernel.

However, this is possible with our pcan driver: you can get an "echoed" message with a HW TX timestamp for each message your application sends.

Regards,
— Stéphane

Markus.Sigg
Posts: 2
Joined: Thu 23. Jan 2020, 10:41

Re: How to properly obtain TX timestamps

Post by Markus.Sigg » Thu 30. Jan 2020, 16:27

Thanks for your fast reply!!!

So, what you suggest is:
  • to stick with my solution
or, if HW TX timestamps are needed:
  • use the pcan chardev driver with the low level API from libpcanfd.h shipped with the driver?
Hope, I got this right. So, no PCAN-Basic invovled here?

Thanks again and best regards,
Markus

User avatar
S.Grosjean
Software Development
Software Development
Posts: 352
Joined: Wed 4. Jul 2012, 17:02

Re: How to properly obtain TX timestamps

Post by S.Grosjean » Fri 31. Jan 2020, 12:08

Hi Markus,

Nope, PCAN-Basic doesn't include this functionality at all.

Yes, you can use the (new) API of the pcan driver which is close to the socket one (IMHO).

FYI we should soon include this "echo" facility in the peak_usb driver. If you're ok to test it, please send your email address to linux@peak-system.com and we will send you a beta version of the modified version of the peak_usb driver as soon as it is operational. Your feedback will be important before pushing the changes to the maintainers list.

Regards,
— Stéphane

Pe3ucTop
Posts: 3
Joined: Fri 13. Mar 2020, 10:08

Re: How to properly obtain TX timestamps

Post by Pe3ucTop » Fri 13. Mar 2020, 10:29

Hello PEAK-Systems.

Do you plan to extend PCAN-Basic functionality to include "echo" or "self receive" options?

I have PEAK USB FD device.
I tried to use socketcan with linux native driver and peak-basic with peak-linux-driver.
I miss ability to receive own sent messages in peak-basic (interested in timestamp of sent messages).
I would return to socketcan , but I do need to port program to windows.

Could you suggest possible solution to get timestamp of sent message, which would have equal realization in linux and windows?

Best regards,
Maksims M.

M.Heidemann
Sales & Support
Sales & Support
Posts: 1072
Joined: Fri 20. Sep 2019, 13:31

Re: How to properly obtain TX timestamps

Post by M.Heidemann » Mon 16. Mar 2020, 11:58

Hello,

To quote the previous post by my colleague Stéphane:
... PCAN-Basic doesn't include this functionality at all.
This feature is not implemented in PCANBasic.

This feature is included in our PCAN-Delevoper 4 package we supply for windows environments:

https://www.peak-system.com/PCAN-Developer-4.461.0.html


A possible solution for linux would be to implment this using SocketCAN (See the post by Markus.Sigg)


Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

Pe3ucTop
Posts: 3
Joined: Fri 13. Mar 2020, 10:08

Re: How to properly obtain TX timestamps

Post by Pe3ucTop » Wed 18. Mar 2020, 09:44

Hello,

Thanks for your answer and I still have some question.
Could you please describe difference between "SelfReceive" and "Echo" of message type?
I noticed, in driver source :
pcan.h only have :

Code: Select all

#define MSGTYPE_SELFRECEIVE   0x04     // self-received message
but pcanfd.h have both:

Code: Select all

#define PCANFD_MSG_SLF          0x00000004
#define PCANFD_MSG_ECHO         0x00000010
I'm using CANFD and would like to understand which parameter to use for correct behavior.

Thanks for suggestion, but "PCAN-Delevoper 4 package" is too expensive for my needs, especial because I'm using Linux most of the time.
And it still platform dependent, and "socketcan" too.
M.Heidemann wrote:
Mon 16. Mar 2020, 11:58
To quote the previous post by my colleague Stéphane:
... PCAN-Basic doesn't include this functionality at all.
This feature is not implemented in PCANBasic.
Yes, I noticed it, but question is 'Do you plan to extend PCAN-Basic functionality to include "echo" or "self receive" options?"
Because, for PCAN Basic (linux) it is just 2~3 lines of code in library to pass ' PCANFD_MSG_ECHO ' flag. I tried it, and it work nice for me.
But I'm still interested in PCAN Basic Windows version, which unfortunately is not open source and only You (PEAK-Systems) could make those changes.

Best regards,
Maksims M.

User avatar
S.Grosjean
Software Development
Software Development
Posts: 352
Joined: Wed 4. Jul 2012, 17:02

Re: How to properly obtain TX timestamps

Post by S.Grosjean » Wed 18. Mar 2020, 11:29

Hello,

The difference is subtle: the _SLF flag is historically the equivalent of the _SRR command of the SJA1000 that requests a transmission onto the CAN bus as well as a copy of the sent frame into its internal Rx fifo.
The _ECHO flag is (only) available with our CAN FD devices and allows the application to set its own flag to differentiate from one _SLF frame with the other.

If you want to deal with TX timestamps, then you should set the _SLF flag first.

Regards,
— Stéphane

M.Heidemann
Sales & Support
Sales & Support
Posts: 1072
Joined: Fri 20. Sep 2019, 13:31

Re: How to properly obtain TX timestamps

Post by M.Heidemann » Wed 18. Mar 2020, 11:41

Hello Maksims,

Regarding the functionality of self-reception (or "Echo") in PCAN-Basic:

We do not plan to extend the PCANBasic API to include this feature.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

Post Reply