Skip to content

F-20: Orchestrator: taking over a moving loco starts from speed 0 #23

Open

Description

@bazauto

Severity: HIGH · Effort: Medium · Batch: 1 · Status: Code done in #21 (7c980f9), awaiting bench verification

Found in the second full review of the firmware. Recorded with the rest of the pass (F-19…F-44) in docs/REVIEW_REMEDIATION_PLAN_2.md, which is where its status is kept.

Description

On acquire, Throttle::assignLocomotive zeroes the model and
OrchestratorBackend::acquireLocomotive zeroes its shadow. The loco's actual state arrived in
the opening STATE_SNAPSHOT (and in every LOCO_STATE since), but onLocoState only routes
addresses that are already assigned, so it was discarded. Taking over a loco another operator
or an automation run has at speed 60, one click clockwise commands speed 4; one click
anticlockwise commands reverse 4.

WiThrottle does not have this problem: JMRI restates speed and direction after M…+.

Plan

  1. OrchestratorClient keeps a compact cache of the latest state per address, filled from
    STATE_SNAPSHOT (which replaces it wholesale) and LOCO_STATE, cleared when the link goes
    down. Bounded in size.
  2. OrchestratorBackend::acquireLocomotive seeds its shadow from the cache and replays the
    cached state through the throttle-state callback, exactly as a LOCO_STATE would arrive.
    This is display-side use of layout state: nothing is sent outward, so the "a snapshot is
    never replayed as commands" rule stands.
  3. Unit test: snapshot, then acquire, then assert the update carried the snapshot's speed and
    direction.

Files: OrchestratorClient.h/.cpp, OrchestratorBackend.cpp, tests

Acceptance Criteria

  • Acquiring a loco the orchestrator already reports as moving shows its speed and
    direction immediately (replayed through the throttle-state callback).
  • The next knob click moves from that speed, not from 0 — the controller's model and
    the backend's shadow are both seeded.
  • Nothing is sent to the orchestrator on acquire.
  • Unit tests test_orch_backend_acquire_seeds_from_layout_state,
    test_orch_backend_acquire_of_unreported_loco_shows_nothing and
    test_orch_snapshot_replaces_cached_state pass on the board (they compile).
  • Bench: drive a loco from the web UI, take it over on the device, click once each way.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions