Compare commits

...

9 Commits

Author SHA1 Message Date
Francesco Valla f42baf505b
Merge 31d4a750d8 into 730aaf5fed 2026-02-09 10:07:05 +01:00
Jonathan Schwartz 730aaf5fed Device: FIRE3: Update disk counts 2026-02-06 14:32:31 -05:00
Kyle Schwarz 1f10adb760 ThirdParty: Update icspb & libredxx 2026-01-30 17:12:09 -05:00
Thomas Stoddard 6a32823a0f Device: FlexRay: Add additional configuration options for Controller and Cluster 2026-01-30 13:06:39 -05:00
Thomas Stoddard 5f16adc103 Device: RADComet3: Add Ethernet settings 2026-01-28 16:00:39 -05:00
Jonathan Schwartz f6926cbb22 Device: Unlock network mutex when going offline 2026-01-27 15:22:12 -05:00
Thomas Stoddard 4c7b8e107a Device: RADComet: Add T1S settings 2026-01-23 13:03:39 -05:00
Jonathan Schwartz 0e55101a16 Device: goOnline: Refactor network locking
Only lock known networks.
2026-01-22 16:46:51 -05:00
Francesco Valla 31d4a750d8 EthernetPacketizer: do a size check on incoming bytestream
An incoming bytestream can be less than 24 bytes, leading to exceptions
when accessing its data (or allocating the vector for its payload).
Perform a size check before trying to decode the bytestream and discard
invalid incoming streams.

Signed-off-by: Francesco Valla <francesco.valla@mta.it>
2025-07-04 10:57:28 +02:00
19 changed files with 1589 additions and 80 deletions

View File

@ -360,7 +360,7 @@ if(LIBICSNEO_ENABLE_DXX)
include(FetchContent) include(FetchContent)
FetchContent_Declare(libredxx FetchContent_Declare(libredxx
GIT_REPOSITORY https://github.com/Zeranoe/libredxx.git GIT_REPOSITORY https://github.com/Zeranoe/libredxx.git
GIT_TAG c28c3f4e1c46f0e0fc119843eb73edd81d5bbb3d GIT_TAG 267abf26a99fa69ed80a4180b155245a36fad101
) )
set(LIBREDXX_DISABLE_INSTALL ON) set(LIBREDXX_DISABLE_INSTALL ON)
FetchContent_MakeAvailable(libredxx) FetchContent_MakeAvailable(libredxx)
@ -392,7 +392,7 @@ endif()
include(FetchContent) include(FetchContent)
FetchContent_Declare(icspb FetchContent_Declare(icspb
GIT_REPOSITORY ${LIBICSNEO_ICSPB_REPO} GIT_REPOSITORY ${LIBICSNEO_ICSPB_REPO}
GIT_TAG 48df5dd7fd0c38034f82a2f94e0eada404d5e2b9 GIT_TAG 3339fa6b83a6b3e7704d41f5c2f2175cfc761a1f
) )
FetchContent_MakeAvailable(icspb) FetchContent_MakeAvailable(icspb)
target_link_libraries(icsneocpp PRIVATE icspb::icspb) target_link_libraries(icsneocpp PRIVATE icspb::icspb)

View File

@ -12,7 +12,6 @@ namespace icsneo {
struct DeviceSettingsNamespace { struct DeviceSettingsNamespace {
using EthLinkMode = AELinkMode; using EthLinkMode = AELinkMode;
using LinkSpeed = EthLinkSpeed;
}; };
void init_idevicesettings(pybind11::module_& m) { void init_idevicesettings(pybind11::module_& m) {
@ -23,13 +22,17 @@ void init_idevicesettings(pybind11::module_& m) {
.value("Slave", DeviceSettingsNamespace::EthLinkMode::AE_LINK_SLAVE) .value("Slave", DeviceSettingsNamespace::EthLinkMode::AE_LINK_SLAVE)
.value("Master", DeviceSettingsNamespace::EthLinkMode::AE_LINK_MASTER); .value("Master", DeviceSettingsNamespace::EthLinkMode::AE_LINK_MASTER);
pybind11::enum_<DeviceSettingsNamespace::LinkSpeed>(settings, "EthernetLinkSpeed") pybind11::enum_<EthPhyLinkMode>(settings, "PhyLinkMode")
.value("Speed10M", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_10) .value("ETH_LINK_MODE_AUTO_NEGOTIATION", ETH_LINK_MODE_AUTO_NEGOTIATION)
.value("Speed100M", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_100) .value("ETH_LINK_MODE_10MBPS_HALFDUPLEX", ETH_LINK_MODE_10MBPS_HALFDUPLEX)
.value("Speed1G", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_1000) .value("ETH_LINK_MODE_10MBPS_FULLDUPLEX", ETH_LINK_MODE_10MBPS_FULLDUPLEX)
.value("Speed2_5G", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_2500) .value("ETH_LINK_MODE_100MBPS_HALFDUPLEX", ETH_LINK_MODE_100MBPS_HALFDUPLEX)
.value("Speed5G", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_5000) .value("ETH_LINK_MODE_100MBPS_FULLDUPLEX", ETH_LINK_MODE_100MBPS_FULLDUPLEX)
.value("Speed10G", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_10000); .value("ETH_LINK_MODE_1GBPS_HALFDUPLEX", ETH_LINK_MODE_1GBPS_HALFDUPLEX)
.value("ETH_LINK_MODE_1GBPS_FULLDUPLEX", ETH_LINK_MODE_1GBPS_FULLDUPLEX)
.value("ETH_LINK_MODE_2_5GBPS_FULLDUPLEX", ETH_LINK_MODE_2_5GBPS_FULLDUPLEX)
.value("ETH_LINK_MODE_5GBPS_FULLDUPLEX", ETH_LINK_MODE_5GBPS_FULLDUPLEX)
.value("ETH_LINK_MODE_10GBPS_FULLDUPLEX", ETH_LINK_MODE_10GBPS_FULLDUPLEX);
pybind11::enum_<LINMode>(settings, "LINMode") pybind11::enum_<LINMode>(settings, "LINMode")
.value("Sleep", LINMode::SLEEP_MODE) .value("Sleep", LINMode::SLEEP_MODE)
@ -63,7 +66,7 @@ void init_idevicesettings(pybind11::module_& m) {
.def("get_lin_commander_response_time", &IDeviceSettings::getLINCommanderResponseTimeFor, pybind11::call_guard<pybind11::gil_scoped_release>()) .def("get_lin_commander_response_time", &IDeviceSettings::getLINCommanderResponseTimeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("set_lin_commander_response_time", &IDeviceSettings::setLINCommanderResponseTimeFor, pybind11::call_guard<pybind11::gil_scoped_release>()) .def("set_lin_commander_response_time", &IDeviceSettings::setLINCommanderResponseTimeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
// Ethernet PHY methods // Ethernet PHY methods (index-based for switch devices)
.def("get_phy_enable", &IDeviceSettings::getPhyEnable, pybind11::call_guard<pybind11::gil_scoped_release>()) .def("get_phy_enable", &IDeviceSettings::getPhyEnable, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("get_phy_mode", &IDeviceSettings::getPhyMode, pybind11::call_guard<pybind11::gil_scoped_release>()) .def("get_phy_mode", &IDeviceSettings::getPhyMode, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("get_phy_speed", &IDeviceSettings::getPhySpeed, pybind11::call_guard<pybind11::gil_scoped_release>()) .def("get_phy_speed", &IDeviceSettings::getPhySpeed, pybind11::call_guard<pybind11::gil_scoped_release>())
@ -71,6 +74,15 @@ void init_idevicesettings(pybind11::module_& m) {
.def("set_phy_mode", &IDeviceSettings::setPhyMode, pybind11::call_guard<pybind11::gil_scoped_release>()) .def("set_phy_mode", &IDeviceSettings::setPhyMode, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("set_phy_speed", &IDeviceSettings::setPhySpeed, pybind11::call_guard<pybind11::gil_scoped_release>()) .def("set_phy_speed", &IDeviceSettings::setPhySpeed, pybind11::call_guard<pybind11::gil_scoped_release>())
// Ethernet PHY methods (network-based for multi-interface devices)
.def("get_phy_enable_for", &IDeviceSettings::getPhyEnableFor, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("get_phy_role_for", &IDeviceSettings::getPhyRoleFor, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("get_phy_link_mode_for", &IDeviceSettings::getPhyLinkModeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("set_phy_enable_for", &IDeviceSettings::setPhyEnableFor, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("set_phy_role_for", &IDeviceSettings::setPhyRoleFor, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("set_phy_link_mode_for", &IDeviceSettings::setPhyLinkModeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("get_supported_phy_link_modes_for", &IDeviceSettings::getSupportedPhyLinkModesFor, pybind11::call_guard<pybind11::gil_scoped_release>())
// 10BASE-T1S methods // 10BASE-T1S methods
.def("is_t1s_plca_enabled", &IDeviceSettings::isT1SPLCAEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>()) .def("is_t1s_plca_enabled", &IDeviceSettings::isT1SPLCAEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("set_t1s_plca", &IDeviceSettings::setT1SPLCAFor, pybind11::call_guard<pybind11::gil_scoped_release>()) .def("set_t1s_plca", &IDeviceSettings::setT1SPLCAFor, pybind11::call_guard<pybind11::gil_scoped_release>())

View File

@ -64,6 +64,7 @@ void init_extension(pybind11::classh<FlexRayNamespace>& c) {
.def_readwrite("accept_startup_range_microticks", &Controller::Configuration::AcceptStartupRangeMicroticks) .def_readwrite("accept_startup_range_microticks", &Controller::Configuration::AcceptStartupRangeMicroticks)
.def_readwrite("allow_passive_to_active_cycle_pairs", &Controller::Configuration::AllowPassiveToActiveCyclePairs) .def_readwrite("allow_passive_to_active_cycle_pairs", &Controller::Configuration::AllowPassiveToActiveCyclePairs)
.def_readwrite("cluster_drift_damping", &Controller::Configuration::ClusterDriftDamping) .def_readwrite("cluster_drift_damping", &Controller::Configuration::ClusterDriftDamping)
.def_readwrite("allow_halt_due_to_clock", &Controller::Configuration::AllowHaltDueToClock)
.def_readwrite("channel_a", &Controller::Configuration::ChannelA) .def_readwrite("channel_a", &Controller::Configuration::ChannelA)
.def_readwrite("channel_b", &Controller::Configuration::ChannelB) .def_readwrite("channel_b", &Controller::Configuration::ChannelB)
.def_readwrite("decoding_correction_microticks", &Controller::Configuration::DecodingCorrectionMicroticks) .def_readwrite("decoding_correction_microticks", &Controller::Configuration::DecodingCorrectionMicroticks)
@ -74,6 +75,7 @@ void init_extension(pybind11::classh<FlexRayNamespace>& c) {
.def_readwrite("extern_offset_correction_microticks", &Controller::Configuration::ExternOffsetCorrectionMicroticks) .def_readwrite("extern_offset_correction_microticks", &Controller::Configuration::ExternOffsetCorrectionMicroticks)
.def_readwrite("extern_rate_correction_microticks", &Controller::Configuration::ExternRateCorrectionMicroticks) .def_readwrite("extern_rate_correction_microticks", &Controller::Configuration::ExternRateCorrectionMicroticks)
.def_readwrite("key_slot_id", &Controller::Configuration::KeySlotID) .def_readwrite("key_slot_id", &Controller::Configuration::KeySlotID)
.def_readwrite("key_slot_only_enabled", &Controller::Configuration::KeySlotOnlyEnabled)
.def_readwrite("key_slot_used_for_startup", &Controller::Configuration::KeySlotUsedForStartup) .def_readwrite("key_slot_used_for_startup", &Controller::Configuration::KeySlotUsedForStartup)
.def_readwrite("key_slot_used_for_sync", &Controller::Configuration::KeySlotUsedForSync) .def_readwrite("key_slot_used_for_sync", &Controller::Configuration::KeySlotUsedForSync)
.def_readwrite("latest_tx_minislot", &Controller::Configuration::LatestTxMinislot) .def_readwrite("latest_tx_minislot", &Controller::Configuration::LatestTxMinislot)
@ -114,6 +116,7 @@ void init_extension(pybind11::classh<FlexRayNamespace>& c) {
.def_readwrite("action_point_offset", &Cluster::Configuration::ActionPointOffset) .def_readwrite("action_point_offset", &Cluster::Configuration::ActionPointOffset)
.def_readwrite("casr_x_low_max", &Cluster::Configuration::CASRxLowMax) .def_readwrite("casr_x_low_max", &Cluster::Configuration::CASRxLowMax)
.def_readwrite("cold_start_attempts", &Cluster::Configuration::ColdStartAttempts) .def_readwrite("cold_start_attempts", &Cluster::Configuration::ColdStartAttempts)
.def_readwrite("cycle_duration_micro_sec", &Cluster::Configuration::CycleDurationMicroSec)
.def_readwrite("dynamic_slot_idle_phase_minislots", &Cluster::Configuration::DynamicSlotIdlePhaseMinislots) .def_readwrite("dynamic_slot_idle_phase_minislots", &Cluster::Configuration::DynamicSlotIdlePhaseMinislots)
.def_readwrite("listen_noise_macroticks", &Cluster::Configuration::ListenNoiseMacroticks) .def_readwrite("listen_noise_macroticks", &Cluster::Configuration::ListenNoiseMacroticks)
.def_readwrite("macroticks_per_cycle", &Cluster::Configuration::MacroticksPerCycle) .def_readwrite("macroticks_per_cycle", &Cluster::Configuration::MacroticksPerCycle)
@ -159,7 +162,8 @@ void init_flexraymessage(pybind11::module_& m) {
.def_readwrite("sync_frame", &FlexRayMessage::sync) .def_readwrite("sync_frame", &FlexRayMessage::sync)
.def_readwrite("startup_frame", &FlexRayMessage::startup) .def_readwrite("startup_frame", &FlexRayMessage::startup)
.def_readwrite("dynamic_frame", &FlexRayMessage::dynamic) .def_readwrite("dynamic_frame", &FlexRayMessage::dynamic)
.def_readwrite("cycle", &FlexRayMessage::cycle); .def_readwrite("cycle", &FlexRayMessage::cycle)
.def_readwrite("cycle_repetition", &FlexRayMessage::cycleRepetition);
//// TODO: Eliminate FlexRayControlMessage class references in controller class and eliminate getStatus function in bindings //// TODO: Eliminate FlexRayControlMessage class references in controller class and eliminate getStatus function in bindings
} }

View File

@ -133,6 +133,10 @@ EthernetPacketizer::EthernetPacket::EthernetPacket(const uint8_t* data, size_t s
int EthernetPacketizer::EthernetPacket::loadBytestream(const std::vector<uint8_t>& bytestream) { int EthernetPacketizer::EthernetPacket::loadBytestream(const std::vector<uint8_t>& bytestream) {
errorWhileDecodingFromBytestream = 0; errorWhileDecodingFromBytestream = 0;
if (bytestream.size() < 24) {
errorWhileDecodingFromBytestream = 1;
return errorWhileDecodingFromBytestream;
}
for(size_t i = 0; i < 6; i++) for(size_t i = 0; i < 6; i++)
destMAC[i] = bytestream[i]; destMAC[i] = bytestream[i];
for(size_t i = 0; i < 6; i++) for(size_t i = 0; i < 6; i++)

View File

@ -563,24 +563,27 @@ bool Device::goOnline() {
if(supportsNetworkMutex()) { if(supportsNetworkMutex()) {
assignedClientId = com->getClientIDSync(); assignedClientId = com->getClientIDSync();
if(assignedClientId) { if(assignedClientId) {
std::set<Network::NetID> nets;
for(auto&& net : getSupportedTXNetworks()) {
nets.insert(net.getNetID());
}
// firmware supports clientid/mutex // firmware supports clientid/mutex
networkMutexCallbackHandle = lockAllNetworks(std::numeric_limits<uint32_t>::max(), std::numeric_limits<uint32_t>::max(), NetworkMutexType::Shared, [this](std::shared_ptr<Message> message) { networkMutexCallbackHandle = lockNetworks(nets, std::numeric_limits<uint32_t>::max(), std::numeric_limits<uint32_t>::max(), NetworkMutexType::Shared, [this](std::shared_ptr<Message> message) {
auto netMutexMsg = std::static_pointer_cast<NetworkMutexMessage>(message); auto netMutexMsg = std::static_pointer_cast<NetworkMutexMessage>(message);
if(netMutexMsg->networks.size() && netMutexMsg->event.has_value()) { if(netMutexMsg->networks.size() && netMutexMsg->event.has_value()) {
switch(*netMutexMsg->event) { switch(*netMutexMsg->event) {
case NetworkMutexEvent::Acquired: case NetworkMutexEvent::Acquired:
lockedNetworks.emplace(*netMutexMsg->networks.begin()); lockedNetworks.emplace(*netMutexMsg->networks.begin());
break; break;
case NetworkMutexEvent::Released: { case NetworkMutexEvent::Released: {
auto it = lockedNetworks.find(*netMutexMsg->networks.begin()); auto it = lockedNetworks.find(*netMutexMsg->networks.begin());
if (it != lockedNetworks.end()) if (it != lockedNetworks.end())
lockedNetworks.erase(it); lockedNetworks.erase(it);
break; break;
}
} }
} }
} }
); });
} }
} }
@ -610,6 +613,11 @@ bool Device::goOffline() {
return true; return true;
} }
if(assignedClientId.has_value()) {
unlockAllNetworks();
assignedClientId.reset();
}
if(!enableNetworkCommunication(false)) if(!enableNetworkCommunication(false))
return false; return false;

View File

@ -0,0 +1,191 @@
=======================
FlexRay Getting Started
=======================
Prerequisites
=============
- icsneopy library installed
- FlexRay hardware device connected (e.g., Fire3 Flexray)
- Proper FlexRay bus termination (100Ω on each channel end)
Physical Hardware Setup for Two-Node Testing
---------------------------------------------
For testing the basic transmit and receive examples with a single device:
- Hardware: Device with dual FlexRay controllers (e.g., neoVI FIRE 3 Flexray)
- Connection: FLEXRAY_01 Channel A looped to FLEXRAY_02 Channel A
- Termination: 100Ω termination resistors on both ends of the loopback
- Cable: Use proper FlexRay twisted pair cable (impedance matched)
.. note::
The basic transmit/receive examples are configured for this loopback setup
where both controllers act as coldstart nodes. For use on an existing
FlexRay network, see the passive monitoring configuration notes in the
receive example.
FlexRay Coldstart
-----------------
FlexRay networks require at least one "coldstart node" to initialize the network timing.
The coldstart node is responsible for starting the FlexRay communication cycle.
For a complete standalone coldstart example, see the Additional Examples section below.
Basic Setup
===========
1. Import the library and find FlexRay device:
.. code-block:: python
import icsneopy
devices = icsneopy.find_all_devices()
# Find a device with FlexRay support
device = None
for dev in devices:
if dev.get_extension("FlexRay"):
device = dev
break
if not device:
raise RuntimeError("No FlexRay-capable device found")
2. Configure FlexRay controller:
.. literalinclude:: ../../examples/python/flexray/flexray_transmit_basic.py
:language: python
:lines: 12-111
3. Open device and go online:
.. code-block:: python
if not device.open():
raise RuntimeError("Failed to open device")
if not device.go_online():
raise RuntimeError("Failed to go online")
Transmitting FlexRay Frames
============================
This example demonstrates a coldstart node that initiates a FlexRay network
and transmits simulated sensor data continuously in slot 1.
**Hardware Setup**: FLEXRAY_01 looped to FLEXRAY_02
**Usage**:
1. Start the receive example first
2. Start this transmit example second
3. Network will initialize and frames will be transmitted
.. literalinclude:: ../../examples/python/flexray/flexray_transmit_basic.py
:language: python
:lines: 113-170
Key Configuration Parameters:
- **slotid**: The FlexRay slot ID for transmission (1-2047 for static segment)
- **cycle**: The FlexRay cycle number (0-63)
- **cycle_repetition**: How often the frame repeats (1 = every cycle, 2 = every other cycle)
- **channel**: Transmission channel (A, B, or AB for both)
- **key_slot_id**: Must be unique per node on the network
- **key_slot_used_for_startup**: True for coldstart nodes
- **key_slot_used_for_sync**: True to provide synchronization frames
Receiving FlexRay Frames
=========================
This example demonstrates receiving FlexRay frames on FLEXRAY_02 Channel A.
**Hardware Setup**: FLEXRAY_01 looped to FLEXRAY_02
**Configuration Note**: This example is configured with coldstart capability
for two-node loopback testing. For passive monitoring on an existing FlexRay
network:
1. Set ``key_slot_used_for_startup = False`` in the controller configuration
2. Remove the ``controller.set_allow_coldstart(True)`` call
3. Ensure all cluster parameters match the existing network
4. The node will sync and receive without transmitting
**Usage**:
1. Start this receive example first
2. Start the transmit example second
3. Frames from slot 1 will be displayed with hex and decimal payload views
.. literalinclude:: ../../examples/python/flexray/flexray_receive_basic.py
:language: python
:lines: 103-170
FlexRay Coldstart Configuration
================================
To use the Coldstart example, ensure the following:
Set the Flexray network in neoVI Explorer to Coldstart.
No other nodes should be present on the network during testing.
Nothing connected to Fire3 FlexRay bus.
Critical Coldstart Settings
----------------------------
.. literalinclude:: ../../examples/python/flexray/flexray_coldstart.py
:language: python
:lines: 40-48
Configuration Example:
.. literalinclude:: ../../examples/python/flexray/flexray_coldstart.py
:language: python
:lines: 20-64
Setting Coldstart on Controller:
.. code-block:: python
controller.set_allow_coldstart(True)
controller.set_start_when_going_online(True)
Cleanup and Resource Management
================================
Always close the device when finished:
.. code-block:: python
try:
# Your FlexRay operations here
pass
finally:
device.close()
See the basic transmit and receive examples for complete implementations.
Additional Examples
===================
Transmit Basic
--------------
Complete working example with coldstart node transmitting simulated sensor data.
All example files are available for download:
**Transmit Basic** - Coldstart node transmitting simulated sensor data
:download:`flexray_transmit_basic.py <../../examples/python/flexray/flexray_transmit_basic.py>`
**Receive Basic** - Receiving and displaying FlexRay frames with formatted output
:download:`flexray_receive_basic.py <../../examples/python/flexray/flexray_receive_basic.py>`
**Coldstart** - Standalone coldstart example demonstrating network initialization
:download:`flexray_coldstart.py <../../examples/python/flexray/flexray_coldstart.py>`

View File

@ -7,6 +7,7 @@ icsneopy
can_getting_started can_getting_started
ethernet_getting_started ethernet_getting_started
flexray_getting_started
examples examples
api api
radepsilon radepsilon

View File

@ -0,0 +1,218 @@
"""
FlexRay coldstart example using icsneopy library.
Demonstrates coldstart capability where one FlexRay device can start
the network without needing other devices connected.
CRITICAL COLDSTART REQUIREMENTS:
1. key_slot_used_for_startup = True
2. key_slot_used_for_sync = True
3. set_allow_coldstart(True)
4. Each controller needs a unique key_slot_id
5. Proper bus termination (required for FlexRay)
"""
import icsneopy
import time
def get_coldstart_controller_config(slot_id):
"""
Create FlexRay controller configuration for COLDSTART.
The three critical settings for coldstart are marked below.
"""
config = icsneopy.FlexRay.Controller.Configuration()
config.accept_startup_range_microticks = 160
config.allow_halt_due_to_clock = True
config.allow_passive_to_active_cycle_pairs = 15
config.cluster_drift_damping = 2
config.channel_a = True
config.channel_b = True
config.decoding_correction_microticks = 56
config.delay_compensation_a_microticks = 28
config.delay_compensation_b_microticks = 28
config.extern_offset_correction_control = 0
config.extern_rate_correction_control = 0
config.extern_offset_correction_microticks = 0
config.extern_rate_correction_microticks = 0
# CRITICAL FOR COLDSTART: Set the key slot ID
config.key_slot_id = slot_id
config.key_slot_only_enabled = False
# CRITICAL FOR COLDSTART: Enable startup and sync on key slot
config.key_slot_used_for_startup = True # Required for coldstart
config.key_slot_used_for_sync = True # Required for coldstart
config.latest_tx_minislot = 226
config.listen_timeout = 401202
config.macro_initial_offset_a = 7
config.macro_initial_offset_b = 7
config.micro_initial_offset_a = 36
config.micro_initial_offset_b = 36
config.micro_per_cycle = 200000
config.mts_on_a = False
config.mts_on_b = False
config.offset_correction_out_microticks = 189
config.rate_correction_out_microticks = 601
config.second_key_slot_id = 0
config.two_key_slot_mode = False
config.wakeup_pattern = 55
config.wakeup_on_channel_b = False
return config
def get_cluster_config():
"""Create FlexRay cluster configuration."""
config = icsneopy.FlexRay.Cluster.Configuration()
config.speed = icsneopy.FlexRay.Cluster.SpeedType.FLEXRAY_BAUDRATE_10M
config.strobe_point_position = icsneopy.FlexRay.Cluster.SPPType.FLEXRAY_SPP_5
config.action_point_offset = 4
config.casr_x_low_max = 64
config.cold_start_attempts = 8
config.cycle_duration_micro_sec = 5000
config.dynamic_slot_idle_phase_minislots = 1
config.listen_noise_macroticks = 4
config.macroticks_per_cycle = 5000
config.macrotick_duration_micro_sec = 1
config.max_without_clock_correction_fatal = 2
config.max_without_clock_correction_passive = 2
config.minislot_action_point_offset_macroticks = 4
config.minislot_duration_macroticks = 10
config.network_idle_time_macroticks = 40
config.network_management_vector_length_bytes = 1
config.number_of_minislots = 0
config.number_of_static_slots = 32
config.offset_correction_start_macroticks = 4991
config.payload_length_of_static_slot_in_words = 67
config.static_slot_macroticks = 155
config.symbol_window_macroticks = 0
config.symbol_window_action_point_offset_macroticks = 0
config.sync_frame_id_count_max = 15
config.transmission_start_sequence_duration_bits = 11
config.wakeup_rx_idle_bits = 40
config.wakeup_rx_low_bits = 40
config.wakeup_rx_window_bits = 301
config.wakeup_tx_active_bits = 60
config.wakeup_tx_idle_bits = 180
return config
def flexray_coldstart():
"""Perform FlexRay coldstart operation."""
devices = icsneopy.find_all_devices()
if not devices:
raise RuntimeError("No devices found")
# Find a device with FlexRay support
device = None
for dev in devices:
if dev.get_extension("FlexRay"):
device = dev
break
if not device:
raise RuntimeError("No FlexRay-capable device found")
print(f"Using device: {device.get_product_name()} {device.get_serial()}")
try:
# Get FlexRay controllers
controllers = device.get_flexray_controllers()
if not controllers:
raise RuntimeError("Device has no FlexRay controllers")
print(f"Device has {len(controllers)} FlexRay controller(s)")
# Configure controllers for coldstart
cluster_config = get_cluster_config()
base_slot_id = 1
for i, controller in enumerate(controllers):
slot_id = base_slot_id + i
controller_config = get_coldstart_controller_config(slot_id)
print(f"\nConfiguring controller {i} for COLDSTART:")
print(f" Key Slot ID: {slot_id}")
print(f" Key Slot Used for Startup: {controller_config.key_slot_used_for_startup}")
print(f" Key Slot Used for Sync: {controller_config.key_slot_used_for_sync}")
# CRITICAL FOR COLDSTART: Enable coldstart capability
controller.set_allow_coldstart(True)
print(f" Allow Coldstart: True")
# Configure to start when going online
controller.set_start_when_going_online(True)
# Set the configuration
controller.set_configuration(cluster_config, controller_config)
# Open device
print("\nOpening device...")
if not device.open():
raise RuntimeError("Failed to open device")
print("Device opened successfully")
# Go online - this triggers coldstart
print("\nGoing online (coldstart will initiate)...")
if not device.go_online():
raise RuntimeError("Failed to go online - check bus termination and configuration")
print("Device online successfully!")
print("\n" + "=" * 60)
print("✓ FlexRay network started via COLDSTART")
print("=" * 60)
# Transmit test messages on the coldstart key slot
print("\nTransmitting initial test messages...")
for i in range(5):
frame = icsneopy.FlexRayMessage()
frame.network = icsneopy.Network(icsneopy.Network.NetID.FLEXRAY_01)
frame.slotid = base_slot_id # Use the first key slot
frame.cycle = 0
frame.cycle_repetition = 1
frame.channel = icsneopy.FlexRay.Channel.AB
frame.data = (0xAA, 0xBB, 0xCC, 0xDD, i, i+1, i+2, i+3)
if device.transmit(frame):
print(f" ✓ Transmitted message {i+1}")
else:
print(f" ✗ Failed to transmit message {i+1}")
time.sleep(0.1)
print("\n" + "=" * 60)
print("Network is now active and will stay alive.")
print("You can now run transmit/receive examples in another terminal.")
print("Press Ctrl+C to stop and shut down the network.")
print("=" * 60)
# Keep transmitting periodically to maintain network presence
counter = 0
try:
while True:
frame = icsneopy.FlexRayMessage()
frame.network = icsneopy.Network(icsneopy.Network.NetID.FLEXRAY_01)
frame.slotid = base_slot_id
frame.cycle = 0
frame.cycle_repetition = 1
frame.channel = icsneopy.FlexRay.Channel.AB
frame.data = (0xCA, 0xFE, 0xBA, 0xBE, counter & 0xFF,
(counter >> 8) & 0xFF, (counter >> 16) & 0xFF, (counter >> 24) & 0xFF)
device.transmit(frame)
counter += 1
time.sleep(1) # Transmit every second
except KeyboardInterrupt:
print("\n\nStopping coldstart node...")
print("\n✓ Coldstart example completed successfully!")
finally:
device.close()
if __name__ == "__main__":
flexray_coldstart()

View File

@ -0,0 +1,188 @@
# Basic FlexRay frame reception example using icsneopy library.
import icsneopy
import time
import signal
import sys
def get_controller_config(slot_id):
"""Create a FlexRay controller configuration matching the network.
Args:
slot_id: The key slot ID for this node (must be unique per node)
Returns:
FlexRay.Controller.Configuration with all parameters set
Note:
For passive listening on an existing network, set:
- key_slot_used_for_startup = False
- Remove set_allow_coldstart(True) call below
"""
config = icsneopy.FlexRay.Controller.Configuration()
config.accept_startup_range_microticks = 160
config.allow_halt_due_to_clock = True
config.allow_passive_to_active_cycle_pairs = 15
config.cluster_drift_damping = 2
# Physical channel configuration (Channel A only for this example)
config.channel_a = True
config.channel_b = False # Single channel A only
config.decoding_correction_microticks = 56
config.delay_compensation_a_microticks = 28
config.delay_compensation_b_microticks = 28
config.extern_offset_correction_control = 0
config.extern_rate_correction_control = 0
config.extern_offset_correction_microticks = 0
config.extern_rate_correction_microticks = 0
# KEY SLOT CONFIGURATION - Critical for FlexRay operation
config.key_slot_id = slot_id # Must be unique per node
config.key_slot_only_enabled = False
config.key_slot_used_for_startup = True # True = participate in coldstart
config.key_slot_used_for_sync = True # True = synchronize with network
config.latest_tx_minislot = 226
config.listen_timeout = 401202
config.macro_initial_offset_a = 7
config.macro_initial_offset_b = 7
config.micro_initial_offset_a = 36
config.micro_initial_offset_b = 36
config.micro_per_cycle = 200000
config.mts_on_a = False
config.mts_on_b = False
config.offset_correction_out_microticks = 189
config.rate_correction_out_microticks = 601
config.second_key_slot_id = 0
config.two_key_slot_mode = False
config.wakeup_pattern = 55
config.wakeup_on_channel_b = False
return config
def get_cluster_config():
"""Create a FlexRay cluster configuration matching the network."""
config = icsneopy.FlexRay.Cluster.Configuration()
config.speed = icsneopy.FlexRay.Cluster.SpeedType.FLEXRAY_BAUDRATE_10M
config.strobe_point_position = icsneopy.FlexRay.Cluster.SPPType.FLEXRAY_SPP_5
config.action_point_offset = 4
config.casr_x_low_max = 64
config.cold_start_attempts = 8
config.cycle_duration_micro_sec = 5000
config.dynamic_slot_idle_phase_minislots = 1
config.listen_noise_macroticks = 4
config.macroticks_per_cycle = 5000
config.macrotick_duration_micro_sec = 1
config.max_without_clock_correction_fatal = 2
config.max_without_clock_correction_passive = 2
config.minislot_action_point_offset_macroticks = 4
config.minislot_duration_macroticks = 10
config.network_idle_time_macroticks = 40
config.network_management_vector_length_bytes = 1
config.number_of_minislots = 0
config.number_of_static_slots = 32
config.offset_correction_start_macroticks = 4991
config.payload_length_of_static_slot_in_words = 67
config.static_slot_macroticks = 155
config.symbol_window_macroticks = 0
config.symbol_window_action_point_offset_macroticks = 0
config.sync_frame_id_count_max = 15
config.transmission_start_sequence_duration_bits = 11
config.wakeup_rx_idle_bits = 40
config.wakeup_rx_low_bits = 40
config.wakeup_rx_window_bits = 301
config.wakeup_tx_active_bits = 60
config.wakeup_tx_idle_bits = 180
return config
def receive_flexray_frames():
"""Receive FlexRay frames as passive node with callback handling."""
devices = icsneopy.find_all_devices()
if not devices:
raise RuntimeError("No devices found")
# Find a device with FlexRay support
device = None
for dev in devices:
if dev.get_extension("FlexRay"):
device = dev
break
if not device:
raise RuntimeError("No FlexRay-capable device found")
frame_count = 0
running = True
def on_frame(frame):
nonlocal frame_count
if isinstance(frame, icsneopy.FlexRayMessage):
# Only show frames from slot 1 (filter out null frames)
if frame.slotid == 1:
frame_count += 1
# Nice formatted view of the frame
payload_hex = ' '.join([f'{b:02X}' for b in frame.data[:8]])
payload_dec = ' '.join([f'{b:3d}' for b in frame.data[:8]])
print(f"[Frame {frame_count:4d}] Slot: {frame.slotid:2d} | Cycle: {frame.cycle:2d} | "
f"Channel: {str(frame.channel):10s}")
print(f" Hex: [{payload_hex}]")
print(f" Dec: [{payload_dec}]\n")
def signal_handler(sig, frame):
nonlocal running
print("\nShutting down...")
running = False
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
frame_filter = icsneopy.MessageFilter(icsneopy.Network.NetID.FLEXRAY_02)
callback = icsneopy.MessageCallback(on_frame, frame_filter)
try:
# Configure FlexRay controller 1 (FLEXRAY_02) as passive node
controllers = device.get_flexray_controllers()
if len(controllers) < 2:
raise RuntimeError("Device needs at least 2 FlexRay controllers")
controller = controllers[1] # Use controller 1
cluster_config = get_cluster_config()
controller_config = get_controller_config(slot_id=2)
# Enable coldstart so this node transmits and coldstart node sees activity
controller.set_allow_coldstart(True)
controller.set_configuration(cluster_config, controller_config)
controller.set_start_when_going_online(True)
if not device.open():
raise RuntimeError("Failed to open device")
if not device.go_online():
raise RuntimeError("Failed to go online")
device.add_message_callback(callback)
print("="*60)
print("FlexRay Receive Node - Coldstart Config Loaded")
print("="*60)
print(f"Controller: FLEXRAY_02 | Slot ID: 2 | Channel: A")
print(f"Listening for frames...")
print(f"Start the transmit script now to begin communication")
print("="*60)
print("Press Ctrl+C to stop\n")
while running:
time.sleep(0.1)
print(f"\nTotal frames received: {frame_count}")
finally:
device.close()
if __name__ == "__main__":
receive_flexray_frames()

View File

@ -0,0 +1,218 @@
# Basic FlexRay frame transmission example using icsneopy library.
import icsneopy
import time
import signal
import sys
import random
def get_controller_config(slot_id, is_coldstart=False):
"""Create a FlexRay controller configuration matching the network.
Args:
slot_id: The key slot ID for this node (must be unique per node)
is_coldstart: True if this node participates in coldstart
Returns:
FlexRay.Controller.Configuration with all parameters set
"""
config = icsneopy.FlexRay.Controller.Configuration()
config.accept_startup_range_microticks = 160
config.allow_halt_due_to_clock = True
config.allow_passive_to_active_cycle_pairs = 15
config.cluster_drift_damping = 2
# Physical channel configuration (Channel A only for this example)
config.channel_a = True
config.channel_b = False # Single channel A only
config.decoding_correction_microticks = 56
config.delay_compensation_a_microticks = 28
config.delay_compensation_b_microticks = 28
config.extern_offset_correction_control = 0
config.extern_rate_correction_control = 0
config.extern_offset_correction_microticks = 0
config.extern_rate_correction_microticks = 0
# KEY SLOT CONFIGURATION - Critical for FlexRay operation
config.key_slot_id = slot_id # Must be unique per node
config.key_slot_only_enabled = False
config.key_slot_used_for_startup = is_coldstart # True = coldstart node
config.key_slot_used_for_sync = is_coldstart # True = provides sync
config.latest_tx_minislot = 226
config.listen_timeout = 401202
config.macro_initial_offset_a = 7
config.macro_initial_offset_b = 7
config.micro_initial_offset_a = 36
config.micro_initial_offset_b = 36
config.micro_per_cycle = 200000
config.mts_on_a = False
config.mts_on_b = False
config.offset_correction_out_microticks = 189
config.rate_correction_out_microticks = 601
config.second_key_slot_id = 0
config.two_key_slot_mode = False
config.wakeup_pattern = 55
config.wakeup_on_channel_b = False
return config
def get_cluster_config():
"""Create a FlexRay cluster configuration matching the network.
All nodes on the FlexRay network must have identical cluster parameters.
These define the timing and structure of the FlexRay communication cycle.
Key parameters:
- cycle_duration_micro_sec: 5000 = 5ms cycle time
- macroticks_per_cycle: 5000 macroticks per cycle
- number_of_static_slots: 32 static slots for guaranteed transmission
- payload_length_of_static_slot_in_words: 67 words = 134 bytes max payload
Returns:
FlexRay.Cluster.Configuration with all timing parameters set
"""
config = icsneopy.FlexRay.Cluster.Configuration()
config.speed = icsneopy.FlexRay.Cluster.SpeedType.FLEXRAY_BAUDRATE_10M
config.strobe_point_position = icsneopy.FlexRay.Cluster.SPPType.FLEXRAY_SPP_5
config.action_point_offset = 4
config.casr_x_low_max = 64
config.cold_start_attempts = 8
config.cycle_duration_micro_sec = 5000
config.dynamic_slot_idle_phase_minislots = 1
config.listen_noise_macroticks = 4
config.macroticks_per_cycle = 5000
config.macrotick_duration_micro_sec = 1
config.max_without_clock_correction_fatal = 2
config.max_without_clock_correction_passive = 2
config.minislot_action_point_offset_macroticks = 4
config.minislot_duration_macroticks = 10
config.network_idle_time_macroticks = 40
config.network_management_vector_length_bytes = 1
config.number_of_minislots = 0
config.number_of_static_slots = 32
config.offset_correction_start_macroticks = 4991
config.payload_length_of_static_slot_in_words = 67
config.static_slot_macroticks = 155
config.symbol_window_macroticks = 0
config.symbol_window_action_point_offset_macroticks = 0
config.sync_frame_id_count_max = 15
config.transmission_start_sequence_duration_bits = 11
config.wakeup_rx_idle_bits = 40
config.wakeup_rx_low_bits = 40
config.wakeup_rx_window_bits = 301
config.wakeup_tx_active_bits = 60
config.wakeup_tx_idle_bits = 180
return config
def transmit_flexray_frame():
"""Transmit FlexRay frames as coldstart node."""
devices = icsneopy.find_all_devices()
if not devices:
raise RuntimeError("No devices found")
# Find a device with FlexRay support
device = None
for dev in devices:
if dev.get_extension("FlexRay"):
device = dev
break
if not device:
raise RuntimeError("No FlexRay-capable device found")
running = True
def signal_handler(sig, frame):
nonlocal running
print("\nShutting down...")
running = False
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
try:
# Configure FlexRay controller 0 (FLEXRAY_01) as coldstart node
controllers = device.get_flexray_controllers()
if not controllers:
raise RuntimeError("Device has no FlexRay controllers")
controller = controllers[0] # Use controller 0
cluster_config = get_cluster_config()
controller_config = get_controller_config(slot_id=1, is_coldstart=True)
# Enable coldstart capability
controller.set_allow_coldstart(True)
controller.set_configuration(cluster_config, controller_config)
controller.set_start_when_going_online(True)
if not device.open():
raise RuntimeError("Failed to open device")
if not device.go_online():
raise RuntimeError("Failed to go online")
print("="*60)
print("FlexRay Transmit Node - Starting Network")
print("="*60)
print(f"Controller: FLEXRAY_01 | Slot ID: 1 | Channel: A")
print(f"Transmitting frames continuously...")
print("="*60)
print("Press Ctrl+C to stop\n")
# Transmit frames continuously starting immediately
counter = 0
sensor_temp = 20.0 # Simulated temperature sensor
sensor_pressure = 100.0 # Simulated pressure sensor
while running:
# Create new frame each time (important for FlexRay)
frame = icsneopy.FlexRayMessage()
frame.network = icsneopy.Network(icsneopy.Network.NetID.FLEXRAY_01)
frame.slotid = 1
frame.cycle = 0
frame.cycle_repetition = 1
frame.channel = icsneopy.FlexRay.Channel.A
# Simulate realistic sensor data
sensor_temp += random.uniform(-0.5, 0.5) # Temperature varies
sensor_pressure += random.uniform(-2.0, 2.0) # Pressure varies
# Pack data: [status, counter, temp_high, temp_low, pressure_high, pressure_low, checksum_placeholder, sequence]
status_byte = 0xA0 | (counter % 16) # Status with rolling bits
temp_int = int(sensor_temp * 10) & 0xFFFF
pressure_int = int(sensor_pressure * 10) & 0xFFFF
frame.data = (
status_byte,
counter & 0xFF,
(temp_int >> 8) & 0xFF,
temp_int & 0xFF,
(pressure_int >> 8) & 0xFF,
pressure_int & 0xFF,
random.randint(0, 255), # Random data
(counter >> 8) & 0xFF
)
success = device.transmit(frame)
if counter % 100 == 0: # Print every 100th to reduce spam
if success:
print(f" [TX {counter}] Temp: {sensor_temp:.1f}°C | Pressure: {sensor_pressure:.1f} kPa")
else:
print(f" Frame {counter}: Failed to transmit")
counter += 1
time.sleep(0.005) # 5ms per cycle
print("\nTransmission complete!")
finally:
device.close()
if __name__ == "__main__":
transmit_flexray_frame()

View File

@ -54,14 +54,18 @@ enum AELinkMode
AE_LINK_SLAVE AE_LINK_SLAVE
}; };
enum EthLinkSpeed enum EthPhyLinkMode
{ {
ETH_SPEED_10 = 0, ETH_LINK_MODE_AUTO_NEGOTIATION = 0,
ETH_SPEED_100, ETH_LINK_MODE_10MBPS_HALFDUPLEX,
ETH_SPEED_1000, ETH_LINK_MODE_10MBPS_FULLDUPLEX,
ETH_SPEED_2500, ETH_LINK_MODE_100MBPS_HALFDUPLEX,
ETH_SPEED_5000, ETH_LINK_MODE_100MBPS_FULLDUPLEX,
ETH_SPEED_10000, ETH_LINK_MODE_1GBPS_HALFDUPLEX,
ETH_LINK_MODE_1GBPS_FULLDUPLEX,
ETH_LINK_MODE_2_5GBPS_FULLDUPLEX,
ETH_LINK_MODE_5GBPS_FULLDUPLEX,
ETH_LINK_MODE_10GBPS_FULLDUPLEX
}; };
typedef struct typedef struct
@ -69,7 +73,7 @@ typedef struct
uint16_t networkId; uint16_t networkId;
uint8_t linkStatus; uint8_t linkStatus;
uint8_t linkFullDuplex; uint8_t linkFullDuplex;
uint8_t linkSpeed; // see EthLinkSpeed uint8_t linkSpeed; // 0=10Mbps, 1=100Mbps, 2=1Gbps, 3=2.5Gbps, 4=5Gbps, 5=10Gbps
int8_t linkMode; // for automotive networks - see AELinkMode int8_t linkMode; // for automotive networks - see AELinkMode
} EthernetNetworkStatus; } EthernetNetworkStatus;
@ -366,6 +370,11 @@ typedef struct SERDESGEN_SETTINGS_t
#define ETHERNET_SETTINGS2_FLAG_DEVICE_HOSTING_ENABLE 0x10 #define ETHERNET_SETTINGS2_FLAG_DEVICE_HOSTING_ENABLE 0x10
#define ETHERNET_SETTINGS2_FLAG_COMM_IN_USE 0x80 #define ETHERNET_SETTINGS2_FLAG_COMM_IN_USE 0x80
// ETHERNET_SETTINGS2 flags2 bit definitions
#define ETHERNET_SETTINGS2_FLAGS2_LINK_MODE_SLAVE 0x01 // bit0: 0=master, 1=slave
#define ETHERNET_SETTINGS2_FLAGS2_PHY_MODE_LEGACY 0x02 // bit1: 0=IEEE, 1=legacy
#define ETHERNET_SETTINGS2_FLAGS2_LINK_MODE_AUTO 0x04 // bit2: auto master/slave negotiation
typedef struct ETHERNET_SETTINGS2_t typedef struct ETHERNET_SETTINGS2_t
{ {
/* bit0: 0=half duplex, 1=full duplex /* bit0: 0=half duplex, 1=full duplex
@ -379,7 +388,13 @@ typedef struct ETHERNET_SETTINGS2_t
uint32_t ip_addr; uint32_t ip_addr;
uint32_t netmask; uint32_t netmask;
uint32_t gateway; uint32_t gateway;
uint8_t rsvd[2]; /* FLAGS2
* bit0: link mode - 0=master, 1=slave
* bit1: PHY mode - 0=IEEE, 1=legacy
* bit2: auto master/slave
*/
uint8_t flags2;
uint8_t rsvd;
} ETHERNET_SETTINGS2; } ETHERNET_SETTINGS2;
#define ETHERNET_SETTINGS2_SIZE 16 #define ETHERNET_SETTINGS2_SIZE 16
@ -808,6 +823,26 @@ public:
return reinterpret_cast<LIN_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data()))); return reinterpret_cast<LIN_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
} }
virtual const ETHERNET_SETTINGS2* getEthernetSettingsFor(Network net) const { (void)net; return nullptr; }
ETHERNET_SETTINGS2* getMutableEthernetSettingsFor(Network net) {
if(disabled || readonly)
return nullptr;
const uint8_t* offset = (const uint8_t*)getEthernetSettingsFor(net);
if(offset == nullptr)
return nullptr;
return reinterpret_cast<ETHERNET_SETTINGS2*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
}
virtual const AE_SETTINGS* getAESettingsFor(Network net) const { (void)net; return nullptr; }
AE_SETTINGS* getMutableAESettingsFor(Network net) {
if(disabled || readonly)
return nullptr;
const uint8_t* offset = (const uint8_t*)getAESettingsFor(net);
if(offset == nullptr)
return nullptr;
return reinterpret_cast<AE_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
}
/** /**
* Some devices have groupings of networks, where software * Some devices have groupings of networks, where software
* switchable termination can only be applied to one network * switchable termination can only be applied to one network
@ -908,39 +943,176 @@ public:
*/ */
bool setLINCommanderResponseTimeFor(Network net, uint8_t bits); bool setLINCommanderResponseTimeFor(Network net, uint8_t bits);
/**
* Set PHY role (Master/Slave/Auto) for switch devices (Epsilon/XL, Jupiter, etc) using port index.
* For all other devices, use setPhyRoleFor() instead.
*
* @param index Port index (0-based)
* @param mode Master/Slave/Auto role
* @return true if successful
*/
virtual bool setPhyMode(uint8_t index, AELinkMode mode) { virtual bool setPhyMode(uint8_t index, AELinkMode mode) {
(void)index, (void)mode; (void)index, (void)mode;
return false; return false;
} }
/**
* Enable/disable PHY for switch devices (Epsilon/XL, Jupiter, etc) using port index.
* For all other devices, use setPhyEnableFor() instead.
*
* @param index Port index (0-based)
* @param enable True to enable, false to disable
* @return true if successful
*/
virtual bool setPhyEnable(uint8_t index, bool enable) { virtual bool setPhyEnable(uint8_t index, bool enable) {
(void)index, (void)enable; (void)index, (void)enable;
return false; return false;
} }
virtual bool setPhySpeed(uint8_t index, EthLinkSpeed speed) { /**
(void)index, (void)speed; * Set PHY link mode (speed and duplex) for switch devices (Epsilon/XL, Jupiter, etc) using port index.
* For all other devices, use setPhyLinkModeFor() instead.
*
* @param index Port index (0-based)
* @param mode Link mode (speed + duplex combination)
* @return true if successful
*/
virtual bool setPhySpeed(uint8_t index, EthPhyLinkMode mode) {
(void)index, (void)mode;
return false; return false;
} }
/**
* Get PHY role (Master/Slave/Auto) for switch devices (Epsilon/XL, Jupiter, etc) using port index.
* For all other devices, use getPhyRoleFor() instead.
*
* @param index Port index (0-based)
* @return Current role, or nullopt if not available
*/
virtual std::optional<AELinkMode> getPhyMode(uint8_t index) { virtual std::optional<AELinkMode> getPhyMode(uint8_t index) {
(void)index; (void)index;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning); report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return std::nullopt; return std::nullopt;
} }
/**
* Get PHY enable state for switch devices (Epsilon/XL, Jupiter, etc) using port index.
* For all other devices, use getPhyEnableFor() instead.
*
* @param index Port index (0-based)
* @return True if enabled, false if disabled, nullopt if not available
*/
virtual std::optional<bool> getPhyEnable(uint8_t index) { virtual std::optional<bool> getPhyEnable(uint8_t index) {
(void)index; (void)index;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning); report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return std::nullopt; return std::nullopt;
} }
virtual std::optional<EthLinkSpeed> getPhySpeed(uint8_t index) { /**
* Get PHY link mode (speed and duplex) for switch devices (Epsilon/XL, Jupiter, etc) using port index.
* For all other devices, use getPhyLinkModeFor() instead.
*
* @param index Port index (0-based)
* @return Current link mode, or nullopt if not available
*/
virtual std::optional<EthPhyLinkMode> getPhySpeed(uint8_t index) {
(void)index; (void)index;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning); report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return std::nullopt; return std::nullopt;
} }
/**
* Set PHY role (Master/Slave/Auto) for network-based devices.
* For switch devices, use setPhyMode() with port index instead.
*
* @param net Network ID
* @param mode Master/Slave/Auto role
* @return true if successful
*/
virtual bool setPhyRoleFor(Network net, AELinkMode mode) {
(void)net, (void)mode;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return false;
}
/**
* Enable/disable PHY for network-based devices.
* For switch devices, use setPhyEnable() with port index instead.
*
* @param net Network ID
* @param enable True to enable, false to disable
* @return true if successful
*/
virtual bool setPhyEnableFor(Network net, bool enable) {
(void)net, (void)enable;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return false;
}
/**
* Get PHY role (Master/Slave/Auto) for network-based devices.
* For switch devices, use getPhyMode() with port index instead.
*
* @param net Network ID
* @return Current role, or nullopt if not available
*/
virtual std::optional<AELinkMode> getPhyRoleFor(Network net) const {
(void)net;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return std::nullopt;
}
/**
* Get PHY enable state for network-based devices.
* For switch devices, use getPhyEnable() with port index instead.
*
* @param net Network ID
* @return True if enabled, false if disabled, nullopt if not available
*/
virtual std::optional<bool> getPhyEnableFor(Network net) const {
(void)net;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return std::nullopt;
}
/**
* Get supported PHY link modes (combined speed+duplex) for a network.
* Each mode represents a valid hardware configuration.
*
* @param net The network to query
* @return Vector of supported modes, empty if network doesn't support PHY settings
*/
virtual std::vector<EthPhyLinkMode> getSupportedPhyLinkModesFor(Network net) const {
(void)net;
return {}; // Default: no PHY support
}
/**
* Set PHY link mode (speed and duplex together).
*
* @param net The network to configure
* @param mode The link mode to set
* @return true if successful, false if mode not supported or error occurred
*/
virtual bool setPhyLinkModeFor(Network net, EthPhyLinkMode mode) {
(void)net; (void)mode;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return false;
}
/**
* Get current PHY link mode.
*
* @param net The network to query
* @return Current link mode, or nullopt if not available or not configured
*/
virtual std::optional<EthPhyLinkMode> getPhyLinkModeFor(Network net) const {
(void)net;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
return std::nullopt;
}
virtual std::optional<bool> isT1SPLCAEnabledFor(Network net) const { virtual std::optional<bool> isT1SPLCAEnabledFor(Network net) const {
(void)net; (void)net;
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning); report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::EventWarning);
@ -1049,6 +1221,32 @@ protected:
return nullptr; return nullptr;
return reinterpret_cast<ICSNEO_UNALIGNED(uint64_t*)>((void*)(settings.data() + (offset - settingsInDeviceRAM.data()))); return reinterpret_cast<ICSNEO_UNALIGNED(uint64_t*)>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
} }
static bool SetNetworkEnabled(uint64_t* bitfields, size_t count, uint64_t networkID) {
const size_t index = networkID / 64;
const size_t offset = networkID & 0x3F;
if (index >= count)
return false;
bitfields[index] |= (1ULL << offset);
return true;
}
static bool ClearNetworkEnabled(uint64_t* bitfields, size_t count, uint64_t networkID) {
const size_t index = networkID / 64;
const size_t offset = networkID & 0x3F;
if (index >= count)
return false;
bitfields[index] &= ~(1ULL << offset);
return true;
}
static bool GetNetworkEnabled(const uint64_t* bitfields, size_t count, uint64_t networkID) {
const size_t index = networkID / 64;
const size_t offset = networkID & 0x3F;
if (index >= count)
return false;
return (bitfields[index] & (1ULL << offset)) != 0;
}
}; };
} }

View File

@ -147,6 +147,10 @@ protected:
return ret; return ret;
} }
size_t getDiskCount() const override {
return 2;
}
bool supportsNetworkMutex() const override { return true; } bool supportsNetworkMutex() const override { return true; }
}; };

View File

@ -102,6 +102,15 @@ protected:
bool supportsEraseMemory() const override { bool supportsEraseMemory() const override {
return true; return true;
} }
size_t getDiskCount() const override {
return 2;
}
bool supportsNetworkMutex() const override {
return true;
}
}; };
} }

View File

@ -262,7 +262,7 @@ public:
if(t1s == nullptr) if(t1s == nullptr)
return std::nullopt; return std::nullopt;
return std::make_optional<bool>((t1s->flags & ETHERNET10T1S_SETTINGS_FLAG_ENABLE_PLCA) != 0); return std::make_optional((t1s->flags & ETHERNET10T1S_SETTINGS_FLAG_ENABLE_PLCA) != 0);
} }
bool setT1SPLCAFor(Network net, bool enable) override { bool setT1SPLCAFor(Network net, bool enable) override {

View File

@ -116,6 +116,141 @@ public:
return nullptr; return nullptr;
} }
} }
std::optional<bool> isT1SPLCAEnabledFor(Network net) const override {
const ETHERNET10T1S_SETTINGS* t1s = getT1SSettingsFor(net);
if(t1s == nullptr)
return std::nullopt;
return std::make_optional((t1s->flags & ETHERNET10T1S_SETTINGS_FLAG_ENABLE_PLCA) != 0);
}
bool setT1SPLCAFor(Network net, bool enable) override {
ETHERNET10T1S_SETTINGS* t1s = getMutableT1SSettingsFor(net);
if(t1s == nullptr)
return false;
if(enable)
t1s->flags |= ETHERNET10T1S_SETTINGS_FLAG_ENABLE_PLCA;
else
t1s->flags &= ~ETHERNET10T1S_SETTINGS_FLAG_ENABLE_PLCA;
return true;
}
std::optional<uint8_t> getT1SLocalIDFor(Network net) const override {
const ETHERNET10T1S_SETTINGS* t1s = getT1SSettingsFor(net);
if(t1s == nullptr)
return std::nullopt;
return std::make_optional(t1s->local_id);
}
bool setT1SLocalIDFor(Network net, uint8_t id) override {
ETHERNET10T1S_SETTINGS* t1s = getMutableT1SSettingsFor(net);
if(t1s == nullptr)
return false;
t1s->local_id = id;
return true;
}
std::optional<uint8_t> getT1SMaxNodesFor(Network net) const override {
const ETHERNET10T1S_SETTINGS* t1s = getT1SSettingsFor(net);
if(t1s == nullptr)
return std::nullopt;
return std::make_optional(t1s->max_num_nodes);
}
bool setT1SMaxNodesFor(Network net, uint8_t nodes) override {
ETHERNET10T1S_SETTINGS* t1s = getMutableT1SSettingsFor(net);
if(t1s == nullptr)
return false;
t1s->max_num_nodes = nodes;
return true;
}
std::optional<uint8_t> getT1STxOppTimerFor(Network net) const override {
const ETHERNET10T1S_SETTINGS* t1s = getT1SSettingsFor(net);
if(t1s == nullptr)
return std::nullopt;
return std::make_optional(t1s->to_timer);
}
bool setT1STxOppTimerFor(Network net, uint8_t timer) override {
ETHERNET10T1S_SETTINGS* t1s = getMutableT1SSettingsFor(net);
if(t1s == nullptr)
return false;
t1s->to_timer = timer;
return true;
}
std::optional<uint8_t> getT1SMaxBurstFor(Network net) const override {
const ETHERNET10T1S_SETTINGS* t1s = getT1SSettingsFor(net);
if(t1s == nullptr)
return std::nullopt;
return std::make_optional(t1s->max_burst_count);
}
bool setT1SMaxBurstFor(Network net, uint8_t burst) override {
ETHERNET10T1S_SETTINGS* t1s = getMutableT1SSettingsFor(net);
if(t1s == nullptr)
return false;
t1s->max_burst_count = burst;
return true;
}
std::optional<uint8_t> getT1SBurstTimerFor(Network net) const override {
const ETHERNET10T1S_SETTINGS* t1s = getT1SSettingsFor(net);
if(t1s == nullptr)
return std::nullopt;
return std::make_optional(t1s->burst_timer);
}
bool setT1SBurstTimerFor(Network net, uint8_t timer) override {
ETHERNET10T1S_SETTINGS* t1s = getMutableT1SSettingsFor(net);
if(t1s == nullptr)
return false;
t1s->burst_timer = timer;
return true;
}
private:
const ETHERNET10T1S_SETTINGS* getT1SSettingsFor(Network net) const {
auto cfg = getStructurePointer<radcomet_settings_t>();
if(cfg == nullptr)
return nullptr;
switch(net.getNetID()) {
case Network::NetID::AE_02: return &(cfg->t1s1);
case Network::NetID::AE_03: return &(cfg->t1s2);
default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return nullptr;
}
}
ETHERNET10T1S_SETTINGS* getMutableT1SSettingsFor(Network net) {
auto cfg = getMutableStructurePointer<radcomet_settings_t>();
if(cfg == nullptr)
return nullptr;
switch(net.getNetID()) {
case Network::NetID::AE_02: return &(cfg->t1s1);
case Network::NetID::AE_03: return &(cfg->t1s2);
default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return nullptr;
}
}
}; };
} }

View File

@ -114,12 +114,50 @@ public:
} }
} }
const ETHERNET_SETTINGS2* getEthernetSettingsFor(Network net) const override {
auto cfg = getStructurePointer<radcomet3_settings_t>();
if(cfg == nullptr)
return nullptr;
switch(net.getNetID()) {
case Network::NetID::ETHERNET_01:
return &(cfg->ethernet);
case Network::NetID::AE_01:
return &(cfg->ethT1);
case Network::NetID::AE_02:
return &(cfg->ethT1s1);
case Network::NetID::AE_03:
return &(cfg->ethT1s2);
case Network::NetID::AE_04:
return &(cfg->ethT1s3);
case Network::NetID::AE_05:
return &(cfg->ethT1s4);
case Network::NetID::AE_06:
return &(cfg->ethT1s5);
case Network::NetID::AE_07:
return &(cfg->ethT1s6);
default:
return nullptr;
}
}
const AE_SETTINGS* getAESettingsFor(Network net) const override {
auto cfg = getStructurePointer<radcomet3_settings_t>();
if(cfg == nullptr)
return nullptr;
switch(net.getNetID()) {
case Network::NetID::AE_01:
return &(cfg->ae_01);
default:
return nullptr;
}
}
std::optional<bool> isT1SPLCAEnabledFor(Network net) const override { std::optional<bool> isT1SPLCAEnabledFor(Network net) const override {
const ETHERNET10T1S_SETTINGS* t1s = getT1SSettingsFor(net); const ETHERNET10T1S_SETTINGS* t1s = getT1SSettingsFor(net);
if(t1s == nullptr) if(t1s == nullptr)
return std::nullopt; return std::nullopt;
return std::make_optional<bool>((t1s->flags & ETHERNET10T1S_SETTINGS_FLAG_ENABLE_PLCA) != 0); return std::make_optional((t1s->flags & ETHERNET10T1S_SETTINGS_FLAG_ENABLE_PLCA) != 0);
} }
bool setT1SPLCAFor(Network net, bool enable) override { bool setT1SPLCAFor(Network net, bool enable) override {
@ -220,6 +258,280 @@ public:
return true; return true;
} }
bool setPhyRoleFor(Network net, AELinkMode mode) override {
if (mode != AE_LINK_AUTO && mode != AE_LINK_MASTER && mode != AE_LINK_SLAVE) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
AE_SETTINGS* ae = getMutableAESettingsFor(net);
if (ae == nullptr) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
ae->ucConfigMode = static_cast<uint8_t>(mode);
ETHERNET_SETTINGS2* ethSettings = getMutableEthernetSettingsFor(net);
if (ethSettings == nullptr) {
return false;
}
uint8_t& flags2 = ethSettings->flags2;
switch (mode) {
case AE_LINK_AUTO:
flags2 |= ETHERNET_SETTINGS2_FLAGS2_LINK_MODE_AUTO;
break;
case AE_LINK_MASTER:
flags2 &= ~ETHERNET_SETTINGS2_FLAGS2_LINK_MODE_AUTO;
flags2 &= ~ETHERNET_SETTINGS2_FLAGS2_LINK_MODE_SLAVE;
break;
case AE_LINK_SLAVE:
flags2 &= ~ETHERNET_SETTINGS2_FLAGS2_LINK_MODE_AUTO;
flags2 |= ETHERNET_SETTINGS2_FLAGS2_LINK_MODE_SLAVE;
break;
}
return true;
}
bool setPhyEnableFor(Network net, bool enable) override {
auto cfg = getMutableStructurePointer<radcomet3_settings_t>();
if (cfg == nullptr)
return false;
if (net.getType() != Network::Type::Ethernet && net.getType() != Network::Type::AutomotiveEthernet) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
auto coreMini = net.getCoreMini();
if (!coreMini.has_value()) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
const uint64_t networkID = static_cast<uint64_t>(coreMini.value());
uint64_t bitfields[2] = { cfg->network_enables, cfg->network_enables_2 };
const bool success = enable ?
SetNetworkEnabled(bitfields, 2, networkID) :
ClearNetworkEnabled(bitfields, 2, networkID);
if (!success) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
cfg->network_enables = bitfields[0];
cfg->network_enables_2 = bitfields[1];
return true;
}
std::optional<AELinkMode> getPhyRoleFor(Network net) const override {
const AE_SETTINGS* ae = getAESettingsFor(net);
if (ae == nullptr) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
}
switch (ae->ucConfigMode) {
case 0:
return std::make_optional(AE_LINK_AUTO);
case 1:
return std::make_optional(AE_LINK_MASTER);
case 2:
return std::make_optional(AE_LINK_SLAVE);
default:
return std::make_optional(AE_LINK_AUTO);
}
}
std::optional<bool> getPhyEnableFor(Network net) const override {
auto cfg = getStructurePointer<radcomet3_settings_t>();
if (cfg == nullptr) {
report(APIEvent::Type::SettingsReadError, APIEvent::Severity::Error);
return std::nullopt;
}
if (net.getType() != Network::Type::Ethernet && net.getType() != Network::Type::AutomotiveEthernet) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
}
auto coreMini = net.getCoreMini();
if (!coreMini.has_value()) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
}
const uint64_t networkID = static_cast<uint64_t>(coreMini.value());
const uint64_t bitfields[2] = { cfg->network_enables, cfg->network_enables_2 };
return GetNetworkEnabled(bitfields, 2, networkID);
}
std::vector<EthPhyLinkMode> getSupportedPhyLinkModesFor(Network net) const override {
switch(net.getNetID()) {
case Network::NetID::ETHERNET_01:
return {
ETH_LINK_MODE_AUTO_NEGOTIATION,
ETH_LINK_MODE_10MBPS_FULLDUPLEX,
ETH_LINK_MODE_100MBPS_FULLDUPLEX,
ETH_LINK_MODE_1GBPS_FULLDUPLEX
};
case Network::NetID::AE_01:
return {
ETH_LINK_MODE_AUTO_NEGOTIATION,
ETH_LINK_MODE_100MBPS_FULLDUPLEX,
ETH_LINK_MODE_1GBPS_FULLDUPLEX
};
case Network::NetID::AE_02:
case Network::NetID::AE_03:
case Network::NetID::AE_04:
case Network::NetID::AE_05:
case Network::NetID::AE_06:
case Network::NetID::AE_07:
return {ETH_LINK_MODE_10MBPS_HALFDUPLEX};
default:
return {};
}
}
bool setPhyLinkModeFor(Network net, EthPhyLinkMode mode) override {
auto supported = getSupportedPhyLinkModesFor(net);
if (std::find(supported.begin(), supported.end(), mode) == supported.end()) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
auto cfg = getMutableStructurePointer<radcomet3_settings_t>();
if (cfg == nullptr)
return false;
if (net.getNetID() == Network::NetID::AE_01) {
AE_SETTINGS* ae = getMutableAESettingsFor(net);
if (ae == nullptr) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
switch (mode) {
case ETH_LINK_MODE_AUTO_NEGOTIATION:
ae->link_spd = 3;
cfg->ethT1.link_speed = 2;
cfg->ethT1.flags |= ETHERNET_SETTINGS2_FLAG_AUTO_NEG;
cfg->ethT1.flags |= ETHERNET_SETTINGS2_FLAG_FULL_DUPLEX;
break;
case ETH_LINK_MODE_100MBPS_FULLDUPLEX:
ae->link_spd = 1;
cfg->ethT1.link_speed = 1;
cfg->ethT1.flags &= ~ETHERNET_SETTINGS2_FLAG_AUTO_NEG;
cfg->ethT1.flags |= ETHERNET_SETTINGS2_FLAG_FULL_DUPLEX;
break;
case ETH_LINK_MODE_1GBPS_FULLDUPLEX:
ae->link_spd = 2;
cfg->ethT1.link_speed = 2;
cfg->ethT1.flags &= ~ETHERNET_SETTINGS2_FLAG_AUTO_NEG;
cfg->ethT1.flags |= ETHERNET_SETTINGS2_FLAG_FULL_DUPLEX;
break;
default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
} else if (net.getNetID() == Network::NetID::ETHERNET_01) {
switch (mode) {
case ETH_LINK_MODE_AUTO_NEGOTIATION:
cfg->ethernet.flags |= ETHERNET_SETTINGS2_FLAG_AUTO_NEG;
cfg->ethernet.link_speed = 2;
cfg->ethernet.flags |= ETHERNET_SETTINGS2_FLAG_FULL_DUPLEX;
break;
case ETH_LINK_MODE_10MBPS_FULLDUPLEX:
cfg->ethernet.link_speed = 0;
cfg->ethernet.flags &= ~ETHERNET_SETTINGS2_FLAG_AUTO_NEG;
cfg->ethernet.flags |= ETHERNET_SETTINGS2_FLAG_FULL_DUPLEX;
break;
case ETH_LINK_MODE_100MBPS_FULLDUPLEX:
cfg->ethernet.link_speed = 1;
cfg->ethernet.flags &= ~ETHERNET_SETTINGS2_FLAG_AUTO_NEG;
cfg->ethernet.flags |= ETHERNET_SETTINGS2_FLAG_FULL_DUPLEX;
break;
case ETH_LINK_MODE_1GBPS_FULLDUPLEX:
cfg->ethernet.link_speed = 2;
cfg->ethernet.flags &= ~ETHERNET_SETTINGS2_FLAG_AUTO_NEG;
cfg->ethernet.flags |= ETHERNET_SETTINGS2_FLAG_FULL_DUPLEX;
break;
default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false;
}
}
return true;
}
std::optional<EthPhyLinkMode> getPhyLinkModeFor(Network net) const override {
auto cfg = getStructurePointer<radcomet3_settings_t>();
if (cfg == nullptr) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
}
if (net.getNetID() == Network::NetID::ETHERNET_01) {
if (cfg->ethernet.flags & ETHERNET_SETTINGS2_FLAG_AUTO_NEG) {
return ETH_LINK_MODE_AUTO_NEGOTIATION;
}
bool fullDuplex = (cfg->ethernet.flags & ETHERNET_SETTINGS2_FLAG_FULL_DUPLEX) != 0;
switch (cfg->ethernet.link_speed) {
case 0:
return fullDuplex ? ETH_LINK_MODE_10MBPS_FULLDUPLEX
: ETH_LINK_MODE_10MBPS_HALFDUPLEX;
case 1:
return fullDuplex ? ETH_LINK_MODE_100MBPS_FULLDUPLEX
: ETH_LINK_MODE_100MBPS_HALFDUPLEX;
case 2:
return fullDuplex ? ETH_LINK_MODE_1GBPS_FULLDUPLEX
: ETH_LINK_MODE_1GBPS_HALFDUPLEX;
default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
}
} else if (net.getNetID() == Network::NetID::AE_01) {
const AE_SETTINGS* ae = &cfg->ae_01;
// Check auto-negotiate
if (ae->link_spd == 3 || (cfg->ethT1.flags & ETHERNET_SETTINGS2_FLAG_AUTO_NEG)) {
return ETH_LINK_MODE_AUTO_NEGOTIATION;
}
// T1 is always full-duplex
switch (ae->link_spd) {
case 1: // 100 Mbps
return ETH_LINK_MODE_100MBPS_FULLDUPLEX;
case 2: // 1000 Mbps
return ETH_LINK_MODE_1GBPS_FULLDUPLEX;
default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
}
} else if (net.getNetID() >= Network::NetID::AE_02 && net.getNetID() <= Network::NetID::AE_07) {
// 10BASE-T1S ports - half-duplex only
return ETH_LINK_MODE_10MBPS_HALFDUPLEX;
} else {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt;
}
}
private: private:
const ETHERNET10T1S_SETTINGS* getT1SSettingsFor(Network net) const { const ETHERNET10T1S_SETTINGS* getT1SSettingsFor(Network net) const {
auto cfg = getStructurePointer<radcomet3_settings_t>(); auto cfg = getStructurePointer<radcomet3_settings_t>();

View File

@ -168,7 +168,7 @@ public:
return true; return true;
} }
bool setPhySpeed(uint8_t index, EthLinkSpeed speed) override { bool setPhySpeed(uint8_t index, EthPhyLinkMode mode) override {
if (index > RADEPSILON_MAX_PHY) { if (index > RADEPSILON_MAX_PHY) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error); report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false; return false;
@ -178,19 +178,30 @@ public:
return false; return false;
} }
EpsilonPhySpeed epsilonSpeed; EpsilonPhySpeed epsilonSpeed;
switch (speed) { switch (mode) {
case ETH_LINK_MODE_AUTO_NEGOTIATION:
// Auto-negotiate - default to 1G base speed
epsilonSpeed = EpsilonPhySpeed::Speed1000;
break;
case ETH_LINK_MODE_100MBPS_FULLDUPLEX:
epsilonSpeed = EpsilonPhySpeed::Speed100;
break;
case ETH_LINK_MODE_1GBPS_FULLDUPLEX:
epsilonSpeed = EpsilonPhySpeed::Speed1000;
break;
case ETH_LINK_MODE_10GBPS_FULLDUPLEX:
epsilonSpeed = EpsilonPhySpeed::Speed10000;
break;
// Reject half-duplex modes - automotive T1 is full-duplex only
case ETH_LINK_MODE_10MBPS_HALFDUPLEX:
case ETH_LINK_MODE_10MBPS_FULLDUPLEX:
case ETH_LINK_MODE_100MBPS_HALFDUPLEX:
case ETH_LINK_MODE_1GBPS_HALFDUPLEX:
case ETH_LINK_MODE_2_5GBPS_FULLDUPLEX:
case ETH_LINK_MODE_5GBPS_FULLDUPLEX:
default: default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error); report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return false; return false;
case ETH_SPEED_100:
epsilonSpeed = EpsilonPhySpeed::Speed100;
break;
case ETH_SPEED_1000:
epsilonSpeed = EpsilonPhySpeed::Speed1000;
break;
case ETH_SPEED_10000:
epsilonSpeed = EpsilonPhySpeed::Speed10000;
break;
} }
cfg->switchSettings.speed[index] = static_cast<uint8_t>(epsilonSpeed); cfg->switchSettings.speed[index] = static_cast<uint8_t>(epsilonSpeed);
return true; return true;
@ -235,7 +246,7 @@ public:
return std::make_optional(static_cast<bool>(cfg->switchSettings.enablePhy[index])); return std::make_optional(static_cast<bool>(cfg->switchSettings.enablePhy[index]));
} }
std::optional<EthLinkSpeed> getPhySpeed(uint8_t index) override { std::optional<EthPhyLinkMode> getPhySpeed(uint8_t index) override {
if (index > RADEPSILON_MAX_PHY) { if (index > RADEPSILON_MAX_PHY) {
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error); report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt; return std::nullopt;
@ -244,22 +255,18 @@ public:
if (cfg == nullptr) { if (cfg == nullptr) {
return std::nullopt; return std::nullopt;
} }
EthLinkSpeed speed; // Automotive Ethernet T1 is always full-duplex
switch (static_cast<EpsilonPhySpeed>(cfg->switchSettings.speed[index])) { switch (static_cast<EpsilonPhySpeed>(cfg->switchSettings.speed[index])) {
case EpsilonPhySpeed::Speed100:
return ETH_LINK_MODE_100MBPS_FULLDUPLEX;
case EpsilonPhySpeed::Speed1000:
return ETH_LINK_MODE_1GBPS_FULLDUPLEX;
case EpsilonPhySpeed::Speed10000:
return ETH_LINK_MODE_10GBPS_FULLDUPLEX;
default: default:
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error); report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
return std::nullopt; return std::nullopt;
case EpsilonPhySpeed::Speed100:
speed = ETH_SPEED_100;
break;
case EpsilonPhySpeed::Speed1000:
speed = ETH_SPEED_1000;
break;
case EpsilonPhySpeed::Speed10000:
speed = ETH_SPEED_10000;
break;
} }
return std::make_optional(speed);
} }
private: private:

View File

@ -254,7 +254,7 @@ namespace icsneo
if(t1s == nullptr) if(t1s == nullptr)
return std::nullopt; return std::nullopt;
return std::make_optional<bool>((t1s->flags & ETHERNET10T1S_SETTINGS_FLAG_ENABLE_PLCA) != 0); return std::make_optional((t1s->flags & ETHERNET10T1S_SETTINGS_FLAG_ENABLE_PLCA) != 0);
} }
bool setT1SPLCAFor(Network net, bool enable) override { bool setT1SPLCAFor(Network net, bool enable) override {

View File

@ -53,7 +53,7 @@ public:
if(t1s == nullptr) if(t1s == nullptr)
return std::nullopt; return std::nullopt;
return std::make_optional<bool>((t1s->flags & ETHERNET10T1S_SETTINGS_FLAG_ENABLE_PLCA) != 0); return std::make_optional((t1s->flags & ETHERNET10T1S_SETTINGS_FLAG_ENABLE_PLCA) != 0);
} }
bool setT1SPLCAFor(Network net, bool enable) override { bool setT1SPLCAFor(Network net, bool enable) override {