@@ -155,6 +155,21 @@ AST_APP_OPTIONS(read_app_options, {
155
155
static const char * readsf_name = "ReceiveSF" ;
156
156
static const char sendsf_name [] = "SendSF" ;
157
157
158
+ /*!
159
+ * \brief Detects SF digits on channel using DSP
160
+ *
161
+ * \param chan channel on which to read digits
162
+ * \param buf Buffer in which to store digits
163
+ * \param buflen Size of buffer
164
+ * \param timeout ms to wait for all digits before giving up
165
+ * \param maxdigits Maximum number of digits
166
+ * \param freq Frequency to use
167
+ * \param features DSP features
168
+ * \param extrapulses Whether to recognize extra pulses
169
+ *
170
+ * \retval 0 if successful
171
+ * \retval -1 if unsuccessful (including hangup).
172
+ */
158
173
static int read_sf_digits (struct ast_channel * chan , char * buf , int buflen , int timeout , int maxdigits , int freq , int features , int extrapulses ) {
159
174
/* Bell System Technical Journal 39 (Nov. 1960) */
160
175
#define SF_MIN_OFF 25
@@ -169,6 +184,7 @@ static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int t
169
184
char * str = buf ;
170
185
int hits = 0 , digits_read = 0 ;
171
186
unsigned short int sf_on = 0 ;
187
+ int res = 0 ;
172
188
173
189
if (!(dsp = ast_dsp_new ())) {
174
190
ast_log (LOG_WARNING , "Unable to allocate DSP!\n" );
@@ -261,7 +277,7 @@ static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int t
261
277
ast_debug (2 , "Got more than 10 pulses, truncating to 10\n" );
262
278
hits = 0 ; /* 10 dial pulses = digit 0 */
263
279
* str ++ = hits + '0' ;
264
- }
280
+ }
265
281
} else {
266
282
if (hits == 10 ) {
267
283
hits = 0 ; /* 10 dial pulses = digit 0 */
@@ -281,13 +297,14 @@ static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int t
281
297
ast_frfree (frame );
282
298
} else {
283
299
pbx_builtin_setvar_helper (chan , "RECEIVESFSTATUS" , "HANGUP" );
300
+ res = -1 ;
284
301
}
285
302
}
286
303
if (dsp ) {
287
304
ast_dsp_free (dsp );
288
305
}
289
306
ast_debug (3 , "channel '%s' - event loop stopped { timeout: %d, remaining_time: %d }\n" , ast_channel_name (chan ), timeout , remaining_time );
290
- return 0 ;
307
+ return res ;
291
308
}
292
309
293
310
static int read_sf_exec (struct ast_channel * chan , const char * data )
@@ -297,7 +314,7 @@ static int read_sf_exec(struct ast_channel *chan, const char *data)
297
314
double tosec ;
298
315
struct ast_flags flags = {0 };
299
316
char * argcopy = NULL ;
300
- int features = 0 , digits = 0 , to = 0 , freq = 2600 ;
317
+ int res , features = 0 , digits = 0 , to = 0 , freq = 2600 ;
301
318
302
319
AST_DECLARE_APP_ARGS (arglist ,
303
320
AST_APP_ARG (variable );
@@ -360,14 +377,14 @@ static int read_sf_exec(struct ast_channel *chan, const char *data)
360
377
features |= DSP_DIGITMODE_RELAXDTMF ;
361
378
}
362
379
363
- read_sf_digits (chan , tmp , BUFFER_SIZE , to , digits , freq , features , ast_test_flag (& flags , OPT_EXTRAPULSES ));
380
+ res = read_sf_digits (chan , tmp , BUFFER_SIZE , to , digits , freq , features , ast_test_flag (& flags , OPT_EXTRAPULSES ));
364
381
pbx_builtin_setvar_helper (chan , arglist .variable , tmp );
365
382
if (!ast_strlen_zero (tmp )) {
366
383
ast_verb (3 , "SF digits received: '%s'\n" , tmp );
367
- } else {
384
+ } else if (! res ) { /* if channel hung up, don't print anything out */
368
385
ast_verb (3 , "No SF digits received.\n" );
369
386
}
370
- return 0 ;
387
+ return res ;
371
388
}
372
389
373
390
static int sendsf_exec (struct ast_channel * chan , const char * vdata )
0 commit comments