Skip to content

Commit

Permalink
Add API re_6_data_invalid (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSomeMan authored Jul 23, 2024
1 parent 360f4d7 commit f5e242b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/ruuvi_endpoint_6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions src/ruuvi_endpoint_6.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions test/test_ruuvi_endpoint_6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit f5e242b

Please sign in to comment.