Fri Jul 24 00:41:10 2009

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"

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
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 struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Morse code" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, }
static char * app_morsecode = "Morsecode"
static struct ast_module_infoast_module_info = &__mod_info
static char * morsecode []
static char * morsecode_descrip
static char * morsecode_synopsis = "Plays morse code"


Detailed Description

Morsecode application.

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

Definition in file app_morsecode.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 165 of file app_morsecode.c.

static void __unreg_module ( void   )  [static]

Definition at line 165 of file app_morsecode.c.

static int load_module ( void   )  [static]

Definition at line 160 of file app_morsecode.c.

References ast_register_application, and morsecode_exec().

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

Definition at line 102 of file app_morsecode.c.

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

Referenced by load_module().

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    /* Use variable MORESEDITLEN, if set (else 80) */
00114    ast_channel_lock(chan);
00115    ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN");
00116    if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%d", &ditlen) != 1)) {
00117       ditlen = 80;
00118    }
00119    ast_channel_unlock(chan);
00120 
00121    /* Use variable MORSETONE, if set (else 800) */
00122    ast_channel_lock(chan);
00123    tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
00124    if (ast_strlen_zero(tonec) || (sscanf(tonec, "%d", &tone) != 1)) {
00125       tone = 800;
00126    }
00127    ast_channel_unlock(chan);
00128 
00129    for (digit = data; *digit; digit++) {
00130       int digit2 = *digit;
00131       char *dahdit;
00132       if (digit2 < 0) {
00133          continue;
00134       }
00135       for (dahdit = morsecode[digit2]; *dahdit; dahdit++) {
00136          if (*dahdit == '-') {
00137             playtone(chan, tone, 3 * ditlen);
00138          } else if (*dahdit == '.') {
00139             playtone(chan, tone, 1 * ditlen);
00140          } else {
00141             /* Account for ditlen of silence immediately following */
00142             playtone(chan, 0, 2 * ditlen);
00143          }
00144 
00145          /* Pause slightly between each dit and dah */
00146          playtone(chan, 0, 1 * ditlen);
00147       }
00148       /* Pause between characters */
00149       playtone(chan, 0, 2 * ditlen);
00150    }
00151 
00152    return res;
00153 }

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

Definition at line 93 of file app_morsecode.c.

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

Referenced by action_bridge(), and morsecode_exec().

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 }

static int unload_module ( void   )  [static]

Definition at line 155 of file app_morsecode.c.

References ast_unregister_application().

00156 {
00157    return ast_unregister_application(app_morsecode);
00158 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Morse code" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static]

Definition at line 165 of file app_morsecode.c.

char* app_morsecode = "Morsecode" [static]

Definition at line 37 of file app_morsecode.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 165 of file app_morsecode.c.

char* morsecode[] [static]

Definition at line 49 of file app_morsecode.c.

char* morsecode_descrip [static]

Definition at line 41 of file app_morsecode.c.

char* morsecode_synopsis = "Plays morse code" [static]

Definition at line 39 of file app_morsecode.c.


Generated on Fri Jul 24 00:41:10 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7