diff --git a/cmvr-es/devices/agv/seer_robokit/include/seer_robokit_protocol.h b/cmvr-es/devices/agv/seer_robokit/include/seer_robokit_protocol.h index e49cba5c..40eec3d3 100644 --- a/cmvr-es/devices/agv/seer_robokit/include/seer_robokit_protocol.h +++ b/cmvr-es/devices/agv/seer_robokit/include/seer_robokit_protocol.h @@ -31,6 +31,9 @@ constexpr std::uint16_t kRobotConfigUploadMap = 4010; constexpr std::uint16_t kRobotConfigDownloadMap = 4011; constexpr std::uint16_t kRobotOtherStartMapping = 6100; constexpr std::uint16_t kRobotOtherStopMapping = 6101; +// The controller can emit this asynchronous mapping event on port 19210 +// while a mapping session is active. It is not the reply to the next command. +constexpr std::uint16_t kRobotOtherMappingEventResponse = 17002; constexpr std::uint16_t kRobotPushConfigReq = 9300; constexpr std::uint16_t kRobotPushConfigRes = 19300; constexpr std::uint16_t kRobotPush = 19301; diff --git a/cmvr-es/devices/agv/seer_robokit/src/seer_robokit_transport.cpp b/cmvr-es/devices/agv/seer_robokit/src/seer_robokit_transport.cpp index 97b7a515..c3366b5c 100644 --- a/cmvr-es/devices/agv/seer_robokit/src/seer_robokit_transport.cpp +++ b/cmvr-es/devices/agv/seer_robokit/src/seer_robokit_transport.cpp @@ -133,25 +133,40 @@ AgvResult SeerRobokitAgv::sendCommandRaw_( "SEER Robokit send command failed: " + systemError()); } - std::uint16_t response_command = 0; - std::string payload_text_response; - const auto result = receiveFrame_(sock, response_command, payload_text_response); - if (!result.ok()) { - return result; - } const auto expected_response_command = static_cast( command + 10000U); - if (response_command != expected_response_command) { - return AgvResult::failure( - AgvErrorCode::CommandFailed, - "SEER Robokit response command mismatch: expected=" - + std::to_string(expected_response_command) - + ", actual=" + std::to_string(response_command)); + constexpr int kMaximumSkippedMappingEvents = 16; + for (int attempt = 0; attempt <= kMaximumSkippedMappingEvents; ++attempt) { + std::uint16_t response_command = 0; + std::string payload_text_response; + const auto result = receiveFrame_( + sock, response_command, payload_text_response); + if (!result.ok()) { + return result; + } + if (response_command == expected_response_command) { + if (response_payload) { + *response_payload = std::move(payload_text_response); + } + return AgvResult::success(); + } + + const bool is_mapping_event = + sock == sock_other_ + && response_command == kRobotOtherMappingEventResponse; + if (!is_mapping_event) { + return AgvResult::failure( + AgvErrorCode::CommandFailed, + "SEER Robokit response command mismatch: expected=" + + std::to_string(expected_response_command) + + ", actual=" + std::to_string(response_command)); + } } - if (response_payload) { - *response_payload = std::move(payload_text_response); - } - return AgvResult::success(); + return AgvResult::failure( + AgvErrorCode::Timeout, + "SEER Robokit timed out waiting for response command " + + std::to_string(expected_response_command) + + " after repeated asynchronous mapping events"); }; const auto close_matching_socket_locked = [this, sock]() { if (sock == sock_status_) {