Root/tools/atrf-txrx/per-text.c

Source at commit 8710be5665ec17da807a848e3286d3940c76dc1d created 6 years 10 months ago.
By Werner Almesberger, tools/atrf-txrx/atrf-txrx.c: add section headers and update clkm comment
1/*
2 * atrf-txrx/per-text.h - Report PER on console as text
3 *
4 * Written 2011 by Werner Almesberger
5 * Copyright 2011 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdio.h>
15
16#include "perdump.h"
17
18
19static char line[65] = "";
20static double t_line;
21static int packets = 0, garbled = 0, bad = 0, skipped = 0;
22static int is_bad = 0;
23
24
25static void flush(void)
26{
27    if (*line) {
28        printf("%9.3f ", t_line);
29        printf("%s\n", line);
30    }
31    *line = 0;
32}
33
34
35static void text_undecided(int symbols, double t)
36{
37    int i;
38
39    flush();
40    printf("%9.3f ", t);
41    for (i = 0; i != symbols/4; i++)
42        putchar('?');
43    putchar('\n');
44}
45
46
47static void text_packet(int symbols, int skip, double t)
48{
49    int i;
50
51    flush();
52    skipped += skip;
53    if (skip < 4)
54        for (i = 0; i != skip; i++)
55            putchar('\n');
56    else
57        printf("\n (%d)\n\n", skip);
58    for (i = 0; i != symbols/4; i++)
59        line[i] = '-';
60    line[i] = 0;
61    t_line = t;
62    packets++;
63    is_bad = 0;
64}
65
66
67static void text_error(int symbol)
68{
69    line[symbol >> 2] = '*';
70    if (!is_bad) {
71        bad++;
72        is_bad = 1;
73    }
74}
75
76
77static void text_finish(void)
78{
79    double per;
80
81    flush();
82    if (packets+garbled)
83        per = (double) (bad+garbled)/(packets+garbled);
84    else
85        per = 0;
86    printf("\n%d total, %d bad, %d garbled, PER %f%%. %d skipped.\n",
87        packets+garbled, bad, garbled, 100*per, skipped);
88}
89
90
91struct result_ops text_ops = {
92    .begin = NULL,
93    .undecided = text_undecided,
94    .packet = text_packet,
95    .error = text_error,
96    .finish = text_finish,
97};
98

Archive Download this file



interactive