Skip to content

Commit

Permalink
Merge pull request #11 from bringauto/fix_command_checking
Browse files Browse the repository at this point in the history
Ignore all commands on first GET
  • Loading branch information
MarioIvancik authored Apr 11, 2024
2 parents a6f8085 + 3dae4b5 commit 91c54a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ INCLUDE(CheckPIESupported)
CHECK_PIE_SUPPORTED()
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)

SET(MISSION_MODULE_VERSION 1.2.2)
SET(MISSION_MODULE_VERSION 1.2.3)

OPTION(BRINGAUTO_INSTALL "Configure install" OFF)
OPTION(BRINGAUTO_PACKAGE "Configure package creation" OFF)
Expand Down
39 changes: 21 additions & 18 deletions source/external_server_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ int wait_for_command(int timeout_time_in_ms, void *context) {
auto con = static_cast<struct bamm::context *> (context);
std::unique_lock lock(con->mutex);
std::vector<std::shared_ptr<model::Message>> commands;
bool parse_commands = con->last_command_timestamp != 0;

try {
commands = con->fleet_api_client->getCommands(con->last_command_timestamp + 1, true);
Expand All @@ -260,27 +261,29 @@ int wait_for_command(int timeout_time_in_ms, void *context) {
con->last_command_timestamp = command->getTimestamp();
}

auto received_device_id = command->getDeviceId();
MissionModule::AutonomyCommand proto_command {};
const auto parse_status = google::protobuf::util::JsonStringToMessage(
command->getPayload()->getData()->getJson().serialize(), &proto_command
);
if(!parse_status.ok()) {
return NOT_OK;
if(parse_commands) {
auto received_device_id = command->getDeviceId();
MissionModule::AutonomyCommand proto_command {};
const auto parse_status = google::protobuf::util::JsonStringToMessage(
command->getPayload()->getData()->getJson().serialize(), &proto_command
);
if(!parse_status.ok()) {
return NOT_OK;
}
std::string command_str;
proto_command.SerializeToString(&command_str);

con->command_vector.emplace_back(command_str, bringauto::fleet_protocol::cxx::DeviceID(
received_device_id->getModuleId(),
received_device_id->getType(),
0, //priority
received_device_id->getRole(),
received_device_id->getName()
));
}
std::string command_str;
proto_command.SerializeToString(&command_str);

con->command_vector.emplace_back(command_str, bringauto::fleet_protocol::cxx::DeviceID(
received_device_id->getModuleId(),
received_device_id->getType(),
0, //priority
received_device_id->getRole(),
received_device_id->getName()
));
}

if(commands.empty()) {
if(commands.empty() || !parse_commands) {
return TIMEOUT_OCCURRED;
}
else {
Expand Down

0 comments on commit 91c54a6

Please sign in to comment.