feat(device): validate StreamingFrequency + return SD logging filename (closes #336, #337) - #349
Conversation
closes #336, #337) #336: StreamingFrequency was an unvalidated auto-property whose value was sent to the hardware verbatim, so a bad rate (0, negative, 50 kHz) reached the device silently and every consumer re-declared the 1-1000 Hz limit. Validate the setter against Metadata.Capabilities.MaxSamplingRate (not a hardcoded constant), throwing ArgumentOutOfRangeException with the valid range — matching the client-side guards Core already applies for PWM (#306) and channel bounds (#300). The MCP server's duplicated HardwareMaxSampleRateHz constant is removed; it now reads the device's advertised max and its --max-sample-rate-hz option still clamps below it. #337: StartSdCardLoggingAsync returned bare Task, so a caller passing fileName:null never learned the log_{timestamp} name Core generated and had to duplicate the convention to report/download/delete the log. It now returns SdCardLoggingSession { FileName, Format } carrying the effective on-card name for both explicit and auto-generated cases. The MCP server drops its duplicated filename generation (and the now-dead ExtensionFor helper) and uses the returned value. Bench-tested on real hardware (Nq1, FW 3.7.2): max read as 1000 Hz, out-of-range rejected; auto + explicit SD names returned and confirmed present in the card's file list. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
PR Summary by QodoValidate StreamingFrequency against device capabilities and return SD log session info
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo
Context used 1.
|
…ep SD API non-breaking - StreamingFrequency setter now sanitizes the ceiling with Math.Max(1, MaxSamplingRate), so an invalid/uninitialized MaxSamplingRate (0 or negative) can't produce an impossible "1..0" range that rejects every frequency (Qodo #1). Added a test for max<=0. - Restore the original `Task StartSdCardLoggingAsync(...)` signature (v1.x public API) as a compatibility overload and add the effective-filename variant as a new `Task<SdCardLoggingSession> StartSdCardLoggingSessionAsync(...)` instead of changing the released return type (Qodo #2). The old method delegates to the new one; MCP uses the new one. Avoids the semver break flagged for a post-1.0 library. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
agentic_review |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 7e608f4 |
Summary
Two
DaqifiStreamingDeviceergonomics fixes that each also delete duplicated logic from the in-repo MCP server.#336 — validate
StreamingFrequencyagainstDeviceCapabilities.MaxSamplingRatePreviously an unvalidated auto-property; its value was sent to the device verbatim on
StartStreaming(), so a bad rate (0, negative, 50 kHz) reached the hardware silently and every consumer re-declared the 1–1000 Hz limit.Metadata.Capabilities.MaxSamplingRate(the effective max comes fromDeviceCapabilities, not a hardcoded constant) and throwsArgumentOutOfRangeExceptionwith the valid range — consistent with the PWM (feat: give PWM frequency and duty commandable defaults and clamp them on set #306) and channel-bounds (Add resolution/range/calibration bounds validation to AnalogChannel #300) guards.Math.Max(1, …)so an invalid/uninitializedMaxSamplingRate(0/negative) can't produce an impossible1..0range (Qodo round 1).HardwareMaxSampleRateHz = 1000constant removed; it now reads the device's advertised max, and its--max-sample-rate-hzoption still clamps below it.#337 — expose the effective on-card filename (non-breaking)
Callers passing
fileName: nullnever learned thelog_{timestamp}name Core generated and had to duplicate the convention to report/download/delete the log.Task<SdCardLoggingSession> StartSdCardLoggingSessionAsync(...)returning{ FileName, Format }. The originalTask StartSdCardLoggingAsync(...)signature is preserved (it shipped in v1.x) and now delegates to the new method — no public/ABI break (Qodo round 1).ExtensionForhelper) and uses the returned session.Testing
dotnet test— Core 1599 pass, MCP 23 pass, 0 fail. Boundary tests forStreamingFrequency(1, max, 0, max+1, lowered-cap, and invalid max≤0); tests asserting the returned SD name matches what was sent to the device (explicit + auto).1..1range; auto + explicit SD names returned via the session method and confirmed on the card.Closes #336, closes #337.