From cf8509d0cdc292704a9cd9a2673f420672333022 Mon Sep 17 00:00:00 2001 From: markster Date: Fri, 20 Sep 2002 17:18:16 +0000 Subject: Version 0.3.1 from FTP git-svn-id: http://svn.digium.com/svn/zaptel/trunk@107 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- ztmonitor.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 11 deletions(-) diff --git a/ztmonitor.c b/ztmonitor.c index 2a6cca9..db20d58 100755 --- a/ztmonitor.c +++ b/ztmonitor.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #ifdef STANDALONE_ZAPATA @@ -128,38 +129,128 @@ int pseudo_open(void) return fd; } +void draw_bar(char *label, int avg) +{ + char bar[35]; + int left; + if (avg > 7500) + avg = 7500; + memset(bar, '#', sizeof(bar)); + bar[sizeof(bar) - 1] = '\0'; + avg /= 200; + left = sizeof(bar) - 1 - avg; + if (left > 0) + memset(bar + avg, ' ', left); + printf("%s %s", label, bar); + fflush(stdout); +} + +void visualize(short *tx, short *rx, int cnt) +{ + int x; + int txavg = 0; + int rxavg = 0; + static int txbest = 0; + static int rxbest = 0; + int ms; + static struct timeval last; + struct timeval tv; + + gettimeofday(&tv, NULL); + ms = (tv.tv_sec - last.tv_sec) * 1000 + (tv.tv_usec - last.tv_usec) / 1000; + for (x=0;x txbest) + txbest = txavg; + if (rxavg > rxbest) + rxbest = rxavg; + + /* Update no more than 10 times a second */ + if (ms < 100) + return; + + memcpy(&last, &tv, sizeof(last)); + /* Clear screen */ + printf("\r"); + draw_bar("Rx", rxbest); + draw_bar("Tx", txbest); + txbest = 0; + rxbest = 0; +} + int main(int argc, char *argv[]) { - int afd, pfd; + int afd = -1, pfd, pfd2 = -1; char buf[8192]; - int res; + char buf2[8192]; + int res, res2; + int visual = 0; struct zt_confinfo zc; if ((argc < 2) || (atoi(argv[1]) < 1)) { - fprintf(stderr, "Usage: ztmonitor \n"); + fprintf(stderr, "Usage: ztmonitor [-v]\n"); exit(1); } - /* Open audio */ - if ((afd = audio_open()) < 0) - exit(1); + if (argc > 2) { + if (!strcmp(argv[2], "-v")) + visual = 1; + } + if (!visual) { + /* Open audio */ + if ((afd = audio_open()) < 0) + exit(1); + } /* Open Pseudo device */ if ((pfd = pseudo_open()) < 0) exit(1); + if (visual && ((pfd2 = pseudo_open()) < 0)) + exit(1); /* Conference them */ memset(&zc, 0, sizeof(zc)); zc.chan = 0; zc.confno = atoi(argv[1]); - zc.confmode = ZT_CONF_MONITORBOTH; - if (ioctl(pfd, ZT_SETCONF, &zc) < 0) { - fprintf(stderr, "Unable to monitor: %s\n", strerror(errno)); - exit(1); + if (visual) { + /* Two pseudo's, one for tx, one for rx */ + zc.confmode = ZT_CONF_MONITORTX; + if (ioctl(pfd, ZT_SETCONF, &zc) < 0) { + fprintf(stderr, "Unable to monitor: %s\n", strerror(errno)); + exit(1); + } + memset(&zc, 0, sizeof(zc)); + zc.chan = 0; + zc.confno = atoi(argv[1]); + zc.confmode = ZT_CONF_MONITOR; + if (ioctl(pfd2, ZT_SETCONF, &zc) < 0) { + fprintf(stderr, "Unable to monitor: %s\n", strerror(errno)); + exit(1); + } + } else { + zc.confmode = ZT_CONF_MONITORBOTH; + if (ioctl(pfd, ZT_SETCONF, &zc) < 0) { + fprintf(stderr, "Unable to monitor: %s\n", strerror(errno)); + exit(1); + } } /* Now, copy from pseudo to audio */ for (;;) { res = read(pfd, buf, sizeof(buf)); if (res < 1) break; - write(afd, buf, res); + if (visual) { + res2 = read(pfd2, buf2, res); + if (res2 < 1) + break; + if (res == res2) + visualize((short *)buf, (short *)buf2, res/2); + else + printf("Huh? res = %d, res2 = %d?\n", res, res2); + } else + write(afd, buf, res); } exit(0); } -- cgit v1.2.3