Added new block for extracting info about base stations

trx_hopping
piotr 2014-08-04 11:31:54 +02:00
parent b529a59a91
commit dda22272e7
10 changed files with 395 additions and 3 deletions

View File

@ -23,5 +23,6 @@ install(FILES
gsm_sch_detector.xml
gsm_fcch_detector.xml
gsm_get_bcch_or_ccch_bursts.xml
gsm_control_channels_decoder.xml DESTINATION share/gnuradio/grc/blocks
gsm_control_channels_decoder.xml
gsm_extract_system_info.xml DESTINATION share/gnuradio/grc/blocks
)

View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<block>
<name>extract_system_info</name>
<key>gsm_extract_system_info</key>
<category>gsm</category>
<import>import gsm</import>
<make>gsm.extract_system_info()</make>
<sink>
<name>msgs</name>
<type>message</type>
</sink>
<sink>
<name>bursts</name>
<type>message</type>
</sink>
</block>

View File

@ -26,5 +26,6 @@ install(FILES
bursts_printer.h
get_bcch_or_ccch_bursts.h
control_channels_decoder.h
gsmtap.h DESTINATION include/gsm
gsmtap.h
extract_system_info.h DESTINATION include/gsm
)

View File

@ -0,0 +1,63 @@
/* -*- 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_H
#define INCLUDED_GSM_EXTRACT_SYSTEM_INFO_H
#include <gsm/api.h>
#include <gnuradio/block.h>
namespace gr {
namespace gsm {
/*!
* \brief <+description of block+>
* \ingroup gsm
*
*/
class GSM_API extract_system_info : virtual public gr::block
{
public:
typedef boost::shared_ptr<extract_system_info> sptr;
/*!
* \brief Return a shared_ptr to a new instance of gsm::extract_system_info.
*
* To avoid accidental use of raw pointers, gsm::extract_system_info's
* constructor is in a private implementation
* class. gsm::extract_system_info::make is the public interface for
* creating new instances.
*/
static sptr make();
virtual void show() = 0;
virtual std::vector<int> get_chans() = 0;
virtual std::vector<int> get_pwrs() = 0;
virtual std::vector<int> get_lac() = 0;
virtual std::vector<int> get_cell_id() = 0;
virtual std::vector<int> get_mnc() = 0;
virtual void reset() = 0;
};
} // namespace gsm
} // namespace gr
#endif /* INCLUDED_GSM_EXTRACT_SYSTEM_INFO_H */

View File

@ -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

View File

@ -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 <gnuradio/io_signature.h>
#include <gsm/gsmtap.h>
#include <iterator>
#include <algorithm>
#include "extract_system_info_impl.h"
#include <unistd.h>
#include <iostream>
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<chan_info, compare_id>::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<chan_info, compare_id>::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<chan_info, compare_id>::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<chan_info> chans(d_c0_channels.begin(), d_c0_channels.end());
std::vector<chan_info>::iterator iter;
//std::sort(chans.begin(), chans.end(), compare_pwr());
for(iter=chans.begin(); iter != chans.end(); ++iter){
std::cout << static_cast<int>((*iter).id) << "(" << static_cast<int>((*iter).pwr_db) << ") ";
}
std::cout << std::endl;
}
std::vector<int> extract_system_info_impl::get_chans()
{
std::vector<chan_info> chans(d_c0_channels.begin(), d_c0_channels.end());
std::vector<int> 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<int> extract_system_info_impl::get_lac()
{
std::vector<chan_info> chans(d_c0_channels.begin(), d_c0_channels.end());
std::vector<int> 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<int> extract_system_info_impl::get_mnc()
{
std::vector<chan_info> chans(d_c0_channels.begin(), d_c0_channels.end());
std::vector<int> 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<int> extract_system_info_impl::get_cell_id()
{
std::vector<chan_info> chans(d_c0_channels.begin(), d_c0_channels.end());
std::vector<int> 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<int> extract_system_info_impl::get_pwrs()
{
std::vector<chan_info> chans(d_c0_channels.begin(), d_c0_channels.end());
std::vector<int> 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 */

View File

@ -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 <gsm/extract_system_info.h>
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<chan_info, compare_id> d_c0_channels;
bool after_reset;
public:
virtual void show();
virtual std::vector<int> get_chans();
virtual std::vector<int> get_pwrs();
virtual std::vector<int> get_lac();
virtual std::vector<int> get_cell_id();
virtual std::vector<int> 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 */

View File

@ -35,7 +35,8 @@ GR_PYTHON_INSTALL(
fcch_burst_tagger.py
sch_detector.py
fcch_detector.py
chirpz.py DESTINATION ${GR_PYTHON_DIR}/gsm
chirpz.py
DESTINATION ${GR_PYTHON_DIR}/gsm
)
########################################################################

View File

@ -50,6 +50,7 @@ from receiver_hier import receiver_hier
from fcch_burst_tagger import fcch_burst_tagger
from sch_detector import sch_detector
from fcch_detector import fcch_detector
#
# ----------------------------------------------------------------

View File

@ -12,6 +12,7 @@
#include "gsm/bursts_printer.h"
#include "gsm/get_bcch_or_ccch_bursts.h"
#include "gsm/control_channels_decoder.h"
#include "gsm/extract_system_info.h"
%}
@ -24,3 +25,5 @@ GR_SWIG_BLOCK_MAGIC2(gsm, bursts_printer);
GR_SWIG_BLOCK_MAGIC2(gsm, get_bcch_or_ccch_bursts);
%include "gsm/control_channels_decoder.h"
GR_SWIG_BLOCK_MAGIC2(gsm, control_channels_decoder);
%include "gsm/extract_system_info.h"
GR_SWIG_BLOCK_MAGIC2(gsm, extract_system_info);