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 <ifm3d/common/json.hpp>
13 #include <ifm3d/device/ifm_network_device.h>
14 #include <ifm3d/device/module_device.h>
15 #include <ifm3d/device/semver.h>
16 #include <string>
17 #include <vector>
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 PixelFormat : std::uint32_t // NOLINT(performance-enum-size)
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 ImageChunk : std::uint32_t // NOLINT(performance-enum-size)
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::ImageChunk::TOF_INFO),
107  RGB_INFO = 421,
108  O3R_RGB_IMAGE_INFO [[deprecated]] =
109  static_cast<uint32_t>(ifm3d::ImageChunk::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 XMLRPC;
122 
132  class IFM3D_EXPORT Device
133  {
134  public:
135  using Ptr = std::shared_ptr<Device>;
136 
143  enum class BootMode : int // NOLINT(performance-enum-size)
144  {
145  PRODUCTIVE = 0,
146  RECOVERY = 1
147  };
148 
153  enum class OperatingMode : int // NOLINT(performance-enum-size)
154  {
155  RUN = 0,
156  EDIT = 1
157  };
158 
162  enum class TriggerMode : int // NOLINT(performance-enum-size)
163  {
164  FREE_RUN = 1,
165  SW = 2
166  };
167 
171  enum class ImportFlags : int // NOLINT(performance-enum-size)
172  {
173  GLOBAL = 0x1,
174  NET = 0x2,
175  APPS = 0x10
176  };
177 
181  enum class SpatialFilter : int // NOLINT(performance-enum-size)
182  {
183  OFF = 0x0,
184  MEDIAN = 0x1,
185  MEAN = 0x2,
186  BILATERAL = 0x3
187  };
188 
192  enum class TemporalFilter : int // NOLINT(performance-enum-size)
193  {
194  OFF = 0x0,
195  MEAN = 0x1,
196  ADAPTIVE_EXP = 0x2
197  };
198 
202  enum class MedianfilterMaskSize : int // NOLINT(performance-enum-size)
203  {
204  _3x3 = 0, // NOLINT(readability-identifier-naming)
205  _5x5 = 1 // NOLINT(readability-identifier-naming)
206  };
207 
208  enum class DeviceFamily : int // NOLINT(performance-enum-size)
209  {
210  UNKNOWN = 0,
211  O3D = 1,
212  O3X = 2,
213  O3R = 3,
214  };
215 
216  enum class SWUVersion : int // NOLINT(performance-enum-size)
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(const std::string& mac,
237  const std::string& temp_ip);
238 
259  static Ptr MakeShared(
260  const std::string& ip = ifm3d::DEFAULT_IP,
261  std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT,
262  const std::string& password = ifm3d::DEFAULT_PASSWORD,
263  bool throw_if_unavailable = true);
264 
276  Device(const std::string& ip = ifm3d::DEFAULT_IP,
277  std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT);
278 
282  virtual ~Device();
283 
284  // Based on our mileage with `libo3d3xx`, disabling copy and move semantics
285  // on the device class has not been an issue, so, we do that here too.
286  Device(Device&&) = delete;
287  Device& operator=(Device&&) = delete;
288  Device(Device&) = delete;
289  Device& operator=(Device&) = delete;
290 
291  // Accessors/Mutators
292 
294  virtual std::string IP();
295 
297  virtual std::uint16_t XMLRPCPort();
298 
305  virtual void Reboot(
306  const BootMode& mode = ifm3d::Device::BootMode::PRODUCTIVE);
307 
315  virtual void ForceTrigger();
316 
338  virtual std::string DeviceType(bool use_cached = true);
339 
345  virtual DeviceFamily WhoAmI();
346 
355  virtual bool AmI(DeviceFamily family);
356 
361  virtual std::string DeviceParameter(const std::string& key);
362 
371  virtual std::vector<std::string> TraceLogs(int count);
372 
390  virtual json ToJSON();
391 
399  virtual std::string ToJSONStr();
400 
419  virtual void FromJSON(const json& j);
420 
427  virtual void FromJSONStr(const std::string& jstr);
428 
438  bool CheckMinimumFirmwareVersion(unsigned int major,
439  unsigned int minor,
440  unsigned int patch);
441 
445  ifm3d::SemVer FirmwareVersion();
446 
452  virtual ifm3d::Device::SWUVersion SwUpdateVersion();
453 
454  json GetSWVersion();
455 
456  protected:
457  class Impl;
458  std::unique_ptr<Impl> _impl;
459 
463  std::string _device_type;
464 
471  int device_id();
472  bool check_device_id(int device_id, int min_id, int max_id);
473 
474  std::shared_ptr<XMLRPC> x_wrapper();
475 
476  }; // end: class Device
477 
478 } // end: namespace ifm3d
479 
480 #endif // IFM3D_DEVICE_DEVICE_H
ifm3d::O3X
Definition: o3x.h:19
ifm3d::Device::OperatingMode
OperatingMode
Device operating modes: run (streaming pixel data), edit (configuring the device/applications).
Definition: device.h:153
ifm3d::Device::BootMode
BootMode
Device boot up modes:
Definition: device.h:143
ifm3d::O3D
Definition: o3d.h:19
ifm3d::Device::MedianfilterMaskSize
MedianfilterMaskSize
Convenient constants for median filter mask sizes.
Definition: device.h:202
ifm3d::Device
Definition: device.h:132
ifm3d::Device::TriggerMode
TriggerMode
Image acquisition trigger modes.
Definition: device.h:162
ifm3d::Device::TemporalFilter
TemporalFilter
Convenience constants for temporal filter types.
Definition: device.h:192
ifm3d::Device::ImportFlags
ImportFlags
Import flags used when importing a Vision Assistant configuration.
Definition: device.h:171
ifm3d::SemVer
Definition: semver.h:18
ifm3d::Device::_device_type
std::string _device_type
The cached device type of the connected device.
Definition: device.h:463
ifm3d::O3R
Definition: o3r.h:40
ifm3d::Device::SpatialFilter
SpatialFilter
Convenience constants for spatial filter types.
Definition: device.h:181