Mon May 14 04:43:46 2007

Asterisk developer's documentation


app_morsecode.c File Reference

Morsecode application. More...

#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/options.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 []
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

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Morse code"   
)

static int load_module ( void   )  [static]

Definition at line 173 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 109 of file app_morsecode.c.

References ast_log(), ast_module_user_add, ast_module_user_remove, ast_strlen_zero(), ast_module_user::chan, LOG_WARNING, pbx_builtin_getvar_helper(), and playtone().

Referenced by load_module().

00110 {
00111    int res=0, ditlen, tone;
00112    char *digit;
00113    const char *ditlenc, *tonec;
00114    struct ast_module_user *u;
00115 
00116    u = ast_module_user_add(chan);
00117 
00118    if (ast_strlen_zero(data)) {
00119       ast_log(LOG_WARNING, "Syntax: Morsecode(<string>) - no argument found\n");
00120       ast_module_user_remove(u);
00121       return 0;
00122    }
00123 
00124    /* Use variable MORESEDITLEN, if set (else 80) */
00125    ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN");
00126    if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%d", &ditlen) != 1)) {
00127       ditlen = 80;
00128    }
00129 
00130    /* Use variable MORSETONE, if set (else 800) */
00131    tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
00132    if (ast_strlen_zero(tonec) || (sscanf(tonec, "%d", &tone) != 1)) {
00133       tone = 800;
00134    }
00135 
00136    for (digit = data; *digit; digit++) {
00137       char *dahdit;
00138       if (*digit < 0) {
00139          continue;
00140       }
00141       for (dahdit = morsecode[(int)*digit]; *dahdit; dahdit++) {
00142          if (*dahdit == '-') {
00143             playtone(chan, tone, 3 * ditlen);
00144          } else if (*dahdit == '.') {
00145             playtone(chan, tone, 1 * ditlen);
00146          } else {
00147             /* Account for ditlen of silence immediately following */
00148             playtone(chan, 0, 2 * ditlen);
00149          }
00150 
00151          /* Pause slightly between each dit and dah */
00152          playtone(chan, 0, 1 * ditlen);
00153       }
00154       /* Pause between characters */
00155       playtone(chan, 0, 2 * ditlen);
00156    }
00157 
00158    ast_module_user_remove(u);
00159    return res;
00160 }

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

Definition at line 100 of file app_morsecode.c.

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

Referenced by morsecode_exec().

00101 {
00102    char dtmf[20];
00103    snprintf(dtmf, sizeof(dtmf), "%d/%d", tone, len);
00104    ast_playtones_start(chan, 0, dtmf, 0);
00105    ast_safe_sleep(chan, len);
00106    ast_playtones_stop(chan);
00107 }

static int unload_module ( void   )  [static]

Definition at line 162 of file app_morsecode.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00163 {
00164    int res;
00165 
00166    res = ast_unregister_application(app_morsecode);
00167 
00168    ast_module_user_hangup_all();
00169 
00170    return res;
00171 }


Variable Documentation

char* app_morsecode = "Morsecode" [static]

Definition at line 44 of file app_morsecode.c.

char* morsecode[] [static]

Definition at line 56 of file app_morsecode.c.

char* morsecode_descrip [static]

Definition at line 48 of file app_morsecode.c.

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

Definition at line 46 of file app_morsecode.c.


Generated on Mon May 14 04:43:47 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1