ifm3d
o3r.h
1 /*
2  * Copyright 2021-present ifm electronic, gmbh
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #ifndef IFM3D_DEVICE_O3R_H
7 #define IFM3D_DEVICE_O3R_H
8 
9 #include <ifm3d/common/features.h>
10 #include <ifm3d/device/device.h>
11 #include <sstream>
12 #ifdef BUILD_MODULE_CRYPTO
13 # include <ifm3d/crypto/crypto.h>
14 #endif
15 #include <ifm3d/device/pcic_command.h>
16 #include <initializer_list>
17 #include <optional>
18 #include <variant>
19 #include <vector>
20 
21 namespace ifm3d
22 {
23  static const int NET_WAIT_O3R_SET =
24  std::getenv("IFM3D_NET_WAIT_O3R_SET") == nullptr ?
25  15000 :
26  std::stoi(std::getenv("IFM3D_NET_WAIT_O3R_SET"));
27 
32  struct IFM3D_EXPORT RtspControlInfo
33  {
35  uint16_t tcp_port;
36  };
37 
42  struct IFM3D_EXPORT RtspMediaEndpoint
43  {
45  std::string path;
46  };
47 
52  struct IFM3D_EXPORT RtspInfo
53  {
57  std::vector<RtspMediaEndpoint> media_endpoints;
60  std::vector<std::string> supported_transports;
61  };
62 
64  struct IFM3D_EXPORT PortInfo
65  {
66  std::string port;
67  uint16_t pcic_port;
68  std::string type;
70  std::optional<RtspInfo> rtsp;
71  };
72 
73 #ifdef BUILD_MODULE_CRYPTO
74  class O3RSealedBox;
75 #endif
76 
81  class IFM3D_EXPORT O3R : public Device
82  {
83  public:
84  using Ptr = std::shared_ptr<O3R>;
85  O3R(const std::string& ip = ifm3d::DEFAULT_IP,
86  std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT);
87 
88  ~O3R() override;
89  O3R(O3R&&) = delete;
90  O3R& operator=(O3R&&) = delete;
91  O3R(O3R&) = delete;
92  O3R& operator=(O3R&) = delete;
93 
101  virtual void FactoryReset(bool keep_network_settings);
102 
109 
123  std::variant<std::monostate, std::string, std::vector<std::string>>
124  pointers);
125 
138  json GetSchema(std::initializer_list<std::string> pointers);
139 
150  const std::vector<std::string>& path = std::vector<std::string>());
151 
160  json ResolveConfig(const json::json_pointer& ptr);
161 
169  void Set(const json& j);
170 
180  void Remove(const std::string& json_pointer);
181 
191  void Reset(const std::string& json_pointer);
192 
199 
209  void SaveInit(const std::vector<std::string>& pointers = {});
210 
218  std::string GetInitStatus();
219 
229  void Lock(const std::string& password);
230 
238  void Unlock(const std::string& password);
239 
246  std::vector<PortInfo> Ports();
247 
255  PortInfo Port(const std::string& port);
256 
263 
271 
280 
281  void Reboot(
282  const BootMode& mode = ifm3d::Device::BootMode::PRODUCTIVE) override;
283 
288 
289  DeviceFamily WhoAmI() override;
290  ifm3d::Device::SWUVersion SwUpdateVersion() override;
291 
296  json ToJSON() override;
297 
302  void FromJSON(const json& j) override;
303 
304  void DownloadServiceReport(const std::string& out_file);
305 
306 #ifdef BUILD_MODULE_CRYPTO
311  std::shared_ptr<O3RSealedBox> SealedBox();
312 #endif
313 
315  {
316  enum Parameter : uint16_t
317  {
318  ODS_OVERHANGING_LOAD = 2003,
319  ODS_ZONE_SET = 2101,
320  ODS_MAXIMUM_HEIGHT = 2102,
321  ODS_MOTION_DATA = 2103,
322  PDS_GET_PALLET = 2200,
323  PDS_GET_ITEM = 2201,
324  PDS_GET_RACK = 2202,
325  PDS_VOL_CHECK = 2203,
326  };
327 
328  Parameter parameter;
329  std::vector<std::uint8_t> data;
330 
332  Parameter param,
333  std::vector<std::uint8_t> parameter_data)
334  : parameter(param),
335  data(std::move(parameter_data))
336  {}
337 
338  std::vector<std::uint8_t>
339  SerializeData() const override
340  {
341  std::vector<std::uint8_t> payload;
342 
343  // 'f' command prefix
344  payload.push_back(static_cast<uint8_t>('f'));
345 
346  // parameter ID as 5-digit ASCII string padded with zeros
347  std::ostringstream param;
348  param << std::setw(5) << std::setfill('0')
349  << static_cast<uint16_t>(parameter);
350  const std::string paramStr = param.str(); // e.g., "02103"
351  payload.insert(payload.end(), paramStr.begin(), paramStr.end());
352 
353  // reserved string "#00000" as bytes
354  const std::string reserved = "#00000";
355  payload.insert(payload.end(), reserved.begin(), reserved.end());
356 
357  // append user data bytes
358  payload.insert(payload.end(), data.begin(), data.end());
359 
360  return payload;
361  }
362  };
363 
364  private:
365  class Impl;
366  std::shared_ptr<Impl> _impl;
367 
368 #ifdef BUILD_MODULE_CRYPTO
369  friend class O3RSealedBox;
370 #endif
371  }; // end: class O3R
372 
373 #ifdef BUILD_MODULE_CRYPTO
381  class IFM3D_EXPORT O3RSealedBox
382  {
383  public:
384  using Ptr = std::shared_ptr<O3RSealedBox>;
385 
386  O3RSealedBox(const O3RSealedBox&) = default;
387  O3RSealedBox(O3RSealedBox&&) = delete;
388  O3RSealedBox& operator=(const O3RSealedBox&) = default;
389  O3RSealedBox& operator=(O3RSealedBox&&) = delete;
390  O3RSealedBox(std::shared_ptr<O3R::Impl> p_impl);
391  ~O3RSealedBox();
392 
400  void SetPassword(const std::string& new_password,
401  std::optional<std::string> old_password = std::nullopt);
402 
408  bool IsPasswordProtected();
409 
415  void RemovePassword(std::string password);
416 
424  void Set(const std::string& password, const json& configuration);
425 
432  std::vector<uint8_t> GetPublicKey();
433 
434  private:
435  std::shared_ptr<O3R::Impl> _impl;
436  };
437 #endif
438 }
439 
440 #endif // IFM3D_DEVICE_O3R_H
Software interface to an ifm 3D device.
Definition: device.h:136
BootMode
Device boot up modes:
Definition: device.h:147
Device specialization for O3R.
Definition: o3r.h:82
void Reset(const std::string &json_pointer)
Sets the default value of an object inside the JSON.
void Set(const json &j)
Overwrites parts of the temporary JSON configuration which is achieved by merging the provided JSON f...
json GetInit()
Return the initial JSON configuration.
json GetDiagnosticFilterSchema()
Returns the JSON schema for the filter expression provided to the getFiltered() method.
json GetSchema()
Return the current JSON schema configuration.
json GetSchema(std::initializer_list< std::string > pointers)
Returns the current JSON schema configuration or a subset of it.
void SaveInit(const std::vector< std::string > &pointers={})
Save to current temporary JSON configuration as initial JSON configuration, so it will be applied wit...
json ResolveConfig(const json::json_pointer &ptr)
Returns a part of the configuration formatted as JSON based on a JSON pointer.
void Remove(const std::string &json_pointer)
Removes an object from the JSON.
json Get(const std::vector< std::string > &path=std::vector< std::string >())
Returns the configuration formatted as JSON based on a path.
void Reboot(const BootMode &mode=ifm3d::Device::BootMode::PRODUCTIVE) override
Reboot the device.
void RebootToRecovery()
Reboot the device into Recovery Mode.
virtual void FactoryReset(bool keep_network_settings)
Sets the device configuration back to the state in which it shipped from the ifm factory.
json ToJSON() override
Serializes the state of the device to JSON.
DeviceFamily WhoAmI() override
This function can be used to retrieve the family of the connected device.
void FromJSON(const json &j) override
Configures the device based on the parameter values of the passed in JSON.
std::vector< PortInfo > Ports()
Returns a list containing information about all connected physical and application ports.
ifm3d::Device::SWUVersion SwUpdateVersion() override
Checks the swupdater version supported by device.
json GetDiagnosticFiltered(const json &filter)
Returns the content of the diagnostic memory formatted in JSON and filtered according to the JSON fil...
PortInfo Port(const std::string &port)
Returns information about a given physical or application port.
json GetDiagnostic()
Returns the content of the diagnostic memory formatted in JSON.
json GetSchema(std::variant< std::monostate, std::string, std::vector< std::string >> pointers)
Returns the current JSON schema configuration or a subset of it.
Definition: pcic_command.h:11
Definition: crypto.h:18
Definition: json.hpp:131
std::vector< std::uint8_t > SerializeData() const override
Serialize the command into a sequence of bytes for PCIC transmission.
Definition: o3r.h:339
Definition: o3r.h:65
std::optional< RtspInfo > rtsp
RTSP streaming information, present when the port advertises it.
Definition: o3r.h:70
RTSP control endpoint information for a port.
Definition: o3r.h:33
uint16_t tcp_port
TCP port the RTSP control channel is served on.
Definition: o3r.h:35
RTSP streaming information advertised by a port.
Definition: o3r.h:53
std::vector< RtspMediaEndpoint > media_endpoints
Media endpoints exposed by the port.
Definition: o3r.h:57
RtspControlInfo control
RTSP control channel information.
Definition: o3r.h:55
std::vector< std::string > supported_transports
Transports supported by the RTSP server (e.g.
Definition: o3r.h:60
A single RTSP media endpoint advertised by a port.
Definition: o3r.h:43
std::string path
Stream path (e.g.
Definition: o3r.h:45