Added new block for extracting info about base stations
diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt
index 15b3673..dc25035 100644
--- a/grc/CMakeLists.txt
+++ b/grc/CMakeLists.txt
@@ -23,5 +23,6 @@
     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
 )
diff --git a/grc/gsm_extract_system_info.xml b/grc/gsm_extract_system_info.xml
new file mode 100644
index 0000000..72434f6
--- /dev/null
+++ b/grc/gsm_extract_system_info.xml
@@ -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>
diff --git a/include/gsm/CMakeLists.txt b/include/gsm/CMakeLists.txt
index 49f4a43..cb71723 100644
--- a/include/gsm/CMakeLists.txt
+++ b/include/gsm/CMakeLists.txt
@@ -26,5 +26,6 @@
     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
 )
diff --git a/include/gsm/extract_system_info.h b/include/gsm/extract_system_info.h
new file mode 100644
index 0000000..a92c937
--- /dev/null
+++ b/include/gsm/extract_system_info.h
@@ -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 */
+
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 @@
     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 <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 */
+
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 <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 */
+
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 67d45f9..651baa5 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -35,7 +35,8 @@
     fcch_burst_tagger.py
     sch_detector.py
     fcch_detector.py 
-    chirpz.py DESTINATION ${GR_PYTHON_DIR}/gsm
+    chirpz.py
+    DESTINATION ${GR_PYTHON_DIR}/gsm
 )
 
 ########################################################################
diff --git a/python/__init__.py b/python/__init__.py
index ee72a0b..cf25d1c 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -50,6 +50,7 @@
 from fcch_burst_tagger import fcch_burst_tagger
 from sch_detector import sch_detector
 from fcch_detector import fcch_detector
+
 #
 
 # ----------------------------------------------------------------
diff --git a/swig/gsm_swig.i b/swig/gsm_swig.i
index 27163f5..724efb3 100644
--- a/swig/gsm_swig.i
+++ b/swig/gsm_swig.i
@@ -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, 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);