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>
impl<const MSG_MAX: usize> Decoder<MSG_MAX>
pub fn new() -> Self
Sourcepub fn with_message(self, message_str: &str, edit_pos_end: bool) -> Self
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.
Sourcepub fn with_edit_position(self, pos: usize) -> Self
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.
Sourcepub fn with_precision(self, precision: Precision) -> Self
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.
Sourcepub fn with_character_set(self, character_set: CharacterSet) -> Self
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.
Sourcepub fn with_morse_code_set(self, morse_code_set: MorseCodeSet) -> Self
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.
Sourcepub fn with_signal_tolerance(self, signal_tolerance: f32) -> Self
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.
Sourcepub fn with_reference_short_ms(self, reference_short_ms: u16) -> Self
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’.
Sourcepub fn with_message_pos_clamping(self) -> Self
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);
Sourcepub fn build(self) -> MorseDecoder<MSG_MAX>
pub fn build(self) -> MorseDecoder<MSG_MAX>
Build and get yourself a shiny new MorseDecoder.
The ring is yours now…