Mon Mar 19 11:30:32 2012

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, const char *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_LOAD_ORDER , .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 = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static const char app_morsecode [] = "Morsecode"
static struct ast_module_infoast_module_info = &__mod_info
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

static void __reg_module ( void   )  [static]

Definition at line 189 of file app_morsecode.c.

static void __unreg_module ( void   )  [static]

Definition at line 189 of file app_morsecode.c.

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(), 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

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 189 of file app_morsecode.c.

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

Definition at line 71 of file app_morsecode.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 189 of file app_morsecode.c.

const char* const morsecode[] [static]

Definition at line 73 of file app_morsecode.c.


Generated on Mon Mar 19 11:30:32 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7