summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattf <mattf@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2005-09-19 18:52:35 +0000
committermattf <mattf@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2005-09-19 18:52:35 +0000
commit744aa75e04d2af602c607380838991a97b06db72 (patch)
treece2c7bdaed515bf663296543c9612e926f3bbaf2
parent7761c25c9ae4056d0470e7dfa0f9c94732050320 (diff)
Remove old notes/code. Fix so it works with debug disabled
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@771 5390a7c7-147a-4af0-8ec9-7488f05a26cb
-rwxr-xr-xfxotune.c186
1 files changed, 5 insertions, 181 deletions
diff --git a/fxotune.c b/fxotune.c
index bde07d9..8a7ad19 100755
--- a/fxotune.c
+++ b/fxotune.c
@@ -60,10 +60,7 @@ static short inline gentone(int hz, int index)
}
/* Returns the power of the buffer of samples in 16bit slinear format.
- * power function = (sum of squares) - (square of sums).
- *
- * TODO: make the function stateless so that you can have some sort of
- * progressive power calculation on the line */
+ * power function = (sum of squares) - (square of sums). */
static float power_of(void *prebuf, int bufsize, int short_format)
{
float sum_of_squares = 0, square_of_sums = 0;
@@ -121,174 +118,6 @@ static float power_of(void *prebuf, int bufsize, int short_format)
return sqrtf(finalanswer);
}
-#if 0
-int fill_outputdata(int freq)
-{
- int i = 0;
-
- for (i = 0; i < TESTDURATIION; i++)
- outbuf[i] = gentone(freq, i);
-
-
-
- int randdev;
- int cursize = 0;
- int needlen = TEST_DURATION * 2;
- int res;
-
- fprintf(stdout, "Getting random impulse data\n");
- randdev = open("/dev/urandom", O_RDONLY);
- if (randdev < 0) {
- fprintf(stdout, "Unable to open /dev/random: %s\n", strerror(errno));
- return -1;
- }
-
- while (needlen) {
- res = read(randdev, &outbuf[cursize], needlen);
- if (res <= 0) {
- fprintf(stdout, "WARNING: could not read from /dev/random: %s\n", strerror(errno));
- return -1;
- }
- cursize += res;
- needlen -= res;
- }
-
- fprintf(stdout, "Succesfully filled the random data buffer\n");
- close(randdev);
-
- return 0;
-}
-#endif
-
-
-#if 0
-/* Returns index in echocan table with the lowest power pulse readback
- * -1 means the device is not an FXO module or fails */
-static int echo_tune(int whichzap, const char *dialstr)
-{
- int bestval = -1;
- int bestindex = -1;
- int i = 0, j=0;
- int x;
- int res = 0;
- int total = sizeof(echo_trys) / sizeof(struct wctdm_echo_coefs);
- short inbuf[BUFFER_LENGTH];
- struct zt_bufferinfo bi;
- struct zt_dialoperation dop;
- struct wctdm_echo_coefs coefs;
-
- /* Set echo settings */
- memset(&coefs, 0, sizeof(coefs));
- if (ioctl(whichzap, WCTDM_SET_ECHOTUNE, &coefs)) {
- fprintf(stdout, "Skipping non-TDM / non-FXO\n");
- return -1;
- }
-
- x = 1;
- if (ioctl(whichzap, ZT_SETLINEAR, &x)) {
- fprintf(stderr, "Unable to set channel to signed linear mode.\n");
- return -1;
- }
-
- memset(&bi, 0, sizeof(bi));
- if (ioctl(whichzap, ZT_GET_BUFINFO, &bi)) {
- fprintf(stderr, "Unable to get buffer information!\n");
- return -1;
- }
- bi.numbufs = 2;
- bi.bufsize = BUFFER_LENGTH;
- bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
- bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
- if (ioctl(whichzap, ZT_SET_BUFINFO, &bi)) {
- fprintf(stderr, "Unable to set buffer information!\n");
- return -1;
- }
-
- /* XXX May need to put in a loop XXX */
- for (j=0;j<(total + 15)/16;j++) {
- printf("Going off hook!\n");
- /* Take off hook */
- x = ZT_OFFHOOK;
- if(ioctl(whichzap, ZT_HOOK, &x)) {
- fprintf(stdout, "Unable to set hook state.\n");
- return -1;
- }
- sleep(2);
- printf("Off hook (event = %d)!\n", x);
- memset(&dop, 0, sizeof(dop));
- dop.op = ZT_DIAL_OP_REPLACE;
- dop.dialstr[0] = 'T';
- strncpy(dop.dialstr + 1, dialstr, sizeof(dop.dialstr) - 1);
- printf("Dialing...\n");
- if (ioctl(whichzap, ZT_DIAL, &dop)) {
- fprintf(stderr, "Unable to dial!\n");
- return -1;
- }
- sleep(2);
- printf("Finished Dialing...\n");
-
- for (i = j * 16; (i < total) && (i < (j+1) * 16); i++) {
- /* Set echo settings */
- if (ioctl(whichzap, WCTDM_SET_ECHOTUNE, &echo_trys[i])) {
- fprintf(stderr, "Unable to set echo params: %s\n", strerror(errno));
- return -1;
- }
-
- x = ZT_FLUSH_READ | ZT_FLUSH_WRITE | ZT_FLUSH_EVENT;
- if (ioctl(whichzap, ZT_FLUSH, &x)) {
- fprintf(stderr, "Unable to flush I/O: %s\n", strerror(errno));
- return -1;
- }
-
- /* write samples */
- res = write(whichzap, outbuf, TEST_DURATION * 2);
- if (res < 0) {
- fprintf(stdout, "Unable to write: %s\n", strerror(errno));
- return -1;
- }
-
- if (res != TEST_DURATION * 2) {
- fprintf(stdout, "Only could write %d of %d bytes.\n", res, TEST_DURATION * 2);
- return -1;
- }
-
- res = read(whichzap, inbuf, BUFFER_LENGTH * 2);
- if (res < 0) {
- fprintf(stdout, "Error in read: %s\n", strerror(errno));
- return -1;
- }
-
- if (res != BUFFER_LENGTH * 2) {
- fprintf(stdout, "Only could read %d of %d bytes.\n", res, BUFFER_LENGTH * 2);
- return -1;
- }
-
- res = process_readbuf(inbuf);
- printf("Test %d: %d\n", i + 1, res);
- /* Check to see if the echo values */
- if ((res < bestval) || (bestval < 0)) {
- bestval = res;
- bestindex = i;
- }
- usleep(100000);
- }
- printf("Going on hook!\n");
- /* Take off hook */
- x = ZT_ONHOOK;
- if(ioctl(whichzap, ZT_HOOK, &x)) {
- fprintf(stdout, "Unable to set hook state.\n");
- return -1;
- }
- sleep(2);
- printf("On hook (event = %d)!\n", x);
- }
- printf("Best is %d from index %d\n", bestval, bestindex);
-
- return 0;
-
-}
-#endif
-
/* Tune the line impedance. Look for best response range */
static int acim_tune(int whichzap, char *dialstr)
{
@@ -418,8 +247,10 @@ static int acim_tune(int whichzap, char *dialstr)
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]);
+ if (debug) {
+ 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 = 0;
for (i = 0; i < 16; i++) {
@@ -541,13 +372,6 @@ set:
/* Do output to file */
int len = 0;
static char output[255] = "";
-#if 0
- snprintf(output, sizeof(output), "%d=%d,%d,%d,%d,%d,%d,%d,%d,%d\n", i+1,
- echo_trys[i].acim, echo_trys[i].coef1, echo_trys[i].coef2,
- echo_trys[i].coef3, echo_trys[i].coef4, echo_trys[i].coef5,
- echo_trys[i].coef6, echo_trys[i].coef7, echo_trys[i].coef8 );
-#endif
-
snprintf(output, sizeof(output), "%d=%d,%d,%d,%d,%d,%d,%d,%d,%d\n", i+1, res,
0, 0, 0, 0, 0, 0, 0, 0);
len = strlen(output);