-
Notifications
You must be signed in to change notification settings - Fork 1
Replace protobuf with JSON #19
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
Open
MarioIvancik
wants to merge
26
commits into
master
Choose a base branch
from
BAF-874/skip_protobuf_option
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
676f5bc
added option to send messages as json
MarioIvancik 908cf59
Merge branch 'master' into BAF-874/skip_protobuf_option
MarioIvancik d9a3919
added flag to use raw json instead of protobuf
MarioIvancik c4d1353
dump json instead of to_string
MarioIvancik 7d9fe2b
use protobuf only for message validation
MarioIvancik 3c47f5f
print received command
MarioIvancik 616f0d3
generate first command manually
MarioIvancik dc4e25b
use to_string on json
MarioIvancik 36fc047
code improvements
MarioIvancik 28b3eb0
config is not iterable
MarioIvancik d452390
add debug prints to command validation
MarioIvancik ef57529
use .at when addressing json keys
MarioIvancik 095b7e7
debug logging
MarioIvancik 39f03d0
validate a command when validating a command
MarioIvancik f998d24
remove debug logging
MarioIvancik 9127756
update version tag
MarioIvancik 7707c2f
formatting fixes
MarioIvancik 4d5572e
Merge branch 'master' into BAF-874/skip_protobuf_option
MarioIvancik 05cc21e
fix cmakelists
MarioIvancik 7bf4394
sonar cloud fixes
MarioIvancik 18b96e9
catch specific exceptions
MarioIvancik db41bef
revert to general exceptions
MarioIvancik f7b61a6
Merge branch 'master' of github.com:bringauto/mission-module into BAF…
MarioIvancik c47cfd6
use from_chars to convert strings
MarioIvancik b01f4eb
update fleet protocol http client version
MarioIvancik 1270015
fix config value checking
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
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,12 +1,13 @@ | ||
| SET(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE) | ||
|
|
||
| BA_PACKAGE_LIBRARY(fleet-protocol-interface v2.0.0 PLATFORM_STRING_MODE any_machine NO_DEBUG ON) | ||
| BA_PACKAGE_LIBRARY(fleet-protocol-cxx-helpers-static v1.1.1) | ||
| BA_PACKAGE_LIBRARY(protobuf v4.21.12) | ||
| BA_PACKAGE_LIBRARY(zlib v1.2.11) | ||
| BA_PACKAGE_LIBRARY(fleet-protocol-interface v2.0.0 PLATFORM_STRING_MODE any_machine NO_DEBUG ON) | ||
| BA_PACKAGE_LIBRARY(fleet-protocol-cxx-helpers-static v1.1.1) | ||
| BA_PACKAGE_LIBRARY(zlib v1.2.11) | ||
| BA_PACKAGE_LIBRARY(nlohmann-json v3.10.5 PLATFORM_STRING_MODE any_machine NO_DEBUG ON) | ||
| BA_PACKAGE_LIBRARY(protobuf v4.21.12) | ||
|
|
||
| IF (FLEET_PROTOCOL_BUILD_EXTERNAL_SERVER) | ||
| BA_PACKAGE_LIBRARY(fleet-http-client-shared v1.5.0) | ||
| BA_PACKAGE_LIBRARY(fleet-http-client-shared v2.0.0) | ||
| BA_PACKAGE_LIBRARY(boost v1.86.0) | ||
| BA_PACKAGE_LIBRARY(cpprestsdk v2.10.20) | ||
| ENDIF () |
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,26 @@ | ||
| #pragma once | ||
|
|
||
| #include <fleet_protocol/common_headers/memory_management.h> | ||
|
|
||
| #include <MissionModule.pb.h> | ||
|
|
||
| #include <nlohmann/json.hpp> | ||
|
|
||
| namespace bringauto::ba_json { | ||
|
|
||
| using json = nlohmann::ordered_json; | ||
|
|
||
| class JsonHelper { | ||
| public: | ||
| static int bufferToJson(json& json, const buffer& buffer); | ||
|
|
||
| static int jsonToBuffer(buffer* buffer, const json& json); | ||
|
|
||
| static MissionModule::AutonomyStatus_State stringToAutonomyState(const std::string_view &state); | ||
|
|
||
| static std::string autonomyStateToString(MissionModule::AutonomyStatus_State state); | ||
|
|
||
| static std::string autonomyActionToString(MissionModule::AutonomyCommand_Action action); | ||
|
|
||
| }; | ||
| } |
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
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,70 @@ | ||
| #include <fleet_protocol/common_headers/general_error_codes.h> | ||
|
|
||
| #include <bringauto/ba_json/JsonHelper.hpp> | ||
|
|
||
|
|
||
| namespace bringauto::ba_json { | ||
|
|
||
| using json = nlohmann::ordered_json; | ||
|
|
||
| int JsonHelper::bufferToJson(json& json, const buffer& buffer) { | ||
| const auto buffer_data = static_cast<char*> (buffer.data); | ||
| try { | ||
| json = json::parse(buffer_data, buffer_data + buffer.size_in_bytes); | ||
| } catch (json::parse_error &) { | ||
| return NOT_OK; | ||
| } | ||
| return OK; | ||
| } | ||
|
|
||
| int JsonHelper::jsonToBuffer(buffer *buffer, const json& json) { | ||
| const std::string tmp = nlohmann::to_string(json); | ||
| if (allocate(buffer, tmp.size()) == NOT_OK) { | ||
| return NOT_OK; | ||
| } | ||
| std::memcpy(buffer->data, tmp.c_str(), tmp.size()); | ||
| return OK; | ||
| } | ||
|
|
||
| MissionModule::AutonomyStatus_State JsonHelper::stringToAutonomyState(const std::string_view &state) { | ||
| if (state == "IDLE") { | ||
| return MissionModule::AutonomyStatus_State::AutonomyStatus_State_IDLE; | ||
| } else if (state == "DRIVE") { | ||
| return MissionModule::AutonomyStatus_State::AutonomyStatus_State_DRIVE; | ||
| } else if (state == "IN_STOP") { | ||
| return MissionModule::AutonomyStatus_State::AutonomyStatus_State_IN_STOP; | ||
| } else if (state == "OBSTACLE") { | ||
| return MissionModule::AutonomyStatus_State::AutonomyStatus_State_OBSTACLE; | ||
| } else if (state == "ERROR") { | ||
| return MissionModule::AutonomyStatus_State::AutonomyStatus_State_ERROR; | ||
| } | ||
| return MissionModule::AutonomyStatus_State::AutonomyStatus_State_ERROR; | ||
| } | ||
|
|
||
| std::string JsonHelper::autonomyStateToString(const MissionModule::AutonomyStatus_State state) { | ||
| switch (state) { | ||
| case MissionModule::AutonomyStatus_State::AutonomyStatus_State_IDLE: | ||
| return "IDLE"; | ||
| case MissionModule::AutonomyStatus_State::AutonomyStatus_State_DRIVE: | ||
| return "DRIVE"; | ||
| case MissionModule::AutonomyStatus_State::AutonomyStatus_State_IN_STOP: | ||
| return "IN_STOP"; | ||
| case MissionModule::AutonomyStatus_State::AutonomyStatus_State_OBSTACLE: | ||
| return "OBSTACLE"; | ||
| default: | ||
| return "ERROR"; | ||
| } | ||
| } | ||
|
|
||
| std::string JsonHelper::autonomyActionToString(const MissionModule::AutonomyCommand_Action action) { | ||
| switch (action) { | ||
| case MissionModule::AutonomyCommand_Action::AutonomyCommand_Action_STOP: | ||
| return "STOP"; | ||
| case MissionModule::AutonomyCommand_Action::AutonomyCommand_Action_START: | ||
| return "DRIVE"; | ||
| default: | ||
| return "NO_ACTION"; | ||
| } | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
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.