ttlappalainen / NMEA0183

Library for handling NMEA0183 messages
76 stars 48 forks source link

NMEA0183SetDPT: Limit depth and offset to two decimal places after comma. #44

Closed Andrei-Errapart closed 1 year ago

Andrei-Errapart commented 1 year ago

Rationale: this is useful in cases when the depth is computed and can have many places after comma. To the best of my knowledge, in nautical applications centimeter precision is sufficient.

ttlappalainen commented 1 year ago

Do you really need 2 decimals instead of default 1?

Andrei-Errapart commented 1 year ago

Yes. The digital files we produce when surveying small harbors are all centimeter precision.

Actually I don't want to force this decision on the library, because users have different requirements for the precision.

Would an overload of NMEA0183SetDPT, with an additional parameter "int numberOfDecimalPlaces", be a way out?

ttlappalainen commented 1 year ago

That may be better. There has been problems with some devices that they are strict of number of decimals.

You could make it with alias: bool NMEA0183SetDPT(tNMEA0183Msg &NMEA0183Msg, double DepthBelowTransducer, double Offset, double Range, const char DepthFormat, const char Src="II");

inline bool NMEA0183SetDPT(tNMEA0183Msg &NMEA0183Msg, double DepthBelowTransducer, double Offset, double Range, const char *Src="II") { NMEA0183SetDPT(NMEA0183Msg,DepthBelowTransducer,Offset,Range,tNMEA0183Msg::DefDoubleFormat,Src); }

Andrei-Errapart commented 1 year ago

There are now new aliases. I dropped the default values for Source for the new aliases, because otherwise the compiler is unable to decide between aliases to call.

ttlappalainen commented 1 year ago

Other option is to use different order: bool NMEA0183SetDPT(tNMEA0183Msg &NMEA0183Msg, const char DepthFormat, double DepthBelowTransducer, double Offset, double Range, const char Src="II");

Andrei-Errapart commented 1 year ago

Reordered differently and simplified by dropping two overloads.