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