bootloader_config.cpp
Go to the documentation of this file.
1 #include "depthai/depthai.hpp"
2 
3 int main(int argc, char** argv) {
4  // Options
5  bool usage = false, read = true, clear = false;
6  std::string path = "";
7  if(argc >= 2) {
8  std::string op = argv[1];
9  if(op == "read") {
10  read = true;
11  } else if(op == "flash") {
12  read = false;
13  if(argc >= 3) {
14  path = argv[2];
15  }
16  } else if(op == "clear") {
17  clear = true;
18  read = false;
19  } else if(op == "clear") {
20  clear = true;
21  read = false;
22  } else {
23  usage = true;
24  }
25  } else {
26  usage = true;
27  }
28  if(usage) {
29  std::cout << "Usage: " << argv[0] << " [read/flash/clear] [flash: path/to/config/json]" << std::endl;
30  return -1;
31  }
32 
33  // DeviceBootloader configuration
34  bool res = false;
37 
38  if(res) {
39  std::cout << "Found device with name: " << info.name << std::endl;
41 
42  try {
43  if(read) {
44  std::cout << "Current flashed configuration\n" << bl.readConfigData().dump(4) << std::endl;
45  } else {
46  std::cout << "Warning! Flashing bootloader config can potentially soft brick your device and should be done with caution." << std::endl;
47  std::cout << "Do not unplug your device while the bootloader config is flashing." << std::endl;
48  std::cout << "Type 'y' and press enter to proceed, otherwise exits: ";
49  std::cin.ignore();
50  if(std::cin.get() != 'y') {
51  std::cout << "Prompt declined, exiting..." << std::endl;
52  return -1;
53  }
54 
55  bool success;
56  std::string error;
57  if(clear) {
58  std::tie(success, error) = bl.flashConfigClear();
59  } else {
60  if(path.empty()) {
61  std::tie(success, error) = bl.flashConfig(dai::DeviceBootloader::Config{});
62  } else {
63  std::tie(success, error) = bl.flashConfigFile(path);
64  }
65  }
66  if(success) {
67  std::cout << "Successfully flashed bootloader configuration\n";
68  } else {
69  std::cout << "Error flashing bootloader configuration: " << error;
70  }
71  }
72  } catch(const std::exception& ex) {
73  std::cout << "Error accessing config: " << ex.what() << std::endl;
74  }
75 
76  } else {
77  std::cout << "No devices found" << std::endl;
78  }
79 
80  return 0;
81 }
dai::DeviceBootloader
Definition: DeviceBootloader.hpp:29
DAI_SPAN_NAMESPACE_NAME::get
constexpr auto get(span< E, S > s) -> decltype(s[N])
Definition: span.hpp:491
dai::DeviceInfo
Definition: XLinkConnection.hpp:27
dai::logger::info
void info(const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:78
dai::DeviceBootloader::Config
Definition: DeviceBootloader.hpp:39
dai::DeviceBootloader::flashConfigClear
std::tuple< bool, std::string > flashConfigClear(Memory memory=Memory::AUTO, Type type=Type::AUTO)
Definition: DeviceBootloader.cpp:1290
depthai.hpp
dai::DeviceBootloader::flashConfigFile
std::tuple< bool, std::string > flashConfigFile(const dai::Path &configPath, Memory memory=Memory::AUTO, Type type=Type::AUTO)
Definition: DeviceBootloader.cpp:1345
main
int main(int argc, char **argv)
Definition: bootloader_config.cpp:3
dai::logger::error
void error(const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:90
dai::DeviceBootloader::readConfigData
nlohmann::json readConfigData(Memory memory=Memory::AUTO, Type type=Type::AUTO)
Definition: DeviceBootloader.cpp:1260
dai::DeviceBootloader::getFirstAvailableDevice
static std::tuple< bool, DeviceInfo > getFirstAvailableDevice()
Definition: DeviceBootloader.cpp:48
dai::DeviceBootloader::flashConfig
std::tuple< bool, std::string > flashConfig(const Config &config, Memory memory=Memory::AUTO, Type type=Type::AUTO)
Definition: DeviceBootloader.cpp:1359


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:18