#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 | |
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 | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } |
static char * | app_morsecode = "Morsecode" |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static char * | morsecode [] |
static char * | morsecode_descrip |
static char * | morsecode_synopsis = "Plays morse code" |
Definition in file app_morsecode.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 179 of file app_morsecode.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 179 of file app_morsecode.c.
static int load_module | ( | void | ) | [static] |
Definition at line 174 of file app_morsecode.c.
References ast_register_application(), and morsecode_exec().
00175 { 00176 return ast_register_application(app_morsecode, morsecode_exec, morsecode_synopsis, morsecode_descrip); 00177 }
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, "%30d", &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, "%30d", &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 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 179 of file app_morsecode.c.
char* app_morsecode = "Morsecode" [static] |
Definition at line 44 of file app_morsecode.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 179 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.