00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "asterisk.h"
00028
00029 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 89512 $")
00030
00031 #include "asterisk/file.h"
00032 #include "asterisk/channel.h"
00033 #include "asterisk/pbx.h"
00034 #include "asterisk/module.h"
00035 #include "asterisk/indications.h"
00036
00037 static char *app_morsecode = "Morsecode";
00038
00039 static char *morsecode_synopsis = "Plays morse code";
00040
00041 static char *morsecode_descrip =
00042 " Morsecode(<string>):\n"
00043 "Plays the Morse code equivalent of the passed string. If the variable\n"
00044 "MORSEDITLEN is set, it will use that value for the length (in ms) of the dit\n"
00045 "(defaults to 80). Additionally, if MORSETONE is set, it will use that tone\n"
00046 "(in Hz). The tone default is 800.\n";
00047
00048
00049 static char *morsecode[] = {
00050 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
00051 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
00052 " ",
00053 ".-.-.-",
00054 ".-..-.",
00055 "",
00056 "",
00057 "",
00058 "",
00059 ".----.",
00060 "-.--.-",
00061 "-.--.-",
00062 "",
00063 "",
00064 "--..--",
00065 "-....-",
00066 ".-.-.-",
00067 "-..-.",
00068 "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.",
00069 "---...",
00070 "-.-.-.",
00071 "",
00072 "-...-",
00073 "",
00074 "..--..",
00075 ".--.-.",
00076 ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
00077 "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..",
00078 "-.--.-",
00079 "-..-.",
00080 "-.--.-",
00081 "",
00082 "..--.-",
00083 ".----.",
00084 ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
00085 "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..",
00086 "-.--.-",
00087 "",
00088 "-.--.-",
00089 "-..-.",
00090 ". . .",
00091 };
00092
00093 static void playtone(struct ast_channel *chan, int tone, int len)
00094 {
00095 char dtmf[20];
00096 snprintf(dtmf, sizeof(dtmf), "%d/%d", tone, len);
00097 ast_playtones_start(chan, 0, dtmf, 0);
00098 ast_safe_sleep(chan, len);
00099 ast_playtones_stop(chan);
00100 }
00101
00102 static int morsecode_exec(struct ast_channel *chan, void *data)
00103 {
00104 int res=0, ditlen, tone;
00105 char *digit;
00106 const char *ditlenc, *tonec;
00107
00108 if (ast_strlen_zero(data)) {
00109 ast_log(LOG_WARNING, "Syntax: Morsecode(<string>) - no argument found\n");
00110 return 0;
00111 }
00112
00113
00114 ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN");
00115 if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%d", &ditlen) != 1)) {
00116 ditlen = 80;
00117 }
00118
00119
00120 tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
00121 if (ast_strlen_zero(tonec) || (sscanf(tonec, "%d", &tone) != 1)) {
00122 tone = 800;
00123 }
00124
00125 for (digit = data; *digit; digit++) {
00126 int digit2 = *digit;
00127 char *dahdit;
00128 if (digit2 < 0) {
00129 continue;
00130 }
00131 for (dahdit = morsecode[digit2]; *dahdit; dahdit++) {
00132 if (*dahdit == '-') {
00133 playtone(chan, tone, 3 * ditlen);
00134 } else if (*dahdit == '.') {
00135 playtone(chan, tone, 1 * ditlen);
00136 } else {
00137
00138 playtone(chan, 0, 2 * ditlen);
00139 }
00140
00141
00142 playtone(chan, 0, 1 * ditlen);
00143 }
00144
00145 playtone(chan, 0, 2 * ditlen);
00146 }
00147
00148 return res;
00149 }
00150
00151 static int unload_module(void)
00152 {
00153 return ast_unregister_application(app_morsecode);
00154 }
00155
00156 static int load_module(void)
00157 {
00158 return ast_register_application(app_morsecode, morsecode_exec, morsecode_synopsis, morsecode_descrip);
00159 }
00160
00161 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Morse code");