blob: 9c650cc19de3ea0ace104564ee13d7f6a88f8ad2 [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 *
Harald Weltee08da972017-11-13 01:00:26 +09008 * SPDX-License-Identifier: GPL-2.0+
9 *
Harald Welte63d3e392010-03-06 11:34:27 +010010 * 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 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 *
24 */
25
26#include <unistd.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <errno.h>
31#include <stdint.h>
32
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010033#include <osmocom/core/bitvec.h>
34#include <osmocom/gsm/rxlev_stat.h>
Harald Welte63d3e392010-03-06 11:34:27 +010035
Harald Welte63d3e392010-03-06 11:34:27 +010036void rxlev_stat_input(struct rxlev_stats *st, uint16_t arfcn, uint8_t rxlev)
37{
38 struct bitvec bv;
39
40 if (rxlev >= NUM_RXLEVS)
41 rxlev = NUM_RXLEVS-1;
42
43 bv.data_len = NUM_ARFCNS/8;
44 bv.data = st->rxlev_buckets[rxlev];
45
46 bitvec_set_bit_pos(&bv, arfcn, ONE);
47}
48
49/* get the next ARFCN that has the specified Rxlev */
50int16_t rxlev_stat_get_next(const struct rxlev_stats *st, uint8_t rxlev, int16_t arfcn)
51{
52 struct bitvec bv;
53
54 if (rxlev >= NUM_RXLEVS)
55 rxlev = NUM_RXLEVS-1;
56
57 bv.data_len = NUM_ARFCNS/8;
58
59 if (arfcn < 0)
60 arfcn = -1;
61
Harald Welte7c3b8fb2011-02-19 16:35:47 +010062 bv.data = (uint8_t *) st->rxlev_buckets[rxlev];
Harald Welte63d3e392010-03-06 11:34:27 +010063
64 return bitvec_find_bit_pos(&bv, arfcn+1, ONE);
65}
66
67void rxlev_stat_reset(struct rxlev_stats *st)
68{
69 memset(st, 0, sizeof(*st));
70}
71
72void rxlev_stat_dump(const struct rxlev_stats *st)
73{
74 int i;
75
76 for (i = NUM_RXLEVS-1; i >= 0; i--) {
77 int16_t arfcn = -1;
78
79 printf("ARFCN with RxLev %u: ", i);
80 while ((arfcn = rxlev_stat_get_next(st, i, arfcn)) >= 0) {
81 printf("%u ", arfcn);
82 }
83 printf("\n");
84 }
85}