Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/v42_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 * 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.28 2008/11/30 10:17:31 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 #if defined(HAVE_CONFIG_H) | |
| 37 #include <config.h> | |
| 38 #endif | |
| 39 | |
| 40 #include <stdlib.h> | |
| 41 #include <stdio.h> | |
| 42 #include <string.h> | |
| 43 #include <assert.h> | |
| 44 | |
| 45 //#if defined(WITH_SPANDSP_INTERNALS) | |
| 46 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES | |
| 47 //#endif | |
| 48 | |
| 49 #include "spandsp.h" | |
| 50 | |
| 51 v42_state_t caller; | |
| 52 v42_state_t answerer; | |
| 53 | |
| 54 int rx_next[3] = {0}; | |
| 55 int tx_next[3] = {0}; | |
| 56 | |
| 57 static void v42_status(void *user_data, int status) | |
| 58 { | |
| 59 int x; | |
| 60 | |
| 61 x = (intptr_t) user_data; | |
| 62 printf("%d: Status is '%s' (%d)\n", x, lapm_status_to_str(status), status); | |
| 63 //if (status == LAPM_DATA) | |
| 64 // lapm_tx_iframe((x == 1) ? &caller.lapm : &answerer.lapm, "ABCDEFGHIJ", 10, 1); | |
| 65 } | |
| 66 | |
| 67 static void v42_frames(void *user_data, const uint8_t *msg, int len) | |
| 68 { | |
| 69 int i; | |
| 70 int x; | |
| 71 | |
| 72 x = (intptr_t) user_data; | |
| 73 for (i = 0; i < len; i++) | |
| 74 { | |
| 75 if (msg[i] != (rx_next[x] & 0xFF)) | |
| 76 printf("%d: Mismatch 0x%02X 0x%02X\n", x, msg[i], rx_next[x] & 0xFF); | |
| 77 rx_next[x]++; | |
| 78 } | |
| 79 printf("%d: Got frame len %d\n", x, len); | |
| 80 } | |
| 81 | |
| 82 int main(int argc, char *argv[]) | |
| 83 { | |
| 84 int i; | |
| 85 int bit; | |
| 86 uint8_t buf[1024]; | |
| 87 | |
| 88 v42_init(&caller, TRUE, TRUE, v42_frames, (void *) 1); | |
| 89 v42_init(&answerer, FALSE, TRUE, v42_frames, (void *) 2); | |
| 90 v42_set_status_callback(&caller, v42_status, (void *) 1); | |
| 91 v42_set_status_callback(&answerer, v42_status, (void *) 2); | |
| 92 span_log_set_level(&caller.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG); | |
| 93 span_log_set_tag(&caller.logging, "caller"); | |
| 94 span_log_set_level(&caller.lapm.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG); | |
| 95 span_log_set_tag(&caller.lapm.logging, "caller"); | |
| 96 span_log_set_level(&caller.lapm.sched.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG); | |
| 97 span_log_set_tag(&caller.lapm.sched.logging, "caller"); | |
| 98 span_log_set_level(&answerer.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG); | |
| 99 span_log_set_tag(&answerer.logging, "answerer"); | |
| 100 span_log_set_level(&answerer.lapm.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG); | |
| 101 span_log_set_tag(&answerer.lapm.logging, "answerer"); | |
| 102 span_log_set_level(&answerer.lapm.sched.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG); | |
| 103 span_log_set_tag(&answerer.lapm.sched.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 ------------------------------------------------------------*/ |
