blob: f1b77f4cf9ec3827d613cec2b41ed9fba89c0bbf [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 *
Harald Welte63d3e392010-03-06 11:34:27 +010020 */
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 Ayuso83419342011-03-22 16:36:13 +010029#include <osmocom/core/bitvec.h>
30#include <osmocom/gsm/rxlev_stat.h>
Harald Welte63d3e392010-03-06 11:34:27 +010031
Harald Welte63d3e392010-03-06 11:34:27 +010032void 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 */
46int16_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 Welte7c3b8fb2011-02-19 16:35:47 +010058 bv.data = (uint8_t *) st->rxlev_buckets[rxlev];
Harald Welte63d3e392010-03-06 11:34:27 +010059
60 return bitvec_find_bit_pos(&bv, arfcn+1, ONE);
61}
62
63void rxlev_stat_reset(struct rxlev_stats *st)
64{
65 memset(st, 0, sizeof(*st));
66}
67
68void 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}