mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-11-04 12:59:07 +01:00
Add bootloader extension
This commit is contained in:
committed by
Kyle Schwarz
parent
4db27aa187
commit
6ac041cadc
@@ -93,6 +93,8 @@ void init_event(pybind11::module_& m) {
|
||||
.value("DiskFormatNotSupported", APIEvent::Type::DiskFormatNotSupported)
|
||||
.value("DiskFormatInvalidCount", APIEvent::Type::DiskFormatInvalidCount)
|
||||
.value("TC10RequestFailed", APIEvent::Type::TC10RequestFailed)
|
||||
.value("FirmwareUpdateNotSupported", APIEvent::Type::FirmwareUpdateNotSupported)
|
||||
.value("FirmwareUpdateFailed", APIEvent::Type::FirmwareUpdateFailed)
|
||||
.value("FailedToRead", APIEvent::Type::FailedToRead)
|
||||
.value("FailedToWrite", APIEvent::Type::FailedToWrite)
|
||||
.value("DriverFailedToOpen", APIEvent::Type::DriverFailedToOpen)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
#include "icsneo/device/extensions/bootloader/api.h"
|
||||
#include "icsneo/device/extensions/bootloader/parser/fwloader.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
struct BootloaderNamespace {};
|
||||
|
||||
void init_bootloader(pybind11::module_& m) {
|
||||
// Dummy class to act as Bootloader namespace
|
||||
pybind11::classh<BootloaderNamespace> bootloader(m, "Bootloader");
|
||||
|
||||
// Opaque handle returned by FWLoader.load and consumed by update
|
||||
pybind11::classh<Bootloader::FWRepo>(bootloader, "FWRepo");
|
||||
|
||||
pybind11::classh<Bootloader::FWLoader>(bootloader, "FWLoader")
|
||||
.def_static("load", &Bootloader::FWLoader::Load, pybind11::arg("path"), pybind11::call_guard<pybind11::gil_scoped_release>());
|
||||
|
||||
bootloader.def_static("update",
|
||||
[](Device& device, const Bootloader::FWRepo& fw, Bootloader::Logger logger, bool alreadyInBootloader, bool forceFlash) {
|
||||
if(!logger) {
|
||||
logger = [](Device::OpenStatusType, const std::string&, std::optional<double>) { return Device::OpenDirective::Continue; };
|
||||
}
|
||||
return Bootloader::update(device, fw, logger, alreadyInBootloader, forceFlash);
|
||||
},
|
||||
pybind11::arg("device"),
|
||||
pybind11::arg("fw"),
|
||||
pybind11::arg("logger") = pybind11::none(),
|
||||
pybind11::arg("already_in_bootloader") = false,
|
||||
pybind11::arg("force_flash") = false,
|
||||
pybind11::call_guard<pybind11::gil_scoped_release>());
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/chrono.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/device/extensions/deviceextension.h"
|
||||
@@ -12,7 +13,22 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_device(pybind11::module_& m) {
|
||||
pybind11::classh<Device>(m, "Device")
|
||||
pybind11::classh<Device> device(m, "Device");
|
||||
|
||||
pybind11::native_enum<Device::OpenDirective>(device, "OpenDirective", "enum.IntEnum")
|
||||
.value("Continue", Device::OpenDirective::Continue)
|
||||
.value("Cancel", Device::OpenDirective::Cancel)
|
||||
.value("Skip", Device::OpenDirective::Skip)
|
||||
.finalize();
|
||||
|
||||
pybind11::native_enum<Device::OpenStatusType>(device, "OpenStatusType", "enum.IntEnum")
|
||||
.value("QuestionContinueSkipCancel", Device::OpenStatusType::QuestionContinueSkipCancel)
|
||||
.value("QuestionContinueCancel", Device::OpenStatusType::QuestionContinueCancel)
|
||||
.value("Progress", Device::OpenStatusType::Progress)
|
||||
.value("Failed", Device::OpenStatusType::Failed)
|
||||
.finalize();
|
||||
|
||||
device
|
||||
.def("__repr__", &Device::describe)
|
||||
.def("add_message_callback", &Device::addMessageCallback, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("clear_script", &Device::clearScript, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
@@ -44,6 +44,9 @@ void init_idevicesettings(pybind11::module_&);
|
||||
void init_ethphymessage(pybind11::module_&);
|
||||
void init_livedata(pybind11::module_&);
|
||||
void init_livedatamessage(pybind11::module_&);
|
||||
#ifdef ICSNEO_ENABLE_BOOTLOADER
|
||||
void init_bootloader(pybind11::module_&);
|
||||
#endif
|
||||
|
||||
PYBIND11_MODULE(icsneopy, m) {
|
||||
pybind11::options options;
|
||||
@@ -88,6 +91,9 @@ PYBIND11_MODULE(icsneopy, m) {
|
||||
init_device(m);
|
||||
init_deviceextension(m);
|
||||
init_idevicesettings(m);
|
||||
#ifdef ICSNEO_ENABLE_BOOTLOADER
|
||||
init_bootloader(m);
|
||||
#endif
|
||||
|
||||
m.def("find_all_devices", &FindAllDevices);
|
||||
m.def("get_supported_devices", &GetSupportedDevices);
|
||||
|
||||
Reference in New Issue
Block a user