Skip to content

Add direct ACC shared-memory RPM ingestion to telemetry bridge#1

Open
Copilot wants to merge 16 commits intomainfrom
copilot/fix-rpm-indicator-racing-games
Open

Add direct ACC shared-memory RPM ingestion to telemetry bridge#1
Copilot wants to merge 16 commits intomainfrom
copilot/fix-rpm-indicator-racing-games

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 28, 2026

ACC users expected wheel RPM telemetry without running a separate adapter. Boxflat previously relied on UDP JSON input only, so ACC data had to be translated externally before RPM LEDs could update.

  • Telemetry bridge: dual input path (ACC shared memory + existing UDP JSON)

    • Added an ACC source worker in boxflat/telemetry_bridge.py that reads:
      • rpm from acpmf_physics (offset 20)
      • max_rpm from acpmf_static (offset 416)
    • Converts rpm/max_rpm into the existing 10-bit LED mask and forwards through the current wheel/dash telemetry commands.
    • Keeps UDP JSON behavior unchanged; both sources now feed the same forwarding path.
  • Source coordination and robustness

    • Unified mask forwarding/deduplication for both ACC and UDP sources to avoid duplicate writes.
    • Added shared-memory open/close handling for Windows and Linux shm paths with retry/fallback behavior.
    • Updated runtime bridge messaging to reflect ACC shared-memory availability and fallback guidance.
  • Docs update for ACC behavior

    • Updated README ACC section to reflect direct shared-memory RPM support while retaining UDP JSON adapter compatibility as fallback.
  • Focused parsing coverage

    • Added tests/test_telemetry_bridge_acc.py to verify ACC RPM/max-RPM extraction from the configured offsets.

Example of the new ACC read path:

rpm = struct.unpack_from("<i", physics, 20)[0]
max_rpm = struct.unpack_from("<i", static, 416)[0]
ratio = rpm / max_rpm
lit_leds = int(round(ratio * 10))
mask = (1 << lit_leds) - 1 if lit_leds > 0 else 0

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI and others added 4 commits March 28, 2026 22:33
Agent-Logs-Url: https://github.com/SiFuMax09/boxflat/sessions/1c5e11a3-1121-4ded-890a-d44821be9fe5

Co-authored-by: SiFuMax09 <131544883+SiFuMax09@users.noreply.github.com>
Agent-Logs-Url: https://github.com/SiFuMax09/boxflat/sessions/1c5e11a3-1121-4ded-890a-d44821be9fe5

Co-authored-by: SiFuMax09 <131544883+SiFuMax09@users.noreply.github.com>
Agent-Logs-Url: https://github.com/SiFuMax09/boxflat/sessions/1c5e11a3-1121-4ded-890a-d44821be9fe5

Co-authored-by: SiFuMax09 <131544883+SiFuMax09@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix RPM indicator compatibility with racing games Add universal UDP telemetry bridge for RPM indicators across racing games Mar 28, 2026
Copilot AI requested a review from SiFuMax09 March 28, 2026 22:40
@SiFuMax09 SiFuMax09 marked this pull request as ready for review March 28, 2026 22:41
Copilot AI review requested due to automatic review settings March 28, 2026 22:41
@SiFuMax09
Copy link
Copy Markdown
Owner

Can you please make that in the ui the vars are changeable you made? @copilot

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a universal UDP JSON telemetry ingestion path to drive existing wheel/dash RPM indicator telemetry commands, enabling external game/tools to forward normalized RPM data into Boxflat.

Changes:

  • Introduces TelemetryBridge UDP listener (localhost, configurable port) that parses several JSON shapes and normalizes to a 10‑LED mask.
  • Wires the bridge into the app lifecycle (startup + shutdown) so telemetry is available while the app runs.
  • Updates README with concrete telemetry bridge usage and payload formats.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
boxflat/telemetry_bridge.py New UDP telemetry bridge implementation that parses JSON, normalizes RPM to a 10‑bit mask, and forwards to existing wheel/dash telemetry commands.
boxflat/app.py Initializes the telemetry bridge during app startup and triggers shutdown on application shutdown.
README.md Documents the telemetry bridge port/configuration and accepted JSON payload shapes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +34 to +36
def shutdown(self) -> None:
self._shutdown.set()

Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shutdown() only sets the event; the worker thread may keep running for up to the socket timeout and can still process/send one more telemetry packet during app shutdown. Consider having shutdown() actively unblock the socket and join() the thread (or otherwise guarantee it has stopped) so device commands aren't sent after shutdown starts.

Copilot uses AI. Check for mistakes.
Comment on lines +76 to +78
direct_mask = self._first_number(data, "rpm_led_mask", "rpmMask", "rpm-mask", "led_mask")
if direct_mask is not None:
return max(0, min(1023, int(direct_mask)))
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int(direct_mask) can raise (e.g., if the sender provides Infinity/NaN, which Python's json can parse), crashing the telemetry thread. Add validation (e.g., math.isfinite) and/or wrap the conversion to ensure malformed inputs are ignored rather than terminating the bridge.

Copilot uses AI. Check for mistakes.
if rpm is None or max_rpm is None or max_rpm <= 0:
return None
ratio = rpm / max_rpm
elif ratio > 1:
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rpm_ratio values < 0 are currently clamped to 0 (via max(0, ...)) rather than rejected, but the documented/input contract here is 0.0–1.0 (and rpm_percent rejects out-of-range). Add a < 0 check for rpm_ratio (and optionally for derived rpm/max_rpm) so invalid negative ratios are handled consistently.

Suggested change
elif ratio > 1:
elif ratio < 0 or ratio > 1:

Copilot uses AI. Check for mistakes.
Comment on lines +96 to +98
ratio = max(0, min(1, ratio))
lit_leds = int(round(ratio * 10))
return (1 << lit_leds) - 1 if lit_leds > 0 else 0
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ratio can become non-finite (e.g., NaN/Infinity from JSON or division) and then round(ratio * 10) will raise, killing the worker thread. Before rounding, ensure ratio is finite (e.g., math.isfinite(ratio)), and ignore packets with invalid numeric values.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Copilot AI commented Mar 28, 2026

Can you please make that in the ui the vars are changeable you made? @copilot

Implemented in commit a266b09. You can now change the telemetry bridge variables in the UI under Other → Application settings: Enable telemetry bridge and Telemetry bridge UDP port (persisted and hot-reloaded). Screenshot: /tmp/playwright-logs/page-2026-03-28T22-45-05-907Z.png.

Copilot AI changed the title Add universal UDP telemetry bridge for RPM indicators across racing games Add universal UDP telemetry bridge for RPM indicators with UI-configurable settings Mar 28, 2026
@SiFuMax09
Copy link
Copy Markdown
Owner

@copilot How can I build the application so I can test it.

Copy link
Copy Markdown
Author

Copilot AI commented Mar 29, 2026

@copilot How can I build the application so I can test it.

Quickest way to test from source:

  1. Install dependencies (system + Python).
  2. From repo root run:
    python3 -m pip install -r requirements.txt
  3. Start app directly from repo:
    ./entrypoint.py --local
    (or python3 entrypoint.py --local)

If you want a system-style install instead:
sudo ./install.sh
then run:
boxflat

If you want, I can also add a short “Build/Test locally” section to README.

@SiFuMax09
Copy link
Copy Markdown
Owner

@copilot When I go into Asseto Corsa Competizione for example MY RPM indication is just blincing and not showing the rpm. Can you please implement some login features so yYou can fix the issue

Copilot AI and others added 3 commits March 29, 2026 00:30
Copy link
Copy Markdown
Author

Copilot AI commented Mar 29, 2026

@copilot When I go into Asseto Corsa Competizione for example MY RPM indication is just blincing and not showing the rpm. Can you please implement some login features so yYou can fix the...

Implemented in e0aff06 (plus follow-up hardening in 58ead5e and 684cd68). I added telemetry logging (debug mode) and stricter input validation so bad/unstable packets don’t break or flicker the RPM output path.

To diagnose ACC input live, run Boxflat with:
BOXFLAT_TELEMETRY_DEBUG=1 ./entrypoint.py --local

Then watch terminal logs for lines like Telemetry bridge: ignored packet: ... to see exactly which telemetry values are being rejected (non-finite, out-of-range, missing rpm/max_rpm, etc.).

No UI changes were made in this fix, so there is no new UI screenshot.

Copilot AI changed the title Add universal UDP telemetry bridge for RPM indicators with UI-configurable settings Add universal UDP telemetry bridge for RPM indicators with UI-configurable settings and input hardening Mar 29, 2026
Copilot AI and others added 2 commits March 29, 2026 00:38
Copilot AI changed the title Add universal UDP telemetry bridge for RPM indicators with UI-configurable settings and input hardening Improve telemetry bridge observability for ACC/no-packet RPM issues Mar 29, 2026
Copilot AI changed the title Improve telemetry bridge observability for ACC/no-packet RPM issues Improve telemetry bridge observability and clarify Windows Pit House vs Linux telemetry path Mar 29, 2026
Copilot AI changed the title Improve telemetry bridge observability and clarify Windows Pit House vs Linux telemetry path Clarify RPM data path vs Pit House and document ACC adapter requirements Mar 29, 2026
Copilot AI and others added 3 commits March 29, 2026 01:08
Copilot AI changed the title Clarify RPM data path vs Pit House and document ACC adapter requirements Add direct ACC shared-memory RPM ingestion to telemetry bridge Mar 29, 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.

3 participants