From 18fe8342adb460d107d4e442ec7ae3fa724e7d01 Mon Sep 17 00:00:00 2001 From: Jonas Vautherin Date: Tue, 10 Oct 2023 11:32:00 +0200 Subject: [PATCH 1/3] camera: fix storage_type translation from MAVLink to MAVSDK --- src/mavsdk/plugins/camera/camera_impl.cpp | 26 +++++++++++++++++++++-- src/mavsdk/plugins/camera/camera_impl.h | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/mavsdk/plugins/camera/camera_impl.cpp b/src/mavsdk/plugins/camera/camera_impl.cpp index 14a332b260..56d11c2877 100644 --- a/src/mavsdk/plugins/camera/camera_impl.cpp +++ b/src/mavsdk/plugins/camera/camera_impl.cpp @@ -917,14 +917,36 @@ void CameraImpl::process_storage_information(const mavlink_message_t& message) _status.data.used_storage_mib = storage_information.used_capacity; _status.data.total_storage_mib = storage_information.total_capacity; _status.data.storage_id = storage_information.storage_id; - _status.data.storage_type = - static_cast(storage_information.type); + _status.data.storage_type = storage_type_from_mavlink(storage_information.type); _status.received_storage_information = true; } check_status(); } +Camera::Status::StorageType +CameraImpl::storage_type_from_mavlink(const int storage_type) const +{ + switch (storage_type) { + default: + LogErr() << "Unknown storage_type enum value: " << storage_type; + // FALLTHROUGH + case STORAGE_TYPE_UNKNOWN: + return mavsdk::Camera::Status::StorageType::Unknown; + case STORAGE_TYPE_USB_STICK: + return mavsdk::Camera::Status::StorageType::UsbStick; + case STORAGE_TYPE_SD: + return mavsdk::Camera::Status::StorageType::Sd; + case STORAGE_TYPE_MICROSD: + return mavsdk::Camera::Status::StorageType::Microsd; + case STORAGE_TYPE_HD: + return mavsdk::Camera::Status::StorageType::Hd; + case STORAGE_TYPE_OTHER: + return mavsdk::Camera::Status::StorageType::Other; + } +} + + void CameraImpl::process_camera_image_captured(const mavlink_message_t& message) { mavlink_camera_image_captured_t image_captured; diff --git a/src/mavsdk/plugins/camera/camera_impl.h b/src/mavsdk/plugins/camera/camera_impl.h index 980d066fd8..ec7e92be1b 100644 --- a/src/mavsdk/plugins/camera/camera_impl.h +++ b/src/mavsdk/plugins/camera/camera_impl.h @@ -133,6 +133,8 @@ class CameraImpl : public PluginImplBase { void process_video_stream_status(const mavlink_message_t& message); void process_flight_information(const mavlink_message_t& message); + Camera::Status::StorageType storage_type_from_mavlink(const int storage_type) const; + Camera::EulerAngle to_euler_angle_from_quaternion(Camera::Quaternion quaternion); void notify_mode(); From ac9878191a502e595f6ed8b0d92264d9f7145d1e Mon Sep 17 00:00:00 2001 From: Jonas Vautherin Date: Tue, 10 Oct 2023 11:32:33 +0200 Subject: [PATCH 2/3] camera: small refactoring --- src/mavsdk/plugins/camera/camera_impl.cpp | 39 ++++++++++++----------- src/mavsdk/plugins/camera/camera_impl.h | 1 + 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/mavsdk/plugins/camera/camera_impl.cpp b/src/mavsdk/plugins/camera/camera_impl.cpp index 56d11c2877..b41205b3d0 100644 --- a/src/mavsdk/plugins/camera/camera_impl.cpp +++ b/src/mavsdk/plugins/camera/camera_impl.cpp @@ -894,25 +894,7 @@ void CameraImpl::process_storage_information(const mavlink_message_t& message) { std::lock_guard lock(_status.mutex); - switch (storage_information.status) { - case STORAGE_STATUS_EMPTY: - _status.data.storage_status = Camera::Status::StorageStatus::NotAvailable; - break; - case STORAGE_STATUS_UNFORMATTED: - _status.data.storage_status = Camera::Status::StorageStatus::Unformatted; - break; - case STORAGE_STATUS_READY: - _status.data.storage_status = Camera::Status::StorageStatus::Formatted; - break; - case STORAGE_STATUS_NOT_SUPPORTED: - _status.data.storage_status = Camera::Status::StorageStatus::NotSupported; - break; - default: - _status.data.storage_status = Camera::Status::StorageStatus::NotSupported; - LogErr() << "Unknown storage status received."; - break; - } - + _status.data.storage_status = storage_status_from_mavlink(storage_information.status); _status.data.available_storage_mib = storage_information.available_capacity; _status.data.used_storage_mib = storage_information.used_capacity; _status.data.total_storage_mib = storage_information.total_capacity; @@ -924,6 +906,25 @@ void CameraImpl::process_storage_information(const mavlink_message_t& message) check_status(); } +Camera::Status::StorageStatus +CameraImpl::storage_status_from_mavlink(const int storage_status) const +{ + switch (storage_status) { + case STORAGE_STATUS_EMPTY: + return Camera::Status::StorageStatus::NotAvailable; + case STORAGE_STATUS_UNFORMATTED: + return Camera::Status::StorageStatus::Unformatted; + case STORAGE_STATUS_READY: + return Camera::Status::StorageStatus::Formatted; + break; + case STORAGE_STATUS_NOT_SUPPORTED: + return Camera::Status::StorageStatus::NotSupported; + default: + LogErr() << "Unknown storage status received."; + return Camera::Status::StorageStatus::NotSupported; + } +} + Camera::Status::StorageType CameraImpl::storage_type_from_mavlink(const int storage_type) const { diff --git a/src/mavsdk/plugins/camera/camera_impl.h b/src/mavsdk/plugins/camera/camera_impl.h index ec7e92be1b..552619696a 100644 --- a/src/mavsdk/plugins/camera/camera_impl.h +++ b/src/mavsdk/plugins/camera/camera_impl.h @@ -133,6 +133,7 @@ class CameraImpl : public PluginImplBase { void process_video_stream_status(const mavlink_message_t& message); void process_flight_information(const mavlink_message_t& message); + Camera::Status::StorageStatus storage_status_from_mavlink(const int storage_status) const; Camera::Status::StorageType storage_type_from_mavlink(const int storage_type) const; Camera::EulerAngle to_euler_angle_from_quaternion(Camera::Quaternion quaternion); From 53fd4dc4506f88471dd009affd731ac0f9e6d64c Mon Sep 17 00:00:00 2001 From: Jonas Vautherin Date: Tue, 10 Oct 2023 11:33:26 +0200 Subject: [PATCH 3/3] Fix style --- src/mavsdk/plugins/camera/camera_impl.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mavsdk/plugins/camera/camera_impl.cpp b/src/mavsdk/plugins/camera/camera_impl.cpp index b41205b3d0..41a93303a1 100644 --- a/src/mavsdk/plugins/camera/camera_impl.cpp +++ b/src/mavsdk/plugins/camera/camera_impl.cpp @@ -925,8 +925,7 @@ CameraImpl::storage_status_from_mavlink(const int storage_status) const } } -Camera::Status::StorageType -CameraImpl::storage_type_from_mavlink(const int storage_type) const +Camera::Status::StorageType CameraImpl::storage_type_from_mavlink(const int storage_type) const { switch (storage_type) { default: @@ -947,7 +946,6 @@ CameraImpl::storage_type_from_mavlink(const int storage_type) const } } - void CameraImpl::process_camera_image_captured(const mavlink_message_t& message) { mavlink_camera_image_captured_t image_captured;