Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(firmware identity, motion limits, unit reporting) is computed by
the raydriver library now; Rayforge only maps the result onto its
device profiles
- Machine: network discovery of FluidNC/ESP3D devices and the xTool
machine-type query now use the raydriver library's HTTP probes
instead of local aiohttp code
- Dependencies: raydriver upgraded to 1.11.0, pinned to a git
revision pending the 1.12.0 release

Expand Down
84 changes: 0 additions & 84 deletions rayforge/machine/driver/grbl/grbl_fingerprint.py

This file was deleted.

7 changes: 5 additions & 2 deletions rayforge/machine/driver/grbl/grbl_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from gettext import gettext as _
from typing import Any, cast

from raydriver.core.discovery.fingerprints import HttpFingerprint
from raydriver.core.discovery.spec import DiscoverySpec, MdnsRecognizer
from raydriver.esp3d import Esp3dConfig, Esp3dSession

from ....core.varset import ChoiceVar, HostnameVar, PortVar, VarSet
from ....core.varset.hostnamevar import is_valid_hostname_or_ip
from ..driver import DriverPrecheckError, DriverSetupError
from .grbl_fingerprint import fingerprint_grbl_http
from .grbl_serial import GrblSerialDriver

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -36,7 +36,10 @@ class GrblNetworkDriver(GrblSerialDriver):
DISCOVERY = DiscoverySpec(
mdns=MdnsRecognizer(
services=("_esp3d._tcp.local.",),
fingerprint=fingerprint_grbl_http,
fingerprint=HttpFingerprint(
path="/command?plain=%5BESP800%5D&PAGEID=",
match_regex=r"\b(fluidnc|esp3d|grblhal|grbl)\b",
),
)
)

Expand Down
51 changes: 3 additions & 48 deletions rayforge/machine/driver/xtool/xtool_network.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import json
import logging
from collections.abc import Awaitable, Callable
from gettext import gettext as _
Expand All @@ -9,9 +8,8 @@
cast,
)

import aiohttp
from raydriver.core import SessionEvent
from raydriver.xtool import XtoolSession
from raydriver.xtool import XtoolSession, query_machine_type

from ....context import RayforgeContext
from ....core.varset import HostnameVar, PortVar, VarSet
Expand Down Expand Up @@ -48,47 +46,6 @@
DEFAULT_HTTP_PORT = 8080
DEFAULT_WS_PORT = 8081

XTOOL_MACHINE_TYPE_URL = "/getmachinetype"


async def fetch_xtool_machine_type(
host: str, port: int, timeout: float = 2.0
) -> str | None:
"""
GETs the xTool machine-type endpoint and returns the reported
machine type (e.g. ``"xTool D1Pro"``) when the device identifies
itself as an xTool machine, ``None`` otherwise. Never raises.
"""
url = f"http://{host}:{port}{XTOOL_MACHINE_TYPE_URL}"
try:
async with (
aiohttp.ClientSession() as session,
session.get(
url, timeout=aiohttp.ClientTimeout(total=timeout)
) as response,
):
if response.status != 200:
return None
text = await response.text()
except Exception:
logger.debug(
"xTool machine-type query of %s:%s failed",
host,
port,
exc_info=True,
)
return None
try:
payload = json.loads(text)
except ValueError:
return None
if not isinstance(payload, dict):
return None
machine_type = str(payload.get("type") or "")
if "xtool" in machine_type.lower():
return machine_type
return None


class XtoolNetworkDriver(Driver):
"""
Expand Down Expand Up @@ -200,11 +157,9 @@ async def probe(
kwargs = dict(kwargs)
host = cast(str, kwargs.get("host", ""))
port = cast(int, kwargs.get("http_port", DEFAULT_HTTP_PORT))
machine_type = await fetch_xtool_machine_type(host, port)
machine_type = await query_machine_type(host, port)
if machine_type is None and port != DEFAULT_HTTP_PORT:
machine_type = await fetch_xtool_machine_type(
host, DEFAULT_HTTP_PORT
)
machine_type = await query_machine_type(host, DEFAULT_HTTP_PORT)
if machine_type is not None:
kwargs["http_port"] = DEFAULT_HTTP_PORT
if machine_type is None:
Expand Down
91 changes: 0 additions & 91 deletions tests/machine/driver/grbl/test_grbl_fingerprint.py

This file was deleted.

13 changes: 8 additions & 5 deletions tests/machine/driver/test_discovery_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import pytest
from raydriver.core.discovery import mdns_channel
from raydriver.core.discovery.engine import find_all_devices
from raydriver.core.discovery.fingerprints import TcpFingerprint
from raydriver.core.discovery.fingerprints import (
HttpFingerprint,
TcpFingerprint,
)
from raydriver.core.discovery.mdns_channel import find_network_devices
from raydriver.core.discovery.mdns_scan import MDNSService
from raydriver.core.discovery.spec import DiscoverySpec, MdnsRecognizer
Expand All @@ -31,9 +34,6 @@
OctoPrintDriver,
drivers,
)
from rayforge.machine.driver.grbl.grbl_fingerprint import (
fingerprint_grbl_http,
)

SCULPFUN_ICUBE_BANNER = (
b"[VER:1.0.15,20240923:]\r\n"
Expand Down Expand Up @@ -251,7 +251,10 @@ def test_builtin_mdns_declarations():
assert octo_spec.mdns.txt_map == {"path": "path"}
grbl_net_spec = GrblNetworkDriver.DISCOVERY
assert grbl_net_spec is not None and grbl_net_spec.mdns is not None
assert grbl_net_spec.mdns.fingerprint is fingerprint_grbl_http
fingerprint = grbl_net_spec.mdns.fingerprint
assert isinstance(fingerprint, HttpFingerprint)
assert fingerprint.path == "/command?plain=%5BESP800%5D&PAGEID="
assert fingerprint.match_regex == r"\b(fluidnc|esp3d|grblhal|grbl)\b"
assert grbl_net_spec.mdns.fingerprint_services == ("_http._tcp",)
telnet_spec = GrblTelnetDriver.DISCOVERY
assert telnet_spec is not None and telnet_spec.mdns is not None
Expand Down
Loading