Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Functions | Variables
app_morsecode.c File Reference

Morsecode application. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/indications.h"
Include dependency graph for app_morsecode.c:

Go to the source code of this file.

Functions

 AST_MODULE_INFO_STANDARD_EXTENDED (ASTERISK_GPL_KEY, "Morse code")
 
static int load_module (void)
 
static int morsecode_exec (struct ast_channel *chan, const char *data)
 
static int playtone (struct ast_channel *chan, int tone, int len)
 
static int unload_module (void)
 

Variables

static const char *const americanmorsecode []
 
static const char app_morsecode [] = "Morsecode"
 
static const char *const internationalcode []
 

Detailed Description

Morsecode application.

Author
Tilghman Lesher app_m.nosp@m.orse.nosp@m.code_.nosp@m._v00.nosp@m.1@the.nosp@m.-til.nosp@m.ghman.nosp@m..com
Naveen Albert aster.nosp@m.isk@.nosp@m.phrea.nosp@m.knet.nosp@m..org

Definition in file app_morsecode.c.

Function Documentation

◆ AST_MODULE_INFO_STANDARD_EXTENDED()

AST_MODULE_INFO_STANDARD_EXTENDED ( ASTERISK_GPL_KEY  ,
"Morse code"   
)

◆ load_module()

static int load_module ( void  )
static

Definition at line 289 of file app_morsecode.c.

290{
292}
static const char app_morsecode[]
Definition: app_morsecode.c:80
static int morsecode_exec(struct ast_channel *chan, const char *data)
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

References app_morsecode, ast_register_application_xml, and morsecode_exec().

◆ morsecode_exec()

static int morsecode_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 181 of file app_morsecode.c.

182{
183 int res = 0, ditlen, tone, toneoff, digit2;
184 const char *digit;
185 const char *ditlenc, *tonec, *toneb, *codetype;
186
187 if (ast_strlen_zero(data)) {
188 ast_log(LOG_WARNING, "Syntax: Morsecode(<string>) - no argument found\n");
189 return 0;
190 }
191
192 ast_channel_lock(chan);
193 /* Use variable MORESEDITLEN, if set (else 80) */
194 ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN");
195 if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%30d", &ditlen) != 1)) {
196 ditlen = 80;
197 }
198
199 /* Use variable MORSETONE, if set (else 800) */
200 tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
201 if (ast_strlen_zero(tonec) || (sscanf(tonec, "%30d", &tone) != 1)) {
202 tone = 800;
203 }
204
205 /* Use variable MORSESPACETONE, if set (else 0) */
206 toneb = pbx_builtin_getvar_helper(chan, "MORSESPACETONE");
207 if (ast_strlen_zero(toneb) || (sscanf(toneb, "%30d", &toneoff) != 1)) {
208 toneoff = 0;
209 }
210
211 /* Use variable MORSETYPE, if set (else INTERNATIONAL) */
212 codetype = pbx_builtin_getvar_helper(chan, "MORSETYPE");
213 if (!codetype || strcmp(codetype, "AMERICAN")) {
214 codetype = "INTERNATIONAL";
215 }
216
217 ast_channel_unlock(chan);
218 if (!strcmp(codetype, "AMERICAN")) {
219 for (digit = data; *digit; digit++) {
220 const char *dahdit;
221 digit2 = *digit;
222 if (digit2 < 0 || digit2 > 127) {
223 continue;
224 }
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); /* long dash */
232 } else if (*dahdit == '0') {
233 res = playtone(chan, tone, 9 * ditlen); /* extra long dash */
234 } else if (*dahdit == ' ') { /* space char (x20) = 6 dot lengths */
235 /* Intra-char pauses, specific to American Morse */
236 res = playtone(chan, toneoff, 3 * ditlen);
237 } else {
238 /* Account for ditlen of silence immediately following */
239 res = playtone(chan, toneoff, 2 * ditlen);
240 }
241
242 /* Pause slightly between each dit and dah */
243 res = playtone(chan, toneoff, 1 * ditlen);
244 if (res)
245 break;
246 }
247 /* Pause between characters */
248 res = playtone(chan, toneoff, 3 * ditlen);
249 if (res)
250 break;
251 }
252 } else { /* International */
253 for (digit = data; *digit; digit++) {
254 const char *dahdit;
255 digit2 = *digit;
256 if (digit2 < 0 || digit2 > 127) {
257 continue;
258 }
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);
264 } else {
265 /* Account for ditlen of silence immediately following */
266 res = playtone(chan, toneoff, 2 * ditlen);
267 }
268
269 /* Pause slightly between each dit and dah */
270 res = playtone(chan, toneoff, 1 * ditlen);
271 if (res)
272 break;
273 }
274 /* Pause between characters */
275 res = playtone(chan, toneoff, 2 * ditlen);
276 if (res)
277 break;
278 }
279 }
280
281 return res;
282}
char digit
static int playtone(struct ast_channel *chan, int tone, int len)
static const char *const internationalcode[]
Definition: app_morsecode.c:82
static const char *const americanmorsecode[]
#define ast_log
Definition: astobj2.c:42
#define ast_channel_lock(chan)
Definition: channel.h:2922
#define ast_channel_unlock(chan)
Definition: channel.h:2923
#define LOG_WARNING
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65

References americanmorsecode, ast_channel_lock, ast_channel_unlock, ast_log, ast_strlen_zero(), digit, internationalcode, LOG_WARNING, pbx_builtin_getvar_helper(), and playtone().

Referenced by load_module().

◆ playtone()

static int playtone ( struct ast_channel chan,
int  tone,
int  len 
)
static

Definition at line 170 of file app_morsecode.c.

171{
172 int res;
173 char dtmf[20];
174 snprintf(dtmf, sizeof(dtmf), "%d/%d", tone, len);
175 ast_playtones_start(chan, 0, dtmf, 0);
176 res = ast_safe_sleep(chan, len);
177 ast_playtones_stop(chan);
178 return res;
179}
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1574
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
Definition: indications.c:302
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:393

References ast_playtones_start(), ast_playtones_stop(), ast_safe_sleep(), and len().

Referenced by action_bridge(), and morsecode_exec().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 284 of file app_morsecode.c.

285{
287}
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References app_morsecode, and ast_unregister_application().

Variable Documentation

◆ americanmorsecode

const char* const americanmorsecode[]
static

Definition at line 126 of file app_morsecode.c.

Referenced by morsecode_exec().

◆ app_morsecode

const char app_morsecode[] = "Morsecode"
static

Definition at line 80 of file app_morsecode.c.

Referenced by load_module(), and unload_module().

◆ internationalcode

const char* const internationalcode[]
static

Definition at line 82 of file app_morsecode.c.

Referenced by morsecode_exec().