Open chrysn opened 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)
).
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:
UNIT_DATE
, UNIT_TIME
and UNIT_TEMP_F
seem to be unused. UNIT_BAR
, UNIT_GPM3
and UNIT_GS
are used but can be converted using an adjustment of scale.UNIT_G
needs a multiplication using gravitational acceleration.UNIT_CPM3
(count per cubic meter, used in sps30
and hm330x
) and UNIT_DPS
(degree per second, used in various sensors) are used and have no base unit equivalent.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.
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
.
Thanks, good split; two remarks:
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
phydat_unit_to_str
that maps precisely to a SenML name if one is defined.Links