Description
The Data Storage Unit is the fundamental memory component for storing binary data within the simulation. It provides a byte-level storage container with pointer-based access, enabling spacecraft systems to store, retrieve, and delete data during operations. The unit models realistic onboard memory with capacity constraints, data persistence across simulation saves, and bit-flip error injection for radiation environment studies.
Example Use Cases
- Science Data Storage: Buffer instrument observations before downlink to ground stations.
- Command Sequence Storage: Store uplinked command sequences for later execution.
- Telemetry Recording: Log housekeeping data for playback during ground contacts.
- Radiation Effects Analysis: Simulate single-event upsets (SEUs) using bit-flip injection.
- Memory Management Studies: Evaluate storage allocation strategies and fragmentation effects.
Module Implementation
The data storage unit operates as a contiguous byte buffer with indexed pointer access. Data is written sequentially, and each write operation returns a pointer that can be used for subsequent read or delete operations.
Storage Architecture
The unit maintains two primary data structures:
- Data Buffer: A contiguous list of bytes containing all stored data
- Pointer Index: A sorted mapping from pointer identifiers to byte offsets
where each pointer maps to the starting byte offset of its associated data chunk.
Capacity and Allocation
The unit has a fixed capacity defining the maximum number of bytes that can be stored:
The default capacity is 1 megabyte (1,048,576 bytes). The current allocation is tracked dynamically as data is written and deleted.
Write Operations
Writing data appends bytes to the end of the buffer and creates a new pointer entry:
where is the byte array to store. The operation:
- Validates sufficient capacity:
- Checks the unit is not locked
- Creates a new pointer index entry
- Appends data to the buffer
- Returns a
DataPointercontaining the pointer ID and data size
If the write fails (insufficient capacity, locked, or empty data), an invalid pointer is returned.
The returned DataPointer structure contains:
| Field | Description |
|---|---|
Pointer | Unique identifier for this data chunk |
Size | Number of bytes in the chunk |
IsValid | Flag indicating the pointer is usable |
Read Operations
Reading retrieves a copy of the stored data without modifying the buffer:
The operation:
- Validates the pointer exists and is valid
- Retrieves the byte offset from the pointer index
- Bounds-checks the read range
- Returns a copy of the requested bytes
If any validation fails, an empty byte array is returned.
Delete Operations
Deleting removes data from the buffer and updates all affected pointer offsets:
The deletion process:
- Validates the pointer and checks the unit is not locked
- Removes the bytes from the buffer at the specified offset
- Updates all pointers with offsets greater than the deleted region:
- Removes any pointers whose data was entirely within the deleted region
This maintains pointer validity for all remaining data chunks after deletion.
Clear All Data
The DeleteAll operation removes all stored data and resets the unit:
This clears the data buffer, removes all pointers, and resets the index counter. The operation fails if the unit is locked.
Locking Mechanism
The unit can be locked to prevent modifications:
When locked:
- Write operations return invalid pointers
- Delete operations return false
- Read operations remain functional
This enables write-protection for critical data or during sensitive operations.
Bit-Flip Error Injection
The FlipBits method simulates radiation-induced single-event upsets by probabilistically flipping bits in stored data:
For each byte in the allocated region, a random test determines if a bit flip occurs. If triggered, a random bit position is selected and inverted:
The default probability is per byte, representing a low radiation environment. Higher values can model more severe radiation conditions or longer exposure times.
Data Persistence
The data storage unit supports save and load operations for simulation state persistence:
Save: Data is encoded to hexadecimal string format, and pointer mappings are serialized to JSON:
Load: The reverse process decodes the hexadecimal data and reconstructs the pointer index:
This enables simulation checkpointing and restart with preserved memory state.
Chunk Tracking
The unit tracks the number of discrete data chunks (write operations) stored:
This provides insight into memory fragmentation and allocation patterns.
Assumptions/Limitations
- Data is stored contiguously; fragmentation from deletions is not compacted automatically.
- Pointer indices are monotonically increasing; deleted pointer IDs are not reused.
- The bit-flip operation affects all allocated data uniformly; location-dependent susceptibility is not modelled.
- Write operations append to the end of the buffer; random-access writes are not supported.
- The unit does not model read/write timing delays; all operations are instantaneous.
- Memory wear-out effects (e.g., flash memory write cycles) are not simulated.
- The locking mechanism is binary; granular access control is not available.
- Pointer validity is not automatically checked after bit-flip operations; corrupted pointers may cause read failures.
- The maximum capacity is limited by integer indexing (approximately 2 GB).