forked from ethercat-rs/ethercat
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add util function to fetch SDOs of a slave
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::{Error, Master, SdoEntryAddr, SdoEntryInfo, SdoIdx, SdoInfo, SdoPos, SlavePos, SubIdx}; | ||
use std::collections::HashMap; | ||
|
||
type Result<T> = std::result::Result<T, Error>; | ||
|
||
pub fn slave_sdos( | ||
master: &mut Master, | ||
slave_pos: SlavePos, | ||
) -> Result<HashMap<SdoIdx, SdoEntryInfo>> { | ||
let slave = master.get_slave_info(slave_pos)?; | ||
let sdo_positions = (0..slave.sdo_count).into_iter().map(SdoPos::from); | ||
let mut res = HashMap::new(); | ||
for sdo_pos in sdo_positions { | ||
let SdoInfo { | ||
idx, max_sub_idx, .. | ||
} = master.get_sdo(slave_pos, sdo_pos)?; | ||
let sdo_idxs = (0..u8::from(max_sub_idx)) | ||
.map(SubIdx::from) | ||
.map(|sub_idx| SdoIdx { idx, sub_idx }); | ||
for sdo_idx in sdo_idxs { | ||
let entry = master.get_sdo_entry(slave_pos, SdoEntryAddr::ByIdx(sdo_idx))?; | ||
res.insert(sdo_idx, entry); | ||
} | ||
} | ||
Ok(res) | ||
} |