QCanBusFrame::TimeStamp is time since Windows has started?
-
reference to: QCanBusFrame timestamp
Hi
I experimented with Peak Can USB and QCanBusFrame and played with the field timestamp. It is great that the class automatically adds a timestamp to a received message, but what time is that?
By experimenting I found out, that this is obviously microseconds since Windows was bootet up. Would it be more convenient, if the timestamp would be microseconds(or milliseconds) since Epoch? I am interested in the absolute time, the frame was received. Then I would be able to convert Timestamp into QDateTime.There is a possibility to obtain the time since windows has started by using sysinfoapi.h and GetTickCount(). I got an even stranger result:
void CanPeak::framesReceived(){ QVector<QCanBusFrame> frames = device->readAllFrames(); for(int a=0;a<frames.size();a++){ QCanBusFrame::TimeStamp tmst1= frames[a].timeStamp(); uint32_t time = GetTickCount(); qint64 tm1 = tmst1.seconds()*1000+tmst1.microSeconds()/1000; qDebug()<<"Timestamp:"<<tm1<<" TickCount:"<<time<<" difference"<<(time-tm1);
Result is:
Timestamp: 2614183 TickCount: 2614031 difference -152
This function is a slot, connected to "Frames Received". I extract the timestamp and calculate it down to milliseconds. Then I pull milliseconds since windows start by using "GetTickCount" (also ms). Now I output both numbers and the result is, that GetTickCount (taken later) is lower than Timestamp by 152 ms????
the timestamp of the received can message is 152ms in the future?
If anyone could explain, how the timestamp on QCanBusFrame is created, this would be of great help.
- How to properly convert timestamp into absolute time since epoch. ?
As a workaround, I would add my own absolute timestamp to received can frames by using
QDateTime::currentDateTime().toMSecsSinceEpoch() / *1000;
Many thanks in advance.
Johannes -
This timestamp reported from the PeakCan driver (there are each received message already contain an additional filed with the timestamp) . You can ask your question about on the PeakCan forums.
Seems that this timestamp is:
The time-stamp contains the number of microseconds since the start of Windows.
see https://documentation.help/PCAN-Basic/documentation.pdf page #100.
-
I am using PEAKcanUSB
I "solved" this issue by using the function "GetTickCount from sysinfoapi.h
This returns ms since system start.
To convert a QCanBusFrame timestamp into QDateTime, I use QDateTime::currentDateTime.toMsecSinceEpoch and subtract "GetTickCount()"
Now I have the offset between QDateTime and TimestampThis works quite well, but not always.
If I use my computer in energy-saving mode and dock it to my docking station, this time sometimes adds a strange offset of 3 seconds.
When I reboot my computer, this offset is gone.If anyone knows, which windows functions PEAK System uses to obtain the current timestamp to put into the Canbusframes, this would be great.
I would like to obtain the "ms since system start" the same way, PEAK does. I hope to get rid of this sterange offset by that.