此页面由 AI 自动翻译。查看英文原版

本页目录

  • 演示
  • 设置
  • 源代码

崩溃报告

固件崩溃时,OAK 相机会自动生成崩溃报告并将其存储在设备中。 崩溃报告包含有关崩溃的信息,例如堆栈跟踪、设备的配置以及崩溃时设备的状态。可以从设备读取崩溃报告并将其发送给 Luxonis 以进行调试。

演示

如果设备上找到了崩溃报告,此示例将读取它并将其保存到 json 文件:
Command Line
1> python crash_report.py
2    Crash dump found on your device!
3    Saved to crashDump_0_184430102163DB0F00_3575b77f20e796b4e79953bf3d2ba22f0416ee8b.json
4    Please report to developers!
发送崩溃报告以及最小可复现示例(DepthAI 问题) 到我们的讨论论坛。谢谢!

设置

此示例需要 DepthAI v3 API,请参阅 安装说明

源代码

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5from json import dump
6from os.path import exists
7
8# Connect to device and start pipeline
9with dai.Device() as device:
10
11    if device.hasCrashDump():
12        crashDump = device.getCrashDump()
13        commitHash = crashDump.depthaiCommitHash
14        deviceId = crashDump.deviceId
15
16        json = crashDump.serializeToJson()
17        
18        i = -1
19        while True:
20            i += 1
21            destPath = "crashDump_" + str(i) + "_" + deviceId + "_" + commitHash + ".json"
22            if exists(destPath):
23                continue
24
25            with open(destPath, 'w', encoding='utf-8') as f:
26                dump(json, f, ensure_ascii=False, indent=4)
27
28            print("Crash dump found on your device!")
29            print(f"Saved to {destPath}")
30            print("Please report to developers!")
31            break
32    else:
33        print("There was no crash dump found on your device!")

C++

1#include <fstream>
2#include <iostream>
3
4// Includes common necessary includes for development using depthai library
5#include "depthai/depthai.hpp"
6
7static bool fileExists(dai::Path path) {
8    std::ifstream file(path);
9    return file.is_open();
10}
11
12int 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}

需要帮助?

请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。