Thu Apr 28 2011 17:13:38

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

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
__MODULE_INFO_SECTION 
__mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Morse code" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static char * app_morsecode = "Morsecode"
static struct ast_module_infoast_module_info = &__mod_info
static char * 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 184 of file app_morsecode.c.

static void __unreg_module ( void  ) [static]

Definition at line 184 of file app_morsecode.c.

static int load_module ( void  ) [static]
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().

{
   int res=0, ditlen, tone;
   char *digit;
   const char *ditlenc, *tonec;

   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "Syntax: Morsecode(<string>) - no argument found\n");
      return 0;
   }

   /* Use variable MORESEDITLEN, if set (else 80) */
   ast_channel_lock(chan);
   ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN");
   if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%30d", &ditlen) != 1)) {
      ditlen = 80;
   }
   ast_channel_unlock(chan);

   /* Use variable MORSETONE, if set (else 800) */
   ast_channel_lock(chan);
   tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
   if (ast_strlen_zero(tonec) || (sscanf(tonec, "%30d", &tone) != 1)) {
      tone = 800;
   }
   ast_channel_unlock(chan);

   for (digit = data; *digit; digit++) {
      int digit2 = *digit;
      char *dahdit;
      if (digit2 < 0) {
         continue;
      }
      for (dahdit = morsecode[digit2]; *dahdit; dahdit++) {
         if (*dahdit == '-') {
            playtone(chan, tone, 3 * ditlen);
         } else if (*dahdit == '.') {
            playtone(chan, tone, 1 * ditlen);
         } else {
            /* Account for ditlen of silence immediately following */
            playtone(chan, 0, 2 * ditlen);
         }

         /* Pause slightly between each dit and dah */
         playtone(chan, 0, 1 * ditlen);
      }
      /* Pause between characters */
      playtone(chan, 0, 2 * ditlen);
   }

   return res;
}
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().

{
   char dtmf[20];
   snprintf(dtmf, sizeof(dtmf), "%d/%d", tone, len);
   ast_playtones_start(chan, 0, dtmf, 0);
   ast_safe_sleep(chan, len);
   ast_playtones_stop(chan);
}
static int unload_module ( void  ) [static]

Definition at line 174 of file app_morsecode.c.

References ast_unregister_application().


Variable Documentation

struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Morse code" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 184 of file app_morsecode.c.

char* app_morsecode = "Morsecode" [static]

Definition at line 66 of file app_morsecode.c.

Definition at line 184 of file app_morsecode.c.

char* morsecode[] [static]

Definition at line 68 of file app_morsecode.c.