pub struct ConversionBlock {Show 18 fields
pub header: BlockHeader,
pub name_addr: Option<u64>,
pub unit_addr: Option<u64>,
pub comment_addr: Option<u64>,
pub inverse_addr: Option<u64>,
pub refs: Vec<u64>,
pub conversion_type: ConversionType,
pub precision: u8,
pub flags: u16,
pub ref_count: u16,
pub value_count: u16,
pub phys_range_min: Option<f64>,
pub phys_range_max: Option<f64>,
pub values: Vec<f64>,
pub formula: Option<String>,
pub resolved_texts: Option<BTreeMap<usize, String>>,
pub resolved_conversions: Option<BTreeMap<usize, Box<ConversionBlock>>>,
pub default_conversion: Option<Box<ConversionBlock>>,
}Fields§
§header: BlockHeader§name_addr: Option<u64>§unit_addr: Option<u64>§comment_addr: Option<u64>§inverse_addr: Option<u64>§refs: Vec<u64>§conversion_type: ConversionType§precision: u8§flags: u16§ref_count: u16§value_count: u16§phys_range_min: Option<f64>§phys_range_max: Option<f64>§values: Vec<f64>§formula: Option<String>§resolved_texts: Option<BTreeMap<usize, String>>Pre-resolved text strings for text-based conversions (ValueToText, RangeToText, etc.) Maps refs indices to their resolved text content
resolved_conversions: Option<BTreeMap<usize, Box<ConversionBlock>>>Pre-resolved nested conversion blocks for chained conversions Maps refs indices to their resolved ConversionBlock content
default_conversion: Option<Box<ConversionBlock>>Default conversion for fallback cases (similar to asammdf’s “default_addr”) This is typically the last reference in refs for some conversion types
Implementations§
Source§impl ConversionBlock
impl ConversionBlock
Sourcepub fn resolve_all_dependencies(&mut self, file_data: &[u8]) -> Result<()>
pub fn resolve_all_dependencies(&mut self, file_data: &[u8]) -> Result<()>
Resolve all dependencies for this conversion block to make it self-contained. This reads referenced text blocks and nested conversions from the file data and stores them in the resolved_texts and resolved_conversions fields.
Supports arbitrary depth conversion chains with cycle detection.
§Arguments
file_data- Memory mapped MDF bytes used to read referenced data
§Returns
Ok(()) on success or an Error if resolution fails
Sourcepub fn resolve_all_dependencies_with_address(
&mut self,
file_data: &[u8],
current_address: u64,
) -> Result<()>
pub fn resolve_all_dependencies_with_address( &mut self, file_data: &[u8], current_address: u64, ) -> Result<()>
Resolve all dependencies with a known current block address (used internally)
Sourcepub fn get_resolved_text(&self, ref_index: usize) -> Option<&String>
pub fn get_resolved_text(&self, ref_index: usize) -> Option<&String>
Get a resolved text string for a given refs index. Returns the text if it was resolved during dependency resolution.
Sourcepub fn get_resolved_conversion(
&self,
ref_index: usize,
) -> Option<&ConversionBlock>
pub fn get_resolved_conversion( &self, ref_index: usize, ) -> Option<&ConversionBlock>
Get a resolved nested conversion for a given refs index. Returns the conversion block if it was resolved during dependency resolution.
Sourcepub fn get_default_conversion(&self) -> Option<&ConversionBlock>
pub fn get_default_conversion(&self) -> Option<&ConversionBlock>
Get the default conversion for fallback cases. Returns the default conversion if it was resolved during dependency resolution.
Sourcepub fn identity() -> Self
pub fn identity() -> Self
Creates an identity conversion (1:1, no change).
This is useful when you want to explicitly indicate that no conversion is applied, while still having a conversion block for consistency.
§Example
use mdf4_rs::blocks::ConversionBlock;
let conv = ConversionBlock::identity();Sourcepub fn linear(offset: f64, factor: f64) -> Self
pub fn linear(offset: f64, factor: f64) -> Self
Creates a linear conversion: physical = offset + factor * raw.
This is the most common conversion type, used for scaling and offset
adjustments. The MDF 4.1 specification defines linear conversion as:
y = P1 + P2 * x where P1 is the offset and P2 is the factor.
§Arguments
offset- The offset value (P1 in the MDF spec)factor- The scaling factor (P2 in the MDF spec)
§Example
use mdf4_rs::blocks::ConversionBlock;
// Convert raw temperature: physical = -40.0 + 0.1 * raw
let temp_conv = ConversionBlock::linear(-40.0, 0.1);
// Convert RPM: physical = 0.0 + 0.25 * raw
let rpm_conv = ConversionBlock::linear(0.0, 0.25);Sourcepub fn rational(p1: f64, p2: f64, p3: f64, p4: f64, p5: f64, p6: f64) -> Self
pub fn rational(p1: f64, p2: f64, p3: f64, p4: f64, p5: f64, p6: f64) -> Self
Creates a rational conversion: physical = (P1 + P2*x + P3*x²) / (P4 + P5*x + P6*x²).
Rational conversions are used for more complex non-linear transformations.
§Arguments
p1- Numerator constant termp2- Numerator linear coefficientp3- Numerator quadratic coefficientp4- Denominator constant termp5- Denominator linear coefficientp6- Denominator quadratic coefficient
§Example
use mdf4_rs::blocks::ConversionBlock;
// Simple linear via rational: physical = (0 + 2*x + 0*x²) / (1 + 0*x + 0*x²) = 2*x
let conv = ConversionBlock::rational(0.0, 2.0, 0.0, 1.0, 0.0, 0.0);Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Check if this is a trivial identity conversion that can be omitted.
Returns true if:
- The conversion type is Identity, OR
- The conversion type is Linear with offset=0 and factor=1
Sourcepub fn with_physical_range(self, min: f64, max: f64) -> Self
pub fn with_physical_range(self, min: f64, max: f64) -> Self
Set the physical range limits for this conversion.
§Arguments
min- Minimum physical valuemax- Maximum physical value
Source§impl ConversionBlock
impl ConversionBlock
Sourcepub fn resolve_formula(&mut self, file_data: &[u8]) -> Result<()>
pub fn resolve_formula(&mut self, file_data: &[u8]) -> Result<()>
Resolve and store the algebraic formula referenced by this block.
§Arguments
file_data- Memory mapped MDF bytes used to read the formula text.
§Returns
Ok(()) on success or an crate::Error if the formula block cannot be
read.
Source§impl ConversionBlock
impl ConversionBlock
Sourcepub fn apply_decoded(
&self,
value: DecodedValue,
file_data: &[u8],
) -> Result<DecodedValue>
pub fn apply_decoded( &self, value: DecodedValue, file_data: &[u8], ) -> Result<DecodedValue>
Applies the conversion formula to a decoded channel value.
Depending on the conversion type, this method either returns a numeric value (wrapped as DecodedValue::Float) or a character string (wrapped as DecodedValue::String). For non-numeric conversions such as Algebraic or Table look-ups, placeholder implementations are provided and can be extended later.
§Parameters
value: The already-decoded channel value (as DecodedValue).
§Returns
A DecodedValue where numeric conversion types yield a Float and string conversion types yield a String.
Trait Implementations§
Source§impl BlockParse<'_> for ConversionBlock
impl BlockParse<'_> for ConversionBlock
const ID: &'static str = "##CC"
fn from_bytes(bytes: &[u8]) -> Result<Self>
fn parse_header(bytes: &[u8]) -> Result<BlockHeader>
Source§impl Clone for ConversionBlock
impl Clone for ConversionBlock
Source§fn clone(&self) -> ConversionBlock
fn clone(&self) -> ConversionBlock
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more