Tue Nov 4 13:20:24 2008

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"

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 174 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       int digit2 = *digit;
00138       char *dahdit;
00139       if (digit2 < 0) {
00140          continue;
00141       }
00142       for (dahdit = morsecode[digit2]; *dahdit; dahdit++) {
00143          if (*dahdit == '-') {
00144             playtone(chan, tone, 3 * ditlen);
00145          } else if (*dahdit == '.') {
00146             playtone(chan, tone, 1 * ditlen);
00147          } else {
00148             /* Account for ditlen of silence immediately following */
00149             playtone(chan, 0, 2 * ditlen);
00150          }
00151 
00152          /* Pause slightly between each dit and dah */
00153          playtone(chan, 0, 1 * ditlen);
00154       }
00155       /* Pause between characters */
00156       playtone(chan, 0, 2 * ditlen);
00157    }
00158 
00159    ast_module_user_remove(u);
00160    return res;
00161 }

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 163 of file app_morsecode.c.

References ast_module_user_hangup_all, and ast_unregister_application().

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


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 Tue Nov 4 13:20:24 2008 for Asterisk - the Open Source PBX by  doxygen 1.4.7