| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2006, Tilghman Lesher.  All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  |  * Updated by Naveen Albert <asterisk@phreaknet.org> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  |  * Tilghman Lesher <app_morsecode__v001@the-tilghman.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This code is released by the author with no restrictions on usage. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \file
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \brief Morsecode application | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \author Tilghman Lesher <app_morsecode__v001@the-tilghman.com> | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  |  * \author Naveen Albert <asterisk@phreaknet.org> | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \ingroup applications | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 20:28:54 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>extended</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/indications.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | /*** DOCUMENTATION
 | 
					
						
							|  |  |  | 	<application name="Morsecode" language="en_US"> | 
					
						
							|  |  |  | 		<synopsis> | 
					
						
							| 
									
										
										
										
											2008-11-05 14:37:07 +00:00
										 |  |  | 			Plays morse code. | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 		</synopsis> | 
					
						
							|  |  |  | 		<syntax> | 
					
						
							|  |  |  | 			<parameter name="string" required="true"> | 
					
						
							|  |  |  | 				<para>String to playback as morse code to channel</para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							|  |  |  | 		</syntax> | 
					
						
							|  |  |  | 		<description> | 
					
						
							|  |  |  | 			<para>Plays the Morse code equivalent of the passed string.</para> | 
					
						
							| 
									
										
										
										
											2011-09-19 20:23:29 +00:00
										 |  |  | 			<para>This application does not automatically answer and should be preceeded by | 
					
						
							|  |  |  | 			an application such as Answer() or Progress().</para> | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 			<para>This application uses the following variables:</para> | 
					
						
							|  |  |  | 			<variablelist> | 
					
						
							|  |  |  | 				<variable name="MORSEDITLEN"> | 
					
						
							|  |  |  | 					<para>Use this value in (ms) for length of dit</para> | 
					
						
							|  |  |  | 				</variable> | 
					
						
							|  |  |  | 				<variable name="MORSETONE"> | 
					
						
							|  |  |  | 					<para>The pitch of the tone in (Hz), default is 800</para> | 
					
						
							|  |  |  | 				</variable> | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 				<variable name="MORSESPACETONE"> | 
					
						
							|  |  |  | 					<para>The pitch of the spaces in (Hz), default is 0</para> | 
					
						
							|  |  |  | 				</variable> | 
					
						
							|  |  |  | 				<variable name="MORSETYPE"> | 
					
						
							|  |  |  | 					<para>The code type to use (AMERICAN for standard American Morse | 
					
						
							|  |  |  | 					or INTERNATIONAL for international code. | 
					
						
							|  |  |  | 					Default is INTERNATIONAL).</para> | 
					
						
							|  |  |  | 				</variable> | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 			</variablelist> | 
					
						
							|  |  |  | 		</description> | 
					
						
							| 
									
										
										
										
											2008-11-05 14:37:07 +00:00
										 |  |  | 		<see-also> | 
					
						
							|  |  |  | 			<ref type="application">SayAlpha</ref> | 
					
						
							|  |  |  | 			<ref type="application">SayPhonetic</ref> | 
					
						
							|  |  |  | 		</see-also> | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 	</application> | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  |  ***/ | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static const char app_morsecode[] = "Morsecode"; | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | static const char * const internationalcode[] = { | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", /*  0-15 */ | 
					
						
							|  |  |  | 	"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", /* 16-31 */ | 
					
						
							|  |  |  | 	" ",      /* 32 - <space> */ | 
					
						
							|  |  |  | 	".-.-.-", /* 33 - ! */ | 
					
						
							|  |  |  | 	".-..-.", /* 34 - " */ | 
					
						
							|  |  |  | 	"",       /* 35 - # */ | 
					
						
							|  |  |  | 	"",       /* 36 - $ */ | 
					
						
							|  |  |  | 	"",       /* 37 - % */ | 
					
						
							|  |  |  | 	"",       /* 38 - & */ | 
					
						
							|  |  |  | 	".----.", /* 39 - ' */ | 
					
						
							|  |  |  | 	"-.--.-", /* 40 - ( */ | 
					
						
							|  |  |  | 	"-.--.-", /* 41 - ) */ | 
					
						
							|  |  |  | 	"",       /* 42 - * */ | 
					
						
							|  |  |  | 	"",       /* 43 - + */ | 
					
						
							|  |  |  | 	"--..--", /* 44 - , */ | 
					
						
							|  |  |  | 	"-....-", /* 45 - - */ | 
					
						
							|  |  |  | 	".-.-.-", /* 46 - . */ | 
					
						
							| 
									
										
										
										
											2006-06-03 02:18:59 +00:00
										 |  |  | 	"-..-.",  /* 47 - / */ | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", /* 48-57 - 0-9 */ | 
					
						
							|  |  |  | 	"---...", /* 58 - : */ | 
					
						
							| 
									
										
										
										
											2006-06-03 02:18:59 +00:00
										 |  |  | 	"-.-.-.", /* 59 - ; */ | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	"",       /* 60 - < */ | 
					
						
							|  |  |  | 	"-...-",  /* 61 - = */ | 
					
						
							|  |  |  | 	"",       /* 62 - > */ | 
					
						
							|  |  |  | 	"..--..", /* 63 - ? */ | 
					
						
							|  |  |  | 	".--.-.", /* 64 - @ */ | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 	".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", /* A-M */ | 
					
						
							|  |  |  | 	"-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", /* N-Z */ | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	"-.--.-", /* 91 - [ (really '(') */ | 
					
						
							| 
									
										
										
										
											2006-06-03 02:17:00 +00:00
										 |  |  | 	"-..-.",  /* 92 - \ (really '/') */ | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	"-.--.-", /* 93 - ] (really ')') */ | 
					
						
							|  |  |  | 	"",       /* 94 - ^ */ | 
					
						
							| 
									
										
										
										
											2006-06-03 02:17:00 +00:00
										 |  |  | 	"..--.-", /* 95 - _ */ | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	".----.", /* 96 - ` */ | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 	".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", /* a-m */ | 
					
						
							|  |  |  | 	"-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", /* n-z */ | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	"-.--.-", /* 123 - { (really '(') */ | 
					
						
							|  |  |  | 	"",       /* 124 - | */ | 
					
						
							|  |  |  | 	"-.--.-", /* 125 - } (really ')') */ | 
					
						
							| 
									
										
										
										
											2006-06-03 02:17:00 +00:00
										 |  |  | 	"-..-.",  /* 126 - ~ (really bar) */ | 
					
						
							|  |  |  | 	". . .",  /* 127 - <del> (error) */ | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | static const char * const americanmorsecode[] = { | 
					
						
							|  |  |  | 	"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", /*  0-15 */ | 
					
						
							|  |  |  | 	"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", /* 16-31 */ | 
					
						
							|  |  |  | 	"  ",    /* 32 - <space> */ | 
					
						
							|  |  |  | 	"---.",   /* 33 - ! */ | 
					
						
							|  |  |  | 	"..-. -.",/* 34 - " (QN)*/ | 
					
						
							|  |  |  | 	"",       /* 35 - # */ | 
					
						
							|  |  |  | 	"... .-..",/* 36 - $ (SX) */ | 
					
						
							|  |  |  | 	"",       /* 37 - % */ | 
					
						
							|  |  |  | 	". ...",  /* 38 - & (ES) */ | 
					
						
							|  |  |  | 	"..-. .-..",/* 39 - ' (QX) */ | 
					
						
							|  |  |  | 	"..... -.", /* 40 - ( (PN) */ | 
					
						
							|  |  |  | 	"..... .. ..", /* 41 - ) (PY) */ | 
					
						
							|  |  |  | 	"",       /* 42 - * */ | 
					
						
							|  |  |  | 	"",       /* 43 - + */ | 
					
						
							|  |  |  | 	".-.-",   /* 44 - , */ | 
					
						
							|  |  |  | 	".... .-..",/* 45 - (HX) */ | 
					
						
							|  |  |  | 	"..--..", /* 46 - . */ | 
					
						
							|  |  |  | 	"..- -",  /* 47 - / (UT) */ | 
					
						
							|  |  |  | 	".--.", "..-..", "...-.", "....-", "---", "......", "--..", "-....", "-..-", "0", /* 48-57 - 0-9 */ | 
					
						
							|  |  |  | 	"-.- . .",/* 58 - : (KO) */ | 
					
						
							|  |  |  | 	"... ..", /* 59 - ; */ | 
					
						
							|  |  |  | 	"",       /* 60 - < */ | 
					
						
							|  |  |  | 	"-...-",  /* 61 - = (paragraph mark) */ | 
					
						
							|  |  |  | 	"",       /* 62 - > */ | 
					
						
							|  |  |  | 	"-..-.",  /* 63 - ? */ | 
					
						
							|  |  |  | 	".--.-.", /* 64 - @ */ | 
					
						
							|  |  |  | 	".-", "-...", ".. .", "-..", ".", ".-.", "--.", "....", "..", ".-.-", "-.-", "L", "--", /* A-M */ | 
					
						
							|  |  |  | 	"-.", ". .", ".....", "..-.", ". ..", "...", "-", "..-", "...-", ".--", ".-..", ".. ..", "... .", /* N-Z */ | 
					
						
							|  |  |  | 	"..... -.", /* 91 - [ (really '(') */ | 
					
						
							|  |  |  | 	"..- -",  /* 92 - \ (really '/') */ | 
					
						
							|  |  |  | 	"..... .. ..", /* 93 - ] (really ')') */ | 
					
						
							|  |  |  | 	"",       /* 94 - ^ */ | 
					
						
							|  |  |  | 	"..--.-", /* 95 - _ */ | 
					
						
							|  |  |  | 	".----.", /* 96 - ` */ | 
					
						
							|  |  |  | 	".-", "-...", ".. .", "-..", ".", ".-.", "--.", "....", "..", ".-.-", "-.-", "L", "--", /* a-m */ | 
					
						
							|  |  |  | 	"-.", ". .", ".....", "..-.", ". ..", "...", "-", "..-", "...-", ".--", ".-..", ".. ..", "... .", /* n-z */ | 
					
						
							|  |  |  | 	"..... -.", /* 123 - { (really '(') */ | 
					
						
							|  |  |  | 	"",       /* 124 - | */ | 
					
						
							|  |  |  | 	"..... .. ..", /* 125 - } (really ')') */ | 
					
						
							|  |  |  | 	"..- -",  /* 126 - ~ (really bar) */ | 
					
						
							|  |  |  | 	". . .",  /* 127 - <del> (error) */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int playtone(struct ast_channel *chan, int tone, int len) | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	char dtmf[20]; | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 	snprintf(dtmf, sizeof(dtmf), "%d/%d", tone, len); | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	ast_playtones_start(chan, 0, dtmf, 0); | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 	res = ast_safe_sleep(chan, len); | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	ast_playtones_stop(chan); | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int morsecode_exec(struct ast_channel *chan, const char *data) | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 	int res = 0, ditlen, tone, toneoff, digit2; | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | 	const char *digit; | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 	const char *ditlenc, *tonec, *toneb, *codetype; | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_strlen_zero(data)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Syntax: Morsecode(<string>) - no argument found\n"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-30 19:21:04 +00:00
										 |  |  | 	ast_channel_lock(chan); | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 	/* Use variable MORESEDITLEN, if set (else 80) */ | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 	ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN"); | 
					
						
							| 
									
										
										
										
											2009-08-10 19:20:57 +00:00
										 |  |  | 	if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%30d", &ditlen) != 1)) { | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 		ditlen = 80; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Use variable MORSETONE, if set (else 800) */ | 
					
						
							|  |  |  | 	tonec = pbx_builtin_getvar_helper(chan, "MORSETONE"); | 
					
						
							| 
									
										
										
										
											2009-08-10 19:20:57 +00:00
										 |  |  | 	if (ast_strlen_zero(tonec) || (sscanf(tonec, "%30d", &tone) != 1)) { | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 		tone = 800; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 	/* Use variable MORSESPACETONE, if set (else 0) */ | 
					
						
							|  |  |  | 	toneb = pbx_builtin_getvar_helper(chan, "MORSESPACETONE"); | 
					
						
							|  |  |  | 	if (ast_strlen_zero(toneb) || (sscanf(toneb, "%30d", &toneoff) != 1)) { | 
					
						
							|  |  |  | 		toneoff = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Use variable MORSETYPE, if set (else INTERNATIONAL) */ | 
					
						
							|  |  |  | 	codetype = pbx_builtin_getvar_helper(chan, "MORSETYPE"); | 
					
						
							|  |  |  | 	if (!codetype || strcmp(codetype, "AMERICAN")) { | 
					
						
							|  |  |  | 		codetype = "INTERNATIONAL"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 19:02:40 +00:00
										 |  |  | 	ast_channel_unlock(chan); | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 	if (!strcmp(codetype, "AMERICAN")) { | 
					
						
							|  |  |  | 		for (digit = data; *digit; digit++) { | 
					
						
							|  |  |  | 			const char *dahdit; | 
					
						
							|  |  |  | 			digit2 = *digit; | 
					
						
							|  |  |  | 			if (digit2 < 0 || digit2 > 127) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (dahdit = americanmorsecode[digit2]; *dahdit; dahdit++) { | 
					
						
							|  |  |  | 				if (*dahdit == '-') { | 
					
						
							|  |  |  | 					res = playtone(chan, tone, 3 * ditlen); | 
					
						
							|  |  |  | 				} else if (*dahdit == '.') { | 
					
						
							|  |  |  | 					res = playtone(chan, tone, 1 * ditlen); | 
					
						
							|  |  |  | 				} else if (*dahdit == 'L' || *dahdit == 'l') { | 
					
						
							|  |  |  | 					res = playtone(chan, tone, 6 * ditlen); /* long dash */ | 
					
						
							|  |  |  | 				} else if (*dahdit == '0') { | 
					
						
							|  |  |  | 					res = playtone(chan, tone, 9 * ditlen); /* extra long dash */ | 
					
						
							|  |  |  | 				} else if (*dahdit == ' ') { /* space char (x20) = 6 dot lengths */ | 
					
						
							|  |  |  | 					/* Intra-char pauses, specific to American Morse */ | 
					
						
							|  |  |  | 					res = playtone(chan, toneoff, 3 * ditlen); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					/* Account for ditlen of silence immediately following */ | 
					
						
							|  |  |  | 					res = playtone(chan, toneoff, 2 * ditlen); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* Pause slightly between each dit and dah */ | 
					
						
							|  |  |  | 				res = playtone(chan, toneoff, 1 * ditlen); | 
					
						
							|  |  |  | 				if (res) | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			/* Pause between characters */ | 
					
						
							|  |  |  | 			res = playtone(chan, toneoff, 3 * ditlen); | 
					
						
							|  |  |  | 			if (res) | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 	} else { /* International */ | 
					
						
							|  |  |  | 		for (digit = data; *digit; digit++) { | 
					
						
							|  |  |  | 			const char *dahdit; | 
					
						
							|  |  |  | 			digit2 = *digit; | 
					
						
							|  |  |  | 			if (digit2 < 0 || digit2 > 127) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 			for (dahdit = internationalcode[digit2]; *dahdit; dahdit++) { | 
					
						
							|  |  |  | 				if (*dahdit == '-') { | 
					
						
							|  |  |  | 					res = playtone(chan, tone, 3 * ditlen); | 
					
						
							|  |  |  | 				} else if (*dahdit == '.') { | 
					
						
							|  |  |  | 					res = playtone(chan, tone, 1 * ditlen); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					/* Account for ditlen of silence immediately following */ | 
					
						
							|  |  |  | 					res = playtone(chan, toneoff, 2 * ditlen); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 14:46:42 +00:00
										 |  |  | 				/* Pause slightly between each dit and dah */ | 
					
						
							|  |  |  | 				res = playtone(chan, toneoff, 1 * ditlen); | 
					
						
							|  |  |  | 				if (res) | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			/* Pause between characters */ | 
					
						
							|  |  |  | 			res = playtone(chan, toneoff, 2 * ditlen); | 
					
						
							|  |  |  | 			if (res) | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-16 13:35:20 +00:00
										 |  |  | 	return ast_unregister_application(app_morsecode); | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 	return ast_register_application_xml(app_morsecode, morsecode_exec); | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-25 16:47:17 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Morse code"); |