Mercurial > hg > audiostuff
comparison spandsp-0.0.3/spandsp-0.0.3/tests/v42_tests.c @ 5:f762bf195c4b
import spandsp-0.0.3
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 16:00:21 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:26cd8f1ef0b1 | 5:f762bf195c4b |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * v42_tests.c | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2004 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: v42_tests.c,v 1.19 2006/11/19 14:07:28 steveu Exp $ | |
26 */ | |
27 | |
28 /* THIS IS A WORK IN PROGRESS. IT IS NOT FINISHED. */ | |
29 | |
30 /*! \page v42_tests_page V.42 tests | |
31 \section v42_tests_page_sec_1 What does it do? | |
32 These tests connect two instances of V.42 back to back. V.42 frames are | |
33 then exchanged between them. | |
34 */ | |
35 | |
36 #ifdef HAVE_CONFIG_H | |
37 #include <config.h> | |
38 #endif | |
39 | |
40 #include <stdio.h> | |
41 #include <inttypes.h> | |
42 #include <stdlib.h> | |
43 #include <string.h> | |
44 #if defined(HAVE_TGMATH_H) | |
45 #include <tgmath.h> | |
46 #endif | |
47 #if defined(HAVE_MATH_H) | |
48 #include <math.h> | |
49 #endif | |
50 #include <assert.h> | |
51 #include <tiffio.h> | |
52 | |
53 #include "spandsp.h" | |
54 | |
55 v42_state_t caller; | |
56 v42_state_t answerer; | |
57 | |
58 int rx_next[3] = {0}; | |
59 int tx_next[3] = {0}; | |
60 | |
61 static void v42_status(void *user_data, int status) | |
62 { | |
63 int x; | |
64 | |
65 x = (intptr_t) user_data; | |
66 printf("%d: Status is '%s' (%d)\n", x, lapm_status_to_str(status), status); | |
67 //if (status == LAPM_DATA) | |
68 // lapm_tx_iframe((x == 1) ? &caller.lapm : &answerer.lapm, "ABCDEFGHIJ", 10, 1); | |
69 } | |
70 | |
71 static void v42_frames(void *user_data, const uint8_t *msg, int len) | |
72 { | |
73 int i; | |
74 int x; | |
75 | |
76 x = (intptr_t) user_data; | |
77 for (i = 0; i < len; i++) | |
78 { | |
79 if (msg[i] != (rx_next[x] & 0xFF)) | |
80 printf("%d: Mismatch 0x%02X 0x%02X\n", x, msg[i], rx_next[x] & 0xFF); | |
81 rx_next[x]++; | |
82 } | |
83 printf("%d: Got frame len %d\n", x, len); | |
84 } | |
85 | |
86 int main(int argc, char *argv[]) | |
87 { | |
88 int i; | |
89 int bit; | |
90 uint8_t buf[1024]; | |
91 | |
92 v42_init(&caller, TRUE, TRUE, v42_frames, (void *) 1); | |
93 v42_init(&answerer, FALSE, TRUE, v42_frames, (void *) 2); | |
94 v42_set_status_callback(&caller, v42_status, (void *) 1); | |
95 v42_set_status_callback(&answerer, v42_status, (void *) 2); | |
96 span_log_set_level(&caller.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); | |
97 span_log_set_tag(&caller.logging, "caller"); | |
98 span_log_set_level(&caller.lapm.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); | |
99 span_log_set_tag(&caller.lapm.logging, "caller"); | |
100 span_log_set_level(&answerer.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); | |
101 span_log_set_tag(&answerer.logging, "answerer"); | |
102 span_log_set_level(&answerer.lapm.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); | |
103 span_log_set_tag(&answerer.lapm.logging, "answerer"); | |
104 for (i = 0; i < 100000; i++) | |
105 { | |
106 bit = v42_tx_bit(&caller); | |
107 v42_rx_bit(&answerer, bit); | |
108 bit = v42_tx_bit(&answerer); | |
109 if (i%10000 == 0) | |
110 bit ^= 1; | |
111 v42_rx_bit(&caller, bit); | |
112 span_schedule_update(&caller.lapm.sched, 4); | |
113 span_schedule_update(&answerer.lapm.sched, 4); | |
114 buf[0] = tx_next[1]; | |
115 if (lapm_tx(&caller.lapm, buf, 1) == 1) | |
116 tx_next[1]++; | |
117 buf[0] = tx_next[2]; | |
118 if (lapm_tx(&answerer.lapm, buf, 1) == 1) | |
119 tx_next[2]++; | |
120 } | |
121 return 0; | |
122 } | |
123 /*- End of function --------------------------------------------------------*/ | |
124 /*- End of file ------------------------------------------------------------*/ |