1
votes

Lets say I'd like to have a field named ABC which will be 2 unsigned bytes: 0 to 65535 However, the actual value which is represented is -5.0 to 60.0 with linear conversion between the bits to the actual value.

I have some XML which defines the messages and their elements: the name, location, bits value (min & max), actual value (min & max), how it is stored in the database (XML is output from the database), conversion type.

I'm writing some conversion tool from the XML to LUA format. How should I write the dissector so that I'll see values between -5 to 60 ?

Thank you

1

1 Answers

0
votes

You need to make sure that instead of being uint16 it is float.

local abc_field = ProtoField.uint16("yourproto.abc", "ABC Value")

to:

local abc_field = ProtoField.float("yourproto.abc", "ABC Value")

And when you add the ABC field:

subtree:add(ABC, buf(0, 2))

do the calculation:

subtree:add(ABC, buf(0, 2):bitfield(0, 16) * (65/65536) - 5)