2018-11-12 17:28:02 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright 2018 hcab14@gmail.com.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
from gnuradio import gr
|
|
|
|
import pmt
|
|
|
|
|
|
|
|
class msg_proxy(gr.basic_block):
|
|
|
|
"""
|
|
|
|
docstring for block msg_proxy
|
|
|
|
"""
|
|
|
|
def __init__(self, physical_layer_object):
|
|
|
|
gr.basic_block.__init__(self,
|
|
|
|
name="msg_proxy",
|
|
|
|
in_sig=[],
|
|
|
|
out_sig=[])
|
|
|
|
self._obj = physical_layer_object
|
2019-09-05 15:01:32 +00:00
|
|
|
self._quality = 0.0
|
2019-09-24 11:31:22 +00:00
|
|
|
self._doppler = 0.0
|
2018-11-12 17:28:02 +00:00
|
|
|
|
|
|
|
self._port_doppler = pmt.intern("doppler")
|
|
|
|
self.message_port_register_in(self._port_doppler)
|
|
|
|
self.message_port_register_out(self._port_doppler)
|
|
|
|
self.set_msg_handler(self._port_doppler, self.msg_handler_doppler)
|
|
|
|
|
|
|
|
self._port_frame_info = pmt.intern("frame_info")
|
|
|
|
self.message_port_register_in(self._port_frame_info)
|
|
|
|
self.message_port_register_out(self._port_frame_info)
|
|
|
|
self.set_msg_handler(self._port_frame_info, self.msg_handler_frame)
|
|
|
|
|
2019-05-10 09:48:56 +00:00
|
|
|
self._port_bits = pmt.intern("bits")
|
|
|
|
self.message_port_register_out(self._port_bits)
|
2019-03-28 16:23:15 +00:00
|
|
|
|
2019-09-05 15:01:32 +00:00
|
|
|
def start(self):
|
|
|
|
return True
|
|
|
|
|
2018-11-12 17:28:02 +00:00
|
|
|
def msg_handler_doppler(self, msg_in):
|
|
|
|
## print('-------------------- msg_handler_doppler --------------------')
|
|
|
|
iq_samples = pmt.to_python(pmt.cdr(msg_in))
|
2019-09-24 11:31:22 +00:00
|
|
|
doppler = self._obj.get_doppler(iq_samples)
|
|
|
|
self._doppler = doppler['doppler']
|
|
|
|
self.message_port_pub(self._port_doppler, pmt.to_pmt(doppler))
|
2018-11-12 17:28:02 +00:00
|
|
|
|
|
|
|
def msg_handler_frame(self, msg_in):
|
|
|
|
## print('-------------------- msg_handler_frame --------------------')
|
2019-05-10 09:48:56 +00:00
|
|
|
symbols = pmt.to_python(pmt.dict_ref(msg_in, pmt.intern('symbols'), pmt.PMT_NIL))
|
2019-03-28 16:23:15 +00:00
|
|
|
soft_dec = pmt.to_python(pmt.dict_ref(msg_in, pmt.intern('soft_dec'), pmt.PMT_NIL))
|
2018-11-12 17:28:02 +00:00
|
|
|
symb,constellation_idx,do_continue,save_soft_dec = self._obj.get_next_frame(symbols)
|
2019-09-14 15:03:12 +00:00
|
|
|
if len(soft_dec) != 0:
|
|
|
|
bits,q = self._obj.decode_soft_dec(soft_dec)
|
|
|
|
if len(bits) > 0:
|
|
|
|
self._quality = q
|
|
|
|
bits = np.array(bits, dtype=np.uint8)
|
|
|
|
msg_out = pmt.make_dict()
|
|
|
|
msg_out = pmt.dict_add(msg_out, pmt.intern('packet_len'), pmt.to_pmt(len(bits)))
|
|
|
|
msg = pmt.cons(msg_out, pmt.to_pmt(bits))
|
|
|
|
self.message_port_pub(self._port_bits, msg)
|
2019-05-10 09:48:56 +00:00
|
|
|
|
2019-09-05 15:01:32 +00:00
|
|
|
msg_out = pmt.to_pmt({'symb': symb['symb'],
|
|
|
|
'scramble': symb['scramble'],
|
|
|
|
'scramble_xor': symb['scramble_xor'],
|
|
|
|
'constellation_idx': constellation_idx,
|
|
|
|
'do_continue': np.bool(do_continue),
|
|
|
|
'save_soft_dec': np.bool(save_soft_dec)})
|
2018-11-12 17:28:02 +00:00
|
|
|
self.message_port_pub(self._port_frame_info, msg_out)
|
2019-09-05 15:01:32 +00:00
|
|
|
|
|
|
|
def get_quality(self):
|
|
|
|
return ('%5.1f %%' % self._quality)
|
2019-09-24 11:31:22 +00:00
|
|
|
|
|
|
|
def get_doppler(self):
|
|
|
|
return self._doppler
|