IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
| Source at commit ac710d0de437e2292a94498c38339d8d978adbee created 6 years 7 months ago. By Werner Almesberger, web/index.html: update shop links; status table; link to ATUSB schematics | |
|---|---|
| 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 | |
| 19 | static char line[65] = ""; |
| 20 | static double t_line; |
| 21 | static int packets = 0, garbled = 0, bad = 0, skipped = 0; |
| 22 | static int is_bad = 0; |
| 23 | |
| 24 | |
| 25 | static 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 | |
| 35 | static 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 | |
| 47 | static 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 | |
| 67 | static void text_error(int symbol) |
| 68 | { |
| 69 | line[symbol >> 2] = '*'; |
| 70 | if (!is_bad) { |
| 71 | bad++; |
| 72 | is_bad = 1; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | |
| 77 | static 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 | |
| 91 | struct 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 | |
