From e303cc64dff1f06605e29efab1b2a0f1892b8c02 Mon Sep 17 00:00:00 2001 From: Jonas Vautherin Date: Thu, 30 Aug 2018 20:03:57 +0200 Subject: [PATCH 1/2] backend: add recording_time_s to CameraStatus --- .../src/plugins/camera/camera_service_impl.h | 2 ++ backend/test/camera_service_impl_test.cpp | 36 +++++++++++++------ plugins/camera/camera.cpp | 9 ++--- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/backend/src/plugins/camera/camera_service_impl.h b/backend/src/plugins/camera/camera_service_impl.h index 053ea2af0a..5361cbf18f 100644 --- a/backend/src/plugins/camera/camera_service_impl.h +++ b/backend/src/plugins/camera/camera_service_impl.h @@ -457,6 +457,7 @@ class CameraServiceImpl final : public rpc::camera::CameraService::Service { status->set_storage_status(translateStorageStatus(camera_status.storage_status)); status->set_used_storage_mib(camera_status.used_storage_mib); status->set_available_storage_mib(camera_status.available_storage_mib); + status->set_recording_time_s(camera_status.recording_time_s); status->set_total_storage_mib(camera_status.total_storage_mib); return status; @@ -485,6 +486,7 @@ class CameraServiceImpl final : public rpc::camera::CameraService::Service { status.storage_status = translateRPCStorageStatus(rpc_camera_status.storage_status()); status.used_storage_mib = rpc_camera_status.used_storage_mib(); status.available_storage_mib = rpc_camera_status.available_storage_mib(); + status.recording_time_s = rpc_camera_status.recording_time_s(); status.total_storage_mib = rpc_camera_status.total_storage_mib(); return status; diff --git a/backend/test/camera_service_impl_test.cpp b/backend/test/camera_service_impl_test.cpp index fda0b1c163..f800eb830e 100644 --- a/backend/test/camera_service_impl_test.cpp +++ b/backend/test/camera_service_impl_test.cpp @@ -100,7 +100,8 @@ class CameraServiceImplTest : public ::testing::TestWithParam { const dronecode_sdk::Camera::Status::StorageStatus storage_status, const float used_storage_mib, const float available_storage_mib, - const float total_storage_mib) const; + const float total_storage_mib, + const float recording_time_s) const; std::future subscribeCameraStatusAsync(std::vector &camera_status_events, std::shared_ptr context) const; @@ -780,7 +781,7 @@ dronecode_sdk::Camera::CaptureInfo CameraServiceImplTest::createArbitraryCapture TEST_F(CameraServiceImplTest, registersToCameraStatus) { const auto expected_camera_status = - createCameraStatus(false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f); + createCameraStatus(false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f, 0.4f); dronecode_sdk::Camera::subscribe_status_callback_t status_callback; EXPECT_CALL(_camera, subscribe_status(_)) .WillOnce(SaveResult(&status_callback, &_callback_saved_promise)); @@ -800,7 +801,8 @@ dronecode_sdk::Camera::Status CameraServiceImplTest::createCameraStatus( const dronecode_sdk::Camera::Status::StorageStatus storage_status, const float used_storage_mib, const float available_storage_mib, - const float total_storage_mib) const + const float total_storage_mib, + const float recording_time_s) const { dronecode_sdk::Camera::Status status; status.video_on = is_video_on; @@ -809,6 +811,7 @@ dronecode_sdk::Camera::Status CameraServiceImplTest::createCameraStatus( status.used_storage_mib = used_storage_mib; status.available_storage_mib = available_storage_mib; status.total_storage_mib = total_storage_mib; + status.recording_time_s = recording_time_s; return status; } @@ -847,7 +850,7 @@ TEST_F(CameraServiceImplTest, sendsOneCameraStatus) { std::vector camera_status_events; auto camera_status_event = - createCameraStatus(false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f); + createCameraStatus(false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f, 22.4f); camera_status_events.push_back(camera_status_event); checkSendsCameraStatus(camera_status_events); @@ -872,7 +875,7 @@ void CameraServiceImplTest::checkSendsCameraStatus( } context->TryCancel(); auto arbitrary_camera_status_event = - createCameraStatus(false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f); + createCameraStatus(false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f, 0.0f); camera_status_callback(arbitrary_camera_status_event); camera_status_events_future.wait(); @@ -886,17 +889,30 @@ TEST_F(CameraServiceImplTest, sendsMultipleCameraStatus) { std::vector camera_status_events; - camera_status_events.push_back(createCameraStatus( - true, true, dronecode_sdk::Camera::Status::StorageStatus::UNFORMATTED, 1.2f, 3.4f, 2.2f)); - camera_status_events.push_back(createCameraStatus( - true, false, dronecode_sdk::Camera::Status::StorageStatus::FORMATTED, 11.2f, 58.4f, 8.65f)); + camera_status_events.push_back( + createCameraStatus(true, + true, + dronecode_sdk::Camera::Status::StorageStatus::UNFORMATTED, + 1.2f, + 3.4f, + 2.2f, + 2.3f)); + camera_status_events.push_back( + createCameraStatus(true, + false, + dronecode_sdk::Camera::Status::StorageStatus::FORMATTED, + 11.2f, + 58.4f, + 8.65f, + 2.2f)); camera_status_events.push_back( createCameraStatus(false, false, dronecode_sdk::Camera::Status::StorageStatus::NOT_AVAILABLE, 1.5f, 8.1f, - 6.3f)); + 6.3f, + 1.4f)); checkSendsCameraStatus(camera_status_events); } diff --git a/plugins/camera/camera.cpp b/plugins/camera/camera.cpp index 21da2affde..6872e87da9 100644 --- a/plugins/camera/camera.cpp +++ b/plugins/camera/camera.cpp @@ -284,20 +284,21 @@ std::ostream &operator<<(std::ostream &str, Camera::CaptureInfo::Quaternion cons bool operator==(const Camera::Status &lhs, const Camera::Status &rhs) { return lhs.video_on == rhs.video_on && lhs.photo_interval_on == rhs.photo_interval_on && - lhs.storage_status == rhs.storage_status && lhs.used_storage_mib == rhs.used_storage_mib && lhs.available_storage_mib == rhs.available_storage_mib && - lhs.total_storage_mib == rhs.total_storage_mib; + lhs.total_storage_mib == rhs.total_storage_mib && + lhs.recording_time_s == rhs.recording_time_s && lhs.storage_status == rhs.storage_status; } std::ostream &operator<<(std::ostream &str, Camera::Status const &status) { return str << "[video_on: " << status.video_on << ", photo_interval_on: " << status.photo_interval_on - << ", storage_status: " << status.storage_status << ", used_storage_mib: " << status.used_storage_mib << ", available_storage_mib: " << status.available_storage_mib - << ", total_storage_mib: " << status.total_storage_mib << "]"; + << ", total_storage_mib: " << status.total_storage_mib + << ", recording_time_s: " << status.recording_time_s + << ", storage_status: " << status.storage_status << "]"; } std::ostream &operator<<(std::ostream &str, Camera::Status::StorageStatus const &storage_status) From 9707e5ca15c842d591e10cb56964381dc1428581 Mon Sep 17 00:00:00 2001 From: Jonas Vautherin Date: Thu, 30 Aug 2018 20:11:43 +0200 Subject: [PATCH 2/2] backend: add media_folder_name to CameraStatus --- backend/proto | 2 +- .../src/plugins/camera/camera_service_impl.h | 2 ++ backend/test/camera_service_impl_test.cpp | 28 +++++++++++-------- plugins/camera/camera.cpp | 2 ++ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/backend/proto b/backend/proto index 2c46494b11..e7a285733a 160000 --- a/backend/proto +++ b/backend/proto @@ -1 +1 @@ -Subproject commit 2c46494b11cf99b48f932e4ee3fae241d630b96d +Subproject commit e7a285733aa03e4b56a771551a68e3f2d4b91a6f diff --git a/backend/src/plugins/camera/camera_service_impl.h b/backend/src/plugins/camera/camera_service_impl.h index 5361cbf18f..918756a4f5 100644 --- a/backend/src/plugins/camera/camera_service_impl.h +++ b/backend/src/plugins/camera/camera_service_impl.h @@ -458,6 +458,7 @@ class CameraServiceImpl final : public rpc::camera::CameraService::Service { status->set_used_storage_mib(camera_status.used_storage_mib); status->set_available_storage_mib(camera_status.available_storage_mib); status->set_recording_time_s(camera_status.recording_time_s); + status->set_media_folder_name(camera_status.media_folder_name); status->set_total_storage_mib(camera_status.total_storage_mib); return status; @@ -487,6 +488,7 @@ class CameraServiceImpl final : public rpc::camera::CameraService::Service { status.used_storage_mib = rpc_camera_status.used_storage_mib(); status.available_storage_mib = rpc_camera_status.available_storage_mib(); status.recording_time_s = rpc_camera_status.recording_time_s(); + status.media_folder_name = rpc_camera_status.media_folder_name(); status.total_storage_mib = rpc_camera_status.total_storage_mib(); return status; diff --git a/backend/test/camera_service_impl_test.cpp b/backend/test/camera_service_impl_test.cpp index f800eb830e..2b5df097b1 100644 --- a/backend/test/camera_service_impl_test.cpp +++ b/backend/test/camera_service_impl_test.cpp @@ -101,7 +101,8 @@ class CameraServiceImplTest : public ::testing::TestWithParam { const float used_storage_mib, const float available_storage_mib, const float total_storage_mib, - const float recording_time_s) const; + const float recording_time_s, + const std::string media_folder_name) const; std::future subscribeCameraStatusAsync(std::vector &camera_status_events, std::shared_ptr context) const; @@ -780,8 +781,8 @@ dronecode_sdk::Camera::CaptureInfo CameraServiceImplTest::createArbitraryCapture TEST_F(CameraServiceImplTest, registersToCameraStatus) { - const auto expected_camera_status = - createCameraStatus(false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f, 0.4f); + const auto expected_camera_status = createCameraStatus( + false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f, 0.4f, "100E90HD"); dronecode_sdk::Camera::subscribe_status_callback_t status_callback; EXPECT_CALL(_camera, subscribe_status(_)) .WillOnce(SaveResult(&status_callback, &_callback_saved_promise)); @@ -802,7 +803,8 @@ dronecode_sdk::Camera::Status CameraServiceImplTest::createCameraStatus( const float used_storage_mib, const float available_storage_mib, const float total_storage_mib, - const float recording_time_s) const + const float recording_time_s, + const std::string media_folder_name) const { dronecode_sdk::Camera::Status status; status.video_on = is_video_on; @@ -812,6 +814,7 @@ dronecode_sdk::Camera::Status CameraServiceImplTest::createCameraStatus( status.available_storage_mib = available_storage_mib; status.total_storage_mib = total_storage_mib; status.recording_time_s = recording_time_s; + status.media_folder_name = media_folder_name; return status; } @@ -849,8 +852,8 @@ TEST_F(CameraServiceImplTest, doesNotSendCameraStatusIfCallbackNotCalled) TEST_F(CameraServiceImplTest, sendsOneCameraStatus) { std::vector camera_status_events; - auto camera_status_event = - createCameraStatus(false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f, 22.4f); + auto camera_status_event = createCameraStatus( + false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f, 22.4f, "105E90HD"); camera_status_events.push_back(camera_status_event); checkSendsCameraStatus(camera_status_events); @@ -874,8 +877,8 @@ void CameraServiceImplTest::checkSendsCameraStatus( camera_status_callback(camera_status_event); } context->TryCancel(); - auto arbitrary_camera_status_event = - createCameraStatus(false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f, 0.0f); + auto arbitrary_camera_status_event = createCameraStatus( + false, true, ARBITRARY_CAMERA_STORAGE_STATUS, 3.4f, 12.6f, 16.0f, 0.0f, "111E90HD"); camera_status_callback(arbitrary_camera_status_event); camera_status_events_future.wait(); @@ -896,7 +899,8 @@ TEST_F(CameraServiceImplTest, sendsMultipleCameraStatus) 1.2f, 3.4f, 2.2f, - 2.3f)); + 2.3f, + "104E90HD")); camera_status_events.push_back( createCameraStatus(true, false, @@ -904,7 +908,8 @@ TEST_F(CameraServiceImplTest, sendsMultipleCameraStatus) 11.2f, 58.4f, 8.65f, - 2.2f)); + 2.2f, + "360E90HD")); camera_status_events.push_back( createCameraStatus(false, false, @@ -912,7 +917,8 @@ TEST_F(CameraServiceImplTest, sendsMultipleCameraStatus) 1.5f, 8.1f, 6.3f, - 1.4f)); + 1.4f, + "GOPRO621")); checkSendsCameraStatus(camera_status_events); } diff --git a/plugins/camera/camera.cpp b/plugins/camera/camera.cpp index 6872e87da9..a93e01194d 100644 --- a/plugins/camera/camera.cpp +++ b/plugins/camera/camera.cpp @@ -287,6 +287,7 @@ bool operator==(const Camera::Status &lhs, const Camera::Status &rhs) lhs.used_storage_mib == rhs.used_storage_mib && lhs.available_storage_mib == rhs.available_storage_mib && lhs.total_storage_mib == rhs.total_storage_mib && + lhs.media_folder_name == rhs.media_folder_name && lhs.recording_time_s == rhs.recording_time_s && lhs.storage_status == rhs.storage_status; } @@ -298,6 +299,7 @@ std::ostream &operator<<(std::ostream &str, Camera::Status const &status) << ", available_storage_mib: " << status.available_storage_mib << ", total_storage_mib: " << status.total_storage_mib << ", recording_time_s: " << status.recording_time_s + << ", media_folder_name: " << status.media_folder_name << ", storage_status: " << status.storage_status << "]"; }