Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/adsi_tests.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 * adsi_tests.c - tests for analogue display service handling. | |
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: adsi_tests.c,v 1.57 2009/05/30 15:23:13 steveu Exp $ | |
26 */ | |
27 | |
28 /*! \page adsi_tests_page ADSI tests | |
29 \section adsi_tests_page_sec_1 What does it do? | |
30 These tests exercise the ADSI module, for all supported standards. A transmit | |
31 and a receive instance of the ADSI module are connected together. A quantity | |
32 of messages is passed between these instances, and checked for accuracy at | |
33 the receiver. Since the FSK modems used for this are exercised fully by other | |
34 tests, these tests do not include line modelling. | |
35 | |
36 \section adsi_tests_page_sec_2 How does it work? | |
37 */ | |
38 | |
39 /* Enable the following definition to enable direct probing into the FAX structures */ | |
40 //#define WITH_SPANDSP_INTERNALS | |
41 | |
42 #if defined(HAVE_CONFIG_H) | |
43 #include "config.h" | |
44 #endif | |
45 | |
46 #include <unistd.h> | |
47 #include <stdlib.h> | |
48 #include <stdio.h> | |
49 #include <string.h> | |
50 #include <assert.h> | |
51 #include <sndfile.h> | |
52 | |
53 //#if defined(WITH_SPANDSP_INTERNALS) | |
54 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES | |
55 //#endif | |
56 | |
57 #include "spandsp.h" | |
58 #include "spandsp-sim.h" | |
59 | |
60 #define OUTPUT_FILE_NAME "adsi.wav" | |
61 | |
62 #define BLOCK_LEN 160 | |
63 | |
64 #define MITEL_DIR "../test-data/mitel/" | |
65 #define BELLCORE_DIR "../test-data/bellcore/" | |
66 | |
67 const char *bellcore_files[] = | |
68 { | |
69 MITEL_DIR "mitel-cm7291-talkoff.wav", | |
70 BELLCORE_DIR "tr-tsy-00763-1.wav", | |
71 BELLCORE_DIR "tr-tsy-00763-2.wav", | |
72 BELLCORE_DIR "tr-tsy-00763-3.wav", | |
73 BELLCORE_DIR "tr-tsy-00763-4.wav", | |
74 BELLCORE_DIR "tr-tsy-00763-5.wav", | |
75 BELLCORE_DIR "tr-tsy-00763-6.wav", | |
76 "" | |
77 }; | |
78 | |
79 char *decode_test_file = NULL; | |
80 | |
81 int errors = 0; | |
82 int basic_testing = FALSE; | |
83 | |
84 adsi_rx_state_t *rx_adsi; | |
85 adsi_tx_state_t *tx_adsi; | |
86 | |
87 int current_standard = 0; | |
88 int good_message_received; | |
89 int log_audio = FALSE; | |
90 SNDFILE *outhandle = NULL; | |
91 int short_preamble = FALSE; | |
92 | |
93 static int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) | |
94 { | |
95 const char *t; | |
96 int len; | |
97 static int cycle = 0; | |
98 | |
99 len = 0; | |
100 switch (current_standard) | |
101 { | |
102 case ADSI_STANDARD_CLASS: | |
103 if (cycle > 3) | |
104 cycle = 0; | |
105 switch (cycle) | |
106 { | |
107 case 0: | |
108 len = adsi_add_field(s, msg, -1, CLASS_MDMF_CALLERID, NULL, 0); | |
109 /* Date and time as MMDDHHMM */ | |
110 len = adsi_add_field(s, msg, len, MCLASS_DATETIME, (uint8_t *) "10011750", 8); | |
111 len = adsi_add_field(s, msg, len, MCLASS_CALLER_NUMBER, (uint8_t *) "12345678", 8); | |
112 len = adsi_add_field(s, msg, len, MCLASS_DIALED_NUMBER, (uint8_t *) "87654321", 8); | |
113 len = adsi_add_field(s, msg, len, MCLASS_CALLER_NAME, (uint8_t *) "Chan Dai Man", 15); | |
114 break; | |
115 case 1: | |
116 len = adsi_add_field(s, msg, -1, CLASS_SDMF_MSG_WAITING, NULL, 0); | |
117 /* Active */ | |
118 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x42", 1); | |
119 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x42", 1); | |
120 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x42", 1); | |
121 break; | |
122 case 2: | |
123 len = adsi_add_field(s, msg, -1, CLASS_SDMF_MSG_WAITING, NULL, 0); | |
124 /* Inactive */ | |
125 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x6F", 1); | |
126 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x6F", 1); | |
127 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x6F", 1); | |
128 break; | |
129 case 3: | |
130 len = adsi_add_field(s, msg, -1, CLASS_SDMF_CALLERID, NULL, 0); | |
131 /* Date and time as MMDDHHMM */ | |
132 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "10011750", 8); | |
133 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "6095551212", 10); | |
134 break; | |
135 } | |
136 break; | |
137 case ADSI_STANDARD_CLIP: | |
138 if (cycle > 4) | |
139 cycle = 0; | |
140 switch (cycle) | |
141 { | |
142 case 0: | |
143 len = adsi_add_field(s, msg, -1, CLIP_MDMF_CALLERID, NULL, 0); | |
144 len = adsi_add_field(s, msg, len, CLIP_CALLTYPE, (uint8_t *) "\x81", 1); | |
145 /* Date and time as MMDDHHMM */ | |
146 len = adsi_add_field(s, msg, len, CLIP_DATETIME, (uint8_t *) "10011750", 8); | |
147 len = adsi_add_field(s, msg, len, CLIP_DIALED_NUMBER, (uint8_t *) "12345678", 8); | |
148 len = adsi_add_field(s, msg, len, CLIP_CALLER_NUMBER, (uint8_t *) "87654321", 8); | |
149 len = adsi_add_field(s, msg, len, CLIP_CALLER_NAME, (uint8_t *) "Chan Dai Man", 15); | |
150 break; | |
151 case 1: | |
152 len = adsi_add_field(s, msg, -1, CLIP_MDMF_MSG_WAITING, NULL, 0); | |
153 /* Inactive */ | |
154 len = adsi_add_field(s, msg, len, CLIP_VISUAL_INDICATOR, (uint8_t *) "\x00", 1); | |
155 break; | |
156 case 2: | |
157 len = adsi_add_field(s, msg, -1, CLIP_MDMF_MSG_WAITING, NULL, 0); | |
158 /* Active */ | |
159 len = adsi_add_field(s, msg, len, CLIP_VISUAL_INDICATOR, (uint8_t *) "\xFF", 1); | |
160 len = adsi_add_field(s, msg, len, CLIP_NUM_MSG, (uint8_t *) "\x05", 1); | |
161 break; | |
162 case 3: | |
163 len = adsi_add_field(s, msg, -1, CLIP_MDMF_SMS, NULL, 0); | |
164 /* Active */ | |
165 len = adsi_add_field(s, msg, len, CLIP_DISPLAY_INFO, (uint8_t *) "\x00" "ABC", 4); | |
166 break; | |
167 case 4: | |
168 len = adsi_add_field(s, msg, -1, CLIP_MDMF_CALLERID, NULL, 0); | |
169 len = adsi_add_field(s, msg, len, CLIP_NUM_MSG, (uint8_t *) "\x03", 1); | |
170 break; | |
171 } | |
172 break; | |
173 case ADSI_STANDARD_ACLIP: | |
174 if (cycle > 0) | |
175 cycle = 0; | |
176 switch (cycle) | |
177 { | |
178 case 0: | |
179 len = adsi_add_field(s, msg, -1, ACLIP_MDMF_CALLERID, NULL, 0); | |
180 /* Date and time as MMDDHHMM */ | |
181 len = adsi_add_field(s, msg, len, ACLIP_DATETIME, (uint8_t *) "10011750", 8); | |
182 len = adsi_add_field(s, msg, len, ACLIP_DIALED_NUMBER, (uint8_t *) "12345678", 8); | |
183 len = adsi_add_field(s, msg, len, ACLIP_CALLER_NUMBER, (uint8_t *) "87654321", 8); | |
184 len = adsi_add_field(s, msg, len, ACLIP_CALLER_NAME, (uint8_t *) "Chan Dai Man", 15); | |
185 break; | |
186 } | |
187 break; | |
188 case ADSI_STANDARD_JCLIP: | |
189 len = adsi_add_field(s, msg, -1, JCLIP_MDMF_CALLERID, NULL, 0); | |
190 len = adsi_add_field(s, msg, len, JCLIP_CALLER_NUMBER, (uint8_t *) "12345678", 8); | |
191 len = adsi_add_field(s, msg, len, JCLIP_CALLER_NUM_DES, (uint8_t *) "215", 3); | |
192 len = adsi_add_field(s, msg, len, JCLIP_DIALED_NUMBER, (uint8_t *) "87654321", 8); | |
193 len = adsi_add_field(s, msg, len, JCLIP_DIALED_NUM_DES, (uint8_t *) "215", 3); | |
194 break; | |
195 case ADSI_STANDARD_CLIP_DTMF: | |
196 if (cycle > 4) | |
197 cycle = 0; | |
198 switch (cycle) | |
199 { | |
200 case 0: | |
201 len = adsi_add_field(s, msg, -1, CLIP_DTMF_C_TERMINATED, NULL, 0); | |
202 len = adsi_add_field(s, msg, len, CLIP_DTMF_C_CALLER_NUMBER, (uint8_t *) "12345678", 8); | |
203 len = adsi_add_field(s, msg, len, CLIP_DTMF_C_ABSENCE, (uint8_t *) "10", 2); | |
204 len = adsi_add_field(s, msg, len, CLIP_DTMF_C_REDIRECT_NUMBER, (uint8_t *) "87654321", 8); | |
205 break; | |
206 case 1: | |
207 len = adsi_add_field(s, msg, -1, CLIP_DTMF_HASH_TERMINATED, NULL, 0); | |
208 len = adsi_add_field(s, msg, len, CLIP_DTMF_HASH_CALLER_NUMBER, (uint8_t *) "12345678", 8); | |
209 break; | |
210 case 2: | |
211 len = adsi_add_field(s, msg, -1, CLIP_DTMF_HASH_TERMINATED, NULL, 0); | |
212 len = adsi_add_field(s, msg, len, CLIP_DTMF_HASH_ABSENCE, (uint8_t *) "1", 1); | |
213 break; | |
214 case 3: | |
215 /* Test the D<number>C format, used in Taiwan and Kuwait */ | |
216 len = adsi_add_field(s, msg, -1, CLIP_DTMF_HASH_TERMINATED, NULL, 0); | |
217 len = adsi_add_field(s, msg, len, CLIP_DTMF_HASH_ABSENCE, (uint8_t *) "12345678", 8); | |
218 break; | |
219 case 4: | |
220 /* Test the <number># format, with no header */ | |
221 len = adsi_add_field(s, msg, -1, CLIP_DTMF_HASH_TERMINATED, NULL, 0); | |
222 len = adsi_add_field(s, msg, len, CLIP_DTMF_HASH_UNSPECIFIED, (uint8_t *) "12345678", 8); | |
223 break; | |
224 } | |
225 break; | |
226 case ADSI_STANDARD_TDD: | |
227 t = "The quick Brown Fox Jumps Over The Lazy dog 0123456789!@#$%^&*()"; | |
228 len = adsi_add_field(s, msg, -1, 0, (uint8_t *) t, strlen(t)); | |
229 break; | |
230 } | |
231 cycle++; | |
232 return len; | |
233 } | |
234 /*- End of function --------------------------------------------------------*/ | |
235 | |
236 static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) | |
237 { | |
238 int i; | |
239 int l; | |
240 uint8_t field_type; | |
241 const uint8_t *field_body; | |
242 int field_len; | |
243 int message_type; | |
244 uint8_t body[256]; | |
245 | |
246 printf("Good message received (%d bytes)\n", len); | |
247 good_message_received = TRUE; | |
248 for (i = 0; i < len; i++) | |
249 { | |
250 printf("%02x ", msg[i]); | |
251 if ((i & 0xF) == 0xF) | |
252 printf("\n"); | |
253 } | |
254 printf("\n"); | |
255 l = -1; | |
256 message_type = -1; | |
257 printf("Message breakdown\n"); | |
258 do | |
259 { | |
260 l = adsi_next_field(rx_adsi, msg, len, l, &field_type, &field_body, &field_len); | |
261 if (l > 0) | |
262 { | |
263 if (field_body) | |
264 { | |
265 memcpy(body, field_body, field_len); | |
266 body[field_len] = '\0'; | |
267 printf("Field type 0x%x, len %d, '%s' - ", field_type, field_len, body); | |
268 switch (current_standard) | |
269 { | |
270 case ADSI_STANDARD_CLASS: | |
271 switch (message_type) | |
272 { | |
273 case CLASS_SDMF_CALLERID: | |
274 break; | |
275 case CLASS_MDMF_CALLERID: | |
276 switch (field_type) | |
277 { | |
278 case MCLASS_DATETIME: | |
279 printf("Date and time (MMDDHHMM)"); | |
280 break; | |
281 case MCLASS_CALLER_NUMBER: | |
282 printf("Caller's number"); | |
283 break; | |
284 case MCLASS_DIALED_NUMBER: | |
285 printf("Dialed number"); | |
286 break; | |
287 case MCLASS_ABSENCE1: | |
288 printf("Caller's number absent: 'O' or 'P'"); | |
289 break; | |
290 case MCLASS_REDIRECT: | |
291 printf("Call forward: universal ('0'), on busy ('1'), or on unanswered ('2')"); | |
292 break; | |
293 case MCLASS_QUALIFIER: | |
294 printf("Long distance: 'L'"); | |
295 break; | |
296 case MCLASS_CALLER_NAME: | |
297 printf("Caller's name"); | |
298 break; | |
299 case MCLASS_ABSENCE2: | |
300 printf("Caller's name absent: 'O' or 'P'"); | |
301 break; | |
302 } | |
303 break; | |
304 case CLASS_SDMF_MSG_WAITING: | |
305 break; | |
306 case CLASS_MDMF_MSG_WAITING: | |
307 switch (field_type) | |
308 { | |
309 case MCLASS_VISUAL_INDICATOR: | |
310 printf("Message waiting/not waiting"); | |
311 break; | |
312 } | |
313 break; | |
314 } | |
315 break; | |
316 case ADSI_STANDARD_CLIP: | |
317 switch (message_type) | |
318 { | |
319 case CLIP_MDMF_CALLERID: | |
320 case CLIP_MDMF_MSG_WAITING: | |
321 case CLIP_MDMF_CHARGE_INFO: | |
322 case CLIP_MDMF_SMS: | |
323 switch (field_type) | |
324 { | |
325 case CLIP_DATETIME: | |
326 printf("Date and time (MMDDHHMM)"); | |
327 break; | |
328 case CLIP_CALLER_NUMBER: | |
329 printf("Caller's number"); | |
330 break; | |
331 case CLIP_DIALED_NUMBER: | |
332 printf("Dialed number"); | |
333 break; | |
334 case CLIP_ABSENCE1: | |
335 printf("Caller's number absent"); | |
336 break; | |
337 case CLIP_CALLER_NAME: | |
338 printf("Caller's name"); | |
339 break; | |
340 case CLIP_ABSENCE2: | |
341 printf("Caller's name absent"); | |
342 break; | |
343 case CLIP_VISUAL_INDICATOR: | |
344 printf("Visual indicator"); | |
345 break; | |
346 case CLIP_MESSAGE_ID: | |
347 printf("Message ID"); | |
348 break; | |
349 case CLIP_CALLTYPE: | |
350 printf("Voice call, ring-back-when-free call, or msg waiting call"); | |
351 break; | |
352 case CLIP_NUM_MSG: | |
353 printf("Number of messages"); | |
354 break; | |
355 #if 0 | |
356 case CLIP_REDIR_NUMBER: | |
357 printf("Redirecting number"); | |
358 break; | |
359 #endif | |
360 case CLIP_CHARGE: | |
361 printf("Charge"); | |
362 break; | |
363 case CLIP_DURATION: | |
364 printf("Duration of the call"); | |
365 break; | |
366 case CLIP_ADD_CHARGE: | |
367 printf("Additional charge"); | |
368 break; | |
369 case CLIP_DISPLAY_INFO: | |
370 printf("Display information"); | |
371 break; | |
372 case CLIP_SERVICE_INFO: | |
373 printf("Service information"); | |
374 break; | |
375 } | |
376 break; | |
377 } | |
378 break; | |
379 case ADSI_STANDARD_ACLIP: | |
380 switch (message_type) | |
381 { | |
382 case ACLIP_SDMF_CALLERID: | |
383 break; | |
384 case ACLIP_MDMF_CALLERID: | |
385 switch (field_type) | |
386 { | |
387 case ACLIP_DATETIME: | |
388 printf("Date and time (MMDDHHMM)"); | |
389 break; | |
390 case ACLIP_CALLER_NUMBER: | |
391 printf("Caller's number"); | |
392 break; | |
393 case ACLIP_DIALED_NUMBER: | |
394 printf("Dialed number"); | |
395 break; | |
396 case ACLIP_NUMBER_ABSENCE: | |
397 printf("Caller's number absent: 'O' or 'P'"); | |
398 break; | |
399 case ACLIP_REDIRECT: | |
400 printf("Call forward: universal, on busy, or on unanswered"); | |
401 break; | |
402 case ACLIP_QUALIFIER: | |
403 printf("Long distance call: 'L'"); | |
404 break; | |
405 case ACLIP_CALLER_NAME: | |
406 printf("Caller's name"); | |
407 break; | |
408 case ACLIP_NAME_ABSENCE: | |
409 printf("Caller's name absent: 'O' or 'P'"); | |
410 break; | |
411 } | |
412 break; | |
413 } | |
414 break; | |
415 case ADSI_STANDARD_JCLIP: | |
416 switch (message_type) | |
417 { | |
418 case JCLIP_MDMF_CALLERID: | |
419 switch (field_type) | |
420 { | |
421 case JCLIP_CALLER_NUMBER: | |
422 printf("Caller's number"); | |
423 break; | |
424 case JCLIP_CALLER_NUM_DES: | |
425 printf("Caller's number data extension signal"); | |
426 break; | |
427 case JCLIP_DIALED_NUMBER: | |
428 printf("Dialed number"); | |
429 break; | |
430 case JCLIP_DIALED_NUM_DES: | |
431 printf("Dialed number data extension signal"); | |
432 break; | |
433 case JCLIP_ABSENCE: | |
434 printf("Caller's number absent: 'C', 'O', 'P' or 'S'"); | |
435 break; | |
436 } | |
437 break; | |
438 } | |
439 break; | |
440 case ADSI_STANDARD_CLIP_DTMF: | |
441 switch (message_type) | |
442 { | |
443 case CLIP_DTMF_HASH_TERMINATED: | |
444 switch (field_type) | |
445 { | |
446 case CLIP_DTMF_HASH_CALLER_NUMBER: | |
447 printf("Caller's number"); | |
448 break; | |
449 case CLIP_DTMF_HASH_ABSENCE: | |
450 printf("Caller's number absent: private (1), overseas (2) or not available (3)"); | |
451 break; | |
452 case CLIP_DTMF_HASH_UNSPECIFIED: | |
453 printf("Unspecified"); | |
454 break; | |
455 } | |
456 break; | |
457 case CLIP_DTMF_C_TERMINATED: | |
458 switch (field_type) | |
459 { | |
460 case CLIP_DTMF_C_CALLER_NUMBER: | |
461 printf("Caller's number"); | |
462 break; | |
463 case CLIP_DTMF_C_REDIRECT_NUMBER: | |
464 printf("Redirect number"); | |
465 break; | |
466 case CLIP_DTMF_C_ABSENCE: | |
467 printf("Caller's number absent"); | |
468 break; | |
469 } | |
470 break; | |
471 } | |
472 break; | |
473 case ADSI_STANDARD_TDD: | |
474 if (basic_testing) | |
475 { | |
476 if (len != 59 | |
477 || | |
478 memcmp(msg, "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 0123456789#$*()", 59)) | |
479 { | |
480 printf("\n"); | |
481 printf("String error\n"); | |
482 exit(2); | |
483 } | |
484 } | |
485 break; | |
486 } | |
487 } | |
488 else | |
489 { | |
490 printf("Message type 0x%x - ", field_type); | |
491 message_type = field_type; | |
492 switch (current_standard) | |
493 { | |
494 case ADSI_STANDARD_CLASS: | |
495 switch (message_type) | |
496 { | |
497 case CLASS_SDMF_CALLERID: | |
498 printf("Single data message caller ID"); | |
499 break; | |
500 case CLASS_MDMF_CALLERID: | |
501 printf("Multiple data message caller ID"); | |
502 break; | |
503 case CLASS_SDMF_MSG_WAITING: | |
504 printf("Single data message message waiting"); | |
505 break; | |
506 case CLASS_MDMF_MSG_WAITING: | |
507 printf("Multiple data message message waiting"); | |
508 break; | |
509 default: | |
510 printf("Unknown"); | |
511 break; | |
512 } | |
513 break; | |
514 case ADSI_STANDARD_CLIP: | |
515 switch (message_type) | |
516 { | |
517 case CLIP_MDMF_CALLERID: | |
518 printf("Multiple data message caller ID"); | |
519 break; | |
520 case CLIP_MDMF_MSG_WAITING: | |
521 printf("Multiple data message message waiting"); | |
522 break; | |
523 case CLIP_MDMF_CHARGE_INFO: | |
524 printf("Multiple data message charge info"); | |
525 break; | |
526 case CLIP_MDMF_SMS: | |
527 printf("Multiple data message SMS"); | |
528 break; | |
529 default: | |
530 printf("Unknown"); | |
531 break; | |
532 } | |
533 break; | |
534 case ADSI_STANDARD_ACLIP: | |
535 switch (message_type) | |
536 { | |
537 case ACLIP_SDMF_CALLERID: | |
538 printf("Single data message caller ID frame"); | |
539 break; | |
540 case ACLIP_MDMF_CALLERID: | |
541 printf("Multiple data message caller ID frame"); | |
542 break; | |
543 default: | |
544 printf("Unknown"); | |
545 break; | |
546 } | |
547 break; | |
548 case ADSI_STANDARD_JCLIP: | |
549 switch (message_type) | |
550 { | |
551 case JCLIP_MDMF_CALLERID: | |
552 printf("Multiple data message caller ID frame"); | |
553 break; | |
554 default: | |
555 printf("Unknown"); | |
556 break; | |
557 } | |
558 break; | |
559 case ADSI_STANDARD_CLIP_DTMF: | |
560 switch (message_type) | |
561 { | |
562 case CLIP_DTMF_HASH_TERMINATED: | |
563 printf("# terminated"); | |
564 break; | |
565 case CLIP_DTMF_C_TERMINATED: | |
566 printf("C terminated"); | |
567 break; | |
568 default: | |
569 printf("Unknown"); | |
570 break; | |
571 } | |
572 break; | |
573 case ADSI_STANDARD_TDD: | |
574 printf("Unknown"); | |
575 break; | |
576 } | |
577 } | |
578 printf("\n"); | |
579 } | |
580 } | |
581 while (l > 0); | |
582 if (l < -1) | |
583 { | |
584 /* This message appears corrupt */ | |
585 printf("Bad message contents\n"); | |
586 exit(2); | |
587 } | |
588 printf("\n"); | |
589 } | |
590 /*- End of function --------------------------------------------------------*/ | |
591 | |
592 static void tdd_character_set_tests(void) | |
593 { | |
594 #if 0 | |
595 char *s; | |
596 int ch; | |
597 int xx; | |
598 int yy; | |
599 | |
600 /* This part tests internal static routines in the ADSI module. It can | |
601 only be run with a modified version of the ADSI module, which makes | |
602 the routines visible. */ | |
603 /* Check the character encode/decode cycle */ | |
604 tx_adsi = adsi_tx_init(NULL, ADSI_STANDARD_TDD); | |
605 rx_adsi = adsi_rx_init(NULL, ADSI_STANDARD_TDD, put_adsi_msg, NULL); | |
606 s = "The quick Brown Fox Jumps Over The Lazy dog 0123456789!@#$%^&*()"; | |
607 while ((ch = *s++)) | |
608 { | |
609 xx = adsi_encode_baudot(tx_adsi, ch); | |
610 if ((xx & 0x3E0)) | |
611 { | |
612 yy = adsi_decode_baudot(rx_adsi, (xx >> 5) & 0x1F); | |
613 if (yy) | |
614 printf("%c", yy); | |
615 } | |
616 yy = adsi_decode_baudot(rx_adsi, xx & 0x1F); | |
617 if (yy) | |
618 printf("%c", yy); | |
619 } | |
620 adsi_tx_free(tx_adsi); | |
621 adsi_rx_free(rx_adsi); | |
622 printf("\n"); | |
623 #endif | |
624 } | |
625 /*- End of function --------------------------------------------------------*/ | |
626 | |
627 static void basic_tests(int standard) | |
628 { | |
629 int16_t amp[BLOCK_LEN]; | |
630 uint8_t adsi_msg[256 + 42]; | |
631 int outframes; | |
632 int len; | |
633 int adsi_msg_len; | |
634 int push; | |
635 int i; | |
636 | |
637 basic_testing = TRUE; | |
638 printf("Testing %s\n", adsi_standard_to_str(standard)); | |
639 tx_adsi = adsi_tx_init(NULL, standard); | |
640 if (short_preamble) | |
641 adsi_tx_set_preamble(tx_adsi, 50, 20, 5, -1); | |
642 rx_adsi = adsi_rx_init(NULL, standard, put_adsi_msg, NULL); | |
643 | |
644 /* Fake an OK condition for the first message test */ | |
645 good_message_received = TRUE; | |
646 push = 0; | |
647 for (i = 0; i < 100000; i++) | |
648 { | |
649 if (push == 0) | |
650 { | |
651 if ((len = adsi_tx(tx_adsi, amp, BLOCK_LEN)) == 0) | |
652 push = 10; | |
653 } | |
654 else | |
655 { | |
656 len = 0; | |
657 /* Push a little silence through, to flush things out */ | |
658 if (--push == 0) | |
659 { | |
660 if (!good_message_received) | |
661 { | |
662 printf("No message received %s (%d)\n", adsi_standard_to_str(standard), i); | |
663 exit(2); | |
664 } | |
665 good_message_received = FALSE; | |
666 adsi_msg_len = adsi_create_message(tx_adsi, adsi_msg); | |
667 adsi_msg_len = adsi_tx_put_message(tx_adsi, adsi_msg, adsi_msg_len); | |
668 } | |
669 } | |
670 if (len < BLOCK_LEN) | |
671 { | |
672 memset(&[len], 0, sizeof(int16_t)*(BLOCK_LEN - len)); | |
673 len = BLOCK_LEN; | |
674 } | |
675 if (log_audio) | |
676 { | |
677 outframes = sf_writef_short(outhandle, | |
678 amp, | |
679 len); | |
680 if (outframes != len) | |
681 { | |
682 fprintf(stderr, " Error writing audio file\n"); | |
683 exit(2); | |
684 } | |
685 } | |
686 adsi_rx(rx_adsi, amp, len); | |
687 } | |
688 adsi_rx_free(rx_adsi); | |
689 adsi_tx_free(tx_adsi); | |
690 basic_testing = FALSE; | |
691 } | |
692 /*- End of function --------------------------------------------------------*/ | |
693 | |
694 static void mitel_cm7291_side_2_and_bellcore_tests(int standard) | |
695 { | |
696 int j; | |
697 int16_t amp[BLOCK_LEN]; | |
698 SNDFILE *inhandle; | |
699 int frames; | |
700 | |
701 /* The remainder of the Mitel tape is the talk-off test */ | |
702 /* Here we use the Bellcore test tapes (much tougher), in six | |
703 files - 1 from each side of the original 3 cassette tapes */ | |
704 printf("Talk-off tests for %s\n", adsi_standard_to_str(standard)); | |
705 rx_adsi = adsi_rx_init(NULL, standard, put_adsi_msg, NULL); | |
706 for (j = 0; bellcore_files[j][0]; j++) | |
707 { | |
708 printf("Testing with %s\n", bellcore_files[j]); | |
709 if ((inhandle = sf_open_telephony_read(bellcore_files[j], 1)) == NULL) | |
710 { | |
711 printf(" Cannot open speech file '%s'\n", bellcore_files[j]); | |
712 exit(2); | |
713 } | |
714 while ((frames = sf_readf_short(inhandle, amp, BLOCK_LEN))) | |
715 { | |
716 adsi_rx(rx_adsi, amp, frames); | |
717 } | |
718 if (sf_close(inhandle) != 0) | |
719 { | |
720 printf(" Cannot close speech file '%s'\n", bellcore_files[j]); | |
721 exit(2); | |
722 } | |
723 } | |
724 adsi_rx_free(rx_adsi); | |
725 if (j > 470) | |
726 { | |
727 printf(" Failed\n"); | |
728 exit(2); | |
729 } | |
730 printf(" Passed\n"); | |
731 } | |
732 /*- End of function --------------------------------------------------------*/ | |
733 | |
734 int main(int argc, char *argv[]) | |
735 { | |
736 int16_t amp[BLOCK_LEN]; | |
737 SNDFILE *inhandle; | |
738 int len; | |
739 int test_standard; | |
740 int first_standard; | |
741 int last_standard; | |
742 int opt; | |
743 int enable_basic_tests; | |
744 int enable_talkoff_tests; | |
745 | |
746 log_audio = FALSE; | |
747 decode_test_file = NULL; | |
748 test_standard = -1; | |
749 short_preamble = FALSE; | |
750 enable_basic_tests = TRUE; | |
751 enable_talkoff_tests = FALSE; | |
752 while ((opt = getopt(argc, argv, "bd:lps:t")) != -1) | |
753 { | |
754 switch (opt) | |
755 { | |
756 case 'b': | |
757 enable_basic_tests = TRUE; | |
758 enable_talkoff_tests = FALSE; | |
759 break; | |
760 case 'd': | |
761 decode_test_file = optarg; | |
762 break; | |
763 case 'l': | |
764 log_audio = TRUE; | |
765 break; | |
766 case 'p': | |
767 short_preamble = TRUE; | |
768 break; | |
769 case 's': | |
770 if (strcasecmp("CLASS", optarg) == 0) | |
771 test_standard = ADSI_STANDARD_CLASS; | |
772 else if (strcasecmp("CLIP", optarg) == 0) | |
773 test_standard = ADSI_STANDARD_CLIP; | |
774 else if (strcasecmp("A-CLIP", optarg) == 0) | |
775 test_standard = ADSI_STANDARD_ACLIP; | |
776 else if (strcasecmp("J-CLIP", optarg) == 0) | |
777 test_standard = ADSI_STANDARD_JCLIP; | |
778 else if (strcasecmp("CLIP-DTMF", optarg) == 0) | |
779 test_standard = ADSI_STANDARD_CLIP_DTMF; | |
780 else if (strcasecmp("TDD", optarg) == 0) | |
781 test_standard = ADSI_STANDARD_TDD; | |
782 else | |
783 test_standard = atoi(optarg); | |
784 break; | |
785 case 't': | |
786 enable_basic_tests = FALSE; | |
787 enable_talkoff_tests = TRUE; | |
788 break; | |
789 default: | |
790 //usage(); | |
791 exit(2); | |
792 break; | |
793 } | |
794 } | |
795 outhandle = NULL; | |
796 | |
797 tdd_character_set_tests(); | |
798 | |
799 if (decode_test_file) | |
800 { | |
801 /* We will decode the audio from a file. */ | |
802 if ((inhandle = sf_open_telephony_read(decode_test_file, 1)) == NULL) | |
803 { | |
804 fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file); | |
805 exit(2); | |
806 } | |
807 if (test_standard < 0) | |
808 current_standard = ADSI_STANDARD_CLASS; | |
809 else | |
810 current_standard = test_standard; | |
811 | |
812 rx_adsi = adsi_rx_init(NULL, current_standard, put_adsi_msg, NULL); | |
813 #if 0 | |
814 span_log_set_level(rx_adsi.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); | |
815 span_log_set_tag(rx_adsi.logging, "ADSI"); | |
816 #endif | |
817 for (;;) | |
818 { | |
819 len = sf_readf_short(inhandle, amp, BLOCK_LEN); | |
820 if (len == 0) | |
821 break; | |
822 adsi_rx(rx_adsi, amp, len); | |
823 } | |
824 if (sf_close(inhandle) != 0) | |
825 { | |
826 fprintf(stderr, " Cannot close audio file '%s'\n", decode_test_file); | |
827 exit(2); | |
828 } | |
829 adsi_rx_free(rx_adsi); | |
830 } | |
831 else | |
832 { | |
833 if (log_audio) | |
834 { | |
835 if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME, 1)) == NULL) | |
836 { | |
837 fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_FILE_NAME); | |
838 exit(2); | |
839 } | |
840 } | |
841 /* Go through all the standards */ | |
842 /* This assumes standard 0 is NULL, and TDD is the last in the list */ | |
843 if (test_standard < 0) | |
844 { | |
845 first_standard = ADSI_STANDARD_CLASS; | |
846 last_standard = ADSI_STANDARD_TDD; | |
847 } | |
848 else | |
849 { | |
850 first_standard = | |
851 last_standard = test_standard; | |
852 } | |
853 for (current_standard = first_standard; current_standard <= last_standard; current_standard++) | |
854 { | |
855 if (enable_basic_tests) | |
856 basic_tests(current_standard); | |
857 if (enable_talkoff_tests) | |
858 mitel_cm7291_side_2_and_bellcore_tests(current_standard); | |
859 } | |
860 if (log_audio) | |
861 { | |
862 if (sf_close(outhandle) != 0) | |
863 { | |
864 fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); | |
865 exit(2); | |
866 } | |
867 } | |
868 printf("Tests passed.\n"); | |
869 } | |
870 | |
871 return 0; | |
872 } | |
873 /*- End of function --------------------------------------------------------*/ | |
874 /*- End of file ------------------------------------------------------------*/ |