crash_report.cpp
Go to the documentation of this file.
1 #include <fstream>
2 #include <iostream>
3 
4 // Includes common necessary includes for development using depthai library
5 #include "depthai/depthai.hpp"
6 
7 static bool fileExists(dai::Path path) {
8  std::ifstream file(path);
9  return file.is_open();
10 }
11 
12 int main() {
13  using namespace std;
14 
15  // Connect to device and start pipeline
16  dai::Device device;
17  if(device.hasCrashDump()) {
18  auto crashDump = device.getCrashDump();
19  std::string commitHash = crashDump.depthaiCommitHash;
20  std::string deviceId = crashDump.deviceId;
21 
22  auto json = crashDump.serializeToJson();
23 
24  for(int i = 0;; i++) {
25  dai::Path destPath = "crashDump_" + to_string(i) + "_" + deviceId + "_" + commitHash + ".json";
26  if(fileExists(destPath)) continue;
27 
28  std::ofstream ob(destPath);
29  ob << std::setw(4) << json << std::endl;
30 
31  std::cout << "Crash dump found on your device!" << std::endl;
32  std::cout << "Saved to " << destPath.string() << std::endl;
33  std::cout << "Please report to developers!" << std::endl;
34  break;
35  }
36  } else {
37  std::cout << "There was no crash dump found on your device!" << std::endl;
38  }
39 
40  return 0;
41 }
main
int main()
Definition: crash_report.cpp:12
fileExists
static bool fileExists(dai::Path path)
Definition: crash_report.cpp:7
dai::Path::string
std::string string() const
Get path in native-encoding string; no conversion.
Definition: Path.hpp:145
depthai.hpp
nanorpc::core::exception::to_string
std::string to_string(std::exception const &e)
Definition: exception.h:46
dai::Device
Definition: Device.hpp:21
std
Definition: Node.hpp:366
dai::DeviceBase::hasCrashDump
bool hasCrashDump()
Definition: DeviceBase.cpp:1264
dai::Path
Represents paths on a filesystem; accepts utf-8, Windows utf-16 wchar_t, or std::filesystem::path.
Definition: Path.hpp:27
dai::CrashDump::depthaiCommitHash
std::string depthaiCommitHash
Definition: CrashDump.hpp:73
dai::DeviceBase::getCrashDump
dai::CrashDump getCrashDump(bool clearCrashDump=true)
Definition: DeviceBase.cpp:1260


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