1 /* Rx Level statistics */
3 /* (C) 2010 by Harald Welte <laforge@gnumonks.org>
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.
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.
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.
30 #include <osmocore/bitvec.h>
31 #include <osmocore/rxlev_stat.h>
33 int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val)
37 for (i = n; i < bv->data_len*8; i++) {
38 if (bitvec_get_bit_pos(bv, i) == val)
45 void rxlev_stat_input(struct rxlev_stats *st, uint16_t arfcn, uint8_t rxlev)
49 if (rxlev >= NUM_RXLEVS)
52 bv.data_len = NUM_ARFCNS/8;
53 bv.data = st->rxlev_buckets[rxlev];
55 bitvec_set_bit_pos(&bv, arfcn, ONE);
58 /* get the next ARFCN that has the specified Rxlev */
59 int16_t rxlev_stat_get_next(const struct rxlev_stats *st, uint8_t rxlev, int16_t arfcn)
63 if (rxlev >= NUM_RXLEVS)
66 bv.data_len = NUM_ARFCNS/8;
71 bv.data = st->rxlev_buckets[rxlev];
73 return bitvec_find_bit_pos(&bv, arfcn+1, ONE);
76 void rxlev_stat_reset(struct rxlev_stats *st)
78 memset(st, 0, sizeof(*st));
81 void rxlev_stat_dump(const struct rxlev_stats *st)
85 for (i = NUM_RXLEVS-1; i >= 0; i--) {
88 printf("ARFCN with RxLev %u: ", i);
89 while ((arfcn = rxlev_stat_get_next(st, i, arfcn)) >= 0) {