1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
diff -uNr asterisk-1.6.2.13.ORIG//apps/app_alarmreceiver.c asterisk-1.6.2.13/apps/app_alarmreceiver.c
--- asterisk-1.6.2.13.ORIG//apps/app_alarmreceiver.c 2010-10-15 18:17:49.000000000 +0100
+++ asterisk-1.6.2.13/apps/app_alarmreceiver.c 2010-10-15 18:18:50.000000000 +0100
@@ -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,86 +140,6 @@
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 = 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
@@ -433,19 +354,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);
@@ -552,9 +483,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;
|