|
| 1 | +import depthai as dai |
| 2 | +import zipfile |
| 3 | +from json import dump, JSONEncoder |
| 4 | +import io |
| 5 | + |
| 6 | +class CustomEncoder(JSONEncoder): |
| 7 | + def default(self, obj): |
| 8 | + if hasattr(obj, '__str__'): |
| 9 | + return str(obj) |
| 10 | + return super().default(obj) |
| 11 | + |
| 12 | +data = {} |
| 13 | + |
| 14 | +with dai.Device() as device: |
| 15 | + data['BootloaderVersion'] = device.getBootloaderVersion() |
| 16 | + data['ConnectedIMU'] = device.getConnectedIMU() |
| 17 | + data['imuFirmwareVersion'] = device.getIMUFirmwareVersion() |
| 18 | + |
| 19 | + filenames = [ |
| 20 | + "metadata.json", |
| 21 | + "userCalib.json", |
| 22 | + "factoryCalib.json" |
| 23 | + ] |
| 24 | + |
| 25 | + # Create in-memory file-like objects |
| 26 | + metadata_io = io.StringIO() |
| 27 | + usercalib_io = io.StringIO() |
| 28 | + factcalib_io = io.StringIO() |
| 29 | + crashDump_io = io.StringIO() |
| 30 | + # Dump data into these in-memory files |
| 31 | + dump(data, metadata_io, indent=2, cls=CustomEncoder) |
| 32 | + |
| 33 | + try: |
| 34 | + dump(device.readCalibration2().eepromToJson(), usercalib_io, indent=2) |
| 35 | + dump(device.readCalibrationRaw(), usercalib_io, indent=4) |
| 36 | + except Exception as ex: |
| 37 | + dump(str(ex), usercalib_io, indent=2) |
| 38 | + |
| 39 | + try: |
| 40 | + dump(device.readFactoryCalibration().eepromToJson(), factcalib_io, indent=2) |
| 41 | + dump(device.readFactoryCalibrationRaw(), factcalib_io, indent=4) |
| 42 | + except Exception as ex: |
| 43 | + dump(str(ex), factcalib_io, indent=2) |
| 44 | + |
| 45 | + in_memory_files = [metadata_io, usercalib_io, factcalib_io] |
| 46 | + |
| 47 | + zip_name = 'device_info.zip' |
| 48 | + |
| 49 | + with zipfile.ZipFile(zip_name, 'w') as z: |
| 50 | + # Zip in-memory file-like objects without writing to disk |
| 51 | + for file_io, filename in zip(in_memory_files, filenames): |
| 52 | + file_io.seek(0) # Reset cursor to the beginning of the file |
| 53 | + z.writestr(filename, file_io.getvalue()) |
| 54 | + |
| 55 | + if device.hasCrashDump(): |
| 56 | + crashDump = device.getCrashDump() |
| 57 | + commitHash = crashDump.depthaiCommitHash |
| 58 | + deviceId = crashDump.deviceId |
| 59 | + filenames.append("crashreport_" + commitHash + "_" + deviceId + ".json") |
| 60 | + dump(crashDump.serializeToJson(), crashDump_io, indent=2) |
| 61 | + in_memory_files.append(crashDump_io) |
| 62 | + |
| 63 | + with zipfile.ZipFile(zip_name, 'w') as z: |
| 64 | + # Zip in-memory file-like objects without writing to disk |
| 65 | + for file_io, filename in zip(in_memory_files, filenames): |
| 66 | + file_io.seek(0) # Reset cursor to the beginning of the file |
| 67 | + z.writestr(filename, file_io.getvalue()) |
| 68 | + |
| 69 | + print("Crash dump found on your device!") |
| 70 | + else: |
| 71 | + print("There was no crash dump found on your device!") |
| 72 | + |
| 73 | +print("Please report to developers with the zip attached!") |
0 commit comments