ifm3d
legacy_device.h
1 /*
2  * Copyright 2021-present ifm electronic, gmbh
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #ifndef IFM3D_DEVICE_LEGACY_DEVICE_H
7 #define IFM3D_DEVICE_LEGACY_DEVICE_H
8 
9 #include <ifm3d/device/device.h>
10 
11 namespace ifm3d
12 {
13  class IFM3D_EXPORT LegacyDevice : public Device
14  {
15  public:
16  using Ptr = std::shared_ptr<LegacyDevice>;
17 
25  using device_family = ifm3d::Device::DeviceFamily;
26 
47  static Ptr MakeShared(
48  const std::string& ip = ifm3d::DEFAULT_IP,
49  std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT,
50  const std::string& password = ifm3d::DEFAULT_PASSWORD);
51 
63  LegacyDevice(const std::string& ip = ifm3d::DEFAULT_IP,
64  std::uint16_t xmlrpc_port = ifm3d::DEFAULT_XMLRPC_PORT,
65  const std::string& password = ifm3d::DEFAULT_PASSWORD);
66 
67  LegacyDevice(const LegacyDevice&) = delete;
68  LegacyDevice(LegacyDevice&&) = delete;
69  LegacyDevice& operator=(const LegacyDevice&) = delete;
70  LegacyDevice& operator=(LegacyDevice&&) = delete;
71  ~LegacyDevice() override;
72 
74  virtual std::string Password();
75 
77  virtual std::string SessionID();
78 
83  virtual void FactoryReset();
84 
111  virtual std::string RequestSession();
112 
125  virtual bool CancelSession();
126 
134  virtual bool CancelSession(const std::string& sid);
135 
148  virtual int Heartbeat(int hb);
149 
150  virtual std::unordered_map<std::string, std::string> NetInfo();
151  virtual std::unordered_map<std::string, std::string> TimeInfo();
152 
171  const std::unordered_map<std::string, std::string>& params);
172 
177  virtual int ActiveApplication();
178 
192 
202  virtual std::vector<std::string> ApplicationTypes();
203 
212  virtual std::vector<std::string> ImagerTypes();
213 
225  virtual int CopyApplication(int idx);
226 
244  virtual int CreateApplication(
245  const std::string& type = DEFAULT_APPLICATION_TYPE);
246 
253  virtual void DeleteApplication(int idx);
254 
262  virtual void SetCurrentTime(int epoch_secs = -1);
263 
268  virtual std::vector<std::uint8_t> UnitVectors();
269 
274  virtual std::vector<std::uint8_t> ExportIFMConfig();
275 
291  virtual std::vector<std::uint8_t> ExportIFMApp(int idx);
292 
297  virtual void ImportIFMConfig(const std::vector<std::uint8_t>& bytes,
298  std::uint16_t flags = 0x0);
299 
313  virtual int ImportIFMApp(const std::vector<std::uint8_t>& bytes);
314 
323  virtual void SetPassword(const std::string& password = "");
324 
325  json ToJSON() override;
326  void FromJSON(const json& j) override;
327  void ForceTrigger() override;
328 
329  protected:
330  class Impl;
331  std::unique_ptr<Impl> _impl;
332 
347  void from_json(const json& j_curr,
348  const json& j_new,
349  const std::function<void(const std::string&,
350  const std::string&)>& set_func,
351  const std::function<void()>& save_func,
352  const std::string& name,
353  int idx = -1);
354 
363  static bool get_app_json(int index, const json& j, json& app);
364 
365  json to_json(bool open_session = true);
366 
367  json get_application_infos_to_json();
368 
369  void apply_device_config(json& current, const json& root);
370  void apply_apps_config(json& current, const json& root);
371  void apply_time_config(json& current, const json& root);
372  void apply_network_config(json& current, const json& root);
373  };
374 }
375 
376 #endif // IFM3D_DEVICE_LEGACY_DEVICE_H
Software interface to an ifm 3D device.
Definition: device.h:134
ImportFlags
Import flags used when importing a Vision Assistant configuration.
Definition: device.h:173
TriggerMode
Image acquisition trigger modes.
Definition: device.h:164
MedianfilterMaskSize
Convenient constants for median filter mask sizes.
Definition: device.h:204
SpatialFilter
Convenience constants for spatial filter types.
Definition: device.h:183
OperatingMode
Device operating modes: run (streaming pixel data), edit (configuring the device/applications).
Definition: device.h:155
BootMode
Device boot up modes:
Definition: device.h:145
TemporalFilter
Convenience constants for temporal filter types.
Definition: device.h:194
Definition: legacy_device.h:14
virtual bool CancelSession(const std::string &sid)
Attempts to cancel a session with a particular session id.
virtual void SetTemporaryApplicationParameters(const std::unordered_map< std::string, std::string > &params)
Sets temporary application parameters in run mode.
void from_json(const json &j_curr, const json &j_new, const std::function< void(const std::string &, const std::string &)> &set_func, const std::function< void()> &save_func, const std::string &name, int idx=-1)
Handles parsing a selected sub-tree of a potential input JSON file, setting the parameters as appropr...
virtual int Heartbeat(int hb)
Heartbeat messages are used to keep a session with the sensor alive.
virtual void SetPassword(const std::string &password="")
Sets or disable the password on the device.
virtual int CreateApplication(const std::string &type=DEFAULT_APPLICATION_TYPE)
Creates a new application on the device of the given type.
virtual bool CancelSession()
Explictly stops the current session with the sensor.
virtual void ImportIFMConfig(const std::vector< std::uint8_t > &bytes, std::uint16_t flags=0x0)
Imports an entire device configuration from a format compatible with Vision Assistant.
virtual int CopyApplication(int idx)
Creates a new application by copying the configuration of another application.
virtual std::vector< std::uint8_t > UnitVectors()
For devices that support fetching the Unit Vectors over XML-RPC, this function will return those data...
virtual void SetCurrentTime(int epoch_secs=-1)
Explicitly sets the current time on the device.
virtual std::string Password()
The password associated with this Device instance.
json ToJSON() override
Serializes the state of the device to JSON.
virtual int ImportIFMApp(const std::vector< std::uint8_t > &bytes)
Import the IFM-encoded application.
static bool get_app_json(int index, const json &j, json &app)
Return json of an app with given index from device configuration json.
virtual std::vector< std::string > ImagerTypes()
Lists the valid imager types supported by the sensor.
virtual int ActiveApplication()
Returns the integer index of the active application.
virtual std::vector< std::string > ApplicationTypes()
Lists the valid application types supported by the sensor.
void FromJSON(const json &j) override
Configures the device based on the parameter values of the passed in JSON.
LegacyDevice(const std::string &ip=ifm3d::DEFAULT_IP, std::uint16_t xmlrpc_port=ifm3d::DEFAULT_XMLRPC_PORT, const std::string &password=ifm3d::DEFAULT_PASSWORD)
Initializes the device interface utilizing library defaults for password, ip, and xmlrpc port unless ...
virtual void FactoryReset()
Sets the device configuration back to the state in which it shipped from the ifm factory.
virtual void DeleteApplication(int idx)
Deletes the application at the specified index from the sensor.
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)
Factory function for instantiating the proper subclass based on h/w probing.
virtual std::string RequestSession()
Requests an edit-mode session with the device.
virtual std::string SessionID()
Retrieves the active session id.
virtual std::vector< std::uint8_t > ExportIFMApp(int idx)
Export the application at the specified index into a byte array suitable for writing to a file.
virtual json ApplicationList()
Delivers basic information about all applications stored on the device.
virtual std::vector< std::uint8_t > ExportIFMConfig()
Exports the entire device configuration in a format compatible with Vision Assistant.
void ForceTrigger() override
Sends a S/W trigger to the device over XMLRPC.
Definition: json.hpp:131