pub trait ObjectAccess: Sync + Send {
Show 22 methods
// Required methods
fn read(
&self,
sub: u8,
offset: usize,
buf: &mut [u8],
) -> Result<usize, AbortCode>;
fn read_size(&self, sub: u8) -> Result<usize, AbortCode>;
fn write(&self, sub: u8, data: &[u8]) -> Result<(), AbortCode>;
fn object_code(&self) -> ObjectCode;
fn sub_info(&self, sub: u8) -> Result<SubInfo, AbortCode>;
// Provided methods
fn begin_partial(&self, sub: u8) -> Result<(), AbortCode> { ... }
fn write_partial(&self, _sub: u8, _buf: &[u8]) -> Result<(), AbortCode> { ... }
fn end_partial(&self, _sub: u8) -> Result<(), AbortCode> { ... }
fn max_sub_number(&self) -> u8 { ... }
fn set_event_flag(&self, _sub: u8) -> Result<(), AbortCode> { ... }
fn read_event_flag(&self, _sub: u8) -> bool { ... }
fn clear_events(&self) { ... }
fn access_type(&self, sub: u8) -> Result<AccessType, AbortCode> { ... }
fn data_type(&self, sub: u8) -> Result<DataType, AbortCode> { ... }
fn size(&self, sub: u8) -> Result<usize, AbortCode> { ... }
fn current_size(&self, sub: u8) -> Result<usize, AbortCode> { ... }
fn read_u32(&self, sub: u8) -> Result<u32, AbortCode> { ... }
fn read_u16(&self, sub: u8) -> Result<u16, AbortCode> { ... }
fn read_u8(&self, sub: u8) -> Result<u8, AbortCode> { ... }
fn read_i32(&self, sub: u8) -> Result<i32, AbortCode> { ... }
fn read_i16(&self, sub: u8) -> Result<i16, AbortCode> { ... }
fn read_i8(&self, sub: u8) -> Result<i8, AbortCode> { ... }
}Expand description
A trait for accessing objects
Any struct which implements an object in the object dictionary must implement this trait
Required Methods§
Sourcefn read(
&self,
sub: u8,
offset: usize,
buf: &mut [u8],
) -> Result<usize, AbortCode>
fn read( &self, sub: u8, offset: usize, buf: &mut [u8], ) -> Result<usize, AbortCode>
Read raw bytes from a subobject
If the specified read goes out of range (i.e. offset + buf.len() > current_size) an error is returned. All implementers are required to allow reading a subset of the object bytes, i.e. offset may be non-zero, and/or the buf length may be shorter than the object data
Sourcefn read_size(&self, sub: u8) -> Result<usize, AbortCode>
fn read_size(&self, sub: u8) -> Result<usize, AbortCode>
Get the number of bytes available for a read
Sourcefn write(&self, sub: u8, data: &[u8]) -> Result<(), AbortCode>
fn write(&self, sub: u8, data: &[u8]) -> Result<(), AbortCode>
Write raw bytes to a subobject
The length of data must match the size of the object, or else it will fail with either
AbortCode::DataTypeMismatchLengthLow or AbortCode::DataTypeMismatchLengthHigh.
If the sub is does not exist, it shall fail with AbortCode::NoSuchSubIndex.
If the sub exists but is not writeable, it shall fail with AbortCode::ReadOnly.
Sourcefn object_code(&self) -> ObjectCode
fn object_code(&self) -> ObjectCode
Get the type of this object
Provided Methods§
Sourcefn begin_partial(&self, sub: u8) -> Result<(), AbortCode>
fn begin_partial(&self, sub: u8) -> Result<(), AbortCode>
Initialize a new partial write
This must be called before performing calls to partial_write.
A default implementation is provided which returns an appropriate error:
AbortCode::NoSuchSubIndexif the sub object does not existAbortCode::ReadOnlyif the sub object is read-onlyAbortCode::UnsupportedAccessif the sub object does not support partial writes
Objects which support partial writing must override the default implementation.
Sourcefn write_partial(&self, _sub: u8, _buf: &[u8]) -> Result<(), AbortCode>
fn write_partial(&self, _sub: u8, _buf: &[u8]) -> Result<(), AbortCode>
Perform a partial write of bytes to a subobject
Most objects do not support partial writes. But in some cases, such as DOMAINs, or very large string objects, it is unavoidable and these must support it.
Partial writes MUST be done sequentially, and implementers may assume that this is the case. Executing multiple concurrent partial writes to the same sub object is not supported. It is up to the application to ensure that this is not done.
Sourcefn end_partial(&self, _sub: u8) -> Result<(), AbortCode>
fn end_partial(&self, _sub: u8) -> Result<(), AbortCode>
Finalize a previous partial write
This must always be called after using partial_write, after all partial_write calls have been completed.
Sourcefn max_sub_number(&self) -> u8
fn max_sub_number(&self) -> u8
Get the highest sub index available in this object
Sourcefn set_event_flag(&self, _sub: u8) -> Result<(), AbortCode>
fn set_event_flag(&self, _sub: u8) -> Result<(), AbortCode>
Set an event flag for the specified sub object on this object
Event flags are used for triggering PDOs. This is optional, as not all objects support PDOs or PDO triggering.
Sourcefn read_event_flag(&self, _sub: u8) -> bool
fn read_event_flag(&self, _sub: u8) -> bool
Read an event flag for the specified sub object
This is optional as not all objects support events
Sourcefn clear_events(&self)
fn clear_events(&self)
Clear event flags for all sub objects
This is optional as not all objects support events
Sourcefn access_type(&self, sub: u8) -> Result<AccessType, AbortCode>
fn access_type(&self, sub: u8) -> Result<AccessType, AbortCode>
Get the access type of a specific sub object
Sourcefn data_type(&self, sub: u8) -> Result<DataType, AbortCode>
fn data_type(&self, sub: u8) -> Result<DataType, AbortCode>
Get the data type of a specific sub object
Sourcefn size(&self, sub: u8) -> Result<usize, AbortCode>
fn size(&self, sub: u8) -> Result<usize, AbortCode>
Get the maximum size of an sub object
For most sub objects, this matches the current_size, but for strings the size of the
currently stored value (returned by current_size()) may be smaller.
Sourcefn current_size(&self, sub: u8) -> Result<usize, AbortCode>
fn current_size(&self, sub: u8) -> Result<usize, AbortCode>
Get the current size of a sub object
Note that this is not necessarily the allocated size of the object, as some objects (such as strings) may have values shorter than their maximum size. As such, this gives the maximum number of bytes which may be read, but not necessarily the number of bytes which may be written.