Skip to content

Commit

Permalink
bump to ethercat-esi 0.2 for cyclic-data info example
Browse files Browse the repository at this point in the history
fixes #47
  • Loading branch information
birkenfeld committed Aug 24, 2024
1 parent ff239ac commit fa554ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ num-traits = "0.2"
thiserror = "1.0"

[dev-dependencies]
ethercat-esi = "0.1"
ethercat-esi = "0.2"
env_logger = "0.8"

[features]
Expand Down
25 changes: 9 additions & 16 deletions examples/cyclic-data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use ethercat::{
AlState, DomainIdx as DomainIndex, Idx, Master, MasterAccess, Offset, PdoCfg, PdoEntryIdx,
PdoEntryIdx as PdoEntryIndex, PdoEntryInfo, PdoEntryPos, PdoIdx, SlaveAddr, SlaveId, SlavePos,
SmCfg, SubIdx,
AlState, DomainIdx as DomainIndex, Master, MasterAccess, Offset, PdoCfg, PdoEntryIdx,
PdoEntryInfo, PdoEntryPos, SlaveAddr, SlaveId, SlavePos, SmCfg,
};
use ethercat_esi::EtherCatInfo;
use std::{
Expand Down Expand Up @@ -64,7 +63,7 @@ pub fn main() -> Result<(), io::Error> {
}
}

type SlaveMap = HashMap<SlavePos, HashMap<PdoEntryIndex, (BitLen, Offset)>>;
type SlaveMap = HashMap<SlavePos, HashMap<PdoEntryIdx, (BitLen, Offset)>>;

pub fn init_master(
esi: &EtherCatInfo,
Expand All @@ -75,7 +74,7 @@ pub fn init_master(
master.reserve()?;
log::debug!("Create domain");
let domain_idx = master.create_domain()?;
let mut offsets: HashMap<SlavePos, HashMap<PdoEntryIndex, (u8, Offset)>> = HashMap::new();
let mut offsets: HashMap<SlavePos, HashMap<PdoEntryIdx, (u8, Offset)>> = HashMap::new();

for (dev_nr, dev) in esi.description.devices.iter().enumerate() {
let slave_pos = SlavePos::from(dev_nr as u16);
Expand All @@ -89,22 +88,19 @@ pub fn init_master(
product_code: dev.product_code,
};
let mut config = master.configure_slave(slave_addr, slave_id)?;
let mut entry_offsets: HashMap<PdoEntryIndex, (u8, Offset)> = HashMap::new();
let mut entry_offsets: HashMap<PdoEntryIdx, (u8, Offset)> = HashMap::new();

let rx_pdos: Vec<PdoCfg> = dev
.rx_pdo
.iter()
.map(|pdo| PdoCfg {
idx: PdoIdx::from(pdo.index),
idx: pdo.idx,
entries: pdo
.entries
.iter()
.enumerate()
.map(|(i, e)| PdoEntryInfo {
entry_idx: PdoEntryIdx {
idx: Idx::from(e.index),
sub_idx: SubIdx::from(e.sub_index.unwrap_or(1) as u8),
},
entry_idx: e.entry_idx,
bit_len: e.bit_len as u8,
name: e.name.clone().unwrap_or_default(),
pos: PdoEntryPos::from(i as u8),
Expand All @@ -117,16 +113,13 @@ pub fn init_master(
.tx_pdo
.iter()
.map(|pdo| PdoCfg {
idx: PdoIdx::from(pdo.index),
idx: pdo.idx,
entries: pdo
.entries
.iter()
.enumerate()
.map(|(i, e)| PdoEntryInfo {
entry_idx: PdoEntryIdx {
idx: Idx::from(e.index),
sub_idx: SubIdx::from(e.sub_index.unwrap_or(1) as u8),
},
entry_idx: e.entry_idx,
bit_len: e.bit_len as u8,
name: e.name.clone().unwrap_or_default(),
pos: PdoEntryPos::from(i as u8),
Expand Down

0 comments on commit fa554ee

Please sign in to comment.