MemoryImage

Struct MemoryImage 

Source
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

Source

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.

Source

pub fn into_raw(self) -> Vec<u8>

Get the raw bytes (for write_memory_image).

Source

pub fn as_raw(&self) -> &[u8]

Borrow the raw bytes.

Source

pub fn as_raw_mut(&mut self) -> &mut [u8]

Mutably borrow the raw bytes.

Source

pub fn channels(&self) -> ChannelAccess<'_>

Access channel data (read-only).

Source

pub fn channels_mut(&mut self) -> ChannelWriter<'_>

Access channel data (mutable, for writing channels).

Source

pub fn settings(&self) -> SettingsAccess<'_>

Access system settings (read-only raw bytes for unmapped regions).

Source

pub fn settings_mut(&mut self) -> SettingsWriter<'_>

Access system settings (mutable, for writing verified settings).

Source

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).

Source

pub fn aprs(&self) -> AprsAccess<'_>

Access the APRS configuration region (raw bytes).

Source

pub fn dstar(&self) -> DstarAccess<'_>

Access the D-STAR configuration region (raw bytes).

Source

pub fn gps(&self) -> GpsAccess<'_>

Access the GPS configuration region (raw bytes).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> MemoryImage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryImage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more