blob: 2ff0ac84880911e65e1a1728da27018ed5de5471 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file rxlev_stat.c
2 * Rx Level statistics */
3/*
4 * (C) 2010 by Harald Welte <laforge@gnumonks.org>
Harald Welte63d3e392010-03-06 11:34:27 +01005 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <unistd.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <errno.h>
29#include <stdint.h>
30
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010031#include <osmocom/core/bitvec.h>
32#include <osmocom/gsm/rxlev_stat.h>
Harald Welte63d3e392010-03-06 11:34:27 +010033
Harald Welte63d3e392010-03-06 11:34:27 +010034void rxlev_stat_input(struct rxlev_stats *st, uint16_t arfcn, uint8_t rxlev)
35{
36 struct bitvec bv;
37
38 if (rxlev >= NUM_RXLEVS)
39 rxlev = NUM_RXLEVS-1;
40
41 bv.data_len = NUM_ARFCNS/8;
42 bv.data = st->rxlev_buckets[rxlev];
43
44 bitvec_set_bit_pos(&bv, arfcn, ONE);
45}
46
47/* get the next ARFCN that has the specified Rxlev */
48int16_t rxlev_stat_get_next(const struct rxlev_stats *st, uint8_t rxlev, int16_t arfcn)
49{
50 struct bitvec bv;
51
52 if (rxlev >= NUM_RXLEVS)
53 rxlev = NUM_RXLEVS-1;
54
55 bv.data_len = NUM_ARFCNS/8;
56
57 if (arfcn < 0)
58 arfcn = -1;
59
Harald Welte7c3b8fb2011-02-19 16:35:47 +010060 bv.data = (uint8_t *) st->rxlev_buckets[rxlev];
Harald Welte63d3e392010-03-06 11:34:27 +010061
62 return bitvec_find_bit_pos(&bv, arfcn+1, ONE);
63}
64
65void rxlev_stat_reset(struct rxlev_stats *st)
66{
67 memset(st, 0, sizeof(*st));
68}
69
70void rxlev_stat_dump(const struct rxlev_stats *st)
71{
72 int i;
73
74 for (i = NUM_RXLEVS-1; i >= 0; i--) {
75 int16_t arfcn = -1;
76
77 printf("ARFCN with RxLev %u: ", i);
78 while ((arfcn = rxlev_stat_get_next(st, i, arfcn)) >= 0) {
79 printf("%u ", arfcn);
80 }
81 printf("\n");
82 }
83}