-
Notifications
You must be signed in to change notification settings - Fork 0
Add module function definitions #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MarioIvancik
merged 6 commits into
master
from
BAF-1155/add_module_function_definitions
Feb 11, 2026
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
be646a7
added module function definitions
MarioIvancik 8065cab
fix cmconf init system
MarioIvancik dc79b0a
fix generateCommand
MarioIvancik a8541c6
fix convertible buffer deserialization
MarioIvancik efba044
move async files to new namespace
MarioIvancik 653d295
fix unit tests
MarioIvancik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| FIND_PACKAGE(CMLIB REQUIRED COMPONENTS CMCONF) | ||
|
|
||
| CMCONF_INIT_SYSTEM(FLEET_PROTOCOL) | ||
|
|
||
| SET(STORAGE_LIST DEP) | ||
|
|
||
| SET(STORAGE_LIST_DEP "https://github.com/bacpack-system/package-tracker.git") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
include/bringauto/fleet_protocol/cxx/AsyncModuleFunctionDefinitions.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| #pragma once | ||
|
|
||
| #include <bringauto/fleet_protocol/cxx/ConvertibleBuffer.hpp> | ||
| #include <bringauto/fleet_protocol/cxx/ConvertibleBufferReturn.hpp> | ||
|
|
||
| #include <bringauto/async_function_execution/AsyncFunctionExecutor.hpp> | ||
|
|
||
|
|
||
| namespace bringauto::fleet_protocol::cxx { | ||
|
MarioIvancik marked this conversation as resolved.
Outdated
|
||
|
|
||
| inline static const async_function_execution::FunctionDefinition getModuleNumberAsync { | ||
| async_function_execution::FunctionId { 0 }, | ||
| async_function_execution::Return { int {} }, | ||
| async_function_execution::Arguments {} | ||
| }; | ||
|
|
||
| inline static const async_function_execution::FunctionDefinition isDeviceTypeSupportedAsync { | ||
| async_function_execution::FunctionId { 1 }, | ||
| async_function_execution::Return { int {} }, | ||
| async_function_execution::Arguments { uint32_t {} } | ||
| }; | ||
|
|
||
| inline static const async_function_execution::FunctionDefinition sendStatusConditionAsync { | ||
| async_function_execution::FunctionId { 2 }, | ||
| async_function_execution::Return { int {} }, | ||
| async_function_execution::Arguments { ConvertibleBuffer {}, ConvertibleBuffer {}, uint32_t {} } | ||
| }; | ||
|
|
||
| inline static const async_function_execution::FunctionDefinition generateCommandAsync { | ||
| async_function_execution::FunctionId { 3 }, | ||
| async_function_execution::Return { ConvertibleBufferReturn {} }, | ||
| async_function_execution::Arguments { ConvertibleBuffer {}, ConvertibleBuffer {}, uint32_t {} } | ||
| }; | ||
|
|
||
| inline static const async_function_execution::FunctionDefinition aggregateStatusAsync { | ||
| async_function_execution::FunctionId { 4 }, | ||
| async_function_execution::Return { ConvertibleBufferReturn {} }, | ||
| async_function_execution::Arguments { ConvertibleBuffer {}, ConvertibleBuffer {}, uint32_t {} } | ||
| }; | ||
|
|
||
| inline static const async_function_execution::FunctionDefinition aggregateErrorAsync { | ||
| async_function_execution::FunctionId { 5 }, | ||
| async_function_execution::Return { ConvertibleBufferReturn {} }, | ||
| async_function_execution::Arguments { ConvertibleBuffer {}, ConvertibleBuffer {}, uint32_t {} } | ||
| }; | ||
|
|
||
| inline static const async_function_execution::FunctionDefinition generateFirstCommandAsync { | ||
| async_function_execution::FunctionId { 6 }, | ||
| async_function_execution::Return { ConvertibleBufferReturn {} }, | ||
| async_function_execution::Arguments { uint32_t {} } | ||
| }; | ||
|
|
||
| inline static const async_function_execution::FunctionDefinition statusDataValidAsync { | ||
| async_function_execution::FunctionId { 7 }, | ||
| async_function_execution::Return { int {} }, | ||
| async_function_execution::Arguments { ConvertibleBuffer {}, uint32_t {} } | ||
| }; | ||
|
|
||
| inline static const async_function_execution::FunctionDefinition commandDataValidAsync { | ||
| async_function_execution::FunctionId { 8 }, | ||
| async_function_execution::Return { int {} }, | ||
| async_function_execution::Arguments { ConvertibleBuffer {}, uint32_t {} } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Type alias for an AsyncFunctionExecutor specialized with module-related functions. | ||
| */ | ||
| using ModuleFunctionExecutor = async_function_execution::AsyncFunctionExecutor< | ||
| decltype(getModuleNumberAsync), | ||
| decltype(isDeviceTypeSupportedAsync), | ||
| decltype(sendStatusConditionAsync), | ||
| decltype(generateCommandAsync), | ||
| decltype(aggregateStatusAsync), | ||
| decltype(aggregateErrorAsync), | ||
| decltype(generateFirstCommandAsync), | ||
| decltype(statusDataValidAsync), | ||
| decltype(commandDataValidAsync) | ||
| >; | ||
|
|
||
| /** | ||
| * @brief FunctionList containing all module-related function definitions. | ||
| */ | ||
| inline static const async_function_execution::FunctionList< | ||
| decltype(getModuleNumberAsync), | ||
| decltype(isDeviceTypeSupportedAsync), | ||
| decltype(sendStatusConditionAsync), | ||
| decltype(generateCommandAsync), | ||
| decltype(aggregateStatusAsync), | ||
| decltype(aggregateErrorAsync), | ||
| decltype(generateFirstCommandAsync), | ||
| decltype(statusDataValidAsync), | ||
| decltype(commandDataValidAsync) | ||
| > moduleFunctionList { | ||
| getModuleNumberAsync, | ||
| isDeviceTypeSupportedAsync, | ||
| sendStatusConditionAsync, | ||
| generateCommandAsync, | ||
| aggregateStatusAsync, | ||
| aggregateErrorAsync, | ||
| generateFirstCommandAsync, | ||
| statusDataValidAsync, | ||
| commandDataValidAsync | ||
| }; | ||
|
|
||
| } | ||
30 changes: 30 additions & 0 deletions
30
include/bringauto/fleet_protocol/cxx/ConvertibleBuffer.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #pragma once | ||
|
|
||
| #include <fleet_protocol/common_headers/device_management.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <span> | ||
|
|
||
|
|
||
|
|
||
| namespace bringauto::fleet_protocol::cxx { | ||
|
|
||
| /** | ||
| * @brief ConvertibleBuffer is a helper class to convert a fleet_protocol 'buffer' struct | ||
| * to/from a byte span for serialization/deserialization. | ||
| */ | ||
| struct ConvertibleBuffer final { | ||
| struct ::buffer buffer {}; | ||
| ConvertibleBuffer() = default; | ||
| ConvertibleBuffer(struct ::buffer buff) : buffer(buff) {} | ||
|
|
||
| std::span<const uint8_t> serialize() const { | ||
| return std::span {reinterpret_cast<const uint8_t *>(buffer.data), buffer.size_in_bytes}; | ||
| } | ||
| void deserialize(std::span<const uint8_t> bytes) { | ||
| buffer.data = const_cast<uint8_t *>(bytes.data()); | ||
| buffer.size_in_bytes = bytes.size(); | ||
| } | ||
| }; | ||
|
|
||
| } |
43 changes: 43 additions & 0 deletions
43
include/bringauto/fleet_protocol/cxx/ConvertibleBufferReturn.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #pragma once | ||
|
|
||
| #include <fleet_protocol/common_headers/device_management.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <cstring> | ||
| #include <span> | ||
|
|
||
|
|
||
|
|
||
| namespace bringauto::fleet_protocol::cxx { | ||
|
|
||
| /** | ||
| * @brief ConvertibleBufferReturn is a helper class to convert a fleet_protocol 'buffer' struct | ||
| * and a return code to/from a byte span for serialization/deserialization. | ||
| * The first 4 bytes represent the return code (int), followed by the buffer data. | ||
| */ | ||
| struct ConvertibleBufferReturn final { | ||
| int returnCode {}; | ||
| struct ::buffer buffer {}; | ||
| ConvertibleBufferReturn() = default; | ||
| ConvertibleBufferReturn(int code, struct ::buffer buff) : returnCode(code), buffer(buff) {} | ||
|
|
||
| std::span<const uint8_t> serialize() const { | ||
| size_t total_size = sizeof(int) + buffer.size_in_bytes; | ||
| uint8_t* data = new uint8_t[total_size]; | ||
| std::memcpy(data, &returnCode, sizeof(int)); | ||
| std::memcpy(data + sizeof(int), buffer.data, buffer.size_in_bytes); | ||
| return {data, total_size}; | ||
| } | ||
| void deserialize(std::span<const uint8_t> bytes) { | ||
| auto size = bytes.size(); | ||
| if (size < sizeof(int)) return; | ||
| std::memcpy(&returnCode, bytes.data(), sizeof(int)); | ||
| size -= sizeof(int); | ||
| buffer.data = new uint8_t[size]; | ||
| buffer.size_in_bytes = size; | ||
| std::memcpy(buffer.data, bytes.data() + sizeof(int), size); | ||
| buffer.size_in_bytes = size; | ||
| } | ||
| }; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #include <bringauto/fleet_protocol/cxx/AsyncModuleFunctionDefinitions.hpp> | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| using namespace bringauto::fleet_protocol::cxx; | ||
|
|
||
|
|
||
| TEST(AsyncModuleFunctionDefinitions_tests, FunctionDefinitionsExist) { | ||
| EXPECT_EQ(getModuleNumberAsync.id.value, 0); | ||
| EXPECT_EQ(isDeviceTypeSupportedAsync.id.value, 1); | ||
| EXPECT_EQ(sendStatusConditionAsync.id.value, 2); | ||
| EXPECT_EQ(generateCommandAsync.id.value, 3); | ||
| EXPECT_EQ(aggregateStatusAsync.id.value, 4); | ||
| EXPECT_EQ(aggregateErrorAsync.id.value, 5); | ||
| EXPECT_EQ(generateFirstCommandAsync.id.value, 6); | ||
| EXPECT_EQ(statusDataValidAsync.id.value, 7); | ||
| EXPECT_EQ(commandDataValidAsync.id.value, 8); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.