Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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"   
)

◆ load_module()

static int load_module ( void  )
static

Definition at line 292 of file app_morsecode.c.

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

References app_morsecode, ast_register_application_xml, and morsecode_exec().

◆ morsecode_exec()

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

Definition at line 184 of file app_morsecode.c.

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

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

◆ playtone()

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

Definition at line 173 of file app_morsecode.c.

174{
175 int res;
176 char dtmf[20];
177 snprintf(dtmf, sizeof(dtmf), "%d/%d", tone, len);
178 ast_playtones_start(chan, 0, dtmf, 0);
179 res = ast_safe_sleep(chan, len);
180 ast_playtones_stop(chan);
181 return res;
182}
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1541
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
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:393

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

Referenced by action_bridge(), and morsecode_exec().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 287 of file app_morsecode.c.

288{
290}
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References app_morsecode, and ast_unregister_application().

Variable Documentation

◆ americanmorsecode

const char* const americanmorsecode[]
static

Definition at line 129 of file app_morsecode.c.

Referenced by morsecode_exec().

◆ app_morsecode

const char app_morsecode[] = "Morsecode"
static

Definition at line 83 of file app_morsecode.c.

Referenced by load_module(), and unload_module().

◆ internationalcode

const char* const internationalcode[]
static

Definition at line 85 of file app_morsecode.c.

Referenced by morsecode_exec().