diff --git a/generator/mavgen_wlua.py b/generator/mavgen_wlua.py index 1960c6d66..f9dc3324f 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 = {} @@ -276,9 +287,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: