OpenCyphal / pycyphal

Python implementation of the Cyphal protocol stack.
https://pycyphal.readthedocs.io/
MIT License
117 stars 106 forks source link

Add experimental subject synchronizer, fixes #65 #220

Closed pavel-kirienko closed 2 years ago

pavel-kirienko commented 2 years ago

The implementation is expressly marked as unstable and experimental, so it should be safe to release without the risk of breaking applications later shall this solution be identified as deficient. Comprehensive docs with usage examples are provided, please see the RTD build:

There are currently two synchronizers. The MonotonicClusteringSynchronizer groups messages into clusters by timestamp (it is actually generalized and works with any ordering/grouping key) with a specified tolerance (which can be auto-tuned externally based on message arrival frequency):

image

The TransferIDSynchronizer simply groups messages by transfer-ID.

Both algorithms are expected to be easily implementable on an embedded system as well.

thirtytwobits commented 2 years ago

The links to https://pycyphal--220.org.readthedocs.build don't resolve to anything?

pavel-kirienko commented 2 years ago

The links to https://pycyphal--220.org.readthedocs.build/ don't resolve to anything?

Works for me ¯\_(ツ)_/¯

pavel-kirienko commented 2 years ago

If you're reviewing it you may notice that the methods of Synchronizer are named weirdly: there are receive/receive_for (with a deadline and duration arguments, respectively), and then there is get (which is like receive_for but returns messages without their metadata, named after Queue.get). Similarly there are receive_in_background and get_in_background.

The names might be counterintuitive but it is done this way to stay consistent with Subscriber, which in turn has to stick to this naming to avoid API breakage. Maybe at one point we should deprecate the weird methods and provide improved alternatives.