read_flash_memory.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <fstream>
3 #include <string>
4 
5 #include "depthai/depthai.hpp"
6 
7 int main(int argc, char** argv) {
8  if(argc < 3) {
9  std::cout << "Usage: " << argv[0] << " offset size [filename]" << std::endl;
10  return 0;
11  }
12  size_t offset = std::stoi(argv[1]);
13  size_t size = std::stoi(argv[2]);
14  std::string filename = "";
15  if(argc == 4) {
16  filename = std::string{argv[3]};
17  }
18 
19  // Find device and read memory
20  bool res = false;
23 
24  if(res) {
25  std::cout << "Found device with name: " << info.name << std::endl;
27 
28  auto progress = [](float p) { std::cout << "Reading progress..." << p * 100 << "%" << std::endl; };
29 
30  if(filename.empty()) {
31  std::vector<uint8_t> data;
32  bl.readCustom(dai::DeviceBootloader::Memory::FLASH, offset, size, data, progress);
33 
34  size_t offset = 0;
35 
36  while(offset < data.size()) {
37  // Print as hex, 32B aligned
38  for(int i = 0; i < 32; i++) {
39  if(offset >= data.size()) {
40  break;
41  }
42  printf("%02X ", data[offset]);
43  offset++;
44  }
45  printf("\n");
46  }
47 
48  } else {
49  bl.readCustom(dai::DeviceBootloader::Memory::FLASH, offset, size, filename, progress);
50  }
51 
52  } else {
53  std::cout << "No devices found" << std::endl;
54  }
55 
56  return 0;
57 }
dai::DeviceBootloader
Definition: DeviceBootloader.hpp:29
dai::DeviceInfo
Definition: XLinkConnection.hpp:27
dai::logger::info
void info(const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:78
main
int main(int argc, char **argv)
Definition: read_flash_memory.cpp:7
DAI_SPAN_NAMESPACE_NAME::detail::data
constexpr auto data(C &c) -> decltype(c.data())
Definition: span.hpp:177
depthai.hpp
DAI_SPAN_NAMESPACE_NAME::detail::size
constexpr auto size(const C &c) -> decltype(c.size())
Definition: span.hpp:167
dai::DeviceBootloader::getFirstAvailableDevice
static std::tuple< bool, DeviceInfo > getFirstAvailableDevice()
Definition: DeviceBootloader.cpp:48
dai::DeviceBootloader::readCustom
std::tuple< bool, std::string > readCustom(Memory memory, size_t offset, size_t size, std::vector< uint8_t > &data, std::function< void(float)> progressCb=nullptr)
Definition: DeviceBootloader.cpp:1190


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