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 #ifdef BUILD_MODULE_CRYPTO
12 # include <ifm3d/crypto/crypto.h>
13 #endif
14 
15 namespace ifm3d
16 {
17  static const int NET_WAIT_O3R_SET =
18  std::getenv("IFM3D_NET_WAIT_O3R_SET") == nullptr ?
19  15000 :
20  std::stoi(std::getenv("IFM3D_NET_WAIT_O3R_SET"));
21 
23  struct IFM3D_EXPORT PortInfo
24  {
25  std::string port;
26  uint16_t pcic_port;
27  std::string type;
28  };
29 
30 #ifdef BUILD_MODULE_CRYPTO
31  class O3RSealedBox;
32 #endif
33 
38  class IFM3D_EXPORT O3R : public Device
39  {
40  public:
41  using Ptr = std::shared_ptr<O3R>;
42  O3R(const std::string& ip = ifm3d::DEFAULT_IP,
43  const std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT);
44 
45  virtual ~O3R();
46  O3R(O3R&&) = delete;
47  O3R& operator=(O3R&&) = delete;
48  O3R(O3R&) = delete;
49  O3R& operator=(O3R&) = delete;
50 
58  virtual void FactoryReset(bool keepNetworkSettings);
59 
65  json GetSchema();
66 
76  json Get(
77  const std::vector<std::string>& path = std::vector<std::string>());
78 
87  json ResolveConfig(const json::json_pointer& ptr);
88 
96  void Set(const json& j);
97 
107  void Remove(const std::string& jsonPointer);
108 
118  void Reset(const std::string& jsonPointer);
119 
125  json GetInit();
126 
136  void SaveInit(const std::vector<std::string>& pointers = {});
137 
145  std::string GetInitStatus();
146 
156  void Lock(const std::string& password);
157 
165  void Unlock(const std::string& password);
166 
173  std::vector<PortInfo> Ports();
174 
182  PortInfo Port(const std::string& port);
183 
189  json GetDiagnostic();
190 
197  json GetDiagnosticFilterSchema();
198 
206  json GetDiagnosticFiltered(json filter);
207 
208  void Reboot(
209  const boot_mode& mode = ifm3d::Device::boot_mode::PRODUCTIVE) override;
210 
214  void RebootToRecovery();
215 
216  device_family WhoAmI() override;
217  ifm3d::Device::swu_version SwUpdateVersion() override;
218 
223  json ToJSON() override;
224 
229  void FromJSON(const json& j) override;
230 
231  void DownloadServiceReport(std::string outFile);
232 
233 #ifdef BUILD_MODULE_CRYPTO
234 
238  std::shared_ptr<O3RSealedBox> SealedBox();
239 #endif
240 
241  private:
242  class Impl;
243  std::shared_ptr<Impl> pImpl;
244 
245 #ifdef BUILD_MODULE_CRYPTO
246  friend class O3RSealedBox;
247 #endif
248  }; // end: class O3R
249 
250 #ifdef BUILD_MODULE_CRYPTO
251 
258  class IFM3D_EXPORT O3RSealedBox
259  {
260  public:
261  using Ptr = std::shared_ptr<O3RSealedBox>;
262 
263  O3RSealedBox(std::shared_ptr<O3R::Impl> pImpl);
264  ~O3RSealedBox();
265 
273  void SetPassword(const std::string& new_password,
274  std::optional<std::string> old_password = std::nullopt);
275 
281  bool IsPasswordProtected();
282 
288  void RemovePassword(std::string password);
289 
297  void Set(const std::string& password, const json& configuration);
298 
305  std::vector<uint8_t> GetPublicKey();
306 
307  private:
308  std::shared_ptr<O3R::Impl> pImpl;
309  };
310 #endif
311 }
312 
313 #endif // IFM3D_DEVICE_O3R_H
ifm3d::json
Definition: json.hpp:128
ifm3d::Device::boot_mode
boot_mode
Device boot up modes:
Definition: device.h:143
ifm3d::Device
Definition: device.h:132
ifm3d::PortInfo
Definition: o3r.h:23
ifm3d::O3R
Definition: o3r.h:38