diff --git a/drivers/adxl345/adxl345_saul.c b/drivers/adxl345/adxl345_saul.c index 432e249595c5..594961e8d94a 100644 --- a/drivers/adxl345/adxl345_saul.c +++ b/drivers/adxl345/adxl345_saul.c @@ -25,7 +25,7 @@ static int read_acc(const void *dev, phydat_t *res) { adxl345_read((const adxl345_t *)dev, (adxl345_data_t *)res->val); - res->unit = UNIT_G; + res->unit = UNIT_G_FORCE; res->scale = -3; return 3; } diff --git a/drivers/bmx055/bmx055_saul.c b/drivers/bmx055/bmx055_saul.c index a84cd8e15fff..5d738b8e3342 100644 --- a/drivers/bmx055/bmx055_saul.c +++ b/drivers/bmx055/bmx055_saul.c @@ -29,7 +29,7 @@ static int read_mag(const void *dev, phydat_t *res) if (bmx055_mag_read(mydev, res->val) != BMX055_OK) { return 0; } - res->unit = UNIT_GS; + res->unit = UNIT_GAUSS; res->scale = 0; return 3; } @@ -41,7 +41,7 @@ static int read_acc(const void *dev, phydat_t *res) if (bmx055_acc_read(mydev, res->val) != BMX055_OK) { return 0; } - res->unit = UNIT_G; + res->unit = UNIT_G_FORCE; res->scale = -3; return 3; } diff --git a/drivers/fxos8700/fxos8700_saul.c b/drivers/fxos8700/fxos8700_saul.c index e9954f9461b5..7a46b5864c13 100644 --- a/drivers/fxos8700/fxos8700_saul.c +++ b/drivers/fxos8700/fxos8700_saul.c @@ -31,7 +31,7 @@ static int read_mag(const void *dev, phydat_t *res) /* Read failure */ return -ECANCELED; } - res->unit = UNIT_GS; + res->unit = UNIT_GAUSS; res->scale = -3; return 3; } @@ -48,7 +48,7 @@ static int read_acc(const void *dev, phydat_t *res) res->scale = 0; } else { - res->unit = UNIT_G; + res->unit = UNIT_G_FORCE; if (((fxos8700_t *)dev)->p.acc_range == FXOS8700_REG_XYZ_DATA_CFG_FS__2G) { res->scale = -4; } diff --git a/drivers/hmc5883l/hmc5883l_saul.c b/drivers/hmc5883l/hmc5883l_saul.c index 63cf50de5fce..ae1b5e2d82f9 100644 --- a/drivers/hmc5883l/hmc5883l_saul.c +++ b/drivers/hmc5883l/hmc5883l_saul.c @@ -28,7 +28,7 @@ static int read(const void *dev, phydat_t *res) res->val[0] = data.x; res->val[1] = data.y; res->val[2] = data.z; - res->unit = UNIT_GS; + res->unit = UNIT_GAUSS; res->scale = -3; return 3; } diff --git a/drivers/lis2dh12/lis2dh12_saul.c b/drivers/lis2dh12/lis2dh12_saul.c index 5fe3d319c89f..6f4f574af927 100644 --- a/drivers/lis2dh12/lis2dh12_saul.c +++ b/drivers/lis2dh12/lis2dh12_saul.c @@ -26,7 +26,7 @@ static int read_accelerometer(const void *dev, phydat_t *res) if (lis2dh12_read(dev, (lis2dh12_fifo_data_t*)res->val) != LIS2DH12_OK) { return 0; } - res->unit = UNIT_G; + res->unit = UNIT_G_FORCE; res->scale = -3; return 3; } diff --git a/drivers/lis3dh/lis3dh_saul.c b/drivers/lis3dh/lis3dh_saul.c index 03cb933a098a..bbf6bd94e4ac 100644 --- a/drivers/lis3dh/lis3dh_saul.c +++ b/drivers/lis3dh/lis3dh_saul.c @@ -39,7 +39,7 @@ static int read_acc(const void *dev, phydat_t *res) res->val[2] = xyz.acc_z; /* unit: milli-G */ res->scale = -3; - res->unit = UNIT_G; + res->unit = UNIT_G_FORCE; return 3; } diff --git a/drivers/lis3mdl/lis3mdl_saul.c b/drivers/lis3mdl/lis3mdl_saul.c index 93efec2ecbf3..92c95c6a079e 100644 --- a/drivers/lis3mdl/lis3mdl_saul.c +++ b/drivers/lis3mdl/lis3mdl_saul.c @@ -29,7 +29,7 @@ static int read_mag(const void *dev, phydat_t *res) lis3mdl_read_mag(d, (lis3mdl_3d_data_t *)res); - res->unit = UNIT_GS; + res->unit = UNIT_GAUSS; res->scale = -3; return 3; } diff --git a/drivers/lsm303dlhc/lsm303dlhc_saul.c b/drivers/lsm303dlhc/lsm303dlhc_saul.c index 461ad66f05d2..f89b31f7f85b 100644 --- a/drivers/lsm303dlhc/lsm303dlhc_saul.c +++ b/drivers/lsm303dlhc/lsm303dlhc_saul.c @@ -34,7 +34,7 @@ static int read_acc(const void *dev, phydat_t *res) res->val[i] *= fac; } - res->unit = UNIT_G; + res->unit = UNIT_G_FORCE; res->scale = -3; return 3; } @@ -63,7 +63,7 @@ static int read_mag(const void *dev, phydat_t *res) res->val[i] = (int16_t)tmp; } - res->unit = UNIT_GS; + res->unit = UNIT_GAUSS; res->scale = -3; return 3; } diff --git a/drivers/lsm6dsl/lsm6dsl_saul.c b/drivers/lsm6dsl/lsm6dsl_saul.c index 1a51f25fe209..39ac219cc482 100644 --- a/drivers/lsm6dsl/lsm6dsl_saul.c +++ b/drivers/lsm6dsl/lsm6dsl_saul.c @@ -31,7 +31,7 @@ static int read_acc(const void *dev, phydat_t *res) } res->scale = -3; - res->unit = UNIT_G; + res->unit = UNIT_G_FORCE; return 3; } diff --git a/drivers/mag3110/mag3110_saul.c b/drivers/mag3110/mag3110_saul.c index 0821ce4c204a..f81ba62487b7 100644 --- a/drivers/mag3110/mag3110_saul.c +++ b/drivers/mag3110/mag3110_saul.c @@ -28,7 +28,7 @@ static int read_mag(const void *dev, phydat_t *res) { mag3110_read((const mag3110_t *)dev, (mag3110_data_t *)res->val); - res->unit = UNIT_GS; + res->unit = UNIT_GAUSS; res->scale = 2; return 3; diff --git a/drivers/mma7660/mma7660_saul.c b/drivers/mma7660/mma7660_saul.c index 411e0d65e863..39860ac548b0 100644 --- a/drivers/mma7660/mma7660_saul.c +++ b/drivers/mma7660/mma7660_saul.c @@ -28,7 +28,7 @@ static int read_acc(const void *dev, phydat_t *res) { mma7660_read((const mma7660_t *)dev, (mma7660_data_t *)res->val); - res->unit = UNIT_G; + res->unit = UNIT_G_FORCE; res->scale = -3; return 3; diff --git a/drivers/mma8x5x/mma8x5x_saul.c b/drivers/mma8x5x/mma8x5x_saul.c index 8a925d740c25..5c4be8dea371 100644 --- a/drivers/mma8x5x/mma8x5x_saul.c +++ b/drivers/mma8x5x/mma8x5x_saul.c @@ -29,7 +29,7 @@ static int read_acc(const void *dev, phydat_t *res) { mma8x5x_read((const mma8x5x_t *)dev, (mma8x5x_data_t *)res->val); - res->unit = UNIT_G; + res->unit = UNIT_G_FORCE; res->scale = -3; return 3; diff --git a/drivers/mpu9x50/mpu9x50_saul.c b/drivers/mpu9x50/mpu9x50_saul.c index 302cc4538ede..f06b94e2ab6e 100644 --- a/drivers/mpu9x50/mpu9x50_saul.c +++ b/drivers/mpu9x50/mpu9x50_saul.c @@ -33,7 +33,7 @@ static int read_acc(const void *dev, phydat_t *res) } res->scale = -3; - res->unit = UNIT_G; + res->unit = UNIT_G_FORCE; return 3; } @@ -59,7 +59,7 @@ static int read_mag(const void *dev, phydat_t *res) } res->scale = -2; - res->unit = UNIT_GS; + res->unit = UNIT_GAUSS; return 3; } diff --git a/drivers/qmc5883l/qmc5883l_saul.c b/drivers/qmc5883l/qmc5883l_saul.c index 266b46e155ef..ed68e4aaaf9f 100644 --- a/drivers/qmc5883l/qmc5883l_saul.c +++ b/drivers/qmc5883l/qmc5883l_saul.c @@ -27,7 +27,7 @@ static int read(const void *dev, phydat_t *res) { int ret = qmc5883l_read((const qmc5883l_t *)dev, res->val); if ((ret == QMC5883L_OK) || (ret == QMC5883L_OVERFLOW)) { - res->unit = UNIT_GS; + res->unit = UNIT_GAUSS; res->scale = -3; return 3; } diff --git a/sys/include/phydat.h b/sys/include/phydat.h index d4083b2a2593..e7847ce549e8 100644 --- a/sys/include/phydat.h +++ b/sys/include/phydat.h @@ -87,16 +87,19 @@ enum { UNIT_M2, /**< square meters */ UNIT_M3, /**< cubic meters */ /* kinetic */ - UNIT_G, /**< gravitational force */ + UNIT_G_FORCE, /**< gravitational force equivalent */ + UNIT_G = UNIT_G_FORCE, /**< @deprecated, use UNIT_G_FORCE instead */ UNIT_DPS, /**< degree per second */ /* weight */ - UNIT_GR, /**< grams - not using the SI unit (kg) here to make scale + UNIT_GRAM, /**< grams - not using the SI unit (kg) here to make scale * handling simpler */ + UNIT_GR = UNIT_GRAM, /**< @deprecated, use UNIT_GRAM instead */ /* electricity */ UNIT_A, /**< Ampere */ UNIT_V, /**< Volts */ UNIT_W, /**< Watt */ - UNIT_GS, /**< gauss */ + UNIT_GAUSS, /**< gauss */ + UNIT_GS = UNIT_GAUSS, /**< @deprecated, use UNIT_GAUSS instead */ UNIT_T, /**< Tesla */ UNIT_DBM, /**< decibel-milliwatts */ UNIT_COULOMB, /**< coulomb */ diff --git a/sys/include/senml/phydat.h b/sys/include/senml/phydat.h index 1c645c5444b4..8ebfb1a20065 100644 --- a/sys/include/senml/phydat.h +++ b/sys/include/senml/phydat.h @@ -58,10 +58,10 @@ void phydat_to_senml_bool(senml_bool_value_t *senml, const phydat_t *phydat, con * * - @ref UNIT_TIME is converted to @ref SENML_UNIT_SECOND. * - @ref UNIT_F is converted to @ref SENML_UNIT_KELVIN. - * - @ref UNIT_G is converted to @ref SENML_UNIT_METER_PER_SQUARE_SECOND. + * - @ref UNIT_G_FORCE is converted to @ref SENML_UNIT_METER_PER_SQUARE_SECOND. * - @ref UNIT_BAR is converted to @ref SENML_UNIT_PASCAL. * - @ref UNIT_GPM3 is converted to @ref SENML_UNIT_KILOGRAM_PER_CUBIC_METER. - * - @ref UNIT_GS is converted to @ref SENML_UNIT_TESLA. + * - @ref UNIT_GAUSS is converted to @ref SENML_UNIT_TESLA. * - Compatible units are set to their SenML equivalent. * - Incompatible (or unknown) units are set to @ref SENML_UNIT_NONE. * @@ -80,7 +80,7 @@ void phydat_to_senml_float(senml_value_t *senml, const phydat_t *phydat, const u * - @ref UNIT_TIME is converted to @ref SENML_UNIT_SECOND. * - @ref UNIT_BAR is converted to @ref SENML_UNIT_PASCAL. * - @ref UNIT_GPM3 is converted to @ref SENML_UNIT_KILOGRAM_PER_CUBIC_METER. - * - @ref UNIT_GS is converted to @ref SENML_UNIT_TESLA. + * - @ref UNIT_GAUSS is converted to @ref SENML_UNIT_TESLA. * - Compatible units are set to their SenML equivalent. * - Incompatible (or unknown) units are set to @ref SENML_UNIT_NONE. * diff --git a/sys/net/application_layer/nanocoap/link_format.c b/sys/net/application_layer/nanocoap/link_format.c index c80db58dd93e..df3209f87fa7 100644 --- a/sys/net/application_layer/nanocoap/link_format.c +++ b/sys/net/application_layer/nanocoap/link_format.c @@ -85,7 +85,7 @@ int nanocoap_link_format_get(nanocoap_sock_t *sock, const char *path, char buffer[CONFIG_NANOCOAP_QS_MAX]; struct dir_list_ctx ctx = { .buf = buffer, - .end = buffer + sizeof(buffer), + .end = buffer + sizeof(buffer) - 1, .cur = buffer, .cb = cb, .ctx = arg, diff --git a/sys/phydat/phydat_str.c b/sys/phydat/phydat_str.c index bad60643f342..566a1ca8a226 100644 --- a/sys/phydat/phydat_str.c +++ b/sys/phydat/phydat_str.c @@ -106,14 +106,14 @@ const char *phydat_unit_to_str(uint8_t unit) case UNIT_M: return "m"; case UNIT_M2: return "m^2"; case UNIT_M3: return "m^3"; - case UNIT_G: return "g"; + case UNIT_G_FORCE: return "gₙ"; case UNIT_DPS: return "dps"; - case UNIT_GR: return "G"; + case UNIT_GRAM: return "g"; case UNIT_A: return "A"; case UNIT_V: return "V"; case UNIT_W: return "W"; case UNIT_DBM: return "dBm"; - case UNIT_GS: return "Gs"; + case UNIT_GAUSS: return "Gs"; case UNIT_T: return "T"; case UNIT_BAR: return "Bar"; case UNIT_PA: return "Pa"; diff --git a/sys/senml/phydat.c b/sys/senml/phydat.c index 31b3c2dd4831..d08a93a96bb0 100644 --- a/sys/senml/phydat.c +++ b/sys/senml/phydat.c @@ -24,7 +24,7 @@ static uint8_t phydat_unit_to_senml_unit(uint8_t unit) case UNIT_M: return SENML_UNIT_METER; case UNIT_M2: return SENML_UNIT_SQUARE_METER; case UNIT_M3: return SENML_UNIT_CUBIC_METER; - case UNIT_GR: return SENML_UNIT_GRAM; + case UNIT_GRAM: return SENML_UNIT_GRAM; case UNIT_A: return SENML_UNIT_AMPERE; case UNIT_V: return SENML_UNIT_VOLT; case UNIT_W: return SENML_UNIT_WATT; @@ -45,8 +45,8 @@ static uint8_t phydat_unit_to_senml_unit(uint8_t unit) /* Incompatible units */ case UNIT_TEMP_F: return SENML_UNIT_NONE; /* use K or Cel instead */ - case UNIT_GS: return SENML_UNIT_NONE; /* use T instead */ - case UNIT_G: return SENML_UNIT_NONE; /* use m/s2 instead */ + case UNIT_GAUSS: return SENML_UNIT_NONE; /* use T instead */ + case UNIT_G_FORCE: return SENML_UNIT_NONE; /* use m/s2 instead */ case UNIT_BAR: return SENML_UNIT_NONE; /* use Pa or hPa instead */ case UNIT_TIME: return SENML_UNIT_NONE; /* split into second/minute/hour */ case UNIT_DATE: return SENML_UNIT_NONE; /* split into day/month/year */ @@ -87,7 +87,7 @@ void phydat_to_senml_float(senml_value_t *senml, const phydat_t *phydat, const u value = (value + 459.67) * (5. / 9.); senml->attr.unit = SENML_UNIT_KELVIN; break; - case UNIT_G: + case UNIT_G_FORCE: /* convert gravitational acceleration to acceleration */ value *= 9.80665; senml->attr.unit = SENML_UNIT_METER_PER_SQUARE_SECOND; @@ -100,7 +100,7 @@ void phydat_to_senml_float(senml_value_t *senml, const phydat_t *phydat, const u value *= 0.001; senml->attr.unit = SENML_UNIT_KILOGRAM_PER_CUBIC_METER; break; - case UNIT_GS: + case UNIT_GAUSS: value *= 0.0001; senml->attr.unit = SENML_UNIT_TESLA; break; @@ -138,7 +138,7 @@ void phydat_to_senml_decimal(senml_value_t *senml, const phydat_t *phydat, const e -= 3; senml->attr.unit = SENML_UNIT_KILOGRAM_PER_CUBIC_METER; break; - case UNIT_GS: + case UNIT_GAUSS: e -= 4; senml->attr.unit = SENML_UNIT_TESLA; break; diff --git a/tests/phydat_dump/main.c b/tests/phydat_dump/main.c index f4225b78c76a..dc18897645f6 100644 --- a/tests/phydat_dump/main.c +++ b/tests/phydat_dump/main.c @@ -39,13 +39,13 @@ _phydat_test_t _test_vector[] = { .dim = 3, .dat = { .val = { 1234, 13456, -14567 }, .unit = UNIT_M, .scale = -3 } }, { .dim = 1, .dat = { .val = { -12345 }, .unit = UNIT_M2, .scale = -5 } }, { .dim = 1, .dat = { .val = { -12345 }, .unit = UNIT_M3, .scale = -6 } }, - { .dim = 3, .dat = { .val = { 12, 34, 5678}, .unit = UNIT_G, .scale = -2 } }, + { .dim = 3, .dat = { .val = { 12, 34, 5678}, .unit = UNIT_G_FORCE, .scale = -2 } }, { .dim = 3, .dat = { .val = { 123, 345, 678 }, .unit = UNIT_DPS, .scale = -3 } }, - { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_GR, .scale = -1 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_GRAM, .scale = -1 } }, { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_A, .scale = 3 } }, { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_V, .scale = 6 } }, { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_W, .scale = 7 } }, - { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_GS, .scale = -1 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_GAUSS, .scale = -1 } }, { .dim = 3, .dat = { .val = { 123, 456, 789 }, .unit = UNIT_T, .scale = -9 } }, { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_DBM, .scale = -3 } }, { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_COULOMB, .scale = 0 } }, diff --git a/tests/phydat_dump/tests/01-run.py b/tests/phydat_dump/tests/01-run.py index 670c589e06d1..5da3e790157e 100755 --- a/tests/phydat_dump/tests/01-run.py +++ b/tests/phydat_dump/tests/01-run.py @@ -33,13 +33,13 @@ def testfunc(child): child.expect(r'\t\[2\] -14567 mm\r\n') child.expect(r'Data:\t -0.12345 m\^2\r\n') child.expect(r'Data:\t -12345e-6 m\^3\r\n') - child.expect(r'Data:\t\[0\] 0.12 g\r\n') - child.expect(r'\t\[1\] 0.34 g\r\n') - child.expect(r'\t\[2\] 56.78 g\r\n') + child.expect(r'Data:\t\[0\] 0.12 gₙ\r\n') + child.expect(r'\t\[1\] 0.34 gₙ\r\n') + child.expect(r'\t\[2\] 56.78 gₙ\r\n') child.expect(r'Data:\t\[0\] 123 mdps\r\n') child.expect(r'\t\[1\] 345 mdps\r\n') child.expect(r'\t\[2\] 678 mdps\r\n') - child.expect(r'Data:\t 1234.5 G\r\n') + child.expect(r'Data:\t 1234.5 g\r\n') child.expect(r'Data:\t 12345 kA\r\n') child.expect(r'Data:\t 12345 MV\r\n') child.expect(r'Data:\t 12345e7 W\r\n') diff --git a/tests/senml_phydat/main.c b/tests/senml_phydat/main.c index 0781912f11dc..2704bb168dc0 100644 --- a/tests/senml_phydat/main.c +++ b/tests/senml_phydat/main.c @@ -84,7 +84,7 @@ static value_test_t value_tests[] = { .senml2 = senml_df(0, 3, SENML_UNIT_NONE), }, { - .phydat = { { 314, 0, 0 }, UNIT_G, -2 }, + .phydat = { { 314, 0, 0 }, UNIT_G_FORCE, -2 }, .senml1 = senml_f(30.792881, SENML_UNIT_METER_PER_SQUARE_SECOND), .senml2 = senml_df(314, -2, SENML_UNIT_NONE), }, @@ -99,7 +99,7 @@ static value_test_t value_tests[] = { .senml2 = senml_df(193, 2, SENML_UNIT_KILOGRAM_PER_CUBIC_METER), }, { - .phydat = { { 220, 0, 0 }, UNIT_GS, 3 }, + .phydat = { { 220, 0, 0 }, UNIT_GAUSS, 3 }, .senml1 = senml_f(22, SENML_UNIT_TESLA), .senml2 = senml_df(220, -1, SENML_UNIT_TESLA), } diff --git a/tests/unittests/tests-phydat/tests-phydat.c b/tests/unittests/tests-phydat/tests-phydat.c index 504f029db581..7287171a7326 100644 --- a/tests/unittests/tests-phydat/tests-phydat.c +++ b/tests/unittests/tests-phydat/tests-phydat.c @@ -58,8 +58,8 @@ static tdat_t data[] = { }, { .dim = 3, - .dat = { { 1032, 10, -509 }, UNIT_G, -3 }, - .json = "{\"d\":[1.032,0.010,-0.509],\"u\":\"g\"}", + .dat = { { 1032, 10, -509 }, UNIT_G_FORCE, -3 }, + .json = "{\"d\":[1.032,0.010,-0.509],\"u\":\"gₙ\"}", }, { .dim = 3, @@ -204,14 +204,14 @@ static void test_unitstr__success(void) TEST_ASSERT_EQUAL_STRING("m", phydat_unit_to_str_verbose(UNIT_M)); TEST_ASSERT_EQUAL_STRING("m^2", phydat_unit_to_str_verbose(UNIT_M2)); TEST_ASSERT_EQUAL_STRING("m^3", phydat_unit_to_str_verbose(UNIT_M3)); - TEST_ASSERT_EQUAL_STRING("g", phydat_unit_to_str_verbose(UNIT_G)); + TEST_ASSERT_EQUAL_STRING("gₙ", phydat_unit_to_str_verbose(UNIT_G_FORCE)); TEST_ASSERT_EQUAL_STRING("dps", phydat_unit_to_str_verbose(UNIT_DPS)); - TEST_ASSERT_EQUAL_STRING("G", phydat_unit_to_str_verbose(UNIT_GR)); + TEST_ASSERT_EQUAL_STRING("g", phydat_unit_to_str_verbose(UNIT_GRAM)); TEST_ASSERT_EQUAL_STRING("A", phydat_unit_to_str_verbose(UNIT_A)); TEST_ASSERT_EQUAL_STRING("V", phydat_unit_to_str_verbose(UNIT_V)); TEST_ASSERT_EQUAL_STRING("W", phydat_unit_to_str_verbose(UNIT_W)); TEST_ASSERT_EQUAL_STRING("dBm", phydat_unit_to_str_verbose(UNIT_DBM)); - TEST_ASSERT_EQUAL_STRING("Gs", phydat_unit_to_str_verbose(UNIT_GS)); + TEST_ASSERT_EQUAL_STRING("Gs", phydat_unit_to_str_verbose(UNIT_GAUSS)); TEST_ASSERT_EQUAL_STRING("T", phydat_unit_to_str_verbose(UNIT_T)); TEST_ASSERT_EQUAL_STRING("Bar", phydat_unit_to_str_verbose(UNIT_BAR)); TEST_ASSERT_EQUAL_STRING("Pa", phydat_unit_to_str_verbose(UNIT_PA));