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 void playtone (struct ast_channel *chan, int tone, int len)
static int unload_module (void)

Variables

static const char app_morsecode [] = "Morsecode"
static const char *const morsecode []


Detailed Description

Morsecode application.

Author:
Tilghman Lesher <app_morsecode__v001@the-tilghman.com>

Definition in file app_morsecode.c.


Function Documentation

AST_MODULE_INFO_STANDARD_EXTENDED ( ASTERISK_GPL_KEY  ,
"Morse code"   
)

static int load_module ( void   )  [static]

Definition at line 184 of file app_morsecode.c.

References ast_register_application_xml, and morsecode_exec().

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

Definition at line 126 of file app_morsecode.c.

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

Referenced by load_module().

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    /* Use variable MORESEDITLEN, if set (else 80) */
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    /* Use variable MORSETONE, if set (else 800) */
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             /* Account for ditlen of silence immediately following */
00166             playtone(chan, 0, 2 * ditlen);
00167          }
00168 
00169          /* Pause slightly between each dit and dah */
00170          playtone(chan, 0, 1 * ditlen);
00171       }
00172       /* Pause between characters */
00173       playtone(chan, 0, 2 * ditlen);
00174    }
00175 
00176    return res;
00177 }

static void playtone ( struct ast_channel chan,
int  tone,
int  len 
) [static]

Definition at line 117 of file app_morsecode.c.

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

Referenced by action_bridge(), and morsecode_exec().

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 }

static int unload_module ( void   )  [static]

Definition at line 179 of file app_morsecode.c.

References ast_unregister_application().

00180 {
00181    return ast_unregister_application(app_morsecode);
00182 }


Variable Documentation

const char app_morsecode[] = "Morsecode" [static]

Definition at line 71 of file app_morsecode.c.

const char* const morsecode[] [static]

Definition at line 73 of file app_morsecode.c.


Generated on Thu Apr 16 06:28:35 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6