From 206bea0a1de148f70ade6b813f4d41eca8924aa2 Mon Sep 17 00:00:00 2001 From: chrysn Date: Tue, 25 Jan 2022 13:46:08 +0100 Subject: [PATCH] phydat: Add Tesla unit While this is equivalent to the existing Gs (1 T = 10^-4 Gs), this is the SI (and thus preferred) unit. --- sys/include/phydat.h | 1 + sys/phydat/phydat_str.c | 1 + tests/phydat_dump/main.c | 1 + tests/phydat_dump/tests/01-run.py | 3 +++ tests/unittests/tests-phydat/tests-phydat.c | 1 + 5 files changed, 7 insertions(+) diff --git a/sys/include/phydat.h b/sys/include/phydat.h index 4e7a99d72c..b83f11c2cc 100644 --- a/sys/include/phydat.h +++ b/sys/include/phydat.h @@ -97,6 +97,7 @@ enum { UNIT_V, /**< Volts */ UNIT_W, /**< Watt */ UNIT_GS, /**< gauss */ + UNIT_T, /**< Tesla */ UNIT_DBM, /**< decibel-milliwatts */ UNIT_COULOMB, /**< coulomb */ UNIT_F, /**< Farad */ diff --git a/sys/phydat/phydat_str.c b/sys/phydat/phydat_str.c index bbdea52bad..bad60643f3 100644 --- a/sys/phydat/phydat_str.c +++ b/sys/phydat/phydat_str.c @@ -114,6 +114,7 @@ const char *phydat_unit_to_str(uint8_t unit) case UNIT_W: return "W"; case UNIT_DBM: return "dBm"; case UNIT_GS: return "Gs"; + case UNIT_T: return "T"; case UNIT_BAR: return "Bar"; case UNIT_PA: return "Pa"; case UNIT_PERMILL: return "permille"; diff --git a/tests/phydat_dump/main.c b/tests/phydat_dump/main.c index b0c73f04a9..8ce6d1ff22 100644 --- a/tests/phydat_dump/main.c +++ b/tests/phydat_dump/main.c @@ -45,6 +45,7 @@ _phydat_test_t _test_vector[] = { .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 = 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 } }, { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_F, .scale = -6 } }, diff --git a/tests/phydat_dump/tests/01-run.py b/tests/phydat_dump/tests/01-run.py index 39a781702f..670c589e06 100755 --- a/tests/phydat_dump/tests/01-run.py +++ b/tests/phydat_dump/tests/01-run.py @@ -44,6 +44,9 @@ def testfunc(child): child.expect(r'Data:\t 12345 MV\r\n') child.expect(r'Data:\t 12345e7 W\r\n') child.expect(r'Data:\t 1234.5 Gs\r\n') + child.expect(r'Data:\t\[0\] 123 nT\r\n') + child.expect(r'\t\[1\] 456 nT\r\n') + child.expect(r'\t\[2\] 789 nT\r\n') child.expect(r'Data:\t 12.345 dBm\r\n') child.expect(r'Data:\t 12345 C\r\n') child.expect(r'Data:\t 12345 uF\r\n') diff --git a/tests/unittests/tests-phydat/tests-phydat.c b/tests/unittests/tests-phydat/tests-phydat.c index de5cce7408..504f029db5 100644 --- a/tests/unittests/tests-phydat/tests-phydat.c +++ b/tests/unittests/tests-phydat/tests-phydat.c @@ -212,6 +212,7 @@ static void test_unitstr__success(void) 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("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)); TEST_ASSERT_EQUAL_STRING("permille", phydat_unit_to_str_verbose(UNIT_PERMILL));