From 755a25134a0d7cf65a6d46e3b119209db084867e Mon Sep 17 00:00:00 2001 From: doronhi Date: Thu, 16 May 2019 09:28:45 +0300 Subject: [PATCH] removed usage of sensor_from_frame() from rs-data-collect. add unit-test "get_sensor_from_frame" --- tools/data-collect/rs-data-collect.cpp | 3 +-- tools/data-collect/rs-data-collect.h | 8 ++---- unit-tests/unit-tests-live.cpp | 37 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/tools/data-collect/rs-data-collect.cpp b/tools/data-collect/rs-data-collect.cpp index 342ceff55a..b7da022f1c 100644 --- a/tools/data-collect/rs-data-collect.cpp +++ b/tools/data-collect/rs-data-collect.cpp @@ -124,7 +124,7 @@ void data_collector::save_data_to_file(const string& out_filename) for (const auto& elem : data_collection) { - csv << "\n\nStream Type,Index,F#,HW Timestamp (ms),Host Timestamp(ms), SerialNumber" + csv << "\n\nStream Type,Index,F#,HW Timestamp (ms),Host Timestamp(ms)" << (val_in_range(elem.first.first, { RS2_STREAM_GYRO,RS2_STREAM_ACCEL }) ? ",3DOF_x,3DOF_y,3DOF_z" : "") << (val_in_range(elem.first.first, { RS2_STREAM_POSE }) ? ",t_x,t_y,t_z,r_x,r_y,r_z,r_w" : "") << std::endl; @@ -161,7 +161,6 @@ void data_collector::collect_frame_attributes(rs2::frame f, std::chrono::time_po rec._params = { pose.translation.x, pose.translation.y, pose.translation.z, pose.rotation.x,pose.rotation.y,pose.rotation.z,pose.rotation.w }; } - rec._dev_serial_no = sensor_from_frame(f)->get_info(RS2_CAMERA_INFO_SERIAL_NUMBER); data_collection[stream_uid].emplace_back(rec); } diff --git a/tools/data-collect/rs-data-collect.h b/tools/data-collect/rs-data-collect.h index c02c42ca83..759d2d50e6 100644 --- a/tools/data-collect/rs-data-collect.h +++ b/tools/data-collect/rs-data-collect.h @@ -194,16 +194,14 @@ namespace rs_data_collect frame_record(unsigned long long frame_number, double frame_ts, double host_ts, rs2_timestamp_domain domain, rs2_stream stream_type,int stream_index, double _p1=0., double _p2=0., double _p3=0., - double _p4=0., double _p5=0., double _p6=0., double _p7=0., - std::string dev_serial=std::string("")): + double _p4=0., double _p5=0., double _p6=0., double _p7=0.): _frame_number(frame_number), _ts(frame_ts), _arrival_time(host_ts), _domain(domain), _stream_type(stream_type), _stream_idx(stream_index), - _params({_p1,_p2,_p3,_p4,_p5,_p6,_p7}), - _dev_serial_no(dev_serial) + _params({_p1,_p2,_p3,_p4,_p5,_p6,_p7}) {}; std::string to_string() const @@ -224,7 +222,6 @@ namespace rs_data_collect for (auto i=0; i _params; // |The parameters are optional and sensor specific - std::string _dev_serial_no; }; private: diff --git a/unit-tests/unit-tests-live.cpp b/unit-tests/unit-tests-live.cpp index cba3e41259..51ab666f5b 100644 --- a/unit-tests/unit-tests-live.cpp +++ b/unit-tests/unit-tests-live.cpp @@ -5549,3 +5549,40 @@ TEST_CASE("Wheel_Odometry_API", "[live]") } } } + + +TEST_CASE("get_sensor_from_frame", "[live][using_pipeline]") +{ + // Require at least one device to be plugged in + rs2::context ctx; + if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.13.0")) + { + std::vector list; + REQUIRE_NOTHROW(list = ctx.query_all_sensors()); + REQUIRE(list.size() > 0); + + pipeline pipe(ctx); + device dev; + // Configure all supported streams to run at 30 frames per second + + rs2::config cfg; + rs2::pipeline_profile profile; + REQUIRE_NOTHROW(profile = cfg.resolve(pipe)); + REQUIRE(profile); + REQUIRE_NOTHROW(dev = profile.get_device()); + REQUIRE(dev); + disable_sensitive_options_for(dev); + + // Test sequence + REQUIRE_NOTHROW(pipe.start(cfg)); + std::string dev_serial_no = dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER); + for (auto i = 0; i < 5; i++) + { + rs2::frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camera + auto frame = data.get_color_frame(); + std::string frame_serail_no = sensor_from_frame(frame)->get_info(RS2_CAMERA_INFO_SERIAL_NUMBER); + REQUIRE(dev_serial_no == frame_serail_no); + } + REQUIRE_NOTHROW(pipe.stop()); + } +}