ifm3d
device.h
1 // -*- c++ -*-
2 /*
3  * Copyright 2018-present ifm electronic, gmbh
4  * Copyright 2017 Love Park Robotics, LLC
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #ifndef IFM3D_DEVICE_DEVICE_H
9 #define IFM3D_DEVICE_DEVICE_H
10 
11 #include <cstdint>
12 #include <string>
13 #include <vector>
14 #include <ifm3d/common/json.hpp>
15 #include <ifm3d/device/device_export.h>
16 #include <ifm3d/device/ifm_network_device.h>
17 #include <ifm3d/device/semver.h>
18 
19 namespace ifm3d
20 {
21  extern IFM3D_DEVICE_EXPORT const std::string DEFAULT_IP;
22  extern IFM3D_DEVICE_EXPORT const std::uint16_t DEFAULT_XMLRPC_PORT;
23  extern IFM3D_DEVICE_EXPORT const int DEFAULT_PCIC_PORT;
24  extern IFM3D_DEVICE_EXPORT const std::uint16_t PCIC_PORT;
25  extern IFM3D_DEVICE_EXPORT const std::string DEFAULT_PASSWORD;
26  extern IFM3D_DEVICE_EXPORT const int MAX_HEARTBEAT;
27  extern IFM3D_DEVICE_EXPORT const std::size_t SESSION_ID_SZ;
28  extern IFM3D_DEVICE_EXPORT const std::string DEFAULT_SESSION_ID;
29  extern IFM3D_DEVICE_EXPORT const std::string DEFAULT_APPLICATION_TYPE;
30  extern IFM3D_DEVICE_EXPORT const long DEFAULT_CURL_CONNECT_TIMEOUT;
31  extern IFM3D_DEVICE_EXPORT const long DEFAULT_CURL_TRANSACTION_TIMEOUT;
32 
33  extern IFM3D_DEVICE_EXPORT const int DEV_O3D_MIN;
34  extern IFM3D_DEVICE_EXPORT const int DEV_O3D_MAX;
35  extern IFM3D_DEVICE_EXPORT const int DEV_O3R_MIN;
36  extern IFM3D_DEVICE_EXPORT const int DEV_O3R_MAX;
37  extern IFM3D_DEVICE_EXPORT const int DEV_O3X_MIN;
38  extern IFM3D_DEVICE_EXPORT const int DEV_O3X_MAX;
39  extern IFM3D_DEVICE_EXPORT const std::string ASSUME_DEVICE;
40 
41  extern IFM3D_DEVICE_EXPORT const unsigned int O3D_TIME_SUPPORT_MAJOR;
42  extern IFM3D_DEVICE_EXPORT const unsigned int O3D_TIME_SUPPORT_MINOR;
43  extern IFM3D_DEVICE_EXPORT const unsigned int O3D_TIME_SUPPORT_PATCH;
44 
45  extern IFM3D_DEVICE_EXPORT const unsigned int O3D_TMP_PARAMS_SUPPORT_MAJOR;
46  extern IFM3D_DEVICE_EXPORT const unsigned int O3D_TMP_PARAMS_SUPPORT_MINOR;
47  extern IFM3D_DEVICE_EXPORT const unsigned int O3D_TMP_PARAMS_SUPPORT_PATCH;
48 
49  extern IFM3D_DEVICE_EXPORT const unsigned int
50  O3D_INTRINSIC_PARAM_SUPPORT_MAJOR;
51  extern IFM3D_DEVICE_EXPORT const unsigned int
52  O3D_INTRINSIC_PARAM_SUPPORT_MINOR;
53  extern IFM3D_DEVICE_EXPORT const unsigned int
54  O3D_INTRINSIC_PARAM_SUPPORT_PATCH;
55 
56  extern IFM3D_DEVICE_EXPORT const unsigned int
57  O3D_INVERSE_INTRINSIC_PARAM_SUPPORT_MAJOR;
58  extern IFM3D_DEVICE_EXPORT const unsigned int
59  O3D_INVERSE_INTRINSIC_PARAM_SUPPORT_MINOR;
60  extern IFM3D_DEVICE_EXPORT const unsigned int
61  O3D_INVERSE_INTRINSIC_PARAM_SUPPORT_PATCH;
62 
63  extern IFM3D_DEVICE_EXPORT const unsigned int
64  O3X_DISTANCE_NOISE_IMAGE_SUPPORT_MAJOR;
65  extern IFM3D_DEVICE_EXPORT const unsigned int
66  O3X_DISTANCE_NOISE_IMAGE_SUPPORT_MINOR;
67  extern IFM3D_DEVICE_EXPORT const unsigned int
68  O3X_DISTANCE_NOISE_IMAGE_SUPPORT_PATCH;
69 
70  enum class pixel_format : std::uint32_t
71  {
72  FORMAT_8U = 0,
73  FORMAT_8S = 1,
74  FORMAT_16U = 2,
75  FORMAT_16S = 3,
76  FORMAT_32U = 4,
77  FORMAT_32S = 5,
78  FORMAT_32F = 6,
79  FORMAT_64U = 7,
80  FORMAT_64F = 8,
81  FORMAT_16U2 = 9,
82  FORMAT_32F3 = 10
83  };
84 
85  enum class image_chunk : std::uint32_t
86  {
87  RADIAL_DISTANCE_IMAGE = 100,
88  NORM_AMPLITUDE_IMAGE = 101, // normalized amplitude
89  AMPLITUDE_IMAGE = 103,
90  GRAYSCALE_IMAGE = 104, // ambient light
91  RADIAL_DISTANCE_NOISE = 105,
92  REFLECTIVITY = 107,
93  CARTESIAN_X_COMPONENT = 200,
94  CARTESIAN_Y_COMPONENT = 201,
95  CARTESIAN_Z_COMPONENT = 202,
96  CARTESIAN_ALL = 203,
97  UNIT_VECTOR_ALL = 223,
98  MONOCHROM_2D_12BIT = 250,
99  MONOCHROM_2D = 251,
100  JPEG_IMAGE = 260,
101  CONFIDENCE_IMAGE = 300,
102  DIAGNOSTIC = 302,
103  JSON_DIAGNOSTIC = 305,
104  EXTRINSIC_CALIB = 400,
105  INTRINSIC_CALIB = 401,
106  INVERSE_INTRINSIC_CALIBRATION = 402,
107  TOF_INFO = 420,
108  O3R_DISTANCE_IMAGE_INFO [[deprecated]] =
109  static_cast<uint32_t>(ifm3d::image_chunk::TOF_INFO),
110  RGB_INFO = 421,
111  O3R_RGB_IMAGE_INFO [[deprecated]] =
112  static_cast<uint32_t>(ifm3d::image_chunk::RGB_INFO),
113  JSON_MODEL = 500,
114  ALGO_DEBUG = 900,
115  O3R_ODS_OCCUPANCY_GRID = 1000,
116  O3R_ODS_INFO = 1001,
117  O3R_RESULT_JSON = 1002,
118  O3R_RESULT_ARRAY2D = 1003,
119  O3R_RESULT_IMU = 1004,
120  };
121 
122  class XMLRPCWrapper;
123 
133  class IFM3D_DEVICE_EXPORT Device
134  {
135  public:
136  using Ptr = std::shared_ptr<Device>;
137 
144  enum class boot_mode : int
145  {
146  PRODUCTIVE = 0,
147  RECOVERY = 1
148  };
149 
154  enum class operating_mode : int
155  {
156  RUN = 0,
157  EDIT = 1
158  };
159 
163  enum class trigger_mode : int
164  {
165  FREE_RUN = 1,
166  SW = 2
167  };
168 
172  enum class import_flags : int
173  {
174  GLOBAL = 0x1,
175  NET = 0x2,
176  APPS = 0x10
177  };
178 
182  enum class spatial_filter : int
183  {
184  OFF = 0x0,
185  MEDIAN = 0x1,
186  MEAN = 0x2,
187  BILATERAL = 0x3
188  };
189 
193  enum class temporal_filter : int
194  {
195  OFF = 0x0,
196  MEAN = 0x1,
197  ADAPTIVE_EXP = 0x2
198  };
199 
203  enum class mfilt_mask_size : int
204  {
205  _3x3 = 0,
206  _5x5 = 1
207  };
208 
209  enum class device_family : int
210  {
211  UNKNOWN = 0,
212  O3D = 1,
213  O3X = 2,
214  O3R = 3,
215  };
216 
217  enum class swu_version : int
218  {
219  SWU_NOT_SUPPORTED = 0,
220  SWU_V1 = 1,
221  SWU_V2 = 2
222  };
223 
230  static std::vector<ifm3d::IFMNetworkDevice> DeviceDiscovery();
231 
252  static Ptr MakeShared(
253  const std::string& ip = ifm3d::DEFAULT_IP,
254  const std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT,
255  const std::string& password = ifm3d::DEFAULT_PASSWORD,
256  bool throwIfUnavailable = true);
257 
269  Device(const std::string& ip = ifm3d::DEFAULT_IP,
270  const std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT);
271 
275  virtual ~Device();
276 
277  // Based on our mileage with `libo3d3xx`, disabling copy and move semantics
278  // on the device class has not been an issue, so, we do that here too.
279  Device(Device&&) = delete;
280  Device& operator=(Device&&) = delete;
281  Device(Device&) = delete;
282  Device& operator=(Device&) = delete;
283 
284  // Accessors/Mutators
285 
287  virtual std::string IP();
288 
290  virtual std::uint16_t XMLRPCPort();
291 
298  virtual void Reboot(
299  const boot_mode& mode = ifm3d::Device::boot_mode::PRODUCTIVE);
300 
308  virtual void ForceTrigger();
309 
331  virtual std::string DeviceType(bool use_cached = true);
332 
338  virtual device_family WhoAmI();
339 
348  virtual bool AmI(device_family family);
349 
354  virtual std::string DeviceParameter(const std::string& key);
355 
364  virtual std::vector<std::string> TraceLogs(int count);
365 
383  virtual json ToJSON();
384 
392  virtual std::string ToJSONStr();
393 
412  virtual void FromJSON(const json& j);
413 
420  virtual void FromJSONStr(const std::string& jstr);
421 
431  bool CheckMinimumFirmwareVersion(unsigned int major,
432  unsigned int minor,
433  unsigned int patch);
434 
438  ifm3d::SemVer FirmwareVersion();
439 
445  virtual ifm3d::Device::swu_version SwUpdateVersion();
446 
447  protected:
448  class Impl;
449  std::unique_ptr<Impl> pImpl;
450 
454  std::string device_type_;
455 
462  int DeviceID();
463  bool checkDeviceID(int deviceID, int minID, int maxID);
464 
465  std::shared_ptr<XMLRPCWrapper> XWrapper();
466 
467  }; // end: class Device
468 
469 } // end: namespace ifm3d
470 
471 #endif // IFM3D_DEVICE_DEVICE_H
ifm3d::Device::spatial_filter
spatial_filter
Convenience constants for spatial filter types.
Definition: device.h:182
ifm3d::O3X
Definition: o3x.h:19
ifm3d::Device::device_type_
std::string device_type_
The cached device type of the connected device.
Definition: device.h:454
ifm3d::Device::temporal_filter
temporal_filter
Convenience constants for temporal filter types.
Definition: device.h:193
ifm3d::O3D
Definition: o3d.h:19
ifm3d::Device::mfilt_mask_size
mfilt_mask_size
Convenient constants for median filter mask sizes.
Definition: device.h:203
ifm3d::Device::boot_mode
boot_mode
Device boot up modes:
Definition: device.h:144
ifm3d::Device
Definition: device.h:133
ifm3d::Device::operating_mode
operating_mode
Device operating modes: run (streaming pixel data), edit (configuring the device/applications).
Definition: device.h:154
ifm3d::SemVer
Definition: semver.h:19
ifm3d::Device::trigger_mode
trigger_mode
Image acquisition trigger modes.
Definition: device.h:163
ifm3d::Device::import_flags
import_flags
Import flags used when importing a Vision Assistant configuration.
Definition: device.h:172
ifm3d::O3R
Definition: o3r.h:30