| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2006, Tilghman Lesher.  All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \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> | 
					
						
							|  |  |  | 			</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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static const char * const morsecode[] = { | 
					
						
							| 
									
										
										
										
											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 - @ */ | 
					
						
							|  |  |  | 	".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", | 
					
						
							|  |  |  | 	"-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", | 
					
						
							|  |  |  | 	"-.--.-", /* 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 - ` */ | 
					
						
							|  |  |  | 	".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", | 
					
						
							|  |  |  | 	"-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", | 
					
						
							|  |  |  | 	"-.--.-", /* 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
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void playtone(struct ast_channel *chan, int tone, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 	ast_safe_sleep(chan, len); | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	ast_playtones_stop(chan); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 	int res=0, ditlen, tone; | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | 	const char *digit; | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 	const char *ditlenc, *tonec; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 	/* Use variable MORESEDITLEN, if set (else 80) */ | 
					
						
							| 
									
										
										
										
											2008-04-30 19:21:04 +00:00
										 |  |  | 	ast_channel_lock(chan); | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-04-30 19:21:04 +00:00
										 |  |  | 	ast_channel_unlock(chan); | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Use variable MORSETONE, if set (else 800) */ | 
					
						
							| 
									
										
										
										
											2008-04-30 19:21:04 +00:00
										 |  |  | 	ast_channel_lock(chan); | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 	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; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-04-30 19:21:04 +00:00
										 |  |  | 	ast_channel_unlock(chan); | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 	for (digit = data; *digit; digit++) { | 
					
						
							| 
									
										
										
										
											2007-07-23 17:49:45 +00:00
										 |  |  | 		int digit2 = *digit; | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | 		const char *dahdit; | 
					
						
							| 
									
										
										
										
											2007-07-23 17:49:45 +00:00
										 |  |  | 		if (digit2 < 0) { | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-07-23 17:49:45 +00:00
										 |  |  | 		for (dahdit = morsecode[digit2]; *dahdit; dahdit++) { | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 			if (*dahdit == '-') { | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 				playtone(chan, tone, 3 * ditlen); | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 			} else if (*dahdit == '.') { | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 				playtone(chan, tone, 1 * ditlen); | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2006-01-13 07:14:42 +00:00
										 |  |  | 				/* Account for ditlen of silence immediately following */ | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 				playtone(chan, 0, 2 * ditlen); | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* Pause slightly between each dit and dah */ | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 			playtone(chan, 0, 1 * ditlen); | 
					
						
							| 
									
										
										
										
											2006-01-12 05:47:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		/* Pause between characters */ | 
					
						
							| 
									
										
										
										
											2006-02-12 03:38:50 +00:00
										 |  |  | 		playtone(chan, 0, 2 * ditlen); | 
					
						
							| 
									
										
										
										
											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"); |