From f5e242b3c8f529ebe4c701187614c325f8919d5a Mon Sep 17 00:00:00 2001 From: TheSomeMan Date: Tue, 23 Jul 2024 16:00:34 +0700 Subject: [PATCH] Add API re_6_data_invalid (#61) --- src/ruuvi_endpoint_6.c | 19 +++++++++++++++++++ src/ruuvi_endpoint_6.h | 8 ++++++++ test/test_ruuvi_endpoint_6.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/src/ruuvi_endpoint_6.c b/src/ruuvi_endpoint_6.c index 916dbc2..2ad31c0 100644 --- a/src/ruuvi_endpoint_6.c +++ b/src/ruuvi_endpoint_6.c @@ -435,4 +435,23 @@ re_status_t re_6_decode (const uint8_t * const p_buffer, re_6_data_t * const p_d return result; } +re_6_data_t re_6_data_invalid (const uint16_t measurement_cnt, const uint64_t radio_mac) +{ + const re_6_data_t data = + { + .pm1p0_ppm = NAN, + .pm2p5_ppm = NAN, + .pm4p0_ppm = NAN, + .pm10p0_ppm = NAN, + .co2 = NAN, + .humidity_rh = NAN, + .voc_index = NAN, + .nox_index = NAN, + .temperature_c = NAN, + .measurement_count = measurement_cnt, + .address = radio_mac, + }; + return data; +} + #endif diff --git a/src/ruuvi_endpoint_6.h b/src/ruuvi_endpoint_6.h index cf114a9..79cf238 100644 --- a/src/ruuvi_endpoint_6.h +++ b/src/ruuvi_endpoint_6.h @@ -166,4 +166,12 @@ bool re_6_check_format (const uint8_t * const p_buffer); */ re_status_t re_6_decode (const uint8_t * const p_buffer, re_6_data_t * const p_data); +/** + * @brief Create invalid Ruuvi DF6 data. + * @param measurement_cnt Running counter of measurement. + * @param radio_mac BLE address of device. + * @return /ref re_6_data_t with all values set to NAN. + */ +re_6_data_t re_6_data_invalid (const uint16_t measurement_cnt, const uint64_t radio_mac); + #endif diff --git a/test/test_ruuvi_endpoint_6.c b/test/test_ruuvi_endpoint_6.c index a70966d..f2fd58b 100644 --- a/test/test_ruuvi_endpoint_6.c +++ b/test/test_ruuvi_endpoint_6.c @@ -362,3 +362,34 @@ void test_ruuvi_endpoint_6_check_format_fail (void) const uint8_t raw_buf_byte0[31] = {0x03, 0x01, 0x04, 0x1B, 0xFF, 0x99, 0x04, 0x06}; TEST_ASSERT_FALSE (re_6_check_format (raw_buf_byte0)); } + +void test_re_6_data_invalid (void) +{ + const uint16_t measurement_cnt = 123; + const uint64_t radio_mac = 0xCBB8334C884FULL; + const re_6_data_t data = re_6_data_invalid (measurement_cnt, radio_mac); + static const re_6_data_t m_re_6_data_invalid = + { + .pm1p0_ppm = NAN, + .pm2p5_ppm = NAN, + .pm4p0_ppm = NAN, + .pm10p0_ppm = NAN, + .co2 = NAN, + .humidity_rh = NAN, + .voc_index = NAN, + .nox_index = NAN, + .temperature_c = NAN, + .measurement_count = 65535, + .address = 0xFFFFFFFFFFFF, + }; + TEST_ASSERT_EQUAL (data.measurement_count, measurement_cnt); + TEST_ASSERT_EQUAL (data.address, radio_mac); + TEST_ASSERT_TRUE (isnan (data.pm1p0_ppm)); + TEST_ASSERT_TRUE (isnan (data.pm1p0_ppm)); + TEST_ASSERT_TRUE (isnan (data.pm1p0_ppm)); + TEST_ASSERT_TRUE (isnan (data.co2)); + TEST_ASSERT_TRUE (isnan (data.humidity_rh)); + TEST_ASSERT_TRUE (isnan (data.voc_index)); + TEST_ASSERT_TRUE (isnan (data.nox_index)); + TEST_ASSERT_TRUE (isnan (data.temperature_c)); +}