Skip to content

Commit

Permalink
Fixing generation of the "data view" and "bare metal" options for the…
Browse files Browse the repository at this point in the history
… payload framing field.
  • Loading branch information
arobenko committed Jan 16, 2025
1 parent 30db70a commit 0c4aaf7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/commsdsl2comms/src/CommsPayloadLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ std::string CommsPayloadLayer::commsCustomFieldDataViewOptsImpl() const
static const std::string Templ =
"/// @brief Extra options for @ref\n"
"/// #^#SCOPE#$##^#SUFFIX#$#::Field field.\n"
"struct #^#CLASS_NAME#$##^#SUFFIX#$# : public TBase::#^#OPT_SCOPE#$#\n"
"struct #^#CLASS_NAME#$##^#SUFFIX#$# : public TBase::#^#OPT_SCOPE#$##^#SUFFIX#$#\n"
"{\n"
" using Field =\n"
" std::tuple<\n"
" comms::option::app::OrigDataView,\n"
" typename TBase::#^#OPT_SCOPE#$#::Field\n"
" typename TBase::#^#OPT_SCOPE#$##^#SUFFIX#$#::Field\n"
" >;\n"
"}; // struct #^#CLASS_NAME#$##^#SUFFIX#$#\n";

Expand All @@ -151,12 +151,12 @@ std::string CommsPayloadLayer::commsCustomFieldBareMetalOptsImpl() const
static const std::string Templ =
"/// @brief Extra options for @ref\n"
"/// #^#SCOPE#$##^#SUFFIX#$#::Field field.\n"
"struct #^#CLASS_NAME#$##^#SUFFIX#$# : public TBase::#^#OPT_SCOPE#$#\n"
"struct #^#CLASS_NAME#$##^#SUFFIX#$# : public TBase::#^#OPT_SCOPE#$##^#SUFFIX#$#\n"
"{\n"
" using Field =\n"
" std::tuple<\n"
" comms::option::app::FixedSizeStorage<DEFAULT_SEQ_FIXED_STORAGE_SIZE * 8>,\n"
" typename TBase::#^#OPT_SCOPE#$#::Field\n"
" typename TBase::#^#OPT_SCOPE#$##^#SUFFIX#$#::Field\n"
" >;\n"
"}; // struct #^#CLASS_NAME#$##^#SUFFIX#$#\n";

Expand Down
42 changes: 42 additions & 0 deletions app/commsdsl2comms/test/test1/test1Test.th
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
#include "test1/frame/Frame.h"
#include "test1/message/Msg1.h"
#include "test1/message/Msg2.h"
#include "test1/options/DataViewDefaultOptions.h"
#include "test1/options/BareMetalDefaultOptions.h"
#include "test1/dispatch/DispatchMessage.h"

class TestSuite : public CxxTest::TestSuite
{
public:
void test1();
void test2();
void test3();
void test4();

using Interface =
test1::Message<
Expand All @@ -25,7 +29,12 @@ public:
>;

TEST1_ALIASES_FOR_ALL_MESSAGES(,,Interface, test1::options::DefaultOptions)
TEST1_ALIASES_FOR_ALL_MESSAGES(DataView,,Interface, test1::options::DataViewDefaultOptions)
TEST1_ALIASES_FOR_ALL_MESSAGES(BareMetal,,Interface, test1::options::BareMetalDefaultOptions)

using Frame = test1::frame::Frame<Interface>;
using DataViewFrame = test1::frame::Frame<Interface, test1::input::AllMessages<Interface, test1::options::DataViewDefaultOptions>, test1::options::DataViewDefaultOptions>;
using BareMetalFrame = test1::frame::Frame<Interface, test1::input::AllMessages<Interface, test1::options::BareMetalDefaultOptions>, test1::options::BareMetalDefaultOptions>;

void polymorphicNameCheck(const Interface& msg, const char* value)
{
Expand Down Expand Up @@ -82,3 +91,36 @@ void TestSuite::test2()
test1::dispatch::dispatchMessageDefaultOptions(test1::MsgId_Msg1, *msg, handler);
TS_ASSERT_EQUALS(handler.m_msg1, 1U);
}

void TestSuite::test3()
{
DataViewFrame frame;
DataViewFrame::AllFields frameFields;
DataViewFrame::MsgPtr msg;
static const std::uint8_t Buf[] = {1, 0x1, 0x2, 0x3, 0x4};
static const std::size_t BufSize = std::extent<decltype(Buf)>::value;
auto readIter = comms::readIteratorFor<Interface>(&Buf[0]);
auto es = frame.readFieldsCached(frameFields, msg, readIter, BufSize);
TS_ASSERT_EQUALS(es, comms::ErrorStatus::Success);
TS_ASSERT_EQUALS(msg->getId(), 1U);

auto& payload = std::get<1>(frameFields).value();
TS_ASSERT(std::equal(payload.begin(), payload.end(), std::begin(Buf) + 1, std::end(Buf)));
}

void TestSuite::test4()
{
BareMetalFrame frame;
BareMetalFrame::AllFields frameFields;
BareMetalFrame::MsgPtr msg;
static const std::uint8_t Buf[] = {1, 0x1, 0x2, 0x3, 0x4};
static const std::size_t BufSize = std::extent<decltype(Buf)>::value;
auto readIter = comms::readIteratorFor<Interface>(&Buf[0]);
auto es = frame.readFieldsCached(frameFields, msg, readIter, BufSize);
TS_ASSERT_EQUALS(es, comms::ErrorStatus::Success);
TS_ASSERT_EQUALS(msg->getId(), 1U);

auto& payload = std::get<1>(frameFields).value();
TS_ASSERT(std::equal(payload.begin(), payload.end(), std::begin(Buf) + 1, std::end(Buf)));
}

0 comments on commit 0c4aaf7

Please sign in to comment.