Index: apps/app_alarmreceiver.c =================================================================== --- apps/app_alarmreceiver.c (revision 287304) +++ apps/app_alarmreceiver.c (working copy) @@ -51,6 +51,7 @@ #include "asterisk/callerid.h" #include "asterisk/astdb.h" #include "asterisk/utils.h" +#include "asterisk/indications.h" #define ALMRCV_CONFIG "alarmreceiver.conf" #define ADEMCO_CONTACT_ID "ADEMCO_CONTACT_ID" @@ -139,87 +140,7 @@ return; } - /* -* Build a MuLaw data block for a single frequency tone -*/ -static void make_tone_burst(unsigned char *data, float freq, float loudness, int len, int *x) -{ - int i; - float val; - - for (i = 0; i < len; i++) { - val = loudness * sin((freq * 2.0 * M_PI * (*x)++)/8000.0); - data[i] = AST_LIN2MU((int)val); - } - - /* wrap back around from 8000 */ - - if (*x >= 8000) - *x = 0; - return; -} - -/* -* Send a single tone burst for a specifed duration and frequency. -* Returns 0 if successful -*/ -static int send_tone_burst(struct ast_channel *chan, float freq, int duration, int tldn) -{ - int res = 0; - int i = 0; - int x = 0; - struct ast_frame *f, wf; - - struct { - unsigned char offset[AST_FRIENDLY_OFFSET]; - unsigned char buf[640]; - } tone_block; - - for (;;) { - - if (ast_waitfor(chan, -1) < 0) { - res = -1; - break; - } - - f = ast_read(chan); - if (!f) { - res = -1; - break; - } - - if (f->frametype == AST_FRAME_VOICE) { - wf.frametype = AST_FRAME_VOICE; - wf.subclass.codec = AST_FORMAT_ULAW; - wf.offset = AST_FRIENDLY_OFFSET; - wf.mallocd = 0; - wf.data.ptr = tone_block.buf; - wf.datalen = f->datalen; - wf.samples = wf.datalen; - - make_tone_burst(tone_block.buf, freq, (float) tldn, wf.datalen, &x); - - i += wf.datalen / 8; - if (i > duration) { - ast_frfree(f); - break; - } - if (ast_write(chan, &wf)) { - ast_verb(4, "AlarmReceiver: Failed to write frame on %s\n", chan->name); - ast_log(LOG_WARNING, "AlarmReceiver Failed to write frame on %s\n",chan->name); - res = -1; - ast_frfree(f); - break; - } - } - - ast_frfree(f); - } - return res; -} - -/* * Receive a string of DTMF digits where the length of the digit string is known in advance. Do not give preferential * treatment to any digit value, and allow separate time out values to be specified for the first digit and all subsequent * digits. @@ -437,19 +358,29 @@ database_increment("calls-received"); /* Wait for first event */ - ast_verb(4, "AlarmReceiver: Waiting for first event from panel\n"); + ast_verb(4, "AlarmReceiver: Waiting for first event from panel...\n"); while (res >= 0) { if (got_some_digits == 0) { /* Send ACK tone sequence */ ast_verb(4, "AlarmReceiver: Sending 1400Hz 100ms burst (ACK)\n"); - res = send_tone_burst(chan, 1400.0, 100, tldn); - if (!res) - res = ast_safe_sleep(chan, 100); + res = ast_playtones_start(chan, tldn, "1400", 0); if (!res) { + ast_safe_sleep(chan, 100); + ast_playtones_stop(chan); + } + if (!res) { + ast_safe_sleep(chan, 100); ast_verb(4, "AlarmReceiver: Sending 2300Hz 100ms burst (ACK)\n"); - res = send_tone_burst(chan, 2300.0, 100, tldn); + res = ast_playtones_start(chan, tldn, "2300", 0); + if (!res) { + ast_safe_sleep(chan, 100); + ast_playtones_stop(chan); + } + } else { + ast_debug(1, "AlarmReceiver: Failed sending tones\n"); } + } if ( res >= 0) res = receive_dtmf_digits(chan, event, sizeof(event) - 1, fdto, sdto); @@ -556,9 +487,14 @@ if (res == 0) res = ast_safe_sleep(chan, 200); - /* Send the kissoff tone */ - if (res == 0) - res = send_tone_burst(chan, 1400.0, 900, tldn); + /* Send the kissoff tone (1400 Hz, 900 ms) */ + if (res == 0) { + res = ast_playtones_start(chan, tldn, "1400", 0); + if (res == 0) { + ast_safe_sleep(chan, 900); + ast_playtones_stop(chan); + } + } } return res;