Skip to content

Commit

Permalink
Mavgen WLUA: Fix incorrect display of negative ints on mac
Browse files Browse the repository at this point in the history
Fix is to not include the value argument when calling add_le function, and let Wireshark
do the value extraction internally. This avoids an issue where a double being cast to
a unsigned int (which should have been an int), becomes 0 on mac, but works on Linux.

The value argument is still required in the case when a float is used to represent an
enum or bitmask.
Also, value is used seperately when adding unit conversions and when doing any bitmask
extraction
  • Loading branch information
shancock884 committed Apr 29, 2024
1 parent 7b72995 commit a859842
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion generator/mavgen_wlua.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,37 @@ def generate_field_dissector(outf, msg, field, offset, enums, cmd=None, param=No
else:
field_var = t.substitute("${fmsg}_${fname}${findex}", {'fmsg': msg.name, 'fname': field.name, 'findex': index_text})

t.write(outf,
# If there is an associated enum and the datatype is not uint, we need to extract
# and pass the value to add_le, as the raw and ProtoField types will not match.
# This occurs in the case of using a command field to represent an enum or bitmask
if enum_obj and tvb_func != "le_uint":
value_extracted = True
t.write(outf,
"""
tvbrange = padded(offset + ${foffset}, ${fbytes})
value = tvbrange:${ftvbfunc}()
subtree = tree:add_le(f.${fvar}, tvbrange, value)
""", {'foffset': offset + i * size, 'fbytes': size, 'ftvbfunc': tvb_func, 'fvar': field_var})
else:
value_extracted = False
t.write(outf,
"""
tvbrange = padded(offset + ${foffset}, ${fbytes})
subtree = tree:add_le(f.${fvar}, tvbrange)
""", {'foffset': offset + i * size, 'fbytes': size, 'ftvbfunc': tvb_func, 'fvar': field_var})

unit = field.units.replace("[","").replace("]","")
global unit_decoder_mapping
if unit in unit_decoder_mapping:
if not value_extracted:
t.write(outf," value = tvbrange:${ftvbfunc}()\n", {'ftvbfunc': tvb_func})
value_extracted = True
t.write(outf," subtree:append_text(" + unit_decoder_mapping[unit] + ")\n")

if enum_obj and enum_obj.bitmask:
if not value_extracted:
t.write(outf," value = tvbrange:${ftvbfunc}()\n", {'ftvbfunc': tvb_func})
value_extracted = True
valuemethod = ":tonumber()" if tvb_func == "le_uint64" else ""
t.write(outf,
"""
Expand Down

0 comments on commit a859842

Please sign in to comment.