80 static const char app_morsecode[] =
"Morsecode";
82 static const char *
const internationalcode[] = {
83 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
84 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
101 "-----",
".----",
"..---",
"...--",
"....-",
".....",
"-....",
"--...",
"---..",
"----.",
109 ".-",
"-...",
"-.-.",
"-..",
".",
"..-.",
"--.",
"....",
"..",
".---",
"-.-",
".-..",
"--",
110 "-.",
"---",
".--.",
"--.-",
".-.",
"...",
"-",
"..-",
"...-",
".--",
"-..-",
"-.--",
"--..",
117 ".-",
"-...",
"-.-.",
"-..",
".",
"..-.",
"--.",
"....",
"..",
".---",
"-.-",
".-..",
"--",
118 "-.",
"---",
".--.",
"--.-",
".-.",
"...",
"-",
"..-",
"...-",
".--",
"-..-",
"-.--",
"--..",
126 static const char *
const americanmorsecode[] = {
127 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
128 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
145 ".--.",
"..-..",
"...-.",
"....-",
"---",
"......",
"--..",
"-....",
"-..-",
"0",
153 ".-",
"-...",
".. .",
"-..",
".",
".-.",
"--.",
"....",
"..",
".-.-",
"-.-",
"L",
"--",
154 "-.",
". .",
".....",
"..-.",
". ..",
"...",
"-",
"..-",
"...-",
".--",
".-..",
".. ..",
"... .",
161 ".-",
"-...",
".. .",
"-..",
".",
".-.",
"--.",
"....",
"..",
".-.-",
"-.-",
"L",
"--",
162 "-.",
". .",
".....",
"..-.",
". ..",
"...",
"-",
"..-",
"...-",
".--",
".-..",
".. ..",
"... .",
170 static int playtone(
struct ast_channel *chan,
int tone,
int len)
174 snprintf(dtmf,
sizeof(dtmf),
"%d/%d", tone, len);
181 static int morsecode_exec(
struct ast_channel *chan,
const char *data)
183 int res = 0, ditlen, tone, toneoff, digit2;
185 const char *ditlenc, *tonec, *toneb, *codetype;
187 if (ast_strlen_zero(data)) {
188 ast_log(LOG_WARNING,
"Syntax: Morsecode(<string>) - no argument found\n");
192 ast_channel_lock(chan);
195 if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc,
"%30d", &ditlen) != 1)) {
201 if (ast_strlen_zero(tonec) || (sscanf(tonec,
"%30d", &tone) != 1)) {
207 if (ast_strlen_zero(toneb) || (sscanf(toneb,
"%30d", &toneoff) != 1)) {
213 if (!codetype || strcmp(codetype,
"AMERICAN")) {
214 codetype =
"INTERNATIONAL";
217 ast_channel_unlock(chan);
218 if (!strcmp(codetype,
"AMERICAN")) {
219 for (digit = data; *digit; digit++) {
222 if (digit2 < 0 || digit2 > 127) {
225 for (dahdit = americanmorsecode[digit2]; *dahdit; dahdit++) {
226 if (*dahdit ==
'-') {
227 res = playtone(chan, tone, 3 * ditlen);
228 }
else if (*dahdit ==
'.') {
229 res = playtone(chan, tone, 1 * ditlen);
230 }
else if (*dahdit ==
'L' || *dahdit ==
'l') {
231 res = playtone(chan, tone, 6 * ditlen);
232 }
else if (*dahdit ==
'0') {
233 res = playtone(chan, tone, 9 * ditlen);
234 }
else if (*dahdit ==
' ') {
236 res = playtone(chan, toneoff, 3 * ditlen);
239 res = playtone(chan, toneoff, 2 * ditlen);
243 res = playtone(chan, toneoff, 1 * ditlen);
248 res = playtone(chan, toneoff, 3 * ditlen);
253 for (digit = data; *digit; digit++) {
256 if (digit2 < 0 || digit2 > 127) {
259 for (dahdit = internationalcode[digit2]; *dahdit; dahdit++) {
260 if (*dahdit ==
'-') {
261 res = playtone(chan, tone, 3 * ditlen);
262 }
else if (*dahdit ==
'.') {
263 res = playtone(chan, tone, 1 * ditlen);
266 res = playtone(chan, toneoff, 2 * ditlen);
270 res = playtone(chan, toneoff, 1 * ditlen);
275 res = playtone(chan, toneoff, 2 * ditlen);
284 static int unload_module(
void)
289 static int load_module(
void)
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
int ast_unregister_application(const char *app)
Unregister an application.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
General Asterisk PBX channel definitions.
Core PBX routines and definitions.
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.