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 ff63d68 commit 870ecca
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/gallia/commands/script/flexray.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ async def main(self, args: Namespace) -> None:
print(f"slot_id: {frame.slot_id:03d}; data: {frame.data.hex()}")



class FRDumpConfig(Script):
"""Dump the flexray configuration as base64"""

Expand Down
1 change: 1 addition & 0 deletions src/gallia/transports/_ctypes_vector_xl.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def check_rxtx_operation(result, function, arguments): # type: ignore
)
return result


def check_status_initialization(result, function, arguments): # type: ignore
if result > 0:
raise VectorInitializationError(
Expand Down
8 changes: 5 additions & 3 deletions src/gallia/transports/_ctypes_vector_xl_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@


class FlexRayCtypesBackend:
def __init__(self, channel_mask: int, port_handle: int) -> None:
def __init__(self, channel_mask: int, port_handle: int, tx_sleep_time: float) -> None:
self.tx_sleep_time = tx_sleep_time
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 @@ -37,6 +38,7 @@ def __init__(self, channel_mask: int, port_handle: int) -> None:
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 @@ -52,6 +54,7 @@ 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 @@ -241,7 +244,6 @@ async def _receive_worker(self) -> None:

try:
while True:

poll_intervall = 100

logger.trace("poller waiting…")
Expand Down Expand Up @@ -299,7 +301,7 @@ 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(0.2)
await asyncio.sleep(self.tx_sleep_time)

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

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 @@ -55,6 +56,7 @@ 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 @@ -86,7 +88,6 @@ async def write_frame_unsafe(self, frame: FlexRayFrame) -> None:

async def write_frame(self, frame: FlexRayFrame) -> None:
async with self.mutex:
logger.warn(f"sending this to the lower layers: {frame}")
await self.write_frame_unsafe(frame)

async def write(
Expand Down

0 comments on commit 870ecca

Please sign in to comment.