Merge branch 'ptrkrysik/trx' of https://github.com/ptrkrysik/gr-gsm into ptrkrysik/trx
diff --git a/grc/gsm_block_tree.xml b/grc/gsm_block_tree.xml
index ac3670e..ae41f4d 100644
--- a/grc/gsm_block_tree.xml
+++ b/grc/gsm_block_tree.xml
@@ -24,6 +24,7 @@
     <cat>
       <name>Transmitter</name>
       <block>gsm_txtime_bursts_tagger</block>
+      <block>gsm_txtime_setter</block>
       <block>gsm_gmsk_mod</block>
     </cat>
     <cat>
diff --git a/grc/transmitter/CMakeLists.txt b/grc/transmitter/CMakeLists.txt
index c41f56a..e512d10 100644
--- a/grc/transmitter/CMakeLists.txt
+++ b/grc/transmitter/CMakeLists.txt
@@ -19,5 +19,6 @@
 
 install(FILES
     gsm_gmsk_mod.xml
-    gsm_txtime_bursts_tagger.xml DESTINATION share/gnuradio/grc/blocks
+    gsm_txtime_bursts_tagger.xml 
+    gsm_txtime_setter.xml DESTINATION share/gnuradio/grc/blocks
 )
diff --git a/grc/transmitter/gsm_txtime_setter.xml b/grc/transmitter/gsm_txtime_setter.xml
new file mode 100644
index 0000000..648f4d9
--- /dev/null
+++ b/grc/transmitter/gsm_txtime_setter.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0"?>
+<block>
+  <name>txtime_setter</name>
+  <key>gsm_txtime_setter</key>
+  <import>import grgsm</import>
+  <make>grgsm.txtime_setter($init_fn if ($init_fn is not None) else 0xffffffff, $init_time_secs, $init_time_fracs, $time_hint_secs, $time_hint_fracs, $timing_advance, $delay_correction)</make>
+  
+  <callback>set_fn_time_reference($init_fn, $init_time_secs, $init_time_fracs)</callback>
+  <callback>set_time_hint($time_hint_secs, $time_hint_secs)</callback>
+  <callback>set_timing_advance($timing_advance)</callback>
+  <callback>set_delay_correction($delay_correction)</callback>
+
+  <param>
+    <name>init_fn</name>
+    <key>init_fn</key>
+    <value>None</value>
+    <type>raw</type>
+    <hide>part</hide>
+  </param>
+
+  <param>
+    <name>init_time_secs</name>
+    <key>init_time_secs</key>
+    <value>0</value>
+    <type>int</type>
+    <hide>part</hide>
+  </param>
+  <param>
+    <name>init_time_fracs</name>
+    <key>init_time_fracs</key>
+    <value>0</value>
+    <type>float</type>
+    <hide>part</hide>
+  </param>
+
+  <param>
+    <name>time_hint_secs</name>
+    <key>time_hint_secs</key>
+    <value>0</value>
+    <type>int</type>
+    <hide>part</hide>
+  </param>
+  <param>
+    <name>time_hint_fracs</name>
+    <key>time_hint_fracs</key>
+    <value>0</value>
+    <type>float</type>
+    <hide>part</hide>
+  </param>
+
+  <param>
+    <name>timing_advance</name>
+    <key>timing_advance</key>
+    <value>0</value>
+    <type>float</type>
+    <hide>part</hide>
+  </param>
+
+  <param>
+    <name>delay_correction</name>
+    <key>delay_correction</key>
+    <value>0</value>
+    <type>float</type>
+    <hide>part</hide>
+  </param>
+
+  <sink>
+    <name>fn_time</name>
+    <type>message</type>
+    <optional>1</optional>
+  </sink>
+
+  <sink>
+    <name>bursts_in</name>
+    <type>message</type>
+    <optional>1</optional>
+  </sink>
+
+  <source>
+    <name>bursts_out</name>
+    <type>message</type>
+    <optional>1</optional>
+  </source>
+</block>
diff --git a/include/grgsm/CMakeLists.txt b/include/grgsm/CMakeLists.txt
index 1ce9134..59034dc 100644
--- a/include/grgsm/CMakeLists.txt
+++ b/include/grgsm/CMakeLists.txt
@@ -35,4 +35,5 @@
 add_subdirectory(misc_utils)
 add_subdirectory(qa_utils)
 add_subdirectory(flow_control)
+add_subdirectory(transmitter)
 add_subdirectory(trx_interface)
diff --git a/include/grgsm/flow_control/uplink_downlink_splitter.h b/include/grgsm/flow_control/uplink_downlink_splitter.h
index 0dbc0bc..874c0b6 100644
--- a/include/grgsm/flow_control/uplink_downlink_splitter.h
+++ b/include/grgsm/flow_control/uplink_downlink_splitter.h
@@ -28,7 +28,7 @@
 #include <gnuradio/block.h>
 
 namespace gr {
-  namespace grgsm {
+  namespace gsm {
 
     /*!
      * \brief <+description of block+>
@@ -51,7 +51,7 @@
       static sptr make();
     };
 
-  } // namespace grgsm
+  } // namespace gsm
 } // namespace gr
 
 #endif /* INCLUDED_GRGSM_UPLINK_DOWNLINK_SPLITTER_H */
diff --git a/include/grgsm/misc_utils/controlled_fractional_resampler_cc.h b/include/grgsm/misc_utils/controlled_fractional_resampler_cc.h
index b085f94..9dae6b8 100644
--- a/include/grgsm/misc_utils/controlled_fractional_resampler_cc.h
+++ b/include/grgsm/misc_utils/controlled_fractional_resampler_cc.h
@@ -57,7 +57,7 @@
       virtual void set_resamp_ratio(float resamp_ratio) = 0;
     };
 
-  } // namespace grgsm
+  } // namespace gsm
 } // namespace gr
 
 #endif /* INCLUDED_GRGSM_CONTROLLED_FRACTIONAL_RESAMPLER_CC_H */
diff --git a/include/grgsm/misc_utils/msg_to_tag.h b/include/grgsm/misc_utils/msg_to_tag.h
index 87e2e78..c7b4e10 100644
--- a/include/grgsm/misc_utils/msg_to_tag.h
+++ b/include/grgsm/misc_utils/msg_to_tag.h
@@ -50,7 +50,7 @@
       static sptr make();
     };
 
-  } // namespace grgsm
+  } // namespace gsm
 } // namespace gr
 
 #endif /* INCLUDED_GRGSM_MSG_TO_TAG_H */
diff --git a/include/grgsm/transmitter/CMakeLists.txt b/include/grgsm/transmitter/CMakeLists.txt
new file mode 100644
index 0000000..78aad43
--- /dev/null
+++ b/include/grgsm/transmitter/CMakeLists.txt
@@ -0,0 +1,25 @@
+# Copyright 2011,2012 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio 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.
+#
+# GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+
+########################################################################
+# Install public header files
+########################################################################
+install(FILES
+    txtime_setter.h DESTINATION include/grgsm/transmitter
+)
diff --git a/include/grgsm/transmitter/txtime_setter.h b/include/grgsm/transmitter/txtime_setter.h
new file mode 100644
index 0000000..0bf0b03
--- /dev/null
+++ b/include/grgsm/transmitter/txtime_setter.h
@@ -0,0 +1,62 @@
+/* -*- c++ -*- */
+/* @file
+ * @author Piotr Krysik <ptrkrysik@gmail.com>
+ * @section LICENSE
+ * 
+ * Gr-gsm 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.
+ * 
+ * Gr-gsm 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 gr-gsm; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ * 
+ */
+
+
+#ifndef INCLUDED_GSM_TXTIME_SETTER_H
+#define INCLUDED_GSM_TXTIME_SETTER_H
+
+#include <grgsm/api.h>
+#include <gnuradio/block.h>
+
+namespace gr {
+  namespace gsm {
+
+    /*!
+     * \brief <+description of block+>
+     * \ingroup gsm
+     *
+     */
+    class GRGSM_API txtime_setter : virtual public gr::block
+    {
+     public:
+      typedef boost::shared_ptr<txtime_setter> sptr;
+
+      /*!
+       * \brief Return a shared_ptr to a new instance of gsm::txtime_setter.
+       *
+       * To avoid accidental use of raw pointers, gsm::txtime_setter's
+       * constructor is in a private implementation
+       * class. gsm::txtime_setter::make is the public interface for
+       * creating new instances.
+       */
+      static sptr make(uint32_t init_fn, uint64_t init_time_secs, double init_time_fracs, uint64_t time_hint_secs, double time_hint_fracs, double timing_advance, double delay_correction);
+      virtual void set_fn_time_reference(uint32_t fn, uint32_t ts, uint64_t time_secs, double time_fracs) = 0;
+      virtual void set_time_hint(uint64_t time_hint_secs, double time_hint_fracs) = 0;
+      virtual void set_delay_correction(double delay_correction) = 0;
+      virtual void set_timing_advance(double timing_advance) = 0;
+    };
+
+  } // namespace gsm
+} // namespace gr
+
+#endif /* INCLUDED_GSM_TXTIME_SETTER_H */
+
diff --git a/include/grgsm/trx_interface/trx.h b/include/grgsm/trx_interface/trx.h
index 997ef62..c55bf36 100644
--- a/include/grgsm/trx_interface/trx.h
+++ b/include/grgsm/trx_interface/trx.h
@@ -27,7 +27,7 @@
 #include <gnuradio/sync_block.h>
 
 namespace gr {
-  namespace grgsm {
+  namespace gsm {
 
     /*!
      * \brief <+description of block+>
@@ -56,7 +56,7 @@
       virtual int ts_filter_get_tn(void) = 0;
     };
 
-  } // namespace grgsm
+  } // namespace gsm
 } // namespace gr
 
 #endif /* INCLUDED_GRGSM_TRX_H */
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 511d459..60758a1 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -70,6 +70,7 @@
 add_subdirectory(misc_utils)
 add_subdirectory(qa_utils)
 add_subdirectory(receiver)
+add_subdirectory(transmitter)
 add_subdirectory(trx_interface)
 
 ########################################################################
diff --git a/lib/flow_control/uplink_downlink_splitter_impl.cc b/lib/flow_control/uplink_downlink_splitter_impl.cc
index 691feb3..de5ae30 100644
--- a/lib/flow_control/uplink_downlink_splitter_impl.cc
+++ b/lib/flow_control/uplink_downlink_splitter_impl.cc
@@ -30,7 +30,7 @@
 #include <grgsm/endian.h>
 #define BURST_SIZE 148
 namespace gr {
-  namespace grgsm {
+  namespace gsm {
 
     uplink_downlink_splitter::sptr
     uplink_downlink_splitter::make()
@@ -71,6 +71,6 @@
     uplink_downlink_splitter_impl::~uplink_downlink_splitter_impl()
     {
     }
-  } /* namespace grgsm */
+  } /* namespace gsm */
 } /* namespace gr */
 
diff --git a/lib/flow_control/uplink_downlink_splitter_impl.h b/lib/flow_control/uplink_downlink_splitter_impl.h
index fb8b2b8..5edfe5a 100644
--- a/lib/flow_control/uplink_downlink_splitter_impl.h
+++ b/lib/flow_control/uplink_downlink_splitter_impl.h
@@ -26,7 +26,7 @@
 #include <grgsm/flow_control/uplink_downlink_splitter.h>
 
 namespace gr {
-  namespace grgsm {
+  namespace gsm {
 
     class uplink_downlink_splitter_impl : public uplink_downlink_splitter
     {
@@ -36,7 +36,7 @@
 
       void process_msg(pmt::pmt_t msg);
     };
-  } // namespace grgsm
+  } // namespace gsm
 } // namespace gr
 
 #endif /* INCLUDED_GRGSM_UPLINK_DOWNLINK_SPLITTER_IMPL_H */
diff --git a/lib/misc_utils/controlled_fractional_resampler_cc_impl.cc b/lib/misc_utils/controlled_fractional_resampler_cc_impl.cc
index 3376c67..36cf170 100644
--- a/lib/misc_utils/controlled_fractional_resampler_cc_impl.cc
+++ b/lib/misc_utils/controlled_fractional_resampler_cc_impl.cc
@@ -177,6 +177,6 @@
       set_relative_rate(1.0 / resamp_ratio);
     }
 
-  } /* namespace grgsm */
+  } /* namespace gsm */
 } /* namespace gr */
 
diff --git a/lib/misc_utils/controlled_fractional_resampler_cc_impl.h b/lib/misc_utils/controlled_fractional_resampler_cc_impl.h
index 24e00ed..1ca8082 100644
--- a/lib/misc_utils/controlled_fractional_resampler_cc_impl.h
+++ b/lib/misc_utils/controlled_fractional_resampler_cc_impl.h
@@ -64,7 +64,7 @@
       void set_resamp_ratio(float resamp_ratio);
     };
 
-  } // namespace grgsm
+  } // namespace gsm
 } // namespace gr
 
 #endif /* INCLUDED_GRGSM_CONTROLLED_FRACTIONAL_RESAMPLER_CC_IMPL_H */
diff --git a/lib/misc_utils/msg_to_tag_impl.cc b/lib/misc_utils/msg_to_tag_impl.cc
index 0ab65e7..e08c7e6 100644
--- a/lib/misc_utils/msg_to_tag_impl.cc
+++ b/lib/misc_utils/msg_to_tag_impl.cc
@@ -94,6 +94,6 @@
       return noutput_items;
     }
 
-  } /* namespace grgsm */
+  } /* namespace gsm */
 } /* namespace gr */
 
diff --git a/lib/misc_utils/msg_to_tag_impl.h b/lib/misc_utils/msg_to_tag_impl.h
index 39c6ca3..55e1fae 100644
--- a/lib/misc_utils/msg_to_tag_impl.h
+++ b/lib/misc_utils/msg_to_tag_impl.h
@@ -44,7 +44,7 @@
          gr_vector_void_star &output_items);
     };
 
-  } // namespace grgsm
+  } // namespace gsm
 } // namespace gr
 
 #endif /* INCLUDED_GRGSM_MSG_TO_TAG_IMPL_H */
diff --git a/lib/transmitter/CMakeLists.txt b/lib/transmitter/CMakeLists.txt
new file mode 100644
index 0000000..31658fd
--- /dev/null
+++ b/lib/transmitter/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Copyright 2011,2012 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio 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.
+#
+# GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+
+add_sources(
+   txtime_setter_impl.cc
+)
diff --git a/lib/transmitter/txtime_setter_impl.cc b/lib/transmitter/txtime_setter_impl.cc
new file mode 100644
index 0000000..9ff1d8a
--- /dev/null
+++ b/lib/transmitter/txtime_setter_impl.cc
@@ -0,0 +1,139 @@
+/* -*- c++ -*- */
+/* @file
+ * @author Piotr Krysik <ptrkrysik@gmail.com>
+ * @section LICENSE
+ * 
+ * Gr-gsm 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.
+ * 
+ * Gr-gsm 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 gr-gsm; 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 <grgsm/gsmtap.h>
+#include "txtime_setter_impl.h"
+
+namespace gr {
+  namespace gsm {
+
+    txtime_setter::sptr
+    txtime_setter::make(uint32_t init_fn, uint64_t init_time_secs, double init_time_fracs, uint64_t time_hint_secs, double time_hint_fracs, double timing_advance, double delay_correction)
+    {
+      return gnuradio::get_initial_sptr
+        (new txtime_setter_impl(init_fn, init_time_secs, init_time_fracs, time_hint_secs, time_hint_fracs, timing_advance, delay_correction));
+    }
+
+    /*
+     * The private constructor
+     */
+    txtime_setter_impl::txtime_setter_impl(uint32_t init_fn, uint64_t init_time_secs, double init_time_fracs, uint64_t time_hint_secs, double time_hint_fracs, double timing_advance, double delay_correction)
+      : gr::block("txtime_setter",
+              gr::io_signature::make(0, 0, 0),
+              gr::io_signature::make(0, 0, 0)),
+        d_fn_ref(init_fn),
+        d_ts_ref(0),
+        d_time_ref(init_time_secs,init_time_fracs),
+        d_time_hint(time_hint_secs,time_hint_fracs),
+        d_timing_advance(timing_advance),
+        d_delay_correction(delay_correction)
+    {
+        message_port_register_in(pmt::intern("fn_time"));
+        message_port_register_in(pmt::intern("bursts_in"));
+        message_port_register_out(pmt::intern("bursts_out"));
+
+        set_msg_handler(pmt::intern("fn_time"), boost::bind(&txtime_setter_impl::process_fn_time_reference, this, _1));
+        set_msg_handler(pmt::intern("bursts_in"),  boost::bind(&txtime_setter_impl::process_txtime_of_burst,   this, _1));
+    }
+
+    /*
+     * Our virtual destructor.
+     */
+    txtime_setter_impl::~txtime_setter_impl()
+    {
+    }
+    
+    void txtime_setter_impl::process_fn_time_reference(pmt::pmt_t msg)
+    {
+//      d_time_hint = pmt::to_python(pmt::dict_ref(msg, pmt::intern("time_hint"), pmt::PMT_NIL))
+        pmt::pmt_t not_found = pmt::intern("not_found");
+        pmt::pmt_t fn_time = pmt::dict_ref(msg, pmt::intern("fn_time"), not_found);
+        pmt::pmt_t time_hint = pmt::dict_ref(msg, pmt::intern("fn_time"), not_found);
+
+        if(fn_time != not_found)
+        {
+          uint32_t fn_ref = static_cast<uint32_t>(pmt::to_uint64(pmt::car(pmt::car(fn_time))));
+          uint32_t ts =  static_cast<uint32_t>(pmt::to_uint64(pmt::cdr(pmt::car(fn_time))));
+          uint64_t time_secs = pmt::to_uint64(pmt::car(pmt::cdr(fn_time)));
+          double time_fracs = pmt::to_double(pmt::cdr(pmt::cdr(fn_time)));
+          set_fn_time_reference(fn_ref, ts,  time_secs, time_fracs);
+        } else if(time_hint != not_found) {
+          set_time_hint(pmt::to_uint64(pmt::car(fn_time)), pmt::to_double(pmt::cdr(fn_time)));
+        }
+
+    }
+    
+    void txtime_setter_impl::process_txtime_of_burst(pmt::pmt_t burst)
+    {
+        pmt::pmt_t header_plus_burst = pmt::cdr(burst);
+        int8_t * burst_int8 = (int8_t *)pmt::blob_data(header_plus_burst);        
+        gsmtap_hdr * header = (gsmtap_hdr *)(burst_int8);
+        
+        uint32_t frame_nr = be32toh(header->frame_number); 
+        uint32_t ts_num = header->timeslot;
+        
+        if(d_fn_ref != 0xffffffff)
+        {
+          time_format txtime = fn_time_delta_cpp(d_fn_ref, d_time_ref, frame_nr, d_time_hint, ts_num, d_ts_ref);
+          time_spec_t txtime_spec = time_spec_t(txtime.first, txtime.second);
+          txtime_spec = txtime_spec - d_delay_correction;
+          txtime_spec = txtime_spec - d_timing_advance;
+          
+          pmt::pmt_t tags_dict = pmt::dict_add(pmt::make_dict(), pmt::intern("tx_time"), pmt::make_tuple(pmt::from_uint64(txtime_spec.get_full_secs()),pmt::from_double(txtime_spec.get_frac_secs())));
+          tags_dict = pmt::dict_add(tags_dict, pmt::intern("fn"), pmt::from_uint64(frame_nr));
+          tags_dict = pmt::dict_add(tags_dict, pmt::intern("ts"), pmt::from_uint64(ts_num));
+          pmt::pmt_t new_msg = pmt::cons(tags_dict, pmt::cdr(burst));
+          message_port_pub(pmt::intern("bursts_out"), new_msg);
+        }
+    }
+
+    void txtime_setter_impl::set_fn_time_reference(uint32_t fn, uint32_t ts, uint64_t time_secs, double time_fracs)
+    {
+      d_fn_ref = fn;
+      d_ts_ref = ts;
+      d_time_ref = std::make_pair(time_secs, time_fracs);
+      set_time_hint(time_secs, time_fracs);
+    }
+
+    void txtime_setter_impl::set_time_hint(uint64_t time_hint_secs, double time_hint_fracs)
+    {
+      d_time_hint = std::make_pair(time_hint_secs, time_hint_fracs);
+    }
+
+    void txtime_setter_impl::set_delay_correction(double delay_correction)
+    {
+      d_delay_correction = delay_correction;
+    }
+
+    void txtime_setter_impl::set_timing_advance(double timing_advance)
+    {
+      d_timing_advance = timing_advance;
+    }
+
+  } /* namespace gsm */
+} /* namespace gr */
+
diff --git a/lib/transmitter/txtime_setter_impl.h b/lib/transmitter/txtime_setter_impl.h
new file mode 100644
index 0000000..e3f195a
--- /dev/null
+++ b/lib/transmitter/txtime_setter_impl.h
@@ -0,0 +1,60 @@
+/* -*- c++ -*- */
+/* @file
+ * @author Piotr Krysik <ptrkrysik@gmail.com>
+ * @section LICENSE
+ * 
+ * Gr-gsm 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.
+ * 
+ * Gr-gsm 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 gr-gsm; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ * 
+ */
+
+#ifndef INCLUDED_GSM_TXTIME_SETTER_IMPL_H
+#define INCLUDED_GSM_TXTIME_SETTER_IMPL_H
+
+#include <grgsm/transmitter/txtime_setter.h>
+#include <grgsm/misc_utils/time_spec.h>
+#include <grgsm/misc_utils/fn_time.h>
+
+namespace gr {
+  namespace gsm {
+
+    class txtime_setter_impl : public txtime_setter
+    {
+     private:
+      uint32_t d_fn_ref;
+      uint32_t d_ts_ref;
+      time_format d_time_ref;
+      time_format d_time_hint;
+      double d_timing_advance;
+      double d_delay_correction;
+      
+     public:
+      txtime_setter_impl(uint32_t init_fn, uint64_t init_time_secs, double init_time_fracs, uint64_t time_hint_secs, double time_hint_fracs, double timing_advance, double delay_correction);
+      ~txtime_setter_impl();
+
+      // Where all the action really happens
+      void process_fn_time_reference(pmt::pmt_t msg);
+      void process_txtime_of_burst(pmt::pmt_t msg);
+      void set_fn_time_reference(uint32_t fn, uint32_t ts, uint64_t time_secs, double time_fracs);
+      void set_time_hint(uint64_t time_hint_secs, double time_hint_fracs);
+      void set_delay_correction(double delay_correction);
+      void set_timing_advance(double timing_advance);
+    };
+
+  } // namespace gsm
+} // namespace gr
+
+#endif /* INCLUDED_GSM_TXTIME_SETTER_IMPL_H */
+
diff --git a/lib/trx_interface/trx_impl.cc b/lib/trx_interface/trx_impl.cc
index 2068da3..8c348ac 100644
--- a/lib/trx_interface/trx_impl.cc
+++ b/lib/trx_interface/trx_impl.cc
@@ -44,7 +44,7 @@
 };
 
 namespace gr {
-  namespace grgsm {
+  namespace gsm {
 
     trx::sptr
     trx::make(
@@ -269,5 +269,5 @@
       message_port_pub(pmt::mp("bursts"), msg);
     }
 
-  } /* namespace grgsm */
+  } /* namespace gsm */
 } /* namespace gr */
diff --git a/lib/trx_interface/trx_impl.h b/lib/trx_interface/trx_impl.h
index d335922..6fecf17 100644
--- a/lib/trx_interface/trx_impl.h
+++ b/lib/trx_interface/trx_impl.h
@@ -29,7 +29,7 @@
 #include <grgsm/trx_interface/trx.h>
 
 namespace gr {
-  namespace grgsm {
+  namespace gsm {
 
     class trx_impl : public trx
     {
@@ -54,7 +54,7 @@
       void handle_ul_burst(uint8_t *payload, size_t len);
     };
 
-  } // namespace grgsm
+  } // namespace gsm
 } // namespace gr
 
 #endif /* INCLUDED_GRGSM_TRX_IMPL_H */
diff --git a/lib/trx_interface/udp_socket.cc b/lib/trx_interface/udp_socket.cc
index be4bb66..5c689c7 100644
--- a/lib/trx_interface/udp_socket.cc
+++ b/lib/trx_interface/udp_socket.cc
@@ -35,7 +35,7 @@
 using boost::asio::ip::udp;
 
 namespace gr {
-  namespace grgsm {
+  namespace gsm {
 
     udp_socket::udp_socket(
       const std::string &remote_addr,
@@ -115,5 +115,5 @@
           boost::asio::placeholders::bytes_transferred));
     }
 
-  } /* namespace blocks */
+  } /* namespace gsm */
 }/* namespace gr */
diff --git a/lib/trx_interface/udp_socket.h b/lib/trx_interface/udp_socket.h
index 5bcc42b..15b2c66 100644
--- a/lib/trx_interface/udp_socket.h
+++ b/lib/trx_interface/udp_socket.h
@@ -32,7 +32,7 @@
 #include <pmt/pmt.h>
 
 namespace gr {
-  namespace grgsm {
+  namespace gsm {
 
     class udp_socket
     {
@@ -63,7 +63,7 @@
       boost::function<void (uint8_t *, size_t)> udp_rx_handler;
     };
 
-  } /* namespace blocks */
+  } /* namespace gsm */
 } /* namespace gr */
 
 #endif /* INCLUDED_GRGSM_TRX_UDP_SOCKET_H */
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 0997931..72f657a 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -59,3 +59,4 @@
 #GR_ADD_TEST(qa_msg_to_tag ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_msg_to_tag.py)
 #GR_ADD_TEST(qa_controlled_fractional_resampler_cc ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_controlled_fractional_resampler_cc.py)
 #GR_ADD_TEST(qa_uplink_downlink_splitter ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_uplink_downlink_splitter.py)
+GR_ADD_TEST(qa_txtime_setter ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_txtime_setter.py)
diff --git a/python/qa_txtime_setter.py b/python/qa_txtime_setter.py
new file mode 100755
index 0000000..d5509a9
--- /dev/null
+++ b/python/qa_txtime_setter.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# @file
+# @author Piotr Krysik <ptrkrysik@gmail.com>
+# @section LICENSE
+# 
+# Gr-gsm 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.
+# 
+# Gr-gsm 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 gr-gsm; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
+# 
+
+from gnuradio import gr, gr_unittest
+from gnuradio import blocks
+import grgsm_swig as grgsm
+
+class qa_txtime_setter (gr_unittest.TestCase):
+
+    def setUp (self):
+        self.tb = gr.top_block ()
+
+    def tearDown (self):
+        self.tb = None
+
+    def test_001_t (self):
+        # set up fg
+        self.tb.run ()
+        # check data
+
+
+if __name__ == '__main__':
+    gr_unittest.run(qa_txtime_setter, "qa_txtime_setter.xml")
diff --git a/swig/grgsm_swig.i b/swig/grgsm_swig.i
index 2743e80..64c1024 100644
--- a/swig/grgsm_swig.i
+++ b/swig/grgsm_swig.i
@@ -70,6 +70,7 @@
 #include "grgsm/trx_interface/trx.h"
 //#include "grgsm/misc_utils/time_spec.h"
 #include "grgsm/misc_utils/fn_time.h"
+#include "grgsm/transmitter/txtime_setter.h"
 %}
 
 %include "constants.i"
@@ -108,7 +109,7 @@
 %include "grgsm/flow_control/dummy_burst_filter.h"
 GR_SWIG_BLOCK_MAGIC2(gsm, dummy_burst_filter);
 %include "grgsm/flow_control/uplink_downlink_splitter.h"
-GR_SWIG_BLOCK_MAGIC2(grgsm, uplink_downlink_splitter);
+GR_SWIG_BLOCK_MAGIC2(gsm, uplink_downlink_splitter);
 
 
 %include "grgsm/misc_utils/bursts_printer.h"
@@ -150,7 +151,7 @@
 %include "grgsm/qa_utils/message_sink.h"
 GR_SWIG_BLOCK_MAGIC2(gsm, message_sink);
 %include "grgsm/trx_interface/trx.h"
-GR_SWIG_BLOCK_MAGIC2(grgsm, trx);
+GR_SWIG_BLOCK_MAGIC2(gsm, trx);
 
 //#pragma SWIG nowarn=319
 //%include "grgsm/misc_utils/time_spec.h"
@@ -175,3 +176,6 @@
 //};
 
 %include "grgsm/misc_utils/fn_time.h"
+
+%include "grgsm/transmitter/txtime_setter.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, txtime_setter);
diff --git a/swig/grgsm_swig.i.orig b/swig/grgsm_swig.i.orig
deleted file mode 100644
index 888f07a..0000000
--- a/swig/grgsm_swig.i.orig
+++ /dev/null
@@ -1,151 +0,0 @@
-/* -*- c++ -*- */
-/*
- * @file
- * @author (C) 2014 by Piotr Krysik <ptrkrysik@gmail.com>
- * @section LICENSE
- *
- * Gr-gsm 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.
- *
- * Gr-gsm 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 gr-gsm; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-
-#define GRGSM_API
-
-%include "gnuradio.i"			// the common stuff
-
-//load generated python docstrings
-%include "grgsm_swig_doc.i"
-
-%{
-#include "grgsm/constants.h"
-#include "grgsm/receiver/receiver.h"
-#include "grgsm/receiver/clock_offset_control.h"
-#include "grgsm/receiver/cx_channel_hopper.h"
-#include "grgsm/decoding/control_channels_decoder.h"
-#include "grgsm/decoding/tch_f_decoder.h"
-#include "grgsm/decryption/decryption.h"
-#include "grgsm/demapping/universal_ctrl_chans_demapper.h"
-#include "grgsm/demapping/tch_f_chans_demapper.h"
-#include "grgsm/flow_control/common.h"
-#include "grgsm/flow_control/burst_timeslot_splitter.h"
-#include "grgsm/flow_control/burst_sdcch_subslot_splitter.h"
-#include "grgsm/flow_control/burst_timeslot_filter.h"
-#include "grgsm/flow_control/burst_sdcch_subslot_filter.h"
-#include "grgsm/flow_control/burst_fnr_filter.h"
-#include "grgsm/flow_control/dummy_burst_filter.h"
-#include "grgsm/flow_control/uplink_downlink_splitter.h"
-#include "grgsm/misc_utils/bursts_printer.h"
-#include "grgsm/misc_utils/controlled_rotator_cc.h"
-#include "grgsm/misc_utils/extract_system_info.h"
-#include "grgsm/misc_utils/extract_immediate_assignment.h"
-#include "grgsm/misc_utils/message_printer.h"
-#include "grgsm/misc_utils/tmsi_dumper.h"
-#include "grgsm/misc_utils/burst_file_sink.h"
-#include "grgsm/misc_utils/burst_file_source.h"
-#include "grgsm/misc_utils/collect_system_info.h"
-#include "grgsm/misc_utils/extract_cmc.h"
-#include "grgsm/qa_utils/burst_sink.h"
-#include "grgsm/qa_utils/burst_source.h"
-#include "grgsm/qa_utils/message_source.h"
-#include "grgsm/qa_utils/message_sink.h"
-#include "grgsm/misc_utils/message_file_sink.h"
-#include "grgsm/misc_utils/message_file_source.h"
-#include "grgsm/misc_utils/msg_to_tag.h"
-#include "grgsm/misc_utils/controlled_fractional_resampler_cc.h"
-#include "grgsm/trx_interface/trx.h"
-%}
-
-%include "constants.i"
-
-%include "grgsm/receiver/receiver.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, receiver);
-%include "grgsm/receiver/clock_offset_control.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, clock_offset_control);
-%include "grgsm/receiver/cx_channel_hopper.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, cx_channel_hopper);
-
-%include "grgsm/decoding/control_channels_decoder.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, control_channels_decoder);
-%include "grgsm/decoding/tch_f_decoder.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, tch_f_decoder);
-
-%include "grgsm/decryption/decryption.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, decryption);
-
-%include "grgsm/demapping/universal_ctrl_chans_demapper.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, universal_ctrl_chans_demapper);
-%include "grgsm/demapping/tch_f_chans_demapper.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, tch_f_chans_demapper);
-
-%include "grgsm/flow_control/common.h"
-%include "grgsm/flow_control/burst_timeslot_splitter.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, burst_timeslot_splitter);
-%include "grgsm/flow_control/burst_sdcch_subslot_splitter.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, burst_sdcch_subslot_splitter);
-%include "grgsm/flow_control/burst_timeslot_filter.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, burst_timeslot_filter);
-%include "grgsm/flow_control/burst_sdcch_subslot_filter.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, burst_sdcch_subslot_filter);
-%include "grgsm/flow_control/burst_fnr_filter.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, burst_fnr_filter);
-%include "grgsm/flow_control/dummy_burst_filter.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, dummy_burst_filter);
-%include "grgsm/flow_control/uplink_downlink_splitter.h"
-GR_SWIG_BLOCK_MAGIC2(grgsm, uplink_downlink_splitter);
-
-
-%include "grgsm/misc_utils/bursts_printer.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, bursts_printer);
-%include "grgsm/misc_utils/burst_file_sink.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, burst_file_sink);
-%include "grgsm/misc_utils/burst_file_source.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, burst_file_source);
-%include "grgsm/misc_utils/collect_system_info.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, collect_system_info);
-%include "grgsm/misc_utils/extract_system_info.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, extract_system_info);
-%include "grgsm/misc_utils/extract_immediate_assignment.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, extract_immediate_assignment);
-%include "grgsm/misc_utils/controlled_rotator_cc.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, controlled_rotator_cc);
-%include "grgsm/misc_utils/message_printer.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, message_printer);
-%include "grgsm/misc_utils/tmsi_dumper.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, tmsi_dumper);
-%include "grgsm/misc_utils/message_file_sink.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, message_file_sink);
-%include "grgsm/misc_utils/message_file_source.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, message_file_source);
-%include "grgsm/misc_utils/msg_to_tag.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, msg_to_tag);
-%include "grgsm/misc_utils/controlled_fractional_resampler_cc.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, controlled_fractional_resampler_cc);
-%include "grgsm/misc_utils/extract_cmc.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, extract_cmc);
-
-
-%include "grgsm/qa_utils/burst_sink.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, burst_sink);
-%include "grgsm/qa_utils/burst_source.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, burst_source);
-%include "grgsm/qa_utils/message_source.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, message_source);
-%include "grgsm/qa_utils/message_sink.h"
-GR_SWIG_BLOCK_MAGIC2(gsm, message_sink);
-<<<<<<< HEAD
-%include "grgsm/trx_interface/trx.h"
-GR_SWIG_BLOCK_MAGIC2(grgsm, trx);
-=======
->>>>>>> development