pub struct MemoryImage { /* private fields */ }Expand description
A parsed TH-D75 memory image providing typed access to all settings.
The image is exactly programming::TOTAL_SIZE bytes (500,480).
Create one from a raw MCP dump, or from a .d75 file via
from_d75_file.
§Examples
use kenwood_thd75::memory::MemoryImage;
let image = MemoryImage::from_raw(raw)?;
// Read channel 0.
let channels = image.channels();
if channels.is_used(0) {
if let Some(entry) = channels.get(0) {
println!("Ch 0: {} — {} Hz", entry.name, entry.flash.rx_frequency.as_hz());
}
}
// Get the raw bytes back for writing.
let bytes = image.into_raw();Implementations§
Source§impl MemoryImage
impl MemoryImage
Sourcepub fn from_raw(data: Vec<u8>) -> Result<Self, MemoryError>
pub fn from_raw(data: Vec<u8>) -> Result<Self, MemoryError>
Create from a raw memory dump (from read_memory_image or .d75
file body).
§Errors
Returns MemoryError::InvalidSize if the data is not exactly
500,480 bytes.
Sourcepub fn as_raw_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_raw_mut(&mut self) -> &mut [u8] ⓘ
Mutably borrow the raw bytes.
Sourcepub fn channels(&self) -> ChannelAccess<'_>
pub fn channels(&self) -> ChannelAccess<'_>
Access channel data (read-only).
Sourcepub fn channels_mut(&mut self) -> ChannelWriter<'_>
pub fn channels_mut(&mut self) -> ChannelWriter<'_>
Access channel data (mutable, for writing channels).
Sourcepub fn settings(&self) -> SettingsAccess<'_>
pub fn settings(&self) -> SettingsAccess<'_>
Access system settings (read-only raw bytes for unmapped regions).
Sourcepub fn settings_mut(&mut self) -> SettingsWriter<'_>
pub fn settings_mut(&mut self) -> SettingsWriter<'_>
Access system settings (mutable, for writing verified settings).
Sourcepub fn modify_setting<F>(&mut self, f: F) -> Option<(u16, u8)>where
F: FnOnce(&mut SettingsWriter<'_>),
pub fn modify_setting<F>(&mut self, f: F) -> Option<(u16, u8)>where
F: FnOnce(&mut SettingsWriter<'_>),
Apply a settings mutation and return the changed byte’s MCP offset and new value.
The closure receives a SettingsWriter to modify exactly one setting.
This method snapshots the settings page before the closure, runs it,
then diffs to find the single changed byte. Returns Some((offset, value))
if a byte changed, or None if nothing changed.
§Panics
Panics if more than one byte changed (the closure should modify exactly one setting).
Sourcepub fn aprs(&self) -> AprsAccess<'_>
pub fn aprs(&self) -> AprsAccess<'_>
Access the APRS configuration region (raw bytes).
Sourcepub fn dstar(&self) -> DstarAccess<'_>
pub fn dstar(&self) -> DstarAccess<'_>
Access the D-STAR configuration region (raw bytes).
Sourcepub fn from_d75_file(data: &[u8]) -> Result<Self, MemoryError>
pub fn from_d75_file(data: &[u8]) -> Result<Self, MemoryError>
Create from a .d75 config file (strips the 256-byte header).
The .d75 file format is a 256-byte file header followed by the
raw MCP memory image. This constructor validates the header and
extracts the image body.
§Errors
Returns MemoryError::D75Error if the file is too short or
the header model string is not recognised.
Returns MemoryError::InvalidSize if the body is not the
expected size.
Sourcepub fn to_d75_file(&self, header: &ConfigHeader) -> Vec<u8> ⓘ
pub fn to_d75_file(&self, header: &ConfigHeader) -> Vec<u8> ⓘ
Export as a .d75 config file (prepends header).
Uses the provided ConfigHeader to build the file. The header
is preserved as-is (including model string and version bytes) for
round-trip fidelity.
Sourcepub fn to_d75_bytes(&self) -> Vec<u8> ⓘ
pub fn to_d75_bytes(&self) -> Vec<u8> ⓘ
Export this image as a .d75 file ready to write to the SD card.
Uses a default TH-D75A header with the standard version bytes.
For a specific model or custom header, use to_d75_file.
§Panics
Panics if the built-in model string is rejected, which should never happen since the model is a known constant.
Sourcepub fn read_region(&self, offset: usize, len: usize) -> Option<&[u8]>
pub fn read_region(&self, offset: usize, len: usize) -> Option<&[u8]>
Read a byte range from the image.
Returns None if the range is out of bounds.
Sourcepub fn write_region(
&mut self,
offset: usize,
data: &[u8],
) -> Result<(), MemoryError>
pub fn write_region( &mut self, offset: usize, data: &[u8], ) -> Result<(), MemoryError>
Write bytes into the image at the given offset.
§Errors
Returns MemoryError::InvalidSize if the write extends past
the end of the image.
Trait Implementations§
Source§impl Clone for MemoryImage
impl Clone for MemoryImage
Source§fn clone(&self) -> MemoryImage
fn clone(&self) -> MemoryImage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more