Skip to content

fix(SV/PTP): fast real AUTO synchronization to own PTP GM without 10-epoch delay - #284

Open
masarray wants to merge 22 commits into
fix/bench-gm-epoch-ms-watchdog-diagnostics-20261022from
fix/ptp-source-fast-auto-lock-20261022
Open

masarray wants to merge 22 commits into
fix/bench-gm-epoch-ms-watchdog-diagnostics-20261022from
fix/ptp-source-fast-auto-lock-20261022

Conversation

@masarray

@masarray masarray commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Root cause

In the 2026-10-22 capture of PR#282 the ESP32-P4 SOURCE PTP Announce, Sync/Follow_Up and the SV 4kfps/gmIdentity stream were already structurally valid, but AUTO held smpSynch=0 for 85,001 frames (~21.25s). The hard-coded SvLocalRefAcquisition::kRequiredCleanEpochs=10 is a conservative multi-second probation appropriate for an external GM receiver but unnecessarily slow for the ESP32's own EMAC 1588 hardware GM. Manual FORCE_2 immediately sets the flag but bypasses timing evidence.

Changes

  • Add a SOURCE-only fast gate requiring two consecutive live 1Hz software phase-qualified epochs with a genuine measured coherent canonical SV MAC TX timestamp pair and same PTP clock source/session/fault generation. This preserves actual GPTimer→EMAC phase and smpCnt=0 epoch alignment, not just packet flags.
  • Receiver/external-GM retains existing conservative 10-epoch qualification. Fast SOURCE gate cannot be entered by a mere GUI FORCE_2, fresh MAC-less stream, PTP SOURCE loss, skipped epoch, changed GM, publisher fault, software phase >4us, or expired descriptor evidence.
  • Existing PTP SOURCE emulation and independent SV/GM identities, VLAN profile, 4kHz ISR, no-loss smpCnt and hardware timestamp schedule remain untouched.
  • Regression exercises AUTO becoming available after first two real evidence-qualified 1Hz epochs (synthetic ~4–5 seconds vs prior ~21s observed), and immediate revocation for changes/faults.

Hardware gate

CI compilation and portable tests do not certify relay. Run on isolated SIPROTEC bench, measure phase lock acquisition after START, Pdelay exchange and relay accepted SV/current/voltage with no sync alarm. Expected faster lock is not a claimed physical result until measured. Never merge to main or stable without review.


2026-10-22 SCL-derived SV metadata and SOURCE_FAST checkpoint

  • Added SCL-backed 4I+4V SV metadata wire mapping: 50Hz 80 samples/period produces smpRate=80/smpMod=0 at 4000 fps, 60Hz 80 samples/period produces 4800 fps; per-second mode remains smpMod=1; legacy optional omission remains backward-compatible. Code commit 017d9a8db9c4ab7f2598577446c5827f82654ec5; integrated binary 4I4V validation and BER roundtrip regression.
  • Removed MSVC /WX optional narrowing warning in sample-rate regression; updated Qt Studio PTP SOURCE_FAST structural contract to require real measured MAC/phase evidence and conservative 10-epoch COLD/WARM tests (25accab5eb45a2036e507f0759ffde0fda9c9b92). Corrected inspector mode SmpPerSec matching the SCL model (3ebe7299c3bc8c777567dba36ffbdb1f505da457).
  • ESP32-P4 firmware, PTP Core, PTP Lab Profile, Embedded Profile CI SUCCESS at 017d9a8. Windows C++ and Qt contracts initially failed on test-only issues, fixed in subsequent commits above; final exact-HEAD CI still pending at checkpoint. Do not imply ESP32 physical retest.
  • Full external PTP AUTO_FAILOVER policy/BMCA/time-lease handoff is not implemented yet; current SOURCE/RECEIVER/MONITOR base remains. Fast SOURCE AUTO patch preserved, but ≤5sec physical lock, selected SIPROTEC GM/Pdelay/PTP LOCKED, SV accepted 4I4V without alarm, external failover/return and 1h soak remain HW FAT TODO.
  • Do not bypass smpSynch=2 qualification, alter main/stable, or merge stacked PRs without verifying exact parent graph/CI and explicit user permission.

P1 external-GM AUTO failover — implementation checkpoint

  • Head of earlier UI checkpoint: 056c7bf0c27f1856bcfe779447f4c7d890912e84 (branch fix/ptp-source-fast-auto-lock-20261022). Base remains original PR#283; no main/stable merge and no PR history deleted.
  • True Ethernet discovery: SOURCE RX verifies external Announce frame through native PTP codec, transportSpecific/domain, exactly matching VLAN, no QinQ, non-self clock; class=255 and malformed/empty GM rejected. Candidate needs 3 distinct Announce separated at least 200ms within 3000ms profile freshness; prior to operator opt-in, passive detection is telemetry only.
  • Explicit PTP AUTOSWITCH 1|0|SHOW CLI, only allow ON after active verified SOURCE; Studio invokes only via SmartSessionController, readback from firmware, exposes candidate GM identity/port/class, valid count, switch/return/fail counters. No optimistic LOCK/SV claimed.
  • Worker SOURCE→RECEIVER and RECEIVER→SOURCE uses the existing PTP control cancellation gate; revokes both SV sync claims before stop, waits for exclusive old EMAC worker cleanup (up to 5s), configures and starts the next physical PTP engine. Receiver must acquire genuine selected GM + measured Pdelay/servo lock before it can report timing usable. 12s receiver initial acquisition failure, 5s after held LOCK loss, 20s re-entry cooldown, 10s bounded SOURCE-restart retry after stranded failure. Human STOP disables auto immediately and cancels a pending START.
  • Portable CTest test ariec61850_ptp_external_failover_tests registered in root CMake for real stable 3-Announce, duplicate/reorder, wrong GM/clock class, mutual-exclusion, lock timeout, post-lock loss, recovery, cooldown and disabled policy. No new workflow created.
  • Earlier exact-head 9f3067a43e9722aaa5ea36dcbb61682bc1687998 passed PTP Core GCC/Clang/MSVC, C++ CI GCC/Clang/MSVC and ESP32 PTP SOURCE+RECEIVER IDF builds. Current exact 056c7bf0 CI status must be checked again before merge; changes after 9f include bounded rollback retry and metadata UI.
  • OUTSTANDING HARDWARE FAT: synchronized SV epoch/smpCnt after each lease switch; genuine selected GM/receiver LOCK at SIPROTEC, Pdelay values, 4I4V waveform, VLAN/domain faults, external GM clock step, hot disconnect/reconnect, ≤5s SOURCE AUTO phase qualification and 1-hour no-loss capture. Do not call physical acceptance complete until these have on-wire evidence.
  • Latest integrated admission regression c0f3b4e3c22dff62f011a9cf88af6fbdf42a50c0: shared production ptp_external_candidate_from_frame validates PTP Announce, domain, transport, VLAN/untagged/QinQ, not-self, source port and clock class; portable CTest now exercises the exact predicate used by the ESP32 source RX, not a duplicate test-only network filter. Final exact-HEAD CI and physical tests remain unverified until results.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-22T03:33:57.979039Z 79e2224 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Accept 80 samples/period at 50/60Hz with 4000/4800 fps and epoch wrap; retain per-second and legacy optional omission. Validate SCL binary before commit, emit exact BER fields in firmware, show effective fields in Studio, exercise encoded PDU and malformed metadata in C++ regression. Preserve PTP SOURCE fast measured lock and older ASCII PROFILE compatibility.
…st-source contract

Keep conservative LOCAL REF 10-epoch and WARM test gates while explicitly checking SOURCE_FAST measured MAC/phase qualification and acquisition reset. Assert exact 16-bit BER sample fields without MSVC narrowing warning under /WX.
…xposing opt-in AUTO switch console

Only non-self matching-domain/transport/VLAN Announce qualifies as discovery, never a timing-LOCK. Pdelay response path unchanged. Introduce AUTOSWITCH 1/0/SHOW without forcing external clocks on users.
…op/config/start and rollback

Opt-in SOURCE actual external Announce triggers receiver admission after stable evidence. Serialized EMAC break-before-make revokes SV synchronization, never forges receiver lock; measured receiver LOCK controls traceability and SV lease. Lost/unlocked receiver returns to captured local SOURCE with anti-flap cooldown. Manual STOP disables supervisor. Expose status/counters.
…onal IDF build

Test qualified consecutive Announce, duplicate/change/expiry, no dual EMAC ownership, missing receiver LOCK, post-LOCK loss, reacquisition, revert cooldown and explicit disable. Compile AUTO command only where PTP firmware is enabled.
…acked status and guardrails

Expose real board AUTOSWITCH capability, candidate Announce evidence, handover/return/error counters. Route button through SmartSessionController authority (no QML direct device mutation), prevent optimistic LOCK status, obey START/profile/firmware update gates, refresh asynchronously over existing serial telemetry. No UX bulk or extra build workflow.
… failed hardware rollback

When no PTP worker remains after a failed receiver→source recovery, attempt break-before-make local startup every 10s rather than silently losing all timing forever. Preserve STOP cancellation and exclusive EMAC. Studio correctly notes disabling AUTO while RECEIVER stays in control.
…sole/Studio before switch

Display physical Ethernet candidate provenance, freshness, stable Announce count and measured receiver authority separately. Stale candidate count falls to zero without discarding observation history. No optimistic GM/LOCK or source recoding.
…VLAN/transport/self admission

Move Ethernet qualification into shared portable production predicate. Cover malformed/non-Announce, double-tagged QinQ, mismatched/untagged VLAN, wrong domain/transport, self clock, absent source port and clock-class 255 in CTest. Preserve source hardware timestamp Pdelay responder unmodified.
This was referenced Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant