Tue Aug 24 20:34:21 2010

Asterisk developer's documentation


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 (ASTERISK_GPL_KEY,"Morse code")
static int load_module (void)
static int morsecode_exec (struct ast_channel *chan, void *data)
static void playtone (struct ast_channel *chan, int tone, int len)
static int unload_module (void)

Variables

static char * app_morsecode = "Morsecode"
static char * 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 ( ASTERISK_GPL_KEY  ,
"Morse code"   
)
static int load_module ( void   )  [static]

Definition at line 179 of file app_morsecode.c.

References ast_register_application_xml, and morsecode_exec().

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

Definition at line 121 of file app_morsecode.c.

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

Referenced by load_module().

00122 {
00123    int res=0, ditlen, tone;
00124    char *digit;
00125    const char *ditlenc, *tonec;
00126 
00127    if (ast_strlen_zero(data)) {
00128       ast_log(LOG_WARNING, "Syntax: Morsecode(<string>) - no argument found\n");
00129       return 0;
00130    }
00131 
00132    /* Use variable MORESEDITLEN, if set (else 80) */
00133    ast_channel_lock(chan);
00134    ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN");
00135    if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%30d", &ditlen) != 1)) {
00136       ditlen = 80;
00137    }
00138    ast_channel_unlock(chan);
00139 
00140    /* Use variable MORSETONE, if set (else 800) */
00141    ast_channel_lock(chan);
00142    tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
00143    if (ast_strlen_zero(tonec) || (sscanf(tonec, "%30d", &tone) != 1)) {
00144       tone = 800;
00145    }
00146    ast_channel_unlock(chan);
00147 
00148    for (digit = data; *digit; digit++) {
00149       int digit2 = *digit;
00150       char *dahdit;
00151       if (digit2 < 0) {
00152          continue;
00153       }
00154       for (dahdit = morsecode[digit2]; *dahdit; dahdit++) {
00155          if (*dahdit == '-') {
00156             playtone(chan, tone, 3 * ditlen);
00157          } else if (*dahdit == '.') {
00158             playtone(chan, tone, 1 * ditlen);
00159          } else {
00160             /* Account for ditlen of silence immediately following */
00161             playtone(chan, 0, 2 * ditlen);
00162          }
00163 
00164          /* Pause slightly between each dit and dah */
00165          playtone(chan, 0, 1 * ditlen);
00166       }
00167       /* Pause between characters */
00168       playtone(chan, 0, 2 * ditlen);
00169    }
00170 
00171    return res;
00172 }

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

Definition at line 112 of file app_morsecode.c.

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

Referenced by action_bridge(), and morsecode_exec().

00113 {
00114    char dtmf[20];
00115    snprintf(dtmf, sizeof(dtmf), "%d/%d", tone, len);
00116    ast_playtones_start(chan, 0, dtmf, 0);
00117    ast_safe_sleep(chan, len);
00118    ast_playtones_stop(chan);
00119 }

static int unload_module ( void   )  [static]

Definition at line 174 of file app_morsecode.c.

References ast_unregister_application().

00175 {
00176    return ast_unregister_application(app_morsecode);
00177 }


Variable Documentation

char* app_morsecode = "Morsecode" [static]

Definition at line 66 of file app_morsecode.c.

char* morsecode[] [static]

Definition at line 68 of file app_morsecode.c.


Generated on 24 Aug 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1