Files
flucto-heisskleber/heisskleber/serial/forwarder.py
Felix Weiler 774e0d8496 Breaking: Change signatures of Publisher.send and Subscriber.__init__.
This commit is a lot and adds breaking changes.
Also adds a UDP subscriber and publisher.
2023-11-07 12:41:07 +01:00

32 lines
790 B
Python

from heisskleber.core.types import Subscriber
from .publisher import SerialPublisher
class SerialForwarder:
def __init__(self, subscriber: Subscriber, publisher: SerialPublisher) -> None:
self.sub = subscriber
self.pub = publisher
"""
Wait for message and forward
"""
def forward_message(self) -> None:
# collected = {}
# for sub in self.sub:
# topic, data = sub.receive()
# collected.update(data)
topic, data = self.sub.receive()
# We send the topic and let the publisher decide what to do with it
self.pub.send(data, topic)
"""
Enter loop and continuously forward messages
"""
def sub_pub_loop(self) -> None:
while True:
self.forward_message()