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
00028
00029
00030
00031 #include "asterisk.h"
00032
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 336716 $")
00034
00035 #include "asterisk/file.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/module.h"
00039 #include "asterisk/indications.h"
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 static const char app_morsecode[] = "Morsecode";
00072
00073 static const char * const morsecode[] = {
00074 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
00075 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
00076 " ",
00077 ".-.-.-",
00078 ".-..-.",
00079 "",
00080 "",
00081 "",
00082 "",
00083 ".----.",
00084 "-.--.-",
00085 "-.--.-",
00086 "",
00087 "",
00088 "--..--",
00089 "-....-",
00090 ".-.-.-",
00091 "-..-.",
00092 "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.",
00093 "---...",
00094 "-.-.-.",
00095 "",
00096 "-...-",
00097 "",
00098 "..--..",
00099 ".--.-.",
00100 ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
00101 "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..",
00102 "-.--.-",
00103 "-..-.",
00104 "-.--.-",
00105 "",
00106 "..--.-",
00107 ".----.",
00108 ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
00109 "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..",
00110 "-.--.-",
00111 "",
00112 "-.--.-",
00113 "-..-.",
00114 ". . .",
00115 };
00116
00117 static void playtone(struct ast_channel *chan, int tone, int len)
00118 {
00119 char dtmf[20];
00120 snprintf(dtmf, sizeof(dtmf), "%d/%d", tone, len);
00121 ast_playtones_start(chan, 0, dtmf, 0);
00122 ast_safe_sleep(chan, len);
00123 ast_playtones_stop(chan);
00124 }
00125
00126 static int morsecode_exec(struct ast_channel *chan, const char *data)
00127 {
00128 int res=0, ditlen, tone;
00129 const char *digit;
00130 const char *ditlenc, *tonec;
00131
00132 if (ast_strlen_zero(data)) {
00133 ast_log(LOG_WARNING, "Syntax: Morsecode(<string>) - no argument found\n");
00134 return 0;
00135 }
00136
00137
00138 ast_channel_lock(chan);
00139 ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN");
00140 if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%30d", &ditlen) != 1)) {
00141 ditlen = 80;
00142 }
00143 ast_channel_unlock(chan);
00144
00145
00146 ast_channel_lock(chan);
00147 tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
00148 if (ast_strlen_zero(tonec) || (sscanf(tonec, "%30d", &tone) != 1)) {
00149 tone = 800;
00150 }
00151 ast_channel_unlock(chan);
00152
00153 for (digit = data; *digit; digit++) {
00154 int digit2 = *digit;
00155 const char *dahdit;
00156 if (digit2 < 0) {
00157 continue;
00158 }
00159 for (dahdit = morsecode[digit2]; *dahdit; dahdit++) {
00160 if (*dahdit == '-') {
00161 playtone(chan, tone, 3 * ditlen);
00162 } else if (*dahdit == '.') {
00163 playtone(chan, tone, 1 * ditlen);
00164 } else {
00165
00166 playtone(chan, 0, 2 * ditlen);
00167 }
00168
00169
00170 playtone(chan, 0, 1 * ditlen);
00171 }
00172
00173 playtone(chan, 0, 2 * ditlen);
00174 }
00175
00176 return res;
00177 }
00178
00179 static int unload_module(void)
00180 {
00181 return ast_unregister_application(app_morsecode);
00182 }
00183
00184 static int load_module(void)
00185 {
00186 return ast_register_application_xml(app_morsecode, morsecode_exec);
00187 }
00188
00189 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Morse code");