From 2b3226393cf5277e5f38b9df8c6ce7ad9a96bb00 Mon Sep 17 00:00:00 2001 From: Simon Hancock Date: Tue, 26 Sep 2023 12:09:37 +0100 Subject: [PATCH] WLua: Cleaner presentation of date --- generator/mavgen_wlua.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/generator/mavgen_wlua.py b/generator/mavgen_wlua.py index fab48d58a..da575fb88 100644 --- a/generator/mavgen_wlua.py +++ b/generator/mavgen_wlua.py @@ -66,7 +66,18 @@ def generate_preamble(outf): end local signature_time_ref = get_timezone() + os.time{year=2015, month=1, day=1, hour=0} -time_usec_threshold = UInt64.new(0,4096) +-- threshold to decide if time is absolute or relative (roughly 13.5 months from epoch) +time_usec_threshold = UInt64.new(0,8192) +-- function to append human-readable time onto unix_time_us fields +local function append_time(subtree,value) + if value > time_usec_threshold then + d = os.date("%Y-%m-%d %H:%M:%S",value:tonumber() / 1000000.0) + us = value % 1000000 + us = string.format("%06d",us:tonumber()) + tz = os.date(" %Z",value:tonumber() / 1000000.0) + subtree:append_text(" [" .. d .. "." .. us .. tz .. "]") + end +end payload_fns = {} @@ -275,9 +286,7 @@ def generate_field_dissector(outf, msg, field, offset, enums, cmd=None, param=No if tvb_func == "le_uint64" and field.name in ["time_usec","time_unix_usec"]: t.write(outf, """ - if value > time_usec_threshold then - subtree:append_text(" [" .. format_date(value:tonumber() / 1000000.0) .. "]") - end + append_time(subtree,value) """) if enum_obj and enum_obj.bitmask: