Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/testadsi.c @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 15:50:58 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * testadsi.c | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2003 Steve Underwood | |
9 * | |
10 * All rights reserved. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License version 2, as | |
14 * published by the Free Software Foundation. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 * | |
25 * $Id: testadsi.c,v 1.23 2009/05/30 15:23:14 steveu Exp $ | |
26 */ | |
27 | |
28 #if defined(HAVE_CONFIG_H) | |
29 #include <config.h> | |
30 #endif | |
31 | |
32 #include <fcntl.h> | |
33 #include <stdio.h> | |
34 #include <string.h> | |
35 #include <errno.h> | |
36 #include <sys/ioctl.h> | |
37 #include <stdlib.h> | |
38 #include <inttypes.h> | |
39 #include <sys/signal.h> | |
40 #include <sys/select.h> | |
41 #include <sys/wait.h> | |
42 #include <sys/resource.h> | |
43 #include <sys/time.h> | |
44 | |
45 #if defined(HAVE_LIBUNICALL) | |
46 | |
47 #include <linux/zaptel.h> | |
48 #include <pthread.h> | |
49 #include <sndfile.h> | |
50 #include <tiffio.h> | |
51 | |
52 #include "unicall.h" | |
53 //#include "../libmfcr2/libmfcr2.h" | |
54 //#include "../libpri/libpri.h" | |
55 | |
56 #include "spandsp.h" | |
57 | |
58 #define FALSE 0 | |
59 #define TRUE (!FALSE) | |
60 | |
61 int caller_mode = FALSE; | |
62 static SNDFILE *rxhandle; | |
63 static SNDFILE *txhandle; | |
64 | |
65 #if 0 | |
66 int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) | |
67 { | |
68 int len; | |
69 | |
70 len = adsi_add_field(s, msg, -1, CLASS_SDMF_CALLERID, 0); | |
71 len = adsi_add_field(s, msg, len, 0, "10011750", 8); | |
72 len = adsi_add_field(s, msg, len, 0, "6095551212", 10); | |
73 return len; | |
74 } | |
75 #endif | |
76 #if 0 | |
77 int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) | |
78 { | |
79 int len; | |
80 | |
81 len = adsi_add_field(s, msg, -1, CLIP_MDMF_CALLERID, 0); | |
82 len = adsi_add_field(s, msg, len, CLIP_CALLTYPE, "\x81", 1); | |
83 len = adsi_add_field(s, msg, len, CLIP_DATETIME, "10011750", 8); | |
84 len = adsi_add_field(s, msg, len, CLIP_CALLER_NUMBER, "12345678", 8); | |
85 len = adsi_add_field(s, msg, len, CLIP_DIALED_NUMBER, "87654321", 8); | |
86 len = adsi_add_field(s, msg, len, CLIP_CALLER_NAME, "Steve Underwood", 15); | |
87 return len; | |
88 } | |
89 #endif | |
90 #if 0 | |
91 int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) | |
92 { | |
93 int len; | |
94 | |
95 len = adsi_add_field(s, msg, -1, CLIP_MDMF_CALLERID, 0); | |
96 len = adsi_add_field(s, msg, len, CLIP_NUM_MSG, "\x03", 1); | |
97 return len; | |
98 } | |
99 #endif | |
100 #if 0 | |
101 int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) | |
102 { | |
103 int len; | |
104 | |
105 len = adsi_add_field(s, msg, -1, CLIP_MDMF_MSG_WAITING, NULL, 0); | |
106 len = adsi_add_field(s, msg, len, CLIP_VISUAL_INDICATOR, "\x00", 1); | |
107 return len; | |
108 } | |
109 #endif | |
110 #if 0 | |
111 int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) | |
112 { | |
113 int len; | |
114 | |
115 len = adsi_add_field(s, msg, -1, CLIP_MDMF_MSG_WAITING, NULL, 0); | |
116 len = adsi_add_field(s, msg, len, CLIP_VISUAL_INDICATOR, "\xFF", 1); | |
117 len = adsi_add_field(s, msg, len, CLIP_NUM_MSG, "\x05", 1); | |
118 return len; | |
119 } | |
120 #endif | |
121 #if 1 | |
122 int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) | |
123 { | |
124 int len; | |
125 | |
126 len = adsi_add_field(s, msg, -1, CLASS_SDMF_MSG_WAITING, NULL, 0); | |
127 len = adsi_add_field(s, msg, len, 0, "\x6F", 1); | |
128 len = adsi_add_field(s, msg, len, 0, "\x6F", 1); | |
129 len = adsi_add_field(s, msg, len, 0, "\x6F", 1); | |
130 return len; | |
131 } | |
132 #endif | |
133 #if 0 | |
134 int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) | |
135 { | |
136 int len; | |
137 | |
138 len = adsi_add_field(s, msg, -1, CLASS_SDMF_MSG_WAITING, NULL, 0); | |
139 len = adsi_add_field(s, msg, len, 0, "\x42", 1); | |
140 len = adsi_add_field(s, msg, len, 0, "\x42", 1); | |
141 len = adsi_add_field(s, msg, len, 0, "\x42", 1); | |
142 return len; | |
143 } | |
144 #endif | |
145 #if 0 | |
146 int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) | |
147 { | |
148 int len; | |
149 | |
150 len = adsi_add_field(s, msg, -1, CLIP_MDMF_SMS, NULL, 0); | |
151 len = adsi_add_field(s, msg, len, CLIP_DISPLAY_INFO, "\x00ABC", 4); | |
152 return len; | |
153 } | |
154 #endif | |
155 | |
156 struct | |
157 { | |
158 pthread_t thread; | |
159 int chan; | |
160 int sig_fd; | |
161 int fd; | |
162 uc_call_t *call; | |
163 uc_crn_t crn; | |
164 int xxx; | |
165 int cause; | |
166 | |
167 dtmf_rx_state_t dtmf_state; | |
168 char dtmf[101]; | |
169 int dtmf_ptr; | |
170 | |
171 char *tag; | |
172 | |
173 char originating_number[32]; | |
174 char destination_number[32]; | |
175 | |
176 adsi_rx_state_t adsi_rx; | |
177 adsi_tx_state_t adsi_tx; | |
178 } chan_stuff[30]; | |
179 | |
180 tone_gen_descriptor_t tone_desc; | |
181 tone_gen_state_t gen; | |
182 | |
183 void channel_read_adsi_channel(uc_t *uc, int chan, void *user_data, uint8_t *buf, int len); | |
184 int channel_write_adsi_channel(uc_t *uc, int chan, void *user_data, uint8_t *buf, int max_len); | |
185 int channel_error(uc_t *uc, int chan, void *user_data, int cause); | |
186 int signaling_error(uc_t *uc, void *user_data, int cause); | |
187 | |
188 void channel_read_adsi_channel(uc_t *uc, int chan, void *user_data, uint8_t *buf, int len) | |
189 { | |
190 int i; | |
191 int xlen; | |
192 int16_t pcm_buf[1024]; | |
193 char *s; | |
194 int outframes; | |
195 | |
196 for (i = 0; i < len; i++) | |
197 pcm_buf[i] = alaw_to_linear(buf[i]); | |
198 /*endfor*/ | |
199 outframes = sf_writef_short(rxhandle, | |
200 AF_DEFAULT_TRACK, | |
201 pcm_buf, | |
202 len); | |
203 if (outframes != len) | |
204 { | |
205 printf("Failed to write %d samples\n", len); | |
206 exit(2); | |
207 } | |
208 | |
209 dtmf_rx(&chan_stuff[chan].dtmf_state, pcm_buf, len); | |
210 xlen = dtmf_rx_get(&chan_stuff[chan].dtmf_state, | |
211 chan_stuff[chan].dtmf + chan_stuff[chan].dtmf_ptr, | |
212 100 - chan_stuff[chan].dtmf_ptr); | |
213 if (xlen > 0) | |
214 { | |
215 s = chan_stuff[chan].dtmf + chan_stuff[chan].dtmf_ptr; | |
216 while (*s) | |
217 { | |
218 if (*s == '#') | |
219 { | |
220 uc_set_channel_read_callback(uc, 0, NULL, 0); | |
221 uc_set_channel_write_callback(uc, 0, NULL, 0); | |
222 if (uc_call_control(uc, UC_OP_DROPCALL, chan_stuff[chan].crn, (void *) UC_CAUSE_NORMAL_CLEARING)) | |
223 printf ("A Drop Call failed\n"); | |
224 /*endif*/ | |
225 break; | |
226 } | |
227 /*endif*/ | |
228 s++; | |
229 } | |
230 /*endwhile*/ | |
231 printf("Got '%s'\n", chan_stuff[chan].dtmf); | |
232 chan_stuff[chan].dtmf_ptr += xlen; | |
233 } | |
234 /*endif*/ | |
235 adsi_rx(&(chan_stuff[chan].adsi_rx), pcm_buf, len); | |
236 } | |
237 /*- End of function --------------------------------------------------------*/ | |
238 | |
239 int channel_write_adsi_channel(uc_t *uc, int chan, void *user_data, uint8_t *buf, int max_len) | |
240 { | |
241 int16_t pcm_buf[1024]; | |
242 int len; | |
243 int i; | |
244 static int block = 0; | |
245 uint8_t adsi_msg[256]; | |
246 int adsi_msg_len; | |
247 | |
248 if (++block == 100) | |
249 { | |
250 adsi_send_alert_tone(&(chan_stuff[chan].adsi_tx)); | |
251 printf("Alert tone sent\n"); | |
252 adsi_msg_len = adsi_create_message(&(chan_stuff[chan].adsi_tx), adsi_msg); | |
253 if ((len = adsi_put_message(&(chan_stuff[chan].adsi_tx), adsi_msg, adsi_msg_len)) > 0) | |
254 printf("Message put - %d bytes\n", len); | |
255 } | |
256 len = adsi_tx(&(chan_stuff[chan].adsi_tx), pcm_buf, max_len); | |
257 sf_writef_short(txhandle, | |
258 AF_DEFAULT_TRACK, | |
259 pcm_buf, | |
260 len); | |
261 for (i = 0; i < len; i++) | |
262 buf[i] = linear_to_alaw(pcm_buf[i]); | |
263 /*endfor*/ | |
264 return len; | |
265 } | |
266 /*- End of function --------------------------------------------------------*/ | |
267 | |
268 int channel_error(uc_t *uc, int chan, void *user_data, int cause) | |
269 { | |
270 printf("Error %d\n", cause); | |
271 return 0; | |
272 } | |
273 /*- End of function --------------------------------------------------------*/ | |
274 | |
275 int signaling_error(uc_t *uc, void *user_data, int cause) | |
276 { | |
277 printf("Error %d\n", cause); | |
278 return 0; | |
279 } | |
280 /*- End of function --------------------------------------------------------*/ | |
281 | |
282 static void initiate_call(uc_t *uc, int chan, uc_event_t *e) | |
283 { | |
284 uc_makecall_t makecall; | |
285 uc_callparms_t *callparms; | |
286 int ret; | |
287 | |
288 printf ("Initiating call\n"); | |
289 if ((callparms = uc_new_callparms(NULL)) == NULL) | |
290 return; | |
291 /*endif*/ | |
292 uc_callparm_originating_number(callparms, chan_stuff[chan].originating_number); | |
293 uc_callparm_destination_number(callparms, chan_stuff[chan].destination_number); | |
294 makecall.callparms = callparms; | |
295 makecall.crn = 0; | |
296 if (ret = uc_call_control(uc, UC_OP_MAKECALL, 0, (void *) &makecall) != UC_RET_OK) | |
297 fprintf(stderr, "Make Call failed - %d\n", ret); | |
298 /*endif*/ | |
299 chan_stuff[chan].crn = makecall.crn; | |
300 free(callparms); | |
301 } | |
302 /*- End of function --------------------------------------------------------*/ | |
303 | |
304 static void handle_uc_event(uc_t *uc, void *user_data, uc_event_t *e) | |
305 { | |
306 int chan; | |
307 | |
308 chan = (int) user_data; | |
309 printf ("-- %s (%d)\n", uc_event2str(e->e), chan); | |
310 switch (e->e) | |
311 { | |
312 case UC_EVENT_DEVICEFAIL: | |
313 break; | |
314 case UC_EVENT_PROTOCOLFAIL: | |
315 printf("-- Protocol failure on channel %d, cause %d\n", e->gen.channel, e->gen.data); | |
316 break; | |
317 case UC_EVENT_SIGCHANSTATUS: | |
318 printf("-- Signalling channel status - %s\n", e->sigchanstatus.ok ? "Up" : "Down"); | |
319 break; | |
320 case UC_EVENT_ALARM: | |
321 printf("-- Alarm - 0x%X 0x%X\n", e->alarm.raised, e->alarm.cleared); | |
322 break; | |
323 case UC_EVENT_FARBLOCKED: | |
324 printf("-- Channel far end blocked! :-(\n"); | |
325 chan_stuff[chan].xxx &= ~1; | |
326 break; | |
327 case UC_EVENT_FARUNBLOCKED: | |
328 printf("-- Channel far end unblocked! :-)\n"); | |
329 chan_stuff[chan].xxx |= 1; | |
330 if (chan_stuff[chan].xxx == 3) | |
331 { | |
332 if (caller_mode) | |
333 initiate_call(uc, chan, e); | |
334 /*endif*/ | |
335 } | |
336 /*endif*/ | |
337 break; | |
338 case UC_EVENT_LOCALBLOCKED: | |
339 printf("-- Channel local end blocked! :-(\n"); | |
340 chan_stuff[chan].xxx &= ~2; | |
341 break; | |
342 case UC_EVENT_LOCALUNBLOCKED: | |
343 printf("-- Channel local end unblocked! :-)\n"); | |
344 chan_stuff[chan].xxx |= 2; | |
345 if (chan_stuff[chan].xxx == 3) | |
346 { | |
347 if (caller_mode) | |
348 initiate_call(uc, chan, e); | |
349 /*endif*/ | |
350 } | |
351 /*endif*/ | |
352 break; | |
353 case UC_EVENT_DIALING: | |
354 printf("-- Dialing on channel %d\n", e->gen.channel); | |
355 break; | |
356 case UC_EVENT_ACCEPTED: | |
357 printf("-- Accepted on channel %d\n", e->gen.channel); | |
358 if (uc_call_control(uc, UC_OP_ANSWERCALL, e->gen.crn, (void *) -1)) | |
359 fprintf(stderr, "Answer Call failed\n"); | |
360 /*endif*/ | |
361 break; | |
362 case UC_EVENT_DETECTED: | |
363 printf("-- Detected on channel %d\n", e->gen.channel); | |
364 break; | |
365 case UC_EVENT_ALERTING: | |
366 printf("-- Alerting on channel %d\n", e->gen.channel); | |
367 /* This is just a notification of call progress. We need take no action at this point. */ | |
368 break; | |
369 case UC_EVENT_FARDISCONNECTED: | |
370 printf("-- Far end disconnected on channel %d\n", e->fardisconnected.channel); | |
371 /* Kill any outstanding audio processing */ | |
372 uc_set_channel_read_callback(uc, 0, NULL, 0); | |
373 uc_set_channel_write_callback(uc, 0, NULL, 0); | |
374 if (uc_call_control(uc, UC_OP_DROPCALL, e->fardisconnected.crn, (void *) UC_CAUSE_NORMAL_CLEARING)) | |
375 fprintf(stderr, "C Drop Call failed\n"); | |
376 /*endif*/ | |
377 break; | |
378 case UC_EVENT_DROPCALL: | |
379 printf("-- Drop call on channel %d\n", e->gen.channel); | |
380 if (uc_call_control(uc, UC_OP_RELEASECALL, e->gen.crn, NULL)) | |
381 fprintf(stderr, "uc_ReleaseCall failed\n"); | |
382 /*endif*/ | |
383 break; | |
384 case UC_EVENT_RELEASECALL: | |
385 printf("-- Released on channel %d\n", e->gen.channel); | |
386 if (caller_mode) | |
387 initiate_call(uc, chan, e); | |
388 /*endif*/ | |
389 break; | |
390 case UC_EVENT_OFFERED: | |
391 printf("-- Offered on channel %d, CRN %d (ANI: %s, DNIS: %s)\n", e->offered.channel, e->offered.crn, e->offered.parms.originating_number, e->offered.parms.destination_number); | |
392 if (!caller_mode) | |
393 { | |
394 switch (chan_stuff[chan].cause) | |
395 { | |
396 case 0: | |
397 if (uc_call_control(uc, UC_OP_ACCEPTCALL, e->offered.crn, (void *) -1)) | |
398 fprintf(stderr, "uc_AcceptCall failed\n"); | |
399 /*endif*/ | |
400 break; | |
401 case 1: | |
402 if (uc_call_control(uc, UC_OP_ANSWERCALL, e->offered.crn, (void *) -1)) | |
403 fprintf(stderr, "uc_AnswerCall failed\n"); | |
404 /*endif*/ | |
405 break; | |
406 case 2: | |
407 if (uc_call_control(uc, UC_OP_DROPCALL, e->offered.crn, (void *) UC_CAUSE_USER_BUSY)) | |
408 fprintf(stderr, "E Drop Call failed\n"); | |
409 /*endif*/ | |
410 break; | |
411 case 3: | |
412 if (uc_call_control(uc, UC_OP_DROPCALL, e->offered.crn, (void *) UC_CAUSE_UNASSIGNED_NUMBER)) | |
413 fprintf(stderr, "F Drop Call failed\n"); | |
414 /*endif*/ | |
415 break; | |
416 case 4: | |
417 if (uc_call_control(uc, UC_OP_DROPCALL, e->offered.crn, (void *) UC_CAUSE_NETWORK_CONGESTION)) | |
418 fprintf(stderr, "G Drop Call failed\n"); | |
419 /*endif*/ | |
420 break; | |
421 case 5: | |
422 if (uc_call_control(uc, UC_OP_DROPCALL, e->offered.crn, (void *) UC_CAUSE_DEST_OUT_OF_ORDER)) | |
423 fprintf(stderr, "H Drop Call failed\n"); | |
424 /*endif*/ | |
425 break; | |
426 } | |
427 /*endswitch*/ | |
428 if (++chan_stuff[chan].cause > 5) | |
429 chan_stuff[chan].cause = 0; | |
430 /*endif*/ | |
431 } | |
432 /*endif*/ | |
433 break; | |
434 case UC_EVENT_ANSWERED: | |
435 printf("-- Answered on channel %d\n", e->gen.channel); | |
436 uc_set_channel_read_callback(uc, 0, channel_read_adsi_channel, (void *) chan); | |
437 printf("XXX read callback set\n"); | |
438 uc_set_channel_write_callback(uc, 0, channel_write_adsi_channel, (void *) chan); | |
439 printf("XXX write callback set\n"); | |
440 adsi_tx_init(&(chan_stuff[chan].adsi_tx), ADSI_STANDARD_CLASS); | |
441 printf("XXX ADSI inited\n"); | |
442 dtmf_rx_init(&chan_stuff[chan].dtmf_state, NULL, NULL); | |
443 printf("XXX DTMF inited\n"); | |
444 break; | |
445 case UC_EVENT_CONNECTED: | |
446 printf("-- Connected on channel %d\n", e->gen.channel); | |
447 if (uc_call_control(uc, UC_OP_DROPCALL, e->offered.crn, (void *) UC_CAUSE_NORMAL_CLEARING)) | |
448 printf ("I Drop Call failed\n"); | |
449 /*endif*/ | |
450 break; | |
451 default: | |
452 fprintf(stderr, "--!! Unknown signaling event %d\n", e->e); | |
453 break; | |
454 } | |
455 /*endswitch*/ | |
456 } | |
457 /*- End of function --------------------------------------------------------*/ | |
458 | |
459 static void *run_uc(void *arg) | |
460 { | |
461 uc_t *uc; | |
462 uc_event_t *e; | |
463 struct timeval tv = {0,0}; | |
464 struct timeval *next; | |
465 fd_set rfds; | |
466 fd_set wfds; | |
467 fd_set efds; | |
468 int res; | |
469 int dfd; | |
470 int chan; | |
471 | |
472 chan = *((int *) arg); | |
473 | |
474 dfd = chan_stuff[chan].fd; | |
475 uc = uc_new(dfd, dfd, "mfcr2", "cn", UC_MODE_CPE, 1); | |
476 //uc = uc_new(dfd, dfd, "pri", "ctr4", UC_MODE_CPE, 1); | |
477 if (uc == NULL) | |
478 { | |
479 fprintf(stderr, "Unable to create instance\n"); | |
480 return NULL; | |
481 } | |
482 /*endif*/ | |
483 uc_set_signaling_callback(uc, handle_uc_event, (void *) chan); | |
484 uc_set_signaling_error_callback(uc, signaling_error, (void *) chan); | |
485 uc_set_channel_error_callback(uc, 0, channel_error, (void *) chan); | |
486 uc_set_logging(uc, 0x7FFFFFFF, 0, chan_stuff[chan].tag); | |
487 uc_call_control(uc, UC_OP_UNBLOCK, 0, (void *) -1); | |
488 for (;;) | |
489 { | |
490 FD_ZERO(&rfds); | |
491 FD_ZERO(&wfds); | |
492 FD_ZERO(&efds); | |
493 FD_SET(dfd, &rfds); | |
494 FD_SET(dfd, &wfds); | |
495 FD_SET(dfd, &efds); | |
496 | |
497 if ((next = uc_schedule_next(uc))) | |
498 { | |
499 gettimeofday(&tv, NULL); | |
500 tv.tv_sec = next->tv_sec - tv.tv_sec; | |
501 tv.tv_usec = next->tv_usec - tv.tv_usec; | |
502 if (tv.tv_usec < 0) | |
503 { | |
504 tv.tv_usec += 1000000; | |
505 tv.tv_sec -= 1; | |
506 } | |
507 /*endif*/ | |
508 if (tv.tv_sec < 0) | |
509 { | |
510 tv.tv_sec = 0; | |
511 tv.tv_usec = 0; | |
512 } | |
513 /*endif*/ | |
514 } | |
515 /*endif*/ | |
516 res = select(dfd + 1, &rfds, NULL, &efds, next ? &tv : NULL); | |
517 e = NULL; | |
518 if (res == 0) | |
519 { | |
520 uc_schedule_run(uc); | |
521 } | |
522 else if (res > 0) | |
523 { | |
524 e = uc_check_event(uc); | |
525 } | |
526 else if (errno != EINTR) | |
527 { | |
528 fprintf(stderr, "Error (%d) on select: %s\n", errno, strerror(errno)); | |
529 } | |
530 /*endif*/ | |
531 | |
532 if (e) | |
533 { | |
534 printf("Non-callback signaling event\n"); | |
535 handle_uc_event(uc, (void *) chan, e); | |
536 } | |
537 /*endif*/ | |
538 } | |
539 /*endfor*/ | |
540 return NULL; | |
541 } | |
542 /*- End of function --------------------------------------------------------*/ | |
543 | |
544 int main(int argc, char *argv[]) | |
545 { | |
546 pthread_attr_t attr; | |
547 struct zt_bufferinfo b; | |
548 struct zt_gains g; | |
549 int chan; | |
550 int chanx; | |
551 char dev_name[20]; | |
552 AFfilesetup filesetup; | |
553 int j; | |
554 | |
555 filesetup = afNewFileSetup(); | |
556 if (filesetup == AF_NULL_FILESETUP) | |
557 { | |
558 fprintf(stderr, " Failed to create file setup\n"); | |
559 exit(2); | |
560 } | |
561 afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); | |
562 afInitRate(filesetup, AF_DEFAULT_TRACK, (float) SAMPLE_RATE); | |
563 afInitFileFormat(filesetup, AF_FILE_WAVE); | |
564 afInitChannels(filesetup, AF_DEFAULT_TRACK, 1); | |
565 rxhandle = afOpenFile("rxadsi.wav", "w", filesetup); | |
566 if (rxhandle == NULL) | |
567 { | |
568 fprintf(stderr, " Failed to open adsi audio file\n"); | |
569 exit(2); | |
570 } | |
571 txhandle = afOpenFile("txadsi.wav", "w", filesetup); | |
572 if (txhandle == NULL) | |
573 { | |
574 fprintf(stderr, " Failed to open adsi audio file\n"); | |
575 exit(2); | |
576 } | |
577 | |
578 uc_start(); | |
579 pthread_attr_init(&attr); | |
580 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | |
581 if (argc < 1) | |
582 { | |
583 fprintf(stderr, "Usage: testcall [call]\n"); | |
584 exit(1); | |
585 } | |
586 /*endif*/ | |
587 for (chan = 0; chan < 1/*30*/; chan++) | |
588 { | |
589 chan_stuff[chan].sig_fd = open("/dev/zap/channel", O_RDWR | O_NONBLOCK); | |
590 if (chan_stuff[chan].sig_fd < 0) | |
591 { | |
592 fprintf(stderr, "Failed to open channel: %s\n", strerror(errno)); | |
593 exit(1); | |
594 } | |
595 /*endif*/ | |
596 chan_stuff[chan].fd = chan_stuff[chan].sig_fd; | |
597 | |
598 /* Allow for the missing channel at TS16 */ | |
599 if (chan < 15) | |
600 chanx = chan + 1; | |
601 else | |
602 chanx = chan + 2; | |
603 /*endif*/ | |
604 if (ioctl(chan_stuff[chan].fd, ZT_SPECIFY, &chanx)) | |
605 { | |
606 fprintf(stderr, "Failed to specify channel %d: %s\n", chanx, strerror(errno)); | |
607 exit(1); | |
608 } | |
609 /*endif*/ | |
610 if (ioctl(chan_stuff[chan].fd, ZT_GET_BUFINFO, &b)) | |
611 { | |
612 fprintf(stderr, "Unable to get buffer info on channel %d: %s\n", chanx, strerror(errno)); | |
613 exit(1); | |
614 } | |
615 /*endif*/ | |
616 printf ("%d %d %d %d %d %d\n", | |
617 b.rxbufpolicy, | |
618 b.txbufpolicy, | |
619 b.numbufs, | |
620 b.bufsize, | |
621 b.readbufs, | |
622 b.writebufs); | |
623 b.rxbufpolicy = ZT_POLICY_IMMEDIATE; | |
624 b.txbufpolicy = ZT_POLICY_IMMEDIATE; | |
625 b.numbufs = 4; | |
626 b.bufsize = 160; | |
627 if (ioctl(chan_stuff[chan].fd, ZT_SET_BUFINFO, &b)) | |
628 { | |
629 fprintf(stderr, "Unable to set buffer info on channel %d: %s\n", chanx, strerror(errno)); | |
630 exit(1); | |
631 } | |
632 /*endif*/ | |
633 if (ioctl(chan_stuff[chan].fd, ZT_GET_BUFINFO, &b)) | |
634 { | |
635 fprintf(stderr, "Unable to get buffer info on channel %d: %s\n", chanx, strerror(errno)); | |
636 exit(1); | |
637 } | |
638 /*endif*/ | |
639 for (j = 0; j < 256; j++) | |
640 { | |
641 g.rxgain[j] = j; | |
642 g.txgain[j] = j; | |
643 } | |
644 ioctl(chan_stuff[chan].fd, ZT_SETGAINS, &g); | |
645 printf("%d %d %d %d %d %d\n", | |
646 b.rxbufpolicy, | |
647 b.txbufpolicy, | |
648 b.numbufs, | |
649 b.bufsize, | |
650 b.readbufs, | |
651 b.writebufs); | |
652 | |
653 if (argc > 1) | |
654 caller_mode = TRUE; | |
655 /*endif*/ | |
656 chan_stuff[chan].chan = chan; | |
657 sprintf(dev_name, "Chan %2d:", chanx); | |
658 chan_stuff[chan].tag = strdup(dev_name); | |
659 sprintf(chan_stuff[chan].originating_number, "%d", 987654321 + chan); | |
660 sprintf(chan_stuff[chan].destination_number, "%d", 1234 + chan); | |
661 | |
662 printf("Thread for channel %d\n", chan); | |
663 if (pthread_create(&chan_stuff[chan].thread, &attr, run_uc, &chan_stuff[chan].chan)) | |
664 exit(2); | |
665 /*endif*/ | |
666 } | |
667 /*endfor*/ | |
668 for (;;) | |
669 { | |
670 sleep(5); | |
671 printf("Main thread\n"); | |
672 } | |
673 /*endfor*/ | |
674 exit(0); | |
675 | |
676 return 0; | |
677 } | |
678 /*- End of function --------------------------------------------------------*/ | |
679 #else | |
680 int main(int argc, char *argv[]) | |
681 { | |
682 printf("This program was not built with Unicall available\n"); | |
683 } | |
684 /*- End of function --------------------------------------------------------*/ | |
685 #endif | |
686 /*- End of file ------------------------------------------------------------*/ |