Skip to content

Commit 6cfed6b

Browse files
committed
Revert "add busParams and use snake case for VectorChannelConfig (hardbyte#1422)"
This reverts commit fb892d6.
1 parent f9c7612 commit 6cfed6b

File tree

4 files changed

+50
-179
lines changed

4 files changed

+50
-179
lines changed

can/interfaces/vector/__init__.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
"""
22
"""
33

4-
from .canlib import (
5-
VectorBus,
6-
get_channel_configs,
7-
VectorChannelConfig,
8-
VectorBusParams,
9-
VectorCanParams,
10-
VectorCanFdParams,
11-
)
4+
from .canlib import VectorBus, VectorChannelConfig, get_channel_configs
125
from .exceptions import VectorError, VectorOperationError, VectorInitializationError

can/interfaces/vector/canlib.py

+37-103
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@ def _find_global_channel_idx(
295295
if serial is not None:
296296
hw_type: Optional[xldefine.XL_HardwareType] = None
297297
for channel_config in channel_configs:
298-
if channel_config.serial_number != serial:
298+
if channel_config.serialNumber != serial:
299299
continue
300300

301-
hw_type = xldefine.XL_HardwareType(channel_config.hw_type)
302-
if channel_config.hw_channel == channel:
303-
return channel_config.channel_index
301+
hw_type = xldefine.XL_HardwareType(channel_config.hwType)
302+
if channel_config.hwChannel == channel:
303+
return channel_config.channelIndex
304304

305305
if hw_type is None:
306306
err_msg = f"No interface with serial {serial} found."
@@ -331,7 +331,7 @@ def _find_global_channel_idx(
331331

332332
# check if channel is a valid global channel index
333333
for channel_config in channel_configs:
334-
if channel == channel_config.channel_index:
334+
if channel == channel_config.channelIndex:
335335
return channel
336336

337337
raise CanInitializationError(
@@ -727,28 +727,26 @@ def _detect_available_configs() -> List[AutoDetectedConfig]:
727727
LOG.info("Found %d channels", len(channel_configs))
728728
for channel_config in channel_configs:
729729
if (
730-
not channel_config.channel_bus_capabilities
730+
not channel_config.channelBusCapabilities
731731
& xldefine.XL_BusCapabilities.XL_BUS_ACTIVE_CAP_CAN
732732
):
733733
continue
734734
LOG.info(
735-
"Channel index %d: %s",
736-
channel_config.channel_index,
737-
channel_config.name,
735+
"Channel index %d: %s", channel_config.channelIndex, channel_config.name
738736
)
739737
configs.append(
740738
{
741739
# data for use in VectorBus.__init__():
742740
"interface": "vector",
743-
"channel": channel_config.hw_channel,
744-
"serial": channel_config.serial_number,
741+
"channel": channel_config.hwChannel,
742+
"serial": channel_config.serialNumber,
745743
# data for use in VectorBus.set_application_config():
746-
"hw_type": channel_config.hw_type,
747-
"hw_index": channel_config.hw_index,
748-
"hw_channel": channel_config.hw_channel,
744+
"hw_type": channel_config.hwType,
745+
"hw_index": channel_config.hwIndex,
746+
"hw_channel": channel_config.hwChannel,
749747
# additional information:
750748
"supports_fd": bool(
751-
channel_config.channel_capabilities
749+
channel_config.channelCapabilities
752750
& xldefine.XL_ChannelCapabilities.XL_CHANNEL_FLAG_CANFD_ISO_SUPPORT
753751
),
754752
"vector_channel_config": channel_config,
@@ -877,53 +875,22 @@ def set_timer_rate(self, timer_rate_ms: int) -> None:
877875
self.xldriver.xlSetTimerRate(self.port_handle, timer_rate_10us)
878876

879877

880-
class VectorCanParams(NamedTuple):
881-
bitrate: int
882-
sjw: int
883-
tseg1: int
884-
tseg2: int
885-
sam: int
886-
output_mode: xldefine.XL_OutputMode
887-
can_op_mode: xldefine.XL_CANFD_BusParams_CanOpMode
888-
889-
890-
class VectorCanFdParams(NamedTuple):
891-
bitrate: int
892-
data_bitrate: int
893-
sjw_abr: int
894-
tseg1_abr: int
895-
tseg2_abr: int
896-
sam_abr: int
897-
sjw_dbr: int
898-
tseg1_dbr: int
899-
tseg2_dbr: int
900-
output_mode: xldefine.XL_OutputMode
901-
can_op_mode: xldefine.XL_CANFD_BusParams_CanOpMode
902-
903-
904-
class VectorBusParams(NamedTuple):
905-
bus_type: xldefine.XL_BusTypes
906-
can: VectorCanParams
907-
canfd: VectorCanFdParams
908-
909-
910878
class VectorChannelConfig(NamedTuple):
911879
"""NamedTuple which contains the channel properties from Vector XL API."""
912880

913881
name: str
914-
hw_type: xldefine.XL_HardwareType
915-
hw_index: int
916-
hw_channel: int
917-
channel_index: int
918-
channel_mask: int
919-
channel_capabilities: xldefine.XL_ChannelCapabilities
920-
channel_bus_capabilities: xldefine.XL_BusCapabilities
921-
is_on_bus: bool
922-
connected_bus_type: xldefine.XL_BusTypes
923-
bus_params: VectorBusParams
924-
serial_number: int
925-
article_number: int
926-
transceiver_name: str
882+
hwType: xldefine.XL_HardwareType
883+
hwIndex: int
884+
hwChannel: int
885+
channelIndex: int
886+
channelMask: int
887+
channelCapabilities: xldefine.XL_ChannelCapabilities
888+
channelBusCapabilities: xldefine.XL_BusCapabilities
889+
isOnBus: bool
890+
connectedBusType: xldefine.XL_BusTypes
891+
serialNumber: int
892+
articleNumber: int
893+
transceiverName: str
927894

928895

929896
def _get_xl_driver_config() -> xlclass.XLdriverConfig:
@@ -940,38 +907,6 @@ def _get_xl_driver_config() -> xlclass.XLdriverConfig:
940907
return driver_config
941908

942909

943-
def _read_bus_params_from_c_struct(bus_params: xlclass.XLbusParams) -> VectorBusParams:
944-
return VectorBusParams(
945-
bus_type=xldefine.XL_BusTypes(bus_params.busType),
946-
can=VectorCanParams(
947-
bitrate=bus_params.data.can.bitRate,
948-
sjw=bus_params.data.can.sjw,
949-
tseg1=bus_params.data.can.tseg1,
950-
tseg2=bus_params.data.can.tseg2,
951-
sam=bus_params.data.can.sam,
952-
output_mode=xldefine.XL_OutputMode(bus_params.data.can.outputMode),
953-
can_op_mode=xldefine.XL_CANFD_BusParams_CanOpMode(
954-
bus_params.data.can.canOpMode
955-
),
956-
),
957-
canfd=VectorCanFdParams(
958-
bitrate=bus_params.data.canFD.arbitrationBitRate,
959-
data_bitrate=bus_params.data.canFD.dataBitRate,
960-
sjw_abr=bus_params.data.canFD.sjwAbr,
961-
tseg1_abr=bus_params.data.canFD.tseg1Abr,
962-
tseg2_abr=bus_params.data.canFD.tseg2Abr,
963-
sam_abr=bus_params.data.canFD.samAbr,
964-
sjw_dbr=bus_params.data.canFD.sjwDbr,
965-
tseg1_dbr=bus_params.data.canFD.tseg1Dbr,
966-
tseg2_dbr=bus_params.data.canFD.tseg2Dbr,
967-
output_mode=xldefine.XL_OutputMode(bus_params.data.canFD.outputMode),
968-
can_op_mode=xldefine.XL_CANFD_BusParams_CanOpMode(
969-
bus_params.data.canFD.canOpMode
970-
),
971-
),
972-
)
973-
974-
975910
def get_channel_configs() -> List[VectorChannelConfig]:
976911
"""Read channel properties from Vector XL API."""
977912
try:
@@ -984,23 +919,22 @@ def get_channel_configs() -> List[VectorChannelConfig]:
984919
xlcc: xlclass.XLchannelConfig = driver_config.channel[i]
985920
vcc = VectorChannelConfig(
986921
name=xlcc.name.decode(),
987-
hw_type=xldefine.XL_HardwareType(xlcc.hwType),
988-
hw_index=xlcc.hwIndex,
989-
hw_channel=xlcc.hwChannel,
990-
channel_index=xlcc.channelIndex,
991-
channel_mask=xlcc.channelMask,
992-
channel_capabilities=xldefine.XL_ChannelCapabilities(
922+
hwType=xldefine.XL_HardwareType(xlcc.hwType),
923+
hwIndex=xlcc.hwIndex,
924+
hwChannel=xlcc.hwChannel,
925+
channelIndex=xlcc.channelIndex,
926+
channelMask=xlcc.channelMask,
927+
channelCapabilities=xldefine.XL_ChannelCapabilities(
993928
xlcc.channelCapabilities
994929
),
995-
channel_bus_capabilities=xldefine.XL_BusCapabilities(
930+
channelBusCapabilities=xldefine.XL_BusCapabilities(
996931
xlcc.channelBusCapabilities
997932
),
998-
is_on_bus=bool(xlcc.isOnBus),
999-
bus_params=_read_bus_params_from_c_struct(xlcc.busParams),
1000-
connected_bus_type=xldefine.XL_BusTypes(xlcc.connectedBusType),
1001-
serial_number=xlcc.serialNumber,
1002-
article_number=xlcc.articleNumber,
1003-
transceiver_name=xlcc.transceiverName.decode(),
933+
isOnBus=bool(xlcc.isOnBus),
934+
connectedBusType=xldefine.XL_BusTypes(xlcc.connectedBusType),
935+
serialNumber=xlcc.serialNumber,
936+
articleNumber=xlcc.articleNumber,
937+
transceiverName=xlcc.transceiverName.decode(),
1004938
)
1005939
channel_list.append(vcc)
1006940
return channel_list

doc/interfaces/vector.rst

-24
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,6 @@ Miscellaneous
5959
:show-inheritance:
6060
:class-doc-from: class
6161

62-
.. autoclass:: can.interfaces.vector.canlib.VectorBusParams
63-
:show-inheritance:
64-
:class-doc-from: class
65-
66-
.. autoclass:: can.interfaces.vector.canlib.VectorCanParams
67-
:show-inheritance:
68-
:class-doc-from: class
69-
70-
.. autoclass:: can.interfaces.vector.canlib.VectorCanFdParams
71-
:show-inheritance:
72-
:class-doc-from: class
73-
7462
.. autoclass:: can.interfaces.vector.xldefine.XL_HardwareType
7563
:show-inheritance:
7664
:member-order: bysource
@@ -95,18 +83,6 @@ Miscellaneous
9583
:members:
9684
:undoc-members:
9785

98-
.. autoclass:: can.interfaces.vector.xldefine.XL_OutputMode
99-
:show-inheritance:
100-
:member-order: bysource
101-
:members:
102-
:undoc-members:
103-
104-
.. autoclass:: can.interfaces.vector.xldefine.XL_CANFD_BusParams_CanOpMode
105-
:show-inheritance:
106-
:member-order: bysource
107-
:members:
108-
:undoc-members:
109-
11086
.. autoclass:: can.interfaces.vector.xldefine.XL_Status
11187
:show-inheritance:
11288
:member-order: bysource

test/test_vector.py

+12-44
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
VectorOperationError,
2323
VectorChannelConfig,
2424
)
25-
from can.interfaces.vector import VectorBusParams, VectorCanParams, VectorCanFdParams
2625
from test.config import IS_WINDOWS
2726

2827
XLDRIVER_FOUND = canlib.xldriver is not None
@@ -605,49 +604,18 @@ def test_winapi_availability() -> None:
605604

606605
def test_vector_channel_config_attributes():
607606
assert hasattr(VectorChannelConfig, "name")
608-
assert hasattr(VectorChannelConfig, "hw_type")
609-
assert hasattr(VectorChannelConfig, "hw_index")
610-
assert hasattr(VectorChannelConfig, "hw_channel")
611-
assert hasattr(VectorChannelConfig, "channel_index")
612-
assert hasattr(VectorChannelConfig, "channel_mask")
613-
assert hasattr(VectorChannelConfig, "channel_capabilities")
614-
assert hasattr(VectorChannelConfig, "channel_bus_capabilities")
615-
assert hasattr(VectorChannelConfig, "is_on_bus")
616-
assert hasattr(VectorChannelConfig, "bus_params")
617-
assert hasattr(VectorChannelConfig, "connected_bus_type")
618-
assert hasattr(VectorChannelConfig, "serial_number")
619-
assert hasattr(VectorChannelConfig, "article_number")
620-
assert hasattr(VectorChannelConfig, "transceiver_name")
621-
622-
623-
def test_vector_bus_params_attributes():
624-
assert hasattr(VectorBusParams, "bus_type")
625-
assert hasattr(VectorBusParams, "can")
626-
assert hasattr(VectorBusParams, "canfd")
627-
628-
629-
def test_vector_can_params_attributes():
630-
assert hasattr(VectorCanParams, "bitrate")
631-
assert hasattr(VectorCanParams, "sjw")
632-
assert hasattr(VectorCanParams, "tseg1")
633-
assert hasattr(VectorCanParams, "tseg2")
634-
assert hasattr(VectorCanParams, "sam")
635-
assert hasattr(VectorCanParams, "output_mode")
636-
assert hasattr(VectorCanParams, "can_op_mode")
637-
638-
639-
def test_vector_canfd_params_attributes():
640-
assert hasattr(VectorCanFdParams, "bitrate")
641-
assert hasattr(VectorCanFdParams, "data_bitrate")
642-
assert hasattr(VectorCanFdParams, "sjw_abr")
643-
assert hasattr(VectorCanFdParams, "tseg1_abr")
644-
assert hasattr(VectorCanFdParams, "tseg2_abr")
645-
assert hasattr(VectorCanFdParams, "sam_abr")
646-
assert hasattr(VectorCanFdParams, "sjw_dbr")
647-
assert hasattr(VectorCanFdParams, "tseg1_dbr")
648-
assert hasattr(VectorCanFdParams, "tseg2_dbr")
649-
assert hasattr(VectorCanFdParams, "output_mode")
650-
assert hasattr(VectorCanFdParams, "can_op_mode")
607+
assert hasattr(VectorChannelConfig, "hwType")
608+
assert hasattr(VectorChannelConfig, "hwIndex")
609+
assert hasattr(VectorChannelConfig, "hwChannel")
610+
assert hasattr(VectorChannelConfig, "channelIndex")
611+
assert hasattr(VectorChannelConfig, "channelMask")
612+
assert hasattr(VectorChannelConfig, "channelCapabilities")
613+
assert hasattr(VectorChannelConfig, "channelBusCapabilities")
614+
assert hasattr(VectorChannelConfig, "isOnBus")
615+
assert hasattr(VectorChannelConfig, "connectedBusType")
616+
assert hasattr(VectorChannelConfig, "serialNumber")
617+
assert hasattr(VectorChannelConfig, "articleNumber")
618+
assert hasattr(VectorChannelConfig, "transceiverName")
651619

652620

653621
# *****************************************************************************

0 commit comments

Comments
 (0)