Ask Your Question
0

dissecting protocol in lua

asked 2025-07-16 13:16:36 +0000

BMWE gravatar image

Hi,

I have a field which is 4 bytes: 8020f912 which represents latitude in radians and resolution of 2^-29. Also this is motorola format.

meaning, the data shall be taken as hex2dec(12f92080) * 2^-19 = 0.5*3067626 rad = 34deg how to i write the diessction properly?

f.Lat = ProtoField.string("data.Lat", "Lat",base.dec)
...
subtree:add_le(f.Lat,buffer(x,4), string.format("%f,buffer(x,4):uint()*2^-32) )

I guess that uint() shall be handled differently but don't know how

edit retag flag offensive close merge delete

Comments

Is this the calculation(?):

print(tonumber("0x12f92080") * 2^-29 * 180 / math.pi)

33.971298214514
Chuckc gravatar imageChuckc ( 2025-07-16 16:44:33 +0000 )edit

The number provided is an example. I need generic solution for different values - note that tere is a need to change the order of the bytes

BMWE gravatar imageBMWE ( 2025-07-16 16:54:20 +0000 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2025-07-16 17:47:24 +0000

Chuckc gravatar image

updated 2025-07-16 17:49:53 +0000

    lat_data = tvb(42,4):le_uint()
    lat_string = string.format("%f", lat_data * 2^-29 * 180 / math.pi)
--    subtree:add(pf.Lat, tvb(42,4), string.format("%x", lat_data))
    subtree:add(pf.Lat, tvb(42,4), lat_string
Data (4 bytes)
    Data: 8020f912
    [Length: 4]
Important EASYPOST Protocol
    Lat: 33.971298

My sample capture was created from 0000 80 20 f9 12 hex import with a udp header..
42 is the offset to UDP data.

edit flag offensive delete link more

Comments

Thanks you!

BMWE gravatar imageBMWE ( 2025-07-16 20:57:50 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-07-16 13:16:36 +0000

Seen: 30 times

Last updated: Jul 16