Added carrier frequency offset correction to radio_if
diff --git a/python/trx/radio_if_grc.py b/python/trx/radio_if_grc.py
index 3cfa931..920b0c5 100755
--- a/python/trx/radio_if_grc.py
+++ b/python/trx/radio_if_grc.py
@@ -5,9 +5,10 @@
 # Title: Trx radio interface
 # Author: (C) Piotr Krysik 2017
 # Description: Alpha version of trx radio interface
-# Generated: Thu Nov 30 13:41:21 2017
+# Generated: Fri Dec  1 10:49:25 2017
 ##################################################
 
+from change_sign_of_dict_elements import change_sign_of_dict_elements
 from gnuradio import blocks
 from gnuradio import digital
 from gnuradio import eng_notation
@@ -25,24 +26,24 @@
 
 class radio_if_grc(gr.top_block):
 
-    def __init__(self, samp_rate=13e6/12.0, tx_gain=30, tx_freq=938900000, rx_freq=938600000, rx_gain=40, osr=4, ppm=-1, trx_base_port="5700", trx_remote_addr="127.0.0.1", delay_correction=285.616e-6, uplink_shift=-(6.0/1625000*(156.25)*3), timing_advance=0):
+    def __init__(self, delay_correction=285.616e-6, osr=4, ppm=-0.799427, rx_freq=935e6+36*0.2e6, rx_gain=40, samp_rate=13e6/12.0, timing_advance=0, trx_base_port="5710", trx_remote_addr="127.0.0.1", tx_freq=935e6+36*0.2e6-45e6, tx_gain=40, uplink_shift=-(6.0/1625000*(156.25)*3)):
         gr.top_block.__init__(self, "Trx radio interface")
 
         ##################################################
         # Parameters
         ##################################################
-        self.samp_rate = samp_rate
-        self.tx_gain = tx_gain
-        self.tx_freq = tx_freq
-        self.rx_freq = rx_freq
-        self.rx_gain = rx_gain
+        self.delay_correction = delay_correction
         self.osr = osr
         self.ppm = ppm
+        self.rx_freq = rx_freq
+        self.rx_gain = rx_gain
+        self.samp_rate = samp_rate
+        self.timing_advance = timing_advance
         self.trx_base_port = trx_base_port
         self.trx_remote_addr = trx_remote_addr
-        self.delay_correction = delay_correction
+        self.tx_freq = tx_freq
+        self.tx_gain = tx_gain
         self.uplink_shift = uplink_shift
-        self.timing_advance = timing_advance
 
         ##################################################
         # Blocks
@@ -89,18 +90,24 @@
         )
         self.gsm_controlled_rotator_cc_0_0 = grgsm.controlled_rotator_cc(-ppm/1.0e6*2*math.pi*tx_freq/samp_rate)
         self.gsm_controlled_rotator_cc_0 = grgsm.controlled_rotator_cc(ppm/1.0e6*2*math.pi*rx_freq/samp_rate)
+        self.gsm_clock_offset_control_0 = grgsm.clock_offset_control(rx_freq, samp_rate, osr)
         self.gsm_burst_type_filter_0 = grgsm.burst_type_filter(([3]))
         self.gsm_burst_to_fn_time_0 = grgsm.burst_to_fn_time()
         self.digital_burst_shaper_xx_0 = digital.burst_shaper_cc((firdes.window(firdes.WIN_HANN, 16, 0)), 0, 20, False, "packet_len")
+        self.change_sign_of_dict_elements = change_sign_of_dict_elements()
         self.blocks_pdu_to_tagged_stream_0_0 = blocks.pdu_to_tagged_stream(blocks.byte_t, "packet_len")
 
         ##################################################
         # Connections
         ##################################################
+        self.msg_connect((self.change_sign_of_dict_elements, 'dict_out'), (self.gsm_msg_to_tag_0_0, 'msg'))    
         self.msg_connect((self.gsm_burst_to_fn_time_0, 'fn_time_out'), (self.gsm_txtime_setter_0, 'fn_time'))    
         self.msg_connect((self.gsm_burst_type_filter_0, 'bursts_out'), (self.gsm_burst_to_fn_time_0, 'bursts_in'))    
+        self.msg_connect((self.gsm_clock_offset_control_0, 'ctrl'), (self.change_sign_of_dict_elements, 'dict_in'))    
+        self.msg_connect((self.gsm_clock_offset_control_0, 'ctrl'), (self.gsm_msg_to_tag_0, 'msg'))    
         self.msg_connect((self.gsm_preprocess_tx_burst_0, 'bursts_out'), (self.blocks_pdu_to_tagged_stream_0_0, 'pdus'))    
         self.msg_connect((self.gsm_receiver_0, 'C0'), (self.gsm_burst_type_filter_0, 'bursts_in'))    
+        self.msg_connect((self.gsm_receiver_0, 'measurements'), (self.gsm_clock_offset_control_0, 'measurements'))    
         self.msg_connect((self.gsm_receiver_0, 'C0'), (self.ts_filter, 'in'))    
         self.msg_connect((self.gsm_trx_burst_if_0, 'bursts'), (self.gsm_txtime_setter_0, 'bursts_in'))    
         self.msg_connect((self.gsm_txtime_setter_0, 'bursts_out'), (self.gsm_preprocess_tx_burst_0, 'bursts_in'))    
@@ -115,32 +122,27 @@
         self.connect((self.low_pass_filter_0_0, 0), (self.gsm_receiver_0, 0))    
         self.connect((self.uhd_usrp_source_0, 0), (self.gsm_msg_to_tag_0, 0))    
 
-    def get_samp_rate(self):
-        return self.samp_rate
+    def get_delay_correction(self):
+        return self.delay_correction
 
-    def set_samp_rate(self, samp_rate):
-        self.samp_rate = samp_rate
-        self.low_pass_filter_0_0.set_taps(firdes.low_pass(1, self.samp_rate, 125e3, 5e3, firdes.WIN_HAMMING, 6.76))
+    def set_delay_correction(self, delay_correction):
+        self.delay_correction = delay_correction
+        self.gsm_txtime_setter_0.set_delay_correction(self.delay_correction+self.uplink_shift)
+
+    def get_osr(self):
+        return self.osr
+
+    def set_osr(self, osr):
+        self.osr = osr
+        self.gsm_gmsk_mod_0.set_sps(self.osr)
+
+    def get_ppm(self):
+        return self.ppm
+
+    def set_ppm(self, ppm):
+        self.ppm = ppm
         self.gsm_controlled_rotator_cc_0.set_phase_inc(self.ppm/1.0e6*2*math.pi*self.rx_freq/self.samp_rate)
         self.gsm_controlled_rotator_cc_0_0.set_phase_inc(-self.ppm/1.0e6*2*math.pi*self.tx_freq/self.samp_rate)
-        self.uhd_usrp_sink_0.set_samp_rate(self.samp_rate)
-        self.uhd_usrp_source_0.set_samp_rate(self.samp_rate)
-
-    def get_tx_gain(self):
-        return self.tx_gain
-
-    def set_tx_gain(self, tx_gain):
-        self.tx_gain = tx_gain
-        self.uhd_usrp_sink_0.set_gain(self.tx_gain, 0)
-        	
-
-    def get_tx_freq(self):
-        return self.tx_freq
-
-    def set_tx_freq(self, tx_freq):
-        self.tx_freq = tx_freq
-        self.gsm_controlled_rotator_cc_0_0.set_phase_inc(-self.ppm/1.0e6*2*math.pi*self.tx_freq/self.samp_rate)
-        self.uhd_usrp_sink_0.set_center_freq(self.tx_freq, 0)
 
     def get_rx_freq(self):
         return self.rx_freq
@@ -158,20 +160,23 @@
         self.uhd_usrp_source_0.set_gain(self.rx_gain, 0)
         	
 
-    def get_osr(self):
-        return self.osr
+    def get_samp_rate(self):
+        return self.samp_rate
 
-    def set_osr(self, osr):
-        self.osr = osr
-        self.gsm_gmsk_mod_0.set_sps(self.osr)
-
-    def get_ppm(self):
-        return self.ppm
-
-    def set_ppm(self, ppm):
-        self.ppm = ppm
+    def set_samp_rate(self, samp_rate):
+        self.samp_rate = samp_rate
         self.gsm_controlled_rotator_cc_0.set_phase_inc(self.ppm/1.0e6*2*math.pi*self.rx_freq/self.samp_rate)
         self.gsm_controlled_rotator_cc_0_0.set_phase_inc(-self.ppm/1.0e6*2*math.pi*self.tx_freq/self.samp_rate)
+        self.low_pass_filter_0_0.set_taps(firdes.low_pass(1, self.samp_rate, 125e3, 5e3, firdes.WIN_HAMMING, 6.76))
+        self.uhd_usrp_sink_0.set_samp_rate(self.samp_rate)
+        self.uhd_usrp_source_0.set_samp_rate(self.samp_rate)
+
+    def get_timing_advance(self):
+        return self.timing_advance
+
+    def set_timing_advance(self, timing_advance):
+        self.timing_advance = timing_advance
+        self.gsm_txtime_setter_0.set_timing_advance(self.timing_advance)
 
     def get_trx_base_port(self):
         return self.trx_base_port
@@ -185,12 +190,21 @@
     def set_trx_remote_addr(self, trx_remote_addr):
         self.trx_remote_addr = trx_remote_addr
 
-    def get_delay_correction(self):
-        return self.delay_correction
+    def get_tx_freq(self):
+        return self.tx_freq
 
-    def set_delay_correction(self, delay_correction):
-        self.delay_correction = delay_correction
-        self.gsm_txtime_setter_0.set_delay_correction(self.delay_correction+self.uplink_shift)
+    def set_tx_freq(self, tx_freq):
+        self.tx_freq = tx_freq
+        self.gsm_controlled_rotator_cc_0_0.set_phase_inc(-self.ppm/1.0e6*2*math.pi*self.tx_freq/self.samp_rate)
+        self.uhd_usrp_sink_0.set_center_freq(self.tx_freq, 0)
+
+    def get_tx_gain(self):
+        return self.tx_gain
+
+    def set_tx_gain(self, tx_gain):
+        self.tx_gain = tx_gain
+        self.uhd_usrp_sink_0.set_gain(self.tx_gain, 0)
+        	
 
     def get_uplink_shift(self):
         return self.uplink_shift
@@ -199,52 +213,45 @@
         self.uplink_shift = uplink_shift
         self.gsm_txtime_setter_0.set_delay_correction(self.delay_correction+self.uplink_shift)
 
-    def get_timing_advance(self):
-        return self.timing_advance
-
-    def set_timing_advance(self, timing_advance):
-        self.timing_advance = timing_advance
-        self.gsm_txtime_setter_0.set_timing_advance(self.timing_advance)
-
 
 def argument_parser():
     parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
     parser.add_option(
-        "", "--samp-rate", dest="samp_rate", type="eng_float", default=eng_notation.num_to_str(13e6/12.0),
-        help="Set samp_rate [default=%default]")
+        "", "--delay-correction", dest="delay_correction", type="eng_float", default=eng_notation.num_to_str(285.616e-6),
+        help="Set delay_correction [default=%default]")
     parser.add_option(
-        "-r", "--tx-gain", dest="tx_gain", type="eng_float", default=eng_notation.num_to_str(30),
-        help="Set tx_gain [default=%default]")
+        "", "--osr", dest="osr", type="intx", default=4,
+        help="Set OSR [default=%default]")
     parser.add_option(
-        "-u", "--tx-freq", dest="tx_freq", type="eng_float", default=eng_notation.num_to_str(938900000),
-        help="Set tx_freq [default=%default]")
+        "", "--ppm", dest="ppm", type="eng_float", default=eng_notation.num_to_str(-0.799427),
+        help="Set Clock offset correction [default=%default]")
     parser.add_option(
-        "-d", "--rx-freq", dest="rx_freq", type="eng_float", default=eng_notation.num_to_str(938600000),
+        "-d", "--rx-freq", dest="rx_freq", type="eng_float", default=eng_notation.num_to_str(935e6+36*0.2e6),
         help="Set rx_freq [default=%default]")
     parser.add_option(
         "-g", "--rx-gain", dest="rx_gain", type="eng_float", default=eng_notation.num_to_str(40),
         help="Set rx_gain [default=%default]")
     parser.add_option(
-        "", "--osr", dest="osr", type="intx", default=4,
-        help="Set OSR [default=%default]")
+        "", "--samp-rate", dest="samp_rate", type="eng_float", default=eng_notation.num_to_str(13e6/12.0),
+        help="Set samp_rate [default=%default]")
     parser.add_option(
-        "", "--ppm", dest="ppm", type="eng_float", default=eng_notation.num_to_str(-1),
-        help="Set Clock offset correction [default=%default]")
+        "", "--timing-advance", dest="timing_advance", type="eng_float", default=eng_notation.num_to_str(0),
+        help="Set timing_advance [default=%default]")
     parser.add_option(
-        "", "--trx-base-port", dest="trx_base_port", type="string", default="5700",
-        help="Set 5700 [default=%default]")
+        "", "--trx-base-port", dest="trx_base_port", type="string", default="5710",
+        help="Set 5710 [default=%default]")
     parser.add_option(
         "", "--trx-remote-addr", dest="trx_remote_addr", type="string", default="127.0.0.1",
         help="Set 127.0.0.1 [default=%default]")
     parser.add_option(
-        "", "--delay-correction", dest="delay_correction", type="eng_float", default=eng_notation.num_to_str(285.616e-6),
-        help="Set delay_correction [default=%default]")
+        "-u", "--tx-freq", dest="tx_freq", type="eng_float", default=eng_notation.num_to_str(935e6+36*0.2e6-45e6),
+        help="Set tx_freq [default=%default]")
+    parser.add_option(
+        "-r", "--tx-gain", dest="tx_gain", type="eng_float", default=eng_notation.num_to_str(40),
+        help="Set tx_gain [default=%default]")
     parser.add_option(
         "", "--uplink-shift", dest="uplink_shift", type="eng_float", default=eng_notation.num_to_str(-(6.0/1625000*(156.25)*3)),
         help="Set uplink_shift [default=%default]")
-    parser.add_option(
-        "", "--timing-advance", dest="timing_advance", type="eng_float", default=eng_notation.num_to_str(0),
-        help="Set timing_advance [default=%default]")
     return parser
 
 
@@ -252,7 +259,7 @@
     if options is None:
         options, _ = argument_parser().parse_args()
 
-    tb = top_block_cls(samp_rate=options.samp_rate, tx_gain=options.tx_gain, tx_freq=options.tx_freq, rx_freq=options.rx_freq, rx_gain=options.rx_gain, osr=options.osr, ppm=options.ppm, trx_base_port=options.trx_base_port, trx_remote_addr=options.trx_remote_addr, delay_correction=options.delay_correction, uplink_shift=options.uplink_shift, timing_advance=options.timing_advance)
+    tb = top_block_cls(delay_correction=options.delay_correction, osr=options.osr, ppm=options.ppm, rx_freq=options.rx_freq, rx_gain=options.rx_gain, samp_rate=options.samp_rate, timing_advance=options.timing_advance, trx_base_port=options.trx_base_port, trx_remote_addr=options.trx_remote_addr, tx_freq=options.tx_freq, tx_gain=options.tx_gain, uplink_shift=options.uplink_shift)
     tb.start()
     tb.wait()