Files
serversdownandClaude Opus 5.5 eeb55effe9 feat(sfm): Series-4 call-home state and audited enable/disable (phase 4)
- micromate: ENABLEABLE_WRITES gains 0x7E/0x7F (the call-home write and its
  confirm; spec row 9, enable/disable only); MicromateClient.get_call_home_content()
  returns the 126-byte 0x2C content.
- sfm/device_access: CallHomeState (serial, series, enabled, dial_string, detail
  with byte5 and the whole block); s4_call_home_state reads bit 0 of [5] and the
  dial string at [6:46]; s4_change_call_home runs the shared change core with
  micromate.writes.plan_call_home_enabled -- built from the read run_change made
  just before, and that same plan is the one sent.  A unit calling home (run
  state 0x03) is refused, nothing sent.  The read-back judges the edited bit
  only; the snapshot records both blocks and every changed offset -- [118:120]
  is unit-maintained and always moves.
- The write-ceiling tests take 0x71 (the setup write, phase 5) as their
  over-the-ceiling example now that 0x7E is enableable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
2026-11-02 16:56:04 -05:00

167 lines
5.5 KiB
Python

"""Series-neutral models. Every operation returns the same shape for both
series; anything only one series has goes under `detail`."""
from __future__ import annotations
import datetime
from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional
from .errors import BadRequest
@dataclass(frozen=True)
class UnitAddress:
host: Optional[str]
tcp_port: Optional[int]
port: Optional[str]
baud: Optional[int]
def __post_init__(self) -> None:
if not self.host and not self.port:
raise BadRequest(
"specify 'host' (TCP, e.g. ?host=10.0.0.5&tcp_port=9034) "
"or 'port' (serial, e.g. ?port=/dev/ttyACM0)"
)
@property
def key(self) -> str:
"""One key per physical link -- what the per-unit lock is keyed on."""
if self.host:
return f"tcp:{self.host}:{self.tcp_port}"
return f"serial:{self.port}"
@dataclass
class UnitInfo:
serial: str
series: int
model: Optional[str]
firmware: Optional[str]
monitoring: Optional[bool]
active_setup: Optional[str]
detail: Dict[str, Any] = field(default_factory=dict)
@dataclass
class UnitStatus:
serial: str
series: int
monitoring: bool
battery_volts: Optional[float]
memory_total_bytes: Optional[int]
memory_free_bytes: Optional[int]
device_time: Optional[str] # ISO, the unit's own local time
event_count: Optional[int] # None where it is not cheap (Series 3)
detail: Dict[str, Any] = field(default_factory=dict)
@dataclass
class UnitSettings:
serial: str
series: int
setup_name: Optional[str]
record_mode: Optional[str] # the unit's own name for its mode
sample_rate: Optional[int]
record_time_s: Optional[float]
histogram_interval_s: Optional[int]
geo_trigger_ips: Optional[float]
notes: Dict[str, str] = field(default_factory=dict)
detail: Dict[str, Any] = field(default_factory=dict)
@dataclass
class CallHomeState:
"""A unit's call-home switch, read by serial (phase 4). `enabled` is None when
the enable byte is not a value ever measured; `detail` keeps `byte5` and the
whole `block` (hex) as read."""
serial: str
series: int
enabled: Optional[bool]
dial_string: Optional[str]
detail: Dict[str, Any] = field(default_factory=dict)
@dataclass
class EventRef:
"""One stored event, as listed. `event_id` is opaque: pass it back to
download the event. `index` is its position in the list right now; an
erase renumbers it, so it is for display, never identity."""
event_id: str
serial: str
series: int
index: int
timestamp: Optional[str] # ISO, the unit's own local time
record_type: Optional[str] # "waveform" | "histogram"
peak_vector_sum_ips: Optional[float]
peaks_ips: Dict[str, float] # geophones only: tran / vert / long
filename: Optional[str] # the name the vendor's software gives it
detail: Dict[str, Any] = field(default_factory=dict)
@dataclass
class EventList:
serial: str
series: int
events: List[EventRef]
detail: Dict[str, Any] = field(default_factory=dict)
@dataclass
class EventDownload:
"""What a download stored. The file and waveform are then served at
/db/events/{db_event_id}/... ."""
event_id: str
serial: str
series: int
db_event_id: Optional[str]
stored_filename: str
filesize: Optional[int] # None only for a stored row with no file recorded
sha256: Optional[str] # None when the event was already stored
inserted: bool # False: already stored; nothing was written (detail.already_stored)
verified: Optional[bool] # True: decode self-check passed; None: no check exists
detail: Dict[str, Any] = field(default_factory=dict)
@dataclass
class DownloadedEvent:
"""The device side's result, before SFM stores it. Not an HTTP shape: it
carries the payload -- a Series-3 Event + its 5A frames + the compliance
config, or a Series-4 file's bytes -- to sfm.event_ingest.
`timestamp` is the event's time as the unit reported it: the store looks up
an existing row by (serial, timestamp) before writing anything. `record` is
what the unit's own event record said (Series 4's 0x0C), for the fields the
file alone does not give."""
event_id: str
serial: str
series: int
filename: str
verified: Optional[bool]
idf_bytes: Optional[bytes] = field(default=None, repr=False)
bw_bytes: Optional[bytes] = field(default=None, repr=False) # Series 3: the assembled Blastware file
event: Any = field(default=None, repr=False)
a5_frames: Optional[list] = field(default=None, repr=False)
compliance: Any = field(default=None, repr=False)
timestamp: Optional[datetime.datetime] = None
record: Dict[str, Any] = field(default_factory=dict)
detail: Dict[str, Any] = field(default_factory=dict)
@dataclass
class ChangeResult:
"""The outcome of a change request. `outcome`: "dry_run" | "skipped" | "sent" |
"failed". `verified`: "ok" | "mismatch" | "not_checked". `plan` is the exact
frames planned (dry run) or sent."""
serial: str
series: int
action: str
dry_run: bool
sent: bool
outcome: str
verified: str
state_before: Optional[str]
state_after: Optional[str]
audit_id: Optional[str]
plan: Dict[str, Any] = field(default_factory=dict)
detail: Dict[str, Any] = field(default_factory=dict)