Asterisk - The Open Source Telephony Project  GIT-master-9ed6387
Functions | Variables
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

 AST_MODULE_INFO_STANDARD_EXTENDED (ASTERISK_GPL_KEY, "Morse code")
 
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 const char app_morsecode [] = "Morsecode"
 
static const char *const morsecode []
 

Detailed Description

Morsecode application.

Author
Tilghman Lesher app_m.nosp@m.orse.nosp@m.code_.nosp@m._v00.nosp@m.1@the.nosp@m.-til.nosp@m.ghman.nosp@m..com

Definition in file app_morsecode.c.

Function Documentation

◆ AST_MODULE_INFO_STANDARD_EXTENDED()

AST_MODULE_INFO_STANDARD_EXTENDED ( ASTERISK_GPL_KEY  ,
"Morse code"   
)

Referenced by load_module().

◆ load_module()

static int load_module ( void  )
static

Definition at line 182 of file app_morsecode.c.

References app_morsecode, AST_MODULE_INFO_STANDARD_EXTENDED(), ast_register_application_xml, ASTERISK_GPL_KEY, and morsecode_exec().

183 {
185 }
static int morsecode_exec(struct ast_channel *chan, const char *data)
static const char app_morsecode[]
Definition: app_morsecode.c:69
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ morsecode_exec()

static int morsecode_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 124 of file app_morsecode.c.

References ast_channel_lock, ast_channel_unlock, ast_log, ast_strlen_zero, digit, LOG_WARNING, morsecode, pbx_builtin_getvar_helper(), and playtone().

Referenced by load_module().

125 {
126  int res=0, ditlen, tone;
127  const char *digit;
128  const char *ditlenc, *tonec;
129 
130  if (ast_strlen_zero(data)) {
131  ast_log(LOG_WARNING, "Syntax: Morsecode(<string>) - no argument found\n");
132  return 0;
133  }
134 
135  /* Use variable MORESEDITLEN, if set (else 80) */
136  ast_channel_lock(chan);
137  ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN");
138  if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%30d", &ditlen) != 1)) {
139  ditlen = 80;
140  }
141  ast_channel_unlock(chan);
142 
143  /* Use variable MORSETONE, if set (else 800) */
144  ast_channel_lock(chan);
145  tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
146  if (ast_strlen_zero(tonec) || (sscanf(tonec, "%30d", &tone) != 1)) {
147  tone = 800;
148  }
149  ast_channel_unlock(chan);
150 
151  for (digit = data; *digit; digit++) {
152  int digit2 = *digit;
153  const char *dahdit;
154  if (digit2 < 0) {
155  continue;
156  }
157  for (dahdit = morsecode[digit2]; *dahdit; dahdit++) {
158  if (*dahdit == '-') {
159  playtone(chan, tone, 3 * ditlen);
160  } else if (*dahdit == '.') {
161  playtone(chan, tone, 1 * ditlen);
162  } else {
163  /* Account for ditlen of silence immediately following */
164  playtone(chan, 0, 2 * ditlen);
165  }
166 
167  /* Pause slightly between each dit and dah */
168  playtone(chan, 0, 1 * ditlen);
169  }
170  /* Pause between characters */
171  playtone(chan, 0, 2 * ditlen);
172  }
173 
174  return res;
175 }
char digit
#define ast_channel_lock(chan)
Definition: channel.h:2837
#define LOG_WARNING
Definition: logger.h:274
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.
#define ast_log
Definition: astobj2.c:42
static const char *const morsecode[]
Definition: app_morsecode.c:71
#define ast_strlen_zero(a)
Definition: muted.c:73
#define ast_channel_unlock(chan)
Definition: channel.h:2838

◆ playtone()

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

Definition at line 115 of file app_morsecode.c.

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

Referenced by action_bridge(), and morsecode_exec().

116 {
117  char dtmf[20];
118  snprintf(dtmf, sizeof(dtmf), "%d/%d", tone, len);
119  ast_playtones_start(chan, 0, dtmf, 0);
120  ast_safe_sleep(chan, len);
121  ast_playtones_stop(chan);
122 }
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1554
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:393
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:302

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 177 of file app_morsecode.c.

References app_morsecode, and ast_unregister_application().

178 {
180 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
static const char app_morsecode[]
Definition: app_morsecode.c:69

Variable Documentation

◆ app_morsecode

const char app_morsecode[] = "Morsecode"
static

Definition at line 69 of file app_morsecode.c.

Referenced by load_module(), and unload_module().

◆ morsecode

const char* const morsecode[]
static

Definition at line 71 of file app_morsecode.c.

Referenced by morsecode_exec().