Skip to content

Talk to the device directly by default, alongside Central; deprecate Central-compat mode (#213) - #215

Merged
cboulay merged 2 commits into
masterfrom
feat/native-default-central-deprecated
Nov 6, 2026
Merged

cboulay merged 2 commits into
masterfrom
feat/native-default-central-deprecated

Conversation

@cboulay

@cboulay cboulay commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Addresses #213. Follow-up to #212 / #214.

Summary

A CereLink STANDALONE session can share a device with a running Central on the same Windows PC, so CereLink no longer needs to go through Central's shared memory to coexist with it. This PR makes talking to the device directly the default, and turns the Central-compatible attach into an opt-in, deprecated mode slated for removal in the next major release.

Changes

Shared device port on Windows (cbdev)

Connection mode (cbsdk)

  • By default a session attaches to another CereLink session's native shared memory for the device, or owns the device. It never touches Central's shared memory.
  • The deprecated Central-compat path is selected with the environment variable CERELINK_CENTRAL_COMPAT=1, not an API parameter, so the C++, C and Python APIs and the cbsdk_config_t layout are unchanged.
    • It only applies while Central is running and has a slot for the device. Without Central, or for a device Central has no slot for (NPLAY, HUB3 before 7.8), the session talks to the device directly as usual.
    • With Central running and a slot, it attaches to Central's shared memory or fails; it does not fall back.
    • It prints a one-time stderr notice.
  • Windows: peer clock consensus is stubbed out, and Central coexistence is inverted (#210) #212's "refuse while Central is running" logic is gone; by default it's no longer needed.
  • ShmemLayout::CENTRAL and the central_client example are marked deprecated.
  • The soak harness sets CERELINK_CENTRAL_COMPAT=1 for --central runs.
  • Docs updated: README, pycbsdk README, shared_memory_architecture.md (new "Running alongside Central" section), and the sequence diagrams.

Is removing the Central path possible?

Yes, as far as we can tell. The one obvious Central-only feature, recording control, works from a NATIVE session. The device echoes SETFILECFG as a broadcast REPFILECFG, and Central's File Storage acts on it. This was verified: a STANDALONE session opened File Storage, recorded and closed it, and the files were written.

Bench results (#213 matrix)

Setup: Central 7.8.0, firmware 7.8, HUB1 + HUB2 at 256 ch × 30 kHz.

Scenario CereLink STANDALONE Central's view
CereLink alone 30k samples/s, 0 missing, sync() < 1 ms, clock ±130–150 µs –
Central alone – 30k/s, 0 missing, sync() ~20 ms, clock ±10 ms
Central first, then CereLink 0 missing, sync() < 1 ms 0 missing
CereLink first; Central starts, then closes 0 missing across both transitions 0 missing
CereLink opens and closes twice under Central 0 missing 0 missing
Central records while CereLink streams 0 missing file written
  • Config propagation: labels, spike thresholds and sample-group membership changed from either side were seen by the other within 20–60 ms.
  • Earlier check on Central 7.7: master's sessions also coexisted with it.
  • This branch with Central 7.8 running:
    • Default Session(HUB1) → STANDALONE, ~30k samples/s, no warning.
    • connection_mode="central" (since replaced by CERELINK_CENTRAL_COMPAT=1) → attaches through Central.

Known caveats (documented)

  • A custom specific custom_client_address cannot share the port with Central; leave it unset.
  • Central's Standby / Shutdown buttons reset or power down the devices for everyone. Closing Central normally doesn't touch them.
  • About 0.6% of the time the device splits a millisecond of samples into two datagrams 3–4 µs apart, and Windows occasionally delivers the second first.
    • Over 10 minutes: 6 events, seen identically by Central and CereLink.
    • The wire capture showed perfect order, so this happens below both sockets.
    • Nothing is lost, but timestamps step backwards once.

Compatibility

  • Behaviour change: sessions that used to auto-attach to Central now talk to the device directly. Data, config and recording all keep working. Code that needs Central's shared memory must now set CERELINK_CENTRAL_COMPAT=1.
  • API / ABI: unchanged.

Tests

  • New Windows-only DeviceSessionTests (they replace Windows: peer clock consensus is stubbed out, and Central coexistence is inverted (#210) #212's exclusive-port tests):
    • Windows_CentralCanBindAfterSession
    • Windows_SessionCanBindAfterCentral
    • Windows_ProtocolProbeCanBindAfterCentral: holds the detected 192.168.137.x address the way Central does; skips without such an adapter.
  • Each was checked to fail against the old behaviour. The probe test reproduces Using Cerelink together with Central on the same Windows computer does not always work #210's exact Failed to bind probe socket (winsock err 10013) without the factory change.
  • SessionLifecycleTest.CentralCompatEnvWithoutCentralSlotIsStandalone (nPlayServer): with CERELINK_CENTRAL_COMPAT=1 and no Central slot for the device, the session is still STANDALONE.
  • macOS (env-var rework): ctest 422/422 run serially.
  • MinGW Debug, Windows 10: ctest 510/510 run serially with Central running (3 skipped), plus the pycbsdk tests.

A session-side recording gate is proposed separately in #218.

Not verified:

  • Linux builds (CI).
  • Legacy (non-Gemini) NSP alongside Central.
  • The README's nPlayServer + Central loopback setup. NPLAY's code path is unchanged by this PR.
  • Windows 11.

🤖 Generated with Claude Code

A STANDALONE session can share a device with a running Central on the
same PC (#213). Central binds each Gemini port on the instrument-network
address without SO_REUSEADDR; a socket bound to the wildcard address
with SO_REUSEADDR coexists with it in either start order, and since the
devices broadcast everything, both receive the full stream. Measured on
Central 7.7 and 7.8 with two hubs at 256 ch x 30 kHz: no lost samples on
either side in any start order, config changes from either side seen by
the other within ~50 ms, and recording commands from a session still
reach Central via the device's broadcast REPFILECFG echo.

So:
- The Windows device socket shares the port again (reverting #212's
  SO_EXCLUSIVEADDRUSE, under which Central crashed on launch), and the
  protocol probe binds the wildcard like the device socket instead of
  the detected address Central holds (the WSAEACCES of #210).
- New SdkConfig::connection_mode / cbsdk_config_t::connection_mode /
  Session(connection_mode=...). NATIVE, the default, never touches
  Central's shared memory. CENTRAL keeps the Central-compatible attach,
  is opt-in only, never falls back to NATIVE, and is deprecated for
  removal in the next major release.
- The soak harness requests CENTRAL explicitly for --central runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The deprecated Central shared-memory path is now chosen by setting
CERELINK_CENTRAL_COMPAT=1 rather than SdkConfig::connection_mode /
cbsdk_config_t::connection_mode / Session(connection_mode=...), so the
public API and the C struct layout are unchanged. The variable only
matters while Central is running and has a slot for the device; otherwise
the session talks to the device directly as usual. Attaching to a running
Central that has a slot still fails rather than falling back.

Also sorts pycbsdk imports and __all__ for ruff.

Co-Authored-By: Claude <[email protected]>
@cboulay
cboulay merged commit 882af12 into master Nov 6, 2026
16 checks passed
@cboulay
cboulay deleted the feat/native-default-central-deprecated branch November 6, 2026 21:38
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