Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file rxlev_stat.c |
| 2 | * Rx Level statistics */ |
| 3 | /* |
| 4 | * (C) 2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 63d3e39 | 2010-03-06 11:34:27 +0100 | [diff] [blame] | 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
| 9 | * |
Harald Welte | 63d3e39 | 2010-03-06 11:34:27 +0100 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
Harald Welte | 63d3e39 | 2010-03-06 11:34:27 +0100 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <unistd.h> |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <errno.h> |
| 27 | #include <stdint.h> |
| 28 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 29 | #include <osmocom/core/bitvec.h> |
| 30 | #include <osmocom/gsm/rxlev_stat.h> |
Harald Welte | 63d3e39 | 2010-03-06 11:34:27 +0100 | [diff] [blame] | 31 | |
Harald Welte | 63d3e39 | 2010-03-06 11:34:27 +0100 | [diff] [blame] | 32 | void rxlev_stat_input(struct rxlev_stats *st, uint16_t arfcn, uint8_t rxlev) |
| 33 | { |
| 34 | struct bitvec bv; |
| 35 | |
| 36 | if (rxlev >= NUM_RXLEVS) |
| 37 | rxlev = NUM_RXLEVS-1; |
| 38 | |
| 39 | bv.data_len = NUM_ARFCNS/8; |
| 40 | bv.data = st->rxlev_buckets[rxlev]; |
| 41 | |
| 42 | bitvec_set_bit_pos(&bv, arfcn, ONE); |
| 43 | } |
| 44 | |
| 45 | /* get the next ARFCN that has the specified Rxlev */ |
| 46 | int16_t rxlev_stat_get_next(const struct rxlev_stats *st, uint8_t rxlev, int16_t arfcn) |
| 47 | { |
| 48 | struct bitvec bv; |
| 49 | |
| 50 | if (rxlev >= NUM_RXLEVS) |
| 51 | rxlev = NUM_RXLEVS-1; |
| 52 | |
| 53 | bv.data_len = NUM_ARFCNS/8; |
| 54 | |
| 55 | if (arfcn < 0) |
| 56 | arfcn = -1; |
| 57 | |
Harald Welte | 7c3b8fb | 2011-02-19 16:35:47 +0100 | [diff] [blame] | 58 | bv.data = (uint8_t *) st->rxlev_buckets[rxlev]; |
Harald Welte | 63d3e39 | 2010-03-06 11:34:27 +0100 | [diff] [blame] | 59 | |
| 60 | return bitvec_find_bit_pos(&bv, arfcn+1, ONE); |
| 61 | } |
| 62 | |
| 63 | void rxlev_stat_reset(struct rxlev_stats *st) |
| 64 | { |
| 65 | memset(st, 0, sizeof(*st)); |
| 66 | } |
| 67 | |
| 68 | void rxlev_stat_dump(const struct rxlev_stats *st) |
| 69 | { |
| 70 | int i; |
| 71 | |
| 72 | for (i = NUM_RXLEVS-1; i >= 0; i--) { |
| 73 | int16_t arfcn = -1; |
| 74 | |
| 75 | printf("ARFCN with RxLev %u: ", i); |
| 76 | while ((arfcn = rxlev_stat_get_next(st, i, arfcn)) >= 0) { |
| 77 | printf("%u ", arfcn); |
| 78 | } |
| 79 | printf("\n"); |
| 80 | } |
| 81 | } |