Asterisk - The Open Source Telephony Project  18.5.0
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"
Include dependency graph for app_morsecode.c:

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 int playtone (struct ast_channel *chan, int tone, int len)
 
static int unload_module (void)
 

Variables

static const char *const americanmorsecode []
 
static const char app_morsecode [] = "Morsecode"
 
static const char *const internationalcode []
 

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
Naveen Albert aster.nosp@m.isk@.nosp@m.phrea.nosp@m.knet.nosp@m..org

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

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

296 {
298 }
static int morsecode_exec(struct ast_channel *chan, const char *data)
static const char app_morsecode[]
Definition: app_morsecode.c:80
#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 181 of file app_morsecode.c.

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

Referenced by load_module().

182 {
183  int res = 0, ditlen, tone, toneoff, digit2;
184  const char *digit;
185  const char *ditlenc, *tonec, *toneb, *codetype;
186 
187  if (ast_strlen_zero(data)) {
188  ast_log(LOG_WARNING, "Syntax: Morsecode(<string>) - no argument found\n");
189  return 0;
190  }
191 
192  /* Use variable MORESEDITLEN, if set (else 80) */
193  ast_channel_lock(chan);
194  ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN");
195  if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%30d", &ditlen) != 1)) {
196  ditlen = 80;
197  }
198  ast_channel_unlock(chan);
199 
200  /* Use variable MORSETONE, if set (else 800) */
201  ast_channel_lock(chan);
202  tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
203  if (ast_strlen_zero(tonec) || (sscanf(tonec, "%30d", &tone) != 1)) {
204  tone = 800;
205  }
206  ast_channel_unlock(chan);
207 
208  /* Use variable MORSEOFF, if set (else 0) */
209  ast_channel_lock(chan);
210  toneb = pbx_builtin_getvar_helper(chan, "MORSEOFF");
211  if (ast_strlen_zero(toneb) || (sscanf(toneb, "%30d", &toneoff) != 1)) {
212  toneoff = 0;
213  }
214  ast_channel_unlock(chan);
215 
216  /* Use variable MORSETYPE, if set (else INTERNATIONAL) */
217  ast_channel_lock(chan);
218  codetype = pbx_builtin_getvar_helper(chan, "MORSETYPE");
219  if (!codetype || strcmp(codetype, "AMERICAN")) {
220  codetype = "INTERNATIONAL";
221  }
222  ast_channel_unlock(chan);
223 
224  if (!strcmp(codetype, "AMERICAN")) {
225  for (digit = data; *digit; digit++) {
226  const char *dahdit;
227  digit2 = *digit;
228  if (digit2 < 0 || digit2 > 127) {
229  continue;
230  }
231  for (dahdit = americanmorsecode[digit2]; *dahdit; dahdit++) {
232  if (*dahdit == '-') {
233  res = playtone(chan, tone, 3 * ditlen);
234  } else if (*dahdit == '.') {
235  res = playtone(chan, tone, 1 * ditlen);
236  } else if (*dahdit == 'L') {
237  res = playtone(chan, tone, 6 * ditlen); /* long dash */
238  } else if (*dahdit == '0') {
239  res = playtone(chan, tone, 9 * ditlen); /* extra long dash */
240  } else if (*dahdit == ' ') { /* space char (x20) = 6 dot lengths */
241  /* Intra-char pauses, specific to American Morse */
242  res = playtone(chan, toneoff, 3 * ditlen);
243  } else {
244  /* Account for ditlen of silence immediately following */
245  res = playtone(chan, toneoff, 2 * ditlen);
246  }
247 
248  /* Pause slightly between each dit and dah */
249  res = playtone(chan, toneoff, 1 * ditlen);
250  if (res)
251  break;
252  }
253  /* Pause between characters */
254  res = playtone(chan, toneoff, 3 * ditlen);
255  if (res)
256  break;
257  }
258  } else { /* International */
259  for (digit = data; *digit; digit++) {
260  const char *dahdit;
261  digit2 = *digit;
262  if (digit2 < 0 || digit2 > 127) {
263  continue;
264  }
265  for (dahdit = internationalcode[digit2]; *dahdit; dahdit++) {
266  if (*dahdit == '-') {
267  res = playtone(chan, tone, 3 * ditlen);
268  } else if (*dahdit == '.') {
269  res = playtone(chan, tone, 1 * ditlen);
270  } else {
271  /* Account for ditlen of silence immediately following */
272  res = playtone(chan, toneoff, 2 * ditlen);
273  }
274 
275  /* Pause slightly between each dit and dah */
276  res = playtone(chan, toneoff, 1 * ditlen);
277  if (res)
278  break;
279  }
280  /* Pause between characters */
281  res = playtone(chan, toneoff, 2 * ditlen);
282  if (res)
283  break;
284  }
285  }
286 
287  return res;
288 }
char digit
#define ast_channel_lock(chan)
Definition: channel.h:2945
static int playtone(struct ast_channel *chan, int tone, int len)
#define LOG_WARNING
Definition: logger.h:274
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_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
static const char *const internationalcode[]
Definition: app_morsecode.c:82
static const char *const americanmorsecode[]
#define ast_channel_unlock(chan)
Definition: channel.h:2946

◆ playtone()

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

Definition at line 170 of file app_morsecode.c.

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

Referenced by action_bridge(), and morsecode_exec().

171 {
172  int res;
173  char dtmf[20];
174  snprintf(dtmf, sizeof(dtmf), "%d/%d", tone, len);
175  ast_playtones_start(chan, 0, dtmf, 0);
176  res = ast_safe_sleep(chan, len);
177  ast_playtones_stop(chan);
178  return res;
179 }
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1574
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 290 of file app_morsecode.c.

References app_morsecode, and ast_unregister_application().

291 {
293 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
static const char app_morsecode[]
Definition: app_morsecode.c:80

Variable Documentation

◆ americanmorsecode

const char* const americanmorsecode[]
static

Definition at line 126 of file app_morsecode.c.

Referenced by morsecode_exec().

◆ app_morsecode

const char app_morsecode[] = "Morsecode"
static

Definition at line 80 of file app_morsecode.c.

Referenced by load_module(), and unload_module().

◆ internationalcode

const char* const internationalcode[]
static

Definition at line 82 of file app_morsecode.c.

Referenced by morsecode_exec().