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/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  };
119 
120  class XMLRPCWrapper;
121 
131  class IFM3D_EXPORT Device
132  {
133  public:
134  using Ptr = std::shared_ptr<Device>;
135 
142  enum class boot_mode : int
143  {
144  PRODUCTIVE = 0,
145  RECOVERY = 1
146  };
147 
152  enum class operating_mode : int
153  {
154  RUN = 0,
155  EDIT = 1
156  };
157 
161  enum class trigger_mode : int
162  {
163  FREE_RUN = 1,
164  SW = 2
165  };
166 
170  enum class import_flags : int
171  {
172  GLOBAL = 0x1,
173  NET = 0x2,
174  APPS = 0x10
175  };
176 
180  enum class spatial_filter : int
181  {
182  OFF = 0x0,
183  MEDIAN = 0x1,
184  MEAN = 0x2,
185  BILATERAL = 0x3
186  };
187 
191  enum class temporal_filter : int
192  {
193  OFF = 0x0,
194  MEAN = 0x1,
195  ADAPTIVE_EXP = 0x2
196  };
197 
201  enum class mfilt_mask_size : int
202  {
203  _3x3 = 0,
204  _5x5 = 1
205  };
206 
207  enum class device_family : int
208  {
209  UNKNOWN = 0,
210  O3D = 1,
211  O3X = 2,
212  O3R = 3,
213  };
214 
215  enum class swu_version : int
216  {
217  SWU_NOT_SUPPORTED = 0,
218  SWU_V1 = 1,
219  SWU_V2 = 2
220  };
221 
228  static std::vector<ifm3d::IFMNetworkDevice> DeviceDiscovery();
229 
235  static void SetTempIPAddress(std::string mac, std::string temp_ip);
236 
257  static Ptr MakeShared(
258  const std::string& ip = ifm3d::DEFAULT_IP,
259  const std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT,
260  const std::string& password = ifm3d::DEFAULT_PASSWORD,
261  bool throwIfUnavailable = true);
262 
274  Device(const std::string& ip = ifm3d::DEFAULT_IP,
275  const std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT);
276 
280  virtual ~Device();
281 
282  // Based on our mileage with `libo3d3xx`, disabling copy and move semantics
283  // on the device class has not been an issue, so, we do that here too.
284  Device(Device&&) = delete;
285  Device& operator=(Device&&) = delete;
286  Device(Device&) = delete;
287  Device& operator=(Device&) = delete;
288 
289  // Accessors/Mutators
290 
292  virtual std::string IP();
293 
295  virtual std::uint16_t XMLRPCPort();
296 
303  virtual void Reboot(
304  const boot_mode& mode = ifm3d::Device::boot_mode::PRODUCTIVE);
305 
313  virtual void ForceTrigger();
314 
336  virtual std::string DeviceType(bool use_cached = true);
337 
343  virtual device_family WhoAmI();
344 
353  virtual bool AmI(device_family family);
354 
359  virtual std::string DeviceParameter(const std::string& key);
360 
369  virtual std::vector<std::string> TraceLogs(int count);
370 
388  virtual json ToJSON();
389 
397  virtual std::string ToJSONStr();
398 
417  virtual void FromJSON(const json& j);
418 
425  virtual void FromJSONStr(const std::string& jstr);
426 
436  bool CheckMinimumFirmwareVersion(unsigned int major,
437  unsigned int minor,
438  unsigned int patch);
439 
443  ifm3d::SemVer FirmwareVersion();
444 
450  virtual ifm3d::Device::swu_version SwUpdateVersion();
451 
452  json GetSWVersion();
453 
454  protected:
455  class Impl;
456  std::unique_ptr<Impl> pImpl;
457 
461  std::string device_type_;
462 
469  int DeviceID();
470  bool checkDeviceID(int deviceID, int minID, int maxID);
471 
472  std::shared_ptr<XMLRPCWrapper> XWrapper();
473 
474  }; // end: class Device
475 
476 } // end: namespace ifm3d
477 
478 #endif // IFM3D_DEVICE_DEVICE_H
ifm3d::Device::spatial_filter
spatial_filter
Convenience constants for spatial filter types.
Definition: device.h:180
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:461
ifm3d::Device::temporal_filter
temporal_filter
Convenience constants for temporal filter types.
Definition: device.h:191
ifm3d::O3D
Definition: o3d.h:19
ifm3d::Device::mfilt_mask_size
mfilt_mask_size
Convenient constants for median filter mask sizes.
Definition: device.h:201
ifm3d::Device::boot_mode
boot_mode
Device boot up modes:
Definition: device.h:142
ifm3d::Device
Definition: device.h:131
ifm3d::Device::operating_mode
operating_mode
Device operating modes: run (streaming pixel data), edit (configuring the device/applications).
Definition: device.h:152
ifm3d::SemVer
Definition: semver.h:19
ifm3d::Device::trigger_mode
trigger_mode
Image acquisition trigger modes.
Definition: device.h:161
ifm3d::Device::import_flags
import_flags
Import flags used when importing a Vision Assistant configuration.
Definition: device.h:170
ifm3d::O3R
Definition: o3r.h:30