9#include "../../_cexports/c_gen_api.h"
11#include "../../global.hpp"
13#include "../_decl/decl_node.hpp"
14#include "../_decl/decl_node_map.hpp"
15#include "../_decl/decl_fw_updater.hpp"
16#include "../../device.hpp"
17#include "../../device_factory.hpp"
19#include "../string_node.hpp"
31 auto firmwareUpdater = Internal::DoResCallObjectOut<FWUpdater>(
32 [&](
void *&handle) {
return CVB_CALL_CAPI(CreateFirmwareUpdater(cname.c_str(), verify, handle)); }, filename);
33 return firmwareUpdater;
36 inline FWUpdater::FWUpdater(
const String &filename,
bool verify)
37 : FWUpdater(std::move(*
Create(filename, verify)))
36 inline FWUpdater::FWUpdater(
const String &filename,
bool verify) {
…}
41 inline FWUpdater::FWUpdater(HandleGuard<FWUpdater> &&guard,
const String &filename, PrivateTag) noexcept
52 return std::make_unique<FWUpdater>(
std::move(guard), filename, PrivateTag{});
57 return NativeCall<size_t>([&](
size_t &count) {
return CVB_CALL_CAPI(FWUpdateFileCount(
Handle(), count)); });
62 return NativeCall<size_t>(
63 [&](
size_t &count) {
return CVB_CALL_CAPI(FWUpdateFileInfoCount(
Handle(), fileIndex, count)); });
68 return NativeCall<String>([&](
String &value) {
70 auto bufferSizeResult = CExports::FWUpdateFileInfoTyped(
Handle(), fileIndex, infoIndex,
71 static_cast<CExports::TFirmwareUpdateInfo
>(cmd),
72 reinterpret_cast<Char *
>(0), bufferSize);
73 if (bufferSizeResult < 0)
74 return bufferSizeResult;
77 auto bufferResult = CExports::FWUpdateFileInfoTyped(
78 Handle(), fileIndex, infoIndex,
static_cast<CExports::TFirmwareUpdateInfo
>(cmd), buffer.data(), bufferSize);
82 value =
String(buffer.data());
92 for (
size_t updateFile = 0; updateFile < updateFileCount; updateFile++)
98 for (
size_t fileInfo = 0; fileInfo < updateFileInfoCount; fileInfo++)
105 return availableGufInformation;
113 for (
size_t updateFile = 0; updateFile < updateFileCount; updateFile++)
118 String fileFirmwareVersion;
119 for (
size_t fileInfo = 0; fileInfo < updateFileInfoCount; fileInfo++)
123 if (key == CVB_LIT(
"Description"))
124 fileDescription = value;
125 if (key == CVB_LIT(
"Version"))
126 fileFirmwareVersion = value;
128 availableFileDescriptions.push_back(fileDescription + CVB_LIT(
" version ") + fileFirmwareVersion);
130 return availableFileDescriptions;
137 for (
size_t fileInfo = 0; fileInfo < updateFileInfoCount; fileInfo++)
141 availableFileInfos.push_back(key + CVB_LIT(
": ") + value);
143 return availableFileInfos;
151 return CVB_CALL_CAPI(
152 FWUpdate(
Handle(), deviceNM_->Handle(), updateFileSelection, &FWUpdater::EventOnDeviceReset,
this));
157 inline CExports::cvbbool_t __stdcall FWUpdater::EventOnDeviceReset(
unsigned int deviceDiscoveryTimeoutMs,
158 unsigned int deviceDiscoveryDelayMs,
159 CExports::NODEMAP &nodeMap,
void *pPrivate)
163 auto fwu =
reinterpret_cast<FWUpdater *
>(pPrivate);
173 std::chrono::system_clock::rep runTimeMs = {0};
179 for (
const auto &device : discover)
185 if (fwu->DeviceSerialNumber() == discoverSn)
193 fwu->SetDevice(std::move(dev));
194 nodeMap = fwu->deviceNM_->Handle();
201 runTimeMs = (endTime - startTime) / std::chrono::milliseconds(1);
202 }
while (runTimeMs < deviceDiscoveryTimeoutMs);
211 runTimeMs = (endTime - startTime) / std::chrono::milliseconds(1);
213 }
while (runTimeMs < deviceDiscoveryTimeoutMs);
222 inline String FWUpdater::DeviceSerialNumber() const noexcept
227 inline void FWUpdater::SetDevice(
DevicePtr &&device)
229 device_ = std::move(device);
230 deviceNM_ = device_->NodeMap(CVB_LIT(
"Device"));
231 deviceSn_ = deviceNM_->Node<StringNode>(CVB_LIT(
"DeviceSerialNumber"))->
Value();
234 inline void FWUpdater::ResetDevice()
236 deviceNM_->Node<CommandNode>(CVB_LIT(
"DeviceReset"))->Execute();
static std::vector< DiscoveryInformation > Discover()
Discovers available devices (not vins) with a default time span of 300ms.
Definition decl_device_factory.hpp:217
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
Opens a device with the given provider with its default board and port (if applicable).
Definition decl_device_factory.hpp:56
Firmware updater class.
Definition decl_fw_updater.hpp:40
std::vector< std::pair< String, String > > AvailableGufInfo()
Collects all key value pairs available in a guf file.
Definition detail_fw_updater.hpp:87
std::vector< String > UpdateFileInfos(const size_t &updateFileIndex)
Collects all information on a single update file available in a guf file.
Definition detail_fw_updater.hpp:133
std::vector< String > AvailableUpdateFiles()
Collects all mandatory update file infos available in a guf file.
Definition detail_fw_updater.hpp:108
String UpdateFileInfo(size_t fileIndex, size_t infoIndex, FirmwareUpdateInfo cmd)
Identifies a single firmware update and gets information about the firmware update as CVB::String.
Definition detail_fw_updater.hpp:66
size_t UpdateFileInfoCount(const size_t &fileIndex)
Gets the number of available update infos in a guf file.
Definition detail_fw_updater.hpp:60
static std::unique_ptr< FWUpdater > Create(const String &filename, bool verify=true)
Create a firmware updater, Validate a guf file and set the location of the guf file as CVB::String.
Definition detail_fw_updater.hpp:28
size_t UpdateFileCount()
Gets the number of available update files in a guf file.
Definition detail_fw_updater.hpp:55
static std::unique_ptr< FWUpdater > FromHandle(HandleGuard< FWUpdater > &&guard, const String &filename)
Creates a firmware updater from a classic API handle.
Definition detail_fw_updater.hpp:47
void * Handle() const noexcept
Classic API node map handle.
Definition decl_fw_updater.hpp:97
void Update(DevicePtr &&device, const size_t updateFileSelection)
Update the device.
Definition detail_fw_updater.hpp:146
@ DeviceSerialNumber
Device only : Serial number.
Definition driver.hpp:247
@ FindAll
Default flags to find all devices and vin-drivers.
Definition driver.hpp:304
Namespace for GenApi based device configuration.
Definition decl_fw_updater.hpp:29
FirmwareUpdateInfo
Defines commands to retrieve firmware information from a guf file.
Definition genapi.hpp:259
@ Value
Gets the value for an info key name.
Definition genapi.hpp:263
@ Key
Gets the key name for a given index.
Definition genapi.hpp:261
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
char Char
Character type for wide characters or unicode characters.
Definition string.hpp:63
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49
std::shared_ptr< Device > DevicePtr
Convenience shared pointer for Device.
Definition global.hpp:98