From 63d3e396e79bae0e3580a8813a8c1c0166a51b59 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 6 Mar 2010 11:34:27 +0100 Subject: [PATCH] introduce RxLev statistics module, an efficient way for power scan data --- include/osmocore/Makefile.am | 2 +- include/osmocore/rxlev_stat.h | 22 ++++++++ src/Makefile.am | 2 +- src/rxlev_stat.c | 94 +++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 include/osmocore/rxlev_stat.h create mode 100644 src/rxlev_stat.c diff --git a/include/osmocore/Makefile.am b/include/osmocore/Makefile.am index b45d02338..9c4fc757d 100644 --- a/include/osmocore/Makefile.am +++ b/include/osmocore/Makefile.am @@ -1,6 +1,6 @@ osmocore_HEADERS = signal.h linuxlist.h timer.h talloc.h msgb.h select.h \ tlv.h bitvec.h comp128.h statistics.h gsm_utils.h utils.h \ - gsmtap.h write_queue.h rsl.h gsm48.h + gsmtap.h write_queue.h rsl.h gsm48.h rxlev_stat.h osmocoredir = $(includedir)/osmocore diff --git a/include/osmocore/rxlev_stat.h b/include/osmocore/rxlev_stat.h new file mode 100644 index 000000000..415509dc2 --- /dev/null +++ b/include/osmocore/rxlev_stat.h @@ -0,0 +1,22 @@ +#ifndef _OSMOCORE_RXLEV_STATS_H +#define _OSMOCORE_RXLEV_STATS_H + +#define NUM_RXLEVS 32 +#define NUM_ARFCNS 1024 + +struct rxlev_stats { + /* the maximum number of ARFCN's is 1024, and there are 32 RxLevels, + * so in we keep one 1024bit-bitvec for each RxLev */ + uint8_t rxlev_buckets[NUM_RXLEVS][NUM_ARFCNS/8]; +}; + +void rxlev_stat_input(struct rxlev_stats *st, uint16_t arfcn, uint8_t rxlev); + +/* get the next ARFCN that has the specified Rxlev */ +int16_t rxlev_stat_get_next(const struct rxlev_stats *st, uint8_t rxlev, int16_t arfcn); + +void rxlev_stat_reset(struct rxlev_stats *st); + +void rxlev_stat_dump(const struct rxlev_stats *st); + +#endif /* _OSMOCORE_RXLEV_STATS_H */ diff --git a/src/Makefile.am b/src/Makefile.am index b6826ea50..99424522f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,4 +9,4 @@ lib_LTLIBRARIES = libosmocore.la libosmocore_la_SOURCES = msgb.c timer.c talloc.c select.c signal.c \ tlv_parser.c bitvec.c comp128.c gsm_utils.c statistics.c \ - write_queue.c utils.c rsl.c gsm48.c + write_queue.c utils.c rsl.c gsm48.c rxlev_stat.c diff --git a/src/rxlev_stat.c b/src/rxlev_stat.c new file mode 100644 index 000000000..1bfd6795a --- /dev/null +++ b/src/rxlev_stat.c @@ -0,0 +1,94 @@ +/* Rx Level statistics */ + +/* (C) 2010 by Harald Welte + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val) +{ + unsigned int i; + + for (i = n; i < bv->data_len*8; i++) { + if (bitvec_get_bit_pos(bv, i) == val) + return i; + } + + return -1; +} + +void rxlev_stat_input(struct rxlev_stats *st, uint16_t arfcn, uint8_t rxlev) +{ + struct bitvec bv; + + if (rxlev >= NUM_RXLEVS) + rxlev = NUM_RXLEVS-1; + + bv.data_len = NUM_ARFCNS/8; + bv.data = st->rxlev_buckets[rxlev]; + + bitvec_set_bit_pos(&bv, arfcn, ONE); +} + +/* get the next ARFCN that has the specified Rxlev */ +int16_t rxlev_stat_get_next(const struct rxlev_stats *st, uint8_t rxlev, int16_t arfcn) +{ + struct bitvec bv; + + if (rxlev >= NUM_RXLEVS) + rxlev = NUM_RXLEVS-1; + + bv.data_len = NUM_ARFCNS/8; + + if (arfcn < 0) + arfcn = -1; + + bv.data = st->rxlev_buckets[rxlev]; + + return bitvec_find_bit_pos(&bv, arfcn+1, ONE); +} + +void rxlev_stat_reset(struct rxlev_stats *st) +{ + memset(st, 0, sizeof(*st)); +} + +void rxlev_stat_dump(const struct rxlev_stats *st) +{ + int i; + + for (i = NUM_RXLEVS-1; i >= 0; i--) { + int16_t arfcn = -1; + + printf("ARFCN with RxLev %u: ", i); + while ((arfcn = rxlev_stat_get_next(st, i, arfcn)) >= 0) { + printf("%u ", arfcn); + } + printf("\n"); + } +}