Home Reference Source
import MorseDecoder from 'morse-pro/src/morse-pro-decoder.js'
public class | source

MorseDecoder

Direct Subclass:

MorseAdaptiveDecoder

Class to convert from timings to Morse code.

Example:

// The messageCallback is called when a character or more is decoded
// It receives a dictionary of the timings, morse, and the message
var messageCallback = function(data) {
    console.log("Decoded: {\n  timings: " + data.timings + "\n  morse: " + data.morse + "\n  message: " + data.message + "\n}");
}
var decoder = new MorseDecoder(10);
decoder.messageCallback = messageCallback;
var t;
while (decoder_is_operating) {
    // get some timing "t" from a sensor, make it +ve for noise and -ve for silence
    decoder.addTiming(t);
}
decoder.flush();  // make sure all the data is pushed through the decoder

Constructor Summary

Public Constructor
public

constructor(wpm: number, fwpm: number, messageCallback: function(), speedCallback: function())

Member Summary

Public Members
public

characters: *[]

public get

Get the millisecond timings of all durations determined to be dah-spaces

public get

dahs: number[]: *

Get the millisecond timings of all durations determined to be dahs

public

defaults: {"wpm": number, "fwpm": number}

public get

ditLen: *

public set

ditLen(dit: number)

Set the length of a dit the decoder will look for.

public get

Get the millisecond timings of all durations determined to be dit-spaces

public get

dits: number[]: *

Get the millisecond timings of all durations determined to be dits

public get

fditLen: *

public set

fditLen(dit: number)

Set the length of a Farnsworth dit the decoder will look for.

public get

fwpm: *

public set

fwpm(fwpm: number)

Should be set to the Farnsworth WPM speed of the input sound.

public
public
public
public get

spaces: number[]: *

Get the millisecond timings of all durations determined to be spaces

public

timings: *[]

public
public get

wpm: *

public set

wpm(wpm: number)

Should be set to the WPM speed of the input sound.

Private Members
private
private
private

_ditLen: *

private
private

_fwpm: *

private

_wpm: *

Method Summary

Public Methods
public

addTiming(duration: number)

Add a timing in ms to the list of recorded timings.

public

flush()

Process the buffer of unused timings, converting them into Morse and converting the generated Morse into a message.

public

messageCallback(jsonData: *)

public

speedCallback(jsonData: *)

Private Methods
private

addDecode(duration: number, character: string)

Store the timing and the corresponding decoded character element.

private

getTimings(character: *): *

private

Convert from millisecond timings to dots and dashes.

private

Public Constructors

public constructor(wpm: number, fwpm: number, messageCallback: function(), speedCallback: function()) source

Params:

NameTypeAttributeDescription
wpm number
  • optional
  • default: 20

The speed of the Morse in words per minute.

fwpm number
  • optional
  • default: wpm

The Farnsworth speed of the Morse in words per minute.

messageCallback function()

Callback executed with {message: string, timings: number[], morse: string} when decoder buffer is flushed (every character).

speedCallback function()

Callback executed with {wpm: number, fwpm: number} if the wpm or fwpm speed changes. The speed in this class doesn't change by itself, but e.g. the fwpm can change if wpm is changed. Returned dictionary has keys 'fwpm' and 'wpm'.

Public Members

public characters: *[] source

public get dahSpaces: number[]: * source

Get the millisecond timings of all durations determined to be dah-spaces

Return:

number[]

public get dahs: number[]: * source

Get the millisecond timings of all durations determined to be dahs

Return:

number[]

public defaults: {"wpm": number, "fwpm": number} source

public get ditLen: * source

public set ditLen(dit: number) source

Set the length of a dit the decoder will look for. The private _wpm, _fwpm, and _fditLen variables are also updated.

public get ditSpaces: number[]: * source

Get the millisecond timings of all durations determined to be dit-spaces

Return:

number[]

public get dits: number[]: * source

Get the millisecond timings of all durations determined to be dits

Return:

number[]

public get fditLen: * source

public set fditLen(dit: number) source

Set the length of a Farnsworth dit the decoder will look for. The private _wpm, _fwpm, and _ditLen variables are also updated.

public get fwpm: * source

public set fwpm(fwpm: number) source

Should be set to the Farnsworth WPM speed of the input sound. The input data is validated and this.defaults.fwpm will be used if there is an error in input. The private _wpm, _ditLen and _fditLen variables are also updated and the speedCallback is executed.

public message: string source

public morse: string source

public noiseThreshold: number source

public get spaces: number[]: * source

Get the millisecond timings of all durations determined to be spaces

Return:

number[]

public timings: *[] source

public unusedTimes: *[] source

public get wpm: * source

public set wpm(wpm: number) source

Should be set to the WPM speed of the input sound. The input data is validated and this.defaults.wpm will be used if there is an error in input. The private _fwpm, _ditLen and _fditLen variables are also updated and the speedCallback is executed.

Private Members

private _dahSpaceThreshold: * source

private _ditDahThreshold: * source

private _ditLen: * source

private _fditLen: * source

private _fwpm: * source

private _wpm: * source

Public Methods

public addTiming(duration: number) source

Add a timing in ms to the list of recorded timings. The duration should be positive for a dit or dah and negative for a space. If the duration is <= noiseThreshold it is assumed to be noise and is added to the previous duration. If a duration is the same sign as the previous one then they are combined.

Params:

NameTypeAttributeDescription
duration number

millisecond duration to add, positive for a dit or dah, negative for a space

public flush() source

Process the buffer of unused timings, converting them into Morse and converting the generated Morse into a message. Should be called only when a character space has been reached (or the message is at an end). Will call the messageCallback with the latest timings, morse (dots and dashes) and message.

public messageCallback(jsonData: *) source

Params:

NameTypeAttributeDescription
jsonData *

public speedCallback(jsonData: *) source

Params:

NameTypeAttributeDescription
jsonData *

Private Methods

private addDecode(duration: number, character: string) source

Store the timing and the corresponding decoded character element.

Params:

NameTypeAttributeDescription
duration number

the millisecond duration (always +ve).

character string

the corresponding character element [.-/ ].

private getTimings(character: *): * source

Params:

NameTypeAttributeDescription
character *

Return:

*

private timings2morse(times: number[]): string source

Convert from millisecond timings to dots and dashes.

Params:

NameTypeAttributeDescription
times number[]

array of millisecond timings, +ve numbers representing a signal, -ve representing a space.

Return:

string

the dots and dashes as a string.

private updateThresholds() source