Skip to content

fix: restore filament reporting to SDCP clients and Home Assistant (v0.5.1) - #116

Open
pdscomp wants to merge 5 commits into
mainfrom
paul/fix-spoolman
Open

pdscomp wants to merge 5 commits into
mainfrom
paul/fix-spoolman

Conversation

@pdscomp

@pdscomp pdscomp commented Nov 1, 2026

Copy link
Copy Markdown
Member

Problem

v0.5.0 stopped emitting TotalExtrusion / CurrentExtrusion in the periodic Status.PrintInfo broadcast, so Spooler v2 and Home Assistant/Spoolman stopped seeing filament usage (#114).

The 1.4.46 patch hooked the function that builds the periodic broadcast. The 1.4.49 port hooked a different site (file 0x36f9ec, the Agora hook), so the keys never reach the status JSON. In the released v0.5.0 update.swu the wrong hook is patched and the real broadcast site (file 0x35d310) is untouched; the key strings themselves were already correct at 0x4519a0 / 0x4519b0.

A second problem sits behind the first: v0.5.0 spoofs the SDCP FirmwareVersion to a bare 1.4.49 for ElegooSlicer, and Home Assistant's elegoo_printer integration only creates the OpenCentauri-only extrusion sensors when that string carries an OC/O marker (Printer._is_open_centauri → printer.open_centauri → PRINTER_STATUS_FDM_OPEN_CENTAURI). With the spoof in place HA never registers the entities at all, so fixing the hook alone still leaves Spoolman empty.

Approach

Four commits:

  • 07d34be re-hooks the real broadcast site, moves the scratch doubles out of stock PRNG state into reserved private BSS, and grows the RW segment allocation (.bss, p_memsz, and the four exported end symbols) instead of borrowing cells the stock binary still uses. It preserves harpua555's signed-difference contract from PR Feature/report filament usage #40 and validates every guarded region before writing a byte.
  • 3d64646 adds TOOLS/check_filament_usage.py, a bounded read-only SDCP observer adapted from lp55's PR feat: stage OpenCentauri v0.5.0 integration for firmware 1.4.49 #106 procedure, plus the 1.4.49 docs rewrite.
  • 5c67124 reports 1.4.49 OC from the slicer spoof cave instead of 1.4.49: the leading version keeps ElegooSlicer recognising the firmware, the marker keeps HA on the OpenCentauri entity set. The cave grows 8 → 11 bytes and still ends ahead of the wait_for_chamber_temp trampoline at 0x004517f0. The spoof patch now validates all four regions up front and refuses a non-zero cave instead of warning.
  • 8a7d9f1 adds OC_VERSION='0.5.1' to firmware-editions/patched and honours it in TOOLS/firmware_version.py, so release builds report 0.5.1-oc instead of <last tag>-<commit count>-oc. The vX.Y.Z-integrate beta path still takes precedence.

Tests

16 tests, all passing (needs unicorn, plus arm-linux-gnueabihf-{as,ld,objcopy} and bspatch for the firmware tests):

uv run --no-project --with unicorn==2.1.4 python3 -m unittest \
  tests.test_report_filament_usage tests.test_spoof_slicer_firmware_version tests.test_firmware_version
  • tests/test_report_filament_usage.py executes the original 1.1.40 trampoline and the new port under Unicorn with a mocked native JSON-number helper and asserts they emit the same (TotalLayer, TotalExtrusion, CurrentExtrusion) sequence for five PrintStats values, that no preserved register, SP, or callee-saved VFP register is clobbered, that stock PRNG cells are byte-identical afterwards, that only the declared regions change, and that every guard failure is non-mutating. The assertion was verified to fail against the pre-fix patch (sabotage run).
  • tests/test_spoof_slicer_firmware_version.py covers the three repointed sites, the untouched real version string, the cave contents, region confinement, non-mutating guard failures, and both halves of the client contract: the reported string still starts with 1.4.49 and still matches HA's OC-marker test.
  • tests/test_firmware_version.py covers the declared-version override, beta precedence, rejection of malformed values, and that the edition config declares 0.5.1.

python3 oc-patches/patch_planner.py 1.4.49 --dry-run lists the full 22-step chain with no cave overlap.

Risk

  • Unproven half: ElegooSlicer with V1.4.49 OC. Nothing in CI proves the slicer still accepts the longer version string. Issue patch overruns 8-byte version slot, breaking ElegooSlicer CANVAS sync / SDCP request attribute #102's thread has users depending on V1.4.49 for filament sync, so this needs one flash and a sync attempt on a CC1 before release. If it misbehaves, revert 5c67124 alone: the hook fix is independent of it, and HA would then need a matching change on the integration side instead.
  • The BSS reservation shifts the exported end symbols by 0x14 bytes. Anything downstream that hard-codes 0x522f04 would notice; the patch map records it.
  • OC_VERSION has to be bumped with each release, otherwise builds keep reporting 0.5.1-oc. The edition config documents this.
  • The HOOK answer to the issue's open question: Spooler's missing history entries are not explained by this. The counter is what Spooler reads for deductions; history is a separate path this PR does not touch.

Not in scope

  • The HA integration itself (its fork already tolerates hex-encoded keys and the OC marker).
  • 1.4.46 / 1.1.40 patch sites.
  • Any change to the slicer spoof's three target sites, only the string it points at.

Credit: harpua555 (PR #40, original patch and signed-difference contract), lp55 (PR #106, test procedure), tomgit-coder for the report in #114.

Preserve harpua555's original PR #40 signed-difference contract on the periodic Status.PrintInfo broadcast. Reserve private zero-initialized ELF BSS instead of overwriting stock PRNG state, and execute original-versus-new ARM regression tests.
Adapt lp55's PR #106 test procedure and document the restored PR #40 contract and ELF scratch reservation. Bound connection opening and closing as well as the observation window.
The slicer spoof made every SDCP FirmwareVersion read "1.4.49", which is also
what Home Assistant's elegoo_printer integration inspects: it only registers the
OpenCentauri-only sensors (total/current extrusion, the ones Spoolman reads) when
Printer._is_open_centauri finds an OC/O marker in that string. With a bare stock
version HA treats the printer as stock and never creates those entities, so
restoring the PrintInfo fields alone still leaves Spoolman with nothing.

Report "1.4.49 OC" instead: the leading version keeps ElegooSlicer recognising
the firmware, the marker keeps HA on the OpenCentauri entity set. The cave grows
from 8 to 11 bytes and still ends ahead of the wait_for_chamber_temp trampoline
at 0x004517f0.

The patch now validates all four regions before writing any byte, and refuses a
non-zero cave instead of warning about it.

Still needs an on-device slicer check: nothing in CI proves ElegooSlicer accepts
the longer version string.
main is always ahead of the last release tag, so git-describe on a release build
reports the previous version plus a commit count instead of the version being
shipped. Add OC_VERSION to the firmware edition config and let firmware_version()
use it. The vX.Y.Z-integrate branch check stays ahead of it, so dev builds keep
reporting their own sha.

Set it to 0.5.1 for this release.
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

PR build artifact

Firmware patches included

OpenCentauri Firmware Build

  • Firmware version: 0.5.1-oc
  • Build complete time: 2026-11-01 11:07:59 UTC
  • Original firmware: FW-CentauriCarbon-v1.4.49-2026-07-29.bin
  • Original SHA-256: b38601e1224d6f73291550ab71c21b5e7995b78d1cd39baab5a6b453caa706cf
  • Final firmware: update-2026-11-01-110759_0.5.1-oc.swu
  • Final SHA-256: b3dcab54bb42c5c67d69ed0dfba3d12dd82d5e12282a20c78070fadc145b1a45

Build metadata

  • Build version: oc-paul-fix-spoolman-e6158c0
  • Branch: paul/fix-spoolman
  • Commit: e6158c076be5a0f76ddf4e2080a86d79a3e877f5

Patches applied (TY Sims!)

Order Patch ID Source
1 Setup patching system setup oc-patches/setup
2 Enable Entware setup, load new kernel modules and more bootstrap_oc oc-patches/services/bootstrap-oc
3 Download tools from the OpenCentauri repository and install them in /bin download_tools oc-patches/firmware/download-tools
4 Misc patches for the firmware base oc-patches/firmware/misc-firmware-patch
5 Always allow adjusting z offset always_allow_z_offset_adjust oc-patches/cc1-app/do-not-block-z-offset-adjust-patch
6 Spoof firmware version reported to ElegooSlicer via SDCP attributes spoof_slicer_firmware_version oc-patches/cc1-app/spoof-slicer-firmware-version
7 Set home position to front right home_position_front_right oc-patches/cc1-app/home-position-front-right-patch
8 Fix exhaust fan automatically turning on during a print disable_exhaust_fan oc-patches/cc1-app/disable-exhaust-fan-patch
9 Block update checks block_update_check oc-patches/cc1-app/block-update-check-patch
10 Adds both cumulative filament usage (per print) and filament requested per 250ms exports in PrintStats JSON report_filament_usage oc-patches/cc1-app/report-filament-usage
11 Fix API access during a print api_during_printing oc-patches/cc1-app/allow-api-during-printing-patch
12 Fix file uploads during a print upload_during_printing oc-patches/cc1-app/allow-uploads-during-printing-patch
13 Block connectivity checks block_connectivity_check oc-patches/cc1-app/block-connectivity-check-patch
14 Allow use of TEMPERATURE_WAIT with SENSOR=box wait_for_chamber_temp oc-patches/cc1-app/wait-for-chamber-temp
15 Replace firmware version with OpenCentauri version set_firmware_version oc-patches/cc1-app/set-firmware-version-patch
16 Misc patches for the CC1 app misc_app oc-patches/cc1-app/misc-app-patch
17 Add gcode commands to control chamber light add_chamber_light_gcode oc-patches/cc1-app/add-chamber-light-gcode-patch
18 Install UART-enabled UBoot uboot oc-patches/firmware/uboot-patch
19 Replace bootlogo replace_bootlogo oc-patches/firmware/replace-bootlogo-patch
20 Implement OTA updates for OpenCentauri firmware ota_updates oc-patches/cc1-app/ota-updates-patch
21 Enable Uart uart oc-patches/firmware/uart-patch
22 Finalise patches finalise oc-patches/finalise

Please provide feedback as comments in this PR or in the #patched-fw channel on Discord.

patch_planner injects the edition variables into the environment of the patch
scripts it launches, but create_manifest.py and the patch summary run as separate
processes from build.sh, so they never saw OC_VERSION. The first CI build on this
branch shipped a manifest reading 0.5.0-8a7d9f1-oc while the binary itself got
0.5.1-oc.

firmware_version() now falls back to the active oc-patches/patch_config edition
file when the variable is not in the environment, so every consumer of the version
agrees. Covered by a test that calls it with no environment at all.
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