I am currently working on a project that deals with the Publisher and Subscriber. Using Java as the coding language, I want to pass the value of the timestamp on the publisher side and also receive the timestamp at the Subscriber side.
How if I invoke this method: <writer>.register_instance_w_timestamp(instance, s_tstamp) ;
Will it work fine? How will I pass the timestamp here as the argument and how will I get it displayed in the Subscriber output? Is there any need to convert its datatype?
Also what will be the procedure to set the current system clock time as the timestamp rather giving my own timestamp?
Thanking in anticipation!
Normally you do not need to pass your own timestamp. Whenever you call the operation on the DataWriter (e.g. register_instance() or writer()) the Connext library will get the current time automatically and put it as part of the Sample that is sent to the DataReader(s).
The only reason to call the _w_timestamp() operations is if you want to suppy a differerent timestamp from the current one in the system. This is not a common scenario.
Either way the source timestamp is available when you receive the sample. This can be found in the source_timestamp field of the SampleInfo.
You do not need to convert the formats. The application handles the time stamp using the Time_t class. This will be automatically marshalled/demarshalled by DDS.
One thing to keep in mind is that the time origin for the Time_t is represented by the reserved value TIME_ZERO and corresponds to the UNIX prime epoch 0h, 1 January 1970. Unfortunately this is not clearly documented in the API docs.
Thanks for replying. But I am not able to figure out how to retrieve this timestamp from SampleInfo? What will be the code required for it?
Consider if I am using the write() method, how should I get the value of the source timestamp on publisher side and reception timestamp on the Subscriber side?
Can I please get a code snippet that implements the retrieval of timestamps from the SampleInfo.
In Subcriber file, I have added this line:
double mytime = _infoSeq.get(i).reception_timestamp.sec + (_infoSeq.get(i).reception_timestamp.nanosec/NANOSECOND);
System.out.println(mytime);
Also added the following line before the main method:
static double NANOSECOND = 1000000000.0;
The output of the subsciber file includes timestamp in this format:
1.5397802978029897E9
How to convert it into mm:ss format? or is there any other way to print the timestamp in the output?
So nice of you!!
Thanks very much!! Now I got the time in a readable format.