Repository navigation
Conversation
- Implemented `write_ntag_pages` method in `GpioEnabledRfidReader` to handle NTAG21x page writes. - Enhanced `Runtime` class to manage pending NTAG write requests with a dedicated queue and threading support. - Introduced `_PendingWrite` class to encapsulate write request state. - Updated `TigerTagProcessor` to parse and log custom messages from the NTAG payload. - Created `encoder` module for TigerTag to encode specifications into a 96-byte payload, including message handling. - Added tests for pending write functionality and encoder round-trip validation. - Updated existing TigerTag YAML configurations to include bed temperature and message fields.
- Implemented `write_ntag_pages` method in `GpioEnabledRfidReader` to handle NTAG21x page writes. - Enhanced `Runtime` class to manage pending NTAG write requests with a dedicated queue and threading support. - Introduced `_PendingWrite` class to encapsulate write request state. - Updated `TigerTagProcessor` to parse and log custom messages from the NTAG payload. - Created `encoder` module for TigerTag to encode specifications into a 96-byte payload, including message handling. - Added tests for pending write functionality and encoder round-trip validation. - Updated existing TigerTag YAML configurations to include bed temperature and message fields.
…nRFID into feat/ntag-write-api
There was a problem hiding this comment.
🟡 Not ready to approve
There are confirmed correctness/API issues in the new write queue and agent endpoints (pending write overwrite, missing error on None status, misleading scan_slot response, and ISO-8601 timestamp parsing gaps) that should be fixed before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR introduces a Moonraker JSON-RPC agent API for OpenRFID, adds an event-exporter to broadcast scan activity to UIs (Mainsail/Fluidd), extends the filament data model with bed temp max + custom message, and adds NTAG21x write support (including a TigerTag payload encoder) to enable remote tag programming.
Changes:
- Add
OpenrfidApiControllerandOpenrfidAgentEventExporterto expose/broadcast OpenRFID channel operations and scan events via Moonraker. - Implement NTAG page writing in the FM175xx reader stack and add a pending-write queue in
Runtimeto serialize writes onto the read loop. - Add TigerTag payload encoding + message/bed-temp parsing, update filament model serialization, and extend/refresh test fixtures and new tests.
File summaries
| File | Description |
|---|---|
| test/test_tigertag_encoder.py | New round-trip tests validating TigerTag encoding and message truncation behavior. |
| test/test_runtime_pending_write.py | New tests covering runtime pending-write submission/drain semantics and edge cases. |
| test/tags/Tigertag/Sunlu PLA Roasted Chestnut TigerTag+.yml | Update expected parsed bed temps; add new fields bed_temp_max_c and message. |
| test/tags/Tigertag/Rosa3D PLA Starter Lithophane Yellow TigerTag+.yml | Update expected parsed bed temps; add new fields bed_temp_max_c and message. |
| test/tags/Tigertag/Rosa3D PLA Starter Lithophane White TigerTag+.yml | Update expected parsed bed temps; add new fields bed_temp_max_c and message. |
| test/tags/Tigertag/Rosa3D PLA Starter Lithophane Magenta TigerTag+.yml | Update expected parsed bed temps; add new fields bed_temp_max_c and message. |
| test/tags/Tigertag/Rosa3D PLA Starter Lithophane Cyan TigerTag+.yml | Update expected parsed bed temps; add new fields bed_temp_max_c and message. |
| test/tags/Tigertag/R3D PETG HS Carbon Fiber Black TigerTag+.yml | Update expected parsed bed temps; add new fields bed_temp_max_c and message. |
| test/tags/Tigertag/eSun PLA Basic Refill Cold White TigerTag+.yml | Update expected parsed bed temps; add new fields bed_temp_max_c and message. |
| test/tags/Tigertag/Elegoo PLA Basic Grey.yml | Update expected bed temp, normalize quoting, add bed_temp_max_c and message. |
| src/tag/tigertag/processor.py | Parse TigerTag message metadata; populate bed temp min/max + message in GenericFilament. |
| src/tag/tigertag/encoder.py | New TigerTag 96-byte payload encoder for writing NTAG user pages. |
| src/tag/tigertag/constants.py | Define message offsets/length within the metadata region. |
| src/runtime.py | Add pending write queue + drain hook; persist last scan per slot for agent listing. |
| src/reader/gpio_enabled_rfid_reader.py | Add NTAG write wrapper framed by GPIO session begin/end. |
| src/reader/fm175xx/rfid.py | Implement low-level NTAG page write support with validation and ACK checking. |
| src/main.py | Register new controller/exporter entity types in the factory wiring. |
| src/filament/generic.py | Extend filament model with bed_temp_max_c and message, include them in to_dict(). |
| src/exporters/openrfid_agent_event.py | New bounded-queue exporter for scan event buffering for the agent API. |
| src/controllers/openrfid_api.py | New Moonraker agent controller exposing list/scan/write/clear/encode methods + event broadcast loop. |
| examples/u1.cfg | Document configuration example for enabling the agent API and event exporter. |
Review details
- Files reviewed: 21/21 changed files
- Comments generated: 5
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
…age, scan_slot validation, ISO-8601 timestamp
There was a problem hiding this comment.
🟡 Not ready to approve
There are concrete concurrency and correctness issues in the new agent + write-queue integration (thread-unsafe socket sends and write/session/timeout handling) that can cause corrupted Moonraker traffic or failed/misreported NTAG writes.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (2)
src/runtime.py:116
- submit_write() can incorrectly report a timeout while a write is actually being drained: _drain_pending_write() pops the entry before doing the write, so a timeout path that blindly pops the slot can race with the drain and return "timeout" even though the write may still complete. Only cancel the pending write if it is still queued, and otherwise treat it as in-progress and wait briefly for a result (or return a distinct "in progress" error).
if not pending.event.wait(timeout=timeout):
with self._pending_write_lock:
self._pending_writes.pop(slot, None)
return {"ok": False, "error": "timeout waiting for write"}
src/runtime.py:152
- _drain_pending_write() calls reader.write_ntag_pages() without ensuring an active RFID session. For readers configured directly as Fm175xx (not wrapped by GpioEnabledRfidReader), write_ntag_pages() requires the carrier wave to be enabled via start_session(), so writes can fail even though reads work. Consider wrapping the write in start_session()/end_session() when available (and avoid double-wrapping for GPIO wrappers).
write = getattr(reader, "write_ntag_pages", None)
if not callable(write):
pending.result = {"ok": False, "error": "reader does not support NTAG writes"}
pending.event.set()
return True
try:
status = write(pending.start_page, pending.data)
- Files reviewed: 21/21 changed files
- Comments generated: 1
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ssing - Introduced comprehensive unit tests for the FM175XX guarded TigerTag Maker transaction in `test_safe_tigertag_writer.py`, covering various scenarios including header invalidation, tag recognition, and error handling. - Updated `test_tags.py` to include expected tag formats for various processors, ensuring consistency in tag processing. - Refactored `test_tigertag_encoder.py` to improve clarity and coverage of encoding and decoding functionalities, including validation of maker payloads and handling of legacy formats. - Added tests for message limits, color handling, and quantity units to ensure robust processing of filament specifications.
Introduce a new Moonraker JSON-RPC agent API for OpenRFID, enabling remote control and monitoring of RFID channels via web UIs like Mainsail/Fluidd. It adds an event exporter to broadcast scan events, extends the filament data model, and implements NTAG write support in the RFID readers. The main highlights are grouped below:
OpenRFID Moonraker Agent API:
OpenrfidApiController(src/controllers/openrfid_api.py) to expose OpenRFID operations (list_channels,scan_slot,write_tag,clear_tag,tigertag_encode) over Moonraker JSON-RPC, with write operations gated by a config flag for safety.examples/u1.cfg) to show how to enable the new agent and event exporter.src/main.py). [1] [2]Agent Event Exporter:
OpenrfidAgentEventExporter(src/exporters/openrfid_agent_event.py), a queue-based exporter that buffers scan events for the agent to broadcast, supporting event selection and queue size configuration.RFID Write Support:
write_ntag_pagesin bothFm175xxandGpioEnabledRfidReaderto allow writing to NTAG21x tags, including session management and error handling. [1] [2]Filament Data Model Extensions:
GenericFilamentto includebed_temp_max_candmessagefields, and updated serialization to include these. [1] [2] [3]Runtime Write Operation Support:
_PendingWriteclass inruntime.pyto manage asynchronous write requests, laying groundwork for agent-initiated write operations.