Wed Jan 8 2020 09:49:54

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 = "ac1f6a56484a8820659555499174e588" , .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

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

185 {
187 }
static int morsecode_exec(struct ast_channel *chan, const char *data)
static const char app_morsecode[]
Definition: app_morsecode.c:71
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
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().

127 {
128  int res=0, ditlen, tone;
129  const char *digit;
130  const char *ditlenc, *tonec;
131 
132  if (ast_strlen_zero(data)) {
133  ast_log(LOG_WARNING, "Syntax: Morsecode(<string>) - no argument found\n");
134  return 0;
135  }
136 
137  /* Use variable MORESEDITLEN, if set (else 80) */
138  ast_channel_lock(chan);
139  ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN");
140  if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%30d", &ditlen) != 1)) {
141  ditlen = 80;
142  }
143  ast_channel_unlock(chan);
144 
145  /* Use variable MORSETONE, if set (else 800) */
146  ast_channel_lock(chan);
147  tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
148  if (ast_strlen_zero(tonec) || (sscanf(tonec, "%30d", &tone) != 1)) {
149  tone = 800;
150  }
151  ast_channel_unlock(chan);
152 
153  for (digit = data; *digit; digit++) {
154  int digit2 = *digit;
155  const char *dahdit;
156  if (digit2 < 0) {
157  continue;
158  }
159  for (dahdit = morsecode[digit2]; *dahdit; dahdit++) {
160  if (*dahdit == '-') {
161  playtone(chan, tone, 3 * ditlen);
162  } else if (*dahdit == '.') {
163  playtone(chan, tone, 1 * ditlen);
164  } else {
165  /* Account for ditlen of silence immediately following */
166  playtone(chan, 0, 2 * ditlen);
167  }
168 
169  /* Pause slightly between each dit and dah */
170  playtone(chan, 0, 1 * ditlen);
171  }
172  /* Pause between characters */
173  playtone(chan, 0, 2 * ditlen);
174  }
175 
176  return res;
177 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
#define LOG_WARNING
Definition: logger.h:144
static void playtone(struct ast_channel *chan, int tone, int len)
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
Definition: pbx.c:10475
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static const char *const morsecode[]
Definition: app_morsecode.c:73
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
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().

118 {
119  char dtmf[20];
120  snprintf(dtmf, sizeof(dtmf), "%d/%d", tone, len);
121  ast_playtones_start(chan, 0, dtmf, 0);
122  ast_safe_sleep(chan, len);
123  ast_playtones_stop(chan);
124 }
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1916
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:411
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
Definition: indications.c:319
static int unload_module ( void  )
static

Definition at line 179 of file app_morsecode.c.

References ast_unregister_application().

180 {
182 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static const char app_morsecode[]
Definition: app_morsecode.c:71

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 = "ac1f6a56484a8820659555499174e588" , .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.

Definition at line 189 of file app_morsecode.c.

const char* const morsecode[]
static

Definition at line 73 of file app_morsecode.c.