Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpelsepp committed Jul 8, 2024
1 parent f02581c commit d57390c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/gallia/transports/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
from typing import Self

assert sys.platform == 'win32', "unsupported platform"
assert sys.platform == "win32", "unsupported platform"

from can.interfaces.vector import canlib, xlclass, xldefine, xldriver
from pydantic import BaseModel, field_validator
Expand Down Expand Up @@ -40,7 +40,6 @@ class RawFlexrayTransport(BaseTransport, scheme="flexray"):
def __init__(self, target: TargetURI) -> None:
super().__init__(target)


self.check_scheme(target)
self.config = RawFlexrayConfig(**target.qs_flat)

Expand Down Expand Up @@ -74,7 +73,12 @@ def __init__(self, target: TargetURI) -> None:
self.event_handle = xlclass.XLhandle()
xldriver.xlSetNotification(self.port_handle, self.event_handle, 1)

xldriver.xlActivateChannel(self.port_handle, self.channel_mask, xldefine.XL_BusTypes.XL_BUS_TYPE_FLEXRAY, vector_ctypes.XL_ACTIVATE_RESET_CLOCK)
xldriver.xlActivateChannel(
self.port_handle,
self.channel_mask,
xldefine.XL_BusTypes.XL_BUS_TYPE_FLEXRAY,
vector_ctypes.XL_ACTIVATE_RESET_CLOCK,
)

@classmethod
async def connect(
Expand Down Expand Up @@ -116,10 +120,10 @@ async def write(

print("writing")
await asyncio.to_thread(
vector_ctypes.xlFrTransmit,
self.port_handle,
self.channel_mask,
ctypes.byref(event),
vector_ctypes.xlFrTransmit,
self.port_handle,
self.channel_mask,
ctypes.byref(event),
)
return len(data)

Expand Down Expand Up @@ -148,6 +152,8 @@ async def read(self, timeout: float | None = None, tags: list[str] | None = None
event = vector_ctypes.XLfrEvent()
vector_ctypes.xlFrReceive(self.port_handle, ctypes.byref(event))

print(event)

# TODO: slicing is correct?
return bytes(event.tagData.raw)[: int(event.size)]

Expand Down

0 comments on commit d57390c

Please sign in to comment.