Skip to content

Commit

Permalink
some optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
baskiton committed Jul 29, 2024
1 parent b563695 commit 5056864
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
6 changes: 1 addition & 5 deletions sats_receiver/gr_modules/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def __init__(self,

self.resamp_gcd = resamp_gcd = math.gcd(bandwidth, samp_rate)

self.blocks_copy = gr.blocks.copy(gr.gr.sizeof_gr_complex)
self.blocks_copy.set_enabled(self.enabled)
self.freqshifter = gr.blocks.rotator_cc(2 * math.pi * (main_tune - frequency) / samp_rate)
self.resampler = gr.filter.rational_resampler_ccc(
interpolation=bandwidth // resamp_gcd,
Expand All @@ -50,15 +48,13 @@ def __init__(self,

self.connect(
self,
self.blocks_copy,
self.freqshifter,
self.resampler,
self,
)

def set_enabled(self, enabled):
self.enabled = enabled
self.blocks_copy.set_enabled(enabled)

def set_freq_offset(self, new_freq: Union[int, float]):
self.freqshifter.set_phase_inc(2 * math.pi * (self.main_tune - new_freq) / self.samp_rate)
Expand Down Expand Up @@ -291,6 +287,7 @@ def start(self, observation_key: str):
for decoder in self.decoders:
decoder.set_observation_key(observation_key)
decoder.start()
self.radio.set_enabled(1)

def stop(self):
if self.is_runned:
Expand Down Expand Up @@ -539,7 +536,6 @@ def start(self):

for r in self.recorders:
r.start(observation_key)
r.radio.set_enabled(1)

def stop(self):
if self.is_runned:
Expand Down
52 changes: 39 additions & 13 deletions sats_receiver/gr_modules/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@ def __init__(self, up, config: Mapping):
self.flow = []
self.signal_src = gr.blocks.null_source(gr.gr.sizeof_gr_complex)
self.flow.append(self.signal_src)
self.connector = 0

if self.dc_block:
self.blocks_correctiq = gr.blocks.correctiq()
self.flow.append(self.blocks_correctiq)
self.connector = self.blocks_correctiq

if self.decimation > 1:
self.decim = gr.filter.rational_resampler_ccc(interpolation=1, decimation=self.decimation, taps=[])
self.flow.append(self.decim)
self.connector = self.decim

if not self.connector:
self.connector = gr.blocks.nop(gr.gr.sizeof_gr_complex)
self.flow.append(self.connector)

self.src_null_sink = gr.blocks.null_sink(gr.gr.sizeof_gr_complex)
self.flow.append(self.src_null_sink)
Expand Down Expand Up @@ -116,9 +123,9 @@ def update_config(self, config: Mapping, force=False):
for sat_name in to_remove_sats:
sat = self.satellites[sat_name]
self.up.scheduler.cancel(*sat.events)
sat.stop()
if self.is_runned:
self.disconnect(self.flow[-2], sat)
self.disconnect(self.connector, sat)
sat.stop()
del self.satellites[sat_name]

for sat_name in to_create_sats:
Expand All @@ -140,8 +147,6 @@ def update_config(self, config: Mapping, force=False):
continue

if self.calculate_pass(sat):
if self.is_runned:
self.connect(self.flow[-2], sat)
self.satellites[sat.name] = sat

if to_remove_sats or to_create_sats:
Expand Down Expand Up @@ -275,7 +280,6 @@ def start(self, max_noutput_items=10000000):
try:
self.signal_src = gr.soapy.source(f'driver={self.source}{self.serial and f",serial={self.serial}"}',
'fc32', 1, '', '', [''], [''])
self.flow[0] = self.signal_src
except RuntimeError as e:
self.log.error('cannot start: %s', e)

Expand All @@ -294,11 +298,9 @@ def start(self, max_noutput_items=10000000):
self.src_settings_keys = {a.key for a in self.signal_src.get_setting_info()}
self.soapy_apply(0)

self.flow[0] = self.signal_src
self.connect(*self.flow)

for sat in self.satellites.values():
self.connect(self.flow[-2], sat)

super(SatsReceiver, self).start(max_noutput_items)
self.is_runned = True

Expand All @@ -314,19 +316,43 @@ def stop(self, sched_clear=True):
super(SatsReceiver, self).stop()

self.disconnect(*self.flow)
from_disc = self.flow[-2]
self.signal_src = gr.blocks.null_source(gr.gr.sizeof_gr_complex)
self.flow[0] = self.signal_src

for sat in self.satellites.values():
if sched_clear:
self.up.scheduler.cancel(*sat.events)
if self.is_runned and sat.is_runned:
try:
self.disconnect(self.connector, sat)
sat.log.warning('stop %s', self.connector.name())
except ValueError as e:
sat.log.warning('stop %s fail: %s', self.connector.name(), e)
sat.stop()
if self.is_runned:
self.disconnect(from_disc, sat)

self.is_runned = False

def sat_attach(self, sat: modules.Satellite):
self.start()

self.lock()
self.connect(self.connector, sat)
sat.log.warning('attach %s', self.connector.name())
self.unlock()
sat.start()

def sat_detach(self, sat: modules.Satellite):
try:
self.lock()
if sat.is_runned:
self.disconnect(self.connector, sat)
sat.log.warning('detach %s', self.connector.name())
except ValueError as e:
sat.log.warning('detach %s fail: %s', self.connector.name(), e)
finally:
self.unlock()
sat.stop()

def action(self):
if self.is_active and not self.start():
for sat in self.satellites.values():
Expand Down Expand Up @@ -368,8 +394,8 @@ def calculate_pass(self, sat: modules.Satellite):
if set_t < rise_t:
rise_t = t
sat.events = [
None if sat.is_runned else self.up.scheduler.plan(rise_t, sat.start),
self.up.scheduler.plan(set_t, sat.stop),
None if sat.is_runned else self.up.scheduler.plan(rise_t, self.sat_attach, sat),
self.up.scheduler.plan(set_t, self.sat_detach, sat),
self.up.scheduler.plan(set_tt, self.calculate_pass, sat)
]
self.log.info('Sat `%s` planned on %s <-> %s',
Expand Down

0 comments on commit 5056864

Please sign in to comment.