4 #include "XLink/XLink.h"
11 return "X_LINK_USB_VSC";
13 return "X_LINK_USB_CDC";
19 return "X_LINK_TCP_IP";
20 case X_LINK_NMB_OF_PROTOCOLS:
21 return "X_LINK_NMB_OF_PROTOCOLS";
22 case X_LINK_ANY_PROTOCOL:
23 return "X_LINK_ANY_PROTOCOL";
25 return "INVALID_ENUM_VALUE";
30 int main(
int argc,
char** argv) {
31 using namespace std::chrono;
35 std::string blTypeStr(argv[1]);
36 if(blTypeStr ==
"usb") {
37 blType = dai::DeviceBootloader::Type::USB;
38 }
else if(blTypeStr ==
"network") {
39 blType = dai::DeviceBootloader::Type::NETWORK;
41 std::cout <<
"Specify either 'usb' or 'network' bootloader type\n";
48 if(deviceInfos.empty()) {
49 std::cout <<
"No device found to flash. Exiting." << std::endl;
52 for(
int i = 0; i < deviceInfos.size(); i++) {
53 const auto& devInfo = deviceInfos[i];
54 std::cout <<
"[" << i <<
"] " << devInfo.getMxId() <<
"[" <<
ProtocolToStr(devInfo.protocol) <<
"]";
55 if(devInfo.state == X_LINK_BOOTLOADER) {
57 std::cout <<
" current bootloader: " << bl.
getVersion();
59 std::cout << std::endl;
62 std::cout <<
"Which DepthAI device to flash bootloader for [0.." << deviceInfos.size() - 1 <<
"]\n";
64 info = deviceInfos[selected];
67 bool hasBootloader = (
info.state == X_LINK_BOOTLOADER);
69 std::cout <<
"Warning! Flashing bootloader can potentially soft brick your device and should be done with caution." << std::endl;
70 std::cout <<
"Do not unplug your device while the bootloader is flashing." << std::endl;
71 std::cout <<
"Type 'y' and press enter to proceed, otherwise exits: ";
73 if(std::cin.
get() !=
'y') {
74 std::cout <<
"Prompt declined, exiting..." << std::endl;
80 std::cout <<
"Booting latest bootloader first, will take a tad longer..." << std::endl;
82 auto currentBlType = bl.
getType();
85 blType = currentBlType;
89 if(currentBlType != blType && hasBootloader) {
90 std::cout <<
"Are you sure you want to flash '" << blType <<
"' bootloader over current '" << currentBlType <<
"' bootloader?" << std::endl;
91 std::cout <<
"Type 'y' and press enter to proceed, otherwise exits: ";
93 if(std::cin.
get() !=
'y') {
94 std::cout <<
"Prompt declined, exiting..." << std::endl;
100 auto progress = [](
float p) { std::cout <<
"Flashing Progress..." << p * 100 <<
"%" << std::endl; };
102 std::cout <<
"Flashing " << blType <<
" bootloader..." << std::endl;
103 auto t1 = steady_clock::now();
104 bool success =
false;
106 std::tie(success, message) = bl.
flashBootloader(dai::DeviceBootloader::Memory::FLASH, blType, progress);
108 std::cout <<
"Flashing successful. Took " << duration_cast<milliseconds>(steady_clock::now() - t1).count() <<
"ms" << std::endl;
110 std::cout <<
"Flashing failed: " << message << std::endl;