feat: add support for SDCP v3.0.0 - #16
Open
amd989 wants to merge 6 commits into
Open
Conversation
Add a network provider system to print from different slicers/software. Testing with UVTools as the first implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the device side of SDCP (Smart Device Control Protocol) v3.0.0, the protocol ChiTu network-capable mainboards speak natively. ChiTuBox and other SDCP clients now discover and drive Mariner as though the printer had network support built in: no client-side configuration, no custom endpoint mapping.
Follows up #15, which added the provider framework and UVTools support.
Why this needed a new provider shape
The UVTools provider is a set of Flask routes on Mariner's existing web port. SDCP cannot work that way: the protocol hard-codes its ports (UDP 3000 for discovery, 3030 for both the WebSocket and file upload), and the discovery reply carries no port number, so clients assume them.
NetworkPrintProvidernow supports two modes:register_routes()provides_http_routes = False+start()start()is called frommain(), never at import time, so importing the app in tests or under a WSGI loader never binds a port. A provider that fails to start is logged and skipped rather than taking the server down.register_routes()is no longer abstract, andget_provider_prefixes()only reports providers that actually own a URL prefix.What's implemented
M99999UDP broadcast on port 3000 with name, model, mainboard ID, and the local IP as routed to the requesting client (correct on multi-homed hosts)./websocket, carrying commands, live status, and printer attributes on the spec's topic scheme. Pushes attributes and status on connect, then on change.POST :3030/uploadFile/upload, verified against the client's MD5. Chunks are assembled in a scratch directory inside the files directory so the final move is an atomic same-filesystem rename rather than a copy of a large file.Serial I/O and file assembly run through an executor, so polling the printer never blocks the event loop. Status polling only runs while a client is connected, since it shares the serial link with the web UI.
Command coverage
Limitations, encoded rather than faked
Where Mariner cannot reach the hardware SDCP models, the response says so instead of pretending:
EXPOSURINGduring a print. The serial link has no notion of the lift/drop phases the protocol models.config.toml.Layer progress is derived from the print file using the same helper the web UI uses, so both surfaces report the same layer.
Two things worth a closer look
aiohttp ^3.9(plus 8 transitive). It serves the WebSocket and the upload endpoint on one port and hosts the UDP listener on the same event loop, so it replaces what would otherwise be several libraries. Also added to.pyre_configurationsearch path, without which CI fails onUndefined import.enabled = falseunder[sdcp]to turn it off. If either port is already in use, Mariner logs an error and continues serving the web interface normally.Configuration
Works with no configuration. Everything is pinnable:
The mainboard ID is derived from the host's machine-id so it stays stable across restarts, which is what lets clients remember the printer.
Testing
os.syncunder pyfakefs and Z-position layer assertions) and are unchanged by this PR.blackandflake8clean.pyrewas not run locally (no Windows binary); strict-mode annotations were added pre-emptively.Docs
docs/network-printing.rstgains an SDCP section covering setup, command coverage, limitations, and configuration. The "Adding more providers" section now documents both provider modes.