The definition of timestamp in struct TPCANRdMsg

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
yangming0
Posts: 2
Joined: Tue 17. Jan 2017, 02:21

The definition of timestamp in struct TPCANRdMsg

Post by yangming0 » Tue 17. Jan 2017, 03:55

1. What is the reference of the timestamp in struct "TPCANRdMsg", for example epoch?
2. Is there any C++11 standard library that can provide the same reference of the timestamp in struct "TPCANRdMsg"?
thx

M.Maidhof
Support
Support
Posts: 1753
Joined: Wed 22. Sep 2010, 14:00

Re: The definition of timestamp in struct TPCANRdMsg

Post by M.Maidhof » Tue 17. Jan 2017, 10:47

Hi,

the driver time is based on the Linux Jiffies, see pcan_main.c line 2104 for more details:

Code: Select all

/* request time in msec, fast */
u32 get_mtime(void)
{
	/* return (jiffies / HZ) * 1000; */
	return jiffies_to_msecs(jiffies);
}
regards

Michael

yangming0
Posts: 2
Joined: Tue 17. Jan 2017, 02:21

Re: The definition of timestamp in struct TPCANRdMsg

Post by yangming0 » Wed 18. Jan 2017, 03:49

M.Maidhof wrote:Hi,

the driver time is based on the Linux Jiffies, see pcan_main.c line 2104 for more details:

Code: Select all

/* request time in msec, fast */
u32 get_mtime(void)
{
	/* return (jiffies / HZ) * 1000; */
	return jiffies_to_msecs(jiffies);
}
regards

Michael
Thx for your answer. There is another question: how can I use "get_mtime(void)" or "jiffies_to_msecs(jiffies)" in my code (in user space)?
regards
yangming0

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

Re: The definition of timestamp in struct TPCANRdMsg

Post by S.Grosjean » Wed 18. Jan 2017, 17:35

Hi,

These calls are Kernel specific. If you want to get time in the same way than the pcan driver, your application should use "struct timeval" objects and "gettimeofday()" from standard libc.

Regards,

Stéphane
— Stéphane

psedlos
Posts: 1
Joined: Fri 21. Feb 2020, 11:52

Re: The definition of timestamp in struct TPCANRdMsg

Post by psedlos » Fri 21. Feb 2020, 11:59

As nobody closed this topic, let me ask for advice regard Timestamp - what is best way to convert timestamp to epoch, or any other universla time? Best in Python or Python-supported

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

Re: The definition of timestamp in struct TPCANRdMsg

Post by S.Grosjean » Fri 21. Feb 2020, 15:16

Hi,

TPCANRdMsg struct type defines "dwTime" as a number of milliseconds. This counter is a 32-bit value so it's obvious that it can't contain any epoch time. It should be used to compute delays between received messages only. These types are kept for compatibility only. If you'd like to deal with more modern timestamps, you'll have to switch to the other and newer API of the driver. Please read the documentation provided by the package.

Regards,
— Stéphane

Post Reply