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