gr-lora/python/lora_receiver.py

75 wiersze
2.6 KiB
Python
Czysty Zwykły widok Historia

2016-06-22 19:43:15 +00:00
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Copyright 2016 Pieter Robyns.
#
# 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.
#
from gnuradio import gr
2018-01-05 09:55:08 +00:00
import gnuradio
2016-08-11 11:37:40 +00:00
import lora
2016-06-22 19:43:15 +00:00
class lora_receiver(gr.hier_block2):
"""
docstring for block lora_receiver
"""
def __init__(self, in_samp_rate, center_freq, channel_list, sf, out_samp_rate, implicit, cr, crc, reduced_rate=False, conj=False):
2016-06-22 19:43:15 +00:00
gr.hier_block2.__init__(self,
"lora_receiver", # Min, Max, gr.sizeof_<type>
gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
gr.io_signature(0, 0, 0)) # Output signature
2016-08-11 11:37:40 +00:00
# Parameters
self.in_samp_rate = in_samp_rate
2017-07-28 08:24:22 +00:00
self.center_freq = center_freq
self.sf = sf
self.out_samp_rate = out_samp_rate
2017-07-28 08:24:22 +00:00
self.channel_list = channel_list
2018-01-05 09:55:08 +00:00
self.conj = conj
2016-08-11 11:37:40 +00:00
2016-06-22 19:43:15 +00:00
# Define blocks
2018-01-05 09:55:08 +00:00
self.block_conj = gnuradio.blocks.conjugate_cc()
2017-07-28 08:24:22 +00:00
self.channelizer = lora.channelizer(in_samp_rate, out_samp_rate, center_freq, channel_list)
self.decoder = lora.decoder(out_samp_rate, sf, implicit, cr, crc, reduced_rate)
2016-06-22 19:43:15 +00:00
# Messages
self.message_port_register_hier_out('frames')
2016-06-22 19:43:15 +00:00
# Connect blocks
2017-07-28 08:24:22 +00:00
self.connect((self, 0), (self.channelizer, 0))
2018-01-05 09:55:08 +00:00
if self.conj:
self.connect((self.channelizer, 0), (self.block_conj, 0))
self.connect((self.block_conj, 0), (self.decoder, 0))
else:
self.connect((self.channelizer, 0), (self.decoder, 0))
2017-07-28 08:24:22 +00:00
self.msg_connect((self.decoder, 'frames'), (self, 'frames'))
self.msg_connect((self.decoder, 'control'), (self.channelizer, 'control'))
2016-08-11 11:37:40 +00:00
def get_sf(self):
2016-09-16 15:07:28 +00:00
return self.sf
2016-08-11 11:37:40 +00:00
2016-09-16 15:07:28 +00:00
def set_sf(self, sf):
self.sf = sf
2017-07-28 08:24:22 +00:00
self.decoder.set_sf(self.sf)
2016-09-09 15:32:15 +00:00
2017-07-28 08:24:22 +00:00
def get_center_freq(self):
return self.center_freq
2016-09-09 15:32:15 +00:00
2017-07-28 08:24:22 +00:00
def set_center_freq(self, center_freq):
self.center_freq = center_freq
self.channelizer.set_center_freq(self.center_freq)