IDS peak genericC++ v1.13.0
Loading...
Searching...
No Matches
peak_firmware_updater.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13
18#include <peak/dll_interface/peak_dll_interface_util.hpp>
19
20#include <memory>
21#include <string>
22#include <vector>
23
24
25namespace peak
26{
27namespace core
28{
29using namespace std::chrono_literals;
30
46class FirmwareUpdater final
47{
48public:
51 FirmwareUpdater(const FirmwareUpdater& other) = delete;
52 FirmwareUpdater& operator=(const FirmwareUpdater& other) = delete;
55
72 std::vector<std::shared_ptr<FirmwareUpdateInformation>> CollectFirmwareUpdateInformation(
73 const std::string& gufPath) const;
74
94 std::vector<std::shared_ptr<FirmwareUpdateInformation>> CollectFirmwareUpdateInformation(
95 const std::string& gufPath, const std::shared_ptr<DeviceDescriptor>& device) const;
96
122 void UpdateDevice(const std::shared_ptr<DeviceDescriptor>& device,
123 const std::shared_ptr<FirmwareUpdateInformation>& updateInformation,
124 const FirmwareUpdateProgressObserver* progressObserver = nullptr,
125 Timeout deviceResetDiscoveryTimeout = Timeout(60000ms));
126
127private:
128 PEAK_FIRMWARE_UPDATER_HANDLE m_backendHandle;
129};
130
131} /* namespace core */
132} /* namespace peak */
133
134/* Implementation */
135namespace peak
136{
137namespace core
138{
139
141 : m_backendHandle(QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATER_HANDLE>(
142 [](PEAK_FIRMWARE_UPDATER_HANDLE* firmwareUpdaterHandle) {
143 return PEAK_C_ABI_PREFIX PEAK_FirmwareUpdater_Construct(firmwareUpdaterHandle);
144 }))
145{}
146
151
152inline std::vector<std::shared_ptr<FirmwareUpdateInformation>> FirmwareUpdater::CollectFirmwareUpdateInformation(
153 const std::string& gufPath) const
154{
155 CallAndCheckCInterfaceFunction([&] {
157 m_backendHandle, gufPath.c_str(), gufPath.size() + 1);
158 });
159
160 auto numFirmwareUpdateInformation = QueryNumericFromCInterfaceFunction<size_t>(
161 [&](size_t* _numFirmwareUpdateInformation) {
163 m_backendHandle, _numFirmwareUpdateInformation);
164 });
165
166 std::vector<std::shared_ptr<FirmwareUpdateInformation>> firmwareUpdateInformation;
167 for (size_t x = 0; x < numFirmwareUpdateInformation; ++x)
168 {
169 auto firmwareUpdateInformationHandle =
170 QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE>(
171 [&](PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE* _firmwareUpdateInformationHandle) {
173 m_backendHandle, x, _firmwareUpdateInformationHandle);
174 });
175
176 firmwareUpdateInformation.emplace_back(
177 std::make_shared<ClassCreator<FirmwareUpdateInformation>>(firmwareUpdateInformationHandle));
178 }
179
180 return firmwareUpdateInformation;
181}
182
183inline std::vector<std::shared_ptr<FirmwareUpdateInformation>> FirmwareUpdater::CollectFirmwareUpdateInformation(
184 const std::string& gufPath, const std::shared_ptr<DeviceDescriptor>& device) const
185{
186 if (device == nullptr)
187 {
188 throw InvalidArgumentException("The given device is a nullptr!");
189 }
190
191 CallAndCheckCInterfaceFunction([&] {
193 m_backendHandle, gufPath.c_str(), gufPath.size() + 1, device->m_backendHandle);
194 });
195
196 auto numFirmwareUpdateInformation = QueryNumericFromCInterfaceFunction<size_t>(
197 [&](size_t* _numFirmwareUpdateInformation) {
199 m_backendHandle, _numFirmwareUpdateInformation);
200 });
201
202 std::vector<std::shared_ptr<FirmwareUpdateInformation>> firmwareUpdateInformation;
203 for (size_t x = 0; x < numFirmwareUpdateInformation; ++x)
204 {
205 auto firmwareUpdateInformationHandle =
206 QueryNumericFromCInterfaceFunction<PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE>(
207 [&](PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE* _firmwareUpdateInformationHandle) {
209 m_backendHandle, x, _firmwareUpdateInformationHandle);
210 });
211
212 firmwareUpdateInformation.emplace_back(
213 std::make_shared<ClassCreator<FirmwareUpdateInformation>>(firmwareUpdateInformationHandle));
214 }
215
216 return firmwareUpdateInformation;
217}
218
219inline void FirmwareUpdater::UpdateDevice(const std::shared_ptr<DeviceDescriptor>& device,
220 const std::shared_ptr<FirmwareUpdateInformation>& updateInformation,
221 const FirmwareUpdateProgressObserver* progressObserver /* = nullptr */,
222 Timeout deviceResetDiscoveryTimeout /* = Timeout{ 60000ms }*/)
223{
224 if (device == nullptr)
225 {
226 throw InvalidArgumentException("The given device is a nullptr!");
227 }
228 if (updateInformation == nullptr)
229 {
230 throw InvalidArgumentException("The given updateInformation is a nullptr!");
231 }
232
233 CallAndCheckCInterfaceFunction([&] {
235 device->m_backendHandle, updateInformation->m_backendHandle,
236 progressObserver ? progressObserver->m_backendHandle : nullptr, deviceResetDiscoveryTimeout);
237 });
238}
239
240} /* namespace core */
241} /* namespace peak */
Allows to observe a firmware update process.
Definition peak_firmware_update_progress_observer.hpp:55
void UpdateDevice(const std::shared_ptr< DeviceDescriptor > &device, const std::shared_ptr< FirmwareUpdateInformation > &updateInformation, const FirmwareUpdateProgressObserver *progressObserver=nullptr, Timeout deviceResetDiscoveryTimeout=Timeout(60000ms))
Updates a given device by using a given firmware update information.
Definition peak_firmware_updater.hpp:219
~FirmwareUpdater()
Definition peak_firmware_updater.hpp:147
FirmwareUpdater(FirmwareUpdater &&other)=delete
FirmwareUpdater()
Definition peak_firmware_updater.hpp:140
std::vector< std::shared_ptr< FirmwareUpdateInformation > > CollectFirmwareUpdateInformation(const std::string &gufPath) const
Collects all firmware update information of a given *.guf file.
Definition peak_firmware_updater.hpp:152
FirmwareUpdater & operator=(FirmwareUpdater &&other)=delete
FirmwareUpdater & operator=(const FirmwareUpdater &other)=delete
FirmwareUpdater(const FirmwareUpdater &other)=delete
The exception thrown for passing an invalid argument to a function.
Definition peak_exception.hpp:116
Represents a timeout value in milliseconds.
Definition peak_timeout.hpp:32
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:34
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:33
PEAK_C_API PEAK_FirmwareUpdater_UpdateDeviceWithResetTimeout(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle, PEAK_DEVICE_DESCRIPTOR_HANDLE deviceDescriptorHandle, PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE firmwareUpdateInformationHandle, PEAK_FIRMWARE_UPDATE_PROGRESS_OBSERVER_HANDLE firmwareUpdateProgressObserverHandle, uint64_t deviceResetDiscoveryTimeout_ms)
Tells the given firmware updater to update the given device with the given update information.
PEAK_C_API PEAK_FirmwareUpdater_GetFirmwareUpdateInformation(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle, size_t index, PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE *firmwareUpdateInformationHandle)
Asks the given firmware updater for the update information with the given index.
PEAK_C_API PEAK_FirmwareUpdater_Construct(PEAK_FIRMWARE_UPDATER_HANDLE *firmwareUpdaterHandle)
Creates a firmware updater.
PEAK_C_API PEAK_FirmwareUpdater_GetNumFirmwareUpdateInformation(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle, size_t *numFirmwareUpdateInformation)
Asks the given firmware updater for its number of update information.
PEAK_C_API PEAK_FirmwareUpdater_Destruct(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle)
Destroys the given firmware updater.
struct PEAK_FIRMWARE_UPDATE_INFORMATION * PEAK_FIRMWARE_UPDATE_INFORMATION_HANDLE
Definition peak_backend.h:497
struct PEAK_FIRMWARE_UPDATER * PEAK_FIRMWARE_UPDATER_HANDLE
Definition peak_backend.h:493
PEAK_C_API PEAK_FirmwareUpdater_CollectFirmwareUpdateInformation(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle, const char *gufPath, size_t gufPathSize, PEAK_DEVICE_DESCRIPTOR_HANDLE deviceDescriptorHandle)
Tells the given firmware updater to collect all update information fitting to the given device.
PEAK_C_API PEAK_FirmwareUpdater_CollectAllFirmwareUpdateInformation(PEAK_FIRMWARE_UPDATER_HANDLE firmwareUpdaterHandle, const char *gufPath, size_t gufPathSize)
Tells the given firmware updater to collect all update information from the .guf file.
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:16