Gateway
A small amount of Python code is enough to create a CAN gateway. When the routing requires more application logic, the PyRbs class keeps individual rules direct and manageable.
./rbs/main.py
Copy code
1from pyrbs import PyRbs, CanMessage23rbs = PyRbs(dashboard=False)45@rbs.can_message.on("CAN1.*")6def gateway_can1_can2(self: CanMessage):7 self.send(channel=2)8Add individual rules only where they are needed
Catch all messages on a channel with one handler, then implement dedicated behavior for the specific CAN messages that require validation, transformation, filtering, or special routing.
This combines a concise default gateway with complete access to the messages that need custom application logic.
./rbs/main.py
Copy code
1from pyrbs import PyRbs, CanMessage23rbs = PyRbs(dashboard=False)45# add more complex logic to the gateway6# by implementing rules for specific messages7@rbs.can_message.on("CAN1.Control_01")8def gateway_control_selector(self: CanMessage):9 for selector in [2, 3, 4]:10 # adjust the Selector Signal value11 self["Selector"].raw = selector12 self.send(channel=selector)1314# pick all messages that have no callback configured15@rbs.can_message.on("CAN1.!*")16def gateway_can1_to_can234(self: CanMessage):17 self.send(channel=2)18 self.send(channel=3)19 self.send(channel=4)