Skip to content

Feat/companion#51

Merged
rightup merged 128 commits intodevfrom
feat/companion
Mar 27, 2026
Merged

Feat/companion#51
rightup merged 128 commits intodevfrom
feat/companion

Conversation

@rightup
Copy link
Copy Markdown
Collaborator

@rightup rightup commented Mar 27, 2026

New Features

  • Added gpiod backend + gpiochip support
  • Introduced KISS modem support (radio type, wrapper, config)
  • Added CH341 USB SPI/GPIO driver (async + full support)
  • Implemented Companion system (modules, protocol, frame server, APIs)
  • Added contact management, path discovery, and messaging features
  • Introduced Listen-Before-Talk (LBT) for KISS modem
  • Added Ed25519-based identity / crypto handling
  • Support for multi-byte path/hash encoding

Enhancements

  • Improved KISS modem wrapper (callbacks, event loop, spec compliance)
  • Enhanced Companion messaging, routing, and advert pipeline
  • Added RSSI/SNR tracking in messages
  • Improved connection handling, timeouts, and async processing
  • Better error handling across GPIO, CH341, and networking
  • Enhanced radio handling (SX126x/SX1262 performance & RX gain)
  • Improved group messaging + path extraction + routing logic

Refactoring & Internal Improvements

  • Refactored Companion modules, handlers, and frame server
  • Cleaned up CH341 driver + GPIO polling logic
  • Improved packet building, hashing, and dispatcher logic
  • Restructured KISS modem command handling
  • General code cleanup (indentation, comments, docs, unused code removal)

Fixes

  • Fixed Companion message duplication, ACK handling, and persistence
  • Corrected path handling (length, truncation, multi-hop stats)
  • Fixed client timeout and connection stability issues
  • Improved frame handling, writer tasks, and async draining
  • Fixed frequency validation and config issues
  • Addressed KISS modem RX buffering / stale data issues
  • Various protocol and packet handling fixes

Misc / Maintenance

  • Merged multiple feature branches (newRadios, companion v2, etc.)
  • Updated documentation (KISS modem + companion protocol)
  • Added gpiod dependency and hardware-related updates
  • Minor tweaks to logging, validation, and constants

theshaun and others added 30 commits January 23, 2026 18:13
…update related documentation

- Updated radio type choices in various example scripts to include 'kiss-modem'.
- Enhanced the create_radio function to support 'kiss-modem' with specific configuration and identity handling.
- Added conditional imports for KissSerialWrapper and KissModemWrapper in the hardware module.
- Updated documentation to reflect changes in radio type options and identity creation logic.
…packet metrics

- Updated the RX callback to accept both (data) and (data, rssi, snr) signatures for improved flexibility.
- Implemented a helper function to invoke the callback with the appropriate number of arguments.
- Modified the dispatcher to handle per-packet RSSI and SNR values, ensuring accurate metrics without race conditions.
- Added a test to verify that the RX callback correctly receives per-packet RSSI and SNR values.
…allbacks

- Introduced a method to set an asyncio event loop for safe callback invocation from background threads.
- Updated the RX callback dispatcher to utilize the event loop when set, ensuring proper async integration.
- Modified the constructor and documentation to reflect changes in callback handling and configuration options.
- Added tests to verify event loop functionality and compatibility with radio configuration keys.
This commit introduces a new driver for the CH341 USB-to-SPI/GPIO interface, utilizing ctypes to directly call libusb for asynchronous operations. The implementation includes support for SPI transfers, GPIO control, and proper handling of USB transfers with error management. Key features include:

- Singleton pattern for driver instance management.
- Asynchronous transfer handling with callbacks.
- GPIO pin manipulation methods for setting direction and state.
- SPI transfer methods with support for both output and input operations.
- Comprehensive error handling and logging throughout the driver.

This driver aims to provide a reliable interface for interacting with CH341 devices in Python.
…rmance; remove unused code and streamline CAD logic
…e; remove unnecessary debug code and enhance edge detection handling
…ulation

- Changed method signature of calc_shared_secret to accept a 32-byte Ed25519 public key instead of X25519.
- Updated documentation to clarify the internal conversion from Ed25519 to X25519 by the modem.
- Added validation to ensure the provided public key is the correct length.
- Enhanced comments for better understanding of the key exchange process.
…ions

- Adjusted command constants for KISS Modem to reflect the correct values as per firmware documentation.
- Renumbered CMD and RESP constants to ensure consistency and avoid conflicts with firmware commands.
- Enhanced comments for clarity regarding the changes made to the command structure.
- Implemented LBT mechanism to check channel availability before transmission, aligning with MeshCore firmware specifications.
- Introduced LBT retry delays and maximum wait time to manage channel busy states.
- Updated send method to return detailed transmission metadata, including LBT metrics.
- Refactored timestamp retrieval in Dispatcher to use asyncio.get_running_loop for better compatibility.
- Added a cleanup method to release modem resources by disconnecting the serial and stopping threads.
- Added a check_radio_health method to verify modem connectivity and respond to pings, enhancing reliability.
- Added a get_status method to retrieve comprehensive radio status, including configuration and statistics.
- Updated command and response constants to align with the new SetHardware protocol.
- Introduced new sub-commands and responses for hardware interactions.
- Enhanced error handling and validation for frame sizes.
- Improved test cases to cover new command structures and ensure correct frame decoding.
…xecution

- Introduced a new method `_write_frame` to ensure complete KISS frame writes to the serial port, enhancing reliability.
- Implemented a `ThreadPoolExecutor` for non-blocking RX callback execution, preventing dropped packets during heavy processing.
- Improved error handling for frame size and invalid escape sequences, ensuring better synchronization and robustness.
- Updated documentation to reflect changes in protocol specifications and callback mechanisms.
…eporting

- Added new command constants for setting and getting signal reports.
- Renumbered response constants to comply with updated protocol specifications.
- Updated test cases to reflect changes in response handling for RxMeta frames.
- Added methods for setting KISS parameters: persistence, slottime, txtail, and full duplex.
- Updated host-side Listen-Before-Talk (LBT) functionality to default to off, with related methods for enabling/disabling.
- Updated the create_radio function to include additional parameters for serial port configuration.
- Enhanced documentation and test cases to cover new features and ensure compliance with protocol specifications.
agessaman and others added 29 commits March 5, 2026 16:28
feat(companion): implement multi-byte path hash encoding and management
- Added logging for optional LPP parse failures in binary parsing functions to improve debugging.
- Introduced a method to retrieve the group text handler for node name synchronization in CompanionBase, CompanionBridge, and CompanionRadio classes.
- Updated path length validation in Packet class to provide clearer error messages for invalid encodings.
- Enhanced tests to ensure proper handling of path length constraints and error scenarios.
- Added `set_path_hash_mode` method to CompanionBase and CompanionRadio to configure path hash mode for flood packets.
- Introduced default path hash mode in Dispatcher for flood packets with 0 hops, allowing compatibility with packets built without the companion.
- Updated Packet class to apply path hash mode and prevent overwriting when already set by the companion.
- Enhanced tests to validate path hash mode functionality and ensure correct behavior for flood packets and TRACE payloads.
…erver

- Changed _DRAIN_BATCH to 1 to ensure clients remain in sync with sends after every frame.
- Updated error handling in _write_err to use ERR_CODE_NOT_FOUND for both bad channel and sendGroupMessage failures, aligning with firmware expectations.
…ses in CompanionFrameServer

- Adjustments to improve compatibility with meshcore_py.
- Changed client_idle_timeout_sec parameter to accept None, allowing users to disable the idle timeout and match firmware behavior.
- Updated documentation to clarify the new behavior regarding connection management and idle timeout settings.
feat(companion, dispatcher): implement path hash mode for flood packets
- Added cancellation and awaiting of the old writer task to ensure proper cleanup before creating a new task.
- Enhanced error handling to log exceptions from the writer task if it fails, improving debugging and stability during client disconnections.
- Refactored writer task management to use a local variable for improved readability and performance.
- Simplified the condition checks for the writer task's state, enhancing code clarity and maintainability.
…n receiving REQ via flood

- Updated response building logic to handle routing based on client out_path, ensuring correct packet types are returned.
- Enhanced tests for ProtocolRequestHandler to validate response generation under various scenarios, including flood and direct requests.
Improve writer task management and update ProtocolRequestHandler
- Refactored path length validation in the _BridgeAckHandler to utilize PathUtils for improved accuracy.
- Updated tests to ensure correct ACK extraction for 2-byte and 3-byte hashes, validating the new path length logic.
- Introduced path_len_encoded parameter in PacketBuilder to support encoded path lengths for improved compatibility with 2-byte and 3-byte hashes.
- Updated LoginServerHandler, ProtocolRequestHandler, and TextMessageHandler to utilize the new path_len_encoded logic.
- Enhanced tests to validate correct behavior of path length encoding in packet creation and ensure alignment with firmware expectations.
- Enhanced path length validation in PacketBuilder to ensure proper handling of truncated paths, capping at 63 bytes when necessary.
- Updated tests to verify correct behavior of path length encoding and consistency across various packet creation scenarios, including text messages and protocol requests.
- Ensured that packets built with truncated paths maintain integrity during write/read operations.
…eliveries

- Added a time-to-live (TTL) mechanism for pending RX data in the KissModemWrapper to drop stale payloads before receiving RxMeta, enhancing data integrity.
- Updated the handling of the pending RX queue to include timestamps and ensure old data is discarded appropriately.
- Introduced a new test to verify that pending data older than the TTL is correctly dropped, preventing ghost deliveries.
- Enhanced the _cmd_set_flood_scope method to correctly process the flood scope data by adjusting the expected data length and updating the slicing logic to align with firmware requirements.
- Added detailed docstring to clarify the wire format for flood scope data.
- Introduced integration tests to verify the correct behavior of channel messages with flood scope, ensuring compatibility with firmware expectations.
Refine path length handling and validation in ACK processing and packets
…d async wrapper

- Changed push_trace_data from async to sync for immediate enqueueing, aligning with usage patterns.
- Introduced push_trace_data_async as an optional async wrapper for compatibility with existing async call sites.
- Updated documentation and tests to reflect changes in trace data handling and ensure correct functionality.
fix(companion): refactor push_trace_data to synchronous method and add async wrapper
- Updated the _cmd_add_update_contact method to maintain command/response parity by returning only a single OK response frame, preventing desynchronization issues with companion clients.
- Removed unnecessary frame writing logic for contact updates to streamline the response process.
- Added a new test to verify that the correct response frame is emitted when adding or updating a contact.
Replay the cached raw ADVERT blob for the selected contact instead of generating a new advert signed by the companion identity. This preserves the contact pubkey on zero-hop share, matches MeshCore firmware behavior, and avoids malformed share semantics when no cached advert exists.

Add contact blob persistence/capture paths, update share logic to enforce direct zero-hop normalization, and include tests/docs for blob-required sharing and pubkey preservation.
Fix CMD_ADD_UPDATE_CONTACT and CMD_SHARE_CONTACT behaviors
…duplication and raw hash blacklisting

- Updated the Dispatcher class to use a raw-frame hash for blacklisting known malformed packets before parsing, enhancing error handling.
- Changed deduplication logic to utilize a payload-based hash, ensuring compatibility with firmware and improving packet processing accuracy.
- Added tests to verify that packets with the same payload but different paths are deduplicated correctly, while different payloads are processed independently.
- Ensured malformed packets are blacklisted by their raw hash to prevent repeated parsing attempts.
refactor(dispatcher): improve packet processing with payload-based deduplication and raw hash blacklisting
- Updated the client_idle_timeout_sec parameter from 120 seconds to 8 hours (28800 seconds) to accommodate longer idle periods without disconnecting clients.
- This change aims to improve user experience by allowing more flexibility in client connections.
fix(companion): extend client idle timeout for CompanionFrameServer
@rightup rightup merged commit 202cf4b into dev Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants