How to create a uint24 data type

asked 2018-07-24 12:18:54 -0500

AnkilP gravatar image

We're trying to read a radar udp packet and one of the data types is of a uint24 type. We were thinking of a couple solutions:

We could create a msg like so:

uint8[3] data

OR

uint8 data1

uint8 data2

uint8 data3

OR

we could create a new struct that could read in this data.

Does ROS have any ros-centric socket library, by any chance?

edit retag flag offensive close merge delete

Comments

1

Is shoving it into a UInt32 that wasteful? (Are there a lot of uint24s in every packet?).

lucasw gravatar image lucasw  ( 2018-07-24 12:36:11 -0500 )edit

If you want a generic ros node to send and receive network packets that belongs in a separate question- it would be very useful if someone were to make one if it doesn't already exist. #q298232 is similar but it and the answer are for TCP, but it could be extended to support either.

lucasw gravatar image lucasw  ( 2018-07-24 12:37:06 -0500 )edit

I agree, put it in a uint32. uint24 isn't a native type to any system, it's just a truncated uint32 used for storage/transport. The compiler will probably word align the data anyway, so it'll take up exactly the same amount of space.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-07-24 12:53:42 -0500 )edit

yeah that was our first solution, however, the rest of the data have strict bit position requirements. Interestingly enough, there's only two 24 bit entries

AnkilP gravatar image AnkilP  ( 2018-07-24 13:02:33 -0500 )edit

You're not trying to have union of raw bytes from the network and ros msg are you? You need to peel apart the source data, convert individual fields as necessary, and populate a ros message field by field. If there is a big array that could go straight across though, like the uint8[] data in Image

lucasw gravatar image lucasw  ( 2018-07-24 15:19:10 -0500 )edit