diff options
author | mattf <mattf@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2005-01-11 02:33:08 +0000 |
---|---|---|
committer | mattf <mattf@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2005-01-11 02:33:08 +0000 |
commit | 7e735b7c23588ca56887503db85d4ca211d6faf8 (patch) | |
tree | 6eaf57228e6e5a4f2298afa8c5b72b2d610cd3cd /fxotune.c | |
parent | d91c38225a1faa429d4422591b72dea4ecfc7753 (diff) |
Working out bugs
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@538 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'fxotune.c')
-rwxr-xr-x | fxotune.c | 68 |
1 files changed, 44 insertions, 24 deletions
@@ -26,7 +26,8 @@ #include "zaptel.h" -static int testduration = 100; /* Test the line for x milliseconds */ +//static int testduration = 100; /* Test the line for x milliseconds */ +#define TESTDURATION 100 /* Test the line for x milliseconds */ static int readduration = 100 * 2; static char *zappath = "/dev/zap"; @@ -39,6 +40,9 @@ static char *usage = #define OUT_OF_BOUNDS(x) ((x) < 0 || (x) > 255) +static short *outbuf = NULL; +static short obufsize = TESTDURATION * 8 * 2; + int process_readbuf(short *ibuf, int isize, short *obuf, int osize) { int i = 0; @@ -52,21 +56,13 @@ int process_readbuf(short *ibuf, int isize, short *obuf, int osize) return minsample; } -/* Returns index in echocan table with the lowest power pulse readback - * -1 means the device is not an FXO module or fails */ -int echo_tune(int whichzap) +int fill_outputdata(void) { - short bestval = 32355; - int bestindex = -1; - int i = 0; - int res = 0; - int total = sizeof(echo_trys) / sizeof(struct wctdm_echo_coefs); int randdev; - short *outbuf = NULL, *inbuf = NULL; - int obufsize = testduration * 8 * 2; /* In one milisecond there are 8 samples of 2 byte length */ - int ibufsize = readduration * 8 * 2; - + int cursize = 0; + int res; + fprintf(stdout, "Getting random impulse data\n"); randdev = open("/dev/random", O_RDONLY); if (randdev < 0) { fprintf(stdout, "Unable to open /dev/random: %s\n", strerror(errno)); @@ -78,21 +74,36 @@ int echo_tune(int whichzap) exit(-1); } - res = read(randdev, outbuf, obufsize); - if (res <= 0) { - fprintf(stdout, "WARNING: could not read from /dev/random: %s\n", strerror(errno)); - return -1; + while (cursize < obufsize) { + res = read(randdev, &outbuf[cursize], obufsize - cursize); + if (res <= 0) { + fprintf(stdout, "WARNING: could not read from /dev/random: %s\n", strerror(errno)); + return -1; + } + cursize += res; } + + fprintf(stdout, "Cool, we filled the random data buffer\n"); + close(randdev); - if (res != obufsize) { - fprintf(stdout, "Could not read request %d bytes from /dev/random. Using only %d\n", obufsize, res); - ibufsize = res; - } + return 0; +} - close(randdev); - outbuf = malloc(readduration); - if (!outbuf) { +/* Returns index in echocan table with the lowest power pulse readback + * -1 means the device is not an FXO module or fails */ +int echo_tune(int whichzap) +{ + short bestval = 32355; + int bestindex = -1; + int i = 0; + int res = 0; + int total = sizeof(echo_trys) / sizeof(struct wctdm_echo_coefs); + short *inbuf = NULL; + int ibufsize = readduration * 8 * 2; + + inbuf = malloc(readduration); + if (!inbuf) { fprintf(stdout, "Malloc failed on readbuf. Bad, bad, bad....\n"); exit(-1); } @@ -235,6 +246,11 @@ int main (int argc , char **argv) return -1; } + if (fill_outputdata()) { + fprintf(stdout, "Error in generating outputdata... dieing\n"); + return -1; + } + for (i = 0; i < 252; i++) { snprintf(zapdev, sizeof(zapdev), "%s/%d", zappath, i+1); @@ -245,6 +261,8 @@ int main (int argc , char **argv) } res = echo_tune(fd); + + close(fd); if (res > -1) { /* Do output to file */ int len = 0; @@ -262,6 +280,8 @@ int main (int argc , char **argv) } } } + + close(configfd); } return 0; |