pub struct DataStore { /* private fields */ }Expand description
A unified data store that maps (area, db_number, offset) -> u8.
Supports:
- Arbitrary area codes (PI / PA / MK / DB / TI / CT / …)
- Per-area registration (
register_area/unregister_area) - CPU run-state (
cpu_state/set_cpu_state) - Read / write event callbacks
Implementations§
Source§impl DataStore
impl DataStore
Sourcepub fn register_area(&self, area_code: u8, size: usize)
pub fn register_area(&self, area_code: u8, size: usize)
Register a memory area. size is a hint; reads beyond written bytes
return zeros.
Sourcepub fn unregister_area(&self, area_code: u8)
pub fn unregister_area(&self, area_code: u8)
Unregister a previously registered area.
Sourcepub fn is_area_registered(&self, area_code: u8) -> bool
pub fn is_area_registered(&self, area_code: u8) -> bool
Check whether an area is registered.
Sourcepub fn registered_areas(&self) -> Vec<u8> ⓘ
pub fn registered_areas(&self) -> Vec<u8> ⓘ
Return the set of registered area codes.
Sourcepub fn lock_area(&self, area_code: u8)
pub fn lock_area(&self, area_code: u8)
Lock an area: subsequent write_area calls to this area return without modifying data (silently skipped, matching C snap7 Srv_LockArea behaviour).
Sourcepub fn unlock_area(&self, area_code: u8)
pub fn unlock_area(&self, area_code: u8)
Unlock an area previously locked with lock_area.
Sourcepub fn is_area_locked(&self, area_code: u8) -> bool
pub fn is_area_locked(&self, area_code: u8) -> bool
Return whether an area is currently locked.
Sourcepub fn get_status(&self) -> ServerStatus
pub fn get_status(&self) -> ServerStatus
Return current server/CPU status and connected client count.
Sourcepub fn set_mask(&self, mask: u32)
pub fn set_mask(&self, mask: u32)
Set the event filter mask. Only events whose kind-bit is set are enqueued.
Sourcepub fn clear_events(&self)
pub fn clear_events(&self)
Drain the event queue.
Sourcepub fn pick_event(&self) -> Option<EventInfo>
pub fn pick_event(&self) -> Option<EventInfo>
Pop the oldest event from the queue. Returns None when empty.
Sourcepub fn set_cpu_state(&self, state: CpuState)
pub fn set_cpu_state(&self, state: CpuState)
Set the simulated CPU state and fire event_callbacks.
Sourcepub fn get_clock(&self) -> [u8; 8]
pub fn get_clock(&self) -> [u8; 8]
Return the simulated RTC as 8 BCD bytes (S7 DATE_AND_TIME format).
Sourcepub fn set_clock(&self, bytes: [u8; 8])
pub fn set_clock(&self, bytes: [u8; 8])
Set the simulated RTC from 8 BCD bytes (S7 DATE_AND_TIME format).
Sourcepub fn read_bytes(&self, db: u16, start: u32, count: u32) -> Vec<u8> ⓘ
pub fn read_bytes(&self, db: u16, start: u32, count: u32) -> Vec<u8> ⓘ
Read a contiguous range of bytes.
Sourcepub fn read_area(&self, area: u8, db: u16, start: u32, count: u32) -> Vec<u8> ⓘ
pub fn read_area(&self, area: u8, db: u16, start: u32, count: u32) -> Vec<u8> ⓘ
Read from an arbitrary area.
Sourcepub fn write_area(&self, area: u8, db: u16, start: u32, data: &[u8])
pub fn write_area(&self, area: u8, db: u16, start: u32, data: &[u8])
Write to an arbitrary area.
Silently no-ops if the area is currently locked via lock_area.
Sourcepub fn write_bytes(&self, db: u16, start: u32, data: &[u8])
pub fn write_bytes(&self, db: u16, start: u32, data: &[u8])
Write to DB area (convenience, retained for backward compat).