67 if (!
parseMode(mode, a, speed))
return false;
69 if (speed > 0)
wpm = speed;
74 static bool isMode(
const char* mode) {
86 LOGE(
"Morse: the speed must be 1 - 100 wpm");
90 LOGE(
"Morse: invalid frequency %.1f Hz", (
double)
frequency);
94 LOGE(
"Morse: invalid ramp_ms or rx_timeout_units");
103 if (mode ==
nullptr)
return false;
114 if (*rest ==
'-') rest++;
118 if (*rest ==
'-') rest++;
119 }
else if (
startsWith(rest,
"international")) {
121 if (*rest ==
'-') rest++;
123 if (*rest == 0)
return true;
125 speed = strtol(rest, &end, 10);
126 return end != rest && *end == 0 && speed >= 1 && speed <= 100;
129 static bool startsWith(
const char* str,
const char* prefix) {
131 if (tolower(*str++) != *prefix++)
return false;
154 static const Timing international = {1, 3, 3, 3, 1, 1, 3, 7};
155 static const Timing american = {1, 2, 4, 5, 1, 2, 3, 6};
162 ch = toupper((
unsigned char)ch);
164 if (e->ch == ch)
return e->code;
171 if (strcmp(e->code, code) == 0)
return e->ch;
183 static const Entry international[] = {
184 {
'A',
".-"}, {
'B',
"-..."}, {
'C',
"-.-."}, {
'D',
"-.."},
185 {
'E',
"."}, {
'F',
"..-."}, {
'G',
"--."}, {
'H',
"...."},
186 {
'I',
".."}, {
'J',
".---"}, {
'K',
"-.-"}, {
'L',
".-.."},
187 {
'M',
"--"}, {
'N',
"-."}, {
'O',
"---"}, {
'P',
".--."},
188 {
'Q',
"--.-"}, {
'R',
".-."}, {
'S',
"..."}, {
'T',
"-"},
189 {
'U',
"..-"}, {
'V',
"...-"}, {
'W',
".--"}, {
'X',
"-..-"},
190 {
'Y',
"-.--"}, {
'Z',
"--.."}, {
'0',
"-----"}, {
'1',
".----"},
191 {
'2',
"..---"}, {
'3',
"...--"}, {
'4',
"....-"}, {
'5',
"....."},
192 {
'6',
"-...."}, {
'7',
"--..."}, {
'8',
"---.."}, {
'9',
"----."},
193 {
'.',
".-.-.-"}, {
',',
"--..--"}, {
'?',
"..--.."}, {
'\'',
".----."},
194 {
'!',
"-.-.--"}, {
'/',
"-..-."}, {
'(',
"-.--."}, {
')',
"-.--.-"},
195 {
'&',
".-..."}, {
':',
"---..."}, {
';',
"-.-.-."}, {
'=',
"-...-"},
196 {
'+',
".-.-."}, {
'-',
"-....-"}, {
'_',
"..--.-"}, {
'"',
".-..-."},
197 {
'$',
"...-..-"}, {
'@',
".--.-."}, {
'\n',
".-.-"}, {0,
nullptr}};
199 static const Entry american[] = {
200 {
'A',
".-"}, {
'B',
"-..."}, {
'C',
".. ."}, {
'D',
"-.."},
201 {
'E',
"."}, {
'F',
".-."}, {
'G',
"--."}, {
'H',
"...."},
202 {
'I',
".."}, {
'J',
"-.-."}, {
'K',
"-.-"}, {
'L',
"_"},
203 {
'M',
"--"}, {
'N',
"-."}, {
'O',
". ."}, {
'P',
"....."},
204 {
'Q',
"..-."}, {
'R',
". .."}, {
'S',
"..."}, {
'T',
"-"},
205 {
'U',
"..-"}, {
'V',
"...-"}, {
'W',
".--"}, {
'X',
".-.."},
206 {
'Y',
".. .."}, {
'Z',
"... ."}, {
'0',
"="}, {
'1',
".--."},
207 {
'2',
"..-.."}, {
'3',
"...-."}, {
'4',
"....-"}, {
'5',
"---"},
208 {
'6',
"......"}, {
'7',
"--.."}, {
'8',
"-...."}, {
'9',
"-..-"},
209 {
'.',
"..--.."}, {
',',
".-.-"}, {
'?',
"-..-."}, {
'!',
"---."},
210 {
'&',
". ..."}, {0,
nullptr}};
The Morse code tables and timing. A code is a string of '.' (dot), '-' (dash), '_' (long dash of the ...
Definition Morse.h:143
static const Entry * table(MorseAlphabet alphabet)
Definition Morse.h:181
static const Timing & timing(MorseAlphabet alphabet)
Definition Morse.h:153
static char decode(MorseAlphabet alphabet, const char *code)
Character of a code: returns 0 if the code is unknown.
Definition Morse.h:169
static const char * encode(MorseAlphabet alphabet, char ch)
Definition Morse.h:161
TinyModem: software audio modems and packets with error correction.
Definition AX25.h:11
MorseAlphabet
Morse code alphabet.
Definition Morse.h:13
@ AMERICAN
Definition Morse.h:18
@ INTERNATIONAL
International Morse code (ITU-R M.1677): dots and dashes of 3 units.
Definition Morse.h:15
const char * code
Definition Morse.h:178
char ch
Definition Morse.h:177
Lengths in units.
Definition Morse.h:146
float extra_long_dash
Definition Morse.h:147
float dot
Definition Morse.h:147
float letter_gap
Definition Morse.h:148
float element_gap
Definition Morse.h:148
float dash
Definition Morse.h:147
float inner_gap
Definition Morse.h:148
float long_dash
Definition Morse.h:147
float word_gap
Definition Morse.h:148
bool setMode(const char *mode)
Definition Morse.h:64
float wpm
speed in words per minute
Definition Morse.h:41
float frequency
frequency of the tone in Hz
Definition Morse.h:43
bool isValid() const
Checks the configuration: returns false (and logs the reason) if invalid.
Definition Morse.h:84
uint8_t channel
receiver: input channel which is used for the decoding
Definition Morse.h:58
static bool startsWith(const char *str, const char *prefix)
Definition Morse.h:129
static bool parseMode(const char *mode, MorseAlphabet &alphabet, float &speed)
Definition Morse.h:101
float ramp_ms
transmitter: rise and fall time of the tone in ms (avoids clicks)
Definition Morse.h:47
MorseConfig()
Definition Morse.h:32
static bool isMode(const char *mode)
true if the mode is a Morse code mode
Definition Morse.h:74
int rx_timeout_units
Definition Morse.h:54
float unitTime() const
length of a unit (dot) in seconds
Definition Morse.h:81
MorseAlphabet alphabet
International (default) or American Morse code.
Definition Morse.h:39
float rx_noise
receiver: (testing only) amplitude of added uniform noise
Definition Morse.h:60
bool rx_one
receiver: stop after the first transmission
Definition Morse.h:56
bool adaptive_speed
receiver: adapt to the speed of the sender
Definition Morse.h:49
float min_amplitude
receiver: minimum amplitude of the tone (1.0 = full scale)
Definition Morse.h:51
float volume
transmit amplitude (0.0 - 1.0)
Definition Morse.h:45