ifm3d
All Classes Functions Variables Typedefs Enumerations Enumerator Modules
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/module_device.h>
16 #include <ifm3d/device/ifm_network_device.h>
17 #include <ifm3d/device/semver.h>
18 
19 namespace ifm3d
20 {
21  extern IFM3D_EXPORT const std::string DEFAULT_IP;
22  extern IFM3D_EXPORT const std::uint16_t DEFAULT_XMLRPC_PORT;
23  extern IFM3D_EXPORT const int DEFAULT_PCIC_PORT;
24  extern IFM3D_EXPORT const std::uint16_t PCIC_PORT;
25  extern IFM3D_EXPORT const std::string DEFAULT_PASSWORD;
26  extern IFM3D_EXPORT const int MAX_HEARTBEAT;
27  extern IFM3D_EXPORT const std::size_t SESSION_ID_SZ;
28  extern IFM3D_EXPORT const std::string DEFAULT_SESSION_ID;
29  extern IFM3D_EXPORT const std::string DEFAULT_APPLICATION_TYPE;
30  extern IFM3D_EXPORT const long DEFAULT_CURL_CONNECT_TIMEOUT;
31  extern IFM3D_EXPORT const long DEFAULT_CURL_TRANSACTION_TIMEOUT;
32 
33  extern IFM3D_EXPORT const int DEV_O3D_MIN;
34  extern IFM3D_EXPORT const int DEV_O3D_MAX;
35  extern IFM3D_EXPORT const int DEV_O3R_MIN;
36  extern IFM3D_EXPORT const int DEV_O3R_MAX;
37  extern IFM3D_EXPORT const int DEV_O3X_MIN;
38  extern IFM3D_EXPORT const int DEV_O3X_MAX;
39  extern IFM3D_EXPORT const std::string ASSUME_DEVICE;
40 
41  extern IFM3D_EXPORT const unsigned int O3D_TIME_SUPPORT_MAJOR;
42  extern IFM3D_EXPORT const unsigned int O3D_TIME_SUPPORT_MINOR;
43  extern IFM3D_EXPORT const unsigned int O3D_TIME_SUPPORT_PATCH;
44 
45  extern IFM3D_EXPORT const unsigned int O3D_TMP_PARAMS_SUPPORT_MAJOR;
46  extern IFM3D_EXPORT const unsigned int O3D_TMP_PARAMS_SUPPORT_MINOR;
47  extern IFM3D_EXPORT const unsigned int O3D_TMP_PARAMS_SUPPORT_PATCH;
48 
49  extern IFM3D_EXPORT const unsigned int O3D_INTRINSIC_PARAM_SUPPORT_MAJOR;
50  extern IFM3D_EXPORT const unsigned int O3D_INTRINSIC_PARAM_SUPPORT_MINOR;
51  extern IFM3D_EXPORT const unsigned int O3D_INTRINSIC_PARAM_SUPPORT_PATCH;
52 
53  extern IFM3D_EXPORT const unsigned int
54  O3D_INVERSE_INTRINSIC_PARAM_SUPPORT_MAJOR;
55  extern IFM3D_EXPORT const unsigned int
56  O3D_INVERSE_INTRINSIC_PARAM_SUPPORT_MINOR;
57  extern IFM3D_EXPORT const unsigned int
58  O3D_INVERSE_INTRINSIC_PARAM_SUPPORT_PATCH;
59 
60  extern IFM3D_EXPORT const unsigned int
61  O3X_DISTANCE_NOISE_IMAGE_SUPPORT_MAJOR;
62  extern IFM3D_EXPORT const unsigned int
63  O3X_DISTANCE_NOISE_IMAGE_SUPPORT_MINOR;
64  extern IFM3D_EXPORT const unsigned int
65  O3X_DISTANCE_NOISE_IMAGE_SUPPORT_PATCH;
66 
67  enum class pixel_format : std::uint32_t
68  {
69  FORMAT_8U = 0,
70  FORMAT_8S = 1,
71  FORMAT_16U = 2,
72  FORMAT_16S = 3,
73  FORMAT_32U = 4,
74  FORMAT_32S = 5,
75  FORMAT_32F = 6,
76  FORMAT_64U = 7,
77  FORMAT_64F = 8,
78  FORMAT_16U2 = 9,
79  FORMAT_32F3 = 10
80  };
81 
82  enum class image_chunk : std::uint32_t
83  {
84  RADIAL_DISTANCE_IMAGE = 100,
85  NORM_AMPLITUDE_IMAGE = 101, // normalized amplitude
86  AMPLITUDE_IMAGE = 103,
87  GRAYSCALE_IMAGE = 104, // ambient light
88  RADIAL_DISTANCE_NOISE = 105,
89  REFLECTIVITY = 107,
90  CARTESIAN_X_COMPONENT = 200,
91  CARTESIAN_Y_COMPONENT = 201,
92  CARTESIAN_Z_COMPONENT = 202,
93  CARTESIAN_ALL = 203,
94  UNIT_VECTOR_ALL = 223,
95  MONOCHROM_2D_12BIT = 250,
96  MONOCHROM_2D = 251,
97  JPEG_IMAGE = 260,
98  CONFIDENCE_IMAGE = 300,
99  DIAGNOSTIC = 302,
100  JSON_DIAGNOSTIC = 305,
101  EXTRINSIC_CALIB = 400,
102  INTRINSIC_CALIB = 401,
103  INVERSE_INTRINSIC_CALIBRATION = 402,
104  TOF_INFO = 420,
105  O3R_DISTANCE_IMAGE_INFO [[deprecated]] =
106  static_cast<uint32_t>(ifm3d::image_chunk::TOF_INFO),
107  RGB_INFO = 421,
108  O3R_RGB_IMAGE_INFO [[deprecated]] =
109  static_cast<uint32_t>(ifm3d::image_chunk::RGB_INFO),
110  JSON_MODEL = 500,
111  ALGO_DEBUG = 900,
112  O3R_ODS_OCCUPANCY_GRID = 1000,
113  O3R_ODS_INFO = 1001,
114  O3R_RESULT_JSON = 1002,
115  O3R_RESULT_ARRAY2D = 1003,
116  O3R_RESULT_IMU = 1004,
117  O3R_ODS_POLAR_OCC_GRID = 1006,
118  O3R_ODS_EXTRINSIC_CALIBRATION_CORRECTION = 1007
119  };
120 
121  class XMLRPCWrapper;
122 
132  class IFM3D_EXPORT Device
133  {
134  public:
135  using Ptr = std::shared_ptr<Device>;
136 
143  enum class boot_mode : int
144  {
145  PRODUCTIVE = 0,
146  RECOVERY = 1
147  };
148 
153  enum class operating_mode : int
154  {
155  RUN = 0,
156  EDIT = 1
157  };
158 
162  enum class trigger_mode : int
163  {
164  FREE_RUN = 1,
165  SW = 2
166  };
167 
171  enum class import_flags : int
172  {
173  GLOBAL = 0x1,
174  NET = 0x2,
175  APPS = 0x10
176  };
177 
181  enum class spatial_filter : int
182  {
183  OFF = 0x0,
184  MEDIAN = 0x1,
185  MEAN = 0x2,
186  BILATERAL = 0x3
187  };
188 
192  enum class temporal_filter : int
193  {
194  OFF = 0x0,
195  MEAN = 0x1,
196  ADAPTIVE_EXP = 0x2
197  };
198 
202  enum class mfilt_mask_size : int
203  {
204  _3x3 = 0,
205  _5x5 = 1
206  };
207 
208  enum class device_family : int
209  {
210  UNKNOWN = 0,
211  O3D = 1,
212  O3X = 2,
213  O3R = 3,
214  };
215 
216  enum class swu_version : int
217  {
218  SWU_NOT_SUPPORTED = 0,
219  SWU_V1 = 1,
220  SWU_V2 = 2
221  };
222 
229  static std::vector<ifm3d::IFMNetworkDevice> DeviceDiscovery();
230 
236  static void SetTempIPAddress(std::string mac, std::string temp_ip);
237 
258  static Ptr MakeShared(
259  const std::string& ip = ifm3d::DEFAULT_IP,
260  const std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT,
261  const std::string& password = ifm3d::DEFAULT_PASSWORD,
262  bool throwIfUnavailable = true);
263 
275  Device(const std::string& ip = ifm3d::DEFAULT_IP,
276  const std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT);
277 
281  virtual ~Device();
282 
283  // Based on our mileage with `libo3d3xx`, disabling copy and move semantics
284  // on the device class has not been an issue, so, we do that here too.
285  Device(Device&&) = delete;
286  Device& operator=(Device&&) = delete;
287  Device(Device&) = delete;
288  Device& operator=(Device&) = delete;
289 
290  // Accessors/Mutators
291 
293  virtual std::string IP();
294 
296  virtual std::uint16_t XMLRPCPort();
297 
304  virtual void Reboot(
305  const boot_mode& mode = ifm3d::Device::boot_mode::PRODUCTIVE);
306 
314  virtual void ForceTrigger();
315 
337  virtual std::string DeviceType(bool use_cached = true);
338 
344  virtual device_family WhoAmI();
345 
354  virtual bool AmI(device_family family);
355 
360  virtual std::string DeviceParameter(const std::string& key);
361 
370  virtual std::vector<std::string> TraceLogs(int count);
371 
389  virtual json ToJSON();
390 
398  virtual std::string ToJSONStr();
399 
418  virtual void FromJSON(const json& j);
419 
426  virtual void FromJSONStr(const std::string& jstr);
427 
437  bool CheckMinimumFirmwareVersion(unsigned int major,
438  unsigned int minor,
439  unsigned int patch);
440 
444  ifm3d::SemVer FirmwareVersion();
445 
451  virtual ifm3d::Device::swu_version SwUpdateVersion();
452 
453  json GetSWVersion();
454 
455  protected:
456  class Impl;
457  std::unique_ptr<Impl> pImpl;
458 
462  std::string device_type_;
463 
470  int DeviceID();
471  bool checkDeviceID(int deviceID, int minID, int maxID);
472 
473  std::shared_ptr<XMLRPCWrapper> XWrapper();
474 
475  }; // end: class Device
476 
477 } // end: namespace ifm3d
478 
479 #endif // IFM3D_DEVICE_DEVICE_H
ifm3d::Device::spatial_filter
spatial_filter
Convenience constants for spatial filter types.
Definition: device.h:181
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:462
ifm3d::Device::temporal_filter
temporal_filter
Convenience constants for temporal filter types.
Definition: device.h:192
ifm3d::O3D
Definition: o3d.h:19
ifm3d::Device::mfilt_mask_size
mfilt_mask_size
Convenient constants for median filter mask sizes.
Definition: device.h:202
ifm3d::Device::boot_mode
boot_mode
Device boot up modes:
Definition: device.h:143
ifm3d::Device
Definition: device.h:132
ifm3d::Device::operating_mode
operating_mode
Device operating modes: run (streaming pixel data), edit (configuring the device/applications).
Definition: device.h:153
ifm3d::SemVer
Definition: semver.h:19
ifm3d::Device::trigger_mode
trigger_mode
Image acquisition trigger modes.
Definition: device.h:162
ifm3d::Device::import_flags
import_flags
Import flags used when importing a Vision Assistant configuration.
Definition: device.h:171
ifm3d::O3R
Definition: o3r.h:30