From 42d7accc93e2c08dd883573f32fd633f197d8809 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Tue, 23 Nov 2021 21:10:13 +0100 Subject: [PATCH 01/69] ImageManip refactor and added additional functionality --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- examples/CMakeLists.txt | 1 + examples/ImageManip/image_manip_tiling.cpp | 4 ++ examples/ImageManip/image_manip_warp_mesh.cpp | 48 +++++++++++++++++++ .../pipeline/datatype/ImageManipConfig.hpp | 6 +++ include/depthai/pipeline/node/ImageManip.hpp | 10 +++- shared/depthai-shared | 2 +- src/pipeline/datatype/ImageManipConfig.cpp | 8 ++++ src/pipeline/node/ImageManip.cpp | 15 ++++++ 9 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 examples/ImageManip/image_manip_warp_mesh.cpp diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 5b7a9c471..2e670abb1 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "7699a5479cd35532e5c6443301491541088d5549") +set(DEPTHAI_DEVICE_SIDE_COMMIT "53ec330e65aef65aac87bd072f4a88c43d635c86") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 12cf33255..c92c4639e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -180,6 +180,7 @@ dai_add_example(image_manip ImageManip/image_manip_example.cpp ON) dai_add_example(image_manip_rotate ImageManip/image_manip_rotate.cpp ON) dai_add_example(image_manip_tiling ImageManip/image_manip_tiling.cpp ON) dai_add_example(rgb_rotate_warp ImageManip/rgb_rotate_warp.cpp ON) +dai_add_example(image_manip_warp_mesh ImageManip/image_manip_warp_mesh.cpp ON) # IMU dai_add_example(imu_gyroscope_accelerometer IMU/imu_gyroscope_accelerometer.cpp ON) diff --git a/examples/ImageManip/image_manip_tiling.cpp b/examples/ImageManip/image_manip_tiling.cpp index 3617b4f1d..a76f7649c 100644 --- a/examples/ImageManip/image_manip_tiling.cpp +++ b/examples/ImageManip/image_manip_tiling.cpp @@ -18,11 +18,15 @@ int main() { // preview frame into 2 500x500 frames auto manip1 = pipeline.create(); manip1->initialConfig.setCropRect(0, 0, 0.5, 1); + // Flip functionality + manip1->initialConfig.setHorizontalFlip(true); manip1->setMaxOutputFrameSize(maxFrameSize); camRgb->preview.link(manip1->inputImage); auto manip2 = pipeline.create(); manip2->initialConfig.setCropRect(0.5, 0, 1, 1); + // Flip functionality + manip1->initialConfig.setVerticalFlip(true); manip2->setMaxOutputFrameSize(maxFrameSize); camRgb->preview.link(manip2->inputImage); diff --git a/examples/ImageManip/image_manip_warp_mesh.cpp b/examples/ImageManip/image_manip_warp_mesh.cpp new file mode 100644 index 000000000..ab20a0d5f --- /dev/null +++ b/examples/ImageManip/image_manip_warp_mesh.cpp @@ -0,0 +1,48 @@ +#include + +// Inludes common necessary includes for development using depthai library +#include "depthai/depthai.hpp" + +int main() { + using namespace std; + + // Create pipeline + dai::Pipeline pipeline; + + auto camRgb = pipeline.create(); + camRgb->setPreviewSize(1000, 500); + camRgb->setInterleaved(false); + auto maxFrameSize = camRgb->getPreviewHeight() * camRgb->getPreviewHeight() * 3; + + // Warp preview frame + auto manip1 = pipeline.create(); + // Create a custom warp mesh + dai::Point2f tl(20, 20); + dai::Point2f tr(460, 20); + dai::Point2f ml(100, 250); + dai::Point2f mr(400, 250); + dai::Point2f bl(20, 460); + dai::Point2f br(460, 460); + manip1->setWarpMesh({tl,tr,ml,mr,bl,br}, 2, 3); + + manip1->setMaxOutputFrameSize(maxFrameSize); + camRgb->preview.link(manip1->inputImage); + + auto xout1 = pipeline.create(); + xout1->setStreamName("out1"); + manip1->out.link(xout1->input); + + dai::Device device(pipeline); + auto q1 = device.getOutputQueue("out1", 8, false); + while(true) { + auto in1 = q1->get(); + if(in1) { + cv::imshow("Warped preview", in1->getCvFrame()); + } + int key = cv::waitKey(1); + if(key == 'q' || key == 'Q') return 0; + } + return 0; +} + + diff --git a/include/depthai/pipeline/datatype/ImageManipConfig.hpp b/include/depthai/pipeline/datatype/ImageManipConfig.hpp index 8d8e6c855..db4008620 100644 --- a/include/depthai/pipeline/datatype/ImageManipConfig.hpp +++ b/include/depthai/pipeline/datatype/ImageManipConfig.hpp @@ -156,6 +156,12 @@ class ImageManipConfig : public Buffer { */ void setHorizontalFlip(bool flip); + /** + * Specify vertical flip + * @param flip True to enable vertical flip, false otherwise + */ + void setVerticalFlip(bool flip); + /** * Instruct ImageManip to not remove current image from its queue and use the same for next message. * @param reuse True to enable reuse, false otherwise diff --git a/include/depthai/pipeline/node/ImageManip.hpp b/include/depthai/pipeline/node/ImageManip.hpp index a95c57258..8514ff097 100644 --- a/include/depthai/pipeline/node/ImageManip.hpp +++ b/include/depthai/pipeline/node/ImageManip.hpp @@ -55,7 +55,7 @@ class ImageManip : public Node { [[deprecated("Use 'initialConfig.setCenterCrop()' instead")]] void setCenterCrop(float ratio, float whRatio = 1.0f); [[deprecated("Use 'initialConfig.setResize()' instead")]] void setResize(int w, int h); [[deprecated("Use 'initialConfig.setResizeThumbnail()' instead")]] void setResizeThumbnail(int w, int h, int bgRed = 0, int bgGreen = 0, int bgBlue = 0); - [[deprecated("Use 'initialConfig.setFrameType()' instead")]] void setFrameType(dai::RawImgFrame::Type name); + [[deprecated("Use 'initialConfig.setFrameType()' instead")]] void setFrameType(ImgFrame::Type name); [[deprecated("Use 'initialConfig.setHorizontalFlip()' instead")]] void setHorizontalFlip(bool flip); void setKeepAspectRatio(bool keep); @@ -77,6 +77,14 @@ class ImageManip : public Node { * @param maxFrameSize Maximum frame size in bytes */ void setMaxOutputFrameSize(int maxFrameSize); + + /** + * Set a custom warp mesh + * @param meshData 2D plane of mesh points, starting from top left to bottom right + * @param width Width of mesh + * @param height Height of mesh + */ + void setWarpMesh(std::vector meshData, int width, int height); }; } // namespace node diff --git a/shared/depthai-shared b/shared/depthai-shared index eb26ac396..47c79f7db 160000 --- a/shared/depthai-shared +++ b/shared/depthai-shared @@ -1 +1 @@ -Subproject commit eb26ac3964cb9ca591a98f5143620529cdec99dd +Subproject commit 47c79f7db369610b9cec26f3179e4dfb13f29d87 diff --git a/src/pipeline/datatype/ImageManipConfig.cpp b/src/pipeline/datatype/ImageManipConfig.cpp index 31ea98de5..f81936547 100644 --- a/src/pipeline/datatype/ImageManipConfig.cpp +++ b/src/pipeline/datatype/ImageManipConfig.cpp @@ -153,6 +153,14 @@ void ImageManipConfig::setHorizontalFlip(bool flip) { cfg.formatConfig.flipHorizontal = flip; } +void ImageManipConfig::setVerticalFlip(bool flip) { + // Enable format stage + cfg.enableFormat = true; + + // Set pixel format + cfg.formatConfig.flipVertical = flip; +} + void ImageManipConfig::setReusePreviousImage(bool reuse) { cfg.reusePreviousImage = reuse; } diff --git a/src/pipeline/node/ImageManip.cpp b/src/pipeline/node/ImageManip.cpp index bb87e89db..74cd65743 100644 --- a/src/pipeline/node/ImageManip.cpp +++ b/src/pipeline/node/ImageManip.cpp @@ -72,5 +72,20 @@ void ImageManip::setMaxOutputFrameSize(int maxFrameSize) { properties.outputFrameSize = maxFrameSize; } +void ImageManip::setWarpMesh(std::vector meshData, int width, int height) { + // TODO(themarpe) - optimize + Asset asset("mesh"); + asset.alignment = 64; + asset.data = std::vector(meshData.size() * sizeof(Point2f)); + for(size_t i = 0; i < meshData.size(); i++) { + // swap x & y, to construct internal representation + reinterpret_cast(asset.data.data())[i].x = meshData[i].y; + reinterpret_cast(asset.data.data())[i].y = meshData[i].x; + } + properties.meshUri = assetManager.set(asset)->getRelativeUri(); + properties.meshWidth = width; + properties.meshHeight = height; +} + } // namespace node } // namespace dai From 3da1b89a57804c969b9394c38f1553da0643a146 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sat, 27 Nov 2021 00:53:01 +0100 Subject: [PATCH 02/69] ImageManip - fixed odd warp mesh width --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- examples/ImageManip/image_manip_warp_mesh.cpp | 38 ++++++++++++---- include/depthai/pipeline/node/ImageManip.hpp | 4 +- src/pipeline/node/ImageManip.cpp | 44 ++++++++++++++++--- 4 files changed, 71 insertions(+), 17 deletions(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 77a4a7d9a..388b5ef5a 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "b62407f092fae8ee16bcd0ad77c3ea357fcfc56c") +set(DEPTHAI_DEVICE_SIDE_COMMIT "9dce18f220f3f927be309fe7b4aa535cf897897a") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") diff --git a/examples/ImageManip/image_manip_warp_mesh.cpp b/examples/ImageManip/image_manip_warp_mesh.cpp index ab20a0d5f..170c79b4f 100644 --- a/examples/ImageManip/image_manip_warp_mesh.cpp +++ b/examples/ImageManip/image_manip_warp_mesh.cpp @@ -10,11 +10,11 @@ int main() { dai::Pipeline pipeline; auto camRgb = pipeline.create(); - camRgb->setPreviewSize(1000, 500); + camRgb->setPreviewSize(500, 500); camRgb->setInterleaved(false); - auto maxFrameSize = camRgb->getPreviewHeight() * camRgb->getPreviewHeight() * 3; + auto maxFrameSize = camRgb->getPreviewWidth() * camRgb->getPreviewHeight() * 3; - // Warp preview frame + // Warp preview frame 1 auto manip1 = pipeline.create(); // Create a custom warp mesh dai::Point2f tl(20, 20); @@ -23,26 +23,46 @@ int main() { dai::Point2f mr(400, 250); dai::Point2f bl(20, 460); dai::Point2f br(460, 460); - manip1->setWarpMesh({tl,tr,ml,mr,bl,br}, 2, 3); - + manip1->setWarpMesh({tl, tr, ml, mr, bl, br}, 2, 3); manip1->setMaxOutputFrameSize(maxFrameSize); - camRgb->preview.link(manip1->inputImage); + camRgb->preview.link(manip1->inputImage); auto xout1 = pipeline.create(); xout1->setStreamName("out1"); manip1->out.link(xout1->input); + // Warp preview frame 2 + auto manip2 = pipeline.create(); + // Create a custom warp mesh + // clang-format off + std::vector mesh2 = { + {20, 20}, {250, 100}, {460, 20}, + {100,250}, {250, 250}, {400, 250}, + {20, 480}, {250,400}, {460,480} + }; + // clang-format on + manip2->setWarpMesh(mesh2, 3, 3); + manip2->setMaxOutputFrameSize(maxFrameSize); + + camRgb->preview.link(manip2->inputImage); + auto xout2 = pipeline.create(); + xout2->setStreamName("out2"); + manip2->out.link(xout2->input); + dai::Device device(pipeline); auto q1 = device.getOutputQueue("out1", 8, false); + auto q2 = device.getOutputQueue("out2", 8, false); while(true) { auto in1 = q1->get(); if(in1) { - cv::imshow("Warped preview", in1->getCvFrame()); + cv::imshow("Warped preview 1", in1->getCvFrame()); + } + auto in2 = q2->get(); + if(in2) { + cv::imshow("Warped preview 2", in2->getCvFrame()); } int key = cv::waitKey(1); if(key == 'q' || key == 'Q') return 0; } return 0; } - - diff --git a/include/depthai/pipeline/node/ImageManip.hpp b/include/depthai/pipeline/node/ImageManip.hpp index 8514ff097..7fc88b671 100644 --- a/include/depthai/pipeline/node/ImageManip.hpp +++ b/include/depthai/pipeline/node/ImageManip.hpp @@ -22,6 +22,7 @@ class ImageManip : public Node { nlohmann::json getProperties() override; std::shared_ptr clone() override; + void setWarpMesh(const float* meshData, int numMeshPoints, int width, int height); public: std::string getName() const override; @@ -84,7 +85,8 @@ class ImageManip : public Node { * @param width Width of mesh * @param height Height of mesh */ - void setWarpMesh(std::vector meshData, int width, int height); + void setWarpMesh(const std::vector& meshData, int width, int height); + void setWarpMesh(const std::vector>& meshData, int width, int height); }; } // namespace node diff --git a/src/pipeline/node/ImageManip.cpp b/src/pipeline/node/ImageManip.cpp index 74cd65743..21fda7e3b 100644 --- a/src/pipeline/node/ImageManip.cpp +++ b/src/pipeline/node/ImageManip.cpp @@ -72,20 +72,52 @@ void ImageManip::setMaxOutputFrameSize(int maxFrameSize) { properties.outputFrameSize = maxFrameSize; } -void ImageManip::setWarpMesh(std::vector meshData, int width, int height) { +void ImageManip::setWarpMesh(const float* meshData, int numMeshPoints, int width, int height) { + if(numMeshPoints < width * height) { + throw std::invalid_argument("Not enough points provided for specified width and height"); + } + // TODO(themarpe) - optimize Asset asset("mesh"); asset.alignment = 64; - asset.data = std::vector(meshData.size() * sizeof(Point2f)); - for(size_t i = 0; i < meshData.size(); i++) { - // swap x & y, to construct internal representation - reinterpret_cast(asset.data.data())[i].x = meshData[i].y; - reinterpret_cast(asset.data.data())[i].y = meshData[i].x; + + // Align stride to 16B + constexpr auto ALIGNMENT = 16; + size_t meshStride = ((size_t)((sizeof(Point2f) * width)) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1); + // Specify final mesh size + size_t meshSize = meshStride * height; + + // Create mesh data + asset.data = std::vector(meshSize); + + // Fill out mesh points with stride + for(int i = 0; i < height; i++) { + for(int j = 0; j < width; j++) { + // get location in meshData + size_t inputMeshIndex = (i * width + j) * 2; // 2 float values per point + + // get output offset + size_t outputMeshOffset = (meshStride * i) + (j * sizeof(Point2f)); + auto& point = reinterpret_cast(asset.data.data()[outputMeshOffset]); + + // Asign reversed mesh coordinates (HW specified) + point.x = meshData[inputMeshIndex + 1]; + point.y = meshData[inputMeshIndex + 0]; + } } + properties.meshUri = assetManager.set(asset)->getRelativeUri(); properties.meshWidth = width; properties.meshHeight = height; } +void ImageManip::setWarpMesh(const std::vector& meshData, int width, int height) { + setWarpMesh(reinterpret_cast(meshData.data()), static_cast(meshData.size()), width, height); +} + +void ImageManip::setWarpMesh(const std::vector>& meshData, int width, int height) { + setWarpMesh(reinterpret_cast(meshData.data()), static_cast(meshData.size()), width, height); +} + } // namespace node } // namespace dai From 1150aecf2ae7640fa0d3e32a2ee43512b7b2a4f0 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 13 Dec 2021 17:03:35 +0100 Subject: [PATCH 03/69] Updated bootloader and added some flash related examples --- cmake/Depthai/DepthaiBootloaderConfig.cmake | 8 +- examples/CMakeLists.txt | 3 + examples/bootloader/flash_boot_header.cpp | 88 ++++++++++ examples/bootloader/read_flash_memory.cpp | 57 +++++++ examples/bootloader/write_flash_memory.cpp | 32 ++++ include/depthai/device/DeviceBootloader.hpp | 56 ++++++- shared/depthai-bootloader-shared | 2 +- src/device/DeviceBootloader.cpp | 173 ++++++++++++++++++-- 8 files changed, 402 insertions(+), 17 deletions(-) create mode 100644 examples/bootloader/flash_boot_header.cpp create mode 100644 examples/bootloader/read_flash_memory.cpp create mode 100644 examples/bootloader/write_flash_memory.cpp diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index 71dea6a0e..2892ed503 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -1,7 +1,7 @@ # Maturity level "snapshot" / "release" -set(DEPTHAI_BOOTLOADER_MATURITY "release") -#set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") +# set(DEPTHAI_BOOTLOADER_MATURITY "release") +set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" -set(DEPTHAI_BOOTLOADER_VERSION "0.0.15") -#set(DEPTHAI_BOOTLOADER_VERSION "870bec4ca0ef026ddb9c490a38dfe9d097614554") +# set(DEPTHAI_BOOTLOADER_VERSION "0.0.15") +set(DEPTHAI_BOOTLOADER_VERSION "a7300b51c7b795a8887eb6614dc48e7627f230e1") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index fce516908..dc1b8a0ab 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -148,6 +148,9 @@ dai_add_example(bootloader_version bootloader/bootloader_version.cpp ON) dai_add_example(flash_bootloader bootloader/flash_bootloader.cpp OFF) dai_add_example(bootloader_config bootloader/bootloader_config.cpp OFF) dai_add_example(poe_set_ip bootloader/poe_set_ip.cpp OFF) +dai_add_example(read_flash_memory bootloader/read_flash_memory.cpp OFF) +dai_add_example(write_flash_memory bootloader/write_flash_memory.cpp OFF) +dai_add_example(flash_boot_header bootloader/flash_boot_header.cpp OFF) # calibration dai_add_example(calibration_flash calibration/calibration_flash.cpp OFF) diff --git a/examples/bootloader/flash_boot_header.cpp b/examples/bootloader/flash_boot_header.cpp new file mode 100644 index 000000000..75a7f1ad0 --- /dev/null +++ b/examples/bootloader/flash_boot_header.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include + +#include "depthai/depthai.hpp" + +int main(int argc, char** argv) { + if(argc < 2) { + std::cout << "Usage: " << argv[0] << " [GPIO_MODE/USB_RECOVERY/NORMAL/FAST] [params]" << std::endl; + std::cout << "\tOptions:\n"; + std::cout << "\t\t" << argv[0] << " GPIO_MODE gpioModeNum" << std::endl; + std::cout << "\t\t" << argv[0] << " USB_RECOVERY" << std::endl; + std::cout << "\t\t" << argv[0] << " NORMAL [offset] [location] [dummyCycles] [frequency]" << std::endl; + std::cout << "\t\t" << argv[0] << " FAST [offset] [location] [dummyCycles] [frequency]" << std::endl; + return 0; + } + std::string mode{argv[1]}; + std::transform(mode.begin(), mode.end(), mode.begin(), ::tolower); + std::function flash; + + if(mode == "gpio_mode") { + // gpio mode header + if(argc < 3) { + std::cout << "Usage: " << argv[0] << " GPIO_MODE gpioModeNum" << std::endl; + return 0; + } + int gpioMode = std::stoi(std::string(argv[2])); + + flash = [gpioMode](dai::DeviceBootloader& bl) { bl.flashGpioModeBootHeader(dai::DeviceBootloader::Memory::FLASH, gpioMode); }; + } else if(mode == "usb_recovery") { + // usb recovery header + flash = [](dai::DeviceBootloader& bl) { bl.flashUsbRecoveryBootHeader(dai::DeviceBootloader::Memory::FLASH); }; + } else if(mode == "normal" || mode == "fast") { + if(argc != 2 && argc != 3 && argc <= 3) { + std::cout << "Usage: " << argv[0] << " NORMAL/FAST [offset] [location] [dummyCycles] [frequency]" << std::endl; + std::cout << "Usage: " << argv[0] << " NORMAL/FAST [frequency]" << std::endl; + return 0; + } + int64_t offset = -1; + int64_t location = -1; + int32_t dummyCycles = -1; + int32_t frequency = -1; + if(argc > 3) { + if(argc >= 3) { + offset = std::stoi(std::string(argv[2])); + } + if(argc >= 4) { + location = std::stoi(std::string(argv[3])); + } + if(argc >= 5) { + dummyCycles = std::stoi(std::string(argv[4])); + } + if(argc >= 6) { + frequency = std::stoi(std::string(argv[5])); + } + } else if(argc == 3) { + frequency = std::stoi(std::string(argv[2])); + } + + if(mode == "normal") { + flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) { + bl.flashBootHeader(dai::DeviceBootloader::Memory::FLASH, offset, location, dummyCycles, frequency); + }; + } else if(mode == "fast") { + flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) { + bl.flashFastBootHeader(dai::DeviceBootloader::Memory::FLASH, offset, location, dummyCycles, frequency); + }; + } + } + + // Find device and flash specified boot header + bool res = false; + dai::DeviceInfo info; + std::tie(res, info) = dai::DeviceBootloader::getFirstAvailableDevice(); + + if(res) { + std::cout << "Found device with name: " << info.desc.name << std::endl; + dai::DeviceBootloader bl(info); + // Flash the specified boot header + flash(bl); + } else { + std::cout << "No devices found" << std::endl; + } + + return 0; +} \ No newline at end of file diff --git a/examples/bootloader/read_flash_memory.cpp b/examples/bootloader/read_flash_memory.cpp new file mode 100644 index 000000000..0bd105b27 --- /dev/null +++ b/examples/bootloader/read_flash_memory.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +#include "depthai/depthai.hpp" + +int main(int argc, char** argv) { + if(argc < 3) { + std::cout << "Usage: " << argv[0] << " offset size [filename]" << std::endl; + return 0; + } + size_t offset = std::stoi(argv[1]); + size_t size = std::stoi(argv[2]); + std::string filename = ""; + if(argc == 4) { + filename = std::string{argv[3]}; + } + + // Find device and read memory + bool res = false; + dai::DeviceInfo info; + std::tie(res, info) = dai::DeviceBootloader::getFirstAvailableDevice(); + + if(res) { + std::cout << "Found device with name: " << info.desc.name << std::endl; + dai::DeviceBootloader bl(info); + + auto progress = [](float p) { std::cout << "Reading progress..." << p * 100 << "%" << std::endl; }; + + if(filename.empty()) { + std::vector data; + bl.readCustom(dai::DeviceBootloader::Memory::FLASH, offset, size, data, progress); + + size_t offset = 0; + + while(offset < data.size()) { + // Print as hex, 32B aligned + for(int i = 0; i < 32; i++) { + if(offset >= data.size()) { + break; + } + printf("%02X ", data[offset]); + offset++; + } + printf("\n"); + } + + } else { + bl.readCustom(dai::DeviceBootloader::Memory::FLASH, offset, size, filename, progress); + } + + } else { + std::cout << "No devices found" << std::endl; + } + + return 0; +} \ No newline at end of file diff --git a/examples/bootloader/write_flash_memory.cpp b/examples/bootloader/write_flash_memory.cpp new file mode 100644 index 000000000..b3895414d --- /dev/null +++ b/examples/bootloader/write_flash_memory.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +#include "depthai/depthai.hpp" + +int main(int argc, char** argv) { + if(argc < 2) { + std::cout << "Usage: " << argv[0] << " offset filename" << std::endl; + return 0; + } + size_t offset = std::stoi(argv[1]); + std::string filename{argv[2]}; + + // Find device and read memory + bool res = false; + dai::DeviceInfo info; + std::tie(res, info) = dai::DeviceBootloader::getFirstAvailableDevice(); + + if(res) { + std::cout << "Found device with name: " << info.desc.name << std::endl; + dai::DeviceBootloader bl(info); + + auto progress = [](float p) { std::cout << "Flashing progress..." << p * 100 << "%" << std::endl; }; + bl.flashCustom(dai::DeviceBootloader::Memory::FLASH, offset, filename, progress); + + } else { + std::cout << "No devices found" << std::endl; + } + + return 0; +} \ No newline at end of file diff --git a/include/depthai/device/DeviceBootloader.hpp b/include/depthai/device/DeviceBootloader.hpp index 5e07fccbf..4974323be 100644 --- a/include/depthai/device/DeviceBootloader.hpp +++ b/include/depthai/device/DeviceBootloader.hpp @@ -240,6 +240,41 @@ class DeviceBootloader { */ std::tuple flashBootloader(Memory memory, Type type, std::function progressCallback, std::string path = ""); + /** + * Flash boot header which boots same as equivalent GPIO mode would + * @param gpioMode GPIO mode equivalent + */ + std::tuple flashGpioModeBootHeader(Memory memory, int gpioMode); + + /** + * Flash USB recovery boot header. Switches to USB ROM Bootloader + * @param memory Which memory to flash the header to + */ + std::tuple flashUsbRecoveryBootHeader(Memory memory); + + /** + * Flash optimized boot header + * @param memory Which memory to flasht the header to + * @param offset Offset in memory to flash the header to. Defaults to offset of boot header + * @param location Target location the header should boot to. Default to location of bootloader + * @param dummyCycles SPI specific parameter + * @param frequency SPI specific parameter, frequency in MHz + * @return std::tuple + */ + std::tuple flashBootHeader(Memory memory, int64_t offset = -1, int64_t location = -1, int32_t dummyCycles = -1, int32_t frequency = -1); + + /** + * Flash fast boot header. Application must already be present in flash, or location must be specified manually. + * Note - Can soft brick your device if firmware location changes. + * @param memory Which memory to flash the header to + * @param offset Offset in memory to flash the header to. Defaults to offset of boot header + * @param location Target location the header should boot to. Default to location of bootloader + * @param dummyCycles SPI specific parameter + * @param frequency SPI specific parameter, frequency in MHz + */ + std::tuple flashFastBootHeader( + Memory memory, int64_t offset = -1, int64_t location = -1, int32_t dummyCycles = -1, int32_t frequency = -1); + /** * Flash arbitrary data at custom offset in specified memory * @param memory Memory to flash @@ -247,7 +282,22 @@ class DeviceBootloader { * @param progressCallback Callback that sends back a value between 0..1 which signifies current flashing progress * @param data Data to flash */ - // std::tuple flashCustom(Memory memory, uint32_t offset, std::function progressCb, std::vector data); + std::tuple flashCustom(Memory memory, size_t offset, const std::vector& data, std::function progressCb = nullptr); + std::tuple flashCustom(Memory memory, size_t offset, const uint8_t* data, size_t size, std::function progressCb = nullptr); + std::tuple flashCustom(Memory memory, size_t offset, std::string filename, std::function progressCb = nullptr); + + /** + * Reads arbitrary data at custom offset in specified memory + * @param memory Memory to read + * @param offset Offset at which to read the specified bytes + * @param size Number of bytes to read + * @param progressCallback Callback that sends back a value between 0..1 which signifies current reading progress + * @param data Data to read to. Must be atleast 'size' number of bytes big + */ + std::tuple readCustom( + Memory memory, size_t offset, size_t size, std::vector& data, std::function progressCb = nullptr); + std::tuple readCustom(Memory memory, size_t offset, size_t size, uint8_t* data, std::function progressCb = nullptr); + std::tuple readCustom(Memory memory, size_t offset, size_t size, std::string filename, std::function progressCb = nullptr); /** * Reads configuration data from bootloader @@ -356,6 +406,10 @@ class DeviceBootloader { template bool receiveResponse(T& response); Version requestVersion(); + std::tuple flashCustom( + Memory memory, size_t offset, const uint8_t* data, size_t size, std::string filename, std::function progressCb); + std::tuple readCustom( + Memory memory, size_t offset, size_t size, uint8_t* data, std::string filename, std::function progressCb); // private variables std::shared_ptr connection; diff --git a/shared/depthai-bootloader-shared b/shared/depthai-bootloader-shared index 126f34415..a89cf177d 160000 --- a/shared/depthai-bootloader-shared +++ b/shared/depthai-bootloader-shared @@ -1 +1 @@ -Subproject commit 126f344155346836a6a2d67b0993c161b6b48729 +Subproject commit a89cf177d577d55f6932b5d924211f3cf03b72d7 diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index 507df4710..4749da828 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -622,8 +622,92 @@ std::tuple DeviceBootloader::flashBootloader(Memory memory, T return {result.success, result.errorMsg}; } -/* TODO(themarpe) -std::tuple DeviceBootloader::flashCustom(Memory memory, uint32_t offset, std::function progressCb, std::vector data) { +std::tuple DeviceBootloader::flashGpioModeBootHeader(Memory memory, int gpioMode) { + // TODO(themarpe) - use memory param + (void)memory; + + Request::UpdateFlashBootHeader updateBootHeader; + updateBootHeader.type = Request::UpdateFlashBootHeader::GPIO_MODE; + updateBootHeader.gpioMode = gpioMode; + + // Send & Get response + if(!sendRequest(updateBootHeader)) return {false, "Couldn't send request to flash boot header"}; + Response::FlashComplete resp = {}; + receiveResponse(resp); + return {resp.success, resp.errorMsg}; +} + +std::tuple DeviceBootloader::flashUsbRecoveryBootHeader(Memory memory) { + // TODO(themarpe) - use memory param + (void)memory; + + Request::UpdateFlashBootHeader updateBootHeader; + updateBootHeader.type = Request::UpdateFlashBootHeader::USB_RECOVERY; + + // Send & Get response + if(!sendRequest(updateBootHeader)) return {false, "Couldn't send request to flash boot header"}; + Response::FlashComplete resp = {}; + receiveResponse(resp); + return {resp.success, resp.errorMsg}; +} + +std::tuple DeviceBootloader::flashBootHeader(Memory memory, int64_t offset, int64_t location, int32_t dummyCycles, int32_t frequency) { + // TODO(themarpe) - use memory param + (void)memory; + + Request::UpdateFlashBootHeader updateBootHeader; + updateBootHeader.type = Request::UpdateFlashBootHeader::NORMAL; + updateBootHeader.offset = offset; + updateBootHeader.location = location; + updateBootHeader.dummyCycles = dummyCycles; + updateBootHeader.frequency = frequency; + + // Send & Get response + if(!sendRequest(updateBootHeader)) return {false, "Couldn't send request to flash boot header"}; + Response::FlashComplete resp = {}; + receiveResponse(resp); + return {resp.success, resp.errorMsg}; +} + +std::tuple DeviceBootloader::flashFastBootHeader(Memory memory, int64_t offset, int64_t location, int32_t dummyCycles, int32_t frequency) { + // TODO(themarpe) - use memory param + (void)memory; + + Request::UpdateFlashBootHeader updateBootHeader; + updateBootHeader.type = Request::UpdateFlashBootHeader::FAST; + updateBootHeader.offset = offset; + updateBootHeader.location = location; + updateBootHeader.dummyCycles = dummyCycles; + updateBootHeader.frequency = frequency; + + // Send & Get response + if(!sendRequest(updateBootHeader)) return {false, "Couldn't send request to flash boot header"}; + Response::FlashComplete resp = {}; + receiveResponse(resp); + return {resp.success, resp.errorMsg}; +} + +std::tuple DeviceBootloader::flashCustom(Memory memory, + size_t offset, + const std::vector& data, + std::function progressCb) { + if(data.size() == 0) { + throw std::invalid_argument("Size to flash is zero"); + } + return flashCustom(memory, offset, data.data(), data.size(), "", progressCb); +} +std::tuple DeviceBootloader::flashCustom( + Memory memory, size_t offset, const uint8_t* data, size_t size, std::function progressCb) { + if(data == nullptr || size == 0) { + throw std::invalid_argument("Data is nullptr or size is zero"); + } + return flashCustom(memory, offset, data, size, "", progressCb); +} +std::tuple DeviceBootloader::flashCustom(Memory memory, size_t offset, std::string filename, std::function progressCb) { + return flashCustom(memory, offset, nullptr, 0, filename, progressCb); +} +std::tuple DeviceBootloader::flashCustom( + Memory memory, size_t offset, const uint8_t* data, size_t size, std::string filename, std::function progressCb) { // Only flash memory is supported for now if(memory != Memory::FLASH) { throw std::invalid_argument("Only FLASH memory is supported for now"); @@ -632,19 +716,25 @@ std::tuple DeviceBootloader::flashCustom(Memory memory, uint3 std::runtime_error("Current bootloader version doesn't support custom flashing"); } - // get streamId - streamId_t streamId = stream->getStreamId(); + std::vector optFileData; + if(!filename.empty()) { + // Read file into memory first + std::ifstream stream(filename, std::ios::in | std::ios::binary); + optFileData = std::vector(std::istreambuf_iterator(stream), {}); + data = optFileData.data(); + size = optFileData.size(); + } // send request to FLASH BOOTLOADER Request::UpdateFlashEx2 updateFlashEx2; updateFlashEx2.memory = memory; - updateFlashEx2.offset = offset; - updateFlashEx2.totalSize = static_cast(data.size()); - updateFlashEx2.numPackets = ((static_cast(data.size()) - 1) / bootloader::XLINK_STREAM_MAX_SIZE) + 1; + updateFlashEx2.offset = static_cast(offset); + updateFlashEx2.totalSize = static_cast(size); + updateFlashEx2.numPackets = ((static_cast(size) - 1) / bootloader::XLINK_STREAM_MAX_SIZE) + 1; if(!sendRequest(updateFlashEx2)) return {false, "Couldn't send bootloader flash request"}; // After that send numPackets of data - stream->writeSplit(data.data(), data.size(), bootloader::XLINK_STREAM_MAX_SIZE); + stream->writeSplit(data, size, bootloader::XLINK_STREAM_MAX_SIZE); // Then wait for response by bootloader // Wait till FLASH_COMPLETE response @@ -654,13 +744,13 @@ std::tuple DeviceBootloader::flashCustom(Memory memory, uint3 if(!receiveResponseData(data)) return {false, "Couldn't receive bootloader response"}; Response::FlashStatusUpdate update; - if(parseBootloaderResponse(data, update)) { + if(parseResponse(data, update)) { // if progress callback is set if(progressCb != nullptr) { progressCb(update.progress); } // if flash complete response arrived, break from while loop - } else if(parseBootloaderResponse(data, result)) { + } else if(parseResponse(data, result)) { break; } else { // Unknown response, shouldn't happen @@ -672,7 +762,68 @@ std::tuple DeviceBootloader::flashCustom(Memory memory, uint3 // Return if flashing was successful return {result.success, result.errorMsg}; } -*/ + +std::tuple DeviceBootloader::readCustom( + Memory memory, size_t offset, size_t size, std::vector& data, std::function progressCb) { + // Resize container if not too small + if(data.size() < size) { + data.resize(size); + } + return readCustom(memory, offset, size, data.data(), "", progressCb); +} +std::tuple DeviceBootloader::readCustom(Memory memory, size_t offset, size_t size, uint8_t* data, std::function progressCb) { + return readCustom(memory, offset, size, data, "", progressCb); +} +std::tuple DeviceBootloader::readCustom( + Memory memory, size_t offset, size_t size, std::string filename, std::function progressCb) { + return readCustom(memory, offset, size, nullptr, filename, progressCb); +} + +std::tuple DeviceBootloader::readCustom( + Memory memory, size_t offset, size_t size, uint8_t* data, std::string filename, std::function progressCb) { + // Only flash memory is supported for now + if(memory != Memory::FLASH) { + throw std::invalid_argument("Only FLASH memory is supported for now"); + } + + // send request to Read Flash + Request::ReadFlash readFlash; + readFlash.memory = memory; + readFlash.offset = static_cast(offset); + readFlash.totalSize = static_cast(size); + if(!sendRequest(readFlash)) return {false, "Couldn't send bootloader flash request"}; + + // Then wait for response by bootloader + Response::ReadFlash response; + receiveResponse(response); + // If error + if(!response.success) { + return {false, std::string(response.errorMsg)}; + } + + // Read numPackets of data + if(filename.empty()) { + // Read to buffer + size_t dataOffset = 0; + for(unsigned i = 0; i < response.numPackets; i++) { + auto d = stream->read(); + memcpy(data + dataOffset, d.data(), d.size()); + dataOffset += d.size(); + if(progressCb) progressCb((1.0f / response.numPackets) * (i + 1)); + } + } else { + // Write to file + std::ofstream outputFile(filename); + for(unsigned i = 0; i < response.numPackets; i++) { + auto d = stream->read(); + outputFile.write(reinterpret_cast(d.data()), d.size()); + if(progressCb) progressCb((1.0f / response.numPackets) * (i + 1)); + } + } + + // Return if flashing was successful + return {response.success, response.errorMsg}; +} nlohmann::json DeviceBootloader::readConfigData(Memory memory, Type type) { // Send request to GET_BOOTLOADER_CONFIG From 7b0e4f38bf6f09f4e6ff964641658c0fbd617ee9 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 20 Dec 2021 02:45:50 +0100 Subject: [PATCH 04/69] ImageManip setResize crop fix --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 388b5ef5a..34b114a32 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "9dce18f220f3f927be309fe7b4aa535cf897897a") +set(DEPTHAI_DEVICE_SIDE_COMMIT "27bc51a1b85d1ce7354aca1e062d7fda1ecfe4fa") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From abe0aad49327d9b5865008efe0d2d6650b75d1ac Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sun, 20 Feb 2022 22:36:44 +0100 Subject: [PATCH 05/69] Added capability to clear flashed application --- cmake/Depthai/DepthaiBootloaderConfig.cmake | 2 +- include/depthai/device/DeviceBootloader.hpp | 9 ++++++++- src/device/DeviceBootloader.cpp | 18 ++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index ff985bb9c..81538a5cf 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -4,4 +4,4 @@ set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" # set(DEPTHAI_BOOTLOADER_VERSION "0.0.17") -set(DEPTHAI_BOOTLOADER_VERSION "2822dce4c81964645b0ad9228cb550bf57a80ed1") +set(DEPTHAI_BOOTLOADER_VERSION "bc0a5cce2f422dbc961ec427efab4a330a9ee2e1") diff --git a/include/depthai/device/DeviceBootloader.hpp b/include/depthai/device/DeviceBootloader.hpp index 0587c453b..f22257b5c 100644 --- a/include/depthai/device/DeviceBootloader.hpp +++ b/include/depthai/device/DeviceBootloader.hpp @@ -224,6 +224,12 @@ class DeviceBootloader { */ std::tuple flashDepthaiApplicationPackage(std::vector package); + /** + * Clears flashed application on the device, by removing SBR boot structure + * Doesnt remove fast boot header capability to still boot the application + */ + std::tuple flashClear(); + /** * Flashes bootloader to the current board * @param progressCallback Callback that sends back a value between 0..1 which signifies current flashing progress @@ -291,13 +297,14 @@ class DeviceBootloader { * @param memory Memory to read * @param offset Offset at which to read the specified bytes * @param size Number of bytes to read - * @param progressCallback Callback that sends back a value between 0..1 which signifies current reading progress * @param data Data to read to. Must be atleast 'size' number of bytes big + * @param progressCallback Callback that sends back a value between 0..1 which signifies current reading progress */ std::tuple readCustom( Memory memory, size_t offset, size_t size, std::vector& data, std::function progressCb = nullptr); std::tuple readCustom(Memory memory, size_t offset, size_t size, uint8_t* data, std::function progressCb = nullptr); std::tuple readCustom(Memory memory, size_t offset, size_t size, std::string filename, std::function progressCb = nullptr); + std::tuple> readCustom(Memory memory, size_t offset, size_t size, std::function progressCb = nullptr); /** * Reads configuration data from bootloader diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index 6138a5d71..4d529777d 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -510,10 +510,10 @@ std::tuple DeviceBootloader::flash(const Pipeline& pipeline, } std::tuple DeviceBootloader::flashDepthaiApplicationPackage(std::function progressCb, std::vector package) { - // Bug in NETWORK bootloader in version 0.0.12 < 0.1.0 - flashing can cause a soft brick + // Bug in NETWORK bootloader in version 0.0.12 < 0.0.14 - flashing can cause a soft brick auto version = getVersion(); if(bootloaderType == Type::NETWORK && version < Version(0, 0, 14)) { - throw std::invalid_argument("Network bootloader requires version 0.1.0 or higher to flash applications. Current version: " + version.toString()); + throw std::invalid_argument("Network bootloader requires version 0.0.14 or higher to flash applications. Current version: " + version.toString()); } // send request to FLASH BOOTLOADER @@ -558,6 +558,14 @@ std::tuple DeviceBootloader::flashDepthaiApplicationPackage(s return flashDepthaiApplicationPackage(nullptr, package); } +std::tuple DeviceBootloader::flashClear() { + std::vector clear; + for(size_t i = 0; i < SBR_RAW_SIZE; i++){ + clear.push_back(0xFF); + } + return flashCustom(Memory::FLASH, bootloader::getStructure(getType()).offset.at(Section::APPLICATION), clear); +} + std::tuple DeviceBootloader::flashBootloader(std::function progressCb, std::string path) { return flashBootloader(Memory::FLASH, bootloaderType, progressCb, path); } @@ -797,6 +805,12 @@ std::tuple DeviceBootloader::readCustom( Memory memory, size_t offset, size_t size, std::string filename, std::function progressCb) { return readCustom(memory, offset, size, nullptr, filename, progressCb); } +std::tuple> DeviceBootloader::readCustom( + Memory memory, size_t offset, size_t size, std::function progressCb) { + std::vector data; + auto ret = readCustom(memory, offset, size, data, progressCb); + return {std::get<0>(ret), std::get<1>(ret), data}; +} std::tuple DeviceBootloader::readCustom( Memory memory, size_t offset, size_t size, uint8_t* data, std::string filename, std::function progressCb) { From 1c2b305d313880a310fba20914d54ebb69cf0f62 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sun, 20 Feb 2022 22:47:02 +0100 Subject: [PATCH 06/69] Applied style --- src/device/DeviceBootloader.cpp | 8 +++++--- tests/src/multiple_devices_test.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index 4d529777d..23d2b530c 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -560,7 +560,7 @@ std::tuple DeviceBootloader::flashDepthaiApplicationPackage(s std::tuple DeviceBootloader::flashClear() { std::vector clear; - for(size_t i = 0; i < SBR_RAW_SIZE; i++){ + for(size_t i = 0; i < SBR_RAW_SIZE; i++) { clear.push_back(0xFF); } return flashCustom(Memory::FLASH, bootloader::getStructure(getType()).offset.at(Section::APPLICATION), clear); @@ -805,8 +805,10 @@ std::tuple DeviceBootloader::readCustom( Memory memory, size_t offset, size_t size, std::string filename, std::function progressCb) { return readCustom(memory, offset, size, nullptr, filename, progressCb); } -std::tuple> DeviceBootloader::readCustom( - Memory memory, size_t offset, size_t size, std::function progressCb) { +std::tuple> DeviceBootloader::readCustom(Memory memory, + size_t offset, + size_t size, + std::function progressCb) { std::vector data; auto ret = readCustom(memory, offset, size, data, progressCb); return {std::get<0>(ret), std::get<1>(ret), data}; diff --git a/tests/src/multiple_devices_test.cpp b/tests/src/multiple_devices_test.cpp index fc33bcc90..6457bd558 100644 --- a/tests/src/multiple_devices_test.cpp +++ b/tests/src/multiple_devices_test.cpp @@ -1,7 +1,7 @@ #include #include -#include #include +#include // Inludes common necessary includes for development using depthai library #include "depthai/depthai.hpp" From bda897075b844750b6d0b0f0bf9d089c12c078b4 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 21 Feb 2022 13:15:15 +0100 Subject: [PATCH 07/69] Fixed not throwing a created exception --- src/device/DeviceBootloader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index 23d2b530c..98ec5b36f 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -738,7 +738,7 @@ std::tuple DeviceBootloader::flashCustom( throw std::invalid_argument("Only FLASH memory is supported for now"); } if(getVersion() < Version(0, 0, 12)) { - std::runtime_error("Current bootloader version doesn't support custom flashing"); + throw std::runtime_error("Current bootloader version doesn't support custom flashing"); } std::vector optFileData; From d36cee0286ba51ba0246dbf5ee93cb625547a527 Mon Sep 17 00:00:00 2001 From: OanaMariaVatavu Date: Fri, 18 Mar 2022 13:27:30 +0200 Subject: [PATCH 08/69] Update FW - [ImageManip][bug fix] Properly align the maximum size of the calculated parameters for the warp filter --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 2419112a4..fea502e4b 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "6852cf545fd02003cf106f58fe3a1ad464f5ad34") +set(DEPTHAI_DEVICE_SIDE_COMMIT "35d2c8c5f2b082326334c982d54ae16908f1315d") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From ae77410cd0254f66e8188cf1753b11c52a35c586 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Fri, 1 Apr 2022 16:04:19 +0200 Subject: [PATCH 09/69] Added additional BL requests and fixed BL versioning --- cmake/Depthai/DepthaiBootloaderConfig.cmake | 2 +- .../rgb_depth_confidence_aligned.cpp | 5 +- examples/bootloader/bootloader_version.cpp | 21 ++ include/depthai/device/DeviceBootloader.hpp | 64 ++++- shared/depthai-bootloader-shared | 2 +- src/device/DeviceBootloader.cpp | 242 +++++++++++++++--- tests/CMakeLists.txt | 3 + tests/src/bootloader_version_test.cpp | 78 ++++++ 8 files changed, 369 insertions(+), 48 deletions(-) create mode 100644 tests/src/bootloader_version_test.cpp diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index 81538a5cf..2fe21eb57 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -4,4 +4,4 @@ set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" # set(DEPTHAI_BOOTLOADER_VERSION "0.0.17") -set(DEPTHAI_BOOTLOADER_VERSION "bc0a5cce2f422dbc961ec427efab4a330a9ee2e1") +set(DEPTHAI_BOOTLOADER_VERSION "0.0.18+ee0c1c3b0f69888c9f69aa8afcc143c512bfb40d") diff --git a/examples/StereoDepth/rgb_depth_confidence_aligned.cpp b/examples/StereoDepth/rgb_depth_confidence_aligned.cpp index 33745c8a3..b606f8a63 100644 --- a/examples/StereoDepth/rgb_depth_confidence_aligned.cpp +++ b/examples/StereoDepth/rgb_depth_confidence_aligned.cpp @@ -143,12 +143,11 @@ int main() { float sumWeight = rgbWeight + depthWeight + confWeight; // Normalize the weights so their sum to be <= 1.0 - if (sumWeight <= 1.0) { + if(sumWeight <= 1.0) { rgbWeightNorm = rgbWeight; depthWeightNorm = depthWeight; confWeightNorm = confWeight; - } - else { + } else { rgbWeightNorm = rgbWeight / sumWeight; depthWeightNorm = depthWeight / sumWeight; confWeightNorm = confWeight / sumWeight; diff --git a/examples/bootloader/bootloader_version.cpp b/examples/bootloader/bootloader_version.cpp index 8b3056173..67bdd5227 100644 --- a/examples/bootloader/bootloader_version.cpp +++ b/examples/bootloader/bootloader_version.cpp @@ -9,6 +9,27 @@ int main(int argc, char** argv) { std::cout << "Found device with name: " << info.desc.name << std::endl; dai::DeviceBootloader bl(info); std::cout << "Version: " << bl.getVersion().toString() << std::endl; + + bool ok; + std::string err; + dai::DeviceBootloader::ApplicationInfo info; + std::tie(ok, err, info) = bl.readApplicationInfo(); + if(ok) { + std::cout << "Application, flashed: " << info.hasApplication << " firmware version: " << info.firmwareVersion + << " application name: " << info.applicationName << std::endl; + } else { + std::cout << "Error reading application infomation: " << err << std::endl; + } + + for(const auto& mem : {dai::DeviceBootloader::Memory::FLASH, dai::DeviceBootloader::Memory::EMMC}) { + dai::DeviceBootloader::MemoryInfo info; + std::tie(ok, err, info) = bl.getMemoryInfo(mem); + if(ok) { + std::cout << "Memory size: " << info.size << ", info: " << info.info << std::endl; + } else { + std::cout << "Error retrieving memory information: " << err << std::endl; + } + } } else { std::cout << "No devices found" << std::endl; } diff --git a/include/depthai/device/DeviceBootloader.hpp b/include/depthai/device/DeviceBootloader.hpp index f22257b5c..d0ba783b3 100644 --- a/include/depthai/device/DeviceBootloader.hpp +++ b/include/depthai/device/DeviceBootloader.hpp @@ -83,6 +83,8 @@ class DeviceBootloader { explicit Version(const std::string& v); /// Construct Version major, minor and patch numbers Version(unsigned major, unsigned minor, unsigned patch); + /// Construct Version major, minor and patch numbers with buildInfo + Version(unsigned major, unsigned minor, unsigned patch, std::string buildInfo); bool operator==(const Version& other) const; bool operator<(const Version& other) const; inline bool operator!=(const Version& rhs) const { @@ -99,9 +101,27 @@ class DeviceBootloader { } /// Convert Version to string std::string toString() const; + /// Convert Version to semver string + std::string toStringSemver() const; + /// Get build info + std::string getBuildInfo() const; + /// Retrieves semver version (no build information) + Version getSemver() const; private: unsigned versionMajor, versionMinor, versionPatch; + std::string buildInfo; + }; + + struct ApplicationInfo { + bool hasApplication; + std::string firmwareVersion; + std::string applicationName; + }; + + struct MemoryInfo { + std::int64_t size; + std::string info; }; // constants @@ -127,17 +147,22 @@ class DeviceBootloader { * @param pipeline Pipeline from which to create the application package * @param pathToCmd Optional path to custom device firmware * @param compress Optional boolean which specifies if contents should be compressed + * @param applicationName Optional name the application that is flashed * @returns Depthai application package */ - static std::vector createDepthaiApplicationPackage(const Pipeline& pipeline, std::string pathToCmd = "", bool compress = false); + static std::vector createDepthaiApplicationPackage(const Pipeline& pipeline, + std::string pathToCmd = "", + bool compress = false, + std::string applicationName = ""); /** * Creates application package which can be flashed to depthai device. * @param pipeline Pipeline from which to create the application package * @param compress Specifies if contents should be compressed + * @param applicationName Name the application that is flashed * @returns Depthai application package */ - static std::vector createDepthaiApplicationPackage(const Pipeline& pipeline, bool compress); + static std::vector createDepthaiApplicationPackage(const Pipeline& pipeline, bool compress, std::string applicationName = ""); /** * Saves application package to a file which can be flashed to depthai device. @@ -145,16 +170,19 @@ class DeviceBootloader { * @param pipeline Pipeline from which to create the application package * @param pathToCmd Optional path to custom device firmware * @param compress Optional boolean which specifies if contents should be compressed + * @param applicationName Optional name the application that is flashed */ - static void saveDepthaiApplicationPackage(std::string path, const Pipeline& pipeline, std::string pathToCmd = "", bool compress = false); + static void saveDepthaiApplicationPackage( + std::string path, const Pipeline& pipeline, std::string pathToCmd = "", bool compress = false, std::string applicationName = ""); /** * Saves application package to a file which can be flashed to depthai device. * @param path Path where to save the application package * @param pipeline Pipeline from which to create the application package * @param compress Specifies if contents should be compressed + * @param applicationName Optional name the application that is flashed */ - static void saveDepthaiApplicationPackage(std::string path, const Pipeline& pipeline, bool compress); + static void saveDepthaiApplicationPackage(std::string path, const Pipeline& pipeline, bool compress, std::string applicationName = ""); /** * @returns Embedded bootloader version @@ -202,14 +230,26 @@ class DeviceBootloader { * Flashes a given pipeline to the device. * @param progressCallback Callback that sends back a value between 0..1 which signifies current flashing progress * @param pipeline Pipeline to flash to the board + * @param compress Compresses application to reduce needed memory size + * @param applicationName Name the application that is flashed */ - std::tuple flash(std::function progressCallback, const Pipeline& pipeline, bool compress = false); + std::tuple flash(std::function progressCallback, + const Pipeline& pipeline, + bool compress = false, + std::string applicationName = ""); /** * Flashes a given pipeline to the device. * @param pipeline Pipeline to flash to the board + * @param compress Compresses application to reduce needed memory size + * @param applicationName Optional name the application that is flashed + */ + std::tuple flash(const Pipeline& pipeline, bool compress = false, std::string applicationName = ""); + + /** + * Reads flashed application information from device */ - std::tuple flash(const Pipeline& pipeline, bool compress = false); + std::tuple readApplicationInfo(); /** * Flashes a specific depthai application package that was generated using createDepthaiApplicationPackage or saveDepthaiApplicationPackage @@ -228,7 +268,7 @@ class DeviceBootloader { * Clears flashed application on the device, by removing SBR boot structure * Doesnt remove fast boot header capability to still boot the application */ - std::tuple flashClear(); + std::tuple flashClear(Memory memory = Memory::AUTO); /** * Flashes bootloader to the current board @@ -353,6 +393,12 @@ class DeviceBootloader { */ std::tuple flashConfig(const Config& config, Memory memory = Memory::AUTO, Type type = Type::AUTO); + /** + * Retrieves information about specified memory + * @param memory Specifies which memory to query + */ + std::tuple getMemoryInfo(Memory memory); + /** * Boots a custom FW in memory * @param fw @@ -407,11 +453,15 @@ class DeviceBootloader { void checkClosed() const; template bool sendRequest(const T& request); + template + void sendRequestThrow(const T& request); bool receiveResponseData(std::vector& data); template bool parseResponse(const std::vector& data, T& response); template bool receiveResponse(T& response); + template + void receiveResponseThrow(T& response); Version requestVersion(); std::tuple flashCustom( Memory memory, size_t offset, const uint8_t* data, size_t size, std::string filename, std::function progressCb); diff --git a/shared/depthai-bootloader-shared b/shared/depthai-bootloader-shared index 5ffae3a4b..74f2cb1a5 160000 --- a/shared/depthai-bootloader-shared +++ b/shared/depthai-bootloader-shared @@ -1 +1 @@ -Subproject commit 5ffae3a4b0274fbd66ddc8582ad31997db0c1c53 +Subproject commit 74f2cb1a5383e31d2e9f81add45edfb578908b83 diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index 98ec5b36f..da10dcb64 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -65,7 +65,10 @@ std::vector DeviceBootloader::getAllAvailableDevices() { return availableDevices; } -std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pipeline& pipeline, std::string pathToCmd, bool compress) { +std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pipeline& pipeline, + std::string pathToCmd, + bool compress, + std::string applicationName) { // Serialize the pipeline PipelineSchema schema; Assets assets; @@ -94,12 +97,17 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip utility::serialize(schema, pipelineBinary); utility::serialize(assets, assetsBinary); + // Prepare FW version buffer + std::string fwVersionBuffer{DEPTHAI_DEVICE_VERSION}; + // Prepare SBR structure SBR sbr = {}; SBR_SECTION* fwSection = &sbr.sections[0]; - SBR_SECTION* pipelineSection = &sbr.sections[1]; - SBR_SECTION* assetsSection = &sbr.sections[2]; - SBR_SECTION* assetStorageSection = &sbr.sections[3]; + SBR_SECTION* fwVersionSection = &sbr.sections[1]; + SBR_SECTION* appNameSection = &sbr.sections[2]; + SBR_SECTION* pipelineSection = &sbr.sections[3]; + SBR_SECTION* assetsSection = &sbr.sections[4]; + SBR_SECTION* assetStorageSection = &sbr.sections[5]; SBR_SECTION* lastSection = assetStorageSection; // Alignup for easier updating @@ -155,19 +163,31 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip sbr_section_set_compression(fwSection, SBR_NO_COMPRESSION); } - // Second section, pipeline schema, name 'pipeline' + // Second section, firmware version + sbr_section_set_name(fwVersionSection, "__fw_version"); + sbr_section_set_size(fwVersionSection, static_cast(fwVersionBuffer.size())); + sbr_section_set_checksum(fwVersionSection, sbr_compute_checksum(fwVersionBuffer.data(), static_cast(fwVersionBuffer.size()))); + sbr_section_set_offset(fwVersionSection, getSectionAlignedOffset(fwSection->offset + fwSection->size)); + + // Third section, application name + sbr_section_set_name(appNameSection, "app_name"); + sbr_section_set_size(appNameSection, static_cast(applicationName.size())); + sbr_section_set_checksum(appNameSection, sbr_compute_checksum(applicationName.data(), static_cast(applicationName.size()))); + sbr_section_set_offset(appNameSection, getSectionAlignedOffset(fwVersionSection->offset + fwVersionSection->size)); + + // Fourth section, pipeline schema, name 'pipeline' sbr_section_set_name(pipelineSection, "pipeline"); sbr_section_set_size(pipelineSection, static_cast(pipelineBinary.size())); sbr_section_set_checksum(pipelineSection, sbr_compute_checksum(pipelineBinary.data(), static_cast(pipelineBinary.size()))); - sbr_section_set_offset(pipelineSection, getSectionAlignedOffset(fwSection->offset + fwSection->size)); + sbr_section_set_offset(pipelineSection, getSectionAlignedOffset(appNameSection->offset + appNameSection->size)); - // Third section, assets map, name 'assets' + // Fifth section, assets map, name 'assets' sbr_section_set_name(assetsSection, "assets"); sbr_section_set_size(assetsSection, static_cast(assetsBinary.size())); sbr_section_set_checksum(assetsSection, sbr_compute_checksum(assetsBinary.data(), static_cast(assetsBinary.size()))); sbr_section_set_offset(assetsSection, getSectionAlignedOffset(pipelineSection->offset + pipelineSection->size)); - // Fourth section, asset storage, name 'asset_storage' + // Sixth section, asset storage, name 'asset_storage' sbr_section_set_name(assetStorageSection, "asset_storage"); sbr_section_set_size(assetStorageSection, static_cast(assetStorage.size())); sbr_section_set_checksum(assetStorageSection, sbr_compute_checksum(assetStorage.data(), static_cast(assetStorage.size()))); @@ -184,25 +204,37 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip // Write to fwPackage for(std::size_t i = 0; i < deviceFirmware.size(); i++) fwPackage[fwSection->offset + i] = deviceFirmware[i]; + for(std::size_t i = 0; i < fwVersionBuffer.size(); i++) fwPackage[fwVersionSection->offset + i] = fwVersionBuffer[i]; + for(std::size_t i = 0; i < applicationName.size(); i++) fwPackage[appNameSection->offset + i] = applicationName[i]; for(std::size_t i = 0; i < pipelineBinary.size(); i++) fwPackage[pipelineSection->offset + i] = pipelineBinary[i]; for(std::size_t i = 0; i < assetsBinary.size(); i++) fwPackage[assetsSection->offset + i] = assetsBinary[i]; for(std::size_t i = 0; i < assetStorage.size(); i++) fwPackage[assetStorageSection->offset + i] = assetStorage[i]; + // Debug + if(spdlog::get_level() == spdlog::level::debug) { + SBR_SECTION* cur = &sbr.sections[0]; + spdlog::debug("DepthAI Application Package"); + for(; cur != lastSection; cur++) { + spdlog::debug("{}, {}B, {}, {}, {}, {}", cur->name, cur->size, cur->offset, cur->checksum, cur->type, cur->flags); + } + } + return fwPackage; } -std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pipeline& pipeline, bool compress) { - return createDepthaiApplicationPackage(pipeline, "", compress); +std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pipeline& pipeline, bool compress, std::string applicationName) { + return createDepthaiApplicationPackage(pipeline, "", compress, applicationName); } -void DeviceBootloader::saveDepthaiApplicationPackage(std::string path, const Pipeline& pipeline, std::string pathToCmd, bool compress) { - auto dap = createDepthaiApplicationPackage(pipeline, pathToCmd, compress); +void DeviceBootloader::saveDepthaiApplicationPackage( + std::string path, const Pipeline& pipeline, std::string pathToCmd, bool compress, std::string applicationName) { + auto dap = createDepthaiApplicationPackage(pipeline, pathToCmd, compress, applicationName); std::ofstream outfile(path, std::ios::binary); outfile.write(reinterpret_cast(dap.data()), dap.size()); } -void DeviceBootloader::saveDepthaiApplicationPackage(std::string path, const Pipeline& pipeline, bool compress) { - auto dap = createDepthaiApplicationPackage(pipeline, compress); +void DeviceBootloader::saveDepthaiApplicationPackage(std::string path, const Pipeline& pipeline, bool compress, std::string applicationName) { + auto dap = createDepthaiApplicationPackage(pipeline, compress, applicationName); std::ofstream outfile(path, std::ios::binary); outfile.write(reinterpret_cast(dap.data()), dap.size()); } @@ -427,6 +459,12 @@ void DeviceBootloader::init(bool embeddedMvcmd, const std::string& pathToMvcmd, // Sleep a bit, so device isn't available anymore std::this_thread::sleep_for(std::chrono::milliseconds(500)); }); + + // Bootloader device ready, check for version + spdlog::debug("Connected bootloader version {}", version.toString()); + if(getEmbeddedBootloaderVersion() > version) { + spdlog::info("New bootloader version available. Device has: {}, available: {}", version.toString(), getEmbeddedBootloaderVersion().toString()); + } } void DeviceBootloader::close() { @@ -478,7 +516,7 @@ DeviceBootloader::Version DeviceBootloader::getVersion() const { } DeviceBootloader::Version DeviceBootloader::requestVersion() { - // Send request to jump to USB bootloader + // Send request to retrieve bootloader version if(!sendRequest(Request::GetBootloaderVersion{})) { throw std::runtime_error("Couldn't get bootloader version"); } @@ -486,11 +524,26 @@ DeviceBootloader::Version DeviceBootloader::requestVersion() { // Receive response Response::BootloaderVersion ver; if(!receiveResponse(ver)) { - throw std::runtime_error("Couldn't get bootloader version"); + throw std::runtime_error("Couldn't parse version response"); } - // Create bootloader::Version object and return - return DeviceBootloader::Version(ver.major, ver.minor, ver.patch); + Version blVersion(ver.major, ver.minor, ver.patch); + + if(blVersion >= Version(Request::GetBootloaderCommit::VERSION)) { + // Send request to retrieve bootloader commit (skip version check) + Request::GetBootloaderCommit request{}; + stream->write((uint8_t*)&request, sizeof(request)); + + // Receive response + Response::BootloaderCommit commit; + if(!receiveResponse(commit)) { + throw std::runtime_error("Couldn't get bootloader commit"); + } + + blVersion = Version(ver.major, ver.minor, ver.patch, commit.commitStr); + } + + return blVersion; } DeviceBootloader::Type DeviceBootloader::getType() const { @@ -501,12 +554,61 @@ bool DeviceBootloader::isAllowedFlashingBootloader() const { return allowFlashingBootloader; } -std::tuple DeviceBootloader::flash(std::function progressCb, const Pipeline& pipeline, bool compress) { - return flashDepthaiApplicationPackage(progressCb, createDepthaiApplicationPackage(pipeline, compress)); +std::tuple DeviceBootloader::flash(std::function progressCb, + const Pipeline& pipeline, + bool compress, + std::string applicationName) { + return flashDepthaiApplicationPackage(progressCb, createDepthaiApplicationPackage(pipeline, compress, applicationName)); } -std::tuple DeviceBootloader::flash(const Pipeline& pipeline, bool compress) { - return flashDepthaiApplicationPackage(createDepthaiApplicationPackage(pipeline, compress)); +std::tuple DeviceBootloader::flash(const Pipeline& pipeline, bool compress, std::string applicationName) { + return flashDepthaiApplicationPackage(createDepthaiApplicationPackage(pipeline, compress, applicationName)); +} + +std::tuple DeviceBootloader::readApplicationInfo() { + // Send request to retrieve bootloader version + sendRequestThrow(Request::GetApplicationDetails{}); + + // Receive response + Response::ApplicationDetails details; + receiveResponseThrow(details); + + // Set default values + ApplicationInfo info; + info.firmwareVersion = ""; + info.applicationName = ""; + + // Fill out details + info.hasApplication = details.hasApplication; + if(details.hasFirmwareVersion) { + info.firmwareVersion = std::string(details.firmwareVersionStr); + } + if(details.hasApplicationName) { + info.applicationName = std::string(details.applicationNameStr); + } + + if(details.success) { + return {true, "", info}; + } else { + return {false, details.errorMsg, info}; + } +} + +std::tuple DeviceBootloader::getMemoryInfo(Memory memory) { + // Send request to retrieve bootloader version + Request::GetMemoryDetails req{}; + req.memory = memory; + sendRequestThrow(req); + + // Receive response + Response::MemoryDetails details; + receiveResponseThrow(details); + + MemoryInfo mem; + mem.size = details.memorySize; + mem.info = std::string(details.memoryInfo); + + return {true, "", mem}; } std::tuple DeviceBootloader::flashDepthaiApplicationPackage(std::function progressCb, std::vector package) { @@ -558,12 +660,12 @@ std::tuple DeviceBootloader::flashDepthaiApplicationPackage(s return flashDepthaiApplicationPackage(nullptr, package); } -std::tuple DeviceBootloader::flashClear() { +std::tuple DeviceBootloader::flashClear(Memory memory) { std::vector clear; for(size_t i = 0; i < SBR_RAW_SIZE; i++) { clear.push_back(0xFF); } - return flashCustom(Memory::FLASH, bootloader::getStructure(getType()).offset.at(Section::APPLICATION), clear); + return flashCustom(memory, bootloader::getStructure(getType()).offset.at(Section::APPLICATION), clear); } std::tuple DeviceBootloader::flashBootloader(std::function progressCb, std::string path) { @@ -873,19 +975,20 @@ nlohmann::json DeviceBootloader::readConfigData(Memory memory, Type type) { // leaves as default values, which correspond to AUTO } - if(!sendRequest(getConfigReq)) return {false, "Couldn't send request to get configuration data"}; + sendRequestThrow(getConfigReq); // Get response Response::GetBootloaderConfig resp; resp.success = 0; // TODO remove these inits after fix https://github.com/luxonis/depthai-bootloader-shared/issues/4 - if(receiveResponse(resp) && resp.success) { + receiveResponseThrow(resp); + if(resp.success) { // Read back bootloader config (1 packet max) auto bsonConfig = stream->read(); // Parse from BSON return nlohmann::json::from_bson(bsonConfig); } else { - return {}; + throw std::runtime_error(resp.errorMsg); } } @@ -1007,27 +1110,44 @@ std::vector DeviceBootloader::getEmbeddedBootloaderBinary(Type typ return Resources::getInstance().getBootloaderFirmware(type); } -DeviceBootloader::Version::Version(const std::string& v) : versionMajor(0), versionMinor(0), versionPatch(0) { +DeviceBootloader::Version::Version(const std::string& v) : versionMajor(0), versionMinor(0), versionPatch(0), buildInfo{""} { // Parse string - if(std::sscanf(v.c_str(), "%u.%u.%u", &versionMajor, &versionMinor, &versionPatch) != 3) throw std::runtime_error("Cannot parse version: " + v); + char buffer[256]{0}; + if(std::sscanf(v.c_str(), "%u.%u.%u+%255s", &versionMajor, &versionMinor, &versionPatch, buffer) != 4) { + if(std::sscanf(v.c_str(), "%u.%u.%u", &versionMajor, &versionMinor, &versionPatch) != 3) { + throw std::runtime_error("Cannot parse version: " + v); + } + } else { + buildInfo = std::string{buffer}; + } } -DeviceBootloader::Version::Version(unsigned vmajor, unsigned vminor, unsigned vpatch) : versionMajor(vmajor), versionMinor(vminor), versionPatch(vpatch) {} +DeviceBootloader::Version::Version(unsigned vmajor, unsigned vminor, unsigned vpatch) + : versionMajor(vmajor), versionMinor(vminor), versionPatch(vpatch), buildInfo{""} {} + +DeviceBootloader::Version::Version(unsigned vmajor, unsigned vminor, unsigned vpatch, std::string buildInfo) + : versionMajor(vmajor), versionMinor(vminor), versionPatch(vpatch), buildInfo(buildInfo) {} bool DeviceBootloader::Version::operator==(const Version& other) const { - if(versionMajor == other.versionMajor && versionMinor == other.versionMinor && versionPatch == other.versionPatch) return true; + if(versionMajor == other.versionMajor && versionMinor == other.versionMinor && versionPatch == other.versionPatch && buildInfo == other.buildInfo) { + return true; + } return false; } bool DeviceBootloader::Version::operator<(const Version& other) const { if(versionMajor < other.versionMajor) { return true; - } else { + } else if(versionMajor == other.versionMajor) { if(versionMinor < other.versionMinor) { return true; - } else { + } else if(versionMinor == other.versionMinor) { if(versionPatch < other.versionPatch) { return true; + } else if(versionPatch == other.versionPatch) { + if(!buildInfo.empty() && other.buildInfo.empty()) { + return true; + } } } } @@ -1035,15 +1155,32 @@ bool DeviceBootloader::Version::operator<(const Version& other) const { } std::string DeviceBootloader::Version::toString() const { - return std::to_string(versionMajor) + "." + std::to_string(versionMinor) + "." + std::to_string(versionPatch); + std::string version = std::to_string(versionMajor) + "." + std::to_string(versionMinor) + "." + std::to_string(versionPatch); + if(!buildInfo.empty()) { + version += "+" + buildInfo; + } + return version; +} + +std::string DeviceBootloader::Version::toStringSemver() const { + std::string version = std::to_string(versionMajor) + "." + std::to_string(versionMinor) + "." + std::to_string(versionPatch); + return version; +} + +std::string DeviceBootloader::Version::getBuildInfo() const { + return buildInfo; +} + +DeviceBootloader::Version DeviceBootloader::Version::getSemver() const { + return Version(versionMajor, versionMinor, versionPatch); } template bool DeviceBootloader::sendRequest(const T& request) { if(stream == nullptr) return false; - // Do a version check beforehand - if(getVersion() < Version(T::VERSION)) { + // Do a version check beforehand (compare just the semver) + if(getVersion().getSemver() < Version(T::VERSION)) { throw std::runtime_error( fmt::format("Bootloader version {} required to send request '{}'. Current version {}", T::VERSION, T::NAME, getVersion().toString())); } @@ -1057,6 +1194,23 @@ bool DeviceBootloader::sendRequest(const T& request) { return true; } +template +void DeviceBootloader::sendRequestThrow(const T& request) { + if(stream == nullptr) throw std::runtime_error("Couldn't send request. Stream is null"); + + // Do a version check beforehand (compare just the semver) + if(getVersion().getSemver() < Version(T::VERSION)) { + throw std::runtime_error( + fmt::format("Bootloader version {} required to send request '{}'. Current version {}", T::VERSION, T::NAME, getVersion().toString())); + } + + try { + stream->write((uint8_t*)&request, sizeof(T)); + } catch(const std::exception&) { + throw std::runtime_error("Couldn't send " + std::string(T::NAME) + " request"); + } +} + bool DeviceBootloader::receiveResponseData(std::vector& data) { if(stream == nullptr) return false; @@ -1091,6 +1245,22 @@ bool DeviceBootloader::receiveResponse(T& response) { return true; } +template +void DeviceBootloader::receiveResponseThrow(T& response) { + if(stream == nullptr) throw std::runtime_error("Couldn't receive response. Stream is null"); + + // Receive data first + std::vector data; + if(!receiveResponseData(data)) { + throw std::runtime_error("Couldn't receive " + std::string(T::NAME) + " response"); + } + + // Then try to parse + if(!parseResponse(data, response)) { + throw std::runtime_error("Couldn't parse " + std::string(T::NAME) + " response"); + } +} + // Config functions void DeviceBootloader::Config::setStaticIPv4(std::string ip, std::string mask, std::string gateway) { network.ipv4 = platform::getIPv4AddressAsBinary(ip); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 044a55e63..c3362bb60 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -165,3 +165,6 @@ dai_add_test(serialization_test src/serialization_test.cpp) # Multiple devices test dai_add_test(multiple_devices_test src/multiple_devices_test.cpp) + +# Bootloader version tests +dai_add_test(bootloader_version_test src/bootloader_version_test.cpp) \ No newline at end of file diff --git a/tests/src/bootloader_version_test.cpp b/tests/src/bootloader_version_test.cpp new file mode 100644 index 000000000..0e1976241 --- /dev/null +++ b/tests/src/bootloader_version_test.cpp @@ -0,0 +1,78 @@ +#define CATCH_CONFIG_MAIN +#include + +// std +#include + +// Include depthai library +#include + +using Version = dai::DeviceBootloader::Version; + +TEST_CASE("Version parsing") { + // Okay versions + { + std::string str = "1.2.3"; + Version v(0, 0, 0); + REQUIRE_NOTHROW(v = Version{str}); + REQUIRE(v.toString() == str); + } + { + std::string str = "4.2.0+c137116638a96d2145ff091235de854890ed56ae"; + Version v(0, 0, 0); + REQUIRE_NOTHROW(v = Version{str}); + REQUIRE(v.toString() == str); + } + + // Wrong versions + // REQUIRE_THROWS(dai::DeviceBootloader::Version("1.2.3.7+abcdef")); + REQUIRE_THROWS(Version("1.7+abcdef")); + REQUIRE_THROWS(Version("1..7+abcdef")); + REQUIRE_THROWS(Version("1..7")); + REQUIRE_THROWS(Version("1..7abcd")); +} + +TEST_CASE("Version comparisons") { + REQUIRE(Version("0.0.15+abcdef") < Version("0.0.16")); + REQUIRE(Version("0.0.15+abcdef") < Version("0.0.15")); + REQUIRE(Version("0.0.14") < Version("0.0.15")); + REQUIRE(Version("0.0.14") < Version("0.0.15+abcdef")); + REQUIRE(Version("0.0.7") < Version("0.0.15+abcdef")); + REQUIRE(Version("0.0.15+abcdef") < Version("0.1.0")); + + REQUIRE(Version("0.0.16") > Version("0.0.15+abcdef")); + REQUIRE(Version("0.0.15") > Version("0.0.15+abcdef")); + REQUIRE(Version("0.0.15") > Version("0.0.14")); + REQUIRE(Version("0.0.15+abcdef") > Version("0.0.14")); + REQUIRE(Version("0.0.15+abcdef") > Version("0.0.7")); + REQUIRE(Version("0.1.0") > Version("0.0.15+abcdef")); + + REQUIRE_FALSE(Version("0.0.15+abcdef") > Version("0.0.16")); + REQUIRE_FALSE(Version("0.0.15+abcdef") > Version("0.0.15")); + REQUIRE_FALSE(Version("0.0.14") > Version("0.0.15")); + REQUIRE_FALSE(Version("0.0.14") > Version("0.0.15+abcdef")); + REQUIRE_FALSE(Version("0.0.7") > Version("0.0.15+abcdef")); + REQUIRE_FALSE(Version("0.0.15+abcdef") > Version("0.1.0")); + REQUIRE_FALSE(Version("1.2.3") > Version("1.2.3")); + + REQUIRE_FALSE(Version("0.0.16") < Version("0.0.15+abcdef")); + REQUIRE_FALSE(Version("0.0.15") < Version("0.0.15+abcdef")); + REQUIRE_FALSE(Version("0.0.15") < Version("0.0.14")); + REQUIRE_FALSE(Version("0.0.15+abcdef") < Version("0.0.14")); + REQUIRE_FALSE(Version("0.0.15+abcdef") < Version("0.0.7")); + REQUIRE_FALSE(Version("0.1.0") < Version("0.0.15+abcdef")); + REQUIRE_FALSE(Version(0, 0, 18, "ee0c1c3b0f69888c9f69aa8afcc143c512bfb40d") < Version(0, 0, 12)); + REQUIRE_FALSE(Version("1.2.3") < Version("1.2.3")); + + REQUIRE(Version("0.0.15") == Version("0.0.15")); + REQUIRE(Version("22.7.15") == Version(22, 7, 15)); + REQUIRE(Version("0.7.15") == Version(0, 7, 15)); + REQUIRE(Version("0.7.15+abc123") == Version(0, 7, 15, "abc123")); + REQUIRE(Version("0.7.15+abc123") == Version("0.7.15+abc123")); + + REQUIRE_FALSE(Version("0.0.15") == Version("0.0.14")); + REQUIRE_FALSE(Version("1.0.15") == Version("0.1.15")); + REQUIRE_FALSE(Version("1.0.15") == Version("1.0.14")); + REQUIRE_FALSE(Version("1.0.15") == Version("1.0.14+abc123")); + REQUIRE_FALSE(Version("1.0.15") == Version("0.0.15+abc123")); +} \ No newline at end of file From 93e13ee60e9df3c3650201d5225666aa80a091c0 Mon Sep 17 00:00:00 2001 From: OanaMariaVatavu Date: Fri, 1 Apr 2022 19:35:16 +0300 Subject: [PATCH 10/69] Update FW - [ImageManip][bug fix][setCropRotatedRect] Adding a fix for the case when the center of the rectangle crop is very close to the image border --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index fea502e4b..56e83d065 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "35d2c8c5f2b082326334c982d54ae16908f1315d") +set(DEPTHAI_DEVICE_SIDE_COMMIT "69f4a4f521e5f3029d30582a5e6ad4352340d12a") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From 7916045efe131ea97814e6a57f4078a0888b2431 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sat, 2 Apr 2022 17:02:20 +0200 Subject: [PATCH 11/69] WIP: Adding support for selecting which memory to flash the application to --- include/depthai/device/DeviceBootloader.hpp | 8 +- src/device/DeviceBootloader.cpp | 84 +++++++++++---------- 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/include/depthai/device/DeviceBootloader.hpp b/include/depthai/device/DeviceBootloader.hpp index d0ba783b3..263fd5cbd 100644 --- a/include/depthai/device/DeviceBootloader.hpp +++ b/include/depthai/device/DeviceBootloader.hpp @@ -236,7 +236,7 @@ class DeviceBootloader { std::tuple flash(std::function progressCallback, const Pipeline& pipeline, bool compress = false, - std::string applicationName = ""); + std::string applicationName = "", Memory memory = Memory::AUTO); /** * Flashes a given pipeline to the device. @@ -244,7 +244,7 @@ class DeviceBootloader { * @param compress Compresses application to reduce needed memory size * @param applicationName Optional name the application that is flashed */ - std::tuple flash(const Pipeline& pipeline, bool compress = false, std::string applicationName = ""); + std::tuple flash(const Pipeline& pipeline, bool compress = false, std::string applicationName = "", Memory memory = Memory::AUTO); /** * Reads flashed application information from device @@ -256,13 +256,13 @@ class DeviceBootloader { * @param progressCallback Callback that sends back a value between 0..1 which signifies current flashing progress * @param package Depthai application package to flash to the board */ - std::tuple flashDepthaiApplicationPackage(std::function progressCallback, std::vector package); + std::tuple flashDepthaiApplicationPackage(std::function progressCallback, std::vector package, Memory memory = Memory::AUTO); /** * Flashes a specific depthai application package that was generated using createDepthaiApplicationPackage or saveDepthaiApplicationPackage * @param package Depthai application package to flash to the board */ - std::tuple flashDepthaiApplicationPackage(std::vector package); + std::tuple flashDepthaiApplicationPackage(std::vector package, Memory memory = Memory::AUTO); /** * Clears flashed application on the device, by removing SBR boot structure diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index da10dcb64..9170ee16b 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -557,12 +557,12 @@ bool DeviceBootloader::isAllowedFlashingBootloader() const { std::tuple DeviceBootloader::flash(std::function progressCb, const Pipeline& pipeline, bool compress, - std::string applicationName) { - return flashDepthaiApplicationPackage(progressCb, createDepthaiApplicationPackage(pipeline, compress, applicationName)); + std::string applicationName, Memory memory) { + return flashDepthaiApplicationPackage(progressCb, createDepthaiApplicationPackage(pipeline, compress, applicationName), memory); } -std::tuple DeviceBootloader::flash(const Pipeline& pipeline, bool compress, std::string applicationName) { - return flashDepthaiApplicationPackage(createDepthaiApplicationPackage(pipeline, compress, applicationName)); +std::tuple DeviceBootloader::flash(const Pipeline& pipeline, bool compress, std::string applicationName, Memory memory) { + return flashDepthaiApplicationPackage(createDepthaiApplicationPackage(pipeline, compress, applicationName), memory); } std::tuple DeviceBootloader::readApplicationInfo() { @@ -611,53 +611,61 @@ std::tuple DeviceBootloader::ge return {true, "", mem}; } -std::tuple DeviceBootloader::flashDepthaiApplicationPackage(std::function progressCb, std::vector package) { +std::tuple DeviceBootloader::flashDepthaiApplicationPackage(std::function progressCb, std::vector package, Memory memory) { // Bug in NETWORK bootloader in version 0.0.12 < 0.0.14 - flashing can cause a soft brick auto version = getVersion(); if(bootloaderType == Type::NETWORK && version < Version(0, 0, 14)) { throw std::invalid_argument("Network bootloader requires version 0.0.14 or higher to flash applications. Current version: " + version.toString()); } - // send request to FLASH BOOTLOADER - Request::UpdateFlash updateFlash; - updateFlash.storage = Request::UpdateFlash::SBR; - updateFlash.totalSize = static_cast(package.size()); - updateFlash.numPackets = ((static_cast(package.size()) - 1) / bootloader::XLINK_STREAM_MAX_SIZE) + 1; - if(!sendRequest(updateFlash)) return {false, "Couldn't send bootloader flash request"}; + if(memory == Memory::AUTO) { - // After that send numPackets of data - stream->writeSplit(package.data(), package.size(), bootloader::XLINK_STREAM_MAX_SIZE); - - // Then wait for response by bootloader - // Wait till FLASH_COMPLETE response - Response::FlashComplete result; - result.success = 0; // TODO remove these inits after fix https://github.com/luxonis/depthai-bootloader-shared/issues/4 - result.errorMsg[0] = 0; - do { - std::vector data; - if(!receiveResponseData(data)) return {false, "Couldn't receive bootloader response"}; + // send request to FLASH BOOTLOADER + Request::UpdateFlash updateFlash; + updateFlash.storage = Request::UpdateFlash::SBR; + updateFlash.totalSize = static_cast(package.size()); + updateFlash.numPackets = ((static_cast(package.size()) - 1) / bootloader::XLINK_STREAM_MAX_SIZE) + 1; + if(!sendRequest(updateFlash)) return {false, "Couldn't send bootloader flash request"}; - Response::FlashStatusUpdate update; - if(parseResponse(data, update)) { - // if progress callback is set - if(progressCb != nullptr) { - progressCb(update.progress); + // After that send numPackets of data + stream->writeSplit(package.data(), package.size(), bootloader::XLINK_STREAM_MAX_SIZE); + + // Then wait for response by bootloader + // Wait till FLASH_COMPLETE response + Response::FlashComplete result; + result.success = 0; // TODO remove these inits after fix https://github.com/luxonis/depthai-bootloader-shared/issues/4 + result.errorMsg[0] = 0; + do { + std::vector data; + if(!receiveResponseData(data)) return {false, "Couldn't receive bootloader response"}; + + Response::FlashStatusUpdate update; + if(parseResponse(data, update)) { + // if progress callback is set + if(progressCb != nullptr) { + progressCb(update.progress); + } + } else if(parseResponse(data, result)) { + break; + } else { + // Unknown response, shouldn't happen + return {false, "Unknown response from bootloader while flashing"}; } - } else if(parseResponse(data, result)) { - break; - } else { - // Unknown response, shouldn't happen - return {false, "Unknown response from bootloader while flashing"}; - } - } while(true); + } while(true); + + // Return if flashing was successful + return {result.success, result.errorMsg}; + + } else { + // Flash custom + return flashCustom(memory, bootloader::getStructure(getType()).offset.at(Section::APPLICATION), package, progressCb); + } - // Return if flashing was successful - return {result.success, result.errorMsg}; } -std::tuple DeviceBootloader::flashDepthaiApplicationPackage(std::vector package) { - return flashDepthaiApplicationPackage(nullptr, package); +std::tuple DeviceBootloader::flashDepthaiApplicationPackage(std::vector package, Memory memory) { + return flashDepthaiApplicationPackage(nullptr, package, memory); } std::tuple DeviceBootloader::flashClear(Memory memory) { From 2440f986428efcc3a441b16791773f78a1929c3a Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Wed, 6 Apr 2022 16:53:27 +0200 Subject: [PATCH 12/69] Removed custom flash read write limitations --- src/device/DeviceBootloader.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index 9170ee16b..a7f748a51 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -843,10 +843,10 @@ std::tuple DeviceBootloader::flashCustom(Memory memory, size_ } std::tuple DeviceBootloader::flashCustom( Memory memory, size_t offset, const uint8_t* data, size_t size, std::string filename, std::function progressCb) { - // Only flash memory is supported for now - if(memory != Memory::FLASH) { - throw std::invalid_argument("Only FLASH memory is supported for now"); - } + // // Only flash memory is supported for now + // if(memory != Memory::FLASH) { + // throw std::invalid_argument("Only FLASH memory is supported for now"); + // } if(getVersion() < Version(0, 0, 12)) { throw std::runtime_error("Current bootloader version doesn't support custom flashing"); } @@ -926,10 +926,10 @@ std::tuple> DeviceBootloader::readCustom std::tuple DeviceBootloader::readCustom( Memory memory, size_t offset, size_t size, uint8_t* data, std::string filename, std::function progressCb) { - // Only flash memory is supported for now - if(memory != Memory::FLASH) { - throw std::invalid_argument("Only FLASH memory is supported for now"); - } + // // Only flash memory is supported for now + // if(memory != Memory::FLASH) { + // throw std::invalid_argument("Only FLASH memory is supported for now"); + // } // send request to Read Flash Request::ReadFlash readFlash; From 950d1167972fe8f8dc6b44cf211bbd911e1fa9c6 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Wed, 6 Apr 2022 18:52:02 +0200 Subject: [PATCH 13/69] Updated bootloader and device FW --- cmake/Depthai/DepthaiBootloaderConfig.cmake | 2 +- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index 2fe21eb57..e442f788b 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -4,4 +4,4 @@ set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" # set(DEPTHAI_BOOTLOADER_VERSION "0.0.17") -set(DEPTHAI_BOOTLOADER_VERSION "0.0.18+ee0c1c3b0f69888c9f69aa8afcc143c512bfb40d") +set(DEPTHAI_BOOTLOADER_VERSION "0.0.18+89b003e0ed2f8929a7c2e9625c479cfc19321cd0") diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 0be772904..148795950 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "afe8d00c868344c73ee897e26278f80a444b9763") +set(DEPTHAI_DEVICE_SIDE_COMMIT "eaaa7b2234e07961225f1e259150bb3b5894c1d8") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From b5e05bae81abc35f6365a92c7d95b541eaf5e25e Mon Sep 17 00:00:00 2001 From: OanaMariaVatavu Date: Thu, 14 Apr 2022 22:53:19 +0300 Subject: [PATCH 14/69] Update FW - [ImageManip] Adding support for input/output GRAY8 format --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index aef3879a0..3ddcab50a 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "391ede37d1b55aa3dac727f58ff99aac7d2865dc") +set(DEPTHAI_DEVICE_SIDE_COMMIT "53c09072ddcc23361a37026486e668196695a790") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From b7b14782a813cf742a488286d5500dc76a9727b7 Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Tue, 3 May 2022 21:26:08 +0300 Subject: [PATCH 15/69] Stereo: Add support for extended and subpixel together --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index d729a65f0..fb75b05f7 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "ade89030cc99e5fb7045bd4eda5705b134631af2") +set(DEPTHAI_DEVICE_SIDE_COMMIT "6d55842132d2ef37b6a6aeaaf810a8e745cd457c") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From dc780b62a39dfa057820ba0597b435306444e618 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Fri, 6 May 2022 20:07:30 +0200 Subject: [PATCH 16/69] Updated bootloader examples --- cmake/Depthai/DepthaiBootloaderConfig.cmake | 2 +- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- examples/bootloader/flash_boot_header.cpp | 8 ++++++-- examples/bootloader/flash_bootloader.cpp | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index e442f788b..abbab41ad 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -4,4 +4,4 @@ set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" # set(DEPTHAI_BOOTLOADER_VERSION "0.0.17") -set(DEPTHAI_BOOTLOADER_VERSION "0.0.18+89b003e0ed2f8929a7c2e9625c479cfc19321cd0") +set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+84556ffa32738cece004a032144eb2145eb91fe4") diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index b59b3bc1c..86694a799 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "d2a6e3c144c65dae612395f8f7973836de9ea630") +set(DEPTHAI_DEVICE_SIDE_COMMIT "2d6e55ce83ba1add4ac7e311a6b967b815335824") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") diff --git a/examples/bootloader/flash_boot_header.cpp b/examples/bootloader/flash_boot_header.cpp index 75a7f1ad0..5a300771b 100644 --- a/examples/bootloader/flash_boot_header.cpp +++ b/examples/bootloader/flash_boot_header.cpp @@ -18,7 +18,7 @@ int main(int argc, char** argv) { } std::string mode{argv[1]}; std::transform(mode.begin(), mode.end(), mode.begin(), ::tolower); - std::function flash; + std::function flash = nullptr; if(mode == "gpio_mode") { // gpio mode header @@ -79,7 +79,11 @@ int main(int argc, char** argv) { std::cout << "Found device with name: " << info.desc.name << std::endl; dai::DeviceBootloader bl(info); // Flash the specified boot header - flash(bl); + if(flash) { + flash(bl); + } else { + std::cout << "Invalid boot option header specified" << std::endl; + } } else { std::cout << "No devices found" << std::endl; } diff --git a/examples/bootloader/flash_bootloader.cpp b/examples/bootloader/flash_bootloader.cpp index 083e42fed..c35e69fd7 100644 --- a/examples/bootloader/flash_bootloader.cpp +++ b/examples/bootloader/flash_bootloader.cpp @@ -3,6 +3,7 @@ #include "depthai/depthai.hpp" #include "depthai/xlink/XLinkConnection.hpp" +#include "XLink/XLink.h" int main(int argc, char** argv) { using namespace std::chrono; @@ -28,7 +29,7 @@ int main(int argc, char** argv) { } else { for(int i = 0; i < deviceInfos.size(); i++) { const auto& devInfo = deviceInfos[i]; - std::cout << "[" << i << "] " << devInfo.getMxId() << "[" << devInfo.desc.protocol << "]"; + std::cout << "[" << i << "] " << devInfo.getMxId() << "[" << XLinkProtocolToStr(devInfo.desc.protocol) << "]"; if(devInfo.state == X_LINK_BOOTLOADER) { dai::DeviceBootloader bl(devInfo); std::cout << " current bootloader: " << bl.getVersion(); From b381160f5ae0c374819acd1053a1996f481a4e05 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sun, 8 May 2022 18:53:48 +0200 Subject: [PATCH 17/69] Added capability to flash BoardConfig with the specified pipeline --- cmake/Depthai/DepthaiBootloaderConfig.cmake | 2 +- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- examples/bootloader/flash_bootloader.cpp | 2 +- include/depthai/device/DeviceBootloader.hpp | 7 ++- include/depthai/pipeline/Pipeline.hpp | 14 +++++ shared/depthai-shared | 2 +- src/device/DeviceBootloader.cpp | 66 ++++++++++----------- src/pipeline/Pipeline.cpp | 10 +++- 8 files changed, 62 insertions(+), 43 deletions(-) diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index abbab41ad..5f9ec84fd 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -4,4 +4,4 @@ set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" # set(DEPTHAI_BOOTLOADER_VERSION "0.0.17") -set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+84556ffa32738cece004a032144eb2145eb91fe4") +set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+2a2bdadf748aa9aca6c266dee6b937abf123bb94") diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 92f006092..af1c334cb 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "613d3600d858acd8b742e15293079d880a2d3789") +set(DEPTHAI_DEVICE_SIDE_COMMIT "a064f0b1c849ae548be1709e7d2462c9c81c26df") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") diff --git a/examples/bootloader/flash_bootloader.cpp b/examples/bootloader/flash_bootloader.cpp index c35e69fd7..7a331c39c 100644 --- a/examples/bootloader/flash_bootloader.cpp +++ b/examples/bootloader/flash_bootloader.cpp @@ -1,9 +1,9 @@ #include #include +#include "XLink/XLink.h" #include "depthai/depthai.hpp" #include "depthai/xlink/XLinkConnection.hpp" -#include "XLink/XLink.h" int main(int argc, char** argv) { using namespace std::chrono; diff --git a/include/depthai/device/DeviceBootloader.hpp b/include/depthai/device/DeviceBootloader.hpp index c3f3df9ba..7e903e53b 100644 --- a/include/depthai/device/DeviceBootloader.hpp +++ b/include/depthai/device/DeviceBootloader.hpp @@ -243,7 +243,8 @@ class DeviceBootloader { std::tuple flash(std::function progressCallback, const Pipeline& pipeline, bool compress = false, - std::string applicationName = "", Memory memory = Memory::AUTO); + std::string applicationName = "", + Memory memory = Memory::AUTO); /** * Flashes a given pipeline to the device. @@ -263,7 +264,9 @@ class DeviceBootloader { * @param progressCallback Callback that sends back a value between 0..1 which signifies current flashing progress * @param package Depthai application package to flash to the board */ - std::tuple flashDepthaiApplicationPackage(std::function progressCallback, std::vector package, Memory memory = Memory::AUTO); + std::tuple flashDepthaiApplicationPackage(std::function progressCallback, + std::vector package, + Memory memory = Memory::AUTO); /** * Flashes a specific depthai application package that was generated using createDepthaiApplicationPackage or saveDepthaiApplicationPackage diff --git a/include/depthai/pipeline/Pipeline.hpp b/include/depthai/pipeline/Pipeline.hpp index 2096b48d5..6eb46f440 100644 --- a/include/depthai/pipeline/Pipeline.hpp +++ b/include/depthai/pipeline/Pipeline.hpp @@ -41,6 +41,8 @@ class PipelineImpl { Device::Config getDeviceConfig() const; void setCameraTuningBlobPath(const dai::Path& path); void setXLinkChunkSize(int sizeBytes); + void setBoardConfig(BoardConfig board); + BoardConfig getBoardConfig() const; // Access to nodes std::vector> getAllNodes() const; @@ -72,6 +74,8 @@ class PipelineImpl { using NodeConnectionMap = std::unordered_map>; // Connection map, NodeId represents id of node connected TO (input) NodeConnectionMap nodeConnectionMap; + // Board configuration + BoardConfig board; // Template create function template @@ -266,6 +270,16 @@ class Pipeline { return impl()->isOpenVINOVersionCompatible(version); } + /// Sets board configuration + void setBoardConfig(BoardConfig board) { + impl()->setBoardConfig(board); + } + + /// Gets board configuration + BoardConfig getBoardConfig() const { + return impl()->getBoardConfig(); + } + /// Get device configuration needed for this pipeline Device::Config getDeviceConfig() const { return impl()->getDeviceConfig(); diff --git a/shared/depthai-shared b/shared/depthai-shared index 66fbed447..954f0b33b 160000 --- a/shared/depthai-shared +++ b/shared/depthai-shared @@ -1 +1 @@ -Subproject commit 66fbed44765a74fb40757f901040997015e5189a +Subproject commit 954f0b33b39cc91d6a752f7838d103871bdc1938 diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index 749aab9af..7e03572a6 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -76,20 +76,11 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip std::vector assetStorage; pipeline.serialize(schema, assets, assetStorage); - // Get openvino version - OpenVINO::Version version = pipeline.getOpenVINOVersion(); + // Get DeviceConfig + DeviceBase::Config deviceConfig = pipeline.getDeviceConfig(); // Prepare device firmware - std::vector deviceFirmware; - if(!pathToCmd.empty()) { - std::ifstream fwStream(pathToCmd, std::ios::binary); - if(!fwStream.is_open()) - throw std::runtime_error(fmt::format("Cannot create application package, device firmware at path: {} doesn't exist", pathToCmd)); - deviceFirmware = std::vector(std::istreambuf_iterator(fwStream), {}); - } else { - // TODO(themarpe) - specify OpenVINO version - deviceFirmware = Resources::getInstance().getDeviceFirmware(false, version); - } + std::vector deviceFirmware = Resources::getInstance().getDeviceFirmware(deviceConfig, pathToCmd); if(deviceFirmware.empty()) { throw std::runtime_error("Error getting device firmware"); } @@ -117,6 +108,11 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip constexpr long SECTION_ALIGNMENT_SIZE = 1 * 1024 * 1024; // 1MiB for easier updating return ((((S) + (SECTION_ALIGNMENT_SIZE)-1)) & ~((SECTION_ALIGNMENT_SIZE)-1)); }; + // Alignup for easier updating + auto getSectionAlignedOffsetSmall = [](long S) { + constexpr long SECTION_ALIGNMENT_SIZE = 64 * 1024; // 64k for flash alignement + return ((((S) + (SECTION_ALIGNMENT_SIZE)-1)) & ~((SECTION_ALIGNMENT_SIZE)-1)); + }; // Should compress firmware? if(compress) { @@ -165,35 +161,35 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip sbr_section_set_compression(fwSection, SBR_NO_COMPRESSION); } - // Second section, firmware version - sbr_section_set_name(fwVersionSection, "__fw_version"); - sbr_section_set_size(fwVersionSection, static_cast(fwVersionBuffer.size())); - sbr_section_set_checksum(fwVersionSection, sbr_compute_checksum(fwVersionBuffer.data(), static_cast(fwVersionBuffer.size()))); - sbr_section_set_offset(fwVersionSection, getSectionAlignedOffset(fwSection->offset + fwSection->size)); - - // Third section, application name - sbr_section_set_name(appNameSection, "app_name"); - sbr_section_set_size(appNameSection, static_cast(applicationName.size())); - sbr_section_set_checksum(appNameSection, sbr_compute_checksum(applicationName.data(), static_cast(applicationName.size()))); - sbr_section_set_offset(appNameSection, getSectionAlignedOffset(fwVersionSection->offset + fwVersionSection->size)); - - // Fourth section, pipeline schema, name 'pipeline' + // Section, pipeline schema, name 'pipeline' sbr_section_set_name(pipelineSection, "pipeline"); sbr_section_set_size(pipelineSection, static_cast(pipelineBinary.size())); sbr_section_set_checksum(pipelineSection, sbr_compute_checksum(pipelineBinary.data(), static_cast(pipelineBinary.size()))); sbr_section_set_offset(pipelineSection, getSectionAlignedOffset(appNameSection->offset + appNameSection->size)); - // Fifth section, assets map, name 'assets' + // Section, assets map, name 'assets' sbr_section_set_name(assetsSection, "assets"); sbr_section_set_size(assetsSection, static_cast(assetsBinary.size())); sbr_section_set_checksum(assetsSection, sbr_compute_checksum(assetsBinary.data(), static_cast(assetsBinary.size()))); - sbr_section_set_offset(assetsSection, getSectionAlignedOffset(pipelineSection->offset + pipelineSection->size)); + sbr_section_set_offset(assetsSection, getSectionAlignedOffsetSmall(pipelineSection->offset + pipelineSection->size)); - // Sixth section, asset storage, name 'asset_storage' + // Section, asset storage, name 'asset_storage' sbr_section_set_name(assetStorageSection, "asset_storage"); sbr_section_set_size(assetStorageSection, static_cast(assetStorage.size())); sbr_section_set_checksum(assetStorageSection, sbr_compute_checksum(assetStorage.data(), static_cast(assetStorage.size()))); - sbr_section_set_offset(assetStorageSection, getSectionAlignedOffset(assetsSection->offset + assetsSection->size)); + sbr_section_set_offset(assetStorageSection, getSectionAlignedOffsetSmall(assetsSection->offset + assetsSection->size)); + + // Section, firmware version + sbr_section_set_name(fwVersionSection, "__fw_version"); + sbr_section_set_size(fwVersionSection, static_cast(fwVersionBuffer.size())); + sbr_section_set_checksum(fwVersionSection, sbr_compute_checksum(fwVersionBuffer.data(), static_cast(fwVersionBuffer.size()))); + sbr_section_set_offset(fwVersionSection, getSectionAlignedOffsetSmall(fwSection->offset + fwSection->size)); + + // Section, application name + sbr_section_set_name(appNameSection, "app_name"); + sbr_section_set_size(appNameSection, static_cast(applicationName.size())); + sbr_section_set_checksum(appNameSection, sbr_compute_checksum(applicationName.data(), static_cast(applicationName.size()))); + sbr_section_set_offset(appNameSection, getSectionAlignedOffsetSmall(fwVersionSection->offset + fwVersionSection->size)); // TODO(themarpe) - Add additional sections (Pipeline nodes will be able to use sections) @@ -557,10 +553,8 @@ bool DeviceBootloader::isAllowedFlashingBootloader() const { return allowFlashingBootloader; } -std::tuple DeviceBootloader::flash(std::function progressCb, - const Pipeline& pipeline, - bool compress, - std::string applicationName, Memory memory) { +std::tuple DeviceBootloader::flash( + std::function progressCb, const Pipeline& pipeline, bool compress, std::string applicationName, Memory memory) { return flashDepthaiApplicationPackage(progressCb, createDepthaiApplicationPackage(pipeline, compress, applicationName), memory); } @@ -614,7 +608,9 @@ std::tuple DeviceBootloader::ge return {true, "", mem}; } -std::tuple DeviceBootloader::flashDepthaiApplicationPackage(std::function progressCb, std::vector package, Memory memory) { +std::tuple DeviceBootloader::flashDepthaiApplicationPackage(std::function progressCb, + std::vector package, + Memory memory) { // Bug in NETWORK bootloader in version 0.0.12 < 0.0.14 - flashing can cause a soft brick auto version = getVersion(); if(bootloaderType == Type::NETWORK && version < Version(0, 0, 14)) { @@ -622,7 +618,6 @@ std::tuple DeviceBootloader::flashDepthaiApplicationPackage(s } if(memory == Memory::AUTO) { - // send request to FLASH BOOTLOADER Request::UpdateFlash updateFlash; updateFlash.storage = Request::UpdateFlash::SBR; @@ -664,7 +659,6 @@ std::tuple DeviceBootloader::flashDepthaiApplicationPackage(s // Flash custom return flashCustom(memory, bootloader::getStructure(getType()).offset.at(Section::APPLICATION), package, progressCb); } - } std::tuple DeviceBootloader::flashDepthaiApplicationPackage(std::vector package, Memory memory) { diff --git a/src/pipeline/Pipeline.cpp b/src/pipeline/Pipeline.cpp index 861f72f01..bac1a4df3 100644 --- a/src/pipeline/Pipeline.cpp +++ b/src/pipeline/Pipeline.cpp @@ -283,7 +283,7 @@ tl::optional PipelineImpl::getPipelineOpenVINOVersion() const Device::Config PipelineImpl::getDeviceConfig() const { Device::Config config; config.version = getPipelineOpenVINOVersion().value_or(OpenVINO::DEFAULT_VERSION); - // TODO(themarpe) - fill out rest of board config + config.board = board; return config; } @@ -300,6 +300,14 @@ void PipelineImpl::setXLinkChunkSize(int sizeBytes) { globalProperties.xlinkChunkSize = sizeBytes; } +void PipelineImpl::setBoardConfig(BoardConfig board) { + this->board = board; +} + +BoardConfig PipelineImpl::getBoardConfig() const { + return board; +} + // Remove node capability void PipelineImpl::remove(std::shared_ptr toRemove) { // Search for this node in 'nodes' vector. From 7b51e1bdb4cd5c2d836b3a1cb05f2fafe9437219 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 9 May 2022 14:01:27 +0200 Subject: [PATCH 18/69] Fixed sections when creating dap --- src/device/DeviceBootloader.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index 7e03572a6..732e3748e 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -95,13 +95,18 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip // Prepare SBR structure SBR sbr = {}; - SBR_SECTION* fwSection = &sbr.sections[0]; - SBR_SECTION* fwVersionSection = &sbr.sections[1]; - SBR_SECTION* appNameSection = &sbr.sections[2]; - SBR_SECTION* pipelineSection = &sbr.sections[3]; - SBR_SECTION* assetsSection = &sbr.sections[4]; - SBR_SECTION* assetStorageSection = &sbr.sections[5]; - SBR_SECTION* lastSection = assetStorageSection; + SBR_SECTION* lastSection = &sbr.sections[0]; + + // Order of sections + SBR_SECTION* fwSection = lastSection++; + SBR_SECTION* pipelineSection = lastSection++; + SBR_SECTION* assetsSection = lastSection++; + SBR_SECTION* assetStorageSection = lastSection++; + SBR_SECTION* fwVersionSection = lastSection++; + SBR_SECTION* appNameSection = lastSection++; + + // Set to last section + lastSection = lastSection-1; // Alignup for easier updating auto getSectionAlignedOffset = [](long S) { @@ -146,7 +151,7 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip deviceFirmware.size() / (1024.0f * 1024.0f)); } - // First section, MVCMD, name '__firmware' + // Section, MVCMD, name '__firmware' sbr_section_set_name(fwSection, "__firmware"); sbr_section_set_bootable(fwSection, true); sbr_section_set_size(fwSection, static_cast(deviceFirmware.size())); @@ -165,7 +170,7 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip sbr_section_set_name(pipelineSection, "pipeline"); sbr_section_set_size(pipelineSection, static_cast(pipelineBinary.size())); sbr_section_set_checksum(pipelineSection, sbr_compute_checksum(pipelineBinary.data(), static_cast(pipelineBinary.size()))); - sbr_section_set_offset(pipelineSection, getSectionAlignedOffset(appNameSection->offset + appNameSection->size)); + sbr_section_set_offset(pipelineSection, getSectionAlignedOffset(fwSection->offset + fwSection->size)); // Section, assets map, name 'assets' sbr_section_set_name(assetsSection, "assets"); @@ -183,7 +188,7 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip sbr_section_set_name(fwVersionSection, "__fw_version"); sbr_section_set_size(fwVersionSection, static_cast(fwVersionBuffer.size())); sbr_section_set_checksum(fwVersionSection, sbr_compute_checksum(fwVersionBuffer.data(), static_cast(fwVersionBuffer.size()))); - sbr_section_set_offset(fwVersionSection, getSectionAlignedOffsetSmall(fwSection->offset + fwSection->size)); + sbr_section_set_offset(fwVersionSection, getSectionAlignedOffsetSmall(assetStorageSection->offset + assetStorageSection->size)); // Section, application name sbr_section_set_name(appNameSection, "app_name"); @@ -212,7 +217,7 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip if(spdlog::get_level() == spdlog::level::debug) { SBR_SECTION* cur = &sbr.sections[0]; spdlog::debug("DepthAI Application Package"); - for(; cur != lastSection; cur++) { + for(; cur != lastSection+1; cur++) { spdlog::debug("{}, {}B, {}, {}, {}, {}", cur->name, cur->size, cur->offset, cur->checksum, cur->type, cur->flags); } } From 88a69cf2703cc0fc3d9ffd44b785721709e6e5d9 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Tue, 10 May 2022 01:36:41 +0200 Subject: [PATCH 19/69] Updated Bootloader (fixed USB BL issue) and fixed toolchain generation --- CMakeLists.txt | 33 +++++++++++++++------ cmake/Depthai/DepthaiBootloaderConfig.cmake | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4680e5646..e49507209 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,11 +8,18 @@ endif() # Create a custom toolchain to pass certain options to dependencies set(gen_toolchain "${CMAKE_CURRENT_BINARY_DIR}/generated/toolchain.cmake") -configure_file( - "${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain/custom.cmake.in" - "${gen_toolchain}" - @ONLY -) + +if(EXISTS "${gen_toolchain}" AND ("${_INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE}" STREQUAL "${CMAKE_TOOLCHAIN_FILE}" OR NOT "${CMAKE_TOOLCHAIN_FILE}" STREQUAL "")) + message(STATUS "Using existing generated toolchain") +else() + message(STATUS "Generating new toolchain...") + configure_file( + "${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain/custom.cmake.in" + "${gen_toolchain}" + @ONLY + ) +endif() + set(CMAKE_TOOLCHAIN_FILE "${gen_toolchain}" CACHE STRING "" FORCE) if(DEFINED _INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE) message(STATUS "Using specified toolchain file: ${_INTERNAL_DEPTHAI_ORIGINAL_CMAKE_TOOLCHAIN_FILE} combined into: ${CMAKE_TOOLCHAIN_FILE}") @@ -87,10 +94,15 @@ set(DEPTHAI_SHARED_LOCAL "" CACHE STRING "Path to local depthai-shared source to set(DEPTHAI_BOOTLOADER_SHARED_LOCAL "" CACHE STRING "Path to local depthai-bootloader-shared source to use instead of submodule") # Enable backward stack printing on crash -option(DEPTHAI_ENABLE_BACKWARD "Enable stacktrace printing on crash using Backward" ON) -# Additional function information for 'backward' stacktrace -if(DEPTHAI_ENABLE_BACKWARD) - set(CMAKE_ENABLE_EXPORTS ON) +if(ANDROID) + # Backward not supported currently on Android + set(DEPTHAI_ENABLE_BACKWARD OFF CACHE BOOL "" FORCE) +else() + option(DEPTHAI_ENABLE_BACKWARD "Enable stacktrace printing on crash using Backward" ON) + # Additional function information for 'backward' stacktrace + if(DEPTHAI_ENABLE_BACKWARD) + set(CMAKE_ENABLE_EXPORTS ON) + endif() endif() # Force Colored output when using Ninja @@ -498,6 +510,9 @@ if(DEPTHAI_SANITIZE) endif() if(DEPTHAI_XLINK_LOCAL) add_sanitizers(XLink) + if(XLINK_LIBUSB_LOCAL) + add_sanitizers(usb-1.0) + endif() endif() endif() diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index 5f9ec84fd..69012502f 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -4,4 +4,4 @@ set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" # set(DEPTHAI_BOOTLOADER_VERSION "0.0.17") -set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+2a2bdadf748aa9aca6c266dee6b937abf123bb94") +set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+487e55540c9cd01845b6c7f012b9861ed9d68325") From 1a5525b0b47496f44b402fefadf6caa03b3576ac Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Wed, 11 May 2022 02:19:52 +0200 Subject: [PATCH 20/69] Updated bootloader and fixed flash_boot_header for custom frequencies --- cmake/Depthai/DepthaiBootloaderConfig.cmake | 2 +- examples/bootloader/flash_boot_header.cpp | 19 +++++++++++++------ src/device/DeviceBootloader.cpp | 4 ++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index 69012502f..3307fe278 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -4,4 +4,4 @@ set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" # set(DEPTHAI_BOOTLOADER_VERSION "0.0.17") -set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+487e55540c9cd01845b6c7f012b9861ed9d68325") +set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+2f10a2f8697dfed8928abc35884df03634c894fc") diff --git a/examples/bootloader/flash_boot_header.cpp b/examples/bootloader/flash_boot_header.cpp index 5a300771b..b046bdda9 100644 --- a/examples/bootloader/flash_boot_header.cpp +++ b/examples/bootloader/flash_boot_header.cpp @@ -18,7 +18,7 @@ int main(int argc, char** argv) { } std::string mode{argv[1]}; std::transform(mode.begin(), mode.end(), mode.begin(), ::tolower); - std::function flash = nullptr; + std::function(dai::DeviceBootloader&)> flash = nullptr; if(mode == "gpio_mode") { // gpio mode header @@ -28,10 +28,10 @@ int main(int argc, char** argv) { } int gpioMode = std::stoi(std::string(argv[2])); - flash = [gpioMode](dai::DeviceBootloader& bl) { bl.flashGpioModeBootHeader(dai::DeviceBootloader::Memory::FLASH, gpioMode); }; + flash = [gpioMode](dai::DeviceBootloader& bl) { return bl.flashGpioModeBootHeader(dai::DeviceBootloader::Memory::FLASH, gpioMode); }; } else if(mode == "usb_recovery") { // usb recovery header - flash = [](dai::DeviceBootloader& bl) { bl.flashUsbRecoveryBootHeader(dai::DeviceBootloader::Memory::FLASH); }; + flash = [](dai::DeviceBootloader& bl) { return bl.flashUsbRecoveryBootHeader(dai::DeviceBootloader::Memory::FLASH); }; } else if(mode == "normal" || mode == "fast") { if(argc != 2 && argc != 3 && argc <= 3) { std::cout << "Usage: " << argv[0] << " NORMAL/FAST [offset] [location] [dummyCycles] [frequency]" << std::endl; @@ -61,11 +61,11 @@ int main(int argc, char** argv) { if(mode == "normal") { flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) { - bl.flashBootHeader(dai::DeviceBootloader::Memory::FLASH, offset, location, dummyCycles, frequency); + return bl.flashBootHeader(dai::DeviceBootloader::Memory::FLASH, offset, location, dummyCycles, frequency); }; } else if(mode == "fast") { flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) { - bl.flashFastBootHeader(dai::DeviceBootloader::Memory::FLASH, offset, location, dummyCycles, frequency); + return bl.flashFastBootHeader(dai::DeviceBootloader::Memory::FLASH, offset, location, dummyCycles, frequency); }; } } @@ -80,7 +80,14 @@ int main(int argc, char** argv) { dai::DeviceBootloader bl(info); // Flash the specified boot header if(flash) { - flash(bl); + bool success; + std::string errorMsg; + std::tie(success, errorMsg) = flash(bl); + if(success) { + std::cout << "Successfully flashed boot header!" << std::endl; + } else { + std::cout << "Couldn't flash boot header: " << errorMsg << std::endl; + } } else { std::cout << "Invalid boot option header specified" << std::endl; } diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index 732e3748e..1ca80de19 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -798,6 +798,8 @@ std::tuple DeviceBootloader::flashBootHeader(Memory memory, i updateBootHeader.location = location; updateBootHeader.dummyCycles = dummyCycles; updateBootHeader.frequency = frequency; + // Set optimized gpio boot mode, which allows changing above parameters + updateBootHeader.gpioMode = 0x7; // Send & Get response if(!sendRequest(updateBootHeader)) return {false, "Couldn't send request to flash boot header"}; @@ -816,6 +818,8 @@ std::tuple DeviceBootloader::flashFastBootHeader(Memory memor updateBootHeader.location = location; updateBootHeader.dummyCycles = dummyCycles; updateBootHeader.frequency = frequency; + // Set optimized gpio boot mode, which allows changing above parameters + updateBootHeader.gpioMode = 0x7; // Send & Get response if(!sendRequest(updateBootHeader)) return {false, "Couldn't send request to flash boot header"}; From c74aa861bee9d11a7bd5b12b4280a476ba68d150 Mon Sep 17 00:00:00 2001 From: OanaMariaVatavu Date: Mon, 16 May 2022 07:47:34 +0300 Subject: [PATCH 21/69] [ImageManip] - FW update: [API maintained] [setKeepAspectRatio] - resize with keeping aspect ratio + crop the input field of view to match the output aspect ratio - using the "setKeepAspectRatio" API in conjunction with the "setResizeThumbnail" API, the "setKeepAspectRatio" API will not have any effect because the "setResizeThumbnail" API has priority - keepAspectRatio config is True by default [bugs fixed] [artifacts/memory coruption] Properly extract the chroma rect Properly compute the luma/chroma cached memory size Input interleaved -> planar conversion + rect rotation [hang] input rectangle outside frame --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 3ddcab50a..37d7af305 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "53c09072ddcc23361a37026486e668196695a790") +set(DEPTHAI_DEVICE_SIDE_COMMIT "ababbe18bad449d5a3db0e238a6bad7d43a377fc") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From 8ecc668c945ff99795e3c7932ae12133f6f8153e Mon Sep 17 00:00:00 2001 From: OanaMariaVatavu Date: Tue, 17 May 2022 11:12:50 +0300 Subject: [PATCH 22/69] [ImageManip] - update FW --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 28641f1ce..882d4515f 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "2041e04ea0a021f4534d630baf14813696f56311") +set(DEPTHAI_DEVICE_SIDE_COMMIT "e483189a46ece011aca33e693eddddbce0236f50") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From c6da67078421ecb9cbdaff20d818e76cfe3be732 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sat, 21 May 2022 01:30:49 +0200 Subject: [PATCH 23/69] Revisited bootloader memory and application info --- cmake/Depthai/DepthaiBootloaderConfig.cmake | 2 +- examples/bootloader/bootloader_version.cpp | 25 +++----- examples/bootloader/flash_boot_header.cpp | 2 +- examples/bootloader/read_flash_memory.cpp | 2 +- examples/bootloader/write_flash_memory.cpp | 2 +- include/depthai/device/DeviceBootloader.hpp | 9 ++- shared/depthai-bootloader-shared | 2 +- src/device/DeviceBootloader.cpp | 71 +++++++++++++++++---- 8 files changed, 80 insertions(+), 35 deletions(-) diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index 3307fe278..1ad79f941 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -4,4 +4,4 @@ set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" # set(DEPTHAI_BOOTLOADER_VERSION "0.0.17") -set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+2f10a2f8697dfed8928abc35884df03634c894fc") +set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+042ea79ae0014054dcb3fc3377229aa6c95ebf3f") diff --git a/examples/bootloader/bootloader_version.cpp b/examples/bootloader/bootloader_version.cpp index b1dc7cb2b..615f155b9 100644 --- a/examples/bootloader/bootloader_version.cpp +++ b/examples/bootloader/bootloader_version.cpp @@ -10,24 +10,17 @@ int main(int argc, char** argv) { dai::DeviceBootloader bl(info); std::cout << "Version: " << bl.getVersion().toString() << std::endl; - bool ok; - std::string err; - dai::DeviceBootloader::ApplicationInfo info; - std::tie(ok, err, info) = bl.readApplicationInfo(); - if(ok) { - std::cout << "Application, flashed: " << info.hasApplication << " firmware version: " << info.firmwareVersion - << " application name: " << info.applicationName << std::endl; - } else { - std::cout << "Error reading application infomation: " << err << std::endl; - } - for(const auto& mem : {dai::DeviceBootloader::Memory::FLASH, dai::DeviceBootloader::Memory::EMMC}) { - dai::DeviceBootloader::MemoryInfo info; - std::tie(ok, err, info) = bl.getMemoryInfo(mem); - if(ok) { - std::cout << "Memory size: " << info.size << ", info: " << info.info << std::endl; + std::cout << std::endl; + auto memoryInfo = bl.getMemoryInfo(mem); + if(memoryInfo.available) { + std::cout << "Memory '" << mem << "' size: " << memoryInfo.size << ", info: " << memoryInfo.info << std::endl; + + auto appInfo = bl.readApplicationInfo(mem); + std::cout << "Application, flashed: " << appInfo.hasApplication << " firmware version: " << appInfo.firmwareVersion + << " application name: " << appInfo.applicationName << std::endl; } else { - std::cout << "Error retrieving memory information: " << err << std::endl; + std::cout << "Memory '" << mem << "' not available..." << std::endl; } } } else { diff --git a/examples/bootloader/flash_boot_header.cpp b/examples/bootloader/flash_boot_header.cpp index b046bdda9..4446fdd66 100644 --- a/examples/bootloader/flash_boot_header.cpp +++ b/examples/bootloader/flash_boot_header.cpp @@ -76,7 +76,7 @@ int main(int argc, char** argv) { std::tie(res, info) = dai::DeviceBootloader::getFirstAvailableDevice(); if(res) { - std::cout << "Found device with name: " << info.desc.name << std::endl; + std::cout << "Found device with name: " << info.name << std::endl; dai::DeviceBootloader bl(info); // Flash the specified boot header if(flash) { diff --git a/examples/bootloader/read_flash_memory.cpp b/examples/bootloader/read_flash_memory.cpp index 0bd105b27..4e9ce57bd 100644 --- a/examples/bootloader/read_flash_memory.cpp +++ b/examples/bootloader/read_flash_memory.cpp @@ -22,7 +22,7 @@ int main(int argc, char** argv) { std::tie(res, info) = dai::DeviceBootloader::getFirstAvailableDevice(); if(res) { - std::cout << "Found device with name: " << info.desc.name << std::endl; + std::cout << "Found device with name: " << info.name << std::endl; dai::DeviceBootloader bl(info); auto progress = [](float p) { std::cout << "Reading progress..." << p * 100 << "%" << std::endl; }; diff --git a/examples/bootloader/write_flash_memory.cpp b/examples/bootloader/write_flash_memory.cpp index b3895414d..dba7d6665 100644 --- a/examples/bootloader/write_flash_memory.cpp +++ b/examples/bootloader/write_flash_memory.cpp @@ -18,7 +18,7 @@ int main(int argc, char** argv) { std::tie(res, info) = dai::DeviceBootloader::getFirstAvailableDevice(); if(res) { - std::cout << "Found device with name: " << info.desc.name << std::endl; + std::cout << "Found device with name: " << info.name << std::endl; dai::DeviceBootloader bl(info); auto progress = [](float p) { std::cout << "Flashing progress..." << p * 100 << "%" << std::endl; }; diff --git a/include/depthai/device/DeviceBootloader.hpp b/include/depthai/device/DeviceBootloader.hpp index 7e903e53b..f2dd9f31a 100644 --- a/include/depthai/device/DeviceBootloader.hpp +++ b/include/depthai/device/DeviceBootloader.hpp @@ -114,12 +114,14 @@ class DeviceBootloader { }; struct ApplicationInfo { + Memory memory; bool hasApplication; std::string firmwareVersion; std::string applicationName; }; struct MemoryInfo { + bool available; std::int64_t size; std::string info; }; @@ -255,9 +257,10 @@ class DeviceBootloader { std::tuple flash(const Pipeline& pipeline, bool compress = false, std::string applicationName = "", Memory memory = Memory::AUTO); /** - * Reads flashed application information from device + * Reads information about flashed application in specified memory from device + * @param memory Specifies which memory to query */ - std::tuple readApplicationInfo(); + ApplicationInfo readApplicationInfo(Memory memory); /** * Flashes a specific depthai application package that was generated using createDepthaiApplicationPackage or saveDepthaiApplicationPackage @@ -407,7 +410,7 @@ class DeviceBootloader { * Retrieves information about specified memory * @param memory Specifies which memory to query */ - std::tuple getMemoryInfo(Memory memory); + MemoryInfo getMemoryInfo(Memory memory); /** * Boots a custom FW in memory diff --git a/shared/depthai-bootloader-shared b/shared/depthai-bootloader-shared index 8720b3bf1..327c4967c 160000 --- a/shared/depthai-bootloader-shared +++ b/shared/depthai-bootloader-shared @@ -1 +1 @@ -Subproject commit 8720b3bf1b67924db17d6fc5e730eb144d05e7e4 +Subproject commit 327c4967c539cd4315ab028cbdccaef975ab742a diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index 5332fa2de..65c3a5875 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -107,7 +107,7 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip SBR_SECTION* appNameSection = lastSection++; // Set to last section - lastSection = lastSection-1; + lastSection = lastSection - 1; // Alignup for easier updating auto getSectionAlignedOffset = [](long S) { @@ -218,7 +218,7 @@ std::vector DeviceBootloader::createDepthaiApplicationPackage(const Pip if(spdlog::get_level() == spdlog::level::debug) { SBR_SECTION* cur = &sbr.sections[0]; spdlog::debug("DepthAI Application Package"); - for(; cur != lastSection+1; cur++) { + for(; cur != lastSection + 1; cur++) { spdlog::debug("{}, {}B, {}, {}, {}, {}", cur->name, cur->size, cur->offset, cur->checksum, cur->type, cur->flags); } } @@ -568,8 +568,11 @@ std::tuple DeviceBootloader::flash(const Pipeline& pipeline, return flashDepthaiApplicationPackage(createDepthaiApplicationPackage(pipeline, compress, applicationName), memory); } -std::tuple DeviceBootloader::readApplicationInfo() { +DeviceBootloader::ApplicationInfo DeviceBootloader::readApplicationInfo(Memory mem) { // Send request to retrieve bootloader version + Request::GetApplicationDetails appDetails; + appDetails.memory = mem; + sendRequestThrow(Request::GetApplicationDetails{}); // Receive response @@ -578,6 +581,7 @@ std::tuple DeviceBootloade // Set default values ApplicationInfo info; + info.memory = mem; info.firmwareVersion = ""; info.applicationName = ""; @@ -590,14 +594,19 @@ std::tuple DeviceBootloade info.applicationName = std::string(details.applicationNameStr); } - if(details.success) { - return {true, "", info}; - } else { - return {false, details.errorMsg, info}; + if(!details.success) { + throw std::runtime_error(details.errorMsg); } + + return info; } -std::tuple DeviceBootloader::getMemoryInfo(Memory memory) { +DeviceBootloader::MemoryInfo DeviceBootloader::getMemoryInfo(Memory memory) { + if(memory == Memory::EMMC && bootloaderType == Type::USB) { + // Warn, as result of "no emmc" might be deceiving + spdlog::warn("USB Bootloader type does NOT support eMMC"); + } + // Send request to retrieve bootloader version Request::GetMemoryDetails req{}; req.memory = memory; @@ -608,10 +617,11 @@ std::tuple DeviceBootloader::ge receiveResponseThrow(details); MemoryInfo mem; + mem.available = details.hasMemory; mem.size = details.memorySize; mem.info = std::string(details.memoryInfo); - return {true, "", mem}; + return mem; } std::tuple DeviceBootloader::flashDepthaiApplicationPackage(std::function progressCb, @@ -623,6 +633,7 @@ std::tuple DeviceBootloader::flashDepthaiApplicationPackage(s throw std::invalid_argument("Network bootloader requires version 0.0.14 or higher to flash applications. Current version: " + version.toString()); } + std::tuple ret; if(memory == Memory::AUTO) { // send request to FLASH BOOTLOADER Request::UpdateFlash updateFlash; @@ -659,12 +670,50 @@ std::tuple DeviceBootloader::flashDepthaiApplicationPackage(s } while(true); // Return if flashing was successful - return {result.success, result.errorMsg}; + ret = {result.success, result.errorMsg}; } else { // Flash custom - return flashCustom(memory, bootloader::getStructure(getType()).offset.at(Section::APPLICATION), package, progressCb); + ret = flashCustom(memory, bootloader::getStructure(getType()).offset.at(Section::APPLICATION), package, progressCb); + } + + // Try specifing final app memory if set explicitly or if AUTO would be EMMC + try { + Memory finalAppMem = Memory::FLASH; + if(memory != Memory::AUTO) { + // Specify final app memory if explicitly set + finalAppMem = memory; + } else if(memory == Memory::AUTO && bootloaderType == Type::NETWORK) { + // If AUTO, only do so if eMMC is target memory + auto mem = getMemoryInfo(Memory::EMMC); + if(mem.available) { + finalAppMem = Memory::EMMC; + } + } + + // Try reading existing config, or create a new one + nlohmann::json configJson; + try { + configJson = readConfigData(); + } catch(const std::exception& ex) { + spdlog::debug("Error while trying to read existing bootloader configuration: {}", ex.what()); + } + // Set the following field 'appMem' (in forward/backward compat manner) + configJson["appMem"] = finalAppMem; + // Flash back the rest of configuration as is + bool success; + std::string errorMsg; + std::tie(success, errorMsg) = flashConfigData(configJson); + if(success) { + spdlog::debug("Success flashing the appMem configuration to '{}'", finalAppMem); + } else { + throw std::runtime_error(errorMsg); + } + } catch(const std::exception& ex) { + spdlog::debug("Error while trying to specify final appMem configuration: {}", ex.what()); } + + return ret; } std::tuple DeviceBootloader::flashDepthaiApplicationPackage(std::vector package, Memory memory) { From 9129750b487926d620cddbc403ba7e272877dfbd Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Fri, 3 Jun 2022 20:34:17 +0300 Subject: [PATCH 24/69] Set lens position from calibration data --- examples/Script/script_forward_frames.cpp | 1 - examples/StereoDepth/rgb_depth_aligned.cpp | 14 ++++++++++++-- .../StereoDepth/rgb_depth_confidence_aligned.cpp | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/examples/Script/script_forward_frames.cpp b/examples/Script/script_forward_frames.cpp index f978076ee..19eea52b7 100644 --- a/examples/Script/script_forward_frames.cpp +++ b/examples/Script/script_forward_frames.cpp @@ -11,7 +11,6 @@ int main() { // Define a source - color camera auto cam = pipeline.create(); - cam->initialControl.setManualFocus(130); // Not needed, you can display 1080P frames as well cam->setIspScale(1, 2); diff --git a/examples/StereoDepth/rgb_depth_aligned.cpp b/examples/StereoDepth/rgb_depth_aligned.cpp index a73a2aa39..c8cfa6509 100644 --- a/examples/StereoDepth/rgb_depth_aligned.cpp +++ b/examples/StereoDepth/rgb_depth_aligned.cpp @@ -26,6 +26,7 @@ int main() { // Create pipeline dai::Pipeline pipeline; + dai::Device device; std::vector queueNames; // Define sources and outputs @@ -49,7 +50,16 @@ int main() { if(downscaleColor) camRgb->setIspScale(2, 3); // For now, RGB needs fixed focus to properly align with depth. // This value was used during calibration - camRgb->initialControl.setManualFocus(135); + try { + auto calibData = device.readCalibration(); + auto lensPosition = calibData.getLensPosition(dai::CameraBoardSocket::RGB); + if(lensPosition) { + camRgb->initialControl.setManualFocus(lensPosition); + } + } catch(const std::exception& ex) { + std::cout << ex.what() << std::endl; + return 1; + } left->setResolution(monoRes); left->setBoardSocket(dai::CameraBoardSocket::LEFT); @@ -70,7 +80,7 @@ int main() { stereo->disparity.link(depthOut->input); // Connect to device and start pipeline - dai::Device device(pipeline); + device.startPipeline(pipeline); // Sets queues size and behavior for(const auto& name : queueNames) { diff --git a/examples/StereoDepth/rgb_depth_confidence_aligned.cpp b/examples/StereoDepth/rgb_depth_confidence_aligned.cpp index b606f8a63..e2e4d8343 100644 --- a/examples/StereoDepth/rgb_depth_confidence_aligned.cpp +++ b/examples/StereoDepth/rgb_depth_confidence_aligned.cpp @@ -30,6 +30,7 @@ int main() { // Create pipeline dai::Pipeline pipeline; + dai::Device device; std::vector queueNames; // Define sources and outputs @@ -56,7 +57,16 @@ int main() { if(downscaleColor) camRgb->setIspScale(2, 3); // For now, RGB needs fixed focus to properly align with depth. // This value was used during calibration - camRgb->initialControl.setManualFocus(135); + try { + auto calibData = device.readCalibration(); + auto lensPosition = calibData.getLensPosition(dai::CameraBoardSocket::RGB); + if(lensPosition) { + camRgb->initialControl.setManualFocus(lensPosition); + } + } catch(const std::exception& ex) { + std::cout << ex.what() << std::endl; + return 1; + } left->setResolution(monoRes); left->setBoardSocket(dai::CameraBoardSocket::LEFT); @@ -78,7 +88,7 @@ int main() { stereo->confidenceMap.link(confOut->input); // Connect to device and start pipeline - dai::Device device(pipeline); + device.startPipeline(pipeline); // Sets queues size and behavior for(const auto& name : queueNames) { From 359b678034f4ddb3095d0302033084f43007b5e1 Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Sat, 4 Jun 2022 13:37:48 +0300 Subject: [PATCH 25/69] Change HIL test worklfow hunter cached path --- .github/workflows/test.workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.workflow.yml b/.github/workflows/test.workflow.yml index c9ddbdda7..c47b12156 100644 --- a/.github/workflows/test.workflow.yml +++ b/.github/workflows/test.workflow.yml @@ -38,7 +38,7 @@ jobs: - name: Cache .hunter folder uses: actions/cache@v2 with: - path: $HOME/.hun_${{ matrix.flavor }} + path: $HOME/.hun2_${{ matrix.flavor }} key: hunter-${{ matrix.os }}-${{ matrix.cmake }} - uses: actions/checkout@v2 with: From cc8299a070d43b5d06b67b7b777661f0eee54299 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sun, 5 Jun 2022 19:20:20 +0200 Subject: [PATCH 26/69] XLink tcp device search data race fix --- cmake/Hunter/config.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake index 48358faf2..f016cea56 100644 --- a/cmake/Hunter/config.cmake +++ b/cmake/Hunter/config.cmake @@ -8,8 +8,8 @@ hunter_config( hunter_config( XLink VERSION "luxonis-2021.4.2-develop" - URL "https://github.com/luxonis/XLink/archive/a5bd7e7dda40e08dc2d6570f6a8c766ba3332703.tar.gz" - SHA1 "dd821a5c08a81b629dae53124cb61512d8de49f1" + URL "https://github.com/luxonis/XLink/archive/3360f36847ba2a1cb8836650e1cd8810404eaf55.tar.gz" + SHA1 "b8e540e51165271facdabf4f2713b7c65ca95e8b" ) hunter_config( From f34ac1d9ecd5fdf2e3ece4a88b9e7e7eee1bbc32 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 6 Jun 2022 19:03:32 +0200 Subject: [PATCH 27/69] Added 'hil-test' label to test workflow --- .github/workflows/test.workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.workflow.yml b/.github/workflows/test.workflow.yml index c47b12156..d89f38e70 100644 --- a/.github/workflows/test.workflow.yml +++ b/.github/workflows/test.workflow.yml @@ -32,7 +32,7 @@ jobs: arch: 'x64' flavor: 'tsan' fail-fast: false - runs-on: ['self-hosted', '${{ matrix.os }}', '${{ matrix.arch }}'] + runs-on: ['self-hosted', 'hil-test', '${{ matrix.os }}', '${{ matrix.arch }}'] steps: - name: Cache .hunter folder From 2855b4a5c3771ac9c55048637317f08fe2f5927e Mon Sep 17 00:00:00 2001 From: alex-luxonis Date: Tue, 7 Jun 2022 01:14:42 +0300 Subject: [PATCH 28/69] Update FW: support for new devices with 3x 4-lane cam ports, TMP: enable RGB-depth alignment for 12MP full FoV (hardcoded) --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 91150b8dc..c6e640108 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "077fa75ba35a83d8c42156c40718d412a5825b77") +set(DEPTHAI_DEVICE_SIDE_COMMIT "47e069cc7f16d29b37e17b2923322bc9824ebed4") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From 28dfd081156048e9a884e2f250f545e10ce38522 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Tue, 7 Jun 2022 00:47:16 +0200 Subject: [PATCH 29/69] Updated FW with better EEPROM board config handling --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- shared/depthai-shared | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 91150b8dc..6b7e2ca4a 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "077fa75ba35a83d8c42156c40718d412a5825b77") +set(DEPTHAI_DEVICE_SIDE_COMMIT "7575837c0a39107dd1d0b88fe9b984c81a5dc22f") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") diff --git a/shared/depthai-shared b/shared/depthai-shared index cb49a5c57..7575837c0 160000 --- a/shared/depthai-shared +++ b/shared/depthai-shared @@ -1 +1 @@ -Subproject commit cb49a5c571c2ed253dfcd0aa80564291767b7a92 +Subproject commit 7575837c0a39107dd1d0b88fe9b984c81a5dc22f From c4eab23369f0a0797ddd379c4a9a8a7aa9b5d8e2 Mon Sep 17 00:00:00 2001 From: alex-luxonis Date: Tue, 7 Jun 2022 19:46:37 +0300 Subject: [PATCH 30/69] Update FW: fix enabling MIPI clocks for 4-lane ports --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index c6e640108..3d4fe2560 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "47e069cc7f16d29b37e17b2923322bc9824ebed4") +set(DEPTHAI_DEVICE_SIDE_COMMIT "35d45ad291a6f988becc9663b6e8b2d58d4de24c") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From c033718742a289612097ce13ede6f155d6995a70 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Tue, 7 Jun 2022 20:35:55 +0200 Subject: [PATCH 31/69] Updated BL & FW for small density Micron NOR chips --- cmake/Depthai/DepthaiBootloaderConfig.cmake | 2 +- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index 04a1af9dd..d4eeead17 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -4,4 +4,4 @@ set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" # set(DEPTHAI_BOOTLOADER_VERSION "0.0.17") -set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+6e3775f5fa8d44fa9a7cea280333f1def8ff0e9f") +set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+4af3b8fe5c0dc6f9a31dedac17affe2e490f81a0") diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 7043f757d..c7f9f0f27 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "63f3da42f123d5dd0e7069c29b6abbbbc920ca43") +set(DEPTHAI_DEVICE_SIDE_COMMIT "b475422afdfcb7da6c49828654f2de8add6dd276") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From e13e4d7e7dca4ff4d02a1e101bd5148baf87b396 Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Wed, 8 Jun 2022 04:36:58 +0300 Subject: [PATCH 32/69] Update FW; do subpixel interpolation for extended mode too --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index ba29d1e11..ac60c2255 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "13c36e636dd00e83b89a5cc1ee76049567657c4b") +set(DEPTHAI_DEVICE_SIDE_COMMIT "d616e5354de2d63602fdcbda434628ab071b56a3") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From 4c287063d7aa5e3ffbe7636ccf4a00a6f2bf40d7 Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Wed, 8 Jun 2022 06:13:12 +0200 Subject: [PATCH 33/69] Windows - added required DLL copying for tests and examples to be runnable outside of CMake --- examples/CMakeLists.txt | 25 +++++++++++++++---------- tests/CMakeLists.txt | 24 ++++++++++++++---------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 046e41eab..426e6f6bb 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -11,24 +11,14 @@ target_include_directories(utility PUBLIC "utility") add_default_flags(utility LEAN) target_link_libraries(utility FP16::fp16 ${OpenCV_LIBS}) -# Specify path separator -set(SYS_PATH_SEPARATOR ";") -if(UNIX) - set(SYS_PATH_SEPARATOR ":") -endif() - # Create environments for usb & poe labels set(test_usb_env - # PATH (dlls) - "PATH=${HUNTER_INSTALL_PREFIX}/bin${SYS_PATH_SEPARATOR}$ENV{PATH}" # Misc "UBSAN_OPTIONS=halt_on_error=1" # DepthAI "DEPTHAI_PROTOCOL=usb" ) set(test_poe_env - # PATH (dlls) - "PATH=${HUNTER_INSTALL_PREFIX}/bin${SYS_PATH_SEPARATOR}$ENV{PATH}" # Misc "UBSAN_OPTIONS=halt_on_error=1" # DepthAI @@ -78,6 +68,21 @@ function(dai_add_example example_name example_src enable_test) set_tests_properties(${example_name}_poe PROPERTIES ENVIRONMENT "${test_poe_env}" LABELS poe) endif() + + # Copy over required DLLs (Windows) + if(WIN32) + # Copy dlls to target directory - Windows only + # TARGET_RUNTIME_DLLS generator expression available since CMake 3.21 + if(CMAKE_VERSION VERSION_LESS "3.21") + file(GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX}/bin/*.dll") + else() + set(depthai_dll_libraries "$") + endif() + add_custom_command(TARGET ${example_name} POST_BUILD COMMAND + ${CMAKE_COMMAND} -E copy ${depthai_dll_libraries} $ + COMMAND_EXPAND_LISTS + ) + endif() endfunction() # Create a custom target which runs all examples for 10 seconds max, and check if they executed without errors diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d40ae78bd..e8fa1f6dc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,24 +6,14 @@ enable_testing() hunter_add_package(Catch2) find_package(Catch2 CONFIG REQUIRED) -# Specify path separator -set(SYS_PATH_SEPARATOR ";") -if(UNIX) - set(SYS_PATH_SEPARATOR ":") -endif() - # Create environments for usb & poe labels set(test_usb_env - # PATH (dlls) - "PATH=${HUNTER_INSTALL_PREFIX}/bin${SYS_PATH_SEPARATOR}$ENV{PATH}" # Misc "UBSAN_OPTIONS=halt_on_error=1" # DepthAI "DEPTHAI_PROTOCOL=usb" ) set(test_poe_env - # PATH (dlls) - "PATH=${HUNTER_INSTALL_PREFIX}/bin${SYS_PATH_SEPARATOR}$ENV{PATH}" # Misc "UBSAN_OPTIONS=halt_on_error=1" # DepthAI @@ -107,6 +97,20 @@ function(dai_add_test test_name test_src) set_tests_properties(${test_name}_conforming_poe PROPERTIES ENVIRONMENT "${test_poe_env}" LABELS poe) endif() + # Copy over required DLLs (Windows) + if(WIN32) + # Copy dlls to target directory - Windows only + # TARGET_RUNTIME_DLLS generator expression available since CMake 3.21 + if(CMAKE_VERSION VERSION_LESS "3.21") + file(GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX}/bin/*.dll") + else() + set(depthai_dll_libraries "$") + endif() + add_custom_command(TARGET ${test_name} POST_BUILD COMMAND + ${CMAKE_COMMAND} -E copy ${depthai_dll_libraries} $ + COMMAND_EXPAND_LISTS + ) + endif() endfunction() # Function for adding compile definitions to tests From ed6a132a12d851f8d818916d94de66863d3e8288 Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Wed, 8 Jun 2022 19:34:14 +0200 Subject: [PATCH 34/69] Fixed incorrect target runtime dlls usage for examples & tests --- examples/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 426e6f6bb..8b34951e2 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -76,7 +76,7 @@ function(dai_add_example example_name example_src enable_test) if(CMAKE_VERSION VERSION_LESS "3.21") file(GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX}/bin/*.dll") else() - set(depthai_dll_libraries "$") + set(depthai_dll_libraries "$") endif() add_custom_command(TARGET ${example_name} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${depthai_dll_libraries} $ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e8fa1f6dc..5ebd32d6a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -104,7 +104,7 @@ function(dai_add_test test_name test_src) if(CMAKE_VERSION VERSION_LESS "3.21") file(GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX}/bin/*.dll") else() - set(depthai_dll_libraries "$") + set(depthai_dll_libraries "$") endif() add_custom_command(TARGET ${test_name} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${depthai_dll_libraries} $ From a38619764cf05412364e67d6b5bb19b6e23e5bf9 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Wed, 8 Jun 2022 19:55:30 +0200 Subject: [PATCH 35/69] Improved error reporting of failed XLink initialization --- cmake/Hunter/config.cmake | 4 ++-- src/utility/Initialization.cpp | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake index 9c07b4c56..85f9a5c35 100644 --- a/cmake/Hunter/config.cmake +++ b/cmake/Hunter/config.cmake @@ -8,8 +8,8 @@ hunter_config( hunter_config( XLink VERSION "luxonis-2021.4.2-develop" - URL "https://github.com/luxonis/XLink/archive/5a0c118ef4710d27bc9e99415b526f22b3af56db.tar.gz" - SHA1 "9ac40df4ed8d6d6911548d951ecf4c0fb11f60f5" + URL "https://github.com/luxonis/XLink/archive/9fcd6dc8b7d0f95d892b059c0c938c97bc9da6dc.tar.gz" + SHA1 "6a4187839a94b948db3d7cc94a7e8e8651573ef4" ) hunter_config( diff --git a/src/utility/Initialization.cpp b/src/utility/Initialization.cpp index 10a3693af..401113bbc 100644 --- a/src/utility/Initialization.cpp +++ b/src/utility/Initialization.cpp @@ -100,7 +100,10 @@ bool initialize(const char* additionalInfo, bool installSignalHandler, void* jav xlinkGlobalHandler.options = javavm; auto status = XLinkInitialize(&xlinkGlobalHandler); if(X_LINK_SUCCESS != status) { - std::string errorMsg = fmt::format("Couldn't initialize XLink: {}", XLinkErrorToStr(status)); + std::string errorMsg = fmt::format("Couldn't initialize XLink: {}. ", XLinkErrorToStr(status)); + if(status == X_LINK_INIT_USB_ERROR) { + errorMsg += fmt::format("If running in a container, make sure that the following is set: \"{}\"", "-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule='c 189:* rmw'"); + } spdlog::debug("Initialize failed - {}", errorMsg); throw std::runtime_error(errorMsg); } From ef79c6f666e10074fe7b5afb143069c054467756 Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Thu, 9 Jun 2022 00:40:54 +0300 Subject: [PATCH 36/69] Update FW before merge --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index ac60c2255..75e2b5698 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "d616e5354de2d63602fdcbda434628ab071b56a3") +set(DEPTHAI_DEVICE_SIDE_COMMIT "6885de2401507c94137146b7c661b924b9ac049c") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From acafc4f88f83217c787397740919653501247cbe Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Thu, 9 Jun 2022 01:56:37 +0300 Subject: [PATCH 37/69] Apply style --- src/utility/Initialization.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utility/Initialization.cpp b/src/utility/Initialization.cpp index 401113bbc..dc3cdbac8 100644 --- a/src/utility/Initialization.cpp +++ b/src/utility/Initialization.cpp @@ -102,7 +102,8 @@ bool initialize(const char* additionalInfo, bool installSignalHandler, void* jav if(X_LINK_SUCCESS != status) { std::string errorMsg = fmt::format("Couldn't initialize XLink: {}. ", XLinkErrorToStr(status)); if(status == X_LINK_INIT_USB_ERROR) { - errorMsg += fmt::format("If running in a container, make sure that the following is set: \"{}\"", "-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule='c 189:* rmw'"); + errorMsg += fmt::format("If running in a container, make sure that the following is set: \"{}\"", + "-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule='c 189:* rmw'"); } spdlog::debug("Initialize failed - {}", errorMsg); throw std::runtime_error(errorMsg); From 1cb8b0aabcead7c9c3e245585025c29de195e10e Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Thu, 9 Jun 2022 02:09:38 +0200 Subject: [PATCH 38/69] Refactored main CI workflow --- .github/workflows/main.workflow.yml | 42 +++++++++-------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/.github/workflows/main.workflow.yml b/.github/workflows/main.workflow.yml index 65e5a0970..fa12fbd84 100644 --- a/.github/workflows/main.workflow.yml +++ b/.github/workflows/main.workflow.yml @@ -17,9 +17,6 @@ on: - gen2 - gen2_develop -env: - CMAKE_WINDOWS_SDK_VERSION: '10.0.18362.0' - jobs: style: @@ -33,7 +30,6 @@ jobs: - name: Install format dependencies run: | sudo apt-get install clang-format-10 - sudo apt-get install libusb-1.0-0-dev - name: configure run: cmake . -Bbuild -DDEPTHAI_CLANG_FORMAT=ON -DCLANG_FORMAT_BIN=clang-format-10 @@ -53,7 +49,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install libusb-1.0-0-dev clang-tidy-10 + sudo apt-get install clang-tidy-10 - name: configure run: cmake . -Bbuild -DDEPTHAI_CLANG_TIDY=ON -DCLANG_TIDY_BIN=clang-tidy-10 @@ -97,21 +93,19 @@ jobs: - name: Install dependencies if: matrix.os == 'macos-latest' run: | - brew install libusb opencv + brew install opencv - name: Install dependencies if: matrix.os == 'ubuntu-latest' run: | sudo apt-get update - sudo apt-get install libusb-1.0-0-dev libopencv-dev + sudo apt-get install libopencv-dev - name: Install dependencies if: matrix.os == 'windows-latest' run: | choco install opencv echo "OpenCV_DIR=C:\tools\opencv\build" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - echo "C:\tools\opencv\build\x64\vc15\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - echo "CMAKE_ARGS=-D'CMAKE_SYSTEM_VERSION=${{ env.CMAKE_WINDOWS_SDK_VERSION }}'" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - name: Build (old CMake, gcc/Clang) if: matrix.cmake == '3.10.x' && matrix.os != 'windows-latest' @@ -138,16 +132,16 @@ jobs: matrix: os: [macos-latest, windows-latest, ubuntu-latest] build-type: [Debug, Release] - shared: [Shared, Static] + shared: [true, false] platform: [x64] include: - platform: Win32 os: windows-latest - shared: Shared + shared: true build-type: Debug - platform: Win32 os: windows-latest - shared: Shared + shared: true build-type: Release steps: - name: Cache .hunter folder @@ -155,13 +149,13 @@ jobs: uses: actions/cache@v2 with: path: ~/.hunter/ - key: hunter-${{ matrix.os }}-${{ matrix.shared }} + key: hunter-${{ matrix.os }}-shared_${{ matrix.shared }} - name: Cache .hunter folder if: matrix.os == 'windows-latest' uses: actions/cache@v2 with: path: C:/.hunter/ - key: hunter-${{ matrix.os }}-${{ matrix.shared }} + key: hunter-${{ matrix.os }}-shared_${{ matrix.shared }} - uses: actions/checkout@v2 with: @@ -170,33 +164,23 @@ jobs: - name: Install dependencies if: matrix.os == 'macos-latest' run: | - brew install libusb opencv + brew install opencv - name: Install dependencies if: matrix.os == 'ubuntu-latest' run: | sudo apt-get update - sudo apt-get install libusb-1.0-0-dev libopencv-dev + sudo apt-get install libopencv-dev - name: Install dependencies if: matrix.os == 'windows-latest' run: | choco install opencv echo "OpenCV_DIR=C:\tools\opencv\build" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - echo "C:\tools\opencv\build\x64\vc15\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - echo "CMAKE_ARGS=-D'CMAKE_SYSTEM_VERSION=${{ env.CMAKE_WINDOWS_SDK_VERSION }}'" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - - - name: Configure ${{ matrix.build-type }}, ${{ matrix.shared }}, ${{ matrix.platform }} - if: matrix.shared == 'Shared' && matrix.os == 'windows-latest' - run: cmake -A ${{ matrix.platform }} -S . -B build -D BUILD_SHARED_LIBS=ON -D CMAKE_BUILD_TYPE=${{ matrix.build-type }} -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/depthai_install ${{ env.CMAKE_ARGS }} - - - name: Configure ${{ matrix.build-type }}, ${{ matrix.shared }} - if: matrix.shared == 'Shared' && matrix.os != 'windows-latest' - run: cmake -S . -B build -D BUILD_SHARED_LIBS=ON -D CMAKE_BUILD_TYPE=${{ matrix.build-type }} -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/depthai_install ${{ env.CMAKE_ARGS }} + echo "CMAKE_GENERATOR_PLATFORM=${{ matrix.platform }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - - name: Configure ${{ matrix.build-type }}, ${{ matrix.shared }} - if: matrix.shared == 'Static' - run: cmake -S . -B build -D BUILD_SHARED_LIBS=OFF -D CMAKE_BUILD_TYPE=${{ matrix.build-type }} -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/depthai_install ${{ env.CMAKE_ARGS }} + - name: Configure ${{ matrix.build-type }}, shared ${{ matrix.shared }}, ${{ matrix.platform }} + run: cmake -S . -B build -D BUILD_SHARED_LIBS=${{ matrix.shared}} -D CMAKE_BUILD_TYPE=${{ matrix.build-type }} -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/depthai_install ${{ env.CMAKE_ARGS }} - name: Set path to shared library dll (Windows) if: matrix.os == 'windows-latest' From d754fe9b7b50b774dd97cb0b6b9490a2858a9081 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Thu, 9 Jun 2022 04:31:29 +0200 Subject: [PATCH 39/69] Reworked boot header flashing functions to be easier to use --- include/depthai/device/DeviceBootloader.hpp | 15 ++++++++------- src/device/DeviceBootloader.cpp | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/depthai/device/DeviceBootloader.hpp b/include/depthai/device/DeviceBootloader.hpp index f2dd9f31a..a9ad09a9f 100644 --- a/include/depthai/device/DeviceBootloader.hpp +++ b/include/depthai/device/DeviceBootloader.hpp @@ -314,25 +314,26 @@ class DeviceBootloader { /** * Flash optimized boot header * @param memory Which memory to flasht the header to - * @param offset Offset in memory to flash the header to. Defaults to offset of boot header + * @param frequency SPI specific parameter, frequency in MHz * @param location Target location the header should boot to. Default to location of bootloader * @param dummyCycles SPI specific parameter - * @param frequency SPI specific parameter, frequency in MHz - * @return std::tuple + * @param offset Offset in memory to flash the header to. Defaults to offset of boot header + * @returns status as std::tuple */ - std::tuple flashBootHeader(Memory memory, int64_t offset = -1, int64_t location = -1, int32_t dummyCycles = -1, int32_t frequency = -1); + std::tuple flashBootHeader(Memory memory, int32_t frequency = -1, int64_t location = -1, int32_t dummyCycles = -1, int64_t offset = -1); /** * Flash fast boot header. Application must already be present in flash, or location must be specified manually. * Note - Can soft brick your device if firmware location changes. * @param memory Which memory to flash the header to - * @param offset Offset in memory to flash the header to. Defaults to offset of boot header + * @param frequency SPI specific parameter, frequency in MHz * @param location Target location the header should boot to. Default to location of bootloader * @param dummyCycles SPI specific parameter - * @param frequency SPI specific parameter, frequency in MHz + * @param offset Offset in memory to flash the header to. Defaults to offset of boot header + * @returns status as std::tuple */ std::tuple flashFastBootHeader( - Memory memory, int64_t offset = -1, int64_t location = -1, int32_t dummyCycles = -1, int32_t frequency = -1); + Memory memory, int32_t frequency = -1, int64_t location = -1, int32_t dummyCycles = -1, int64_t offset = -1); /** * Flash arbitrary data at custom offset in specified memory diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index 65c3a5875..a2b18a5fd 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -838,7 +838,7 @@ std::tuple DeviceBootloader::flashUsbRecoveryBootHeader(Memor return {resp.success, resp.errorMsg}; } -std::tuple DeviceBootloader::flashBootHeader(Memory memory, int64_t offset, int64_t location, int32_t dummyCycles, int32_t frequency) { +std::tuple DeviceBootloader::flashBootHeader(Memory memory, int32_t frequency, int64_t location, int32_t dummyCycles, int64_t offset) { // TODO(themarpe) - use memory param (void)memory; @@ -858,7 +858,7 @@ std::tuple DeviceBootloader::flashBootHeader(Memory memory, i return {resp.success, resp.errorMsg}; } -std::tuple DeviceBootloader::flashFastBootHeader(Memory memory, int64_t offset, int64_t location, int32_t dummyCycles, int32_t frequency) { +std::tuple DeviceBootloader::flashFastBootHeader(Memory memory, int32_t frequency, int64_t location, int32_t dummyCycles, int64_t offset) { // TODO(themarpe) - use memory param (void)memory; From c17aa8e57cb5bbf32418b90fe4f7cf509747764d Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Fri, 10 Jun 2022 01:42:27 +0200 Subject: [PATCH 40/69] Updated flash_boot_header example --- examples/bootloader/flash_boot_header.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/bootloader/flash_boot_header.cpp b/examples/bootloader/flash_boot_header.cpp index 4446fdd66..2acb8fd6d 100644 --- a/examples/bootloader/flash_boot_header.cpp +++ b/examples/bootloader/flash_boot_header.cpp @@ -12,8 +12,8 @@ int main(int argc, char** argv) { std::cout << "\tOptions:\n"; std::cout << "\t\t" << argv[0] << " GPIO_MODE gpioModeNum" << std::endl; std::cout << "\t\t" << argv[0] << " USB_RECOVERY" << std::endl; - std::cout << "\t\t" << argv[0] << " NORMAL [offset] [location] [dummyCycles] [frequency]" << std::endl; - std::cout << "\t\t" << argv[0] << " FAST [offset] [location] [dummyCycles] [frequency]" << std::endl; + std::cout << "\t\t" << argv[0] << " NORMAL [frequency] [location] [dummyCycles] [offset]" << std::endl; + std::cout << "\t\t" << argv[0] << " FAST [frequency] [location] [dummyCycles] [offset]" << std::endl; return 0; } std::string mode{argv[1]}; @@ -34,7 +34,7 @@ int main(int argc, char** argv) { flash = [](dai::DeviceBootloader& bl) { return bl.flashUsbRecoveryBootHeader(dai::DeviceBootloader::Memory::FLASH); }; } else if(mode == "normal" || mode == "fast") { if(argc != 2 && argc != 3 && argc <= 3) { - std::cout << "Usage: " << argv[0] << " NORMAL/FAST [offset] [location] [dummyCycles] [frequency]" << std::endl; + std::cout << "Usage: " << argv[0] << " NORMAL/FAST [frequency] [location] [dummyCycles] [offset]" << std::endl; std::cout << "Usage: " << argv[0] << " NORMAL/FAST [frequency]" << std::endl; return 0; } @@ -61,11 +61,11 @@ int main(int argc, char** argv) { if(mode == "normal") { flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) { - return bl.flashBootHeader(dai::DeviceBootloader::Memory::FLASH, offset, location, dummyCycles, frequency); + return bl.flashBootHeader(dai::DeviceBootloader::Memory::FLASH, frequency, location, dummyCycles, offset); }; } else if(mode == "fast") { flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) { - return bl.flashFastBootHeader(dai::DeviceBootloader::Memory::FLASH, offset, location, dummyCycles, frequency); + return bl.flashFastBootHeader(dai::DeviceBootloader::Memory::FLASH, frequency, location, dummyCycles, offset); }; } } From ed357c24b015a95170c67e501aa586b5449275de Mon Sep 17 00:00:00 2001 From: Erol444 Date: Tue, 14 Jun 2022 17:36:05 +0200 Subject: [PATCH 41/69] Added overload for the setBlob function --- include/depthai/pipeline/node/NeuralNetwork.hpp | 8 ++++++++ src/pipeline/node/NeuralNetwork.cpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/include/depthai/pipeline/node/NeuralNetwork.hpp b/include/depthai/pipeline/node/NeuralNetwork.hpp index 171bbb072..407f962c4 100644 --- a/include/depthai/pipeline/node/NeuralNetwork.hpp +++ b/include/depthai/pipeline/node/NeuralNetwork.hpp @@ -72,6 +72,14 @@ class NeuralNetwork : public NodeCRTPnetworkOpenvinoVersion = blob.version; auto asset = assetManager.set("__blob", std::move(blob.data)); From 15da903ba3f8489d03fd0ece9fb331f9cc50f81c Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Thu, 16 Jun 2022 04:48:14 +0200 Subject: [PATCH 42/69] Fixed wrong rpath for installed depthai library --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab7b1f9f5..a00566179 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -585,6 +585,14 @@ configure_file(cmake/${PROJECT_NAME}Config.cmake.in ${PROJECT_NAME}Config.cmake set(DEPTHAI_DEPENDENCIES_INSTALLATION_PATH_REL "./dependencies") configure_file(cmake/${PROJECT_NAME}Config.cmake.in _install/${PROJECT_NAME}Config.cmake @ONLY) +# Modify RPath to point to the cmake/depthai/dependencies/lib +# note: macOS is APPLE and also UNIX! +if(APPLE) + set_target_properties(${TARGET_CORE_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/cmake/${PROJECT_NAME}/dependencies/lib") +elseif(UNIX) + set_target_properties(${TARGET_CORE_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib") +endif() + # Export to CMake registry if specified if(CMAKE_EXPORT_PACKAGE_REGISTRY) export(PACKAGE depthai) From 59700a1e3aef41030e9059db1a75f762244ad915 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Fri, 17 Jun 2022 00:30:46 +0200 Subject: [PATCH 43/69] Added capability to read raw EEPROM areas --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- include/depthai/device/DeviceBase.hpp | 16 +++++++++++++++ src/device/DeviceBase.cpp | 22 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index c7f9f0f27..9c9dd57a9 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "b475422afdfcb7da6c49828654f2de8add6dd276") +set(DEPTHAI_DEVICE_SIDE_COMMIT "b6ecdc6f5a272abbf8404f0afd5f921620256d97") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") diff --git a/include/depthai/device/DeviceBase.hpp b/include/depthai/device/DeviceBase.hpp index 6dceb6219..09c608b3f 100644 --- a/include/depthai/device/DeviceBase.hpp +++ b/include/depthai/device/DeviceBase.hpp @@ -559,6 +559,22 @@ class DeviceBase { */ CalibrationHandler readFactoryCalibrationOrDefault(); + /** + * Fetches the raw EEPROM data from User area + * + * @throws std::runtime_exception if any error occured + * @returns Binary dump of User area EEPROM data + */ + std::vector readCalibrationRaw(); + + /** + * Fetches the raw EEPROM data from Factory area + * + * @throws std::runtime_exception if any error occured + * @returns Binary dump of Factory area EEPROM data + */ + std::vector readFactoryCalibrationRaw(); + /** * Retrieves USB connection speed * diff --git a/src/device/DeviceBase.cpp b/src/device/DeviceBase.cpp index 830fd9dc1..3c91ec55c 100644 --- a/src/device/DeviceBase.cpp +++ b/src/device/DeviceBase.cpp @@ -1000,6 +1000,28 @@ void DeviceBase::factoryResetCalibration() { } } +std::vector DeviceBase::readCalibrationRaw() { + bool success; + std::string errorMsg; + std::vector eepromDataRaw; + std::tie(success, errorMsg, eepromDataRaw) = pimpl->rpcClient->call("readFromEepromRaw").as>>(); + if(!success) { + throw std::runtime_error(errorMsg); + } + return eepromDataRaw; +} + +std::vector DeviceBase::readFactoryCalibrationRaw() { + bool success; + std::string errorMsg; + std::vector eepromDataRaw; + std::tie(success, errorMsg, eepromDataRaw) = pimpl->rpcClient->call("readFromEepromFactoryRaw").as>>(); + if(!success) { + throw std::runtime_error(errorMsg); + } + return eepromDataRaw; +} + bool DeviceBase::startPipeline() { // Deprecated return true; From d216ea277ef123e823c57729e1ebdf4354166e2b Mon Sep 17 00:00:00 2001 From: alex-luxonis Date: Fri, 17 Jun 2022 03:04:38 +0300 Subject: [PATCH 44/69] FW: fix for Right cam on the new OAK-D-Pro-PoE and OAK-D-PoE S2, fix RGB-depth alignment when RGB streams at 12MP 4:3 full FoV (downscaled) --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 3d4fe2560..088540039 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "35d45ad291a6f988becc9663b6e8b2d58d4de24c") +set(DEPTHAI_DEVICE_SIDE_COMMIT "47275bd444a4214b11a16e7a2e268ca3dc5ce68f") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From a92c82c776864f42928f189cfc239959c5fe294a Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Fri, 17 Jun 2022 13:33:27 +0200 Subject: [PATCH 45/69] Specify CMAKE_GENERATOR to allow the PLATFORM to be taken into account --- .github/workflows/main.workflow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.workflow.yml b/.github/workflows/main.workflow.yml index fa12fbd84..151e3d1a5 100644 --- a/.github/workflows/main.workflow.yml +++ b/.github/workflows/main.workflow.yml @@ -67,6 +67,7 @@ jobs: exclude: - os: windows-latest cmake: '3.10.x' + steps: - name: Cache .hunter folder if: matrix.os != 'windows-latest' @@ -177,6 +178,7 @@ jobs: run: | choco install opencv echo "OpenCV_DIR=C:\tools\opencv\build" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + echo "CMAKE_GENERATOR=\"Visual Studio 17 2022\"" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append echo "CMAKE_GENERATOR_PLATFORM=${{ matrix.platform }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - name: Configure ${{ matrix.build-type }}, shared ${{ matrix.shared }}, ${{ matrix.platform }} From 87ac98591c30f6585bf449ed6589e5e3472dc453 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Fri, 17 Jun 2022 15:18:02 +0200 Subject: [PATCH 46/69] Reduced parallelism of test workflow --- .github/workflows/test.workflow.yml | 4 ++-- examples/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.workflow.yml b/.github/workflows/test.workflow.yml index d89f38e70..b9e294708 100644 --- a/.github/workflows/test.workflow.yml +++ b/.github/workflows/test.workflow.yml @@ -55,7 +55,7 @@ jobs: if: matrix.os != 'linux' run: | cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D HUNTER_ROOT=$HOME/.hun2_${{ matrix.flavor }} -D DEPTHAI_BUILD_EXAMPLES=ON -D DEPTHAI_BUILD_TESTS=ON -D DEPTHAI_TEST_EXAMPLES=ON - cmake --build build --parallel 8 --config Release + cmake --build build --parallel 4 --config Release cd build ctest -C Release --output-on-failure -L usb @@ -65,6 +65,6 @@ jobs: export DISPLAY=:99 xdpyinfo -display $DISPLAY >/dev/null 2>&1 || (Xvfb $DISPLAY &) cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D HUNTER_ROOT=$HOME/.hun2_${{ matrix.flavor }} -D DEPTHAI_BUILD_EXAMPLES=ON -D DEPTHAI_BUILD_TESTS=ON -D DEPTHAI_TEST_EXAMPLES=ON - cmake --build build --parallel 8 --config Release + cmake --build build --parallel 4 --config Release cd build ctest -C Release --output-on-failure -L usb diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 8b34951e2..e6570590c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -31,7 +31,7 @@ function(dai_add_example example_name example_src enable_test) # Add example add_executable(${example_name} ${example_src}) add_default_flags(${example_name} LEAN) - target_link_libraries(${example_name} PRIVATE utility depthai::opencv ${OpenCV_LIBS}) + target_link_libraries(${example_name} PRIVATE utility depthai::opencv ${OpenCV_LIBS} Threads::Threads) # Add sanitizers for example if(COMMAND add_sanitizers) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5ebd32d6a..5fb47eb96 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -46,7 +46,7 @@ function(dai_add_test test_name test_src) endif() # Link to core and Catch2 testing framework - target_link_libraries(${test_name} PRIVATE depthai-core Catch2::Catch2) + target_link_libraries(${test_name} PRIVATE depthai-core Catch2::Catch2 Threads::Threads) # Add sanitizers for tests as well if(COMMAND add_sanitizers) @@ -68,7 +68,7 @@ function(dai_add_test test_name test_src) add_default_flags(${test_name}_conforming LEAN) # Link to core and Catch2 testing framework - target_link_libraries(${test_name}_conforming PRIVATE depthai-core Catch2::Catch2) + target_link_libraries(${test_name}_conforming PRIVATE depthai-core Catch2::Catch2 Threads::Threads) # Set compiler c++ standard target_compile_options(${test_name}_conforming PRIVATE "${CMAKE_CXX${DAT_CXX_STANDARD}_STANDARD_COMPILE_OPTION}") From 86cd8141f23353227cc17062e0519178ec06f642 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Fri, 17 Jun 2022 16:34:55 +0200 Subject: [PATCH 47/69] Modified dll copying to copy_if_different --- examples/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- tests/integration/CMakeLists.txt | 17 +++++++---------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e6570590c..fa3214d75 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -79,7 +79,7 @@ function(dai_add_example example_name example_src enable_test) set(depthai_dll_libraries "$") endif() add_custom_command(TARGET ${example_name} POST_BUILD COMMAND - ${CMAKE_COMMAND} -E copy ${depthai_dll_libraries} $ + ${CMAKE_COMMAND} -E copy_if_different ${depthai_dll_libraries} $ COMMAND_EXPAND_LISTS ) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5fb47eb96..f04bde6db 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -107,7 +107,7 @@ function(dai_add_test test_name test_src) set(depthai_dll_libraries "$") endif() add_custom_command(TARGET ${test_name} POST_BUILD COMMAND - ${CMAKE_COMMAND} -E copy ${depthai_dll_libraries} $ + ${CMAKE_COMMAND} -E copy_if_different ${depthai_dll_libraries} $ COMMAND_EXPAND_LISTS ) endif() diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 52bd4ddf3..b9c12bbf7 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -19,15 +19,11 @@ function(add_runtime_dependencies depending_target dependency) if(WIN32) if(TARGET ${dependency}) get_property(imported_configs TARGET ${dependency} PROPERTY IMPORTED_CONFIGURATIONS) - set(dlls "") + set(depthai_dll_libraries "") foreach(cfg ${imported_configs}) get_property(dll TARGET ${dependency} PROPERTY IMPORTED_LOCATION_${cfg}) - set(dlls ${dlls} $<$:${dll}>) + set(depthai_dll_libraries ${depthai_dll_libraries} $<$:${dll}>) endforeach() - add_custom_command(TARGET ${depending_target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${dlls} - $) else() # TARGET_RUNTIME_DLLS generator expression available since CMake 3.21 if(CMAKE_VERSION VERSION_LESS "3.21") @@ -35,11 +31,12 @@ function(add_runtime_dependencies depending_target dependency) else() set(depthai_dll_libraries "$") endif() - add_custom_command(TARGET ${depending_target} POST_BUILD COMMAND - ${CMAKE_COMMAND} -E copy ${depthai_dll_libraries} $ - COMMAND_EXPAND_LISTS - ) endif() + # Copy the required dlls + add_custom_command(TARGET ${depending_target} POST_BUILD COMMAND + ${CMAKE_COMMAND} -E copy_if_different ${depthai_dll_libraries} $ + COMMAND_EXPAND_LISTS + ) endif() endfunction() From 2edc55acb32b0f8bdd893d8248555f309952af91 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 20 Jun 2022 12:42:52 +0200 Subject: [PATCH 48/69] Updated GENERATOR env var for windows-latest --- .github/workflows/main.workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.workflow.yml b/.github/workflows/main.workflow.yml index 151e3d1a5..4c3d206e2 100644 --- a/.github/workflows/main.workflow.yml +++ b/.github/workflows/main.workflow.yml @@ -178,7 +178,7 @@ jobs: run: | choco install opencv echo "OpenCV_DIR=C:\tools\opencv\build" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - echo "CMAKE_GENERATOR=\"Visual Studio 17 2022\"" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + echo "CMAKE_GENERATOR=Visual Studio 17 2022" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append echo "CMAKE_GENERATOR_PLATFORM=${{ matrix.platform }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - name: Configure ${{ matrix.build-type }}, shared ${{ matrix.shared }}, ${{ matrix.platform }} From dde4b3edbcd1292bad3c7fe7baf0d1f015334635 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 20 Jun 2022 18:48:58 +0200 Subject: [PATCH 49/69] Added a guard for integration tests wrt OpenCV support --- tests/integration/CMakeLists.txt | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index b9c12bbf7..8277c4cc3 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -40,19 +40,22 @@ function(add_runtime_dependencies depending_target dependency) endif() endfunction() +include(CTest) +enable_testing() + # Create target dependant on depthai::core add_executable(integration-test-core src/main.cpp) target_link_libraries(integration-test-core PRIVATE depthai::core) - -# Create target dependant on depthai::opencv -add_executable(integration-test-opencv src/main.cpp) -target_link_libraries(integration-test-opencv PRIVATE depthai::opencv) - -# Add runtime dependencies add_runtime_dependencies(integration-test-core usb-1.0) -add_runtime_dependencies(integration-test-opencv usb-1.0) - -include(CTest) -enable_testing() add_test(integration-test-core integration-test-core) -add_test(integration-test-opencv integration-test-opencv) \ No newline at end of file + +# Create target dependant on depthai::opencv (if available) +if(TARGET depthai::opencv) + add_executable(integration-test-opencv src/main.cpp) + target_link_libraries(integration-test-opencv PRIVATE depthai::opencv) + add_runtime_dependencies(integration-test-opencv usb-1.0) + add_test(integration-test-opencv integration-test-opencv) +elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + # Make sure that DepthAI OpenCV support is avaible with x64 + message(FATAL_ERROR "Integration test targeting x64 assumes opencv support to be available, which seems to be missing.") +endif() From 6ad19aac417297fa160b9aeab5b62a2542bbf9ab Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 20 Jun 2022 20:48:28 +0200 Subject: [PATCH 50/69] Updated Windows dependency management and CI --- .github/workflows/main.workflow.yml | 6 +++--- .github/workflows/test.workflow.yml | 4 ++-- tests/integration/CMakeLists.txt | 31 ++++++++++++++--------------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.github/workflows/main.workflow.yml b/.github/workflows/main.workflow.yml index 4c3d206e2..9a41632f0 100644 --- a/.github/workflows/main.workflow.yml +++ b/.github/workflows/main.workflow.yml @@ -210,21 +210,21 @@ jobs: cmake -S tests/integration/ -B tests/integration/build_add_subdirectory -D TEST_FIND_PACKAGE=OFF ${{ env.CMAKE_ARGS }} cmake --build tests/integration/build_add_subdirectory --config ${{ matrix.build-type }} --parallel 4 cd tests/integration/build_add_subdirectory - ctest -C ${{ matrix.build-type }} --output-on-failure + ctest -C ${{ matrix.build-type }} --output-on-failure --no-tests=error - name: Build and test find_package (installed) run: | cmake -S tests/integration/ -B tests/integration/build_find_package -D TEST_FIND_PACKAGE=ON -D depthai_DIR=$GITHUB_WORKSPACE/depthai_install/lib/cmake/depthai ${{ env.CMAKE_ARGS }} cmake --build tests/integration/build_find_package --config ${{ matrix.build-type }} --parallel 4 cd tests/integration/build_find_package - ctest -C ${{ matrix.build-type }} --output-on-failure + ctest -C ${{ matrix.build-type }} --output-on-failure --no-tests=error - name: Build and test find_package (build directory) run: | cmake -S tests/integration/ -B tests/integration/build_find_package_2 -D TEST_FIND_PACKAGE=ON -D depthai_DIR=$GITHUB_WORKSPACE/build ${{ env.CMAKE_ARGS }} cmake --build tests/integration/build_find_package_2 --config ${{ matrix.build-type }} --parallel 4 cd tests/integration/build_find_package_2 - ctest -C ${{ matrix.build-type }} --output-on-failure + ctest -C ${{ matrix.build-type }} --output-on-failure --no-tests=error release: diff --git a/.github/workflows/test.workflow.yml b/.github/workflows/test.workflow.yml index b9e294708..8ba4199b1 100644 --- a/.github/workflows/test.workflow.yml +++ b/.github/workflows/test.workflow.yml @@ -57,7 +57,7 @@ jobs: cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D HUNTER_ROOT=$HOME/.hun2_${{ matrix.flavor }} -D DEPTHAI_BUILD_EXAMPLES=ON -D DEPTHAI_BUILD_TESTS=ON -D DEPTHAI_TEST_EXAMPLES=ON cmake --build build --parallel 4 --config Release cd build - ctest -C Release --output-on-failure -L usb + ctest -C Release --output-on-failure -L usb --no-tests=error - name: Configure, Build and Test if: matrix.os == 'linux' @@ -67,4 +67,4 @@ jobs: cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D HUNTER_ROOT=$HOME/.hun2_${{ matrix.flavor }} -D DEPTHAI_BUILD_EXAMPLES=ON -D DEPTHAI_BUILD_TESTS=ON -D DEPTHAI_TEST_EXAMPLES=ON cmake --build build --parallel 4 --config Release cd build - ctest -C Release --output-on-failure -L usb + ctest -C Release --output-on-failure -L usb --no-tests=error diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 8277c4cc3..138220e6d 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -17,24 +17,21 @@ endif() # Helper function function(add_runtime_dependencies depending_target dependency) if(WIN32) - if(TARGET ${dependency}) - get_property(imported_configs TARGET ${dependency} PROPERTY IMPORTED_CONFIGURATIONS) - set(depthai_dll_libraries "") - foreach(cfg ${imported_configs}) - get_property(dll TARGET ${dependency} PROPERTY IMPORTED_LOCATION_${cfg}) - set(depthai_dll_libraries ${depthai_dll_libraries} $<$:${dll}>) - endforeach() + get_property(imported_configs TARGET ${dependency} PROPERTY IMPORTED_CONFIGURATIONS) + set(dlls "") + foreach(cfg ${imported_configs}) + get_property(dll TARGET ${dependency} PROPERTY IMPORTED_LOCATION_${cfg}) + set(dlls ${depthai_dll_libraries} $<$:${dll}>) + endforeach() + # TARGET_RUNTIME_DLLS generator expression available since CMake 3.21 + if(CMAKE_VERSION VERSION_LESS "3.21") + file(GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX}/bin/*.dll") else() - # TARGET_RUNTIME_DLLS generator expression available since CMake 3.21 - if(CMAKE_VERSION VERSION_LESS "3.21") - file(GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX}/bin/*.dll") - else() - set(depthai_dll_libraries "$") - endif() + set(depthai_dll_libraries "$") endif() # Copy the required dlls add_custom_command(TARGET ${depending_target} POST_BUILD COMMAND - ${CMAKE_COMMAND} -E copy_if_different ${depthai_dll_libraries} $ + ${CMAKE_COMMAND} -E copy_if_different ${dlls} ${depthai_dll_libraries} $ COMMAND_EXPAND_LISTS ) endif() @@ -55,7 +52,9 @@ if(TARGET depthai::opencv) target_link_libraries(integration-test-opencv PRIVATE depthai::opencv) add_runtime_dependencies(integration-test-opencv usb-1.0) add_test(integration-test-opencv integration-test-opencv) -elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") +elseif(NOT "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + message(STATUS "Skipping DepthAI OpenCV integration test as its not readily available on Win32 architecture.") +else() # Make sure that DepthAI OpenCV support is avaible with x64 - message(FATAL_ERROR "Integration test targeting x64 assumes opencv support to be available, which seems to be missing.") + message(FATAL_ERROR "Integration test assumes DepthAI OpenCV support to be available, which seems to be missing.") endif() From c4f048873f72f6959074e9e7d1fcadc479fdbda0 Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Tue, 21 Jun 2022 20:30:35 +0200 Subject: [PATCH 51/69] Fixed integration test --- tests/integration/CMakeLists.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 138220e6d..8c0f8a911 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -17,12 +17,14 @@ endif() # Helper function function(add_runtime_dependencies depending_target dependency) if(WIN32) - get_property(imported_configs TARGET ${dependency} PROPERTY IMPORTED_CONFIGURATIONS) - set(dlls "") - foreach(cfg ${imported_configs}) - get_property(dll TARGET ${dependency} PROPERTY IMPORTED_LOCATION_${cfg}) - set(dlls ${depthai_dll_libraries} $<$:${dll}>) - endforeach() + if(TARGET ${dependency}) + get_property(imported_configs TARGET ${dependency} PROPERTY IMPORTED_CONFIGURATIONS) + set(dlls "") + foreach(cfg ${imported_configs}) + get_property(dll TARGET ${dependency} PROPERTY IMPORTED_LOCATION_${cfg}) + set(dlls ${depthai_dll_libraries} $<$:${dll}>) + endforeach() + endif() # TARGET_RUNTIME_DLLS generator expression available since CMake 3.21 if(CMAKE_VERSION VERSION_LESS "3.21") file(GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX}/bin/*.dll") From 9350401abd19ae6903dea5d5cddec025cc4ec5f8 Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Wed, 22 Jun 2022 09:59:53 +0200 Subject: [PATCH 52/69] Fixed Win32 integration test --- tests/integration/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 8c0f8a911..2d77d20bd 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -54,7 +54,7 @@ if(TARGET depthai::opencv) target_link_libraries(integration-test-opencv PRIVATE depthai::opencv) add_runtime_dependencies(integration-test-opencv usb-1.0) add_test(integration-test-opencv integration-test-opencv) -elseif(NOT "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") +elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") message(STATUS "Skipping DepthAI OpenCV integration test as its not readily available on Win32 architecture.") else() # Make sure that DepthAI OpenCV support is avaible with x64 From de503e458016c84c243d26307b6d6e559026107f Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Fri, 17 Jun 2022 00:30:46 +0200 Subject: [PATCH 53/69] Added capability to read raw EEPROM areas --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- include/depthai/device/DeviceBase.hpp | 16 +++++++++++++++ src/device/DeviceBase.cpp | 22 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 088540039..9c9dd57a9 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "47275bd444a4214b11a16e7a2e268ca3dc5ce68f") +set(DEPTHAI_DEVICE_SIDE_COMMIT "b6ecdc6f5a272abbf8404f0afd5f921620256d97") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") diff --git a/include/depthai/device/DeviceBase.hpp b/include/depthai/device/DeviceBase.hpp index 6dceb6219..09c608b3f 100644 --- a/include/depthai/device/DeviceBase.hpp +++ b/include/depthai/device/DeviceBase.hpp @@ -559,6 +559,22 @@ class DeviceBase { */ CalibrationHandler readFactoryCalibrationOrDefault(); + /** + * Fetches the raw EEPROM data from User area + * + * @throws std::runtime_exception if any error occured + * @returns Binary dump of User area EEPROM data + */ + std::vector readCalibrationRaw(); + + /** + * Fetches the raw EEPROM data from Factory area + * + * @throws std::runtime_exception if any error occured + * @returns Binary dump of Factory area EEPROM data + */ + std::vector readFactoryCalibrationRaw(); + /** * Retrieves USB connection speed * diff --git a/src/device/DeviceBase.cpp b/src/device/DeviceBase.cpp index 830fd9dc1..3c91ec55c 100644 --- a/src/device/DeviceBase.cpp +++ b/src/device/DeviceBase.cpp @@ -1000,6 +1000,28 @@ void DeviceBase::factoryResetCalibration() { } } +std::vector DeviceBase::readCalibrationRaw() { + bool success; + std::string errorMsg; + std::vector eepromDataRaw; + std::tie(success, errorMsg, eepromDataRaw) = pimpl->rpcClient->call("readFromEepromRaw").as>>(); + if(!success) { + throw std::runtime_error(errorMsg); + } + return eepromDataRaw; +} + +std::vector DeviceBase::readFactoryCalibrationRaw() { + bool success; + std::string errorMsg; + std::vector eepromDataRaw; + std::tie(success, errorMsg, eepromDataRaw) = pimpl->rpcClient->call("readFromEepromFactoryRaw").as>>(); + if(!success) { + throw std::runtime_error(errorMsg); + } + return eepromDataRaw; +} + bool DeviceBase::startPipeline() { // Deprecated return true; From 0139f912fa4e246b86a8bbaefaf2acb9250c5fd3 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Wed, 22 Jun 2022 17:45:35 +0200 Subject: [PATCH 54/69] EEPROMv7 fixes --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 9c9dd57a9..2c1b984d9 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "b6ecdc6f5a272abbf8404f0afd5f921620256d97") +set(DEPTHAI_DEVICE_SIDE_COMMIT "a35d3a30f927ba29486d2aad2242bc2e756b249a") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From 629bd3d6baccb00bde579d8e400652a334d2e687 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Fri, 24 Jun 2022 18:27:30 +0200 Subject: [PATCH 55/69] Updated bootloader to release 0.0.19 --- cmake/Depthai/DepthaiBootloaderConfig.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index d4eeead17..c85c30bd2 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -1,7 +1,7 @@ # Maturity level "snapshot" / "release" -# set(DEPTHAI_BOOTLOADER_MATURITY "release") -set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") +set(DEPTHAI_BOOTLOADER_MATURITY "release") +# set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" -# set(DEPTHAI_BOOTLOADER_VERSION "0.0.17") -set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+4af3b8fe5c0dc6f9a31dedac17affe2e490f81a0") +set(DEPTHAI_BOOTLOADER_VERSION "0.0.19") +# set(DEPTHAI_BOOTLOADER_VERSION "0.0.19+4af3b8fe5c0dc6f9a31dedac17affe2e490f81a0") From 55066c5078f47eea588433945c0fec2840cbe12a Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sat, 25 Jun 2022 02:38:45 +0200 Subject: [PATCH 56/69] Added host monitor thread and some isClosed preventative changes --- include/depthai/device/DeviceBase.hpp | 8 +++- include/depthai/utility/LockingQueue.hpp | 12 +++++- include/depthai/xlink/XLinkConnection.hpp | 3 +- src/device/DataQueue.cpp | 8 +++- src/device/DeviceBase.cpp | 45 +++++++++++++++++++++-- src/xlink/XLinkConnection.cpp | 6 ++- 6 files changed, 71 insertions(+), 11 deletions(-) diff --git a/include/depthai/device/DeviceBase.hpp b/include/depthai/device/DeviceBase.hpp index 09c608b3f..1d634bd40 100644 --- a/include/depthai/device/DeviceBase.hpp +++ b/include/depthai/device/DeviceBase.hpp @@ -667,11 +667,17 @@ class DeviceBase { std::thread loggingThread; std::atomic loggingRunning{true}; + // Monitor thread + std::thread monitorThread; + std::mutex lastWatchdogPingTimeMtx; + std::chrono::steady_clock::time_point lastWatchdogPingTime; + // RPC stream std::unique_ptr rpcStream; // closed - std::atomic closed{false}; + mutable std::mutex closedMtx; + bool closed{false}; // pimpl class Impl; diff --git a/include/depthai/utility/LockingQueue.hpp b/include/depthai/utility/LockingQueue.hpp index 4b3e98e05..a40179dfb 100644 --- a/include/depthai/utility/LockingQueue.hpp +++ b/include/depthai/utility/LockingQueue.hpp @@ -42,9 +42,11 @@ class LockingQueue { } void destruct() { - if(!destructed.exchange(true)) { + std::unique_lock lock(guard); + if(!destructed) { signalPop.notify_all(); signalPush.notify_all(); + destructed = true; } } ~LockingQueue() = default; @@ -57,6 +59,7 @@ class LockingQueue { // First checks predicate, then waits bool pred = signalPush.wait_for(lock, timeout, [this]() { return !queue.empty() || destructed; }); if(!pred) return false; + if(destructed) return false; // Continue here if and only if queue has any elements while(!queue.empty()) { @@ -75,6 +78,7 @@ class LockingQueue { signalPush.wait(lock, [this]() { return !queue.empty() || destructed; }); if(queue.empty()) return false; + if(destructed) return false; while(!queue.empty()) { callback(queue.front()); @@ -120,6 +124,7 @@ class LockingQueue { } } else { signalPop.wait(lock, [this]() { return queue.size() < maxSize || destructed; }); + if(destructed) return false; } queue.push(data); @@ -149,6 +154,7 @@ class LockingQueue { // First checks predicate, then waits bool pred = signalPop.wait_for(lock, timeout, [this]() { return queue.size() < maxSize || destructed; }); if(!pred) return false; + if(destructed) return false; } queue.push(data); @@ -192,6 +198,7 @@ class LockingQueue { signalPush.wait(lock, [this]() { return (!queue.empty() || destructed); }); if(queue.empty()) return false; + if(destructed) return false; value = std::move(queue.front()); queue.pop(); @@ -208,6 +215,7 @@ class LockingQueue { // First checks predicate, then waits bool pred = signalPush.wait_for(lock, timeout, [this]() { return !queue.empty() || destructed; }); if(!pred) return false; + if(destructed) return false; value = std::move(queue.front()); queue.pop(); @@ -226,7 +234,7 @@ class LockingQueue { bool blocking = true; std::queue queue; mutable std::mutex guard; - std::atomic destructed{false}; + bool destructed{false}; std::condition_variable signalPop; std::condition_variable signalPush; }; diff --git a/include/depthai/xlink/XLinkConnection.hpp b/include/depthai/xlink/XLinkConnection.hpp index 61483cd9b..7173583d3 100644 --- a/include/depthai/xlink/XLinkConnection.hpp +++ b/include/depthai/xlink/XLinkConnection.hpp @@ -101,7 +101,8 @@ class XLinkConnection { DeviceInfo deviceInfo; // closed - std::atomic closed{false}; + mutable std::mutex closedMtx; + bool closed{false}; constexpr static std::chrono::milliseconds WAIT_FOR_BOOTUP_TIMEOUT{15000}; constexpr static std::chrono::milliseconds WAIT_FOR_CONNECT_TIMEOUT{5000}; diff --git a/src/device/DataQueue.cpp b/src/device/DataQueue.cpp index bb1cf4326..2fa72097c 100644 --- a/src/device/DataQueue.cpp +++ b/src/device/DataQueue.cpp @@ -53,7 +53,9 @@ DataOutputQueue::DataOutputQueue(const std::shared_ptr conn, co } // Add 'data' to queue - queue.push(data); + if(!queue.push(data)) { + throw std::runtime_error(fmt::format("Underlying queue destructed")); + } // Increment numPacketsRead numPacketsRead++; @@ -284,7 +286,9 @@ void DataInputQueue::send(const std::shared_ptr& rawMsg) { throw std::runtime_error(fmt::format("Trying to send larger ({}B) message than XLinkIn maxDataSize ({}B)", rawMsg->data.size(), maxDataSize)); } - queue.push(rawMsg); + if(!queue.push(rawMsg)) { + throw std::runtime_error(fmt::format("Underlying queue destructed")); + } } void DataInputQueue::send(const std::shared_ptr& msg) { if(!msg) throw std::invalid_argument("Message passed is not valid (nullptr)"); diff --git a/src/device/DeviceBase.cpp b/src/device/DeviceBase.cpp index 3c91ec55c..baf50eb93 100644 --- a/src/device/DeviceBase.cpp +++ b/src/device/DeviceBase.cpp @@ -366,10 +366,11 @@ DeviceBase::DeviceBase(Config config, const DeviceInfo& devInfo) : deviceInfo(de } void DeviceBase::close() { - // Only allow to close once - if(closed.exchange(true)) return; - - closeImpl(); + std::unique_lock lock(closedMtx); + if(!closed) { + closeImpl(); + closed = true; + } } void DeviceBase::closeImpl() { @@ -395,6 +396,8 @@ void DeviceBase::closeImpl() { if(timesyncThread.joinable()) timesyncThread.join(); // And at the end stop logging thread if(loggingThread.joinable()) loggingThread.join(); + // At the end stop the monitor thread + if(monitorThread.joinable()) monitorThread.join(); // Close rpcStream pimpl->rpcStream = nullptr; @@ -403,6 +406,7 @@ void DeviceBase::closeImpl() { } bool DeviceBase::isClosed() const { + std::unique_lock lock(closedMtx); return closed || !watchdogRunning; } @@ -599,12 +603,23 @@ void DeviceBase::init2(Config cfg, const dai::Path& pathToMvcmd, tl::optional std::chrono::milliseconds(0)) { + // Specify "last" ping time (5s in the future, for some grace time) + { + std::unique_lock lock(lastWatchdogPingTimeMtx); + lastWatchdogPingTime = std::chrono::steady_clock::now() + std::chrono::seconds(5); + } + + // Start watchdog thread for device watchdogThread = std::thread([this, watchdogTimeout]() { try { XLinkStream stream(connection, device::XLINK_CHANNEL_WATCHDOG, 128); std::vector watchdogKeepalive = {0, 0, 0, 0}; while(watchdogRunning) { stream.write(watchdogKeepalive); + { + std::unique_lock lock(lastWatchdogPingTimeMtx); + lastWatchdogPingTime = std::chrono::steady_clock::now(); + } // Ping with a period half of that of the watchdog timeout std::this_thread::sleep_for(watchdogTimeout / 2); } @@ -616,6 +631,28 @@ void DeviceBase::init2(Config cfg, const dai::Path& pathToMvcmd, tl::optional lock(lastWatchdogPingTimeMtx); + prevPingTime = lastWatchdogPingTime; + } + if(std::chrono::steady_clock::now() - prevPingTime > watchdogTimeout) { + spdlog::debug("Monitor thread - ping was missed, closing the device connection"); + // ping was missed, reset the device + watchdogRunning = false; + // close the underlying connection + connection->close(); + } + } + }); + } else { // Still set watchdogRunning explictitly // as it indicates device not being closed diff --git a/src/xlink/XLinkConnection.cpp b/src/xlink/XLinkConnection.cpp index 129a2cf56..ab3c16df3 100644 --- a/src/xlink/XLinkConnection.cpp +++ b/src/xlink/XLinkConnection.cpp @@ -306,6 +306,7 @@ XLinkConnection::XLinkConnection(const DeviceInfo& deviceDesc, XLinkDeviceState_ } bool XLinkConnection::isClosed() const { + std::unique_lock lock(closedMtx); return closed; } @@ -314,7 +315,8 @@ void XLinkConnection::checkClosed() const { } void XLinkConnection::close() { - if(closed.exchange(true)) return; + std::unique_lock lock(closedMtx); + if(closed) return; using namespace std::chrono; constexpr auto RESET_TIMEOUT = seconds(2); @@ -350,6 +352,8 @@ void XLinkConnection::close() { spdlog::debug("XLinkResetRemote of linkId: ({})", tmp); } + + closed = true; } XLinkConnection::~XLinkConnection() { From ffdfcc1d164e04f7dc41fd7cf92d2919b01145bb Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Tue, 28 Jun 2022 17:18:02 +0300 Subject: [PATCH 57/69] Add support for Yolo v6 decoding --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 9e5685450..bfe178aa5 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "796eb3f58b24447286ee88ba2278c52709133591") +set(DEPTHAI_DEVICE_SIDE_COMMIT "52f7331e81fc872f2191fd473adc96032675f518") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From 5458342a3509a9bfa054b026ae041898b3d7df44 Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Fri, 1 Jul 2022 01:54:30 +0300 Subject: [PATCH 58/69] Stereo: Add pixel shift option for input frame --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- shared/depthai-shared | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index bfe178aa5..8cc2a7bcf 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "52f7331e81fc872f2191fd473adc96032675f518") +set(DEPTHAI_DEVICE_SIDE_COMMIT "b9b9152331a82b3a962d6cdfa226b248fd5206f1") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") diff --git a/shared/depthai-shared b/shared/depthai-shared index cb49a5c57..190d09f0f 160000 --- a/shared/depthai-shared +++ b/shared/depthai-shared @@ -1 +1 @@ -Subproject commit cb49a5c571c2ed253dfcd0aa80564291767b7a92 +Subproject commit 190d09f0f7e2ef36664719e14c7ad419f9535ae0 From 046765fe129aa7e6f33f8a0de9136f1cd4ec1d35 Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Fri, 1 Jul 2022 18:14:12 +0300 Subject: [PATCH 59/69] Stereo: improve pixel shifting performance --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 8cc2a7bcf..f4e2b3fc6 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "b9b9152331a82b3a962d6cdfa226b248fd5206f1") +set(DEPTHAI_DEVICE_SIDE_COMMIT "5fb3c74512ab06b5c01a58a251d5e9c6318a01e8") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From e0090d60956f08bcf0cb63a7e77a45a761b8860d Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Tue, 5 Jul 2022 11:54:06 +0200 Subject: [PATCH 60/69] Fixed monitor thread warning after a proper shutdown --- src/device/DeviceBase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/device/DeviceBase.cpp b/src/device/DeviceBase.cpp index 5b5003f1b..6a57cc2ee 100644 --- a/src/device/DeviceBase.cpp +++ b/src/device/DeviceBase.cpp @@ -643,7 +643,8 @@ void DeviceBase::init2(Config cfg, const dai::Path& pathToMvcmd, tl::optional lock(lastWatchdogPingTimeMtx); prevPingTime = lastWatchdogPingTime; } - if(std::chrono::steady_clock::now() - prevPingTime > watchdogTimeout) { + // Recheck if watchdogRunning wasn't already closed + if(watchdogRunning && std::chrono::steady_clock::now() - prevPingTime > watchdogTimeout) { spdlog::warn("Monitor thread (device: {} [{}]) - ping was missed, closing the device connection", deviceInfo.mxid, deviceInfo.name); // ping was missed, reset the device watchdogRunning = false; From def822ff981a368a262ad735876077762974dcaf Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Wed, 6 Jul 2022 11:39:59 +0300 Subject: [PATCH 61/69] Update FW, add convenience functions --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- .../depthai/pipeline/datatype/StereoDepthConfig.hpp | 10 ++++++++++ include/depthai/pipeline/node/StereoDepth.hpp | 5 +++++ shared/depthai-shared | 2 +- src/pipeline/datatype/StereoDepthConfig.cpp | 6 ++++++ src/pipeline/node/StereoDepth.cpp | 4 ++++ 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index f4e2b3fc6..3fbc085f1 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "5fb3c74512ab06b5c01a58a251d5e9c6318a01e8") +set(DEPTHAI_DEVICE_SIDE_COMMIT "6821a65c99033d806e42472985c6e66985f05ca9") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") diff --git a/include/depthai/pipeline/datatype/StereoDepthConfig.hpp b/include/depthai/pipeline/datatype/StereoDepthConfig.hpp index e5da8903f..ede7c7ef6 100644 --- a/include/depthai/pipeline/datatype/StereoDepthConfig.hpp +++ b/include/depthai/pipeline/datatype/StereoDepthConfig.hpp @@ -111,6 +111,16 @@ class StereoDepthConfig : public Buffer { */ StereoDepthConfig& setDepthUnit(AlgorithmControl::DepthUnit depthUnit); + /** + * Shift input frame by a number of pixels to increase minimum depth. + * For example shifting by 48 will change effective disparity search range from (0,95] to [48,143]. + * An alternative approach to reducing the minZ. + * We normally only recommend doing this when it is known that there will be no objects + * farther away than MaxZ, such as having a depth camera mounted above a table + * pointing down at the table surface. + */ + StereoDepthConfig& setDisparityShift(int disparityShift); + /** * Get depth unit of depth map. */ diff --git a/include/depthai/pipeline/node/StereoDepth.hpp b/include/depthai/pipeline/node/StereoDepth.hpp index e4dee6805..90a0cb519 100644 --- a/include/depthai/pipeline/node/StereoDepth.hpp +++ b/include/depthai/pipeline/node/StereoDepth.hpp @@ -346,6 +346,11 @@ class StereoDepth : public NodeCRTP { * used from calibration data. */ void useHomographyRectification(bool useHomographyRectification); + + /** + * Equivalent to useHomographyRectification(!enableDistortionCorrection) + */ + void enableDistortionCorrection(bool enableDistortionCorrection); }; } // namespace node diff --git a/shared/depthai-shared b/shared/depthai-shared index 190d09f0f..3622d7faf 160000 --- a/shared/depthai-shared +++ b/shared/depthai-shared @@ -1 +1 @@ -Subproject commit 190d09f0f7e2ef36664719e14c7ad419f9535ae0 +Subproject commit 3622d7faf0438409e598d843c8e7d565fb66d57c diff --git a/src/pipeline/datatype/StereoDepthConfig.cpp b/src/pipeline/datatype/StereoDepthConfig.cpp index 69d758df1..36c962711 100644 --- a/src/pipeline/datatype/StereoDepthConfig.cpp +++ b/src/pipeline/datatype/StereoDepthConfig.cpp @@ -76,6 +76,11 @@ StereoDepthConfig& StereoDepthConfig::setDepthUnit(AlgorithmControl::DepthUnit d return *this; } +StereoDepthConfig& StereoDepthConfig::setDisparityShift(int disparityShift) { + cfg.algorithmControl.disparityShift = disparityShift; + return *this; +} + dai::StereoDepthConfig::AlgorithmControl::DepthUnit StereoDepthConfig::getDepthUnit() { return cfg.algorithmControl.depthUnit; } @@ -86,6 +91,7 @@ float StereoDepthConfig::getMaxDisparity() const { maxDisp = 63; } if(cfg.costMatching.enableCompanding) maxDisp = 175; + maxDisp += cfg.algorithmControl.disparityShift; if(cfg.algorithmControl.enableExtended) maxDisp *= 2; if(cfg.algorithmControl.enableSubpixel) maxDisp *= (1 << cfg.algorithmControl.subpixelFractionalBits); return maxDisp; diff --git a/src/pipeline/node/StereoDepth.cpp b/src/pipeline/node/StereoDepth.cpp index 55c894b8c..e017d16be 100644 --- a/src/pipeline/node/StereoDepth.cpp +++ b/src/pipeline/node/StereoDepth.cpp @@ -174,6 +174,10 @@ void StereoDepth::useHomographyRectification(bool useHomographyRectification) { properties.useHomographyRectification = useHomographyRectification; } +void StereoDepth::enableDistortionCorrection(bool enableDistortionCorrection) { + useHomographyRectification(!enableDistortionCorrection); +} + void StereoDepth::setDefaultProfilePreset(PresetMode mode) { presetMode = mode; switch(presetMode) { From f8bbd424e05ea5461658249146e14c774b83c608 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Wed, 6 Jul 2022 15:04:25 +0200 Subject: [PATCH 62/69] Added checks for Source Code downloaded package as well as package extracted under a parent git repo --- CMakeLists.txt | 14 +++++++++++--- shared/depthai-bootloader-shared.cmake | 11 +++++++++-- shared/depthai-shared.cmake | 12 ++++++++++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a00566179..2ba60b967 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,11 +128,19 @@ set(PROJECT_EXPORT_GROUP "${PROJECT_NAME}Targets") find_package(Git) if(GIT_FOUND) execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse --is-inside-work-tree + COMMAND ${GIT_EXECUTABLE} rev-parse --show-toplevel WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - RESULT_VARIABLE DEPTHAI_DOWNLOADED_SOURCES - OUTPUT_QUIET ERROR_QUIET + RESULT_VARIABLE _git_root_dir_error + OUTPUT_VARIABLE _git_root_dir + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE ) + set(DEPTHAI_DOWNLOADED_SOURCES ON) + if(_git_root_dir_error EQUAL 0 AND "${_git_root_dir}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") + set(DEPTHAI_DOWNLOADED_SOURCES OFF) + endif() + message(DEBUG "Git root dir (${_git_root_dir_error}): ${_git_root_dir}") + message(DEBUG "DepthAI as downloaded sources: ${DEPTHAI_DOWNLOADED_SOURCES}") execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} diff --git a/shared/depthai-bootloader-shared.cmake b/shared/depthai-bootloader-shared.cmake index 0d909473a..d0db90509 100644 --- a/shared/depthai-bootloader-shared.cmake +++ b/shared/depthai-bootloader-shared.cmake @@ -30,7 +30,7 @@ if(GIT_FOUND AND NOT DEPTHAI_DOWNLOADED_SOURCES) ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) string(SUBSTRING ${statusCommit} 0 1 status) - if(${status} STREQUAL "-") + if("${status}" STREQUAL "-") message(FATAL_ERROR "Submodule 'depthai-bootloader-shared' not initialized/updated. Run 'git submodule update --init --recursive' first") endif() endif() @@ -49,4 +49,11 @@ if(GIT_FOUND AND NOT DEPTHAI_DOWNLOADED_SOURCES) else() set(DEPTHAI_BOOTLOADER_SHARED_COMMIT_FOUND FALSE) endif() -endif() \ No newline at end of file +endif() + +# Make sure files exist +foreach(source_file ${DEPTHAI_BOOTLOADER_SHARED_SOURCES}) + if(NOT EXISTS ${source_file}) + message(FATAL_ERROR "depthai-bootloader-shared submodule files missing. Make sure to download prepackaged release instead of \"Source code\" on GitHub. Example: depthai-core-vX.Y.Z.tar.gz") + endif() +endforeach() \ No newline at end of file diff --git a/shared/depthai-shared.cmake b/shared/depthai-shared.cmake index 5f48ced90..72f46ce99 100644 --- a/shared/depthai-shared.cmake +++ b/shared/depthai-shared.cmake @@ -36,7 +36,7 @@ if(GIT_FOUND AND NOT DEPTHAI_DOWNLOADED_SOURCES) ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) string(SUBSTRING ${statusCommit} 0 1 status) - if(${status} STREQUAL "-") + if("${status}" STREQUAL "-") message(FATAL_ERROR "Submodule 'depthai-shared' not initialized/updated. Run 'git submodule update --init --recursive' first") endif() endif() @@ -55,4 +55,12 @@ if(GIT_FOUND AND NOT DEPTHAI_DOWNLOADED_SOURCES) else() set(DEPTHAI_SHARED_COMMIT_FOUND FALSE) endif() -endif() \ No newline at end of file +endif() + +# Make sure files exist +foreach(source_file ${DEPTHAI_SHARED_SOURCES}) + message(STATUS "Checking file: ${source_file}") + if(NOT EXISTS ${source_file}) + message(FATAL_ERROR "depthai-shared submodule files missing. Make sure to download prepackaged release instead of \"Source code\" on GitHub. Example: depthai-core-vX.Y.Z.tar.gz") + endif() +endforeach() \ No newline at end of file From 55daf871130c25bcb6aa73335ea119b813be9bd0 Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Wed, 6 Jul 2022 20:33:41 +0300 Subject: [PATCH 63/69] Update FW: Fix static frame input from host with RGB alignment and stereo --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 3fbc085f1..823fc555c 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "6821a65c99033d806e42472985c6e66985f05ca9") +set(DEPTHAI_DEVICE_SIDE_COMMIT "33cc407af320f00d4c0ccc3f49eda8289342105d") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From 831565552dddc1d707b9f483afa23ec81b3e2819 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 11 Jul 2022 03:25:03 +0200 Subject: [PATCH 64/69] Updated XLink library to allow running without USB capabilities --- cmake/Hunter/config.cmake | 4 ++-- src/utility/Initialization.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake index 85f9a5c35..8905019ea 100644 --- a/cmake/Hunter/config.cmake +++ b/cmake/Hunter/config.cmake @@ -8,8 +8,8 @@ hunter_config( hunter_config( XLink VERSION "luxonis-2021.4.2-develop" - URL "https://github.com/luxonis/XLink/archive/9fcd6dc8b7d0f95d892b059c0c938c97bc9da6dc.tar.gz" - SHA1 "6a4187839a94b948db3d7cc94a7e8e8651573ef4" + URL "https://github.com/luxonis/XLink/archive/117fdee6990dfbf7ad7e056775df75f91ac902aa.tar.gz" + SHA1 "edc1fd791e2e3f02df8d22adf9e297111adc734a" ) hunter_config( diff --git a/src/utility/Initialization.cpp b/src/utility/Initialization.cpp index dc3cdbac8..af35ef70d 100644 --- a/src/utility/Initialization.cpp +++ b/src/utility/Initialization.cpp @@ -99,15 +99,22 @@ bool initialize(const char* additionalInfo, bool installSignalHandler, void* jav xlinkGlobalHandler.protocol = X_LINK_USB_VSC; xlinkGlobalHandler.options = javavm; auto status = XLinkInitialize(&xlinkGlobalHandler); + std::string errorMsg; + const auto ERROR_MSG_USB_TIP = fmt::format("If running in a container, make sure that the following is set: \"{}\"", + "-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule='c 189:* rmw'"); if(X_LINK_SUCCESS != status) { std::string errorMsg = fmt::format("Couldn't initialize XLink: {}. ", XLinkErrorToStr(status)); if(status == X_LINK_INIT_USB_ERROR) { - errorMsg += fmt::format("If running in a container, make sure that the following is set: \"{}\"", - "-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule='c 189:* rmw'"); + errorMsg += ERROR_MSG_USB_TIP; } spdlog::debug("Initialize failed - {}", errorMsg); throw std::runtime_error(errorMsg); } + // Check that USB protocol is available + if(!XLinkIsProtocolInitialized(X_LINK_USB_VSC)) { + spdlog::warn("USB protocol not available - {}", ERROR_MSG_USB_TIP); + } + // Suppress XLink related errors mvLogDefaultLevelSet(MVLOG_FATAL); From 5136a452dac64624cfd51723494657783a7d6ea1 Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Mon, 11 Jul 2022 12:48:52 +0300 Subject: [PATCH 65/69] Update FW: yolov7 support --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 8f276179c..16e50ca13 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "c9cb313f127e628d213a4d830a78250b8eb57a15") +set(DEPTHAI_DEVICE_SIDE_COMMIT "adc0375d7ec059f253627e076edc4aab7f7a1a6b") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") From 1589735f5f8a808d355d88672f20a3963f39fb1c Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 11 Jul 2022 15:30:23 +0200 Subject: [PATCH 66/69] Updated bootloader_version example --- examples/bootloader/bootloader_version.cpp | 32 +++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/examples/bootloader/bootloader_version.cpp b/examples/bootloader/bootloader_version.cpp index 615f155b9..3ac84523c 100644 --- a/examples/bootloader/bootloader_version.cpp +++ b/examples/bootloader/bootloader_version.cpp @@ -10,18 +10,30 @@ int main(int argc, char** argv) { dai::DeviceBootloader bl(info); std::cout << "Version: " << bl.getVersion().toString() << std::endl; - for(const auto& mem : {dai::DeviceBootloader::Memory::FLASH, dai::DeviceBootloader::Memory::EMMC}) { - std::cout << std::endl; - auto memoryInfo = bl.getMemoryInfo(mem); - if(memoryInfo.available) { - std::cout << "Memory '" << mem << "' size: " << memoryInfo.size << ", info: " << memoryInfo.info << std::endl; + auto supportedMemTypes = {dai::DeviceBootloader::Memory::FLASH, dai::DeviceBootloader::Memory::EMMC}; + if(bl.getType() == dai::DeviceBootloader::Type::USB){ + std::cout << "USB Bootloader - supports only Flash memory" << std::endl; + supportedMemTypes = {dai::DeviceBootloader::Memory::FLASH}; + } else { + std::cout << "NETWORK Bootloader" << std::endl; + } + + try { + for(const auto& mem : supportedMemTypes) { + std::cout << std::endl; + auto memoryInfo = bl.getMemoryInfo(mem); + if(memoryInfo.available) { + std::cout << "Memory '" << mem << "' size: " << memoryInfo.size << ", info: " << memoryInfo.info << std::endl; - auto appInfo = bl.readApplicationInfo(mem); - std::cout << "Application, flashed: " << appInfo.hasApplication << " firmware version: " << appInfo.firmwareVersion - << " application name: " << appInfo.applicationName << std::endl; - } else { - std::cout << "Memory '" << mem << "' not available..." << std::endl; + auto appInfo = bl.readApplicationInfo(mem); + std::cout << "Application, flashed: " << appInfo.hasApplication << " firmware version: " << appInfo.firmwareVersion + << " application name: " << appInfo.applicationName << std::endl; + } else { + std::cout << "Memory '" << mem << "' not available..." << std::endl; + } } + } catch(const std::exception& ex) { + std::cout << "Couldn't retrieve memory details: " << ex.what() << std::endl; } } else { std::cout << "No devices found" << std::endl; From faaaeff8f69106ddf1787d99943c08c920d8728e Mon Sep 17 00:00:00 2001 From: alex-luxonis Date: Mon, 11 Jul 2022 17:20:57 +0300 Subject: [PATCH 67/69] FW: support for the new S2/Pro devices, including OV9782 on RGB socket --- cmake/Depthai/DepthaiDeviceSideConfig.cmake | 2 +- shared/depthai-shared | 2 +- src/pipeline/node/ColorCamera.cpp | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 16e50ca13..2a382ca2f 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "adc0375d7ec059f253627e076edc4aab7f7a1a6b") +set(DEPTHAI_DEVICE_SIDE_COMMIT "87b278f6d491234baae352f7cdf3dd0dc7791bba") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") diff --git a/shared/depthai-shared b/shared/depthai-shared index c30f5bd1d..6b14f7b7e 160000 --- a/shared/depthai-shared +++ b/shared/depthai-shared @@ -1 +1 @@ -Subproject commit c30f5bd1df960c2bc3e23a3c20c10ae1e125ec35 +Subproject commit 6b14f7b7e2f2fa0d4d36a216c854c1a1a58fcc83 diff --git a/src/pipeline/node/ColorCamera.cpp b/src/pipeline/node/ColorCamera.cpp index 7a5d7d8ce..7a895d327 100644 --- a/src/pipeline/node/ColorCamera.cpp +++ b/src/pipeline/node/ColorCamera.cpp @@ -295,6 +295,14 @@ std::tuple ColorCamera::getResolutionSize() const { case ColorCameraProperties::SensorResolution::THE_13_MP: return {4208, 3120}; break; + + case ColorCameraProperties::SensorResolution::THE_720_P: + return {1280, 720}; + break; + + case ColorCameraProperties::SensorResolution::THE_800_P: + return {1280, 800}; + break; } return {1920, 1080}; From 100cfcddc24571455e1afee338b9bfb601163edb Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 11 Jul 2022 17:06:50 +0200 Subject: [PATCH 68/69] Updated bootloader_config example --- examples/bootloader/bootloader_config.cpp | 52 ++++++++++++----------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/examples/bootloader/bootloader_config.cpp b/examples/bootloader/bootloader_config.cpp index 9c1901945..4d5272ee0 100644 --- a/examples/bootloader/bootloader_config.cpp +++ b/examples/bootloader/bootloader_config.cpp @@ -39,34 +39,38 @@ int main(int argc, char** argv) { std::cout << "Found device with name: " << info.name << std::endl; dai::DeviceBootloader bl(info); - if(read) { - std::cout << "Current flashed configuration\n" << bl.readConfigData().dump(4) << std::endl; - } else { - std::cout << "Warning! Flashing bootloader config can potentially soft brick your device and should be done with caution." << std::endl; - std::cout << "Do not unplug your device while the bootloader config is flashing." << std::endl; - std::cout << "Type 'y' and press enter to proceed, otherwise exits: "; - std::cin.ignore(); - if(std::cin.get() != 'y') { - std::cout << "Prompt declined, exiting..." << std::endl; - return -1; - } - - bool success; - std::string error; - if(clear) { - std::tie(success, error) = bl.flashConfigClear(); + try { + if(read) { + std::cout << "Current flashed configuration\n" << bl.readConfigData().dump(4) << std::endl; } else { - if(path.empty()) { - std::tie(success, error) = bl.flashConfig(dai::DeviceBootloader::Config{}); + std::cout << "Warning! Flashing bootloader config can potentially soft brick your device and should be done with caution." << std::endl; + std::cout << "Do not unplug your device while the bootloader config is flashing." << std::endl; + std::cout << "Type 'y' and press enter to proceed, otherwise exits: "; + std::cin.ignore(); + if(std::cin.get() != 'y') { + std::cout << "Prompt declined, exiting..." << std::endl; + return -1; + } + + bool success; + std::string error; + if(clear) { + std::tie(success, error) = bl.flashConfigClear(); } else { - std::tie(success, error) = bl.flashConfigFile(path); + if(path.empty()) { + std::tie(success, error) = bl.flashConfig(dai::DeviceBootloader::Config{}); + } else { + std::tie(success, error) = bl.flashConfigFile(path); + } + } + if(success) { + std::cout << "Successfully flashed bootloader configuration\n"; + } else { + std::cout << "Error flashing bootloader configuration: " << error; } } - if(success) { - std::cout << "Successfully flashed bootloader configuration\n"; - } else { - std::cout << "Error flashing bootloader configuration: " << error; - } + } catch (const std::exception& ex) { + std::cout << "Error accessing config: " << ex.what() << std::endl; } } else { From b63ee54e4ad0b5921b60dfbce1ff9b2660207a91 Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Tue, 12 Jul 2022 00:27:27 +0300 Subject: [PATCH 69/69] Release v2.17.0 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ba60b967..ec1d5bed2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ if(WIN32) endif() # Create depthai project -project(depthai VERSION "2.16.0" LANGUAGES CXX C) +project(depthai VERSION "2.17.0" LANGUAGES CXX C) get_directory_property(has_parent PARENT_DIRECTORY) if(has_parent) set(DEPTHAI_VERSION ${PROJECT_VERSION} PARENT_SCOPE)