From b159e003162d2bbf594619c2eb48b3ab5449e70d Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 12 Apr 2011 20:53:17 -0300 Subject: [PATCH] atrf-path: added min/max values and corrected averaging algorithm - atrf-path.c (rssi_to_dBm, sample): moved RSSI value to dBm conversion to separate function - atrf-path.c (sample): corrected calculation of average - atrf-path.c (sample): also output minimum and maximum value - plot: new option -e to display extremal values - plot: added comment to explain y range --- tools/atrf-path/atrf-path.c | 21 +++++++++++++++++---- tools/atrf-path/plot | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/tools/atrf-path/atrf-path.c b/tools/atrf-path/atrf-path.c index 23ef61d..ea8007c 100644 --- a/tools/atrf-path/atrf-path.c +++ b/tools/atrf-path/atrf-path.c @@ -50,10 +50,17 @@ static void init_rx(struct atrf_dsc *dsc, int trim, int chan) } +static double rssi_to_dBm(double rssi) +{ + return -91+3*(rssi-1); +} + + static void sample(struct atrf_dsc *tx, struct atrf_dsc *rx, int trim_tx, int power, int chan, int cont_tx, int samples) { - int i, rssi = 0; + int i, rssi; + int sum = 0, min = -1, max = -1; double offset = tx_power_step2dBm(tx, power); init_tx(tx, trim_tx, power, chan); @@ -67,14 +74,20 @@ static void sample(struct atrf_dsc *tx, struct atrf_dsc *rx, int trim_tx, /* according to 8.3.2, PHY_RSSI is updated every 2 us */ usleep(2); - rssi += atrf_reg_read(rx, REG_PHY_RSSI) & RSSI_MASK; + rssi = atrf_reg_read(rx, REG_PHY_RSSI) & RSSI_MASK; + sum += rssi; + if (min == -1 || rssi < min) + min = rssi; + if (rssi > max) + max = rssi; } cw_test_end(tx); - printf("%.1f %.1f\n", + printf("%.1f %.2f %.0f %.0f\n", 2350+5*chan+(cont_tx == CONT_TX_M500K ? -0.5 : 0.5), - -91+3*(rssi-1.0)/samples-offset); + rssi_to_dBm((double) sum/samples)-offset, + rssi_to_dBm(min)-offset, rssi_to_dBm(max)-offset); } diff --git a/tools/atrf-path/plot b/tools/atrf-path/plot index 90de088..14d0ef8 100755 --- a/tools/atrf-path/plot +++ b/tools/atrf-path/plot @@ -2,11 +2,18 @@ usage() { - echo "usage: file ..." 1>&2 + echo "usage: [-e] file ..." 1>&2 exit 1 } +style=lines +if [ "$1" = -e ]; then + style=errorlines + shift +fi + [ "$1" ] || usage + files= while [ "$1" ]; do [ "$files" ] && files="$files, " @@ -15,9 +22,12 @@ while [ "$1" ]; do done gnuplot -persist <