morse_codec::decoder

Struct Decoder

Source
pub struct Decoder<const MSG_MAX: usize> { /* private fields */ }
Expand description

This is the builder, or public interface of the decoder using builder pattern. It builds a MorseDecoder which is the concrete implementation and returns it with build(). For details on how to use the decoder, refer to MorseDecoder documentation.

Implementations§

Source§

impl<const MSG_MAX: usize> Decoder<MSG_MAX>

Source

pub fn new() -> Self

Source

pub fn with_message(self, message_str: &str, edit_pos_end: bool) -> Self

Build decoder with a starting message.

edit_pos_end means we’ll continue decoding from the end of this string. If you pass false to it, we’ll start from the beginning.

Source

pub fn with_edit_position(self, pos: usize) -> Self

Build decoder with an arbitrary editing start position.

Maybe client code saved the previous editing position to an EEPROM, harddisk, local storage in web and wants to continue from that.

Source

pub fn with_precision(self, precision: Precision) -> Self

Set decoder precision.

  • Precision::Lazy is more human friendly,
  • Precision::Accurate is for learning or a challenge - contest.
  • Precision::Farnsworth means extra delays will be added to spaces between characters and words but intracharacter speed is not affected. Difference between current decoding speed and a reduced decoding speed will determine the length of the delays. The reduced decoding speed is determined by the factor value passed to the enum variant Farnsworth. This value will be multiplied by the current speed to find a reduction in overall speed. Factor value will be clamped between 0.01 and 0.99.

As an example for Farnsworth precision, let’s say client code wants a reduction to half the current speed:

let decoder = Decoder::new().with_precision(Precision::Farnsworth(0.5)).build();
// At this point if our words per minute speed is 20,
// overall transmission speed will be reduced to 10 WPM
// preserving the character speed at 20 WPM but distributing
// the difference in time among spaces between chars and words.
Source

pub fn with_character_set(self, character_set: CharacterSet) -> Self

Use a different character set than default english alphabet.

This can be helpful to create a message with trivial encryption. Letters can be shuffled for example. With utf-8 feature flag, a somewhat stronger encryption can be used. These kind of encryptions can easily be broken with powerful algorithms and AI. DON’T use it for secure communication.

Source

pub fn with_morse_code_set(self, morse_code_set: MorseCodeSet) -> Self

Use a different morse code set than the default.

It’s mainly useful for a custom morse code set with utf8 character sets. Different alphabets have different corresponding morse code sets.

Source

pub fn with_signal_tolerance(self, signal_tolerance: f32) -> Self

Use a different signal tolerance range factor than the default 0.5.

Tolerance factors higher than 0.5 tend to overlap and result in wrong decoding. You can lower this value though for stricter morse signalling. In any case the value will be clamped between 0.0 and 1.0 so values higher than 1.0 will be 1.0.

Source

pub fn with_reference_short_ms(self, reference_short_ms: u16) -> Self

Change initial reference short signal duration from 0 to some other value.

This value will determine the reference durations of signal types (short, long or very long). The value will be multiplied by LONG_SIGNAL_MULTIPLIER (x3) and WORD_SPACE_MULTIPLIER (x7) to determine long signals and very long word separator signals. Default value of 0 means MorseDecoder will try to calculate the reference short duration from incoming signals. This might not work well if the message starts with a ‘T’.

Source

pub fn with_message_pos_clamping(self) -> Self

Change the wrapping behaviour of message position to clamping.

This will prevent the position cycling back to 0 when overflows or jumping forward to max when falls below 0. Effectively limiting the position to move within the message length from 0 to message length maximum without jumps.

If at one point you want to change it back to wrapping:

decoder.message.set_edit_position_clamp(false);
Source

pub fn build(self) -> MorseDecoder<MSG_MAX>

Build and get yourself a shiny new MorseDecoder.

The ring is yours now…

Trait Implementations§

Source§

impl<const MSG_MAX: usize> Default for Decoder<MSG_MAX>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const MSG_MAX: usize> Freeze for Decoder<MSG_MAX>

§

impl<const MSG_MAX: usize> RefUnwindSafe for Decoder<MSG_MAX>

§

impl<const MSG_MAX: usize> Send for Decoder<MSG_MAX>

§

impl<const MSG_MAX: usize> Sync for Decoder<MSG_MAX>

§

impl<const MSG_MAX: usize> Unpin for Decoder<MSG_MAX>

§

impl<const MSG_MAX: usize> UnwindSafe for Decoder<MSG_MAX>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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