diff --git a/cmvr-es/devices/dexhand/oymotion_ap001/include/oymotion_ap001.h b/cmvr-es/devices/dexhand/oymotion_ap001/include/oymotion_ap001.h index ed886384..b3d8e43a 100644 --- a/cmvr-es/devices/dexhand/oymotion_ap001/include/oymotion_ap001.h +++ b/cmvr-es/devices/dexhand/oymotion_ap001/include/oymotion_ap001.h @@ -13,76 +13,85 @@ namespace cmvr::device { -class OYMotionAP001 : public AbstractDexHand { -public: - static constexpr size_t MOTOR_COUNT = 6; - explicit OYMotionAP001(const config::OYMotionAP001Config& config); - ~OYMotionAP001() override; - std::string typeName() const override { return type_name_; } - bool init() override; - bool start() override; - bool stop() override; - Status state() const override; - std::string lastError() const override; - void getState(DexHandState& state) override; - void setAngles(const std::vector& values) override; - void setPositions(const std::vector& values) override; - void setVelocities(const std::vector& values) override; - void setForce(const std::vector& values) override; - void setTactilePollingRegions(const std::vector& regions) override; - bool acquireSensorDataStream() override; - void releaseSensorDataStream() override; - std::vector getSensorData() override; - TactileRegionData getSensorData(FingerType finger, TactileRegion region) override; - ResultantForce getResultantForce(FingerType finger, TactileRegion region) override; - ForceNewtons getResultantForceNewtons(FingerType finger, TactileRegion region) override; + class OYMotionAP001 : public AbstractDexHand { + public: + static constexpr size_t MOTOR_COUNT = 6; -protected: - OYMotionAP001(std::string id, std::string can_interface, - uint32_t hand_id, uint32_t master_id, - uint32_t command_timeout_ms, std::string type_name); + explicit OYMotionAP001(const config::OYMotionAP001Config& config); + ~OYMotionAP001() override; -private: - static uint32_t sdkMillis(); - static void sdkDelay(uint32_t milliseconds); - static void sdkSend(uint8_t address, uint8_t* data, uint8_t size, void* context); - static void sdkReceive(void* context); - static OYMotionAP001* fromSdkContext(void* context); - bool openSocket(); - bool checkSdkResult(uint8_t result, uint8_t remote_error, const char* operation); - void startTactilePolling(); - void stopTactilePolling(); - void tactilePollingLoop(); - void setFault(const std::string& message); - void setState(Status state); - std::array normalizedPositions(const std::vector& values, int maximum) const; + std::string typeName() const override { return type_name_; } + bool init() override; + bool start() override; + bool stop() override; - std::string type_name_{"OYMotionAP001"}; - std::string can_interface_; - uint32_t command_timeout_ms_{255}; - uint8_t hand_id_{2}; - uint8_t master_id_{1}; - int socket_fd_{-1}; - void* sdk_context_{nullptr}; - mutable std::mutex state_mutex_; - mutable std::mutex io_mutex_; - Status lifecycle_state_{Status::CREATED}; - std::string last_error_; - std::array speeds_{{255, 255, 255, 255, 255, 255}}; - std::array current_positions_{}; - // OHand SDK reports the physical joint angle in degrees * 100. - std::array current_angles_{}; - std::vector tactile_regions_; - static constexpr size_t INDEX_TACTILE_COUNT = 60; - std::atomic tactile_running_{false}; - std::mutex tactile_subscription_mutex_; - size_t tactile_subscriber_count_{0}; - std::thread tactile_thread_; - mutable std::mutex tactile_mutex_; - std::array index_tactile_{}; - bool index_tactile_valid_{false}; - uint64_t index_tactile_sequence_{0}; -}; + Status state() const override; + std::string lastError() const override; + void getState(DexHandState& state) override; + + void setAngles(const std::vector& values) override; + void setPositions(const std::vector& values) override; + void setVelocities(const std::vector& values) override; + void setForce(const std::vector& values) override; + + void setTactilePollingRegions(const std::vector& regions) override; + bool acquireSensorDataStream() override; + void releaseSensorDataStream() override; + + std::vector getSensorData() override; + TactileRegionData getSensorData(FingerType finger, TactileRegion region) override; + ResultantForce getResultantForce(FingerType finger, TactileRegion region) override; + ForceNewtons getResultantForceNewtons(FingerType finger, TactileRegion region) override; + + protected: + OYMotionAP001(std::string id, std::string can_interface, + uint32_t hand_id, uint32_t master_id, + uint32_t command_timeout_ms, std::string type_name); + + private: + static uint32_t sdkMillis(); + static void sdkDelay(uint32_t milliseconds); + static void sdkSend(uint8_t address, uint8_t* data, uint8_t size, void* context); + static void sdkReceive(void* context); + static OYMotionAP001* fromSdkContext(void* context); + bool openSocket(); + bool checkSdkResult(uint8_t result, uint8_t remote_error, const char* operation); + void startTactilePolling(); + void stopTactilePolling(); + void tactilePollingLoop(); + void setFault(const std::string& message); + void setState(Status state); + std::array normalizedPositions(const std::vector& values, int maximum) const; + + std::string type_name_{"OYMotionAP001"}; + std::string can_interface_; + uint32_t command_timeout_ms_{255}; + uint8_t hand_id_{2}; + uint8_t master_id_{1}; + int socket_fd_{-1}; + void* sdk_context_{nullptr}; + + mutable std::mutex state_mutex_; + mutable std::mutex io_mutex_; + Status lifecycle_state_{Status::CREATED}; + std::string last_error_; + + std::array speeds_{{255, 255, 255, 255, 255, 255}}; + std::array current_positions_{}; + // OHand SDK reports the physical joint angle in degrees * 100. + std::array current_angles_{}; + + std::vector tactile_regions_; + static constexpr size_t INDEX_TACTILE_COUNT = 60; + std::atomic tactile_running_{false}; + std::mutex tactile_subscription_mutex_; + size_t tactile_subscriber_count_{0}; + std::thread tactile_thread_; + mutable std::mutex tactile_mutex_; + std::array index_tactile_{}; + bool index_tactile_valid_{false}; + uint64_t index_tactile_sequence_{0}; + }; } // namespace cmvr::device -#endif +#endif // CMVR_ES_OYMOTION_AP001_H diff --git a/cmvr-es/devices/dexhand/oymotion_ap001/src/oymotion_ap001.cpp b/cmvr-es/devices/dexhand/oymotion_ap001/src/oymotion_ap001.cpp index e5c81780..ee722d85 100644 --- a/cmvr-es/devices/dexhand/oymotion_ap001/src/oymotion_ap001.cpp +++ b/cmvr-es/devices/dexhand/oymotion_ap001/src/oymotion_ap001.cpp @@ -5,6 +5,7 @@ #include #include #include + #include #include #include @@ -13,51 +14,52 @@ #include #include #include "OHandSerialAPI.h" + #include "common/base/logging/logger.h" namespace cmvr::device { namespace { -constexpr int kPositionInputMaximum = 2000; -constexpr int kAngleInputMaximum = 1000; -constexpr int kVelocityInputMaximum = 1000; -constexpr int kForceInputMaximum = 3000; -constexpr uint8_t kIndexTactileSensorId = 1; -constexpr int kIndexTactileRows = 12; -constexpr int kIndexTactileCols = 5; -constexpr auto kTactilePollingPeriod = std::chrono::microseconds(6667); + constexpr int kPositionInputMaximum = 2000; + constexpr int kAngleInputMaximum = 1000; + constexpr int kVelocityInputMaximum = 1000; + constexpr int kForceInputMaximum = 3000; + constexpr uint8_t kIndexTactileSensorId = 1; + constexpr int kIndexTactileRows = 12; + constexpr int kIndexTactileCols = 5; + constexpr auto kTactilePollingPeriod = std::chrono::microseconds(6667); -// cmvr-es exposes dex-hand joints as: -// pinky, ring, middle, index, thumb flexion, thumb rotation. -// OHand SDK uses: -// thumb flexion, index, middle, ring, pinky, thumb rotation. -constexpr std::array kApiToSdkMotor{ - 4, 3, 2, 1, 0, 5}; + // cmvr-es exposes dex-hand joints as: + // pinky, ring, middle, index, thumb flexion, thumb rotation. + // OHand SDK uses: + // thumb flexion, index, middle, ring, pinky, thumb rotation. + constexpr std::array kApiToSdkMotor{ + 4, 3, 2, 1, 0, 5}; -template -std::array apiToSdkMotorOrder( - const std::array& api_values) { - std::array sdk_values{}; - for (size_t api_index = 0; api_index < kApiToSdkMotor.size(); ++api_index) { - sdk_values[kApiToSdkMotor[api_index]] = api_values[api_index]; + template + std::array apiToSdkMotorOrder( + const std::array& api_values) { + std::array sdk_values{}; + for (size_t api_index = 0; api_index < kApiToSdkMotor.size(); ++api_index) { + sdk_values[kApiToSdkMotor[api_index]] = api_values[api_index]; + } + return sdk_values; } - return sdk_values; -} -template -std::array sdkToApiMotorOrder( - const std::array& sdk_values) { - std::array api_values{}; - for (size_t api_index = 0; api_index < kApiToSdkMotor.size(); ++api_index) { - api_values[api_index] = sdk_values[kApiToSdkMotor[api_index]]; + template + std::array sdkToApiMotorOrder( + const std::array& sdk_values) { + std::array api_values{}; + for (size_t api_index = 0; api_index < kApiToSdkMotor.size(); ++api_index) { + api_values[api_index] = sdk_values[kApiToSdkMotor[api_index]]; + } + return api_values; } - return api_values; -} -struct TactileSnapshot { - std::array(kIndexTactileRows * kIndexTactileCols)> - values{}; -}; + struct TactileSnapshot { + std::array(kIndexTactileRows * kIndexTactileCols)> + values{}; + }; } OYMotionAP001::OYMotionAP001(const config::OYMotionAP001Config& config) @@ -72,21 +74,37 @@ OYMotionAP001::OYMotionAP001(std::string id, std::string can_interface, can_interface_(can_interface.empty() ? "can0" : std::move(can_interface)), command_timeout_ms_(command_timeout_ms == 0 ? 255 : command_timeout_ms) { id_ = std::move(id); - if (hand_id > 0 && hand_id <= 0xff) hand_id_ = static_cast(hand_id); - if (master_id > 0 && master_id <= 0xff) master_id_ = static_cast(master_id); + if (hand_id > 0 && hand_id <= 0xff) { + hand_id_ = static_cast(hand_id); + } + if (master_id > 0 && master_id <= 0xff) { + master_id_ = static_cast(master_id); + } +} + +OYMotionAP001::~OYMotionAP001() { + stop(); } -OYMotionAP001::~OYMotionAP001() { stop(); } uint32_t OYMotionAP001::sdkMillis() { static const auto start = std::chrono::steady_clock::now(); - return static_cast(std::chrono::duration_cast(std::chrono::steady_clock::now() - start).count()); + return static_cast(std::chrono::duration_cast( + std::chrono::steady_clock::now() - start).count()); +} + +void OYMotionAP001::sdkDelay(uint32_t milliseconds) { + std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); +} + +OYMotionAP001* OYMotionAP001::fromSdkContext(void* context) { + return context ? *static_cast(context) : nullptr; } -void OYMotionAP001::sdkDelay(uint32_t milliseconds) { std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); } -OYMotionAP001* OYMotionAP001::fromSdkContext(void* context) { return context ? *static_cast(context) : nullptr; } void OYMotionAP001::sdkSend(uint8_t address, uint8_t* data, uint8_t size, void* context) { auto* self = fromSdkContext(context); - if (!self || self->socket_fd_ < 0) return; + if (!self || self->socket_fd_ < 0) { + return; + } for (uint8_t offset = 0; offset < size; offset += CAN_MAX_DLEN) { can_frame frame{}; frame.can_id = address; @@ -101,49 +119,80 @@ void OYMotionAP001::sdkSend(uint8_t address, uint8_t* data, uint8_t size, void* void OYMotionAP001::sdkReceive(void* context) { auto* self = fromSdkContext(context); - if (!self || self->socket_fd_ < 0) return; + if (!self || self->socket_fd_ < 0) { + return; + } can_frame frame{}; while (read(self->socket_fd_, &frame, sizeof(frame)) == sizeof(frame)) { - if ((frame.can_id & CAN_EFF_FLAG) || (frame.can_id & CAN_RTR_FLAG)) continue; - for (uint8_t i = 0; i < frame.can_dlc; ++i) HAND_OnData(context, frame.data[i]); + if ((frame.can_id & CAN_EFF_FLAG) || (frame.can_id & CAN_RTR_FLAG)) { + continue; + } + for (uint8_t i = 0; i < frame.can_dlc; ++i) { + HAND_OnData(context, frame.data[i]); + } } } bool OYMotionAP001::openSocket() { socket_fd_ = socket(PF_CAN, SOCK_RAW, CAN_RAW); - if (socket_fd_ < 0) return false; + if (socket_fd_ < 0) { + return false; + } ifreq request{}; std::strncpy(request.ifr_name, can_interface_.c_str(), IFNAMSIZ - 1); - if (ioctl(socket_fd_, SIOCGIFINDEX, &request) < 0) return false; + if (ioctl(socket_fd_, SIOCGIFINDEX, &request) < 0) { + return false; + } sockaddr_can address{}; address.can_family = AF_CAN; address.can_ifindex = request.ifr_ifindex; - if (bind(socket_fd_, reinterpret_cast(&address), sizeof(address)) < 0) return false; + if (bind(socket_fd_, reinterpret_cast(&address), sizeof(address)) < 0) { + return false; + } const int flags = fcntl(socket_fd_, F_GETFL, 0); return flags >= 0 && fcntl(socket_fd_, F_SETFL, flags | O_NONBLOCK) == 0; } bool OYMotionAP001::init() { std::lock_guard io_lock(io_mutex_); - if (sdk_context_) return true; - if (!openSocket()) { setFault("[OYMotionAP001] cannot open " + can_interface_ + "; ensure it is UP at 1 Mbps"); return false; } + if (sdk_context_) { + return true; + } + if (!openSocket()) { + setFault("[OYMotionAP001] cannot open " + can_interface_ + "; ensure it is UP at 1 Mbps"); + return false; + } HAND_SetTimerFunction(sdkMillis, sdkDelay); sdk_context_ = HAND_CreateContext(this, HAND_PROTOCOL_UART, master_id_, sdkSend, sdkReceive); - if (!sdk_context_) { setFault("[OYMotionAP001] HAND_CreateContext failed"); return false; } + if (!sdk_context_) { + setFault("[OYMotionAP001] HAND_CreateContext failed"); + return false; + } HAND_SetCommandTimeOut(sdk_context_, static_cast( std::min(command_timeout_ms_, 65535))); uint8_t major = 0, minor = 0, remote_error = 0; - if (!checkSdkResult(HAND_GetProtocolVersion(sdk_context_, hand_id_, &major, &minor, &remote_error), remote_error, "HAND_GetProtocolVersion")) return false; - CMVR_LOG(INFO) << "[OYMotionAP001] connected: id=" << id_ << ", interface=" << can_interface_ << ", hand_id=" << static_cast(hand_id_) << ", protocol=" << static_cast(major) << "." << static_cast(minor); + if (!checkSdkResult( + HAND_GetProtocolVersion( + sdk_context_, hand_id_, &major, &minor, &remote_error), + remote_error, "HAND_GetProtocolVersion")) { + return false; + } + CMVR_LOG(INFO) << "[OYMotionAP001] connected: id=" << id_ + << ", interface=" << can_interface_ + << ", hand_id=" << static_cast(hand_id_) + << ", protocol=" << static_cast(major) << "." << static_cast(minor); setState(Status::INITIALIZED); return true; } bool OYMotionAP001::start() { - if (!init()) return false; + if (!init()) { + return false; + } setState(Status::STREAMING); return true; } + bool OYMotionAP001::stop() { { std::lock_guard subscription_lock( @@ -152,13 +201,29 @@ bool OYMotionAP001::stop() { stopTactilePolling(); } std::lock_guard io_lock(io_mutex_); - if (sdk_context_) { HAND_FreeContext(sdk_context_); sdk_context_ = nullptr; } - if (socket_fd_ >= 0) { close(socket_fd_); socket_fd_ = -1; } - if (state() != Status::FAULT) setState(Status::STOPPED); + if (sdk_context_) { + HAND_FreeContext(sdk_context_); + sdk_context_ = nullptr; + } + if (socket_fd_ >= 0) { + close(socket_fd_); + socket_fd_ = -1; + } + if (state() != Status::FAULT) { + setState(Status::STOPPED); + } return true; } -AbstractDexHand::Status OYMotionAP001::state() const { std::lock_guard lock(state_mutex_); return lifecycle_state_; } -std::string OYMotionAP001::lastError() const { std::lock_guard lock(state_mutex_); return last_error_; } + +AbstractDexHand::Status OYMotionAP001::state() const { + std::lock_guard lock(state_mutex_); + return lifecycle_state_; +} + +std::string OYMotionAP001::lastError() const { + std::lock_guard lock(state_mutex_); + return last_error_; +} void OYMotionAP001::getState(DexHandState& output) { DexHandState next{}; @@ -211,14 +276,22 @@ void OYMotionAP001::getState(DexHandState& output) { next.hands[i].speed = static_cast(speeds_[i]) * kVelocityInputMaximum / 255; } const auto error = lastError(); - if (!error.empty()) next.hands[0].error_message.push_back(error); + if (!error.empty()) { + next.hands[0].error_message.push_back(error); + } output = std::move(next); } -std::array OYMotionAP001::normalizedPositions(const std::vector& values, int maximum) const { - if (values.size() != MOTOR_COUNT) throw std::invalid_argument("OYMotionAP001 expects exactly 6 values"); +std::array OYMotionAP001::normalizedPositions( + const std::vector& values, int maximum) const { + if (values.size() != MOTOR_COUNT) { + throw std::invalid_argument("OYMotionAP001 expects exactly 6 values"); + } std::array output{}; - for (size_t i = 0; i < MOTOR_COUNT; ++i) output[i] = static_cast(static_cast(std::clamp(values[i], 0, maximum)) * 65535U / maximum); + for (size_t i = 0; i < MOTOR_COUNT; ++i) { + output[i] = static_cast( + static_cast(std::clamp(values[i], 0, maximum)) * 65535U / maximum); + } return output; } @@ -228,23 +301,41 @@ void OYMotionAP001::setPositions(const std::vector& values) { std::lock_guard lock(io_mutex_); auto speeds = apiToSdkMotorOrder(speeds_); uint8_t remote_error = 0; - checkSdkResult(HAND_SetFingerPosAll(sdk_context_, hand_id_, positions.data(), speeds.data(), MOTOR_COUNT, &remote_error), remote_error, "HAND_SetFingerPosAll"); + checkSdkResult( + HAND_SetFingerPosAll( + sdk_context_, hand_id_, positions.data(), speeds.data(), + MOTOR_COUNT, &remote_error), + remote_error, "HAND_SetFingerPosAll"); } + void OYMotionAP001::setAngles(const std::vector& values) { auto positions = apiToSdkMotorOrder( normalizedPositions(values, kAngleInputMaximum)); std::lock_guard lock(io_mutex_); auto speeds = apiToSdkMotorOrder(speeds_); uint8_t remote_error = 0; - checkSdkResult(HAND_SetFingerPosAll(sdk_context_, hand_id_, positions.data(), speeds.data(), MOTOR_COUNT, &remote_error), remote_error, "HAND_SetFingerPosAll(angle normalization)"); + checkSdkResult( + HAND_SetFingerPosAll( + sdk_context_, hand_id_, positions.data(), speeds.data(), + MOTOR_COUNT, &remote_error), + remote_error, "HAND_SetFingerPosAll(angle normalization)"); } + void OYMotionAP001::setVelocities(const std::vector& values) { - if (values.size() != MOTOR_COUNT) throw std::invalid_argument("OYMotionAP001 expects exactly 6 velocities"); + if (values.size() != MOTOR_COUNT) { + throw std::invalid_argument("OYMotionAP001 expects exactly 6 velocities"); + } std::lock_guard lock(io_mutex_); - for (size_t i = 0; i < MOTOR_COUNT; ++i) speeds_[i] = static_cast(std::clamp(values[i], 0, kVelocityInputMaximum) * 255 / kVelocityInputMaximum); + for (size_t i = 0; i < MOTOR_COUNT; ++i) { + speeds_[i] = static_cast( + std::clamp(values[i], 0, kVelocityInputMaximum) * 255 / kVelocityInputMaximum); + } } + void OYMotionAP001::setForce(const std::vector& values) { - if (values.size() != MOTOR_COUNT) throw std::invalid_argument("OYMotionAP001 expects exactly 6 force values"); + if (values.size() != MOTOR_COUNT) { + throw std::invalid_argument("OYMotionAP001 expects exactly 6 force values"); + } std::lock_guard lock(io_mutex_); for (size_t api_index = 0; api_index < MOTOR_COUNT; ++api_index) { uint8_t remote_error = 0; @@ -263,13 +354,17 @@ void OYMotionAP001::setForce(const std::vector& values) { void OYMotionAP001::setTactilePollingRegions( const std::vector& regions) { - if (!hasTactileFeedback()) return; + if (!hasTactileFeedback()) { + return; + } std::lock_guard lock(io_mutex_); tactile_regions_ = regions; } bool OYMotionAP001::acquireSensorDataStream() { - if (!hasTactileFeedback()) return false; + if (!hasTactileFeedback()) { + return false; + } std::lock_guard lock(tactile_subscription_mutex_); ++tactile_subscriber_count_; if (tactile_subscriber_count_ == 1) { @@ -284,21 +379,31 @@ bool OYMotionAP001::acquireSensorDataStream() { void OYMotionAP001::releaseSensorDataStream() { std::lock_guard lock(tactile_subscription_mutex_); - if (tactile_subscriber_count_ == 0) return; + if (tactile_subscriber_count_ == 0) { + return; + } --tactile_subscriber_count_; - if (tactile_subscriber_count_ == 0) stopTactilePolling(); + if (tactile_subscriber_count_ == 0) { + stopTactilePolling(); + } } void OYMotionAP001::startTactilePolling() { - if (!hasTactileFeedback()) return; + if (!hasTactileFeedback()) { + return; + } bool expected = false; - if (!tactile_running_.compare_exchange_strong(expected, true)) return; + if (!tactile_running_.compare_exchange_strong(expected, true)) { + return; + } tactile_thread_ = std::thread(&OYMotionAP001::tactilePollingLoop, this); } void OYMotionAP001::stopTactilePolling() { tactile_running_.store(false); - if (tactile_thread_.joinable()) tactile_thread_.join(); + if (tactile_thread_.joinable()) { + tactile_thread_.join(); + } } void OYMotionAP001::tactilePollingLoop() { @@ -357,11 +462,15 @@ void OYMotionAP001::tactilePollingLoop() { } std::vector OYMotionAP001::getSensorData() { - if (!hasTactileFeedback()) return {}; + if (!hasTactileFeedback()) { + return {}; + } auto snapshot = std::make_shared(); { std::lock_guard lock(tactile_mutex_); - if (!index_tactile_valid_) return {}; + if (!index_tactile_valid_) { + return {}; + } snapshot->values = index_tactile_; } return {TactileRegionData{ @@ -373,7 +482,9 @@ std::vector OYMotionAP001::getSensorData() { AbstractDexHand::TactileRegionData OYMotionAP001::getSensorData( FingerType finger, TactileRegion region) { - if (finger != FingerType::INDEX || region != TactileRegion::PAD) return {}; + if (finger != FingerType::INDEX || region != TactileRegion::PAD) { + return {}; + } auto regions = getSensorData(); return regions.empty() ? TactileRegionData{} : regions.front(); } @@ -381,7 +492,9 @@ AbstractDexHand::TactileRegionData OYMotionAP001::getSensorData( AbstractDexHand::ResultantForce OYMotionAP001::getResultantForce( FingerType finger, TactileRegion region) { const auto tactile_data = getSensorData(finger, region); - if (!tactile_data.valid()) return {}; + if (!tactile_data.valid()) { + return {}; + } ResultantForce resultant{}; for (int row = 0; row < tactile_data.view.rows; ++row) { @@ -402,10 +515,30 @@ AbstractDexHand::ForceNewtons OYMotionAP001::getResultantForceNewtons( } bool OYMotionAP001::checkSdkResult(uint8_t result, uint8_t remote_error, const char* operation) { - if (result == HAND_RESP_SUCCESS) return true; - setFault("[OYMotionAP001] " + std::string(operation) + " failed: result=" + std::to_string(result) + ", remote_error=" + std::to_string(remote_error)); + if (result == HAND_RESP_SUCCESS) { + return true; + } + setFault("[OYMotionAP001] " + std::string(operation) + " failed: result=" + + std::to_string(result) + ", remote_error=" + + std::to_string(remote_error)); return false; } -void OYMotionAP001::setFault(const std::string& message) { { std::lock_guard lock(state_mutex_); lifecycle_state_ = Status::FAULT; last_error_ = message; } CMVR_LOG(ERROR) << message; } -void OYMotionAP001::setState(Status next) { std::lock_guard lock(state_mutex_); lifecycle_state_ = next; if (next == Status::INITIALIZED || next == Status::STREAMING) last_error_.clear(); } + +void OYMotionAP001::setFault(const std::string& message) { + { + std::lock_guard lock(state_mutex_); + lifecycle_state_ = Status::FAULT; + last_error_ = message; + } + CMVR_LOG(ERROR) << message; +} + +void OYMotionAP001::setState(Status next) { + std::lock_guard lock(state_mutex_); + lifecycle_state_ = next; + if (next == Status::INITIALIZED || next == Status::STREAMING) { + last_error_.clear(); + } +} + } // namespace cmvr::device