Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
test_ieee11073_01.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <cassert>
3#include <cinttypes>
4#include <cstring>
5
6#define CATCH_CONFIG_RUNNER
7// #define CATCH_CONFIG_MAIN
8#include <catch2/catch_amalgamated.hpp>
10
12
13using namespace ieee11073;
14
15static void test_float32_IEEE11073_to_IEEE754(const std::string& msg, const uint32_t raw, const float expFloat) {
16 const float has = FloatTypes::float32_IEEE11073_to_IEEE754(raw);
17 INFO_STR(msg+": has '"+std::to_string(has));
18 INFO_STR(msg+": exp '"+std::to_string(expFloat)+"', diff "+std::to_string(fabsf(has-expFloat)));
19 REQUIRE_EPSI_MSG(msg, has, expFloat);
20}
21
22static void test_AbsoluteTime_IEEE11073(const std::string& msg, const uint8_t * data_le, const int size, const std::string& expStr) {
23 ieee11073::AbsoluteTime has(data_le, size);
24 const std::string has_str = has.toString();
25 INFO_STR(msg+": has '"+has_str+"', len "+std::to_string(has_str.length()));
26 INFO_STR(msg+": exp '"+expStr+"', len "+std::to_string(expStr.length())+", equal: "+std::to_string(has_str==expStr));
27 REQUIRE_MSG(msg, has_str.length() == expStr.length());
28 REQUIRE_MSG(msg, has_str == expStr);
29}
30
31TEST_CASE( "Datatype IEEE11073 Test 01", "[datatype][IEEE11073]" ) {
32 // 0x06 670100FF E40704040B1A00 00
33 // 0x06 640100FF E40704040B2C00 00
34
35 // 79 09 00 FE -> 24.25f
36 test_float32_IEEE11073_to_IEEE754("IEEE11073-float01", 0xFE000979, 24.25f);
37 // 670100FF -> 35.900002
38 test_float32_IEEE11073_to_IEEE754("IEEE11073-float01", 0xFF000167, 35.900002f);
39 // 640100FF -> 35.600002
40 test_float32_IEEE11073_to_IEEE754("IEEE11073-float02", 0xFF000164, 35.600002f);
41
42 {
43 // E40704040B1A00 -> 2020-04-04 11:26:00
44 const uint8_t input[] = { 0xE4, 0x07, 0x04, 0x04, 0x0B, 0x1A, 0x00 };
45 test_AbsoluteTime_IEEE11073("IEEE11073 time01", input, 7, "2020-04-04 11:26:00");
46 }
47 {
48 // E40704040B2C00 -> 2020-04-04 11:44:00
49 const uint8_t input[] = { 0xE4, 0x07, 0x04, 0x04, 0x0B, 0x2C, 0x00 };
50 test_AbsoluteTime_IEEE11073("IEEE11073 time02", input, 7, "2020-04-04 11:44:00");
51 }
52}
53
#define INFO_STR(msg)
Definition: catch2_ext.hpp:75
#define REQUIRE_EPSI_MSG(m, a, b)
Definition: catch2_ext.hpp:78
#define REQUIRE_MSG(MSG,...)
Definition: catch2_ext.hpp:58
date / timestamp format
Definition: DataTypes.hpp:72
std::string toString() const
Definition: DataTypes.cpp:60
std::string to_string(const alphabet &v) noexcept
Definition: base_codec.hpp:97
IEEE11073 Data Types.
Definition: DataTypes.hpp:47
TEST_CASE("Datatype IEEE11073 Test 01", "[datatype][IEEE11073]")
static void test_AbsoluteTime_IEEE11073(const std::string &msg, const uint8_t *data_le, const int size, const std::string &expStr)
static void test_float32_IEEE11073_to_IEEE754(const std::string &msg, const uint32_t raw, const float expFloat)