From 74130d7f7111b6587cef448457531178e15f2bec Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Thu, 2 Mar 2023 09:52:53 -0500 Subject: [PATCH] ucdr msg template add timestamp protections - if timestamp (or timestamp_sample) unpopulated fill it with current hrt_absolute_time() - if using provided timestamp don't allow it to exceed current hrt_absolute_time() --- Tools/msg/templates/ucdr/msg.h.em | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tools/msg/templates/ucdr/msg.h.em b/Tools/msg/templates/ucdr/msg.h.em index 59203bb75f..5f68b9256e 100644 --- a/Tools/msg/templates/ucdr/msg.h.em +++ b/Tools/msg/templates/ucdr/msg.h.em @@ -164,7 +164,8 @@ for field_type, field_name, field_size, padding in fields: print('\tmemcpy(&topic.{0}, buf.iterator, sizeof(topic.{0}));'.format(field_name)) if field_type == 'uint64' and (field_name == 'timestamp' or field_name == 'timestamp_sample'): - print('\ttopic.{0} -= time_offset;'.format(field_name)) + print('\tif (topic.{0} == 0) topic.{0} = hrt_absolute_time();'.format(field_name, field_name)) + print('\telse topic.{0} = math::min(topic.{0} - time_offset, hrt_absolute_time());'.format(field_name, field_name)) print('\tbuf.iterator += sizeof(topic.{:});'.format(field_name)) print('\tbuf.offset += sizeof(topic.{:});'.format(field_name))