Commit 6c3c03cb authored by nfoy's avatar nfoy
Browse files

remove +10ms delay, allow to set a timestamp to 0 to let the acquisition...

remove +10ms delay, allow to set a timestamp to 0 to let the acquisition server set the timestamp itself, set late tags at the beginning of the current chunk instead of discarding it
parent bc2ca387
......@@ -30,6 +30,8 @@ for i in range(100):
# create the three pieces of the tag, padding, event_id and timestamp
padding=[0]*8
event_id=list(to_byte(EVENT_ID, 8))
# timestamp can be either the posix time in ms, or 0 to let the acquisition server timestamp the tag itself.
timestamp=list(to_byte(int(time()*1000)+DELAY, 8))
# send tag and sleep
......
......@@ -97,6 +97,17 @@ public:
void handleRead(const boost::system::error_code& error)
{
if (!error) {
// If the timestamp is 0, set timestamp to current posix time.
if (m_tag.timestamp==0) {
// Get POSIX time (number of milliseconds since epoch)
timeb time_buffer;
ftime(&time_buffer);
uint64 posixTime = time_buffer.time*1000ULL + time_buffer.millitm;
// edit timestamp
m_tag.timestamp=posixTime;
}
// Push tag to the queue.
m_queuePtr->push(m_tag);
......@@ -231,18 +242,12 @@ void CPluginTCPTagging::loopHook(std::vector < std::vector < OpenViBE::float32 >
// Collect tags from the stream until exhaustion.
while(tagStream.pop(tag)) {
m_rKernelContext.getLogManager() << Kernel::LogLevel_Info << "New Tag received (" << tag.padding << ", " << tag.identifier << ", " << tag.timestamp << ") at " << posixTime << "\n";
// Add 10 ms delay to reduce the risk of a race condition.
// The duration (dt) between the moment when the tag is timestamped and the moment when it is received by the acquisition server is generally small.
// Typically dt<1ms for localhost. Nonetheless it may still happen that timestamp + dt > m_previousPosixTime.
// This would result in a tag loss. The delay allows to compensate for dt. Its value is empirical and should be >= max(dt).
tag.timestamp += 10;
m_rKernelContext.getLogManager() << Kernel::LogLevel_Info << "New Tag received (" << tag.padding << ", " << tag.identifier << ", " << tag.timestamp << ") at " << posixTime << " (posix time in ms)\n";
// Check that the timestamp fits in the time frame.
// Check that the timestamp fits the current chunk.
if (tag.timestamp < m_previousPosixTime) {
m_rKernelContext.getLogManager() << Kernel::LogLevel_Error << "The Tag is discarded because it arrives too late to be inserted in the current signal block\n";
continue;
m_rKernelContext.getLogManager() << Kernel::LogLevel_Warning << "The Tag has arrived before the beginning of the current chunk and will be inserted at the beginning of this chunk\n";
tag.timestamp = m_previousPosixTime;
}
// Marker time correction (simple local linear interpolation).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment