projecthorus / horusdemodlib

High Altitude Balloon Telemetry Library
GNU Lesser General Public License v2.1
58 stars 26 forks source link

Add string and hex to custom payload decoder #267

Open sp9uob opened 3 months ago

sp9uob commented 3 months ago

Hi,

Can you add hex and/or binary field postprocessing for custom payload data section. That can be useful when sending binary flags from payload.

Also I want to transmit ITU prefix from payload - so n byte string field can be also usefull (for example 2s - 2 byte string).

TIA. TOM.

darksidelemm commented 3 months ago

This will be a bit complicated to do, but not impossible.

I'll also need to think about how this will impact receivers running old versions of horusdemodlib - unfortunately it looks like the way i've written the custom field handler, if theres a field type that isn't known, it will cause an error and I think the entire packet will not be decoded. I can fix that so that unknown types are ignored, but its going to require everyone to update...

darksidelemm commented 3 months ago

I thought that strings might have already worked, but i think they won't because of this line: https://github.com/projecthorus/horusdemodlib/blob/master/horusdemodlib/delegates.py#L191 If you include a string in the struct (e.g. 2s), that will get decoded as bytes, which will cause an error. So again, this is something that is going to require a large update to fix :(

sp9uob commented 3 months ago

I thought that strings might have already worked, but i think they won't because of this line: https://github.com/projecthorus/horusdemodlib/blob/master/horusdemodlib/delegates.py#L191 If you include a string in the struct (e.g. 2s), that will get decoded as bytes, which will cause an error. So again, this is something that is going to require a large update to fix :(

Yeah, I've already tried that.

sp9uob commented 3 months ago

I think that this issue can be resolved by adding a second custom field file. So the new version can check if a second file with more flexible fields exists and perform required actions.

darksidelemm commented 3 months ago

Yes, that might have to be the workaround... not entirely happy about that, but it might have to do.

As for handling bitfields, this gets a bit complicated, as i'll probably need to bring in a library like bitstruct, and then have some kind of nested definitions... Not quite sure of the best way to handle that in the json file yet.

sp9uob commented 3 months ago

It doesnt have to be a bitfield. Just take byte and display it in binary representation :-)