Use the app_info->name instead of the hostname
[osmocom-bb.git] / src / rxlev_stat.c
1 /* 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
30 #include <osmocore/bitvec.h>
31 #include <osmocore/rxlev_stat.h>
32
33 int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val)
34 {
35         unsigned int i;
36
37         for (i = n; i < bv->data_len*8; i++) {
38                 if (bitvec_get_bit_pos(bv, i) == val)
39                         return i;
40         }
41
42         return -1;
43 }
44
45 void rxlev_stat_input(struct rxlev_stats *st, uint16_t arfcn, uint8_t rxlev)
46 {
47         struct bitvec bv;
48
49         if (rxlev >= NUM_RXLEVS)
50                 rxlev = NUM_RXLEVS-1;
51
52         bv.data_len = NUM_ARFCNS/8;
53         bv.data = st->rxlev_buckets[rxlev];
54
55         bitvec_set_bit_pos(&bv, arfcn, ONE);
56 }
57
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)
60 {
61         struct bitvec bv;
62
63         if (rxlev >= NUM_RXLEVS)
64                 rxlev = NUM_RXLEVS-1;
65
66         bv.data_len = NUM_ARFCNS/8;
67
68         if (arfcn < 0)
69                 arfcn = -1;
70
71         bv.data = st->rxlev_buckets[rxlev];
72
73         return bitvec_find_bit_pos(&bv, arfcn+1, ONE);
74 }
75
76 void rxlev_stat_reset(struct rxlev_stats *st)
77 {
78         memset(st, 0, sizeof(*st));
79 }
80
81 void rxlev_stat_dump(const struct rxlev_stats *st)
82 {
83         int i;
84
85         for (i = NUM_RXLEVS-1; i >= 0; i--) {
86                 int16_t arfcn = -1;
87
88                 printf("ARFCN with RxLev %u: ", i);
89                 while ((arfcn = rxlev_stat_get_next(st, i, arfcn)) >= 0) {
90                         printf("%u ", arfcn);
91                 }
92                 printf("\n");
93         }
94 }