remotivelabs.topology.mapping.models
1from __future__ import annotations 2 3from enum import Enum 4from typing import Annotated, Any, Literal 5 6from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator 7 8_CUSTOM_TYPE_PREFIX = "custom." 9 10MAPPING_SCHEMA_URL = "https://files.remotivelabs.com/schemas/gateway-mapping-0.2.schema.json" 11"""Canonical URL of the mapping schema this library implements — the value of the `schema:` key in mapping files.""" 12 13DEFAULT_ECU = "topology" 14"""Default `ecu` role used to resolve a mapping `channel` to a broker namespace (the topology catch-all).""" 15 16 17class ChannelType(str, Enum): 18 """ 19 The kind of channel a built-in address is on — the v2 broker API's `ChannelType`. 20 21 Derived from the mapping's own declared address `type` (`can`, `lin`, `ethernet.pdu`), which 22 is the authority on how a namespace publishes: the broker's chain type cannot be trusted for 23 this (CAN-over-UDP and ethernet PDU tunnels both report `udp`). 24 """ 25 26 CAN = "can" 27 LIN = "lin" 28 ETHERNET = "ethernet" 29 30 31class _MappingFields(BaseModel): 32 """Dict-style read access to the fields authored in the mapping file. 33 34 `obj["device"]` / `obj.get("offset", 0)` read any authored YAML field — declared or 35 type-specific extra — without pydantic knowledge. 36 """ 37 38 def __getitem__(self, key: str) -> Any: 39 if key in type(self).model_fields: 40 return getattr(self, key) 41 extra = self.model_extra or {} 42 if key in extra: 43 return extra[key] 44 raise KeyError(f"{type(self).__name__} has no field {key!r} — is it missing from the mapping file entry?") 45 46 def get(self, key: str, default: Any = None) -> Any: 47 """Return the authored field `key`, or `default` if the entry doesn't carry it.""" 48 try: 49 return self[key] 50 except KeyError: 51 return default 52 53 54class PassthroughTransform(BaseModel): 55 """Forwards values unchanged from source to target.""" 56 57 model_config = ConfigDict(extra="forbid") 58 59 type: Literal["passthrough"] = "passthrough" 60 61 62class LinearTransform(BaseModel): 63 """Applies y = factor * x + offset, optionally clamped to [min, max].""" 64 65 model_config = ConfigDict(extra="forbid") 66 67 type: Literal["linear"] = "linear" 68 factor: float 69 offset: float = 0.0 70 min: float | None = None 71 max: float | None = None 72 73 74class LookupTransform(BaseModel): 75 """Replaces each input value with the corresponding entry in the mapping table.""" 76 77 model_config = ConfigDict(extra="forbid") 78 79 type: Literal["lookup"] = "lookup" 80 mapping: dict[int, int] 81 82 83class CustomTransform(_MappingFields): 84 """Custom (`custom.`-prefixed) transform: register a factory with 85 `remotivelabs.topology.mapping.MappingModel.register_transform` to run it. Type-specific 86 fields are preserved and read with `transform["field"]`.""" 87 88 model_config = ConfigDict(extra="allow") 89 90 type: str 91 92 @field_validator("type") 93 @classmethod 94 def _require_custom_prefix(cls, v: str) -> str: 95 if not v.startswith(_CUSTOM_TYPE_PREFIX): 96 raise ValueError(f"custom transform types must be prefixed {_CUSTOM_TYPE_PREFIX!r}, e.g. 'custom.toggle' (got {v!r})") 97 return v 98 99 100# left_to_right: the builtin literals reject `custom.*` type values, so the catch-all comes last 101# and a typo'd builtin type fails every variant loudly instead of being absorbed. 102Transform = Annotated[ 103 PassthroughTransform | LinearTransform | LookupTransform | CustomTransform, 104 Field(union_mode="left_to_right"), 105] 106 107 108# --- Addresses ---------------------------------------------------------------- 109# 110# An `Address` names a message or a signal on a channel (or a bare channel, for 111# compact routes). Field names follow the v2 broker API addresses: the unit is 112# `frame` for can/lin (CanFrameAddress/LinFrameAddress) and `pdu` for 113# ethernet.pdu (EthernetPduAddress); "message" is the cross-protocol umbrella 114# term (ReceivedMessage), used for the unions and entry names — never as a field. 115# 116# Built-in addresses share a strict base. extra="forbid" is load-bearing, not 117# cosmetic: a CAN message and a CAN signal both carry type "can", so the entry 118# union discriminates them by required-field shape (`signal` present or not). 119# With pydantic's default extra="ignore", a signal payload could silently 120# validate as a message address, dropping its `signal`. forbid also matches the 121# JSON schema's additionalProperties: false. 122# 123# `type` keeps a literal default so the models stay ergonomic to construct in 124# Python; the YAML still must carry `type` because the unions that consume these 125# (MessageAddress, SignalAddress, ChannelAddress) discriminate on it. 126 127 128class _StrictAddress(_MappingFields): 129 model_config = ConfigDict(extra="forbid", frozen=True) 130 131 type: str 132 channel: str 133 134 @property 135 def channel_type(self) -> ChannelType: 136 """The kind of channel this address is on (`ethernet.pdu` addresses are on an ethernet channel).""" 137 return ChannelType.ETHERNET if self.type.startswith("ethernet.") else ChannelType(self.type) 138 139 def broker_namespace(self, ecu: str = DEFAULT_ECU) -> str: 140 """ 141 The broker namespace this address lives on. 142 143 A mapping file names the bare bus `channel` (e.g. `BodyCan0`); the broker namespace is 144 role-scoped: `topology-BodyCan0` for standalone consumers, `RLCM-BodyCan0` when running 145 as the RLCM ECU, and an empty `ecu` gives the channel verbatim (for flat namespaces that 146 don't follow that scheme). Ethernet PDU addresses fold their ARXML socket pair in — 147 topology-generated brokers wire one namespace per SoAd socket connection, spelled 148 `<ecu>-<source_socket>-<target_socket>-<channel>`. This is the single spot that knows 149 broker namespace spelling — replace it with namespace discovery under a future broker API. 150 """ 151 channel = self.channel 152 if isinstance(self, _EthernetPduSockets): 153 channel = f"{self.source_socket}-{self.target_socket}-{channel}" 154 return f"{ecu}-{channel}" if ecu else channel 155 156 157class _EthernetPduSockets(BaseModel): 158 """ARXML socket pair carried by every Ethernet PDU address.""" 159 160 source_socket: str 161 target_socket: str 162 163 164# Channel-only addresses (compact route entries) ---------------------------------- 165 166 167class CanChannelAddress(_StrictAddress): 168 """A CAN channel (compact route address).""" 169 170 type: Literal["can"] = "can" 171 172 def message(self, frame: str) -> CanFrameAddress: 173 """The address of `frame` on this channel.""" 174 return CanFrameAddress(channel=self.channel, frame=frame) 175 176 177class LinChannelAddress(_StrictAddress): 178 """A LIN channel (compact route address).""" 179 180 type: Literal["lin"] = "lin" 181 182 def message(self, frame: str) -> LinFrameAddress: 183 """The address of `frame` on this channel.""" 184 return LinFrameAddress(channel=self.channel, frame=frame) 185 186 187class EthernetPduChannelAddress(_StrictAddress, _EthernetPduSockets): 188 """An Ethernet PDU channel (compact route address), with its ARXML sockets.""" 189 190 type: Literal["ethernet.pdu"] = "ethernet.pdu" 191 192 def message(self, pdu: str) -> EthernetPduAddress: 193 """The address of `pdu` on this channel's socket pair.""" 194 return EthernetPduAddress(channel=self.channel, source_socket=self.source_socket, target_socket=self.target_socket, pdu=pdu) 195 196 197# Message addresses (frame for can/lin, pdu for ethernet.pdu — per the v2 addresses) 198 199 200class CanFrameAddress(_StrictAddress): 201 """A CAN frame on a given channel.""" 202 203 type: Literal["can"] = "can" 204 frame: str 205 206 207class LinFrameAddress(_StrictAddress): 208 """A LIN frame on a given channel.""" 209 210 type: Literal["lin"] = "lin" 211 frame: str 212 213 214class EthernetPduAddress(_StrictAddress, _EthernetPduSockets): 215 """An Ethernet-tunneled PDU, identified by pdu, channel, and source/target sockets.""" 216 217 type: Literal["ethernet.pdu"] = "ethernet.pdu" 218 pdu: str 219 220 221# Signal addresses ----------------------------------------------------------------- 222 223 224class CanSignalAddress(_StrictAddress): 225 """A CAN signal within a frame on a given channel.""" 226 227 type: Literal["can"] = "can" 228 frame: str 229 signal: str 230 231 232class LinSignalAddress(_StrictAddress): 233 """A LIN signal within a frame on a given channel.""" 234 235 type: Literal["lin"] = "lin" 236 frame: str 237 signal: str 238 239 240class EthernetPduSignalAddress(_StrictAddress, _EthernetPduSockets): 241 """A signal within an Ethernet-tunneled PDU, identified by pdu, channel, and source/target sockets.""" 242 243 type: Literal["ethernet.pdu"] = "ethernet.pdu" 244 pdu: str 245 signal: str 246 247 248# Custom addresses ----------------------------------------------------------------- 249 250 251class _CustomAddress(_MappingFields): 252 """Catch-all base for non-built-in (`custom.`-prefixed) addresses. Type-specific extra fields 253 are preserved and read with `address["field"]`.""" 254 255 model_config = ConfigDict(extra="allow") 256 257 type: str 258 259 @field_validator("type") 260 @classmethod 261 def _require_custom_prefix(cls, v: str) -> str: 262 if not v.startswith(_CUSTOM_TYPE_PREFIX): 263 raise ValueError(f"custom address types must be prefixed {_CUSTOM_TYPE_PREFIX!r}, e.g. 'custom.evdev' (got {v!r})") 264 return v 265 266 267class CustomMessageAddress(_CustomAddress): 268 """Custom message-level address: only `type` is required — the unit field is type-defined and read 269 from model_extra by the custom implementation. Must not carry `signal` (that makes the payload 270 signal-level; the guard keeps a typo'd signal address from silently classifying as message-level).""" 271 272 @model_validator(mode="after") 273 def _reject_signal_key(self) -> CustomMessageAddress: 274 if "signal" in (self.model_extra or {}): 275 raise ValueError("custom message-level addresses must not carry `signal` — use a signal-level entry") 276 return self 277 278 279class CustomSignalAddress(_CustomAddress): 280 """Custom signal address (e.g. custom.evdev). Extra technology-specific fields preserved in model_extra.""" 281 282 signal: str 283 284 285# left_to_right (not smart mode — its scoring is unpredictable with extra="allow" catch-alls): 286# built-ins are tried first and discriminate by required-field shape thanks to extra="forbid"; 287# the custom catch-all comes last, so a stale `type: broker` or a typo fails every variant and 288# raises a loud ValidationError instead of being silently absorbed. 289MessageAddress = Annotated[ 290 CanFrameAddress | LinFrameAddress | EthernetPduAddress | CustomMessageAddress, 291 Field(union_mode="left_to_right"), 292] 293SignalAddress = Annotated[ 294 CanSignalAddress | LinSignalAddress | EthernetPduSignalAddress | CustomSignalAddress, 295 Field(union_mode="left_to_right"), 296] 297 298BuiltinMessageAddress = CanFrameAddress | LinFrameAddress | EthernetPduAddress 299BuiltinSignalAddress = CanSignalAddress | LinSignalAddress | EthernetPduSignalAddress 300BuiltinChannelAddress = CanChannelAddress | LinChannelAddress | EthernetPduChannelAddress 301BuiltinAddress = BuiltinChannelAddress | BuiltinMessageAddress | BuiltinSignalAddress 302 303 304def namespace_for(address: BuiltinAddress | str, ecu: str = DEFAULT_ECU) -> str: 305 """ 306 Resolve a mapping address (or bare `channel` string) to a broker namespace. 307 308 Thin dispatch to `broker_namespace` on the address — see its docstring for the spelling. 309 A bare string resolves as a can/lin-style channel (`<ecu>-<channel>`); pass the address 310 itself whenever it is at hand, so ethernet PDU socket pairs resolve correctly. 311 """ 312 if isinstance(address, str): 313 return f"{ecu}-{address}" if ecu else address 314 return address.broker_namespace(ecu) 315 316 317def message_name(address: BuiltinMessageAddress | BuiltinSignalAddress) -> str: 318 """The broker message name a built-in address points at (or into, for signal addresses). 319 320 Per-type dispatch over the v2-style field names: `pdu` for ethernet.pdu, `frame` for can/lin. 321 """ 322 if isinstance(address, (EthernetPduAddress, EthernetPduSignalAddress)): 323 return address.pdu 324 return address.frame 325 326 327# Channel addresses have distinct `type` values, so a discriminated union is both the 328# clearest model and the thing that makes `type` mandatory in route YAML (pydantic raises 329# when the discriminator is absent, even though the members keep a literal default). 330ChannelAddress = Annotated[ 331 CanChannelAddress | LinChannelAddress | EthernetPduChannelAddress, 332 Field(discriminator="type"), 333] 334 335 336class RouteEntry(BaseModel): 337 """ 338 Compact message routing: many messages between one channel pair. 339 340 Mirrors the remotive-signal-database socket/connections model. 341 The required 'messages' field discriminates this from the mapping entries. 342 """ 343 344 source: ChannelAddress 345 target: ChannelAddress 346 messages: dict[str, str] # source message name → target message name 347 348 349class SignalMappingEntry(BaseModel): 350 """A signal-level mapping: one source signal to one or more targets with an optional shared value transform.""" 351 352 model_config = ConfigDict(extra="forbid") 353 354 source: SignalAddress 355 target: SignalAddress | Annotated[list[SignalAddress], Field(min_length=1)] 356 transform: Transform = PassthroughTransform() 357 358 @property 359 def targets(self) -> tuple[SignalAddress, ...]: 360 """Normalized target list — `target` preserves the authored shape (single address or list).""" 361 return tuple(self.target) if isinstance(self.target, list) else (self.target,) 362 363 364class MessageMappingEntry(BaseModel): 365 """ 366 A message-level mapping: one source message copied to one or more target messages. 367 368 Message routing is always passthrough — the raw payload is relayed without decode — so this 369 entry carries no `transform` (extra="forbid" rejects one loudly instead of ignoring it). 370 """ 371 372 model_config = ConfigDict(extra="forbid") 373 374 source: MessageAddress 375 target: MessageAddress | Annotated[list[MessageAddress], Field(min_length=1)] 376 377 @property 378 def targets(self) -> tuple[MessageAddress, ...]: 379 """Normalized target list — `target` preserves the authored shape (single address or list).""" 380 return tuple(self.target) if isinstance(self.target, list) else (self.target,) 381 382 383# RouteEntry is tried first (required 'messages' field). SignalMappingEntry comes BEFORE 384# MessageMappingEntry: CustomMessageAddress matches any custom payload (only `type` required), so the 385# message-level entry would otherwise swallow custom→custom signal entries. A built-in message 386# payload lacks `signal` and falls through to MessageMappingEntry; mixed message/signal source and 387# target in one entry fails both — loudly. 388Entry = Annotated[RouteEntry | SignalMappingEntry | MessageMappingEntry, Field(union_mode="left_to_right")] 389 390 391class MappingConfig(BaseModel): 392 """Top-level YAML mapping file: a schema identifier and the list of routing entries.""" 393 394 model_config = ConfigDict(populate_by_name=True) 395 396 schema_: str = Field(alias="schema") 397 mappings: list[Entry] 398 399 400__all__ = [ 401 # Schema identity 402 "MAPPING_SCHEMA_URL", 403 # Namespace resolution 404 "DEFAULT_ECU", 405 "ChannelType", 406 "namespace_for", 407 # Transforms 408 "PassthroughTransform", 409 "LinearTransform", 410 "LookupTransform", 411 "CustomTransform", 412 # Channel addresses 413 "CanChannelAddress", 414 "LinChannelAddress", 415 "EthernetPduChannelAddress", 416 "ChannelAddress", 417 # Message addresses 418 "CanFrameAddress", 419 "LinFrameAddress", 420 "EthernetPduAddress", 421 "CustomMessageAddress", 422 # Signal addresses 423 "CanSignalAddress", 424 "LinSignalAddress", 425 "EthernetPduSignalAddress", 426 "CustomSignalAddress", 427 # Address unions + dispatch 428 "BuiltinAddress", 429 "BuiltinChannelAddress", 430 "BuiltinMessageAddress", 431 "BuiltinSignalAddress", 432 "message_name", 433 # Entries 434 "RouteEntry", 435 "MessageMappingEntry", 436 "SignalMappingEntry", 437 "MappingConfig", 438]
Canonical URL of the mapping schema this library implements — the value of the schema: key in mapping files.
Default ecu role used to resolve a mapping channel to a broker namespace (the topology catch-all).
18class ChannelType(str, Enum): 19 """ 20 The kind of channel a built-in address is on — the v2 broker API's `ChannelType`. 21 22 Derived from the mapping's own declared address `type` (`can`, `lin`, `ethernet.pdu`), which 23 is the authority on how a namespace publishes: the broker's chain type cannot be trusted for 24 this (CAN-over-UDP and ethernet PDU tunnels both report `udp`). 25 """ 26 27 CAN = "can" 28 LIN = "lin" 29 ETHERNET = "ethernet"
The kind of channel a built-in address is on — the v2 broker API's ChannelType.
Derived from the mapping's own declared address type (can, lin, ethernet.pdu), which
is the authority on how a namespace publishes: the broker's chain type cannot be trusted for
this (CAN-over-UDP and ethernet PDU tunnels both report udp).
305def namespace_for(address: BuiltinAddress | str, ecu: str = DEFAULT_ECU) -> str: 306 """ 307 Resolve a mapping address (or bare `channel` string) to a broker namespace. 308 309 Thin dispatch to `broker_namespace` on the address — see its docstring for the spelling. 310 A bare string resolves as a can/lin-style channel (`<ecu>-<channel>`); pass the address 311 itself whenever it is at hand, so ethernet PDU socket pairs resolve correctly. 312 """ 313 if isinstance(address, str): 314 return f"{ecu}-{address}" if ecu else address 315 return address.broker_namespace(ecu)
Resolve a mapping address (or bare channel string) to a broker namespace.
Thin dispatch to broker_namespace on the address — see its docstring for the spelling.
A bare string resolves as a can/lin-style channel (<ecu>-<channel>); pass the address
itself whenever it is at hand, so ethernet PDU socket pairs resolve correctly.
55class PassthroughTransform(BaseModel): 56 """Forwards values unchanged from source to target.""" 57 58 model_config = ConfigDict(extra="forbid") 59 60 type: Literal["passthrough"] = "passthrough"
Forwards values unchanged from source to target.
63class LinearTransform(BaseModel): 64 """Applies y = factor * x + offset, optionally clamped to [min, max].""" 65 66 model_config = ConfigDict(extra="forbid") 67 68 type: Literal["linear"] = "linear" 69 factor: float 70 offset: float = 0.0 71 min: float | None = None 72 max: float | None = None
Applies y = factor * x + offset, optionally clamped to [min, max].
75class LookupTransform(BaseModel): 76 """Replaces each input value with the corresponding entry in the mapping table.""" 77 78 model_config = ConfigDict(extra="forbid") 79 80 type: Literal["lookup"] = "lookup" 81 mapping: dict[int, int]
Replaces each input value with the corresponding entry in the mapping table.
84class CustomTransform(_MappingFields): 85 """Custom (`custom.`-prefixed) transform: register a factory with 86 `remotivelabs.topology.mapping.MappingModel.register_transform` to run it. Type-specific 87 fields are preserved and read with `transform["field"]`.""" 88 89 model_config = ConfigDict(extra="allow") 90 91 type: str 92 93 @field_validator("type") 94 @classmethod 95 def _require_custom_prefix(cls, v: str) -> str: 96 if not v.startswith(_CUSTOM_TYPE_PREFIX): 97 raise ValueError(f"custom transform types must be prefixed {_CUSTOM_TYPE_PREFIX!r}, e.g. 'custom.toggle' (got {v!r})") 98 return v
Custom (custom.-prefixed) transform: register a factory with
remotivelabs.topology.mapping.MappingModel.register_transform to run it. Type-specific
fields are preserved and read with transform["field"].
Inherited Members
168class CanChannelAddress(_StrictAddress): 169 """A CAN channel (compact route address).""" 170 171 type: Literal["can"] = "can" 172 173 def message(self, frame: str) -> CanFrameAddress: 174 """The address of `frame` on this channel.""" 175 return CanFrameAddress(channel=self.channel, frame=frame)
A CAN channel (compact route address).
173 def message(self, frame: str) -> CanFrameAddress: 174 """The address of `frame` on this channel.""" 175 return CanFrameAddress(channel=self.channel, frame=frame)
The address of frame on this channel.
Inherited Members
178class LinChannelAddress(_StrictAddress): 179 """A LIN channel (compact route address).""" 180 181 type: Literal["lin"] = "lin" 182 183 def message(self, frame: str) -> LinFrameAddress: 184 """The address of `frame` on this channel.""" 185 return LinFrameAddress(channel=self.channel, frame=frame)
A LIN channel (compact route address).
183 def message(self, frame: str) -> LinFrameAddress: 184 """The address of `frame` on this channel.""" 185 return LinFrameAddress(channel=self.channel, frame=frame)
The address of frame on this channel.
Inherited Members
188class EthernetPduChannelAddress(_StrictAddress, _EthernetPduSockets): 189 """An Ethernet PDU channel (compact route address), with its ARXML sockets.""" 190 191 type: Literal["ethernet.pdu"] = "ethernet.pdu" 192 193 def message(self, pdu: str) -> EthernetPduAddress: 194 """The address of `pdu` on this channel's socket pair.""" 195 return EthernetPduAddress(channel=self.channel, source_socket=self.source_socket, target_socket=self.target_socket, pdu=pdu)
An Ethernet PDU channel (compact route address), with its ARXML sockets.
201class CanFrameAddress(_StrictAddress): 202 """A CAN frame on a given channel.""" 203 204 type: Literal["can"] = "can" 205 frame: str
A CAN frame on a given channel.
Inherited Members
208class LinFrameAddress(_StrictAddress): 209 """A LIN frame on a given channel.""" 210 211 type: Literal["lin"] = "lin" 212 frame: str
A LIN frame on a given channel.
Inherited Members
215class EthernetPduAddress(_StrictAddress, _EthernetPduSockets): 216 """An Ethernet-tunneled PDU, identified by pdu, channel, and source/target sockets.""" 217 218 type: Literal["ethernet.pdu"] = "ethernet.pdu" 219 pdu: str
An Ethernet-tunneled PDU, identified by pdu, channel, and source/target sockets.
268class CustomMessageAddress(_CustomAddress): 269 """Custom message-level address: only `type` is required — the unit field is type-defined and read 270 from model_extra by the custom implementation. Must not carry `signal` (that makes the payload 271 signal-level; the guard keeps a typo'd signal address from silently classifying as message-level).""" 272 273 @model_validator(mode="after") 274 def _reject_signal_key(self) -> CustomMessageAddress: 275 if "signal" in (self.model_extra or {}): 276 raise ValueError("custom message-level addresses must not carry `signal` — use a signal-level entry") 277 return self
Custom message-level address: only type is required — the unit field is type-defined and read
from model_extra by the custom implementation. Must not carry signal (that makes the payload
signal-level; the guard keeps a typo'd signal address from silently classifying as message-level).
Inherited Members
225class CanSignalAddress(_StrictAddress): 226 """A CAN signal within a frame on a given channel.""" 227 228 type: Literal["can"] = "can" 229 frame: str 230 signal: str
A CAN signal within a frame on a given channel.
Inherited Members
233class LinSignalAddress(_StrictAddress): 234 """A LIN signal within a frame on a given channel.""" 235 236 type: Literal["lin"] = "lin" 237 frame: str 238 signal: str
A LIN signal within a frame on a given channel.
Inherited Members
241class EthernetPduSignalAddress(_StrictAddress, _EthernetPduSockets): 242 """A signal within an Ethernet-tunneled PDU, identified by pdu, channel, and source/target sockets.""" 243 244 type: Literal["ethernet.pdu"] = "ethernet.pdu" 245 pdu: str 246 signal: str
A signal within an Ethernet-tunneled PDU, identified by pdu, channel, and source/target sockets.
280class CustomSignalAddress(_CustomAddress): 281 """Custom signal address (e.g. custom.evdev). Extra technology-specific fields preserved in model_extra.""" 282 283 signal: str
Custom signal address (e.g. custom.evdev). Extra technology-specific fields preserved in model_extra.
Inherited Members
318def message_name(address: BuiltinMessageAddress | BuiltinSignalAddress) -> str: 319 """The broker message name a built-in address points at (or into, for signal addresses). 320 321 Per-type dispatch over the v2-style field names: `pdu` for ethernet.pdu, `frame` for can/lin. 322 """ 323 if isinstance(address, (EthernetPduAddress, EthernetPduSignalAddress)): 324 return address.pdu 325 return address.frame
The broker message name a built-in address points at (or into, for signal addresses).
Per-type dispatch over the v2-style field names: pdu for ethernet.pdu, frame for can/lin.
337class RouteEntry(BaseModel): 338 """ 339 Compact message routing: many messages between one channel pair. 340 341 Mirrors the remotive-signal-database socket/connections model. 342 The required 'messages' field discriminates this from the mapping entries. 343 """ 344 345 source: ChannelAddress 346 target: ChannelAddress 347 messages: dict[str, str] # source message name → target message name
Compact message routing: many messages between one channel pair.
Mirrors the remotive-signal-database socket/connections model. The required 'messages' field discriminates this from the mapping entries.
365class MessageMappingEntry(BaseModel): 366 """ 367 A message-level mapping: one source message copied to one or more target messages. 368 369 Message routing is always passthrough — the raw payload is relayed without decode — so this 370 entry carries no `transform` (extra="forbid" rejects one loudly instead of ignoring it). 371 """ 372 373 model_config = ConfigDict(extra="forbid") 374 375 source: MessageAddress 376 target: MessageAddress | Annotated[list[MessageAddress], Field(min_length=1)] 377 378 @property 379 def targets(self) -> tuple[MessageAddress, ...]: 380 """Normalized target list — `target` preserves the authored shape (single address or list).""" 381 return tuple(self.target) if isinstance(self.target, list) else (self.target,)
A message-level mapping: one source message copied to one or more target messages.
Message routing is always passthrough — the raw payload is relayed without decode — so this
entry carries no transform (extra="forbid" rejects one loudly instead of ignoring it).
378 @property 379 def targets(self) -> tuple[MessageAddress, ...]: 380 """Normalized target list — `target` preserves the authored shape (single address or list).""" 381 return tuple(self.target) if isinstance(self.target, list) else (self.target,)
Normalized target list — target preserves the authored shape (single address or list).
350class SignalMappingEntry(BaseModel): 351 """A signal-level mapping: one source signal to one or more targets with an optional shared value transform.""" 352 353 model_config = ConfigDict(extra="forbid") 354 355 source: SignalAddress 356 target: SignalAddress | Annotated[list[SignalAddress], Field(min_length=1)] 357 transform: Transform = PassthroughTransform() 358 359 @property 360 def targets(self) -> tuple[SignalAddress, ...]: 361 """Normalized target list — `target` preserves the authored shape (single address or list).""" 362 return tuple(self.target) if isinstance(self.target, list) else (self.target,)
A signal-level mapping: one source signal to one or more targets with an optional shared value transform.
359 @property 360 def targets(self) -> tuple[SignalAddress, ...]: 361 """Normalized target list — `target` preserves the authored shape (single address or list).""" 362 return tuple(self.target) if isinstance(self.target, list) else (self.target,)
Normalized target list — target preserves the authored shape (single address or list).
392class MappingConfig(BaseModel): 393 """Top-level YAML mapping file: a schema identifier and the list of routing entries.""" 394 395 model_config = ConfigDict(populate_by_name=True) 396 397 schema_: str = Field(alias="schema") 398 mappings: list[Entry]
Top-level YAML mapping file: a schema identifier and the list of routing entries.