l500-serializable.cpp
Go to the documentation of this file.
1 
4 #include "l500-serializable.h"
5 #include "../../../third-party/json.hpp"
6 #include <set>
7 #include "l500-options.h"
8 
9 namespace librealsense
10 {
11  using json = nlohmann::json;
12 
14  :_hw_monitor_ptr(hw_monitor),
15  _depth_sensor(depth_sensor)
16  {
17  }
18 
19  std::vector<uint8_t> l500_serializable::serialize_json() const
20  {
22 
23  json j;
24  auto options = _depth_sensor.get_supported_options();
25 
26  for( auto o : options )
27  {
28  auto && opt = _depth_sensor.get_option( o );
29  auto val = opt.query();
30  j[get_string( o )] = val;
31  }
32 
33  auto str = j.dump( 4 );
34  return std::vector< uint8_t >( str.begin(), str.end() );
35  } );
36 
37  }
38 
39  void l500_serializable::load_json( const std::string & json_content )
40  {
42  json j = json::parse( json_content );
43 
44  // Set of options that should not be set in the loop
45  std::set< rs2_option > options_to_ignore{ RS2_OPTION_SENSOR_MODE,
48 
49  // We have to set the sensor mode (resolution) first
50  auto & sensor_mode = _depth_sensor.get_option( RS2_OPTION_SENSOR_MODE );
51  auto found_sensor_mode = j.find( get_string( RS2_OPTION_SENSOR_MODE ) );
52  if( found_sensor_mode != j.end() )
53  {
54  float sensor_mode_val = found_sensor_mode.value();
55  sensor_mode.set( sensor_mode_val );
56  }
57 
58  // If a non custom preset is used, we should ignore all the settings that are
59  // automatically set by the preset
60  auto found_iterator = j.find( get_string( RS2_OPTION_VISUAL_PRESET ) );
61  if( found_iterator != j.end() )
62  {
63  auto found_preset = rs2_l500_visual_preset( int( found_iterator.value() ) );
64  if( found_preset != RS2_L500_VISUAL_PRESET_CUSTOM
65  && found_preset != RS2_L500_VISUAL_PRESET_DEFAULT )
66  {
76  }
77  }
78 
80 
81  auto default_preset = false;
82  for( auto o : opts )
83  {
84  auto & opt = _depth_sensor.get_option( o );
85  if( opt.is_read_only() )
86  continue;
87  if( options_to_ignore.find( o ) != options_to_ignore.end() )
88  continue;
89 
90  auto key = get_string( o );
91  auto it = j.find( key );
92  if( it != j.end() )
93  {
94  float val = it.value();
96  && (int)val == (int)RS2_L500_VISUAL_PRESET_DEFAULT )
97  {
98  default_preset = true;
99  continue;
100  }
101 
102  opt.set( val );
103  }
104  }
105  if( default_preset )
106  {
107  auto options = dynamic_cast< l500_options * >( this );
108  if( options )
109  {
110  auto preset = options->calc_preset_from_controls();
111  options->set_preset_value( preset );
112  }
113  }
114  } );
115  }
116  } // namespace librealsense
const char * get_string(rs2_rs400_visual_preset value)
static basic_json parse(T(&array)[N], const parser_callback_t cb=nullptr)
deserialize from an array
Definition: json.hpp:5979
a class to store JSON values
Definition: json.hpp:221
GLsizei const GLchar *const * string
void load_json(const std::string &json_content) override
option & get_option(rs2_option id) override
Definition: options.h:58
virtual float query() const =0
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.hpp:4358
std::vector< rs2_option > get_supported_options() const override
Definition: option.cpp:197
GLuint GLfloat * val
GLuint64 key
Definition: glext.h:8966
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:4201
GLint j
std::vector< uint8_t > serialize_json() const override
l500_serializable(std::shared_ptr< hw_monitor > hw_monitor, synthetic_sensor &depth_sensor)
static auto it
string_t dump(const int indent=-1) const
serialization
Definition: json.hpp:2187
reference value() const
return the value of an iterator
Definition: json.hpp:8820
auto group_multiple_fw_calls(synthetic_sensor &s, T action) -> decltype(action())
Definition: l500-private.h:615
basic_json<> json
default JSON class
Definition: json.hpp:12124
rs2_l500_visual_preset
For L500 devices: provides optimized settings (presets) for specific types of usage.
Definition: rs_option.h:151


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:21