Skip to content

Commit

Permalink
fixup! fixup! feat(flexray): Add support for FlexRay via the Vector X…
Browse files Browse the repository at this point in the history
…L library
  • Loading branch information
rumpelsepp committed Jul 18, 2024
1 parent 870ecca commit d3944c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/gallia/transports/_ctypes_vector_xl_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@


class FlexRayCtypesBackend:
def __init__(self, channel_mask: int, port_handle: int, tx_sleep_time: float) -> None:
self.tx_sleep_time = tx_sleep_time
def __init__(self, channel_mask: int, port_handle: int) -> None:
self.channel_mask = channel_mask
self.port_handle = port_handle
self.queue: asyncio.Queue[_ctypes_vector_xl.XL_FR_RX_FRAME_EV] = asyncio.Queue()
Expand All @@ -38,7 +37,6 @@ def __init__(self, channel_mask: int, port_handle: int, tx_sleep_time: float) ->
def create(
cls,
channel_no: int | None,
tx_sleep_time: float = 0.05,
rx_queue_size: int = 0x2000,
) -> Self:
cls._enable_vector_license()
Expand All @@ -54,7 +52,6 @@ def create(
return cls(
channel_mask=channel_mask,
port_handle=port_handle,
tx_sleep_time=tx_sleep_time,
)

def set_configuration(self, config: _ctypes_vector_xl.XLfrClusterConfig) -> None:
Expand Down Expand Up @@ -301,8 +298,6 @@ async def transmit(self, slot_id: int, data: bytes) -> None:
ctypes.c_ubyte * _ctypes_vector_xl.XL_FR_MAX_DATA_LENGTH
).from_buffer_copy(data)

await asyncio.sleep(self.tx_sleep_time)

await asyncio.to_thread(
_ctypes_vector_xl.xlFrTransmit,
self.port_handle,
Expand Down
10 changes: 8 additions & 2 deletions src/gallia/transports/flexray_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

class RawFlexRayConfig(BaseModel):
rx_queue_size: int = 0x20000
tx_sleep_time: float = 0.05
channel_no: int | None = None

@field_validator(
Expand Down Expand Up @@ -56,7 +55,6 @@ def __init__(self, target: TargetURI) -> None:
self.backend = _ctypes_vector_xl_wrapper.FlexRayCtypesBackend.create(
channel_no=self.config.channel_no,
rx_queue_size=self.config.rx_queue_size,
tx_sleep_time=self.config.tx_sleep_time,
)
self.backend.start_queue()

Expand Down Expand Up @@ -141,6 +139,7 @@ class FlexrayTPLegacyConfig(BaseModel):
payload_rx_end_index: int
fc_block_size: int = 0xFF
fc_separation_time: int = 0x04
tx_sleep_time: float = 0.05

@field_validator(
"src_slot_id",
Expand Down Expand Up @@ -379,6 +378,13 @@ async def write_unsafe(
)

await self.write_tp_frame(cf_frame)

# XXX: FlexRay has a defined schedule.
# In the best case, we get notified that our
# frame has been written to the bus. We do
# not have this information, so we sleep for
# a configurable time frame…
await asyncio.sleep(self.config.tx_sleep_time)
counter = (counter + 1) & 0x0F

logger.debug("wrote data: %s", data.hex())
Expand Down

0 comments on commit d3944c3

Please sign in to comment.