ifm3d
swupdater.h
1 /*
2  * Copyright 2019 ifm electronic, gmbh
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #ifndef IFM3D_SWUPDATER_SWUPDATER_H
7 #define IFM3D_SWUPDATER_SWUPDATER_H
8 #pragma once
9 
10 #include <ifm3d/device/legacy_device.h>
11 #include <ifm3d/swupdater/module_swupdater.h>
12 #include <memory>
13 #include <string>
14 
15 namespace ifm3d
16 {
17  /* const for the swupdate recovery port value */
18  extern IFM3D_EXPORT const std::uint16_t SWUPDATER_RECOVERY_PORT;
19 
21  class IFM3D_EXPORT SWUpdater
22  {
23  public:
24  using Ptr = std::shared_ptr<SWUpdater>;
25 
35  using FlashStatusCb = std::function<void(float, const std::string&)>;
36 
47  const ifm3d::Device::Ptr& cam,
48  const ifm3d::SWUpdater::FlashStatusCb& cb = {},
49  std::uint16_t swupdate_recovery_port = ifm3d::SWUPDATER_RECOVERY_PORT,
50  std::optional<ifm3d::Device::SWUVersion> force_swu_version =
51  std::nullopt);
52 
53  virtual ~SWUpdater();
54 
55  // disable copy/move semantics
56  SWUpdater(SWUpdater&&) = delete;
57  SWUpdater& operator=(SWUpdater&&) = delete;
58  SWUpdater(SWUpdater&) = delete;
59  SWUpdater& operator=(const SWUpdater&) = delete;
60 
71  const std::optional<std::string>& password = std::nullopt);
72 
90  bool WaitForRecovery(long timeout_millis = 0);
91 
100 
118  bool WaitForProductive(long timeout_millis = 0);
119 
139  bool FlashFirmware(const std::string& swu_file, long timeout_millis = 0);
140 
141  class IFM3D_EXPORT Impl;
142 
143  private:
144  std::unique_ptr<Impl> _impl;
145 
146  }; // end: class SWUpdater
147 
148 } // end: namespace ifm3d
149 
150 #endif // IFM3D_SWUPDATER_SWUPDATER_H
Definition: swupdater.h:22
bool WaitForRecovery(long timeout_millis=0)
Polls on status of the device, waiting for it to present in recovery mode.
bool WaitForProductive(long timeout_millis=0)
Polls on status of the device, waiting for it to present in productive mode.
bool FlashFirmware(const std::string &swu_file, long timeout_millis=0)
Uploads a firmware image to the device's recovery system.
void RebootToProductive()
Reboots the device from recovery to productive.
void RebootToRecovery(const std::optional< std::string > &password=std::nullopt)
Reboots the device from productive to recovery.
SWUpdater(const ifm3d::Device::Ptr &cam, const ifm3d::SWUpdater::FlashStatusCb &cb={}, std::uint16_t swupdate_recovery_port=ifm3d::SWUPDATER_RECOVERY_PORT, std::optional< ifm3d::Device::SWUVersion > force_swu_version=std::nullopt)
Ctor.
std::function< void(float, const std::string &)> FlashStatusCb
Signature for user callback to receive status information about firmware flashing.
Definition: swupdater.h:35