Returning to clean state after 0.5s if not synchronized
This commit is contained in:
parent
8e4d72721e
commit
8cfe4c43ea
|
@ -22,6 +22,7 @@
|
||||||
from numpy import *
|
from numpy import *
|
||||||
from gnuradio import gr
|
from gnuradio import gr
|
||||||
import pmt
|
import pmt
|
||||||
|
from threading import Timer
|
||||||
|
|
||||||
class clock_offset_control(gr.basic_block):
|
class clock_offset_control(gr.basic_block):
|
||||||
"""
|
"""
|
||||||
|
@ -41,6 +42,8 @@ class clock_offset_control(gr.basic_block):
|
||||||
self.ppm_estimate = -1e6
|
self.ppm_estimate = -1e6
|
||||||
self.first_measurement = True
|
self.first_measurement = True
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
|
self.last_state = ""
|
||||||
|
self.timer = Timer(0.5, self.conditional_reset)
|
||||||
|
|
||||||
def process_measurement(self,msg):
|
def process_measurement(self,msg):
|
||||||
if pmt.is_tuple(msg):
|
if pmt.is_tuple(msg):
|
||||||
|
@ -50,15 +53,19 @@ class clock_offset_control(gr.basic_block):
|
||||||
ppm = -freq_offset/self.fc*1.0e6
|
ppm = -freq_offset/self.fc*1.0e6
|
||||||
state = pmt.symbol_to_string(pmt.tuple_ref(msg,2))
|
state = pmt.symbol_to_string(pmt.tuple_ref(msg,2))
|
||||||
|
|
||||||
if abs(ppm) > 50:
|
self.last_state = state
|
||||||
|
|
||||||
|
if abs(ppm) > 100: #safeguard against flawed measurements
|
||||||
ppm = 0
|
ppm = 0
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
if state == "fcch_search":
|
if state == "fcch_search":
|
||||||
msg_ppm = pmt.from_double(ppm)
|
msg_ppm = pmt.from_double(ppm)
|
||||||
self.message_port_pub(pmt.intern("ppm"), msg_ppm)
|
self.message_port_pub(pmt.intern("ppm"), msg_ppm)
|
||||||
|
self.timer.cancel()
|
||||||
if state == "synchronized":
|
self.timer = Timer(0.5, self.conditional_reset)
|
||||||
|
self.timer.start()
|
||||||
|
elif state == "synchronized":
|
||||||
if self.first_measurement:
|
if self.first_measurement:
|
||||||
self.ppm_estimate = ppm
|
self.ppm_estimate = ppm
|
||||||
self.first_measurement = False
|
self.first_measurement = False
|
||||||
|
@ -71,11 +78,18 @@ class clock_offset_control(gr.basic_block):
|
||||||
self.message_port_pub(pmt.intern("ppm"), msg_ppm)
|
self.message_port_pub(pmt.intern("ppm"), msg_ppm)
|
||||||
else:
|
else:
|
||||||
self.counter=self.counter+1
|
self.counter=self.counter+1
|
||||||
|
elif state == "sync_loss":
|
||||||
if state == "sync_loss":
|
|
||||||
self.reset()
|
self.reset()
|
||||||
msg_ppm = pmt.from_double(0.0)
|
msg_ppm = pmt.from_double(0.0)
|
||||||
self.message_port_pub(pmt.intern("ppm"), msg_ppm)
|
self.message_port_pub(pmt.intern("ppm"), msg_ppm)
|
||||||
|
|
||||||
|
def conditional_reset(self):
|
||||||
|
if self.last_state != "synchronized":
|
||||||
|
# print "conditional reset"
|
||||||
|
self.reset()
|
||||||
|
msg_ppm = pmt.from_double(0.0)
|
||||||
|
self.message_port_pub(pmt.intern("ppm"), msg_ppm)
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.ppm_estimate = -1e6
|
self.ppm_estimate = -1e6
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
|
|
Loading…
Reference in New Issue