Skip to content

Commit bf7f3b2

Browse files
committed
diagnostic tool that zip important info
1 parent 1b1b3a6 commit bf7f3b2

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import depthai as dai
2+
import zipfile
3+
from json import dump , JSONEncoder
4+
from os.path import exists
5+
import os
6+
7+
class CustomEncoder(JSONEncoder):
8+
def default(self, obj):
9+
# If the object has a `__str__` method, use it
10+
if hasattr(obj, '__str__'):
11+
return str(obj)
12+
# Otherwise, use the default encoder's method
13+
return super().default(obj)
14+
15+
data = {}
16+
17+
with dai.Device() as device:
18+
19+
data['BootloaderVersion'] = device.getBootloaderVersion()
20+
data['ConnectedIMU'] = device.getConnectedIMU()
21+
data['imuFirmwareVersion'] = device.getIMUFirmwareVersion()
22+
filename = 'metadata.json'
23+
with open(filename, 'w') as f:
24+
dump(data, f, indent=2, cls=CustomEncoder)
25+
26+
27+
usercalibPath = 'userCalib.json'
28+
try:
29+
30+
with open(usercalibPath,'w') as f:
31+
dump(device.readCalibration2().eepromToJson(), f, indent=2)
32+
dump(device.readCalibrationRaw(), f, indent=4)
33+
except Exception as ex:
34+
35+
with open(usercalibPath,'w') as f:
36+
dump(str(ex), f, indent=2)
37+
38+
factcalibPath = 'factoryCalib.json'
39+
try:
40+
41+
with open(factcalibPath,'w') as f:
42+
dump(device.readFactoryCalibration().eepromToJson(), f, indent=2)
43+
dump(device.readFactoryCalibrationRaw(), f, indent=4)
44+
except Exception as ex:
45+
46+
with open(factcalibPath,'w') as f:
47+
dump(str(ex), f, indent=2)
48+
49+
zip_name = 'device_info.zip'
50+
if device.hasCrashDump():
51+
crashDump = device.getCrashDump()
52+
commitHash = crashDump.depthaiCommitHash
53+
deviceId = crashDump.deviceId
54+
55+
json = crashDump.serializeToJson()
56+
57+
i = -1
58+
while True:
59+
i += 1
60+
destPath = "crashDump_" + str(i) + "_" + deviceId + "_" + commitHash + ".json"
61+
if exists(destPath):
62+
continue
63+
64+
with open(destPath, 'w', encoding='utf-8') as f:
65+
dump(json, f, ensure_ascii=False, indent=4)
66+
67+
print("Crash dump found on your device!")
68+
print(f"Saved to {destPath}")
69+
print("Please report to developers!")
70+
with zipfile.ZipFile(zip_name, 'w') as z:
71+
z.write(filename)
72+
z.write(usercalibPath)
73+
z.write(factcalibPath)
74+
z.write(destPath)
75+
os.remove(filename)
76+
os.remove(usercalibPath)
77+
os.remove(factcalibPath)
78+
os.remove(destPath)
79+
break
80+
else:
81+
with zipfile.ZipFile(zip_name, 'w') as z:
82+
z.write(filename)
83+
z.write(usercalibPath)
84+
z.write(factcalibPath)
85+
os.remove(filename)
86+
os.remove(usercalibPath)
87+
os.remove(factcalibPath)
88+
print("There was no crash dump found on your device!")
89+
# Zip the JSON file
90+
91+
92+
93+
print("Please report to developers via forum with the zip attached!")

0 commit comments

Comments
 (0)