feat: Python xbot_service_interface library#25
Merged
Conversation
Runtime serialization (no codegen) for connecting to xBot services from Python. Supports both schema-validated (Mode 1) and schema-from-advertisement (Mode 2) modes. - datatypes.py: XbotHeader/DataDescriptor/ClaimPayload struct formats, MessageType enum - serialization.py: type string parser, pack/unpack for all C primitives, char arrays, enums - schema.py: ServiceSchema wrapping service.json, lookup by id/name/snake_name - discovery.py: multicast listener on 233.255.255.0:4242, CBOR advertisement parse - io.py: unicast UDP, claim flow, heartbeat watchdog, send_data/send_transaction - interface.py: ServiceInterface with dynamic send_*/on_*_changed dispatch, RegisterProxy, transaction context manager - manager.py: XbotServiceIo tying discovery + IO + interfaces together - examples/: echo_with_schema.py (Mode 1) and echo_no_schema.py (Mode 2)
b692c2a to
d34db42
Compare
Add 331 tests across datatypes, serialization, schema, interface, io and discovery. Bugs fixed: - serialization: parse_type_string regex rejected uppercase enum type names (e.g. MotorMode) — changed [a-z_] to [a-zA-Z_] - discovery: _handle_packet crashed when malformed CBOR decoded to a non-dict object instead of raising — added isinstance(msg, dict) guard
The service resets all registers to defaults before applying any config transaction (HandleConfigurationTransaction calls loadConfigurationDefaults then allRegistersValid). Sending a single-register transaction left required registers invalid, causing 'Configuration message did not contain all required registers' on every live register update.
- Rename top-level directory from xbot_py to xbot_service_interface to match library name and C++ sibling convention (libxbot-service-interface) - Fix pyproject.toml build-backend (setuptools.backends.legacy → build_meta) - Add full PyPI metadata: author, license, classifiers, project URLs - Add README.md for PyPI landing page with API overview and examples - Add py.typed marker for PEP 561 type checking support - Update .gitignore to exclude dist/, build/, *.egg-info/ - Verified: python -m build produces sdist + wheel successfully
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
send_{input_name}(value)methods andon_{output_name}_changedcallbacks via__getattr__/__setattr__— mirrors C++ generated API in snake_caseservice.registers['Name'] = valuedict-like proxy; sent immediately if connected, queued for nextCONFIGURATION_REQUESTotherwisewith service.transaction(): ...Test plan
pip install cbor2EchoService(C++ example binary)python examples/echo_with_schema.py— Mode 1: schema validation, register config, echo callbackspython examples/echo_no_schema.py— Mode 2: schema from advertisement, no local JSON needed