Skip to content

Commit

Permalink
Merge pull request #9 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 f7f0945 + 50cd293 commit b255dad
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 @@ -7,7 +7,7 @@ SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_EXTENSIONS OFF) # For increased portability
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)

SET(IO_MODULE_VERSION 1.2.2)
SET(IO_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 @@ -241,6 +241,7 @@ int wait_for_command(int timeout_time_in_ms, void *context) {

std::unique_lock lock(con->mutex);
std::vector<std::shared_ptr<org::openapitools::client::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 @@ -249,31 +250,33 @@ int wait_for_command(int timeout_time_in_ms, void *context) {
}

for(auto command : commands) {
auto received_device_id = command->getDeviceId();
std::string command_str = command->getPayload()->getData()->getJson().serialize();
if(command->getTimestamp() > con->last_command_timestamp) {
con->last_command_timestamp = command->getTimestamp();
}

bringauto::io_module_utils::DeviceCommand command_obj;
buffer command_buff {nullptr, 0};
bringauto::fleet_protocol::cxx::StringAsBuffer::createBufferAndCopyData(&command_buff, command_str);
if(parse_commands) {
auto received_device_id = command->getDeviceId();
std::string command_str = command->getPayload()->getData()->getJson().serialize();

if(command_obj.deserializeFromBuffer(command_buff) == NOT_OK) {
return NOT_OK;
}
bringauto::io_module_utils::DeviceCommand command_obj;
buffer command_buff {nullptr, 0};
bringauto::fleet_protocol::cxx::StringAsBuffer::createBufferAndCopyData(&command_buff, command_str);

con->command_vector.emplace_back(command_obj, bringauto::fleet_protocol::cxx::DeviceID(
received_device_id->getModuleId(),
received_device_id->getType(),
0, // priority not returned from HTTP Api
received_device_id->getRole(),
received_device_id->getName()
));
if(command_obj.deserializeFromBuffer(command_buff) == NOT_OK) {
return NOT_OK;
}

if(command->getTimestamp() > con->last_command_timestamp) {
con->last_command_timestamp = command->getTimestamp();
con->command_vector.emplace_back(command_obj, bringauto::fleet_protocol::cxx::DeviceID(
received_device_id->getModuleId(),
received_device_id->getType(),
0, // priority not returned from HTTP Api
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 b255dad

Please sign in to comment.