From dda22272e7aedefc6737dc8cf2cf9dc47009a85e Mon Sep 17 00:00:00 2001 From: piotr Date: Mon, 4 Aug 2014 11:31:54 +0200 Subject: Added new block for extracting info about base stations --- lib/CMakeLists.txt | 1 + lib/misc_utils/extract_system_info_impl.cc | 219 +++++++++++++++++++++++++++++ lib/misc_utils/extract_system_info_impl.h | 83 +++++++++++ 3 files changed, 303 insertions(+) create mode 100644 lib/misc_utils/extract_system_info_impl.cc create mode 100644 lib/misc_utils/extract_system_info_impl.h (limited to 'lib') diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 8e707be..5a730b9 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -30,6 +30,7 @@ list(APPEND gsm_sources receiver/viterbi_detector.cc receiver/sch.c misc_utils/bursts_printer_impl.cc + misc_utils/extract_system_info_impl.cc demapping/get_bcch_or_ccch_bursts_impl.cc decoding/control_channels_decoder_impl.cc decoding/cch.c diff --git a/lib/misc_utils/extract_system_info_impl.cc b/lib/misc_utils/extract_system_info_impl.cc new file mode 100644 index 0000000..1d20d8d --- /dev/null +++ b/lib/misc_utils/extract_system_info_impl.cc @@ -0,0 +1,219 @@ +/* -*- c++ -*- */ +/* + * Copyright 2014 <+YOU OR YOUR COMPANY+>. + * + * This 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 3, or (at your option) + * any later version. + * + * This software 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include "extract_system_info_impl.h" +#include + +#include + +namespace gr { + namespace gsm { + boost::mutex extract_mutex; + void extract_system_info_impl::process_bursts(pmt::pmt_t msg) + { + pmt::pmt_t burst = pmt::cdr(msg); + int8_t * burst_elements = (int8_t *)pmt::blob_data(burst); + size_t burst_len=pmt::blob_length(burst); + + pmt::pmt_t header_blob = pmt::car(msg); + gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_blob); + chan_info info; + info.id = header->arfcn; + info.pwr_db = header->signal_dbm; + + std::set::iterator iter = d_c0_channels.find(info); + + boost::mutex::scoped_lock lock(extract_mutex); + if(iter != d_c0_channels.end()){ + info.lac = iter->lac; + info.cell_id = iter->cell_id; + info.mnc = iter->mnc; + d_c0_channels.erase(iter); + d_c0_channels.insert(info); + } + d_c0_channels.insert(info); + } + + void extract_system_info_impl::process_sysinfo(pmt::pmt_t msg){ + pmt::pmt_t msg_blob = pmt::cdr(msg); + uint8_t * msg_elements = (uint8_t *)pmt::blob_data(msg_blob); + + if(msg_elements[2]==0x1b){ + //wyciągnij arfcn + pmt::pmt_t header_blob = pmt::car(msg); + gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_blob); + chan_info info; + info.id = header->arfcn; + info.pwr_db = header->signal_dbm; + info.cell_id = (msg_elements[3]<<8)+msg_elements[4]; //wyciągnij cell id + info.lac = (msg_elements[8]<<8)+msg_elements[9]; //wyciągnij lac + info.mnc = (msg_elements[7]>>4); //wyciągnij id operatora + + std::set::iterator iter = d_c0_channels.find(info); + boost::mutex::scoped_lock lock(extract_mutex); + if(iter != d_c0_channels.end()){ + d_c0_channels.erase(iter); + } + d_c0_channels.insert(info); + } + else if(msg_elements[2]==0x1c){ + pmt::pmt_t header_blob = pmt::car(msg); + gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_blob); + chan_info info; + info.id = header->arfcn; + info.pwr_db = header->signal_dbm; + info.lac = (msg_elements[6]<<8)+msg_elements[7]; //wyciągnij lac + info.mnc = (msg_elements[5]>>4); //wyciągnij id operatora + + + std::set::iterator iter = d_c0_channels.find(info); + boost::mutex::scoped_lock lock(extract_mutex); + if(iter != d_c0_channels.end()){ + d_c0_channels.erase(iter); + if(iter->cell_id!=0){ + info.cell_id=iter->cell_id; + } + } + d_c0_channels.insert(info); + } + } + + void extract_system_info_impl::show(){ + std::vector chans(d_c0_channels.begin(), d_c0_channels.end()); + std::vector::iterator iter; + //std::sort(chans.begin(), chans.end(), compare_pwr()); + for(iter=chans.begin(); iter != chans.end(); ++iter){ + std::cout << static_cast((*iter).id) << "(" << static_cast((*iter).pwr_db) << ") "; + } + std::cout << std::endl; + } + + std::vector extract_system_info_impl::get_chans() + { + std::vector chans(d_c0_channels.begin(), d_c0_channels.end()); + std::vector chans_ids(chans.size(),-1); + //std::sort(chans.begin(), chans.end(), compare_pwr()); + + for(int ii; ii < chans.size(); ++ii){ + chans_ids[ii] = chans[ii].id; + } + + return chans_ids; + } + + std::vector extract_system_info_impl::get_lac() + { + std::vector chans(d_c0_channels.begin(), d_c0_channels.end()); + std::vector chans_ids(chans.size(),-1); + //std::sort(chans.begin(), chans.end(), compare_pwr()); + + for(int ii; ii < chans.size(); ++ii){ + chans_ids[ii] = chans[ii].lac; + } + + return chans_ids; + } + std::vector extract_system_info_impl::get_mnc() + { + std::vector chans(d_c0_channels.begin(), d_c0_channels.end()); + std::vector chans_ids(chans.size(),-1); + //std::sort(chans.begin(), chans.end(), compare_pwr()); + + for(int ii; ii < chans.size(); ++ii){ + chans_ids[ii] = chans[ii].mnc; + } + + return chans_ids; + } + std::vector extract_system_info_impl::get_cell_id() + { + std::vector chans(d_c0_channels.begin(), d_c0_channels.end()); + std::vector chans_ids(chans.size(),-1); + //std::sort(chans.begin(), chans.end(), compare_pwr()); + + for(int ii; ii < chans.size(); ++ii){ + chans_ids[ii] = chans[ii].cell_id; + } + + return chans_ids; + } + + std::vector extract_system_info_impl::get_pwrs() + { + std::vector chans(d_c0_channels.begin(), d_c0_channels.end()); + std::vector pwrs(chans.size(),-1); + //std::sort(chans.begin(), chans.end(), compare_pwr()); + + for(int ii; ii < chans.size(); ++ii){ + pwrs[ii] = chans[ii].pwr_db; + } + + return pwrs; + } + + void extract_system_info_impl::reset() + { + d_c0_channels.clear(); + if(!empty_p(pmt::mp("bursts"))){ + delete_head_blocking(pmt::mp("bursts")); + } + } + + extract_system_info::sptr + extract_system_info::make() + { + return gnuradio::get_initial_sptr + (new extract_system_info_impl()); + } + + /* + * The private constructor + */ + extract_system_info_impl::extract_system_info_impl() + : gr::block("extract_system_info", + gr::io_signature::make(0, 0, 0), + gr::io_signature::make(0, 0, 0)), + after_reset(false) + { + message_port_register_in(pmt::mp("bursts")); + set_msg_handler(pmt::mp("bursts"), boost::bind(&extract_system_info_impl::process_bursts, this, _1)); + message_port_register_in(pmt::mp("msgs")); + set_msg_handler(pmt::mp("msgs"), boost::bind(&extract_system_info_impl::process_sysinfo, this, _1)); + } + + /* + * Our virtual destructor. + */ + extract_system_info_impl::~extract_system_info_impl() + { + } + + + } /* namespace gsm */ +} /* namespace gr */ + diff --git a/lib/misc_utils/extract_system_info_impl.h b/lib/misc_utils/extract_system_info_impl.h new file mode 100644 index 0000000..288a75d --- /dev/null +++ b/lib/misc_utils/extract_system_info_impl.h @@ -0,0 +1,83 @@ +/* -*- c++ -*- */ +/* + * Copyright 2014 <+YOU OR YOUR COMPANY+>. + * + * This 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 3, or (at your option) + * any later version. + * + * This software 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GSM_EXTRACT_SYSTEM_INFO_IMPL_H +#define INCLUDED_GSM_EXTRACT_SYSTEM_INFO_IMPL_H + +#include + + + +namespace gr { + namespace gsm { + + class chan_info { + public: + unsigned int id; + int8_t pwr_db; + unsigned int arfcn; + float freq; + unsigned int lac; + unsigned int cell_id; + unsigned int mnc; + + chan_info() : id(-1), pwr_db(0), arfcn(0), freq(0), lac(0), cell_id(0), mnc(0){} + chan_info(const chan_info & info) : id(info.id), pwr_db(info.pwr_db), arfcn(info.arfcn), freq(info.freq), lac(info.lac), cell_id(info.cell_id), mnc(info.mnc){} + ~chan_info(){} + }; + + + struct compare_id { + inline bool operator()(const chan_info &a, const chan_info &b) const + { + return a.id < b.id; + } + }; + struct compare_pwr { + inline bool operator()(const chan_info &a, const chan_info &b) const + { + return a.pwr_db < b.pwr_db; + } + }; + + + class extract_system_info_impl : public extract_system_info + { + private: + void process_bursts(pmt::pmt_t burst); + void process_sysinfo(pmt::pmt_t msg); + std::set d_c0_channels; + bool after_reset; + public: + virtual void show(); + virtual std::vector get_chans(); + virtual std::vector get_pwrs(); + virtual std::vector get_lac(); + virtual std::vector get_cell_id(); + virtual std::vector get_mnc(); + virtual void reset(); + extract_system_info_impl(); + ~extract_system_info_impl(); + }; + } // namespace gsm +} // namespace gr + +#endif /* INCLUDED_GSM_EXTRACT_SYSTEM_INFO_IMPL_H */ + -- cgit v1.2.3