From acad905ea2be31aadbc28e32a90edfc826778a26 Mon Sep 17 00:00:00 2001 From: alex-luxonis Date: Fri, 23 Jul 2021 18:59:16 +0300 Subject: [PATCH 1/9] Partially revert f6173f9, add back flash_bootloader.py --- depthai-core | 2 +- examples/flash_bootloader.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100755 examples/flash_bootloader.py diff --git a/depthai-core b/depthai-core index 3df1e1319..7ce7614ec 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 3df1e13199f72dd830fa46d5e2147bda6de3fea1 +Subproject commit 7ce7614ece441d1f03b64d85976fc946b7bc51fa diff --git a/examples/flash_bootloader.py b/examples/flash_bootloader.py new file mode 100755 index 000000000..59b5a8499 --- /dev/null +++ b/examples/flash_bootloader.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +import depthai as dai +import sys +import time + +blType = dai.DeviceBootloader.Type.USB + +if len(sys.argv) > 1: + if sys.argv[1] == 'usb': + blType = dai.DeviceBootloader.Type.USB + elif sys.argv[1] == 'eth': + blType = dai.DeviceBootloader.Type.NETWORK + else: + print("Specify either 'usb' or 'eth' bootloader type") + quit() + +(res, info) = dai.DeviceBootloader.getFirstAvailableDevice() + +bl = dai.DeviceBootloader(info) +progress = lambda p : print(f'Flashing progress: {p*100:.1f}%') + +print("=== Flashing", blType.name, "bootloader...") +startTime = time.monotonic() +(res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, blType, progress) +if res: + print("Flashing successful. Took", time.monotonic() - startTime, "seconds") +else: + print("Flashing failed:", message) From b0410e916bc92656765313ea809670e4cab7e4ae Mon Sep 17 00:00:00 2001 From: alex-luxonis Date: Wed, 28 Jul 2021 20:51:03 +0300 Subject: [PATCH 2/9] Update core/bootloader --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index 7ce7614ec..92a5c0dca 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 7ce7614ece441d1f03b64d85976fc946b7bc51fa +Subproject commit 92a5c0dca19a24619f9513e29bb625be29951844 From 147a2df73c54ecd68fa65065df75cd474bde8713 Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Thu, 29 Jul 2021 05:00:25 +0200 Subject: [PATCH 3/9] Updated flash_bootloader example --- depthai-core | 2 +- examples/flash_bootloader.py | 49 +++++++++++++++++++++++--------- src/DeviceBootloaderBindings.cpp | 6 ++-- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/depthai-core b/depthai-core index 92a5c0dca..9eedc3531 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 92a5c0dca19a24619f9513e29bb625be29951844 +Subproject commit 9eedc3531d14832e98d8c1ea336e5f38dad819b9 diff --git a/examples/flash_bootloader.py b/examples/flash_bootloader.py index 59b5a8499..ef4689ca2 100755 --- a/examples/flash_bootloader.py +++ b/examples/flash_bootloader.py @@ -5,25 +5,46 @@ import time blType = dai.DeviceBootloader.Type.USB - if len(sys.argv) > 1: if sys.argv[1] == 'usb': blType = dai.DeviceBootloader.Type.USB - elif sys.argv[1] == 'eth': + elif sys.argv[1] == 'network': blType = dai.DeviceBootloader.Type.NETWORK else: - print("Specify either 'usb' or 'eth' bootloader type") - quit() + print("Specify either 'usb' or 'network' bootloader type") + exit() + +print("Warning! Flashing bootloader can potentially soft brick your device and should be done with caution.") +print("Do not unplug your device in while the bootloader is flashing.") +print("Type 'y' and press enter to proceed, otherwise exits: ") +if input() != 'y': + print("Prompt declined, exiting...") + exit(-1) + +(found, info) = dai.DeviceBootloader.getFirstAvailableDevice() +if not found: + print("No device found to flash. Exiting.") + exit(-1) -(res, info) = dai.DeviceBootloader.getFirstAvailableDevice() +# Open DeviceBootloader and allow flashing bootloader +with dai.DeviceBootloader(info, allowFlashingBootloader=True) as bl: + currentBlType = bl.getType() -bl = dai.DeviceBootloader(info) -progress = lambda p : print(f'Flashing progress: {p*100:.1f}%') + # Check if bootloader type is the same + if currentBlType != blType: + print(f"Are you sure you want to flash '{blType.name}' bootloader over current '{currentBlType.name}' bootloader?") + print(f"Type 'y' and press enter to proceed, otherwise exits: ") + if input() != 'y': + print("Prompt declined, exiting...") + exit(-1); -print("=== Flashing", blType.name, "bootloader...") -startTime = time.monotonic() -(res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, blType, progress) -if res: - print("Flashing successful. Took", time.monotonic() - startTime, "seconds") -else: - print("Flashing failed:", message) + # Create a progress callback lambda + progress = lambda p : print(f'Flashing progress: {p*100:.1f}%') + + print(f"Flashing {blType.name} bootloader...") + startTime = time.monotonic() + (res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, blType, progress) + if res: + print("Flashing successful. Took", time.monotonic() - startTime, "seconds") + else: + print("Flashing failed:", message) diff --git a/src/DeviceBootloaderBindings.cpp b/src/DeviceBootloaderBindings.cpp index 890364a30..50c7ccf5c 100644 --- a/src/DeviceBootloaderBindings.cpp +++ b/src/DeviceBootloaderBindings.cpp @@ -66,8 +66,8 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ .def_static("getEmbeddedBootloaderVersion", &DeviceBootloader::getEmbeddedBootloaderVersion, DOC(dai, DeviceBootloader, getEmbeddedBootloaderVersion)) .def_static("getEmbeddedBootloaderBinary", &DeviceBootloader::getEmbeddedBootloaderBinary, DOC(dai, DeviceBootloader, getEmbeddedBootloaderBinary)) - .def(py::init(), py::arg("deviceDesc"), DOC(dai, DeviceBootloader, DeviceBootloader)) - .def(py::init(), py::arg("deviceDesc"), py::arg("pathToCmd"), DOC(dai, DeviceBootloader, DeviceBootloader, 2)) + .def(py::init(), py::arg("devInfo"), py::arg("allowFlashingBootloader") = false, DOC(dai, DeviceBootloader, DeviceBootloader)) + .def(py::init(), py::arg("devInfo"), py::arg("pathToCmd"), py::arg("allowFlashingBootloader") = false, DOC(dai, DeviceBootloader, DeviceBootloader, 2)) .def("flash", [](DeviceBootloader& db, std::function progressCallback, Pipeline& pipeline) { py::gil_scoped_release release; return db.flash(progressCallback, pipeline); }, py::arg("progressCallback"), py::arg("pipeline"), DOC(dai, DeviceBootloader, flash)) .def("flashDepthaiApplicationPackage", [](DeviceBootloader& db, std::function progressCallback, std::vector package) { py::gil_scoped_release release; return db.flashDepthaiApplicationPackage(progressCallback, package); }, py::arg("progressCallback"), py::arg("package"), DOC(dai, DeviceBootloader, flashDepthaiApplicationPackage)) .def("flashBootloader", [](DeviceBootloader& db, std::function progressCallback, std::string path) { py::gil_scoped_release release; return db.flashBootloader(progressCallback, path); }, py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader)) @@ -76,6 +76,8 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ .def("getVersion", [](DeviceBootloader& db) { py::gil_scoped_release release; return db.getVersion(); }, DOC(dai, DeviceBootloader, getVersion)) .def("isEmbeddedVersion", &DeviceBootloader::isEmbeddedVersion, DOC(dai, DeviceBootloader, isEmbeddedVersion)) + .def("getType", &DeviceBootloader::getType, DOC(dai, DeviceBootloader, getType)) + .def("isAllowedFlashingBootloader", &DeviceBootloader::isAllowedFlashingBootloader, DOC(dai, DeviceBootloader, isAllowedFlashingBootloader)) ; } From 9420ab7785d343ee9bcdf7a7efb1a0c239c84de3 Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Thu, 29 Jul 2021 15:16:24 +0200 Subject: [PATCH 4/9] Updated core --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index 9eedc3531..08e6ad7f0 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 9eedc3531d14832e98d8c1ea336e5f38dad819b9 +Subproject commit 08e6ad7f0765340e07a0bbb846a72b4b02cb2ca7 From 5992be8988a5fbd133834db0740d6101fb9dccae Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Wed, 4 Aug 2021 19:58:32 +0200 Subject: [PATCH 5/9] Updated core and flash_bootloader example typo --- depthai-core | 2 +- examples/flash_bootloader.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/depthai-core b/depthai-core index 154203bbb..819e9e221 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 154203bbbd66cf567d2485fce4048c97c4b91dbc +Subproject commit 819e9e2211041113ed8f30f203d9ca12ba03b2cd diff --git a/examples/flash_bootloader.py b/examples/flash_bootloader.py index ef4689ca2..17ebf4797 100755 --- a/examples/flash_bootloader.py +++ b/examples/flash_bootloader.py @@ -15,7 +15,7 @@ exit() print("Warning! Flashing bootloader can potentially soft brick your device and should be done with caution.") -print("Do not unplug your device in while the bootloader is flashing.") +print("Do not unplug your device while the bootloader is flashing.") print("Type 'y' and press enter to proceed, otherwise exits: ") if input() != 'y': print("Prompt declined, exiting...") From dbd7e48aa19c46c0560aff060b756fdde18c8b84 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Tue, 17 Aug 2021 10:57:37 +0200 Subject: [PATCH 6/9] Updated flash_bootloader.py example --- depthai-core | 2 +- examples/flash_bootloader.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index f7711f909..5dc961ab5 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit f7711f9091998871e4c07d2efe7f13fab9a0e94f +Subproject commit 5dc961ab5eb8ec4feb6e351760c6f647c69f235b diff --git a/examples/flash_bootloader.py b/examples/flash_bootloader.py index 17ebf4797..d84ef1e4d 100755 --- a/examples/flash_bootloader.py +++ b/examples/flash_bootloader.py @@ -13,6 +13,9 @@ else: print("Specify either 'usb' or 'network' bootloader type") exit() +else: + print(f"Usage: {sys.argv[0]} ") + exit() print("Warning! Flashing bootloader can potentially soft brick your device and should be done with caution.") print("Do not unplug your device while the bootloader is flashing.") From e53ca51234798217ea92ecfd7480bdc2be820b2d Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sat, 21 Aug 2021 22:35:30 +0200 Subject: [PATCH 7/9] Added bindings for DeviceBootloader Config --- CMakeLists.txt | 1 + depthai-core | 2 +- examples/bootloader_configuration.py | 53 +++++ external/CMakeLists.txt | 4 +- external/pybind11_json/CMakeLists.txt | 3 + .../include/pybind11_json/pybind11_json.hpp | 223 ++++++++++++++++++ src/DeviceBootloaderBindings.cpp | 73 +++++- src/pybind11_common.hpp | 1 + 8 files changed, 355 insertions(+), 5 deletions(-) create mode 100755 examples/bootloader_configuration.py create mode 100644 external/pybind11_json/CMakeLists.txt create mode 100644 external/pybind11_json/include/pybind11_json/pybind11_json.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ad1730e14..1ebca983b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,6 +157,7 @@ target_link_libraries(${TARGET_NAME} pybind11::pybind11 depthai::core # Use non-opencv target as we use opencv-python in bindings hedley + pybind11_json ) # Find Git diff --git a/depthai-core b/depthai-core index 5dc961ab5..93df9978e 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 5dc961ab5eb8ec4feb6e351760c6f647c69f235b +Subproject commit 93df9978e301265229ca8a613a47397cf5f3dc47 diff --git a/examples/bootloader_configuration.py b/examples/bootloader_configuration.py new file mode 100755 index 000000000..17c7d0d24 --- /dev/null +++ b/examples/bootloader_configuration.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +import depthai as dai +import sys + +usage = False +read = True +clear = False +path = '' +if len(sys.argv) >= 2: + op = sys.argv[1] + if op == 'read': + read = True + elif op == 'flash': + read = False + if len(sys.argv) >= 3: + path = sys.argv[2] + elif op == 'clear': + clear = True + read = False + else: + usage = True +else: + usage = True + +if usage: + print(f'Usage: {sys.argv[0]} [read/flash/clear] [flash: path/to/config/json]') + exit(-1) + +(res, info) = dai.DeviceBootloader.getFirstAvailableDevice() + +if res: + print(f'Found device with name: {info.desc.name}'); + with dai.DeviceBootloader(info) as bl: + if read: + print('Current flashed configuration') + print(f'{bl.readConfigData()}') + else: + success = None + error = None + if clear: + (success, error) = bl.flashConfigClear() + else: + if path == '': + (success, error) = bl.flashConfig(dai.DeviceBootloader.Config()) + else: + (success, error) = bl.flashConfigFile(path) + if success: + print('Successfully flashed bootloader configuration') + else: + print(f'Error flashing bootloader configuration: {error}') +else: + print('No devices found') diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index ebc46f957..c0e240707 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,2 +1,4 @@ # Add 'hedley' library -add_subdirectory(hedley) \ No newline at end of file +add_subdirectory(hedley) +# Add 'pybind11_json' library +add_subdirectory(pybind11_json) \ No newline at end of file diff --git a/external/pybind11_json/CMakeLists.txt b/external/pybind11_json/CMakeLists.txt new file mode 100644 index 000000000..1e2842c70 --- /dev/null +++ b/external/pybind11_json/CMakeLists.txt @@ -0,0 +1,3 @@ +# pybind11_json library +add_library(pybind11_json INTERFACE) +target_include_directories(pybind11_json INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include") diff --git a/external/pybind11_json/include/pybind11_json/pybind11_json.hpp b/external/pybind11_json/include/pybind11_json/pybind11_json.hpp new file mode 100644 index 000000000..773a30cf4 --- /dev/null +++ b/external/pybind11_json/include/pybind11_json/pybind11_json.hpp @@ -0,0 +1,223 @@ +/*************************************************************************** +* Copyright (c) 2019, Martin Renou * +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#ifndef PYBIND11_JSON_HPP +#define PYBIND11_JSON_HPP + +#include +#include + +#include "nlohmann/json.hpp" + +#include "pybind11/pybind11.h" + +namespace py = pybind11; +namespace nl = nlohmann; + +namespace pyjson +{ + inline py::object from_json(const nl::json& j) + { + if (j.is_null()) + { + return py::none(); + } + else if (j.is_boolean()) + { + return py::bool_(j.get()); + } + else if (j.is_number_integer()) + { + return py::int_(j.get()); + } + else if (j.is_number_unsigned()) + { + return py::int_(j.get()); + } + else if (j.is_number_float()) + { + return py::float_(j.get()); + } + else if (j.is_string()) + { + return py::str(j.get()); + } + else if (j.is_array()) + { + py::list obj; + for (const auto& el : j) + { + obj.append(from_json(el)); + } + return std::move(obj); + } + else // Object + { + py::dict obj; + for (nl::json::const_iterator it = j.cbegin(); it != j.cend(); ++it) + { + obj[py::str(it.key())] = from_json(it.value()); + } + return std::move(obj); + } + } + + inline nl::json to_json(const py::handle& obj) + { + if (obj.ptr() == nullptr || obj.is_none()) + { + return nullptr; + } + if (py::isinstance(obj)) + { + return obj.cast(); + } + if (py::isinstance(obj)) + { + try + { + nl::json::number_integer_t s = obj.cast(); + if (py::int_(s).equal(obj)) + { + return s; + } + } + catch (...) + { + } + try + { + nl::json::number_unsigned_t u = obj.cast(); + if (py::int_(u).equal(obj)) + { + return u; + } + } + catch (...) + { + } + throw std::runtime_error("to_json received an integer out of range for both nl::json::number_integer_t and nl::json::number_unsigned_t type: " + py::repr(obj).cast()); + } + if (py::isinstance(obj)) + { + return obj.cast(); + } + if (py::isinstance(obj)) + { + py::module base64 = py::module::import("base64"); + return base64.attr("b64encode")(obj).attr("decode")("utf-8").cast(); + } + if (py::isinstance(obj)) + { + return obj.cast(); + } + if (py::isinstance(obj) || py::isinstance(obj)) + { + auto out = nl::json::array(); + for (const py::handle value : obj) + { + out.push_back(to_json(value)); + } + return out; + } + if (py::isinstance(obj)) + { + auto out = nl::json::object(); + for (const py::handle key : obj) + { + out[py::str(key).cast()] = to_json(obj[key]); + } + return out; + } + throw std::runtime_error("to_json not implemented for this type of object: " + py::repr(obj).cast()); + } +} + +// nlohmann_json serializers +namespace nlohmann +{ + #define MAKE_NLJSON_SERIALIZER_DESERIALIZER(T) \ + template <> \ + struct adl_serializer \ + { \ + inline static void to_json(json& j, const T& obj) \ + { \ + j = pyjson::to_json(obj); \ + } \ + \ + inline static T from_json(const json& j) \ + { \ + return pyjson::from_json(j); \ + } \ + } + + #define MAKE_NLJSON_SERIALIZER_ONLY(T) \ + template <> \ + struct adl_serializer \ + { \ + inline static void to_json(json& j, const T& obj) \ + { \ + j = pyjson::to_json(obj); \ + } \ + } + + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::object); + + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::bool_); + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::int_); + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::float_); + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::str); + + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::list); + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::tuple); + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::dict); + + MAKE_NLJSON_SERIALIZER_ONLY(py::handle); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::item_accessor); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::list_accessor); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::tuple_accessor); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::sequence_accessor); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::str_attr_accessor); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::obj_attr_accessor); + + #undef MAKE_NLJSON_SERIALIZER + #undef MAKE_NLJSON_SERIALIZER_ONLY +} + +// pybind11 caster +namespace pybind11 +{ + namespace detail + { + template <> struct type_caster + { + public: + PYBIND11_TYPE_CASTER(nl::json, _("json")); + + bool load(handle src, bool) + { + try { + value = pyjson::to_json(src); + return true; + } + catch (...) + { + return false; + } + } + + static handle cast(nl::json src, return_value_policy /* policy */, handle /* parent */) + { + object obj = pyjson::from_json(src); + return obj.release(); + } + }; + } +} + +#endif diff --git a/src/DeviceBootloaderBindings.cpp b/src/DeviceBootloaderBindings.cpp index 50c7ccf5c..c9c7d1bea 100644 --- a/src/DeviceBootloaderBindings.cpp +++ b/src/DeviceBootloaderBindings.cpp @@ -13,6 +13,9 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ py::enum_ deviceBootloaderType(deviceBootloader, "Type"); py::enum_ deviceBootloaderMemory(deviceBootloader, "Memory"); py::enum_ deviceBootloaderSection(deviceBootloader, "Section"); + py::class_ deviceBootlaoderUsbConfig(deviceBootloader, "UsbConfig"); + py::class_ deviceBootlaoderNetworkConfig(deviceBootloader, "NetworkConfig"); + py::class_ deviceBootloderConfig(deviceBootloader, "Config"); /////////////////////////////////////////////////////////////////////// @@ -39,20 +42,72 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ ; deviceBootloaderType + .value("AUTO", DeviceBootloader::Type::AUTO) .value("USB", DeviceBootloader::Type::USB) .value("NETWORK", DeviceBootloader::Type::NETWORK) ; deviceBootloaderMemory + .value("AUTO", DeviceBootloader::Memory::AUTO) .value("FLASH", DeviceBootloader::Memory::FLASH) .value("EMMC", DeviceBootloader::Memory::EMMC) ; deviceBootloaderSection + .value("AUTO", DeviceBootloader::Section::AUTO) .value("HEADER", DeviceBootloader::Section::HEADER) .value("BOOTLOADER", DeviceBootloader::Section::BOOTLOADER) .value("BOOTLOADER_CONFIG", DeviceBootloader::Section::BOOTLOADER_CONFIG) .value("APPLICATION", DeviceBootloader::Section::APPLICATION) ; + deviceBootlaoderUsbConfig + .def(py::init<>()) + .def_readwrite("timeoutMs", &DeviceBootloader::UsbConfig::timeoutMs) + .def_readwrite("maxUsbSpeed", &DeviceBootloader::UsbConfig::maxUsbSpeed) + .def_readwrite("vid", &DeviceBootloader::UsbConfig::vid) + .def_readwrite("pid", &DeviceBootloader::UsbConfig::pid) + ; + deviceBootlaoderNetworkConfig + .def(py::init<>()) + .def_readwrite("timeoutMs", &DeviceBootloader::NetworkConfig::timeoutMs) + .def_readwrite("ipv4", &DeviceBootloader::NetworkConfig::ipv4) + .def_readwrite("ipv4Mask", &DeviceBootloader::NetworkConfig::ipv4Mask) + .def_readwrite("ipv4Gateway", &DeviceBootloader::NetworkConfig::ipv4Gateway) + .def_readwrite("ipv4Dns", &DeviceBootloader::NetworkConfig::ipv4Dns) + .def_readwrite("ipv4DnsAlt", &DeviceBootloader::NetworkConfig::ipv4DnsAlt) + .def_readwrite("staticIpv4", &DeviceBootloader::NetworkConfig::staticIpv4) + .def_readwrite("ipv6", &DeviceBootloader::NetworkConfig::ipv6) + .def_readwrite("ipv6Prefix", &DeviceBootloader::NetworkConfig::ipv6Prefix) + .def_readwrite("ipv6Gateway", &DeviceBootloader::NetworkConfig::ipv6Gateway) + .def_readwrite("ipv6Dns", &DeviceBootloader::NetworkConfig::ipv6Dns) + .def_readwrite("ipv6DnsAlt", &DeviceBootloader::NetworkConfig::ipv6DnsAlt) + .def_readwrite("staticIpv6", &DeviceBootloader::NetworkConfig::staticIpv6) + .def_readwrite("mac", &DeviceBootloader::NetworkConfig::mac) + ; + + deviceBootloderConfig + .def(py::init<>()) + .def_readwrite("appMem", &DeviceBootloader::Config::appMem) + .def_readwrite("usb", &DeviceBootloader::Config::usb) + .def_readwrite("network", &DeviceBootloader::Config::network) + .def("setStaticIPv4", &DeviceBootloader::Config::setStaticIPv4) + .def("setDynamicIPv4", &DeviceBootloader::Config::setDynamicIPv4) + .def("isStaticIPV4", &DeviceBootloader::Config::isStaticIPV4) + .def("getIPv4", &DeviceBootloader::Config::getIPv4) + .def("getIPv4Mask", &DeviceBootloader::Config::getIPv4Mask) + .def("getIPv4Gateway", &DeviceBootloader::Config::getIPv4Gateway) + .def("setDnsIPv4", &DeviceBootloader::Config::setDnsIPv4) + .def("getDnsIPv4", &DeviceBootloader::Config::getDnsIPv4) + .def("getDnsAltIPv4", &DeviceBootloader::Config::getDnsAltIPv4) + .def("setUsbTimeout", &DeviceBootloader::Config::setUsbTimeout) + .def("getUsbTimeout", &DeviceBootloader::Config::getUsbTimeout) + .def("setNetworkTimeout", &DeviceBootloader::Config::setNetworkTimeout) + .def("getNetworkTimeout", &DeviceBootloader::Config::getNetworkTimeout) + .def("setMacAddress", &DeviceBootloader::Config::setMacAddress) + .def("getMacAddress", &DeviceBootloader::Config::getMacAddress) + .def("setUsbMaxSpeed", &DeviceBootloader::Config::setUsbMaxSpeed) + .def("getUsbMaxSpeed", &DeviceBootloader::Config::getUsbMaxSpeed) + ; + deviceBootloader // Python only methods .def("__enter__", [](py::object obj){ return obj; }) @@ -61,17 +116,29 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ .def_static("getFirstAvailableDevice", &DeviceBootloader::getFirstAvailableDevice, DOC(dai, DeviceBootloader, getFirstAvailableDevice)) .def_static("getAllAvailableDevices", &DeviceBootloader::getAllAvailableDevices, DOC(dai, DeviceBootloader, getAllAvailableDevices)) - .def_static("saveDepthaiApplicationPackage", &DeviceBootloader::saveDepthaiApplicationPackage, py::arg("path"), py::arg("pipeline"), py::arg("pathToCmd") = "", DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage)) - .def_static("createDepthaiApplicationPackage", &DeviceBootloader::createDepthaiApplicationPackage, py::arg("pipeline"), py::arg("pathToCmd") = "", DOC(dai, DeviceBootloader, createDepthaiApplicationPackage)) + .def_static("saveDepthaiApplicationPackage", py::overload_cast(&DeviceBootloader::saveDepthaiApplicationPackage), py::arg("path"), py::arg("pipeline"), py::arg("pathToCmd") = "", py::arg("compress") = false, DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage)) + .def_static("saveDepthaiApplicationPackage", py::overload_cast(&DeviceBootloader::saveDepthaiApplicationPackage), py::arg("path"), py::arg("pipeline"), py::arg("compress") = false, DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage, 2)) + .def_static("createDepthaiApplicationPackage", py::overload_cast(&DeviceBootloader::createDepthaiApplicationPackage), py::arg("pipeline"), py::arg("pathToCmd") = "", py::arg("compress") = false, DOC(dai, DeviceBootloader, createDepthaiApplicationPackage)) + .def_static("createDepthaiApplicationPackage", py::overload_cast(&DeviceBootloader::createDepthaiApplicationPackage), py::arg("pipeline"), py::arg("compress"), DOC(dai, DeviceBootloader, createDepthaiApplicationPackage, 2)) .def_static("getEmbeddedBootloaderVersion", &DeviceBootloader::getEmbeddedBootloaderVersion, DOC(dai, DeviceBootloader, getEmbeddedBootloaderVersion)) .def_static("getEmbeddedBootloaderBinary", &DeviceBootloader::getEmbeddedBootloaderBinary, DOC(dai, DeviceBootloader, getEmbeddedBootloaderBinary)) .def(py::init(), py::arg("devInfo"), py::arg("allowFlashingBootloader") = false, DOC(dai, DeviceBootloader, DeviceBootloader)) .def(py::init(), py::arg("devInfo"), py::arg("pathToCmd"), py::arg("allowFlashingBootloader") = false, DOC(dai, DeviceBootloader, DeviceBootloader, 2)) - .def("flash", [](DeviceBootloader& db, std::function progressCallback, Pipeline& pipeline) { py::gil_scoped_release release; return db.flash(progressCallback, pipeline); }, py::arg("progressCallback"), py::arg("pipeline"), DOC(dai, DeviceBootloader, flash)) + .def("flash", [](DeviceBootloader& db, std::function progressCallback, const Pipeline& pipeline, bool compress) { py::gil_scoped_release release; return db.flash(progressCallback, pipeline, compress); }, py::arg("progressCallback"), py::arg("pipeline"), py::arg("compress") = false, DOC(dai, DeviceBootloader, flash)) + .def("flash", [](DeviceBootloader& db, const Pipeline& pipeline, bool compress) { py::gil_scoped_release release; return db.flash(pipeline, compress); }, py::arg("pipeline"), py::arg("compress") = false, DOC(dai, DeviceBootloader, flash, 2)) .def("flashDepthaiApplicationPackage", [](DeviceBootloader& db, std::function progressCallback, std::vector package) { py::gil_scoped_release release; return db.flashDepthaiApplicationPackage(progressCallback, package); }, py::arg("progressCallback"), py::arg("package"), DOC(dai, DeviceBootloader, flashDepthaiApplicationPackage)) + .def("flashDepthaiApplicationPackage", [](DeviceBootloader& db, std::vector package) { py::gil_scoped_release release; return db.flashDepthaiApplicationPackage(package); }, py::arg("package"), DOC(dai, DeviceBootloader, flashDepthaiApplicationPackage, 2)) .def("flashBootloader", [](DeviceBootloader& db, std::function progressCallback, std::string path) { py::gil_scoped_release release; return db.flashBootloader(progressCallback, path); }, py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader)) .def("flashBootloader", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type, std::function progressCallback, std::string path) { py::gil_scoped_release release; return db.flashBootloader(memory, type, progressCallback, path); }, py::arg("memory"), py::arg("type"), py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader, 2)) + + .def("readConfigData", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.readConfigData(memory, type); }, py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, readConfigData)) + .def("flashConfigData", [](DeviceBootloader& db, nlohmann::json configData, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfigData(configData, memory, type); }, py::arg("configData"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfigData)) + .def("flashConfigFile", [](DeviceBootloader& db, std::string configPath, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfigFile(configPath, memory, type); }, py::arg("configData"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfigFile)) + .def("flashConfigClear", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfigClear(memory, type); }, py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfigClear)) + .def("readConfig", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.readConfig(memory, type); }, py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, readConfig)) + .def("flashConfig", [](DeviceBootloader& db, const DeviceBootloader::Config& config, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfig(config, memory, type); }, py::arg("config"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfig)) + //.def("flashCustom", &DeviceBootloader::flashCustom, py::arg("memory"), py::arg("offset"), py::arg("progressCallback"), py::arg("data"), DOC(dai, DeviceBootloader, flashCustom)) .def("getVersion", [](DeviceBootloader& db) { py::gil_scoped_release release; return db.getVersion(); }, DOC(dai, DeviceBootloader, getVersion)) diff --git a/src/pybind11_common.hpp b/src/pybind11_common.hpp index 8fbab8dd8..1669cdf40 100644 --- a/src/pybind11_common.hpp +++ b/src/pybind11_common.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include From 39871af4763a2434c091db3cd33c74aaef3816ae Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sat, 21 Aug 2021 22:35:47 +0200 Subject: [PATCH 8/9] Updated flash_bootloader example --- depthai-core | 2 +- examples/flash_bootloader.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/depthai-core b/depthai-core index 93df9978e..6a414d4c0 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 93df9978e301265229ca8a613a47397cf5f3dc47 +Subproject commit 6a414d4c081903a748a3941aed9b6f1c400cb31f diff --git a/examples/flash_bootloader.py b/examples/flash_bootloader.py index d84ef1e4d..3ea3e6077 100755 --- a/examples/flash_bootloader.py +++ b/examples/flash_bootloader.py @@ -4,7 +4,7 @@ import sys import time -blType = dai.DeviceBootloader.Type.USB +blType = dai.DeviceBootloader.Type.AUTO if len(sys.argv) > 1: if sys.argv[1] == 'usb': blType = dai.DeviceBootloader.Type.USB @@ -13,9 +13,6 @@ else: print("Specify either 'usb' or 'network' bootloader type") exit() -else: - print(f"Usage: {sys.argv[0]} ") - exit() print("Warning! Flashing bootloader can potentially soft brick your device and should be done with caution.") print("Do not unplug your device while the bootloader is flashing.") @@ -30,11 +27,12 @@ exit(-1) # Open DeviceBootloader and allow flashing bootloader +print(f"Booting latest bootloader first, will take a tad longer...") with dai.DeviceBootloader(info, allowFlashingBootloader=True) as bl: currentBlType = bl.getType() # Check if bootloader type is the same - if currentBlType != blType: + if blType != dai.DeviceBootloader.Type.AUTO and currentBlType != blType: print(f"Are you sure you want to flash '{blType.name}' bootloader over current '{currentBlType.name}' bootloader?") print(f"Type 'y' and press enter to proceed, otherwise exits: ") if input() != 'y': @@ -44,9 +42,9 @@ # Create a progress callback lambda progress = lambda p : print(f'Flashing progress: {p*100:.1f}%') - print(f"Flashing {blType.name} bootloader...") + print(f"Flashing {currentBlType.name} bootloader...") startTime = time.monotonic() - (res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, blType, progress) + (res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, currentBlType, progress) if res: print("Flashing successful. Took", time.monotonic() - startTime, "seconds") else: From 34d2993e0a371ab3057d7d1878b4a8e3511172ac Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 23 Aug 2021 05:28:44 +0200 Subject: [PATCH 9/9] Updated bindings and example name --- depthai-core | 2 +- examples/{bootloader_configuration.py => bootloader_config.py} | 0 src/DeviceBootloaderBindings.cpp | 3 +++ 3 files changed, 4 insertions(+), 1 deletion(-) rename examples/{bootloader_configuration.py => bootloader_config.py} (100%) diff --git a/depthai-core b/depthai-core index 6a414d4c0..fb57b8978 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 6a414d4c081903a748a3941aed9b6f1c400cb31f +Subproject commit fb57b897826fb7feeb99522b5c63a2350764dde5 diff --git a/examples/bootloader_configuration.py b/examples/bootloader_config.py similarity index 100% rename from examples/bootloader_configuration.py rename to examples/bootloader_config.py diff --git a/src/DeviceBootloaderBindings.cpp b/src/DeviceBootloaderBindings.cpp index c9c7d1bea..a975bc10b 100644 --- a/src/DeviceBootloaderBindings.cpp +++ b/src/DeviceBootloaderBindings.cpp @@ -139,6 +139,9 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ .def("readConfig", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.readConfig(memory, type); }, py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, readConfig)) .def("flashConfig", [](DeviceBootloader& db, const DeviceBootloader::Config& config, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfig(config, memory, type); }, py::arg("config"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfig)) + .def("bootMemory", [](DeviceBootloader& db, const std::vector& fw) { py::gil_scoped_release release; return db.bootMemory(fw); }, py::arg("fw"), DOC(dai, DeviceBootloader, bootMemory)) + .def("bootUsbRomBootloader", [](DeviceBootloader& db) { py::gil_scoped_release release; return db.bootUsbRomBootloader(); }, DOC(dai, DeviceBootloader, bootUsbRomBootloader)) + //.def("flashCustom", &DeviceBootloader::flashCustom, py::arg("memory"), py::arg("offset"), py::arg("progressCallback"), py::arg("data"), DOC(dai, DeviceBootloader, flashCustom)) .def("getVersion", [](DeviceBootloader& db) { py::gil_scoped_release release; return db.getVersion(); }, DOC(dai, DeviceBootloader, getVersion))