"""No-I/O recorder for existing reads/commands; opt-in never changes ownership.""" try: from .bounded_diagnostics import BoundedDiagnostics except ModuleNotFoundError: import runpy from pathlib import Path BoundedDiagnostics=runpy.run_path(str(Path(__file__).resolve().parents[3]/ "packages/plugin-sdk/python/missioncore_plugin_sdk/bounded_diagnostics.py"))["BoundedDiagnostics"] try: from .diagnostic_options import LEGACY_OPTIONS, diagnostic_options except ModuleNotFoundError: import runpy from pathlib import Path _options=runpy.run_path(str(Path(__file__).resolve().parents[3]/ "packages/plugin-sdk/python/missioncore_plugin_sdk/diagnostic_options.py")) LEGACY_OPTIONS,diagnostic_options=_options["LEGACY_OPTIONS"],_options["diagnostic_options"] class DriveDiagnostics(BoundedDiagnostics): def __init__(self,root): super().__init__('vesc') from .session_log import SessionLog self.log=SessionLog(root) self.stop_after=None self.options=dict(LEGACY_OPTIONS) def add(self,event,**data): if not self.active():return row=super().add(event,**data) if row is not None: try:self.log.append(row) except Exception:self.rejected+=1 def exchange(self,body): if not isinstance(body,dict) or set(body)-{'id','enabled','after','vehicle','core_events','relay_events','export','stop_after','options'}: raise ValueError('Invalid diagnostic request') if type(body.get('enabled')) is not bool or type(body.get('after')) is not int or body['after']<0: raise ValueError('Invalid diagnostic state') stop_after=body.get('stop_after') if 'stop_after' in body and (type(stop_after) is not int or not 0<=stop_after<=2**53-1 or body['enabled']): raise ValueError('Invalid diagnostic stop cursor') options=diagnostic_options(body.get('options')) if body['id']==self.id and options!=self.options: raise ValueError('Diagnostic capture options changed') previous=self.id self.options=options if body['enabled'] or body['id']!=self.id: try:self.log.start(body['id'],body.get('vehicle','Rover'),create=body['enabled'],options=options) except OSError as error: self.log.id=body['id'];self.log.error=type(error).__name__;self.log.closed=True self.configure(body['id'],False) return {**self.snapshot(body['after'],24),'id':body['id'],'storage':self.log.status()} if previous!=body['id']:self.stop_after=None if stop_after is not None: if self.stop_after is not None and self.stop_after!=stop_after: raise ValueError('Diagnostic stop cursor changed') self.stop_after=stop_after stop_after=self.stop_after if options['core_trace']:self.log.external('core',body.get('core_events',[])) self.log.external('node',body.get('relay_events',[])) if not body['enabled'] and self.active():self.add('capture_stopped') self.configure(body['id'],body['enabled'] and stop_after is None and not self.log.closed and not self.log.closing and not self.log.error) # Stop acquisition now; preserve only the already-created Core/browser # tail until its final sequence has been accepted by the disk writer. draining=stop_after is not None and self.log.external_ack.get('core',0)