RIOT-OS / RIOT

RIOT - The friendly OS for IoT
https://riot-os.org
GNU Lesser General Public License v2.1
4.97k stars 1.99k forks source link

phydat units: Align with SenML #17571

Open chrysn opened 2 years ago

chrysn commented 2 years ago

Description

SenML is maintaining a good list of IoT base units at https://www.iana.org/assignments/senml/senml.xhtml (along with secondary units that are affine transformations of the base units).

Phydats unit list is a much more unmanaged (literally "extend this list as needed") collection contains many of these, but unlike SenML contains no guidance as to which are preferred, and worse, has no well-described way of getting the types out to interoperate. (phydat_unit_to_str{,_verbose} do not claim compliance with any scheme).

Proposed way forward

Links

chrysn commented 2 years ago

@silkeh, given you've worked a lot in this area, I'd appreciate your input on this. In particular, do you think it'd make sense to pull all defined SenML units into phydat? (For #16384 that could allow unifying these types, and would make the currently big-switch-statement list of which phydat units have a corresponding SenML unit a simple if (unit < UNIT_END_SENML)).

silkeh commented 2 years ago

do you think it'd make sense to pull all defined SenML units into phydat?

Yes, I think that makes a lot of sense to follow the standardized SenML unit list. It both clarifies the use of the units in RIOT OS, and greatly improves the maintainability of the SenML code. The proposed way forward seems sensible to me as well.

As for deprecating/migrating units: the complexity of this varies:

chrysn commented 2 years ago

Thanks.

g and F probably both can go into the bucket of bar, g/m³, Gs by being non-SenML units but having known affine transformations to primary units, and could become secondary units if anyone went through the IANA procedure. (Not a fan of F, but I can see how g is somewhat practical around accelerometers).

The CPM (/m³) and DPS (°/s) could probably even become primary and secondary units, respectively (the latter for rad/s).

Given #16384 is in rather good a shape and approaching completion, I for one would hold off on actually tackling this until that's in, unless you prefer it the other way 'round.

silkeh commented 2 years ago

Ok, so for a migration to the SenML units, I think we would need the following SenML primary units:

Symbol Description Type
1/m3 1 per cubic meter float
rad/s radian per second float

And the following secondary units:

Symbol Description SenML Unit Scale Offset
deg/s degree per second rad/s π/180 0
g-force gravitational force equivalent m/s2 9.80665 0

We could request bar, gram/m³ or gauss as secondary units, but I think it makes more sense to convert these to pascal, kg/m³ and tesla within RIOT-OS itself. Fahrenheit is not used, so I would propose to remove it entirely.

I'm open for suggestions for something better than g-force.

chrysn commented 2 years ago

Thanks, good split; two remarks: