Skip to content

Commit e90ea80

Browse files
committed
group additional information of vector channel config
1 parent 9fcca8e commit e90ea80

2 files changed

Lines changed: 48 additions & 14 deletions

File tree

can/interfaces/vector/canlib.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,7 @@ def _detect_available_configs():
609609
):
610610
continue
611611
LOG.info(
612-
"Channel index %d: %s",
613-
channel_config.channelIndex,
614-
channel_config.name.decode("ascii"),
612+
"Channel index %d: %s", channel_config.channelIndex, channel_config.name
615613
)
616614
configs.append(
617615
{
@@ -620,19 +618,15 @@ def _detect_available_configs():
620618
"channel": channel_config.hwChannel,
621619
"serial": channel_config.serialNumber,
622620
# data for use in VectorBus.set_application_config():
623-
"hw_type": xldefine.XL_HardwareType(channel_config.hwType),
621+
"hw_type": channel_config.hwType,
624622
"hw_index": channel_config.hwIndex,
625623
"hw_channel": channel_config.hwChannel,
626624
# additional information:
627625
"supports_fd": bool(
628626
channel_config.channelCapabilities
629627
& xldefine.XL_ChannelCapabilities.XL_CHANNEL_FLAG_CANFD_ISO_SUPPORT
630628
),
631-
"isOnBus": bool(channel_config.isOnBus),
632-
"name": channel_config.name.decode(),
633-
"channelIndex": channel_config.channelIndex,
634-
"channelMask": channel_config.channelMask,
635-
"transceiverName": channel_config.transceiverName.decode(),
629+
"vector_channel_config": channel_config,
636630
}
637631
)
638632
return configs
@@ -735,7 +729,23 @@ def set_timer_rate(self, timer_rate_ms: int) -> None:
735729
xldriver.xlSetTimerRate(self.port_handle, timer_rate_10us)
736730

737731

738-
def get_channel_configs() -> List[xlclass.XLchannelConfig]:
732+
class VectorChannelConfig(typing.NamedTuple):
733+
name: str
734+
hwType: xldefine.XL_HardwareType
735+
hwIndex: int
736+
hwChannel: int
737+
channelIndex: int
738+
channelMask: int
739+
channelCapabilities: xldefine.XL_ChannelCapabilities
740+
channelBusCapabilities: xldefine.XL_BusCapabilities
741+
isOnBus: bool
742+
connectedBusType: xldefine.XL_BusTypes
743+
serialNumber: int
744+
articleNumber: int
745+
transceiverName: str
746+
747+
748+
def get_channel_configs() -> List[VectorChannelConfig]:
739749
if xldriver is None:
740750
return []
741751
driver_config = xlclass.XLdriverConfig()
@@ -745,4 +755,28 @@ def get_channel_configs() -> List[xlclass.XLchannelConfig]:
745755
xldriver.xlCloseDriver()
746756
except VectorError:
747757
pass
748-
return [driver_config.channel[i] for i in range(driver_config.channelCount)]
758+
759+
channel_list: List[VectorChannelConfig] = []
760+
for i in range(driver_config.channelCount):
761+
xlcc: xlclass.XLchannelConfig = driver_config.channel[i]
762+
vcc = VectorChannelConfig(
763+
name=xlcc.name.decode(),
764+
hwType=xldefine.XL_HardwareType(xlcc.hwType),
765+
hwIndex=xlcc.hwIndex,
766+
hwChannel=xlcc.hwChannel,
767+
channelIndex=xlcc.channelIndex,
768+
channelMask=xlcc.channelMask,
769+
channelCapabilities=xldefine.XL_ChannelCapabilities(
770+
xlcc.channelCapabilities
771+
),
772+
channelBusCapabilities=xldefine.XL_BusCapabilities(
773+
xlcc.channelBusCapabilities
774+
),
775+
isOnBus=bool(xlcc.isOnBus),
776+
connectedBusType=xldefine.XL_BusTypes(xlcc.connectedBusType),
777+
serialNumber=xlcc.serialNumber,
778+
articleNumber=xlcc.articleNumber,
779+
transceiverName=xlcc.transceiverName.decode(),
780+
)
781+
channel_list.append(vcc)
782+
return channel_list

can/interfaces/vector/xldefine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Import Python Modules
66
# ==============================
7-
from enum import IntEnum
7+
from enum import IntEnum, IntFlag
88

99

1010
MAX_MSG_LEN = 8
@@ -22,7 +22,7 @@ class XL_AcceptanceFilter(IntEnum):
2222
XL_CAN_EXT = 2
2323

2424

25-
class XL_BusCapabilities(IntEnum):
25+
class XL_BusCapabilities(IntFlag):
2626
XL_BUS_COMPATIBLE_CAN = 1
2727
XL_BUS_ACTIVE_CAP_CAN = 65536
2828

@@ -106,7 +106,7 @@ class XL_CANFD_TX_MessageFlags(IntEnum):
106106
XL_CAN_TXMSG_FLAG_WAKEUP = 512
107107

108108

109-
class XL_ChannelCapabilities(IntEnum):
109+
class XL_ChannelCapabilities(IntFlag):
110110
XL_CHANNEL_FLAG_TIME_SYNC_RUNNING = 1
111111
XL_CHANNEL_FLAG_NO_HWSYNC_SUPPORT = 1024
112112
XL_CHANNEL_FLAG_SPDIF_CAPABLE = 16384

0 commit comments

Comments
 (0)