2
0

adsi_tests.c 31 KB

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