MorseDecoder
Direct Subclass:
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 |
Get the millisecond timings of all durations determined to be dahs |
|
public |
|
|
public get |
ditLen: * |
|
public set |
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 |
Get the millisecond timings of all durations determined to be dits |
|
public get |
fditLen: * |
|
public set |
Set the length of a Farnsworth dit the decoder will look for. |
|
public get |
fwpm: * |
|
public set |
Should be set to the Farnsworth WPM speed of the input sound. |
|
public |
|
|
public |
|
|
public |
|
|
public get |
Get the millisecond timings of all durations determined to be spaces |
|
public |
timings: *[] |
|
public |
unusedTimes: *[] |
|
public get |
wpm: * |
|
public set |
Should be set to the WPM speed of the input sound. |
Private Members | ||
private |
|
|
private |
|
|
private |
_ditLen: * |
|
private |
_fditLen: * |
|
private |
_fwpm: * |
|
private |
_wpm: * |
Method Summary
Public Methods | ||
public |
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 |
Store the timing and the corresponding decoded character element. |
|
private |
getTimings(character: *): * |
|
private |
timings2morse(times: number[]): string Convert from millisecond timings to dots and dashes. |
|
private |
|
Public Constructors
public constructor(wpm: number, fwpm: number, messageCallback: function(), speedCallback: function()) source
Params:
Name | Type | Attribute | Description |
wpm | number |
|
The speed of the Morse in words per minute. |
fwpm | number |
|
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
public get dahs: number[]: * source
Get the millisecond timings of all durations determined to be dahs
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
public get dits: number[]: * source
Get the millisecond timings of all durations determined to be dits
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 get spaces: number[]: * source
Get the millisecond timings of all durations determined to be spaces
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
jsonData | * |
public speedCallback(jsonData: *) source
Params:
Name | Type | Attribute | Description |
jsonData | * |
Private Methods
private addDecode(duration: number, character: string) source
Store the timing and the corresponding decoded character element.
private getTimings(character: *): * source
Params:
Name | Type | Attribute | Description |
character | * |
Return:
* |
private timings2morse(times: number[]): string source
Convert from millisecond timings to dots and dashes.
Params:
Name | Type | Attribute | Description |
times | number[] | array of millisecond timings, +ve numbers representing a signal, -ve representing a space. |