mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-06 05:11:58 +00:00
With use_printer_agents on, a sync started by hand from a printer of another agent than the preset's that reports no model, or one no profile knows with no switch or install planned, no longer runs best effort. A message asks the user to select the printer's preset and sync again (Go to Device Page / OK). The decision is sync_model_unfound() in DevSyncSwitch.h, with print_blocked()'s agent rule, so the sync and Print and Send agree. Through the preset's own agent, and for an agent-only or extruder-count-only difference, the best-effort question stays. The Print and Send status line now says what the modal offers: where a switch can be planned it names the printer's model and the preset's and says Send switches to its preset. The plan is kept until the printer or its inputs change.
558 lines
38 KiB
Markdown
558 lines
38 KiB
Markdown
# Printer agents
|
|
|
|
Printer agents isolate printer-specific communication from the rest of OrcaSlicer. The GUI and
|
|
`DeviceManager` operate on a shared set of printer operations and device state; a selected printer
|
|
agent implements those operations for a particular printer ecosystem. The agent boundary allows
|
|
Bambu, Moonraker-based printers, built-in integrations, and Python-provided integrations to use the
|
|
same application workflow without making the GUI understand every printer protocol.
|
|
|
|
The current boundary is an adapter boundary around the existing application contract. In particular,
|
|
some request fields and message payloads still use the Bambu-shaped representation that existing
|
|
`MachineObject` and `DeviceManager` code consumes. The printer agent is responsible for translating
|
|
that representation into the protocol spoken by its printer. This is an intentional compatibility
|
|
constraint of the current design; the interface is not yet a neutral printer protocol.
|
|
|
|
The v1 dialect migration path is deliberately narrow. `DeviceManager` currently speaks the Bambu JSON
|
|
dialect because that is the payload shape already used throughout the command and state workflow. The
|
|
v1 `OrcaPrinterAgent` also accepts that Bambu dialect. Its transport path places the small translation
|
|
needed for the target printer at `deliver_to_sink`, keeping the compatibility code at the edge rather
|
|
than spreading it through `DeviceManager` or the agent interface.
|
|
|
|
On the wire, `OrcaPrinterAgent` speaks the Orca Printing Communication Protocol (OPCP), the protocol
|
|
OrcaSlicer, printers and the OrcaCloud gateway use with each other. The agent speaks it with a printer
|
|
directly on the LAN, and with the OrcaCloud gateway, over the MQTT connection `OrcaCloudServiceAgent`
|
|
owns, when it reaches a printer through OrcaCloud. The protocol's specification, JSON Schemas and
|
|
conformance traces are in `docs/OPCP/`, a git submodule of
|
|
[OrcaSlicer/OPCP](https://github.com/OrcaSlicer/OPCP) that follows its `main` branch. Run
|
|
`git submodule update --init docs/OPCP` to check it out, and `git submodule update --remote docs/OPCP`
|
|
to move it to the latest specification.
|
|
|
|
The eventual direction is for `DeviceManager` to produce an Orca JSON dialect. The Bambu agent will then
|
|
own the translation from Orca JSON to Bambu's protocol, while `OrcaPrinterAgent` can forward the Orca
|
|
payload directly to its sink. The v1 translation at `deliver_to_sink` can then be removed without
|
|
changing `DeviceManager`, the command callers, or the rest of the agent workflow.
|
|
|
|
## Components
|
|
|
|
The system has four relevant layers:
|
|
|
|
```text
|
|
GUI / DeviceManager / MachineObject
|
|
|
|
|
NetworkAgent
|
|
/ \
|
|
IPrinterAgent ICloudServiceAgent
|
|
| |
|
|
printer protocol authentication and cloud services
|
|
```
|
|
|
|
### `DeviceManager` and `MachineObject`
|
|
|
|
`DeviceManager` owns the application-facing printer workflow. It maintains `MachineObject` instances,
|
|
updates their state, lists the devices a picker can select (`get_selectable_machine_list()`: the active
|
|
agent's with `use_printer_agents` off, those of every registered agent with it on), and initiates
|
|
operations such as homing, temperature changes, printing, subscriptions, and camera playback.
|
|
|
|
`MachineObject` remains the shared state model used by the GUI. It does not contain the implementation
|
|
of a printer protocol. When a device is discovered or returned by a cloud query, the device is tagged
|
|
with the `printer_agent_id` of the agent that found it. Selecting a device makes the agent in that tag
|
|
live, so an operation never goes through an agent that does not own the device.
|
|
|
|
### `NetworkAgent`
|
|
|
|
`NetworkAgent` is the façade used by the GUI and `DeviceManager`. It owns:
|
|
|
|
- the currently selected `IPrinterAgent`;
|
|
- the registered cloud-service instances, indexed by provider;
|
|
- callbacks shared by the active printer agent and the application;
|
|
- the forwarding methods for printer commands and cloud operations.
|
|
|
|
With `use_printer_agents` on, the live agent is the owner of the connected printer, which may differ
|
|
from the agent the printer preset names. The preset's agent says what the G-code is for; the live
|
|
agent says which printer the application is talking to. Selecting a printer makes its owning agent
|
|
live: `DeviceManager::set_selected_machine()` resolves the owner first (a printer whose agent cannot be
|
|
resolved leaves the current connection alone), disconnects the previous printer, installs the owner
|
|
with `NetworkAgent::set_printer_agent()`, which increments the machine-list generation, disconnects the
|
|
old agent and removes its callbacks, and tells the application once the new selection is stored.
|
|
A printer whose agent is not registered cannot be selected: the picker greys it with a tooltip, and the
|
|
print and send dialogs do not list it. With `use_printer_agents` on, a saved printer that names no agent
|
|
belongs to the preset's agent: the picker lists it with that agent's printers, and selecting it
|
|
connects through that agent, making it live when another agent is. The selection gives the printer that
|
|
agent in memory, so the connect result finds it; a successful connect saves it under that agent, and a
|
|
failed one takes the agent away again, so a wrong guess is not kept. Agents that never report a failed
|
|
connect, the Moonraker family, keep the guessed agent in memory only until the next selection. The print
|
|
and send dialogs list such a printer but never pick it as their default; only the user's own choice
|
|
selects it. With the setting off, a printer that names no agent is greyed in the picker, cannot be
|
|
selected and is dropped from the list at an agent install.
|
|
|
|
With the setting off, there is one active printer agent for the currently selected printer preset.
|
|
Switching the preset increments the machine-list generation, disconnects the old printer agent,
|
|
removes its callbacks, and installs the newly selected agent. The façade then forwards printer
|
|
operations to that agent.
|
|
|
|
### Preset changes and the preset's host
|
|
|
|
With `use_printer_agents` on, changing the printer preset leaves a connected printer and its agent in
|
|
place. While a printer is connected, a preset that names a `print_host` selects that host only when its
|
|
agent is registered and is not the Bambu agent, and its host target (agent, address and port, plus the
|
|
access code for Moonraker) differs from the one last applied, so editing other printer settings, saving,
|
|
or loading a plugin never replaces a printer picked on the Device page. A preset with no host resets the
|
|
target last applied, and a printer reconnected at startup counts the preset's host as applied. With
|
|
nothing connected, a preset change installs the preset's agent and selects its printer as it does with
|
|
the setting off. The host connects through the preset's agent, unless another agent already owns its
|
|
`dev_id`, in which case it keeps that owner; a record owned by the Orca agent, which never connects, is
|
|
re-inserted under the preset's agent. A printer added by IP address is detected through, and recorded
|
|
under, the preset's agent. If the live agent has been unregistered (a plugin unloaded), the preset
|
|
change tears the connection down and installs the preset's agent.
|
|
|
|
### Startup reconnect
|
|
|
|
`last_connected_printers` holds the `dev_id` of the printer last selected. A selection writes it and a
|
|
deselect erases it, whether by hand, on sign-out, or after a failed or lost connection; only the
|
|
deselect before an agent swap leaves it. Turning the setting off erases it, since nothing records it
|
|
while the setting is off. Once per session, at startup, that printer, when it is in the local list and
|
|
belongs to another agent than the preset's, reconnects with the owner taken from its local record,
|
|
before the preset's own selection. The preset's selection follows when it cannot be reconnected, or
|
|
when its LAN connect later reports a failure or a lost connection. The wait for that report ends at the
|
|
next selection of any kind, so a printer picked by hand is never replaced. Agents that report no failed
|
|
connect (the Moonraker family) and cloud printers get no such fallback.
|
|
|
|
### Networking restart
|
|
|
|
Before a networking restart rebuilds the agent, a connected printer of an agent other than the preset's
|
|
is disconnected through its own agent, which is still live; the rebuild then installs the preset's agent
|
|
and selects its printer. A printer of the preset's own agent is left to the rebuild, as with the setting
|
|
off.
|
|
|
|
### Printing and sending to another agent's printer
|
|
|
|
When Prepare prints or sends to a printer whose agent differs from the preset's, it warns before
|
|
anything is sent and lets the user continue; an incompatible printer model blocks. Picking another
|
|
agent's printer in the Print or Send dialog selects it, which makes its agent live and disconnects the
|
|
current printer. With nothing connected, the Print dialog lists the preset's agent's printers first,
|
|
and the Send dialog, with no remembered printer either, picks the first of them, so both default to the
|
|
preset's agent when it has a printer online.
|
|
|
|
The Device page draws a printer by its own agent (`MachineObject::is_bbl_agent_printer()`), not the
|
|
preset's vendor, where the decision is about the printer's data, protocol or layout; the printer's own
|
|
agent is used only with the setting on and a printer that names one. Decisions about the preset's own
|
|
layout, such as how its extruders map to the printer's tools, still read the preset's vendor.
|
|
|
|
With `use_printer_agents` on, the Print dialog (for the plate, not a file on the printer) and the
|
|
Send to printer storage dialog decide with `print_gate()` (`DevSyncCompat.h`) from the printer's
|
|
`classify_sync()` differences. Two cases block (`print_blocked()`): a known model other than the
|
|
preset's that the app does not treat as compatible with it (`compatible_machine`, as
|
|
`DevPrinterConfigUtil::is_printer_model_compatible()` reads it; an upgrade kit already counts through
|
|
the shown model), and a printer of another agent than the preset's that reports no model or one no
|
|
installed profile knows. Every other difference is printed to after the dialog's warnings: the agent,
|
|
the extruder count, a compatible model, and no model or an unknown one through the preset's own agent,
|
|
which is the usual Klipper printer under its own Klipper preset. The sync is stricter: it still asks
|
|
about any of these.
|
|
|
|
The Print and Send buttons stay enabled and the status line states the block, so pressing them opens a
|
|
modal instead of starting a job. Where a switch can be planned, the status line names the printer's
|
|
model and the preset's and says that Send switches to its preset, as the modal will offer; the plan
|
|
behind it is kept until the printer or its inputs change, since a plan may read every vendor's models. Where `plan_switch()` in `Plater.cpp` plans a switch to, or install
|
|
of, the printer's own preset, as for a sync, the modal names the printer, its model and the preset's
|
|
model and offers Switch, Device Page and Cancel. Switch closes the dialog, then plans again and
|
|
switches or installs with no sync, and the modal has said the plate must be sliced again; Device
|
|
Page closes the dialog and opens the Device tab; Cancel returns to it. Otherwise (no model, an
|
|
unknown model no vendor offers, a failed plan) the modal says the printer cannot be printed to and
|
|
offers Device Page and OK. A blocked printer that has reported no model while it holds one to
|
|
confirm, such as a saved record before its first discovery reply, is waited for rather than called a
|
|
mismatch, for 15 seconds from the first time Print or Send asked about it (in practice from when the
|
|
dialog opened); the block is then worded as waiting for its model, and after the wait the usual rule
|
|
applies. MCP `print_start` and `printer_send` refuse a blocked printer before opening a dialog
|
|
(`printer_model_mismatch`, `printer_model_pending`). With the setting off none of this applies and the
|
|
existing model checks and their unknown-model warning stand; the print host's upload dialog is never
|
|
affected.
|
|
|
|
### Syncing from an incompatible printer
|
|
|
|
With `use_printer_agents` on, `classify_sync()` (`DevSyncCompat.h`) compares the printer with the preset:
|
|
the agent, the model and the extruder count. A printer that reports no model is unidentified and one
|
|
whose model no installed profile knows is unknown; both are differences, not mismatches. An extruder
|
|
count of 0 is unknown and never a mismatch. The automatic syncs (on picking a printer preset, on
|
|
returning to Prepare, on loading a project) do not run for an incompatible printer. A sync started by
|
|
hand (the printer sync button, the pre-slice "Sync now", the filament sync button) asks once before
|
|
anything is synced.
|
|
|
|
A printer of another known model, or of an unknown model while the preset's model is known
|
|
(`sync_may_switch()`), is offered its own preset where a vendor offers the model with a nozzle.
|
|
`plan_sync_switch()` (`DevSyncSwitch.h`) is a pure function that picks the model and nozzle, and plans
|
|
no switch to the preset's own model. `Plater::switch_preset_for_sync()` gives it the loaded vendors'
|
|
models, and reads every vendor the app ships, on the UI thread behind a busy cursor, when that plans no
|
|
switch. Installed, the question names the target preset, with Yes, No and Device Page,
|
|
which opens the Device tab; not installed, a Yes/No question offers the install, and its Yes asks about
|
|
unsaved changes, runs `Ops::install_printers()` and refreshes the model registry. Either question starts
|
|
with the agent line when the agents differ too. A Yes selects the preset, and whatever still differs
|
|
syncs as after a Yes to the best-effort question; a No syncs nothing. Where the switch cannot be done, a
|
|
message says why and nothing syncs: before the question, when the planned preset is not found or, for a
|
|
known model, the vendors' models cannot be read or offer no nozzle; after a Yes, when the install fails
|
|
or leaves no preset, the preset cannot be selected or is still for another model, or the print target
|
|
changes. A Cancel at either unsaved-changes prompt, or Device Page, syncs nothing without a message. A
|
|
printer of another known model is not synced best effort, unless its model arrives while the best-effort
|
|
question is open; the consent then covers it.
|
|
|
|
A printer of another agent than the preset's whose model cannot be found (`sync_model_unfound()` in
|
|
`DevSyncSwitch.h`): it reports no model, or one no installed profile knows and no switch could be
|
|
planned for, is not synced best effort. A message says the printer does not report its model, so the
|
|
preset cannot be matched to it, and asks the user to select its preset and sync again, with Go to
|
|
Device Page and OK; nothing syncs. This is the agent rule of `print_blocked()`, so a printer the sync
|
|
cannot match is the one Print and Send block.
|
|
|
|
Any other difference gets the best-effort question, which lists each difference and has Yes, No and
|
|
Device Page: the agent, the extruder count, and, through the preset's own agent, an unidentified model
|
|
and an unknown model that no vendor offers (or whose vendors cannot be read) or that meets a preset of
|
|
unknown model. On Yes to it each item
|
|
syncs where it can. The nozzle diameter comes from the preset's variant that has it, so the printer
|
|
preset can switch variant, and a user preset can move to the system preset of that variant. The AMS
|
|
counts sync on a two-extruder preset. A printer that reports no flow type never has it forced to
|
|
Standard, and a best-effort sync writes only a flow type the preset offers. With a different extruder
|
|
count the nozzles and AMS counts are skipped, and a multi-nozzle preset gets no nozzle sync from an
|
|
unidentified or unknown model. A change of print target during the sync stops it and says so. When the
|
|
printer sync button leaves something unsynced, a modal report lists it and offers the filaments. The
|
|
project-load preset switch runs for an incompatible printer too.
|
|
|
|
With the setting on, the filament sync does not refuse a printer of another model as another printer; it
|
|
asks the question above, and every other refusal stays. The printer sync button's Yes covers the one
|
|
filament step it offers; if the printer or its inputs changed meanwhile, that step asks again. MCP
|
|
`filament_sync_ams` with a `mode` asks nothing and keeps its refusals; with no arguments it is the
|
|
filament sync button and asks as it does.
|
|
|
|
The diameter, flow and AMS checkmarks show what matches and are recomputed from the config against the
|
|
device on every printer message. The flow mark needs the setting on and a printer that reports flow, and
|
|
with the setting on a single-extruder preset also shows the nozzle mark on its Variant box. A printer of
|
|
the preset's model shows the preset mark whatever its agent; an unidentified or unknown model loses only
|
|
that mark. A printer of another known model, or with a different extruder count, clears every mark, as
|
|
with the setting off.
|
|
|
|
### Several printers
|
|
|
|
`NetworkAgent::agent_for(agent_id)` returns the agent for any registered ID, through a resolver the
|
|
application installs, so a caller is not limited to the live agent. The application holds one printer
|
|
connection at a time. Three places enforce it: `DeviceManager::set_selected_machine()` disconnects the
|
|
previous printer before it connects the new one, `NetworkAgent::set_printer_agent()` disconnects the
|
|
outgoing agent whenever another one goes live, and `GUI_App::restart_networking()` disconnects a
|
|
selected printer of another agent before the rebuild. `DeviceManager::get_print_target()` returns the
|
|
printer Prepare prints to and syncs from, the connected printer. Four places assume the one connection:
|
|
|
|
- `DeviceManager::get_my_machine()` filters by the live agent;
|
|
- `restart_networking()` disconnects `get_selected_machine()`, not every printer in `get_connected_machines()`;
|
|
- `DeviceManager::record_user_last_machine()` and `last_connected_printers` store one `dev_id`, overwriting the last;
|
|
- `is_bbl_agent_selected_printer()` reads the global selection, not the printer a widget shows.
|
|
|
|
Discovery is not tied to the active agent. See [Discovery](#discovery).
|
|
|
|
Cloud operations are selected separately using a provider key. `NetworkAgent` forwards a cloud request
|
|
to the matching `ICloudServiceAgent`, and forwards cloud camera operations with a device ID. The
|
|
printer agent receives a cloud-agent pointer through `set_cloud_agent()` when it is created, allowing
|
|
printer communication to obtain cloud tokens without depending on a concrete cloud implementation.
|
|
|
|
### `IPrinterAgent`
|
|
|
|
`IPrinterAgent` is the printer-facing contract. It covers:
|
|
|
|
- cloud-relay and direct-LAN message delivery;
|
|
- LAN connection, discovery, binding, and certificates;
|
|
- printer subscriptions and callbacks;
|
|
- print operations;
|
|
- filament synchronization;
|
|
- camera capability and local camera URL reporting;
|
|
- printer command methods.
|
|
|
|
Concrete built-in implementations include the Bambu wrapper, the native Orca/Moonraker path, and
|
|
other printer-agent implementations registered by the application. A printer agent may use either
|
|
the cloud agent, a direct LAN connection, or both.
|
|
|
|
An agent may report `tool_display_order(dev_id, tool_count)` from cached device state. Each entry
|
|
is a zero-based device tool ID in display order; for a two-tool printer the first entry is the left
|
|
tool. An empty result leaves the order unspecified. The GUI uses identity order for generic devices
|
|
and the Bambu two-tool convention when the corresponding agent is unavailable. Invalid permutations
|
|
are rejected. This order controls presentation, not the preset's `physical_extruder_map`, which
|
|
routes logical tools to physical tools.
|
|
|
|
### `ICloudServiceAgent`
|
|
|
|
`ICloudServiceAgent` owns authentication and services provided by a cloud backend. It covers login
|
|
state, tokens, user and printer lists, settings synchronization, model services, cloud messages, and
|
|
cloud camera operations.
|
|
|
|
Cloud camera operations are device-scoped:
|
|
|
|
- `get_camera_url(dev_id, callback)` obtains a stream URL for one device;
|
|
- `create_camera_signaling_channel(dev_id)` creates signaling for one device where the provider
|
|
supports it.
|
|
|
|
This is separate from the local camera URL exposed by `IPrinterAgent`, which is currently scoped to
|
|
the active printer agent because a normal LAN agent represents one physical printer connection.
|
|
|
|
## Agent registration and selection
|
|
|
|
`NetworkAgentFactory` maintains the printer-agent registry. Each registry entry contains an agent ID,
|
|
a display name, and a factory function. Built-in agents register during application initialization.
|
|
Python printer-agent capabilities register dynamically and contribute an agent ID and factory entry.
|
|
|
|
The selected printer preset contains the printer-agent choice. If no explicit choice is stored, the
|
|
application preserves the existing default behavior: Bambu presets select the Bambu agent and other
|
|
presets select the native Orca agent. When a preset is changed, `GUI_App` resolves the effective agent
|
|
ID, takes that agent from the registry, which created it when networking was built, and installs it in
|
|
`NetworkAgent`, unless a printer is connected and printer agents are on (see
|
|
[Preset changes and the preset's host](#preset-changes-and-the-presets-host)).
|
|
|
|
The registry rejects conflicting agent IDs. This matters for Python plugins because an agent ID is the
|
|
stable identity used by presets and device ownership; two enabled plugin capabilities must not claim
|
|
the same ID.
|
|
|
|
## Message and command flow
|
|
|
|
There are two low-level message paths:
|
|
|
|
- `send_message()` publishes a command through the printer's cloud relay;
|
|
- `send_message_to_printer()` sends a command directly to the printer over the LAN path.
|
|
|
|
Both paths accept a JSON string, quality-of-service and flag values, and return the existing network
|
|
status code domain. The agent owns the conversion from that JSON contract to its native transport.
|
|
|
|
The typed `command_*` methods are the application-facing convenience layer. The five generic defaults
|
|
currently implemented by `IPrinterAgent` construct the existing JSON dialect and route through the
|
|
same message path:
|
|
|
|
| Method | Default operation |
|
|
| --- | --- |
|
|
| `command_xyz_abs()` | Send `G90` for absolute positioning |
|
|
| `command_auto_leveling()` | Send `G29` for bed leveling |
|
|
| `command_go_home()` | Use the supported homing operation or send `G28` |
|
|
| `command_set_bed()` | Use the supported bed control or send `M140` |
|
|
| `command_set_nozzle()` | Send `M104` for nozzle temperature |
|
|
|
|
These are compatibility defaults for common printer workflows, not a guarantee that every firmware
|
|
implements every command identically. An agent can override a method when its protocol needs another
|
|
operation. For example, a Klipper configuration may use `BED_MESH_CALIBRATE` instead of `G29`.
|
|
|
|
The remaining common command methods default to `ORCA_NETWORK_ERR_CMD_NOT_SUPPORTED` because their
|
|
existing behavior is vendor-specific or has no portable implementation:
|
|
|
|
- AMS RFID refresh;
|
|
- AMS calibration;
|
|
- AMS tray selection;
|
|
- camera start;
|
|
- axis control.
|
|
|
|
The methods remain on the common interface so an agent that supports them can override them explicitly.
|
|
`sequence_id` remains part of the command contract because `DeviceManager` creates and tracks it as
|
|
the command ID. Device-layer commands draw it from one process-wide atomic counter,
|
|
`PrinterSequenceIds`, inside the 20000-29999 band that marks a reply as an answer to this app. The
|
|
counter wraps inside the band, so replies still count as the app's own however many commands a session
|
|
sends. It starts at a random point in the band at each launch, so a printer that remembers recent ids
|
|
does not take a new launch's commands for repeats. The Orca agent's connect requests keep their fixed
|
|
ids in the band.
|
|
|
|
The JSON commands the device layer sends are built in one place, `Utils/OpcpCommands`, with one
|
|
builder per wire message grouped by the message's top-level namespace. `MachineObject` and the
|
|
`DeviceCore` controls call the builders and keep their own gating and state updates; the builders hold
|
|
the field names and types, which are the contract every agent translates. A test pins the exact text
|
|
each command hands its agent, so moving a builder cannot change what a printer receives.
|
|
|
|
## Discovery
|
|
|
|
With the `use_printer_agents` app setting on, every registered printer agent that scans the LAN
|
|
discovers at the same time, whether or not it is the active agent, and each device it finds is recorded
|
|
under that agent.
|
|
|
|
With the setting off (the default) only the active agent discovers. The Orca agent scans in the
|
|
background once one of its printers is configured, and otherwise from when the printer picker is first
|
|
opened; any other active agent always discovers. When another agent goes live, the old one's scan is left
|
|
running with its events dropped, and it reports again once it is live again, since stopping a scan can
|
|
wait on the agent's thread. Every agent is still created up front, as described below, but no other
|
|
agent is started for discovery, and the `disabled_discovery_agents` setting does not apply and is not
|
|
shown in Preferences.
|
|
`GUI_App::refresh_discovery_agents()` picks the mode, and turning the setting on or off applies it at
|
|
once. The rest of this section describes the setting on.
|
|
|
|
`IPrinterAgent::discovers_on_lan()` says whether `start_discovery()` really scans. It defaults to
|
|
false. The Orca agent returns true. The Bambu agent returns true only while the network plug-in is
|
|
loaded, because its discovery runs inside the plug-in. The Moonraker family does not scan: it reports
|
|
the host the user configured in the preset. A Python agent opts in by overriding `discovers_on_lan()`;
|
|
without it, the agent discovers only while it is the active agent.
|
|
|
|
Every registered printer agent exists up front. `NetworkAgentFactory::create_printer_agents()` creates
|
|
the built-in ones when `GUI_App::on_init_network()` builds networking, and hands each cached built-in
|
|
agent the rebuilt cloud agent when networking is rebuilt; a Python agent is put in the cache when its plugin
|
|
registers it, since its capability object is the agent. `NetworkAgentFactory::get_discovery_candidates()`
|
|
only reads that cache, so an agent that scans discovers without a preset having selected it, and
|
|
`discovers_on_lan()` is the only thing that says whether it scans. Creating the agents is cheap: the
|
|
built-in constructors do no I/O and start no threads.
|
|
|
|
The cache also records which agents `create_printer_agent_by_id()` handed out to be selected. Only those
|
|
are disconnected when the cache lets an agent go, at shutdown or when a Python plugin is reloaded or
|
|
unloaded, since the others never connected.
|
|
|
|
`NetworkAgent::sync_discovery()` takes those agents (from the factory's cache, so the active agent and
|
|
the discovering agent are the same object) and makes the discovering set: each agent
|
|
that scans and is not disabled, plus the active agent when it does not scan, so it reports its
|
|
configured host. A scanning active agent that is disabled joins only while a printer picker asks for
|
|
devices (`set_live_discovery_requested()`). Agents that join are started, agents that leave are
|
|
stopped, and the others are left running, so an agent switch never stops or re-registers another
|
|
agent's discovery. `GUI_App::refresh_discovery_agents()` calls it at startup, after an agent switch,
|
|
after the network plug-in is reloaded, and when a Python printer agent is registered or deregistered.
|
|
|
|
Each discovering agent has its own SSDP callback, which carries the agent's id, and its own session
|
|
token. A callback only queues work onto the UI thread while its session is alive, and the queued work
|
|
checks the session again, so nothing from an agent fires after it was stopped, replaced, deregistered
|
|
or its `NetworkAgent` destroyed. Shutdown stops every discovering agent except the Bambu agent, whose
|
|
plug-in scan is stopped only on Windows. Nothing clears the listener at shutdown (only a network
|
|
plug-in reload does); an event that still arrives is dropped because the listener checks
|
|
`GUI_App::is_closing()`, and every session expires when the `NetworkAgent` is destroyed.
|
|
|
|
The `disabled_discovery_agents` app setting turns a scanning agent's background discovery off. It holds
|
|
agent ids joined by `;` and is empty by default, so every scanning agent discovers. It does not affect
|
|
an active agent that only reports its configured host. While printer agents are on, Preferences shows it
|
|
on the Online tab under Printer discovery as one checkbox per agent whose `discovers_on_lan()` is true,
|
|
checked while it discovers: the Orca agent, the Bambu agent while its network plug-in is loaded, and any
|
|
Python agent that opts in.
|
|
|
|
`DeviceManager::on_machine_alive()` receives the id of the agent that found the device and uses it
|
|
instead of the active agent. A discovery does not take over a device that another agent owns: one saved
|
|
in the app config, one in that agent's cloud list, or one in the local list. The active agent is the
|
|
exception for two of them. It takes over a local record another agent only found, one that is not
|
|
connected and not saved under that agent, so arrival order does not decide which agent owns a printer
|
|
they both find. It also takes over a cloud record, which is owned by whichever agent was active when the
|
|
list was fetched, and nothing fetches the list again on an agent switch. A refused discovery is logged
|
|
once per device and agent, then ignored. With `use_printer_agents` on, a device with no owner counts as
|
|
the preset's agent's (`DeviceManager::printer_owner_agent_id()`), so only that agent's discovery takes it
|
|
over and records itself as the owner in memory; a device saved without an owner is not saved again by a
|
|
discovery, which would save the guessed owner and the announced name, and is saved only by a successful
|
|
connect. With it off, any finder takes it and the record is saved. Changing the owner is deliberate
|
|
and goes through `DeviceManager::insert_local_device()`, called for the agent the user selected.
|
|
`clear_other_devices()` keeps the devices the other agents discovered across an agent switch. It removes
|
|
the devices with no owner unless the setting is on, which lists them under the preset's agent.
|
|
|
|
## Device ownership and stale responses
|
|
|
|
Printer-agent ownership is represented by `printer_agent_id` on device records and `MachineObject`
|
|
instances. The finding agent's ID is attached when a device is discovered and the active agent's ID when
|
|
one is returned by a cloud list. `insert_local_device()` sets the owner its caller passes, else the
|
|
active agent's ID; with the setting on, the caller passes the preset's agent for the preset's host or a
|
|
printer added by IP address. With the setting on, a device with no owner is saved under the agent it
|
|
connects through once that connect succeeds. Local-machine configuration also persists the agent ID so a
|
|
saved LAN device is not silently reused by an unrelated agent.
|
|
|
|
Cloud printer-list responses carry three pieces of request context added by `NetworkAgent`:
|
|
|
|
```text
|
|
provider cloud provider used for the request
|
|
agent_id active printer agent when the request was made
|
|
generation machine-list generation when the request was made
|
|
```
|
|
|
|
`DeviceManager` accepts the response only when those values still match the current provider, active
|
|
agent, and generation. This prevents a slow response from the previous preset or provider from
|
|
repopulating the current device list.
|
|
|
|
The provider mapping is currently selected by `GUI_App`: the Bambu agent maps to the Bambu cloud
|
|
provider and other agents map to the Orca cloud provider. The generation check protects that existing
|
|
selection from races; it does not make cloud-provider ownership intrinsic to an agent. Cloud-printer
|
|
ownership and the broader Orca cloud services are therefore still separate architectural concerns.
|
|
|
|
## Printer model identity
|
|
|
|
Model identity is separate from printer-agent ownership. `MachineObject::printer_type` can contain a
|
|
saved or preset-derived value, but `printer_model_advertised` marks whether the model was actually
|
|
reported by the printer. Saved and manually supplied values are not proof of the connected model.
|
|
Agents must provide a printer-reported model in binding and discovery responses, or leave it empty;
|
|
Moonraker also accepts a model reported by `/server/info`.
|
|
|
|
`DevPrinterConfigUtil` resolves reported IDs and names using installed vendor models and legacy
|
|
protocol aliases to obtain a canonical model ID; ambiguous aliases are not resolved. An empty report
|
|
makes no new model claim, while a nonempty unrecognized report leaves the model unknown. Compatibility
|
|
checks compare the canonical ID with the selected preset's model ID, while retaining the existing
|
|
compatible-machine and upgrade-kit rules; an installed upgrade kit changes the shown model used for
|
|
comparison, not the advertised identity. With `use_printer_agents` off, a missing or unrecognized model
|
|
is optional: the user is warned, but model compatibility does not block printing. With it on, Print and
|
|
Send to such a printer are blocked when its agent differs from the preset's (see
|
|
[Printing and sending to another agent's printer](#printing-and-sending-to-another-agents-printer)).
|
|
|
|
The agents resolve a reported model against the installed vendors and leave `printer_type` empty when
|
|
none knows it, so `MachineObject::reported_printer_model` keeps the id as the printer reported it; such a
|
|
printer counts as an unknown model, not an unidentified one. It is cleared whenever the model stops
|
|
counting as advertised (a model taken from a preset, the Bambu C11 fallback, or a change of owning agent),
|
|
so a stale report never offers a switch.
|
|
|
|
With `use_printer_agents` off, model sync does not choose a printer or nozzle preset for an unknown
|
|
model, nor an arbitrary nozzle variant for a recognized model. With it on, a sync started by hand can
|
|
switch to, or install, the printer's own preset and switch the nozzle variant (see
|
|
[Syncing from an incompatible printer](#syncing-from-an-incompatible-printer)).
|
|
|
|
## Python printer agents
|
|
|
|
`PrinterAgentPluginCapability` implements `IPrinterAgent` directly. The live capability object is
|
|
registered with `NetworkAgentFactory` and handed out as the printer agent when its agent ID is selected.
|
|
The plugin receives the selected `ICloudServiceAgent` through `set_cloud_agent()` just like a built-in
|
|
printer agent.
|
|
|
|
When a plugin starts to unload, its capability is marked as unloading before its calls are drained and
|
|
its module is released. From then on every `IPrinterAgent` method of the capability answers with the
|
|
value of a missing agent instead of calling into Python, so the host can keep holding the agent, as a
|
|
deferred deregistration or a discovery refresh does. The guard has two limits. A call that is already
|
|
inside Python when the mark is set is waited for only 2 s before the module is released. And when the
|
|
unload runs on a worker thread, the deregistration is deferred to the UI thread and runs after the
|
|
mark, so the plugin never receives the `disconnect_printer()` or `start_discovery(False)` that
|
|
deregistration sends; a plugin must not rely on them to release its connections or threads.
|
|
|
|
Python plugins must implement the core communication and lifecycle methods required by the interface,
|
|
including agent metadata, printer connection, discovery callbacks, and the two message-send methods.
|
|
Methods that are meaningful only to a particular printer are optional overrides where the C++ base
|
|
class provides a default.
|
|
|
|
All ten `command_*` methods are available in the Python binding and in the trampoline. Their override
|
|
status is intentionally optional:
|
|
|
|
- the five generic commands use the C++ default when Python does not override them;
|
|
- the five vendor-specific commands return `NOT_SUPPORTED` unless Python supplies an implementation;
|
|
- a Python implementation can replace either behavior for its own protocol.
|
|
|
|
The Python camera binding exposes HTTP, HTTPS, RTSP, and HTTP-snapshot modes. WebRTC remains a
|
|
built-in C++ camera mode, but is not exposed as a Python mode because the current Python capability
|
|
does not provide the corresponding cloud signaling-channel contract.
|
|
|
|
## Camera playback boundary
|
|
|
|
The camera stream mode describes how a stream is obtained; it does not by itself define ownership of
|
|
the wxWidgets view that renders it. `MediaPlayCtrl` selects and tears down the active backend, while
|
|
the wx parent owns the child window or renderer. This is important because a web view, native media
|
|
control, and frame-based/WebRTC renderer have different wx window-lifetime requirements.
|
|
|
|
Cloud URL and signaling requests are routed through `NetworkAgent` to the cloud provider selected for
|
|
the device. Local URL requests are routed to the active printer agent. The distinction keeps cloud
|
|
account services device-scoped while preserving the current one-LAN-agent/one-printer model.
|
|
|
|
## Compatibility constraints
|
|
|
|
The printer-agent boundary intentionally preserves several existing application contracts:
|
|
|
|
- Bambu-shaped JSON is still the shared command representation;
|
|
- existing network status codes are reused, with Orca-specific unsupported/capability errors added
|
|
in the Orca-reserved range;
|
|
- `MachineObject` remains the shared device-state model;
|
|
- preset and local-machine data retain compatibility with the existing agent-selection behavior;
|
|
- Python plugins use the existing capability and pybind11 registration system.
|
|
|
|
The agent abstraction is therefore responsible for containing vendor differences, not for pretending
|
|
that all vendor protocols are identical. The planned Orca JSON dialect is the protocol-neutral command
|
|
model for the `DeviceManager`/agent boundary. Once it is introduced, Bambu-specific translation remains
|
|
inside the Bambu agent and the Orca agent's v1 sink adapter can be removed as a self-contained cleanup.
|
|
|
|
## Main implementation locations
|
|
|
|
- [`IPrinterAgent`](../../src/slic3r/Utils/IPrinterAgent.hpp) — printer-agent contract and generic command defaults
|
|
- [`ICloudServiceAgent`](../../src/slic3r/Utils/ICloudServiceAgent.hpp) — cloud service and per-device
|
|
cloud camera contract
|
|
- [`NetworkAgent`](../../src/slic3r/Utils/NetworkAgent.hpp) — façade and dispatch between active agents
|
|
- [`NetworkAgentFactory`](../../src/slic3r/Utils/NetworkAgentFactory.hpp) — built-in and Python agent registry
|
|
- [`DeviceManager`](../../src/slic3r/GUI/DeviceCore/DevManager.cpp) — device ownership, filtering, and
|
|
stale-response checks
|
|
- [`PrinterAgentPluginCapability`](../../src/slic3r/plugin/pluginTypes/printerAgent/PrinterAgentPluginCapability.cpp)
|
|
— Python bindings
|
|
- [`MediaPlayCtrl`](../../src/slic3r/GUI/MediaPlayCtrl.cpp) — camera backend selection and playback lifecycle
|