remotivelabs.broker.restbus
The RemotiveBroker exposes a Restbus interface for simulating CAN bus traffic.
import asyncio
from remotivelabs.broker import BrokerClient
from remotivelabs.broker.restbus import RestbusFrameConfig, RestbusSignalConfig
async def main() -> None:
async with BrokerClient(url="http://127.0.0.1:50051") as broker_client:
# Start the restbus on the "DriverCan" namespace with one frame configuration
await broker_client.restbus.add(
("DriverCan", [RestbusFrameConfig(name="EngineData")]),
start=True,
)
# now update some of its signals
signal_configs: list[RestbusSignalConfig] = [
RestbusSignalConfig.set(name="EngineData.EngineRpm", value=1500),
RestbusSignalConfig.set(name="EngineData.EngineTemp", value=90),
]
await broker_client.restbus.update_signals(
("DriverCan", signal_configs),
)
if __name__ == "__main__":
asyncio.run(main())
Restbus client for managing Restbus operations on the RemoteLabs Broker.
Removes all configured signals and stops the Restbus on the specified namespace.
Arguments:
- *namespace: One or more namespaces to close
Adds one or more frames to the Restbus with optional start flag.
Arguments:
- *frames: One or more tuples, each containing namespace and list of frame configurations which should be added to the restbus
- start: If True, starts the frames after adding. Defaults to False.
Note: The start flag affects all frames running on the namespace, even if they are added since before.
Starts Restbus signal publishing for the specified namespaces.
Arguments:
- *namespace: One or more namespaces to start
Stops Restbus signal publishing for the specified namespaces.
Arguments:
- *namespace: One or more namespaces to stop. A stopped restbus can be started again.
Removes specific frames from the Restbus.
Arguments:
- *frames: One or more tuples, each containing namespace and list of frame names to remove from the restbus
Updates the configured signals on the Restbus with new values.
Arguments:
- *signals: One or more tuples, each containing namespace and list of signal configurations to apply to the restbus
Defines how a specific signal should behave when emitted by the Restbus.
Signal values are driven by a two-phase sequence:
- initial - values emitted once, in order, before the loop starts. May be empty.
- loop - values emitted in order, then repeated from the beginning indefinitely.
On each Restbus tick the next value in the sequence is used. Once initial is
exhausted the Restbus cycles through loop forever. A single-element loop
(e.g., loop=[0]) produces a constant value after the initial sequence.
Example - update-bit pattern (sends 1 once, then constant 0):
RestbusSignalConfig(name="UpdateBit", initial=[1], loop=[0])
# equivalent to:
RestbusSignalConfig.set_update_bit("UpdateBit")
Attributes:
Create a SignalConfig with a constant value.
Arguments:
- name: Name of the signal
- value: Value to set in Restbus
Configuration for a frame in the Restbus.
Attributes:
- name: The name of the frame to configure.
- cycle_time: Optional cycle time override for the frame in ms. If None, the default from the broker's database is used.