billvaglienti / ProtoGen

Communications protocol generation software
MIT License
30 stars 16 forks source link

Round floats when converting to int #30

Closed jefffisher closed 8 years ago

jefffisher commented 8 years ago

Currently, a floating point value is encoded like so:

uint8ToBytes((uint8_t)user->Float0, data, &byteindex);
int8ToBytes((int8_t)user->Float1, data, &byteindex);

Both truncate any fractional data. Ideally, that would look more like this:

float32ScaledTo1UnsignedBytes(user->Float0, data, &byteindex, 0, 1.0f);
float32ScaledTo1SignedBytes(user->Float1, data, &byteindex, 1.0f);

Another option, of course, would be to specify the min and/or scaler in my XML file.

billvaglienti commented 8 years ago

The correct way to handle this problem is for the protocol to specify scaler="1.0". Issued addressed by having Protogen generates a warning against possible truncation and suggest the user to set scaler="1.0". Version 1.6.4.