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_O3C_MIN;
38  extern IFM3D_EXPORT const int DEV_O3C_MAX;
39  extern IFM3D_EXPORT const int DEV_O3X_MIN;
40  extern IFM3D_EXPORT const int DEV_O3X_MAX;
41  extern IFM3D_EXPORT const std::string ASSUME_DEVICE;
42 
43  extern IFM3D_EXPORT const unsigned int O3D_TIME_SUPPORT_MAJOR;
44  extern IFM3D_EXPORT const unsigned int O3D_TIME_SUPPORT_MINOR;
45  extern IFM3D_EXPORT const unsigned int O3D_TIME_SUPPORT_PATCH;
46 
47  extern IFM3D_EXPORT const unsigned int O3D_TMP_PARAMS_SUPPORT_MAJOR;
48  extern IFM3D_EXPORT const unsigned int O3D_TMP_PARAMS_SUPPORT_MINOR;
49  extern IFM3D_EXPORT const unsigned int O3D_TMP_PARAMS_SUPPORT_PATCH;
50 
51  extern IFM3D_EXPORT const unsigned int O3D_INTRINSIC_PARAM_SUPPORT_MAJOR;
52  extern IFM3D_EXPORT const unsigned int O3D_INTRINSIC_PARAM_SUPPORT_MINOR;
53  extern IFM3D_EXPORT const unsigned int O3D_INTRINSIC_PARAM_SUPPORT_PATCH;
54 
55  extern IFM3D_EXPORT const unsigned int
56  O3D_INVERSE_INTRINSIC_PARAM_SUPPORT_MAJOR;
57  extern IFM3D_EXPORT const unsigned int
58  O3D_INVERSE_INTRINSIC_PARAM_SUPPORT_MINOR;
59  extern IFM3D_EXPORT const unsigned int
60  O3D_INVERSE_INTRINSIC_PARAM_SUPPORT_PATCH;
61 
62  extern IFM3D_EXPORT const unsigned int
63  O3X_DISTANCE_NOISE_IMAGE_SUPPORT_MAJOR;
64  extern IFM3D_EXPORT const unsigned int
65  O3X_DISTANCE_NOISE_IMAGE_SUPPORT_MINOR;
66  extern IFM3D_EXPORT const unsigned int
67  O3X_DISTANCE_NOISE_IMAGE_SUPPORT_PATCH;
68 
69  enum class PixelFormat : std::uint32_t // NOLINT(performance-enum-size)
70  {
71  FORMAT_8U = 0,
72  FORMAT_8S = 1,
73  FORMAT_16U = 2,
74  FORMAT_16S = 3,
75  FORMAT_32U = 4,
76  FORMAT_32S = 5,
77  FORMAT_32F = 6,
78  FORMAT_64U = 7,
79  FORMAT_64F = 8,
80  FORMAT_16U2 = 9,
81  FORMAT_32F3 = 10
82  };
83 
84  enum class ImageChunk : std::uint32_t // NOLINT(performance-enum-size)
85  {
86  RADIAL_DISTANCE_IMAGE = 100,
87  NORM_AMPLITUDE_IMAGE = 101, // normalized amplitude
88  AMPLITUDE_IMAGE = 103,
89  GRAYSCALE_IMAGE = 104, // ambient light
90  RADIAL_DISTANCE_NOISE = 105,
91  REFLECTIVITY = 107,
92  CARTESIAN_X_COMPONENT = 200,
93  CARTESIAN_Y_COMPONENT = 201,
94  CARTESIAN_Z_COMPONENT = 202,
95  CARTESIAN_ALL = 203,
96  UNIT_VECTOR_ALL = 223,
97  MONOCHROM_2D_12BIT = 250,
98  MONOCHROM_2D = 251,
99  JPEG_IMAGE = 260,
100  CONFIDENCE_IMAGE = 300,
101  DIAGNOSTIC = 302,
102  JSON_DIAGNOSTIC = 305,
103  EXTRINSIC_CALIB = 400,
104  INTRINSIC_CALIB = 401,
105  INVERSE_INTRINSIC_CALIBRATION = 402,
106  TOF_INFO = 420,
107  O3R_DISTANCE_IMAGE_INFO [[deprecated]] =
108  static_cast<uint32_t>(ifm3d::ImageChunk::TOF_INFO),
109  RGB_INFO = 421,
110  O3R_RGB_IMAGE_INFO [[deprecated]] =
111  static_cast<uint32_t>(ifm3d::ImageChunk::RGB_INFO),
112  JSON_MODEL = 500,
113  ALGO_DEBUG = 900,
114  O3R_ODS_OCCUPANCY_GRID = 1000,
115  O3R_ODS_INFO = 1001,
116  O3R_RESULT_JSON = 1002,
117  O3R_RESULT_ARRAY2D = 1003,
118  O3R_RESULT_IMU = 1004,
119  O3R_ODS_POLAR_OCC_GRID = 1006,
120  O3R_ODS_EXTRINSIC_CALIBRATION_CORRECTION = 1007,
121  O3R_ODS_RENDERED_ZONES = 1008
122  };
123 
124  class XMLRPC;
125 
135  class IFM3D_EXPORT Device
136  {
137  public:
138  using Ptr = std::shared_ptr<Device>;
139 
146  enum class BootMode : int // NOLINT(performance-enum-size)
147  {
148  PRODUCTIVE = 0,
149  RECOVERY = 1
150  };
151 
156  enum class OperatingMode : int // NOLINT(performance-enum-size)
157  {
158  RUN = 0,
159  EDIT = 1
160  };
161 
165  enum class TriggerMode : int // NOLINT(performance-enum-size)
166  {
167  FREE_RUN = 1,
168  SW = 2
169  };
170 
174  enum class ImportFlags : int // NOLINT(performance-enum-size)
175  {
176  GLOBAL = 0x1,
177  NET = 0x2,
178  APPS = 0x10
179  };
180 
184  enum class SpatialFilter : int // NOLINT(performance-enum-size)
185  {
186  OFF = 0x0,
187  MEDIAN = 0x1,
188  MEAN = 0x2,
189  BILATERAL = 0x3
190  };
191 
195  enum class TemporalFilter : int // NOLINT(performance-enum-size)
196  {
197  OFF = 0x0,
198  MEAN = 0x1,
199  ADAPTIVE_EXP = 0x2
200  };
201 
205  enum class MedianfilterMaskSize : int // NOLINT(performance-enum-size)
206  {
207  _3x3 = 0, // NOLINT(readability-identifier-naming)
208  _5x5 = 1 // NOLINT(readability-identifier-naming)
209  };
210 
211  enum class DeviceFamily : int // NOLINT(performance-enum-size)
212  {
213  UNKNOWN = 0,
214  O3D = 1,
215  O3X = 2,
216  O3R = 3,
217  O3C = 4,
218  };
219 
220  enum class SWUVersion : int // NOLINT(performance-enum-size)
221  {
222  SWU_NOT_SUPPORTED = 0,
223  SWU_V1 = 1,
224  SWU_V2 = 2
225  };
226 
233  static std::vector<ifm3d::IFMNetworkDevice> DeviceDiscovery();
234 
240  static void SetTempIPAddress(const std::string& mac,
241  const std::string& temp_ip);
242 
263  static Ptr MakeShared(
264  const std::string& ip = ifm3d::DEFAULT_IP,
265  std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT,
266  const std::string& password = ifm3d::DEFAULT_PASSWORD,
267  bool throw_if_unavailable = true);
268 
280  Device(const std::string& ip = ifm3d::DEFAULT_IP,
281  std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT);
282 
286  virtual ~Device();
287 
288  // Based on our mileage with `libo3d3xx`, disabling copy and move semantics
289  // on the device class has not been an issue, so, we do that here too.
290  Device(Device&&) = delete;
291  Device& operator=(Device&&) = delete;
292  Device(Device&) = delete;
293  Device& operator=(Device&) = delete;
294 
295  // Accessors/Mutators
296 
298  virtual std::string IP();
299 
301  virtual std::uint16_t XMLRPCPort();
302 
309  virtual void Reboot(
310  const BootMode& mode = ifm3d::Device::BootMode::PRODUCTIVE);
311 
319  virtual void ForceTrigger();
320 
342  virtual std::string DeviceType(bool use_cached = true);
343 
349  virtual DeviceFamily WhoAmI();
350 
359  virtual bool AmI(DeviceFamily family);
360 
365  virtual std::string DeviceParameter(const std::string& key);
366 
375  virtual std::vector<std::string> TraceLogs(int count);
376 
394  virtual json ToJSON();
395 
403  virtual std::string ToJSONStr();
404 
423  virtual void FromJSON(const json& j);
424 
431  virtual void FromJSONStr(const std::string& jstr);
432 
442  bool CheckMinimumFirmwareVersion(unsigned int major,
443  unsigned int minor,
444  unsigned int patch);
445 
450 
456  virtual ifm3d::Device::SWUVersion SwUpdateVersion();
457 
458  json GetSWVersion();
459 
460  protected:
461  class Impl;
462  std::unique_ptr<Impl> _impl;
463 
467  std::string _device_type;
468 
475  int device_id();
476  bool check_device_id(int device_id, int min_id, int max_id);
477 
478  std::shared_ptr<XMLRPC> x_wrapper();
479 
480  }; // end: class Device
481 
482 } // end: namespace ifm3d
483 
484 #endif // IFM3D_DEVICE_DEVICE_H
Software interface to an ifm 3D device.
Definition: device.h:136
virtual void ForceTrigger()
Sends a S/W trigger to the device over XMLRPC.
ImportFlags
Import flags used when importing a Vision Assistant configuration.
Definition: device.h:175
virtual std::string DeviceParameter(const std::string &key)
Convenience accessor for extracting a device parameters (i.e., no edit session created on the device)
virtual DeviceFamily WhoAmI()
This function can be used to retrieve the family of the connected device.
virtual ~Device()
The dtor will cancel any open edit sessions with the device.
virtual void Reboot(const BootMode &mode=ifm3d::Device::BootMode::PRODUCTIVE)
Reboot the device.
virtual void FromJSONStr(const std::string &jstr)
Accepts a string with properly formatted/escaped JSON text, converts it to a json object,...
virtual void FromJSON(const json &j)
Configures the device based on the parameter values of the passed in JSON.
virtual bool AmI(DeviceFamily family)
This is a convenience function for checking whether a device is one of the specified device family.
virtual std::vector< std::string > TraceLogs(int count)
Delivers the trace log from the device A session is not required to call this function.
TriggerMode
Image acquisition trigger modes.
Definition: device.h:166
static void SetTempIPAddress(const std::string &mac, const std::string &temp_ip)
This function Provides a way to set temporary IP.
virtual std::string DeviceType(bool use_cached=true)
This is a convenience function for extracting out the device type of the connected device.
MedianfilterMaskSize
Convenient constants for median filter mask sizes.
Definition: device.h:206
virtual std::string IP()
The IP address associated with this Device instance.
std::string _device_type
The cached device type of the connected device.
Definition: device.h:467
Device(const std::string &ip=ifm3d::DEFAULT_IP, std::uint16_t xmlrpc_port=ifm3d::DEFAULT_XMLRPC_PORT)
Initializes the device interface utilizing library defaults for password, ip, and xmlrpc port unless ...
SpatialFilter
Convenience constants for spatial filter types.
Definition: device.h:185
OperatingMode
Device operating modes: run (streaming pixel data), edit (configuring the device/applications).
Definition: device.h:157
int device_id()
Implements the serialization of the device state to JSON.
ifm3d::SemVer FirmwareVersion()
get the firmware version of the device
bool CheckMinimumFirmwareVersion(unsigned int major, unsigned int minor, unsigned int patch)
Checks for a minimum ifm device software version.
static Ptr MakeShared(const std::string &ip=ifm3d::DEFAULT_IP, std::uint16_t xmlrpc_port=ifm3d::DEFAULT_XMLRPC_PORT, const std::string &password=ifm3d::DEFAULT_PASSWORD, bool throw_if_unavailable=true)
Factory function for instantiating the proper subclass based on h/w probing.
virtual std::uint16_t XMLRPCPort()
The XMLRPC Port associated with this Device instance.
virtual json ToJSON()
Serializes the state of the device to JSON.
virtual std::string ToJSONStr()
A stringified version of the JSON object returned by ToJSON().
static std::vector< ifm3d::IFMNetworkDevice > DeviceDiscovery()
This function Provides a convinent way to find all ifm devices on the network.
virtual ifm3d::Device::SWUVersion SwUpdateVersion()
Checks the swupdater version supported by device.
BootMode
Device boot up modes:
Definition: device.h:147
TemporalFilter
Convenience constants for temporal filter types.
Definition: device.h:196
Device specialization for O3C.
Definition: o3c.h:26
Device specialization for O3D.
Definition: o3d.h:20
Device specialization for O3R.
Definition: o3r.h:43
Device specialization for O3X.
Definition: o3x.h:20
Definition: json.hpp:131
Definition: semver.h:20