-
Notifications
You must be signed in to change notification settings - Fork 58
Closed
Description
When combining message of different 'sizes', e.g., msg1 with 2 fields (each 2 bytes), and msg2 with 3 fields (each 4 bytes), I get the wrong size for msg2 - it's the same size as the combined message. Here's some sample code:
simple_msg.hpp:
#include <msg/callback.hpp>
#include <msg/field.hpp>
#include <msg/handler.hpp>
#include <msg/message.hpp>
#include <cib/cib.hpp>
namespace simple_message {
using namespace msg;
// msg 1
using field0_f = msg::field<"field0", uint16_t>::located<msg::at{15_msb, 0_lsb}>;
using field1_f = msg::field<"field1", uint16_t>::located<msg::at{31_msb, 16_lsb}>;
// msg 2
using field2_f = msg::field<"field2", uint32_t>::located<msg::at{63_msb, 32_lsb}>;
using field3_f = msg::field<"field3", uint32_t>::located<msg::at{95_msb, 64_lsb}>;
using field4_f = msg::field<"field4", uint32_t>::located<msg::at{127_msb, 96_lsb}>;
using msg_1_defn = message<"msg_1",
field0_f,
field1_f
>;
using msg_2_defn = message<"msg_2",
field2_f,
field3_f,
field4_f
>;
using msg1_defn = extend<combine<"combine1", msg_1_defn, msg_2_defn>, "msg1", field0_f::with_required<1>>;
using msg2_defn = extend<combine<"combine2", msg_1_defn, msg_2_defn>, "msg2", field0_f::with_required<2>>;
constexpr auto field0_match1 = msg::equal_to<msg1_defn::field_t<"field0">, 1>;
constexpr auto field0_match2 = msg::equal_to<msg2_defn::field_t<"field0">, 2>;
} // namespace
using simple_msg1 = msg::owning<simple_message::msg1_defn>;
using simple_msg2 = msg::owning<simple_message::msg2_defn>;
test_simple_msg.cpp:
#include "simple_msg.hpp"
#include <catch2/catch_test_macros.hpp>
#include <iostream>
TEST_CASE("message sizes", "Simple Message Tests") {
using namespace msg::literals;
// msg_1_defn: 2 fields
auto s_1 = simple_message::msg_1_defn::size<uint8_t>::value;
std::cout << "s_1: " << s_1 << std::endl;
// msg1_def: 2 fields + 3 fields, field0 = 1, using extend<combine>>
auto s1 = simple_message::msg1_defn::size<uint8_t>::value;
std::cout << "s1: " << s1 << std::endl;
// msg_2_defn: 3 fields
auto s_2 = simple_message::msg_2_defn::size<uint8_t>::value;
std::cout << "s_2: " << s_2 << std::endl;
// msg2_def: 2 fields + 3 fields, field0 = 2, using extend<combine>>
auto s2 = simple_message::msg2_defn::size<uint8_t>::value;
std::cout << "s2: " << s2 << std::endl;
REQUIRE( s_1 == 2 * sizeof(uint16_t));
REQUIRE( s2 != s_2);
REQUIRE( s1 != s_1);
REQUIRE( s1 == s2 );
REQUIRE( s_2 == 3 * sizeof(uint32_t));
}
TEST_CASE("message ids", "Simple Message Tests") {
using namespace msg::literals;
// msg1 field0 = 1
simple_msg1 s1_msg{};
// msg2 field0 = 2
simple_msg2 s2_msg{};
REQUIRE( 1 == s1_msg.get("field0"_field) );
REQUIRE( 2 == s2_msg.get("field0"_field) );
}
Output from running test_simple_msg:
.../compile-time-init-build-main/examples/cib_serial_port $ ./test_simple_msg
Randomness seeded to: 672942124
s_1: 4
s1: 16
s_2: 16
s2: 16
test_simple_msg is a Catch2 v3.8.0 host application.
Run with -? for options
-------------------------------------------------------------------------------
message sizes
-------------------------------------------------------------------------------
test_simple_msg.cpp:7
...............................................................................
test_simple_msg.cpp:26: FAILED:
REQUIRE( s2 != s_2 )
with expansion:
16 != 16
===============================================================================
test cases: 2 | 1 passed | 1 failed
assertions: 4 | 3 passed | 1 failed
This doesn't seem to be a problem when packing the two definitions (and of course removing the bit offsets for the msg2 fields in that case).
Metadata
Metadata
Assignees
Labels
No labels