Skip to content

Commit

Permalink
feat(flexray): Add method to load and dump config
Browse files Browse the repository at this point in the history
In theory the following should work: Dump the flexray config from canoe
to a file and use this configuration later on.
  • Loading branch information
rumpelsepp committed Jul 18, 2024
1 parent 85f7dad commit 27401ed
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/gallia/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@


if sys.platform == "win32":
from gallia.commands.script.flexray import FRDump
from gallia.commands.script.flexray import FRDump, FRDumpConfig

registry.append(FRDump)
__all__.append("FRDump")
registry += [FRDump, FRDumpConfig]
__all__ += ["FRDump", "FRDumpConfig"]
5 changes: 2 additions & 3 deletions src/gallia/commands/script/flexray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#
# SPDX-License-Identifier: Apache-2.0

import base64
import pickle
import sys
from argparse import BooleanOptionalAction, Namespace

assert sys.platform == "win32"

from gallia.command import AsyncScript
from gallia.transports.flexray_vector import RawFlexRayTransport
from gallia.command import AsyncScript, Script
from gallia.transports._ctypes_vector_xl_wrapper import FlexRayCtypesBackend
from gallia.transports.flexray_vector import FlexRayFrame, RawFlexRayTransport, parse_frame_type
Expand Down Expand Up @@ -114,4 +114,3 @@ def main(self, args: Namespace) -> None:
print(raw_config)
else:
print(base64.b64encode(config))
>>>>>>> b32077b (fixup! feat(flexray): Add a helper script to dump bus traffic)
83 changes: 83 additions & 0 deletions src/gallia/transports/_ctypes_vector_xl.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def check_status_operation(result, function, arguments): # type: ignore
)
return result


def check_rxtx_operation(result, function, arguments): # type: ignore
match result:
case XL_Status.XL_ERR_QUEUE_IS_FULL:
Expand All @@ -162,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 Expand Up @@ -274,6 +276,73 @@ class XL_BusTypes(IntFlag):
XL_BUS_TYPE_A429 = 8192 # =0x00002000


class XL_HardwareType(IntEnum):
XL_HWTYPE_NONE = 0
XL_HWTYPE_VIRTUAL = 1
XL_HWTYPE_CANCARDX = 2
XL_HWTYPE_CANAC2PCI = 6
XL_HWTYPE_CANCARDY = 12
XL_HWTYPE_CANCARDXL = 15
XL_HWTYPE_CANCASEXL = 21
XL_HWTYPE_CANCASEXL_LOG_OBSOLETE = 23
XL_HWTYPE_CANBOARDXL = 25
XL_HWTYPE_CANBOARDXL_PXI = 27
XL_HWTYPE_VN2600 = 29
XL_HWTYPE_VN2610 = XL_HWTYPE_VN2600
XL_HWTYPE_VN3300 = 37
XL_HWTYPE_VN3600 = 39
XL_HWTYPE_VN7600 = 41
XL_HWTYPE_CANCARDXLE = 43
XL_HWTYPE_VN8900 = 45
XL_HWTYPE_VN8950 = 47
XL_HWTYPE_VN2640 = 53
XL_HWTYPE_VN1610 = 55
XL_HWTYPE_VN1630 = 57
XL_HWTYPE_VN1640 = 59
XL_HWTYPE_VN8970 = 61
XL_HWTYPE_VN1611 = 63
XL_HWTYPE_VN5240 = 64
XL_HWTYPE_VN5610 = 65
XL_HWTYPE_VN5620 = 66
XL_HWTYPE_VN7570 = 67
XL_HWTYPE_VN5650 = 68
XL_HWTYPE_IPCLIENT = 69
XL_HWTYPE_VN5611 = 70
XL_HWTYPE_IPSERVER = 71
XL_HWTYPE_VN5612 = 72
XL_HWTYPE_VX1121 = 73
XL_HWTYPE_VN5601 = 74
XL_HWTYPE_VX1131 = 75
XL_HWTYPE_VT6204 = 77
XL_HWTYPE_VN1630_LOG = 79
XL_HWTYPE_VN7610 = 81
XL_HWTYPE_VN7572 = 83
XL_HWTYPE_VN8972 = 85
XL_HWTYPE_VN0601 = 87
XL_HWTYPE_VN5640 = 89
XL_HWTYPE_VX0312 = 91
XL_HWTYPE_VH6501 = 94
XL_HWTYPE_VN8800 = 95
XL_HWTYPE_IPCL8800 = 96
XL_HWTYPE_IPSRV8800 = 97
XL_HWTYPE_CSMCAN = 98
XL_HWTYPE_VN5610A = 101
XL_HWTYPE_VN7640 = 102
XL_HWTYPE_VX1135 = 104
XL_HWTYPE_VN4610 = 105
XL_HWTYPE_VT6306 = 107
XL_HWTYPE_VT6104A = 108
XL_HWTYPE_VN5430 = 109
XL_HWTYPE_VTSSERVICE = 110
XL_HWTYPE_VN1530 = 112
XL_HWTYPE_VN1531 = 113
XL_HWTYPE_VX1161A = 114
XL_HWTYPE_VX1161B = 115
XL_HWTYPE_VGNSS = 116
XL_HWTYPE_VXLAPINIC = 118
XL_MAX_HWTYPE = 120


class XL_InterfaceVersion(IntEnum):
XL_INTERFACE_VERSION_V2 = 2
XL_INTERFACE_VERSION_V3 = 3
Expand Down Expand Up @@ -1032,6 +1101,10 @@ class s_xl_fr_event(IntrospectMixin, ctypes.Structure):
xlCloseDriver.restype = XLstatus
xlCloseDriver.errcheck = check_status_operation

xlGetChannelMask = _xlapi_dll.xlGetChannelMask
xlGetChannelMask.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
xlGetChannelMask.restype = XLaccess

xlOpenPort = _xlapi_dll.xlOpenPort
xlOpenPort.argtypes = [
ctypes.POINTER(XLportHandle),
Expand Down Expand Up @@ -1116,3 +1189,13 @@ class s_xl_fr_event(IntrospectMixin, ctypes.Structure):
xlFlushReceiveQueue.argtypes = [XLportHandle]
xlFlushReceiveQueue.restype = XLstatus
xlFlushReceiveQueue.errcheck = check_status_operation

xlFrSetConfiguration = _xlapi_dll.xlFrSetConfiguration
xlFrSetConfiguration.argtypes = [XLportHandle, XLaccess, ctypes.POINTER(XLfrClusterConfig)]
xlFrSetConfiguration.restype = XLstatus
xlFrSetConfiguration.errcheck = check_status_initialization

xlFrGetChannelConfiguration = _xlapi_dll.xlFrGetChannelConfiguration
xlFrGetChannelConfiguration.argtypes = [XLportHandle, XLaccess, ctypes.POINTER(XLfrChannelConfig)]
xlFrGetChannelConfiguration.restype = XLstatus
xlFrGetChannelConfiguration.errcheck = check_status_operation
25 changes: 23 additions & 2 deletions src/gallia/transports/_ctypes_vector_xl_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,42 @@ def __init__(self, channel_mask: int, port_handle: int) -> None:
self.event_handle: _ctypes_vector_xl.XLhandle | None = None

@classmethod
def create(cls, channel_no: int | None, rx_queue_size: int) -> Self:
cls._open_driver()
def create(
cls,
channel_no: int | None,
rx_queue_size: int = 0x2000,
) -> Self:
cls._enable_vector_license()
cls._open_driver()

channel_mask = cls._find_flexray_channel(channel_no)
port_handle = cls._open_flexray_port(
cls.__class__.__name__,
channel_mask,
rx_queue_size,
)

return cls(
channel_mask=channel_mask,
port_handle=port_handle,
)

def set_configuration(self, config: _ctypes_vector_xl.XLfrClusterConfig) -> None:
_ctypes_vector_xl.xlFrSetConfiguration(
_ctypes_vector_xl.XLportHandle(self.port_handle),
_ctypes_vector_xl.XLaccess(self.channel_mask),
ctypes.byref(config),
)

def get_configuration(self) -> _ctypes_vector_xl.XLfrClusterConfig:
config = _ctypes_vector_xl.XLfrChannelConfig()
_ctypes_vector_xl.xlFrGetChannelConfiguration(
_ctypes_vector_xl.XLportHandle(self.port_handle),
_ctypes_vector_xl.XLaccess(self.channel_mask),
ctypes.byref(config),
)
return cast(_ctypes_vector_xl.XLfrClusterConfig, config.xlFrClusterConfig)

@staticmethod
def _open_driver() -> None:
_ctypes_vector_xl.xlOpenDriver()
Expand Down

0 comments on commit 27401ed

Please sign in to comment.