# HG changeset patch # User Matthew Wild # Date 1242421942 -3600 # Node ID cfb60868c7458d7b95f1404edaa96234c58b7c5f # Parent 2f2165f8c8ea9746ab0dc7945a3e9552fadb1ef6 Print RMS of 15 samples diff -r 2f2165f8c8ea -r cfb60868c745 main.c --- a/main.c Fri May 15 21:03:40 2009 +0100 +++ b/main.c Fri May 15 22:12:22 2009 +0100 @@ -1,4 +1,5 @@ #include +#include #include #include @@ -7,10 +8,12 @@ xmpp_conn_t *conn1, *conn2; -unsigned long mincount, maxcount, count; +unsigned long mincount, maxcount; +unsigned long count = 0; -long samples; /* Current number of samples taken */ -long max_samples; /* The number of samples to do, if specified by user */ +unsigned long sum_squares = 0; +unsigned long samples = 0; /* Current number of samples taken */ +unsigned long max_samples = 15; /* The number of samples to do, if specified by user */ time_t lasttime; /* Time of the last sample we took */ @@ -33,11 +36,22 @@ count++; if(time(NULL) != lasttime) { - printf("%d stanzas/sec\n", count); - if(count > maxcount) + + if(lasttime > 0) { - printf("%d beats old maximum of %d\n", count, maxcount); - maxcount = count; + //printf("%d stanzas/sec\n", count); + if(count > maxcount && lasttime > 0) + { + //printf("%d beats old maximum of %d\n", count, maxcount); + maxcount = count; + } + sum_squares += count*count; + samples++; + if(samples >= max_samples) + { + printf("%Lf\n", sqrtl(sum_squares/samples)); + exit(0); + } } count = 0; lasttime = time(NULL); @@ -57,7 +71,7 @@ if (status == XMPP_CONN_CONNECT) { xmpp_stanza_t* pres; - fprintf(stderr, "DEBUG: connected\n"); + //fprintf(stderr, "DEBUG: connected\n"); xmpp_handler_add(conn,message_handler, NULL, "message", NULL, ctx); /* Send initial so that we appear online to contacts */ @@ -69,13 +83,13 @@ if(conn == conn2) { count = 0; - lasttime = time(NULL); + lasttime = 0; xmpp_send(conn1, bstanza); } } else { - fprintf(stderr, "DEBUG: disconnected\n"); + //fprintf(stderr, "DEBUG: disconnected\n"); xmpp_stop(ctx); } } @@ -86,7 +100,7 @@ xmpp_log_t *log = NULL; xmpp_stanza_t *body, *text; - printf("Loading...\n"); + //printf("Loading...\n"); /* init library */ xmpp_initialize(); @@ -128,7 +142,7 @@ xmpp_connect_client(conn1, "localhost", 5222, conn_handler, ctx); xmpp_connect_client(conn2, "localhost", 5222, conn_handler, ctx); - printf("Connecting...\n"); + //printf("Connecting...\n"); /* enter the event loop - our connect handler will trigger an exit */ xmpp_run(ctx);