Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch and add getter for slave alias address #213

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ An EtherCAT master written in Rust.

## [Unreleased] - ReleaseDate

### Added

- [#213](https://github.com/ethercrab-rs/ethercrab/pull/213) (@jbbjarnason) Add `alias_address`
method to `Slave` and `SlaveRef` to get a SubDevice's alias address.

## [0.4.1] - 2024-04-05

### Fixed
Expand Down Expand Up @@ -370,8 +375,8 @@ An EtherCAT master written in Rust.
- Initial release

<!-- next-url -->
[unreleased]: https://github.com/ethercrab-rs/ethercrab/compare/ethercrab-v0.4.1...HEAD

[unreleased]: https://github.com/ethercrab-rs/ethercrab/compare/ethercrab-v0.4.1...HEAD
[0.4.1]: https://github.com/ethercrab-rs/ethercrab/compare/ethercrab-v0.4.0...ethercrab-v0.4.1
[0.4.0]: https://github.com/ethercrab-rs/ethercrab/compare/v0.3.6...ethercrab-v0.4.0
[0.3.7]: https://github.com/ethercrab-rs/ethercrab/compare/v0.3.6...v0.3.7
Expand Down
25 changes: 23 additions & 2 deletions src/slave/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub struct Slave {
/// Configured station address.
pub(crate) configured_address: u16,

pub(crate) alias_address: u16,

pub(crate) config: SlaveConfig,

pub(crate) identity: SlaveIdentity,
Expand Down Expand Up @@ -94,6 +96,7 @@ pub struct Slave {
impl PartialEq for Slave {
fn eq(&self, other: &Self) -> bool {
self.configured_address == other.configured_address
&& self.alias_address == other.alias_address
&& self.config == other.config
&& self.identity == other.identity
&& self.name == other.name
Expand All @@ -115,6 +118,7 @@ impl Clone for Slave {
fn clone(&self) -> Self {
Self {
configured_address: self.configured_address,
alias_address: self.alias_address,
config: self.config.clone(),
identity: self.identity,
name: self.name.clone(),
Expand Down Expand Up @@ -173,6 +177,11 @@ impl Slave {
.receive::<SupportFlags>(client)
.await?;

let alias_address = slave_ref
.read(RegisterAddress::ConfiguredStationAlias)
.receive::<u16>(client)
.await?;

let ports = slave_ref
.read(RegisterAddress::DlStatus)
.receive::<DlStatus>(client)
Expand All @@ -189,16 +198,18 @@ impl Slave {
})?;

fmt::debug!(
"Slave {:#06x} name {} {}, {}, {}",
"Slave {:#06x} name {} {}, {}, {}, alias address {:#06x}",
configured_address,
name,
identity,
flags,
ports
ports,
alias_address
);

Ok(Self {
configured_address,
alias_address,
config: SlaveConfig::default(),
index,
parent_index: None,
Expand Down Expand Up @@ -229,6 +240,11 @@ impl Slave {
self.configured_address
}

/// Get alias address for the slave device.
pub fn alias_address(&self) -> u16 {
self.alias_address
}

/// Get the network propagation delay of this device in nanoseconds.
///
/// Note that before [`Client::init`](crate::client::Client::init) is called, this method will
Expand Down Expand Up @@ -320,6 +336,11 @@ where
self.state.identity
}

/// Get alias address for the slave device.
pub fn alias_address(&self) -> u16 {
self.state.alias_address
}

/// Get the network propagation delay of this device in nanoseconds.
///
/// Note that before [`Client::init`](crate::client::Client::init) is called, this method will
Expand Down
Binary file modified tests/replay-ek1100-el2828-el2889-no-reborrow.pcapng
Binary file not shown.
Binary file modified tests/replay-ek1100-el2828-el2889.pcapng
Binary file not shown.
Binary file modified tests/replay-ek1914-el3004-mailbox.pcapng
Binary file not shown.
Binary file modified tests/replay-ek1914-no-complete-access.pcapng
Binary file not shown.
Binary file modified tests/replay-ek1914-segmented-upload.pcapng
Binary file not shown.