From 387025b1cb918f00acf049f0c7302df62d1fcf7f Mon Sep 17 00:00:00 2001 From: mattf Date: Fri, 25 Feb 2005 21:13:41 +0000 Subject: Fixed fxotune utility. It now can automatically find the best impedance and other values for the line. If you are having problems with echo on your FXO modules, take a look at this utility. It should fix most of your echo issues. git-svn-id: http://svn.digium.com/svn/zaptel/trunk@594 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- fxotune.c | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) (limited to 'fxotune.c') diff --git a/fxotune.c b/fxotune.c index 8560e75..2726e13 100755 --- a/fxotune.c +++ b/fxotune.c @@ -50,18 +50,6 @@ static short outbuf[TEST_DURATION]; static int debug = 0; -#if 0 -int process_readbuf(short *ibuf) -{ - int sum=0; - int x; - for (x=0;x 0) { + square_of_sums += (float)sbuf[i]; + } else { + sbuf[i] *= -1; + square_of_sums += (float)sbuf[i]; + } } } else { /* Version for float inputs */ @@ -107,12 +103,23 @@ static float power_of(void *prebuf, int bufsize, int short_format) } } + if (debug) printf("sum_of_squares = %f\n", sum_of_squares); + square_of_sums *= square_of_sums; /* sums ^ 2 */ - finalanswer = sum_of_squares - square_of_sums; + if (debug) printf("square_of_sums = %f\n", square_of_sums); + + finalanswer = square_of_sums - sum_of_squares; + + if (debug) printf("finalanswer = %f\n", finalanswer); - if (finalanswer < 0) + if (finalanswer < 0) { + printf("Error: Final answer negative number %f\n", finalanswer); return -3; + } +#if 0 + finalanswer = finalanswer * (float)-1; +#endif return sqrtf(finalanswer); } @@ -407,14 +414,15 @@ static int acim_tune(int whichzap, char *dialstr) /* calculate power of response */ freq_results[(freq/200)-1] = power_of(inbuf+SKIP_BYTES, BUFFER_LENGTH-SKIP_BYTES, 1); - fprintf(outfile, "%d,%d,%f\n", i, freq, freq_results[(freq/200)-1]); + if (debug) fprintf(outfile, "%d,%d,%f\n", acim, freq, freq_results[(freq/200)-1]); } - - acim_results[i] = power_of(freq_results, 15, 0); + acim_results[acim] = power_of(freq_results, 15, 0); } + for (i = 0; i < 16; i++) + fprintf(outfile, "acim_results[%d] = %f\n", i, acim_results[i]); /* Find out what the "best" impedance is for the line */ - lowest = 1; + lowest = 0; for (i = 0; i < 16; i++) { if (acim_results[i] < acim_results[lowest]) { lowest = i; @@ -431,6 +439,7 @@ int main (int argc , char **argv) int fd; int res = 0; int configfd; + FILE *fp = NULL; if ((argc < 2) || (argc > 3)) { /* Show usage */ @@ -439,7 +448,7 @@ int main (int argc , char **argv) } if (!strcasecmp(argv[1], "-s")) { - FILE *fp = NULL; +set: fp = fopen(configfile, "r"); @@ -548,6 +557,8 @@ int main (int argc , char **argv) } close(configfd); + /* Some getto goto hackery to make this more convenient */ + goto set; } return 0; -- cgit v1.2.3