pull/21/head v0.2
Pieter Robyns 2016-08-11 13:37:40 +02:00
rodzic 96eec1df79
commit ad85c5e416
17 zmienionych plików z 4662 dodań i 101 usunięć

Wyświetl plik

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<?grc format='1' created='3.7.9'?>
<?grc format='1' created='3.7.10'?>
<flow_graph>
<timestamp>Tue Apr 12 11:23:34 2016</timestamp>
<block>
@ -163,30 +163,62 @@
</param>
</block>
<block>
<key>variable</key>
<key>variable_slider</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>converver</key>
<value>int_converter</value>
</param>
<param>
<key>value</key>
<value>-95</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(464, 77)</value>
<value>(976, 16)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>decimation</value>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>value</key>
<value>10</value>
<key>id</key>
<value>finetune</value>
</param>
<param>
<key>label</key>
<value></value>
</param>
<param>
<key>max</key>
<value>150</value>
</param>
<param>
<key>min</key>
<value>-150</value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>num_steps</key>
<value>300</value>
</param>
<param>
<key>style</key>
<value>wx.SL_HORIZONTAL</value>
</param>
</block>
<block>
@ -267,7 +299,7 @@
</param>
<param>
<key>value</key>
<value>10e6 </value>
<value>10e6</value>
</param>
</block>
<block>
@ -375,7 +407,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(16, 141)</value>
<value>(16, 188)</value>
</param>
<param>
<key>_rotation</key>
@ -406,61 +438,6 @@
<value>1</value>
</param>
</block>
<block>
<key>blocks_file_source</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>0</value>
</param>
<param>
<key>file</key>
<value>/tmp/cap.cfile</value>
</param>
<param>
<key>_coordinate</key>
<value>(16, 205)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_file_source_0_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>repeat</key>
<value>True</value>
</param>
<param>
<key>vlen</key>
<value>1</value>
</param>
</block>
<block>
<key>blocks_throttle</key>
<param>
@ -532,7 +509,11 @@
</param>
<param>
<key>_enabled</key>
<value>True</value>
<value>1</value>
</param>
<param>
<key>finetune</key>
<value>finetune</value>
</param>
<param>
<key>freq</key>
@ -540,7 +521,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(424, 182)</value>
<value>(424, 168)</value>
</param>
<param>
<key>_rotation</key>
@ -554,6 +535,10 @@
<key>offset</key>
<value>offset</value>
</param>
<param>
<key>realtime</key>
<value>False</value>
</param>
<param>
<key>in_samp_rate</key>
<value>samp_rate</value>
@ -587,7 +572,7 @@
</param>
<param>
<key>_enabled</key>
<value>0</value>
<value>1</value>
</param>
<param>
<key>fft_size</key>
@ -599,7 +584,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(80, 325)</value>
<value>(424, 284)</value>
</param>
<param>
<key>_rotation</key>
@ -611,7 +596,7 @@
</param>
<param>
<key>id</key>
<value>wxgui_fftsink2_0</value>
<value>wxgui_fftsink2_1</value>
</param>
<param>
<key>notebook</key>
@ -668,12 +653,6 @@
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_file_source_0_0</source_block_id>
<sink_block_id>blocks_throttle_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_throttle_0</source_block_id>
<sink_block_id>lora_lora_receiver_0</sink_block_id>
@ -682,7 +661,7 @@
</connection>
<connection>
<source_block_id>blocks_throttle_0</source_block_id>
<sink_block_id>wxgui_fftsink2_0</sink_block_id>
<sink_block_id>wxgui_fftsink2_1</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>

Wyświetl plik

@ -3,7 +3,7 @@
##################################################
# GNU Radio Python Flow Graph
# Title: Lora Receive File
# Generated: Wed Jun 22 19:59:10 2016
# Generated: Thu Aug 11 11:27:08 2016
##################################################
if __name__ == '__main__':
@ -19,8 +19,12 @@ if __name__ == '__main__':
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import wxgui
from gnuradio.eng_option import eng_option
from gnuradio.fft import window
from gnuradio.filter import firdes
from gnuradio.wxgui import fftsink2
from gnuradio.wxgui import forms
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import lora
@ -43,13 +47,52 @@ class lora_receive_file(grc_wxgui.top_block_gui):
self.symbols_per_sec = symbols_per_sec = bw / (2**sf)
self.offset = offset = -(capture_freq - target_freq)
self.firdes_tap = firdes_tap = firdes.low_pass(1, samp_rate, bw, 10000, firdes.WIN_HAMMING, 6.67)
self.decimation = decimation = 10
self.finetune = finetune = -95
self.bitrate = bitrate = sf * (1 / (2**sf / bw))
##################################################
# Blocks
##################################################
self.lora_lora_receiver_0 = lora.lora_receiver(samp_rate, capture_freq, offset)
_finetune_sizer = wx.BoxSizer(wx.VERTICAL)
self._finetune_text_box = forms.text_box(
parent=self.GetWin(),
sizer=_finetune_sizer,
value=self.finetune,
callback=self.set_finetune,
label='finetune',
converter=forms.int_converter(),
proportion=0,
)
self._finetune_slider = forms.slider(
parent=self.GetWin(),
sizer=_finetune_sizer,
value=self.finetune,
callback=self.set_finetune,
minimum=-150,
maximum=150,
num_steps=300,
style=wx.SL_HORIZONTAL,
cast=int,
proportion=1,
)
self.Add(_finetune_sizer)
self.wxgui_fftsink2_1 = fftsink2.fft_sink_c(
self.GetWin(),
baseband_freq=capture_freq,
y_per_div=10,
y_divs=10,
ref_level=0,
ref_scale=2.0,
sample_rate=samp_rate,
fft_size=1024,
fft_rate=15,
average=False,
avg_alpha=None,
title="FFT Plot",
peak_hold=False,
)
self.Add(self.wxgui_fftsink2_1.win)
self.lora_lora_receiver_0 = lora.lora_receiver(samp_rate, capture_freq, offset, finetune, False)
self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
self.blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*1, "counting_cr4_sf7.cfile", True)
@ -58,6 +101,7 @@ class lora_receive_file(grc_wxgui.top_block_gui):
##################################################
self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0))
self.connect((self.blocks_throttle_0, 0), (self.lora_lora_receiver_0, 0))
self.connect((self.blocks_throttle_0, 0), (self.wxgui_fftsink2_1, 0))
def get_target_freq(self):
return self.target_freq
@ -71,14 +115,15 @@ class lora_receive_file(grc_wxgui.top_block_gui):
def set_sf(self, sf):
self.sf = sf
self.set_bitrate(self.sf * (1 / (2**self.sf / self.bw)))
self.set_symbols_per_sec(self.bw / (2**self.sf))
self.set_bitrate(self.sf * (1 / (2**self.sf / self.bw)))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.wxgui_fftsink2_1.set_sample_rate(self.samp_rate)
self.set_firdes_tap(firdes.low_pass(1, self.samp_rate, self.bw, 10000, firdes.WIN_HAMMING, 6.67))
self.blocks_throttle_0.set_sample_rate(self.samp_rate)
@ -88,15 +133,16 @@ class lora_receive_file(grc_wxgui.top_block_gui):
def set_capture_freq(self, capture_freq):
self.capture_freq = capture_freq
self.set_offset(-(self.capture_freq - self.target_freq))
self.wxgui_fftsink2_1.set_baseband_freq(self.capture_freq)
def get_bw(self):
return self.bw
def set_bw(self, bw):
self.bw = bw
self.set_bitrate(self.sf * (1 / (2**self.sf / self.bw)))
self.set_firdes_tap(firdes.low_pass(1, self.samp_rate, self.bw, 10000, firdes.WIN_HAMMING, 6.67))
self.set_symbols_per_sec(self.bw / (2**self.sf))
self.set_firdes_tap(firdes.low_pass(1, self.samp_rate, self.bw, 10000, firdes.WIN_HAMMING, 6.67))
self.set_bitrate(self.sf * (1 / (2**self.sf / self.bw)))
def get_symbols_per_sec(self):
return self.symbols_per_sec
@ -116,11 +162,14 @@ class lora_receive_file(grc_wxgui.top_block_gui):
def set_firdes_tap(self, firdes_tap):
self.firdes_tap = firdes_tap
def get_decimation(self):
return self.decimation
def get_finetune(self):
return self.finetune
def set_decimation(self, decimation):
self.decimation = decimation
def set_finetune(self, finetune):
self.finetune = finetune
self._finetune_slider.set_value(self.finetune)
self._finetune_text_box.set_value(self.finetune)
self.lora_lora_receiver_0.set_finetune(self.finetune)
def get_bitrate(self):
return self.bitrate

Plik diff jest za duży Load Diff

Wyświetl plik

@ -0,0 +1,199 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Lora Receive Realtime
# Generated: Thu Aug 11 11:27:37 2016
##################################################
if __name__ == '__main__':
import ctypes
import sys
if sys.platform.startswith('linux'):
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print "Warning: failed to XInitThreads()"
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import uhd
from gnuradio import wxgui
from gnuradio.eng_option import eng_option
from gnuradio.fft import window
from gnuradio.filter import firdes
from gnuradio.wxgui import fftsink2
from gnuradio.wxgui import forms
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import lora
import time
import wx
class lora_receive_realtime(grc_wxgui.top_block_gui):
def __init__(self):
grc_wxgui.top_block_gui.__init__(self, title="Lora Receive Realtime")
##################################################
# Variables
##################################################
self.target_freq = target_freq = 868.1e6
self.sf = sf = 12
self.samp_rate = samp_rate = 2e6
self.capture_freq = capture_freq = 867.8e6
self.bw = bw = 125e3
self.symbols_per_sec = symbols_per_sec = bw / (2**sf)
self.offset = offset = -(capture_freq - target_freq)
self.firdes_tap = firdes_tap = firdes.low_pass(1, samp_rate, bw, 10000, firdes.WIN_HAMMING, 6.67)
self.finetune = finetune = -95
self.bitrate = bitrate = sf * (1 / (2**sf / bw))
##################################################
# Blocks
##################################################
_finetune_sizer = wx.BoxSizer(wx.VERTICAL)
self._finetune_text_box = forms.text_box(
parent=self.GetWin(),
sizer=_finetune_sizer,
value=self.finetune,
callback=self.set_finetune,
label='finetune',
converter=forms.int_converter(),
proportion=0,
)
self._finetune_slider = forms.slider(
parent=self.GetWin(),
sizer=_finetune_sizer,
value=self.finetune,
callback=self.set_finetune,
minimum=-150,
maximum=150,
num_steps=300,
style=wx.SL_HORIZONTAL,
cast=int,
proportion=1,
)
self.Add(_finetune_sizer)
self.wxgui_fftsink2_1 = fftsink2.fft_sink_c(
self.GetWin(),
baseband_freq=capture_freq,
y_per_div=10,
y_divs=10,
ref_level=0,
ref_scale=2.0,
sample_rate=samp_rate,
fft_size=1024,
fft_rate=15,
average=False,
avg_alpha=None,
title="FFT Plot",
peak_hold=False,
)
self.Add(self.wxgui_fftsink2_1.win)
self.uhd_usrp_source_0 = uhd.usrp_source(
",".join(("", "")),
uhd.stream_args(
cpu_format="fc32",
channels=range(1),
),
)
self.uhd_usrp_source_0.set_samp_rate(samp_rate)
self.uhd_usrp_source_0.set_center_freq(capture_freq, 0)
self.uhd_usrp_source_0.set_gain(15, 0)
self.uhd_usrp_source_0.set_antenna("RX2", 0)
self.lora_lora_receiver_0 = lora.lora_receiver(samp_rate, capture_freq, offset, finetune, True)
##################################################
# Connections
##################################################
self.connect((self.uhd_usrp_source_0, 0), (self.lora_lora_receiver_0, 0))
self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_fftsink2_1, 0))
def get_target_freq(self):
return self.target_freq
def set_target_freq(self, target_freq):
self.target_freq = target_freq
self.set_offset(-(self.capture_freq - self.target_freq))
def get_sf(self):
return self.sf
def set_sf(self, sf):
self.sf = sf
self.set_symbols_per_sec(self.bw / (2**self.sf))
self.set_bitrate(self.sf * (1 / (2**self.sf / self.bw)))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.wxgui_fftsink2_1.set_sample_rate(self.samp_rate)
self.uhd_usrp_source_0.set_samp_rate(self.samp_rate)
self.set_firdes_tap(firdes.low_pass(1, self.samp_rate, self.bw, 10000, firdes.WIN_HAMMING, 6.67))
def get_capture_freq(self):
return self.capture_freq
def set_capture_freq(self, capture_freq):
self.capture_freq = capture_freq
self.set_offset(-(self.capture_freq - self.target_freq))
self.wxgui_fftsink2_1.set_baseband_freq(self.capture_freq)
self.uhd_usrp_source_0.set_center_freq(self.capture_freq, 0)
def get_bw(self):
return self.bw
def set_bw(self, bw):
self.bw = bw
self.set_symbols_per_sec(self.bw / (2**self.sf))
self.set_firdes_tap(firdes.low_pass(1, self.samp_rate, self.bw, 10000, firdes.WIN_HAMMING, 6.67))
self.set_bitrate(self.sf * (1 / (2**self.sf / self.bw)))
def get_symbols_per_sec(self):
return self.symbols_per_sec
def set_symbols_per_sec(self, symbols_per_sec):
self.symbols_per_sec = symbols_per_sec
def get_offset(self):
return self.offset
def set_offset(self, offset):
self.offset = offset
def get_firdes_tap(self):
return self.firdes_tap
def set_firdes_tap(self, firdes_tap):
self.firdes_tap = firdes_tap
def get_finetune(self):
return self.finetune
def set_finetune(self, finetune):
self.finetune = finetune
self._finetune_slider.set_value(self.finetune)
self._finetune_text_box.set_value(self.finetune)
self.lora_lora_receiver_0.set_finetune(self.finetune)
def get_bitrate(self):
return self.bitrate
def set_bitrate(self, bitrate):
self.bitrate = bitrate
def main(top_block_cls=lora_receive_realtime, options=None):
tb = top_block_cls()
tb.Start(True)
tb.Wait()
if __name__ == '__main__':
main()

Wyświetl plik

@ -4,7 +4,14 @@
<key>lora_lora_receiver</key>
<category>lora</category>
<import>import lora</import>
<make>lora.lora_receiver($in_samp_rate, $freq, $offset)</make>
<make>lora.lora_receiver($in_samp_rate, $freq, $offset, $finetune, $realtime)</make>
<callback>set_finetune($finetune)</callback>
<param>
<name>Finetune</name>
<key>finetune</key>
<type>int</type>
</param>
<param>
<name>Sample rate</name>
@ -24,6 +31,12 @@
<type>float</type>
</param>
<param>
<name>Realtime</name>
<key>realtime</key>
<type>bool</type>
</param>
<sink>
<name>in</name>
<type>complex</type>

Wyświetl plik

@ -22,5 +22,5 @@
########################################################################
install(FILES
api.h
DESTINATION include/lora
decoder.h DESTINATION include/lora
)

Wyświetl plik

@ -0,0 +1,714 @@
/* -*- c++ -*- */
/* GNU GENERAL PUBLIC LICENSE
* Version 3, 29 June 2007
*
* Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*
* Preamble
*
* The GNU General Public License is a free, copyleft license for
* software and other kinds of works.
*
* The licenses for most software and other practical works are designed
* to take away your freedom to share and change the works. By contrast,
* the GNU General Public License is intended to guarantee your freedom to
* share and change all versions of a program--to make sure it remains free
* software for all its users. We, the Free Software Foundation, use the
* GNU General Public License for most of our software; it applies also to
* any other work released this way by its authors. You can apply it to
* your programs, too.
*
* When we speak of free software, we are referring to freedom, not
* price. Our General Public Licenses are designed to make sure that you
* have the freedom to distribute copies of free software (and charge for
* them if you wish), that you receive source code or can get it if you
* want it, that you can change the software or use pieces of it in new
* free programs, and that you know you can do these things.
*
* To protect your rights, we need to prevent others from denying you
* these rights or asking you to surrender the rights. Therefore, you have
* certain responsibilities if you distribute copies of the software, or if
* you modify it: responsibilities to respect the freedom of others.
*
* For example, if you distribute copies of such a program, whether
* gratis or for a fee, you must pass on to the recipients the same
* freedoms that you received. You must make sure that they, too, receive
* or can get the source code. And you must show them these terms so they
* know their rights.
*
* Developers that use the GNU GPL protect your rights with two steps:
* (1) assert copyright on the software, and (2) offer you this License
* giving you legal permission to copy, distribute and/or modify it.
*
* For the developers' and authors' protection, the GPL clearly explains
* that there is no warranty for this free software. For both users' and
* authors' sake, the GPL requires that modified versions be marked as
* changed, so that their problems will not be attributed erroneously to
* authors of previous versions.
*
* Some devices are designed to deny users access to install or run
* modified versions of the software inside them, although the manufacturer
* can do so. This is fundamentally incompatible with the aim of
* protecting users' freedom to change the software. The systematic
* pattern of such abuse occurs in the area of products for individuals to
* use, which is precisely where it is most unacceptable. Therefore, we
* have designed this version of the GPL to prohibit the practice for those
* products. If such problems arise substantially in other domains, we
* stand ready to extend this provision to those domains in future versions
* of the GPL, as needed to protect the freedom of users.
*
* Finally, every program is threatened constantly by software patents.
* States should not allow patents to restrict development and use of
* software on general-purpose computers, but in those that do, we wish to
* avoid the special danger that patents applied to a free program could
* make it effectively proprietary. To prevent this, the GPL assures that
* patents cannot be used to render the program non-free.
*
* The precise terms and conditions for copying, distribution and
* modification follow.
*
* TERMS AND CONDITIONS
*
* 0. Definitions.
*
* "This License" refers to version 3 of the GNU General Public License.
*
* "Copyright" also means copyright-like laws that apply to other kinds of
* works, such as semiconductor masks.
*
* "The Program" refers to any copyrightable work licensed under this
* License. Each licensee is addressed as "you". "Licensees" and
* "recipients" may be individuals or organizations.
*
* To "modify" a work means to copy from or adapt all or part of the work
* in a fashion requiring copyright permission, other than the making of an
* exact copy. The resulting work is called a "modified version" of the
* earlier work or a work "based on" the earlier work.
*
* A "covered work" means either the unmodified Program or a work based
* on the Program.
*
* To "propagate" a work means to do anything with it that, without
* permission, would make you directly or secondarily liable for
* infringement under applicable copyright law, except executing it on a
* computer or modifying a private copy. Propagation includes copying,
* distribution (with or without modification), making available to the
* public, and in some countries other activities as well.
*
* To "convey" a work means any kind of propagation that enables other
* parties to make or receive copies. Mere interaction with a user through
* a computer network, with no transfer of a copy, is not conveying.
*
* An interactive user interface displays "Appropriate Legal Notices"
* to the extent that it includes a convenient and prominently visible
* feature that (1) displays an appropriate copyright notice, and (2)
* tells the user that there is no warranty for the work (except to the
* extent that warranties are provided), that licensees may convey the
* work under this License, and how to view a copy of this License. If
* the interface presents a list of user commands or options, such as a
* menu, a prominent item in the list meets this criterion.
*
* 1. Source Code.
*
* The "source code" for a work means the preferred form of the work
* for making modifications to it. "Object code" means any non-source
* form of a work.
*
* A "Standard Interface" means an interface that either is an official
* standard defined by a recognized standards body, or, in the case of
* interfaces specified for a particular programming language, one that
* is widely used among developers working in that language.
*
* The "System Libraries" of an executable work include anything, other
* than the work as a whole, that (a) is included in the normal form of
* packaging a Major Component, but which is not part of that Major
* Component, and (b) serves only to enable use of the work with that
* Major Component, or to implement a Standard Interface for which an
* implementation is available to the public in source code form. A
* "Major Component", in this context, means a major essential component
* (kernel, window system, and so on) of the specific operating system
* (if any) on which the executable work runs, or a compiler used to
* produce the work, or an object code interpreter used to run it.
*
* The "Corresponding Source" for a work in object code form means all
* the source code needed to generate, install, and (for an executable
* work) run the object code and to modify the work, including scripts to
* control those activities. However, it does not include the work's
* System Libraries, or general-purpose tools or generally available free
* programs which are used unmodified in performing those activities but
* which are not part of the work. For example, Corresponding Source
* includes interface definition files associated with source files for
* the work, and the source code for shared libraries and dynamically
* linked subprograms that the work is specifically designed to require,
* such as by intimate data communication or control flow between those
* subprograms and other parts of the work.
*
* The Corresponding Source need not include anything that users
* can regenerate automatically from other parts of the Corresponding
* Source.
*
* The Corresponding Source for a work in source code form is that
* same work.
*
* 2. Basic Permissions.
*
* All rights granted under this License are granted for the term of
* copyright on the Program, and are irrevocable provided the stated
* conditions are met. This License explicitly affirms your unlimited
* permission to run the unmodified Program. The output from running a
* covered work is covered by this License only if the output, given its
* content, constitutes a covered work. This License acknowledges your
* rights of fair use or other equivalent, as provided by copyright law.
*
* You may make, run and propagate covered works that you do not
* convey, without conditions so long as your license otherwise remains
* in force. You may convey covered works to others for the sole purpose
* of having them make modifications exclusively for you, or provide you
* with facilities for running those works, provided that you comply with
* the terms of this License in conveying all material for which you do
* not control copyright. Those thus making or running the covered works
* for you must do so exclusively on your behalf, under your direction
* and control, on terms that prohibit them from making any copies of
* your copyrighted material outside their relationship with you.
*
* Conveying under any other circumstances is permitted solely under
* the conditions stated below. Sublicensing is not allowed; section 10
* makes it unnecessary.
*
* 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
*
* No covered work shall be deemed part of an effective technological
* measure under any applicable law fulfilling obligations under article
* 11 of the WIPO copyright treaty adopted on 20 December 1996, or
* similar laws prohibiting or restricting circumvention of such
* measures.
*
* When you convey a covered work, you waive any legal power to forbid
* circumvention of technological measures to the extent such circumvention
* is effected by exercising rights under this License with respect to
* the covered work, and you disclaim any intention to limit operation or
* modification of the work as a means of enforcing, against the work's
* users, your or third parties' legal rights to forbid circumvention of
* technological measures.
*
* 4. Conveying Verbatim Copies.
*
* You may convey verbatim copies of the Program's source code as you
* receive it, in any medium, provided that you conspicuously and
* appropriately publish on each copy an appropriate copyright notice;
* keep intact all notices stating that this License and any
* non-permissive terms added in accord with section 7 apply to the code;
* keep intact all notices of the absence of any warranty; and give all
* recipients a copy of this License along with the Program.
*
* You may charge any price or no price for each copy that you convey,
* and you may offer support or warranty protection for a fee.
*
* 5. Conveying Modified Source Versions.
*
* You may convey a work based on the Program, or the modifications to
* produce it from the Program, in the form of source code under the
* terms of section 4, provided that you also meet all of these conditions:
*
* a) The work must carry prominent notices stating that you modified
* it, and giving a relevant date.
*
* b) The work must carry prominent notices stating that it is
* released under this License and any conditions added under section
* 7. This requirement modifies the requirement in section 4 to
* "keep intact all notices".
*
* c) You must license the entire work, as a whole, under this
* License to anyone who comes into possession of a copy. This
* License will therefore apply, along with any applicable section 7
* additional terms, to the whole of the work, and all its parts,
* regardless of how they are packaged. This License gives no
* permission to license the work in any other way, but it does not
* invalidate such permission if you have separately received it.
*
* d) If the work has interactive user interfaces, each must display
* Appropriate Legal Notices; however, if the Program has interactive
* interfaces that do not display Appropriate Legal Notices, your
* work need not make them do so.
*
* A compilation of a covered work with other separate and independent
* works, which are not by their nature extensions of the covered work,
* and which are not combined with it such as to form a larger program,
* in or on a volume of a storage or distribution medium, is called an
* "aggregate" if the compilation and its resulting copyright are not
* used to limit the access or legal rights of the compilation's users
* beyond what the individual works permit. Inclusion of a covered work
* in an aggregate does not cause this License to apply to the other
* parts of the aggregate.
*
* 6. Conveying Non-Source Forms.
*
* You may convey a covered work in object code form under the terms
* of sections 4 and 5, provided that you also convey the
* machine-readable Corresponding Source under the terms of this License,
* in one of these ways:
*
* a) Convey the object code in, or embodied in, a physical product
* (including a physical distribution medium), accompanied by the
* Corresponding Source fixed on a durable physical medium
* customarily used for software interchange.
*
* b) Convey the object code in, or embodied in, a physical product
* (including a physical distribution medium), accompanied by a
* written offer, valid for at least three years and valid for as
* long as you offer spare parts or customer support for that product
* model, to give anyone who possesses the object code either (1) a
* copy of the Corresponding Source for all the software in the
* product that is covered by this License, on a durable physical
* medium customarily used for software interchange, for a price no
* more than your reasonable cost of physically performing this
* conveying of source, or (2) access to copy the
* Corresponding Source from a network server at no charge.
*
* c) Convey individual copies of the object code with a copy of the
* written offer to provide the Corresponding Source. This
* alternative is allowed only occasionally and noncommercially, and
* only if you received the object code with such an offer, in accord
* with subsection 6b.
*
* d) Convey the object code by offering access from a designated
* place (gratis or for a charge), and offer equivalent access to the
* Corresponding Source in the same way through the same place at no
* further charge. You need not require recipients to copy the
* Corresponding Source along with the object code. If the place to
* copy the object code is a network server, the Corresponding Source
* may be on a different server (operated by you or a third party)
* that supports equivalent copying facilities, provided you maintain
* clear directions next to the object code saying where to find the
* Corresponding Source. Regardless of what server hosts the
* Corresponding Source, you remain obligated to ensure that it is
* available for as long as needed to satisfy these requirements.
*
* e) Convey the object code using peer-to-peer transmission, provided
* you inform other peers where the object code and Corresponding
* Source of the work are being offered to the general public at no
* charge under subsection 6d.
*
* A separable portion of the object code, whose source code is excluded
* from the Corresponding Source as a System Library, need not be
* included in conveying the object code work.
*
* A "User Product" is either (1) a "consumer product", which means any
* tangible personal property which is normally used for personal, family,
* or household purposes, or (2) anything designed or sold for incorporation
* into a dwelling. In determining whether a product is a consumer product,
* doubtful cases shall be resolved in favor of coverage. For a particular
* product received by a particular user, "normally used" refers to a
* typical or common use of that class of product, regardless of the status
* of the particular user or of the way in which the particular user
* actually uses, or expects or is expected to use, the product. A product
* is a consumer product regardless of whether the product has substantial
* commercial, industrial or non-consumer uses, unless such uses represent
* the only significant mode of use of the product.
*
* "Installation Information" for a User Product means any methods,
* procedures, authorization keys, or other information required to install
* and execute modified versions of a covered work in that User Product from
* a modified version of its Corresponding Source. The information must
* suffice to ensure that the continued functioning of the modified object
* code is in no case prevented or interfered with solely because
* modification has been made.
*
* If you convey an object code work under this section in, or with, or
* specifically for use in, a User Product, and the conveying occurs as
* part of a transaction in which the right of possession and use of the
* User Product is transferred to the recipient in perpetuity or for a
* fixed term (regardless of how the transaction is characterized), the
* Corresponding Source conveyed under this section must be accompanied
* by the Installation Information. But this requirement does not apply
* if neither you nor any third party retains the ability to install
* modified object code on the User Product (for example, the work has
* been installed in ROM).
*
* The requirement to provide Installation Information does not include a
* requirement to continue to provide support service, warranty, or updates
* for a work that has been modified or installed by the recipient, or for
* the User Product in which it has been modified or installed. Access to a
* network may be denied when the modification itself materially and
* adversely affects the operation of the network or violates the rules and
* protocols for communication across the network.
*
* Corresponding Source conveyed, and Installation Information provided,
* in accord with this section must be in a format that is publicly
* documented (and with an implementation available to the public in
* source code form), and must require no special password or key for
* unpacking, reading or copying.
*
* 7. Additional Terms.
*
* "Additional permissions" are terms that supplement the terms of this
* License by making exceptions from one or more of its conditions.
* Additional permissions that are applicable to the entire Program shall
* be treated as though they were included in this License, to the extent
* that they are valid under applicable law. If additional permissions
* apply only to part of the Program, that part may be used separately
* under those permissions, but the entire Program remains governed by
* this License without regard to the additional permissions.
*
* When you convey a copy of a covered work, you may at your option
* remove any additional permissions from that copy, or from any part of
* it. (Additional permissions may be written to require their own
* removal in certain cases when you modify the work.) You may place
* additional permissions on material, added by you to a covered work,
* for which you have or can give appropriate copyright permission.
*
* Notwithstanding any other provision of this License, for material you
* add to a covered work, you may (if authorized by the copyright holders of
* that material) supplement the terms of this License with terms:
*
* a) Disclaiming warranty or limiting liability differently from the
* terms of sections 15 and 16 of this License; or
*
* b) Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it; or
*
* c) Prohibiting misrepresentation of the origin of that material, or
* requiring that modified versions of such material be marked in
* reasonable ways as different from the original version; or
*
* d) Limiting the use for publicity purposes of names of licensors or
* authors of the material; or
*
* e) Declining to grant rights under trademark law for use of some
* trade names, trademarks, or service marks; or
*
* f) Requiring indemnification of licensors and authors of that
* material by anyone who conveys the material (or modified versions of
* it) with contractual assumptions of liability to the recipient, for
* any liability that these contractual assumptions directly impose on
* those licensors and authors.
*
* All other non-permissive additional terms are considered "further
* restrictions" within the meaning of section 10. If the Program as you
* received it, or any part of it, contains a notice stating that it is
* governed by this License along with a term that is a further
* restriction, you may remove that term. If a license document contains
* a further restriction but permits relicensing or conveying under this
* License, you may add to a covered work material governed by the terms
* of that license document, provided that the further restriction does
* not survive such relicensing or conveying.
*
* If you add terms to a covered work in accord with this section, you
* must place, in the relevant source files, a statement of the
* additional terms that apply to those files, or a notice indicating
* where to find the applicable terms.
*
* Additional terms, permissive or non-permissive, may be stated in the
* form of a separately written license, or stated as exceptions;
* the above requirements apply either way.
*
* 8. Termination.
*
* You may not propagate or modify a covered work except as expressly
* provided under this License. Any attempt otherwise to propagate or
* modify it is void, and will automatically terminate your rights under
* this License (including any patent licenses granted under the third
* paragraph of section 11).
*
* However, if you cease all violation of this License, then your
* license from a particular copyright holder is reinstated (a)
* provisionally, unless and until the copyright holder explicitly and
* finally terminates your license, and (b) permanently, if the copyright
* holder fails to notify you of the violation by some reasonable means
* prior to 60 days after the cessation.
*
* Moreover, your license from a particular copyright holder is
* reinstated permanently if the copyright holder notifies you of the
* violation by some reasonable means, this is the first time you have
* received notice of violation of this License (for any work) from that
* copyright holder, and you cure the violation prior to 30 days after
* your receipt of the notice.
*
* Termination of your rights under this section does not terminate the
* licenses of parties who have received copies or rights from you under
* this License. If your rights have been terminated and not permanently
* reinstated, you do not qualify to receive new licenses for the same
* material under section 10.
*
* 9. Acceptance Not Required for Having Copies.
*
* You are not required to accept this License in order to receive or
* run a copy of the Program. Ancillary propagation of a covered work
* occurring solely as a consequence of using peer-to-peer transmission
* to receive a copy likewise does not require acceptance. However,
* nothing other than this License grants you permission to propagate or
* modify any covered work. These actions infringe copyright if you do
* not accept this License. Therefore, by modifying or propagating a
* covered work, you indicate your acceptance of this License to do so.
*
* 10. Automatic Licensing of Downstream Recipients.
*
* Each time you convey a covered work, the recipient automatically
* receives a license from the original licensors, to run, modify and
* propagate that work, subject to this License. You are not responsible
* for enforcing compliance by third parties with this License.
*
* An "entity transaction" is a transaction transferring control of an
* organization, or substantially all assets of one, or subdividing an
* organization, or merging organizations. If propagation of a covered
* work results from an entity transaction, each party to that
* transaction who receives a copy of the work also receives whatever
* licenses to the work the party's predecessor in interest had or could
* give under the previous paragraph, plus a right to possession of the
* Corresponding Source of the work from the predecessor in interest, if
* the predecessor has it or can get it with reasonable efforts.
*
* You may not impose any further restrictions on the exercise of the
* rights granted or affirmed under this License. For example, you may
* not impose a license fee, royalty, or other charge for exercise of
* rights granted under this License, and you may not initiate litigation
* (including a cross-claim or counterclaim in a lawsuit) alleging that
* any patent claim is infringed by making, using, selling, offering for
* sale, or importing the Program or any portion of it.
*
* 11. Patents.
*
* A "contributor" is a copyright holder who authorizes use under this
* License of the Program or a work on which the Program is based. The
* work thus licensed is called the contributor's "contributor version".
*
* A contributor's "essential patent claims" are all patent claims
* owned or controlled by the contributor, whether already acquired or
* hereafter acquired, that would be infringed by some manner, permitted
* by this License, of making, using, or selling its contributor version,
* but do not include claims that would be infringed only as a
* consequence of further modification of the contributor version. For
* purposes of this definition, "control" includes the right to grant
* patent sublicenses in a manner consistent with the requirements of
* this License.
*
* Each contributor grants you a non-exclusive, worldwide, royalty-free
* patent license under the contributor's essential patent claims, to
* make, use, sell, offer for sale, import and otherwise run, modify and
* propagate the contents of its contributor version.
*
* In the following three paragraphs, a "patent license" is any express
* agreement or commitment, however denominated, not to enforce a patent
* (such as an express permission to practice a patent or covenant not to
* sue for patent infringement). To "grant" such a patent license to a
* party means to make such an agreement or commitment not to enforce a
* patent against the party.
*
* If you convey a covered work, knowingly relying on a patent license,
* and the Corresponding Source of the work is not available for anyone
* to copy, free of charge and under the terms of this License, through a
* publicly available network server or other readily accessible means,
* then you must either (1) cause the Corresponding Source to be so
* available, or (2) arrange to deprive yourself of the benefit of the
* patent license for this particular work, or (3) arrange, in a manner
* consistent with the requirements of this License, to extend the patent
* license to downstream recipients. "Knowingly relying" means you have
* actual knowledge that, but for the patent license, your conveying the
* covered work in a country, or your recipient's use of the covered work
* in a country, would infringe one or more identifiable patents in that
* country that you have reason to believe are valid.
*
* If, pursuant to or in connection with a single transaction or
* arrangement, you convey, or propagate by procuring conveyance of, a
* covered work, and grant a patent license to some of the parties
* receiving the covered work authorizing them to use, propagate, modify
* or convey a specific copy of the covered work, then the patent license
* you grant is automatically extended to all recipients of the covered
* work and works based on it.
*
* A patent license is "discriminatory" if it does not include within
* the scope of its coverage, prohibits the exercise of, or is
* conditioned on the non-exercise of one or more of the rights that are
* specifically granted under this License. You may not convey a covered
* work if you are a party to an arrangement with a third party that is
* in the business of distributing software, under which you make payment
* to the third party based on the extent of your activity of conveying
* the work, and under which the third party grants, to any of the
* parties who would receive the covered work from you, a discriminatory
* patent license (a) in connection with copies of the covered work
* conveyed by you (or copies made from those copies), or (b) primarily
* for and in connection with specific products or compilations that
* contain the covered work, unless you entered into that arrangement,
* or that patent license was granted, prior to 28 March 2007.
*
* Nothing in this License shall be construed as excluding or limiting
* any implied license or other defenses to infringement that may
* otherwise be available to you under applicable patent law.
*
* 12. No Surrender of Others' Freedom.
*
* If conditions are imposed on you (whether by court order, agreement or
* otherwise) that contradict the conditions of this License, they do not
* excuse you from the conditions of this License. If you cannot convey a
* covered work so as to satisfy simultaneously your obligations under this
* License and any other pertinent obligations, then as a consequence you may
* not convey it at all. For example, if you agree to terms that obligate you
* to collect a royalty for further conveying from those to whom you convey
* the Program, the only way you could satisfy both those terms and this
* License would be to refrain entirely from conveying the Program.
*
* 13. Use with the GNU Affero General Public License.
*
* Notwithstanding any other provision of this License, you have
* permission to link or combine any covered work with a work licensed
* under version 3 of the GNU Affero General Public License into a single
* combined work, and to convey the resulting work. The terms of this
* License will continue to apply to the part which is the covered work,
* but the special requirements of the GNU Affero General Public License,
* section 13, concerning interaction through a network will apply to the
* combination as such.
*
* 14. Revised Versions of this License.
*
* The Free Software Foundation may publish revised and/or new versions of
* the GNU General Public License from time to time. Such new versions will
* be similar in spirit to the present version, but may differ in detail to
* address new problems or concerns.
*
* Each version is given a distinguishing version number. If the
* Program specifies that a certain numbered version of the GNU General
* Public License "or any later version" applies to it, you have the
* option of following the terms and conditions either of that numbered
* version or of any later version published by the Free Software
* Foundation. If the Program does not specify a version number of the
* GNU General Public License, you may choose any version ever published
* by the Free Software Foundation.
*
* If the Program specifies that a proxy can decide which future
* versions of the GNU General Public License can be used, that proxy's
* public statement of acceptance of a version permanently authorizes you
* to choose that version for the Program.
*
* Later license versions may give you additional or different
* permissions. However, no additional obligations are imposed on any
* author or copyright holder as a result of your choosing to follow a
* later version.
*
* 15. Disclaimer of Warranty.
*
* THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
* APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
* HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
* OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
* IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
* ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
*
* 16. Limitation of Liability.
*
* IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
* WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
* THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
* GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
* USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
* DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
* PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
* EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGES.
*
* 17. Interpretation of Sections 15 and 16.
*
* If the disclaimer of warranty and limitation of liability provided
* above cannot be given local legal effect according to their terms,
* reviewing courts shall apply local law that most closely approximates
* an absolute waiver of all civil liability in connection with the
* Program, unless a warranty or assumption of liability accompanies a
* copy of the Program in return for a fee.
*
* END OF TERMS AND CONDITIONS
*
* How to Apply These Terms to Your New Programs
*
* If you develop a new program, and you want it to be of the greatest
* possible use to the public, the best way to achieve this is to make it
* free software which everyone can redistribute and change under these terms.
*
* To do so, attach the following notices to the program. It is safest
* to attach them to the start of each source file to most effectively
* state the exclusion of warranty; and each file should have at least
* the "copyright" line and a pointer to where the full notice is found.
*
* {one line to give the program's name and a brief idea of what it does.}
* Copyright (C) {year} {name of author}
*
* This program 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 of the License, or
* (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
* Also add information on how to contact you by electronic and paper mail.
*
* If the program does terminal interaction, make it output a short
* notice like this when it starts in an interactive mode:
*
* {project} Copyright (C) {year} {fullname}
* This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
* This is free software, and you are welcome to redistribute it
* under certain conditions; type `show c' for details.
*
* The hypothetical commands `show w' and `show c' should show the appropriate
* parts of the General Public License. Of course, your program's commands
* might be different; for a GUI interface, you would use an "about box".
*
* You should also get your employer (if you work as a programmer) or school,
* if any, to sign a "copyright disclaimer" for the program, if necessary.
* For more information on this, and how to apply and follow the GNU GPL, see
* <http://www.gnu.org/licenses/>.
*
* The GNU General Public License does not permit incorporating your program
* into proprietary programs. If your program is a subroutine library, you
* may consider it more useful to permit linking proprietary applications with
* the library. If this is what you want to do, use the GNU Lesser General
* Public License instead of this License. But first, please read
* <http://www.gnu.org/philosophy/why-not-lgpl.html>.
*/
#ifndef INCLUDED_LORA_DECODER_H
#define INCLUDED_LORA_DECODER_H
#include <lora/api.h>
#include <gnuradio/sync_block.h>
namespace gr {
namespace lora {
/*!
* \brief <+description of block+>
* \ingroup lora
*
*/
class LORA_API decoder : virtual public gr::sync_block
{
public:
typedef boost::shared_ptr<decoder> sptr;
/*!
* \brief Return a shared_ptr to a new instance of lora::decoder.
*
* To avoid accidental use of raw pointers, lora::decoder's
* constructor is in a private implementation
* class. lora::decoder::make is the public interface for
* creating new instances.
*/
static sptr make(int finetune);
virtual void set_finetune(int32_t finetune) = 0;
};
} // namespace lora
} // namespace gr
#endif /* INCLUDED_LORA_DECODER_H */

Wyświetl plik

@ -26,6 +26,7 @@ include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
list(APPEND lora_sources
decoder_impl.cc
)
set(lora_sources "${lora_sources}" PARENT_SCOPE)
@ -35,7 +36,7 @@ if(NOT lora_sources)
endif(NOT lora_sources)
add_library(gnuradio-lora SHARED ${lora_sources})
target_link_libraries(gnuradio-lora ${Boost_LIBRARIES} ${GNURADIO_ALL_LIBRARIES})
target_link_libraries(gnuradio-lora ${Boost_LIBRARIES} ${GNURADIO_ALL_LIBRARIES} liquid)
set_target_properties(gnuradio-lora PROPERTIES DEFINE_SYMBOL "gnuradio_lora_EXPORTS")
if(APPLE)
@ -73,6 +74,7 @@ target_link_libraries(
${Boost_LIBRARIES}
${CPPUNIT_LIBRARIES}
gnuradio-lora
liquid
)
GR_ADD_TEST(test_lora test-lora)

536
lib/decoder_impl.cc 100644
Wyświetl plik

@ -0,0 +1,536 @@
/* -*- c++ -*- */
/*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include <gnuradio/expj.h>
#include <liquid/liquid.h>
#include "decoder_impl.h"
#include "tables.h"
#include "utilities.h"
#define CORRELATION_SEARCH_RANGE 1024
#define DELAY_AFTER_SYNC 262
//#define NO_TMP_WRITES 1
namespace gr {
namespace lora {
decoder::sptr
decoder::make(int finetune) {
return gnuradio::get_initial_sptr
(new decoder_impl(finetune));
}
/*
* The private constructor
*/
decoder_impl::decoder_impl(int finetune) : gr::sync_block("decoder",
gr::io_signature::make(1, -1, sizeof(gr_complex)),
gr::io_signature::make(0, 2, sizeof(float))) {
d_state = DETECT;
d_debug_samples.open("/tmp/grlora_debug", std::ios::out | std::ios::binary);
d_debug.open("/tmp/grlora_debug_txt", std::ios::out);
d_sf = 7; // Only affects PHY send
d_bw = 125000;
d_cr = 4;
d_bits_per_second = (double)d_sf * 1.0f / (pow(2.0f, d_sf) / d_bw);
d_samples_per_second = 1000000;
d_symbols_per_second = (double)d_bw / pow(2.0f, d_sf);
d_bits_per_symbol = (uint32_t)(d_bits_per_second / d_symbols_per_second);
d_samples_per_symbol = (uint32_t)(d_samples_per_second / d_symbols_per_second);
d_number_of_bins = (uint32_t)pow(2, d_sf);
d_number_of_bins_hdr = d_number_of_bins / 4;
d_compression = 8;
d_payload_symbols = 0;
d_finetune = finetune;
// Some preparations
std::cout << "Bits per symbol: " << d_bits_per_symbol << std::endl;
std::cout << "Bins per symbol: " << d_number_of_bins << std::endl;
std::cout << "Header bins per symbol: " << d_number_of_bins_hdr << std::endl;
std::cout << "Samples per symbol: " << d_samples_per_symbol << std::endl;
build_ideal_downchirp();
set_output_multiple(2*d_samples_per_symbol);
d_fft.resize(d_samples_per_symbol);
d_mult.resize(d_samples_per_symbol);
d_q = fft_create_plan(d_samples_per_symbol, &d_mult[0], &d_fft[0], LIQUID_FFT_FORWARD, 0);
}
/*
* Our virtual destructor.
*/
decoder_impl::~decoder_impl() {
if(d_debug_samples.is_open())
d_debug_samples.close();
if(d_debug.is_open())
d_debug.close();
fft_destroy_plan(d_q);
}
void decoder_impl::build_ideal_downchirp(void) {
d_downchirp.resize(d_samples_per_symbol);
d_downchirp_fft.resize(d_samples_per_symbol);
double T = 1.0f / d_symbols_per_second;
double dir = -1.0f;
double dt = 1.0f / d_samples_per_second;
double f0 = (d_bw / 2.0f);
double amplitude = 1.0f;
// Store time domain signal
for(int i = 0; i < d_samples_per_symbol; i++) { // Width in number of samples = samples_per_symbol
// See https://en.wikipedia.org/wiki/Chirp#Linear
double t = dt * i;
d_downchirp[i] = gr_complex(amplitude, amplitude) * gr_expj(2.0f * M_PI * (f0 * t + (dir * (0.5 * d_bw / T) * pow(t, 2))));
}
// Store FFT of downchirp TODO needed?
int flags = 0;
fftplan q = fft_create_plan(d_samples_per_symbol, &d_downchirp[0], &d_downchirp_fft[0], LIQUID_FFT_FORWARD, flags);
fft_execute(q);
fft_destroy_plan(q);
samples_to_file("/tmp/downchirp", &d_downchirp[0], d_downchirp.size(), sizeof(gr_complex));
samples_to_file("/tmp/downchirp_fft", &d_downchirp_fft[0], d_downchirp_fft.size(), sizeof(gr_complex));
}
void decoder_impl::samples_to_file(const std::string path, const gr_complex* v, int length, int elem_size) {
#ifndef NO_TMP_WRITES
std::ofstream out_file;
out_file.open(path, std::ios::out | std::ios::binary);
//for(std::vector<gr_complex>::const_iterator it = v.begin(); it != v.end(); ++it) {
for(uint32_t i = 0; i < length; i++) {
out_file.write(reinterpret_cast<const char *>(&v[i]), elem_size);
}
out_file.close();
#endif
}
void decoder_impl::samples_debug(const gr_complex* v, int length) {
gr_complex start_indicator(0.0f,32.0f);
d_debug_samples.write(reinterpret_cast<const char *>(&start_indicator), sizeof(gr_complex));
for(uint32_t i = 1; i < length; i++) {
d_debug_samples.write(reinterpret_cast<const char *>(&v[i]), sizeof(gr_complex));
}
}
bool decoder_impl::calc_energy_threshold(gr_complex* samples, int window_size, float threshold) {
float result = 0.0f;
for(int i = 0; i < window_size; i++) {
result += std::pow(abs(samples[i]), 2);
}
result /= (float)window_size;
//d_debug << "T: " << result << "\n";
if(result > threshold) {
return true;
} else {
return false;
}
}
inline void decoder_impl::phase(gr_complex* in_samples, float* out_phase, int window) {
for(int i = 0; i < window; i++) {
out_phase[i] = arg(in_samples[i]); // = the same as atan2(imag(in_samples[i]),real(in_samples[i]));
}
}
double decoder_impl::freq_cross_correlate(const gr_complex *samples_1, const gr_complex *samples_2, int window) {
double result = 0.0f;
float instantaneous_phase[window];
float instantaneous_phase_down[window];
float instantaneous_freq[window];
float instantaneous_freq_down[window];
// Determine instant phase
for(unsigned int i = 0; i < window; i++) {
instantaneous_phase[i] = arg(samples_1[i]);
instantaneous_phase_down[i] = arg(samples_2[i]);
}
liquid_unwrap_phase(instantaneous_phase, window);
liquid_unwrap_phase(instantaneous_phase_down, window);
// Instant freq
for(unsigned int i = 1; i < window; i++) {
instantaneous_freq[i-1] = instantaneous_phase[i] - instantaneous_phase[i-1];
instantaneous_freq_down[i-1] = instantaneous_phase_down[i] - instantaneous_phase_down[i-1];
}
for (int i = 0; i < window-1; i++) {
result += instantaneous_freq[i] * instantaneous_freq_down[i];
}
result = result / window;
return result;
}
// TODO: Instead of the finetuning parameter, one could look at the minimum
// and maximum instantaneous frequency to determine how detuned the sender
// is from the channel frequency.
int decoder_impl::sync_fft(const gr_complex* samples) {
float fft_mag[d_samples_per_symbol];
// Multiply with ideal downchirp
for(uint32_t i = 0; i < d_samples_per_symbol; i++) {
d_mult[i] = samples[i] * d_downchirp[i];
}
// Perform FFT
fft_execute(d_q);
// Get magnitude
for(int i = 0; i < d_samples_per_symbol; i++) {
fft_mag[i] = abs(d_fft[i]);
}
samples_to_file("/tmp/fft", &d_fft[0], d_samples_per_symbol, sizeof(gr_complex));
// Return argmax here
return (std::max_element(fft_mag,fft_mag+d_samples_per_symbol) - fft_mag);
}
unsigned int decoder_impl::max_frequency_gradient_idx(gr_complex* samples) {
float instantaneous_phase[d_samples_per_symbol];
float instantaneous_freq[d_samples_per_symbol];
float bins[d_number_of_bins];
// Determine instant phase
for(unsigned int i = 0; i < d_samples_per_symbol; i++) {
instantaneous_phase[i] = arg(samples[i]);
}
liquid_unwrap_phase(instantaneous_phase, d_samples_per_symbol);
float max_if_diff = 2000.0f;
unsigned int max_if_diff_idx = 0;
for(unsigned int i = 1; i < d_samples_per_symbol; i++) {
float ifreq = (instantaneous_phase[i] - instantaneous_phase[i-1]) / (2.0f * M_PI) * d_samples_per_second; // TODO: constant multiplication can be removed
instantaneous_freq[i-1] = ifreq;
}
int osr = d_samples_per_symbol / d_number_of_bins;
float last_avg = instantaneous_freq[0];
for(unsigned int i = 0; i < d_number_of_bins; i++) {
float avg = 0.0f;
for(unsigned int j = 0; j < osr; j++) {
avg += instantaneous_freq[(osr*i) + j];
}
avg /= osr;
float diff = abs(last_avg - avg);
if(diff > max_if_diff) {
max_if_diff = diff;
max_if_diff_idx = i;
}
last_avg = avg;
}
//std::cout << "!!!" << max_if_diff << std::endl;
return max_if_diff_idx;
}
bool decoder_impl::demodulate(gr_complex* samples, bool is_header) {
unsigned int bin_idx = max_frequency_gradient_idx(samples);
// Header has additional redundancy
if(is_header) {
bin_idx /= 4;
}
// Decode (actually gray encode) the bin to get the symbol value
unsigned int word = gray_encode(bin_idx);
d_debug << bin_idx << " " << to_bin(word, is_header ? 5 : 7) << std::endl;
d_words.push_back(word);
// Look for 4+cr symbols and stop
if(d_words.size() == (4 + d_cr)) {
// Deinterleave
if(is_header) {
//print_vector(d_words, "M", d_sf - 2);
deinterleave(d_sf - 2);
} else {
//print_vector(d_words, "M", d_sf);
deinterleave(d_sf);
}
return true; // Signal that a block is ready for decoding
}
return false; // We need more words in order to decode a block
}
void decoder_impl::deinterleave(int ppm) {
unsigned int bits_per_word = d_words.size();
if(bits_per_word > 8) { // Not sure if this can ever occur. It would imply coding rate high than 4/8 e.g. 4/9.
std::cout << "More than 8 bits per word. uint8_t will not be sufficient! Bytes need to be stored in intermediate array and then packed into words_deinterleaved!" << std::endl;
}
unsigned int offset_start = ppm-1;
std::vector<uint8_t> words_deinterleaved;
for(unsigned int i = 0; i < ppm; i++) {
uint8_t d = 0;
unsigned int offset_diag = offset_start;
for(unsigned int j = 0; j < bits_per_word; j++) {
uint8_t power = pow(2, j);
unsigned int power_check = pow(2, offset_diag); // TODO: Here we are actually reversing endianess. This needs to be fixed in the future by implementing the interleaving similarly to how it is done in the Python based decoder.
if((d_words[j] & power_check) > 0) { // Mask triggers
d += power;
}
if(offset_diag == 0)
offset_diag = ppm-1;
else
offset_diag -= 1;
}
offset_start -= 1;
words_deinterleaved.push_back(d);
}
//print_vector(words_deinterleaved, "D", sizeof(uint8_t)*8);
std::reverse(words_deinterleaved.begin(),words_deinterleaved.end());
// Add to demodulated data
for(int i = 0; i < words_deinterleaved.size(); i++) {
d_demodulated.push_back(words_deinterleaved[i]);
}
// Cleanup
d_words.clear();
}
int decoder_impl::decode(uint8_t* out_data, bool is_header) {
const uint8_t* prng = NULL;
const uint8_t shuffle_pattern[] = {7, 6, 3, 4, 2, 1, 0, 5};
if(is_header) {
prng = prng_header;
} else {
prng = prng_payload;
}
deshuffle(shuffle_pattern);
dewhiten(prng);
hamming_decode(out_data);
// Nibbles are reversed
nibble_reverse(out_data, d_payload_length);
// Print result
std::stringstream result;
for (int i = 0; i < d_payload_length; i++) {
result << " " << std::hex << std::setw(2) << std::setfill('0') << (int)out_data[i];
}
if(!is_header)
std::cout << result.str() << std::endl;
return 0;
}
void decoder_impl::deshuffle(const uint8_t* shuffle_pattern) {
for(int i = 0; i < d_demodulated.size(); i++) {
uint8_t original = d_demodulated[i];
uint8_t result = 0;
for(int j = 0; j < sizeof(shuffle_pattern) / sizeof(uint8_t); j++) {
uint8_t mask = pow(2, shuffle_pattern[j]);
if((original & mask) > 0) {
result += pow(2, j);
}
}
d_words_deshuffled.push_back(result);
}
//print_vector(d_words_deshuffled, "S", sizeof(uint8_t)*8);
// We're done with these words
d_demodulated.clear();
}
void decoder_impl::dewhiten(const uint8_t* prng) {
for(int i = 0; i < d_words_deshuffled.size(); i++) {
uint8_t xor_b = d_words_deshuffled[i] ^ prng[i];
xor_b = (xor_b & 0xF0) >> 4 | (xor_b & 0x0F) << 4; // TODO: reverse bit order is performed here, but is probably due to mistake in interleaving
xor_b = (xor_b & 0xCC) >> 2 | (xor_b & 0x33) << 2;
xor_b = (xor_b & 0xAA) >> 1 | (xor_b & 0x55) << 1;
d_words_dewhitened.push_back(xor_b);
}
//print_vector(d_words_dewhitened, "W", sizeof(uint8_t)*8);
d_words_deshuffled.clear();
}
void decoder_impl::hamming_decode(uint8_t* out_data) {
unsigned int n = ceil(d_words_dewhitened.size() * 4.0 / 8.0);
fec_scheme fs = LIQUID_FEC_HAMMING84;
unsigned int k = fec_get_enc_msg_length(fs, n);
fec hamming = fec_create(fs, NULL);
fec_decode(hamming, n, &d_words_dewhitened[0], out_data);
d_words_dewhitened.clear();
fec_destroy(hamming);
}
void decoder_impl::nibble_reverse(uint8_t* out_data, int len) {
for(int i = 0; i < len; i++) {
out_data[i] = ((out_data[i] & 0x0f) << 4) | ((out_data[i] & 0xf0) >> 4);
}
}
int decoder_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items) {
gr_complex * input = (gr_complex*) input_items[0];
float *out = (float*)output_items[0];
switch(d_state) {
case DETECT: {
if(calc_energy_threshold(input, noutput_items, 0.0002)) {
d_debug << "Got something\n";
// Attempt to synchronize to an upchirp of the preamble
int chirp_start_pos = -1;
for(int i = 0; i < CORRELATION_SEARCH_RANGE; i++) {
int c = sync_fft(&input[i]);
if(c == 0) {
chirp_start_pos = i;
d_debug << "DETECT: " << i << std::endl;
samples_to_file("/tmp/detect", &input[chirp_start_pos + d_finetune], CORRELATION_SEARCH_RANGE, sizeof(gr_complex));
break;
}
}
if(chirp_start_pos != -1) {
d_state = SYNC;
d_corr_fails = 0;
consume_each(chirp_start_pos + d_finetune);
} else {
consume_each(noutput_items);
}
} else {
consume_each(noutput_items);
}
break;
}
case SYNC: {
double c = freq_cross_correlate(&input[0], &d_downchirp[0], CORRELATION_SEARCH_RANGE);
d_debug << "C: " << c << std::endl;
if(c > 0.045f) {
d_debug << "SYNC: " << c << std::endl;
// Debug stuff
samples_to_file("/tmp/sync", &input[0], CORRELATION_SEARCH_RANGE, sizeof(gr_complex));
d_state = PAUSE;
consume_each(d_samples_per_symbol);
} else {
d_corr_fails++;
if(d_corr_fails > 32) {
d_state = DETECT;
}
consume_each(d_samples_per_symbol);
}
break;
}
case PAUSE: {
d_state = DECODE_HEADER;
samples_debug(input, d_samples_per_symbol + DELAY_AFTER_SYNC);
consume_each(d_samples_per_symbol + DELAY_AFTER_SYNC);
break;
}
case DECODE_HEADER: {
if(demodulate(input, true)) {
uint8_t decoded[3];
d_payload_length = 3; // TODO: A bit messy. I think it's better to make an internal decoded std::vector
decode(decoded, true);
nibble_reverse(decoded, 1); // TODO: Why?
d_payload_length = decoded[0];
d_cr = 4; // TODO: Get from header instead of hardcode
int symbols_per_block = d_cr + 4;
int bits_needed = ((d_payload_length * 8) + 16) * (symbols_per_block / 4);
float symbols_needed = float(bits_needed) / float(d_sf);
int blocks_needed = ceil(symbols_needed / symbols_per_block);
d_payload_symbols = blocks_needed * symbols_per_block;
d_debug << "LEN: " << d_payload_length << " (" << d_payload_symbols << " symbols)" << std::endl;
d_state = DECODE_PAYLOAD;
}
samples_debug(input, d_samples_per_symbol);
consume_each(d_samples_per_symbol);
break;
}
case DECODE_PAYLOAD: {
if(demodulate(input, false)) {
d_payload_symbols -= (4 + d_cr);
if(d_payload_symbols <= 0) {
uint8_t decoded[d_payload_length];
decode(decoded, false);
d_state = DETECT;
}
}
samples_debug(input, d_samples_per_symbol);
consume_each(d_samples_per_symbol);
break;
}
case STOP: {
consume_each(d_samples_per_symbol);
break;
}
default: {
std::cout << "Shouldn't happen\n";
break;
}
}
// Tell runtime system how many output items we produced.
return 0;
}
void decoder_impl::set_finetune(int32_t finetune) {
d_finetune = finetune;
}
} /* namespace lora */
} /* namespace gr */

107
lib/decoder_impl.h 100644
Wyświetl plik

@ -0,0 +1,107 @@
/* -*- c++ -*- */
/*
* 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.
*/
#ifndef INCLUDED_LORA_DECODER_IMPL_H
#define INCLUDED_LORA_DECODER_IMPL_H
#include <lora/decoder.h>
#include <list>
#include <string>
#include <vector>
#include <fstream>
namespace gr {
namespace lora {
typedef enum decoder_state {
DETECT,
SYNC,
PAUSE,
DECODE_HEADER,
DECODE_PAYLOAD,
STOP
} decoder_state;
class decoder_impl : public decoder
{
private:
decoder_state d_state;
std::vector<gr_complex> d_downchirp;
std::vector<gr_complex> d_downchirp_fft;
std::vector<gr_complex> d_fft;
std::vector<gr_complex> d_mult;
int32_t d_finetune;
uint8_t d_sf;
uint32_t d_bw;
uint8_t d_cr;
double d_bits_per_second;
uint32_t d_samples_per_second;
double d_symbols_per_second;
uint32_t d_bits_per_symbol;
uint32_t d_samples_per_symbol;
uint32_t d_number_of_bins;
uint32_t d_number_of_bins_hdr;
uint32_t d_compression;
uint32_t d_payload_symbols;
uint32_t d_payload_length;
uint32_t d_corr_fails;
std::vector<unsigned int> d_words;
std::vector<uint8_t> d_demodulated;
std::vector<uint8_t> d_words_deshuffled;
std::vector<uint8_t> d_words_dewhitened;
std::vector<uint8_t> d_data;
std::ofstream d_debug_samples;
std::ofstream d_debug;
fftplan d_q;
bool calc_energy_threshold(gr_complex* samples, int window_size, float threshold);
void build_ideal_downchirp(void);
void samples_to_file(const std::string path, const gr_complex* v, int length, int elem_size);
void samples_debug(const gr_complex* v, int length);
double freq_cross_correlate(const gr_complex *samples_1, const gr_complex *samples_2, int window);
int sync_fft(const gr_complex* samples);
unsigned int max_frequency_gradient_idx(gr_complex* samples);
bool demodulate(gr_complex* samples, bool is_header);
void deinterleave(int ppm);
int decode(uint8_t* out_data, bool is_header);
void deshuffle(const uint8_t* shuffle_pattern);
void dewhiten(const uint8_t* prng);
void hamming_decode(uint8_t* out_data);
void nibble_reverse(uint8_t* out_data, int len);
inline void phase(gr_complex* in_samples, float* out_phase, int window);
public:
decoder_impl(int finetune);
~decoder_impl();
// Where all the action really happens
int work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
// GRC interfaces
virtual void set_finetune(int32_t finetune);
};
} // namespace lora
} // namespace gr
#endif /* INCLUDED_LORA_DECODER_IMPL_H */

16
lib/tables.h 100644
Wyświetl plik

@ -0,0 +1,16 @@
#ifndef TABLES_H
#define TABLES_H
namespace gr {
namespace lora {
const uint8_t prng_header[] = {
0x22, 0x11, 0x0, 0x0, 0x0
};
const uint8_t prng_payload[] = {
0xdf, 0xef, 0xb0, 0xf7, 0x9e, 0xfd, 0xc6, 0xdf, 0x10, 0xfb, 0x43, 0x34, 0xa8, 0x5f, 0xf2, 0x97, 0x62, 0x8, 0xf8, 0x49, 0xbe, 0x8a, 0xa4, 0xd6, 0x16, 0xe6, 0x85, 0x39, 0x6b, 0xef, 0xe5, 0xbc, 0xb3, 0x1c, 0x14, 0xa7, 0x3d, 0x4f, 0x91, 0x61, 0x85, 0x72, 0x20, 0x45, 0x4, 0x25, 0x80, 0x1b, 0x41, 0xa7, 0x5b, 0x4, 0xa2, 0x80, 0x9b, 0x41, 0xa7, 0x10, 0x4f, 0x43, 0x61, 0xa8, 0x39, 0xb9, 0xa4, 0x83, 0x16, 0xcb, 0x85, 0xa0, 0x6b, 0x68, 0xae, 0xbc, 0x19, 0x1c, 0x8d, 0xa7, 0xba, 0x4f, 0xda, 0x2a, 0x64, 0xd8, 0x58, 0xdc, 0xb0, 0xa2, 0x9e, 0xd0, 0xc6, 0x46, 0x10, 0x7c, 0x8, 0x34, 0x2, 0x5f, 0x6b, 0x97, 0xe5, 0x8, 0xb3, 0x2, 0x5f, 0x20, 0xdc, 0x4f, 0xa2, 0x61, 0x9b, 0x72, 0xec, 0xe, 0xae, 0xc4, 0x19, 0xa8, 0x8d, 0xb9, 0xf1, 0xc8, 0x3b, 0x2a, 0x57, 0xd8, 0x46, 0xdc, 0x7c, 0xe9, 0x34, 0x31, 0x5f, 0x75, 0xdc, 0x62, 0xa2, 0xf8, 0x9b, 0xf5, 0xa7, 0xe, 0x4, 0xc0, 0x80, 0xa8, 0xa, 0xb9, 0xba, 0xa3, 0xda, 0x80, 0x2f, 0x43, 0xf2, 0x79, 0x62, 0xa2, 0xb3, 0xd0, 0x14, 0xd, 0x76, 0x96, 0x2b, 0xee, 0xd7, 0x72, 0xd, 0x44, 0x96, 0x7e, 0xee, 0xb1, 0x70, 0x77, 0x2f, 0x39, 0xc0, 0x52, 0x28, 0x27, 0xb0, 0x3, 0x73, 0x16, 0xbf, 0xce, 0xdf, 0xc9, 0xb7, 0xd6, 0x18, 0xe6, 0xcd, 0x7a, 0x43, 0x4f, 0x7c, 0xbf, 0x7b, 0xa, 0xbe, 0x6b, 0xc5, 0xe5, 0x5d, 0xe4, 0xe4, 0xbc, 0x5b, 0xce, 0xd1, 0xa8, 0xe6, 0x57, 0x3b, 0x4, 0xcf, 0xa6, 0xbc, 0xd9, 0x57, 0x27, 0x45, 0x69, 0xe6, 0xf7, 0xe2, 0x36, 0x3b, 0x77, 0xe5, 0x89, 0x5d, 0x46, 0x2f, 0x2f, 0x79, 0x49, 0x83, 0xb8, 0xdb, 0x5f, 0xe9, 0x5, 0x88, 0x1d, 0x9b, 0x7, 0x2, 0x8, 0x2b, 0x99, 0xf5, 0x91, 0xbb, 0x85, 0x90, 0x60, 0x76, 0x7f, 0x3a, 0x61, 0x1c, 0x7c, 0xee, 0xc7, 0x5f, 0x6a, 0x41, 0x31, 0x39, 0xfe, 0xcf, 0x82, 0xb8, 0xdb, 0x14, 0xa2, 0xac, 0x68, 0xd5, 0xf6, 0xfc, 0x3e, 0xf7, 0x7e, 0x2c, 0xd8, 0xc4, 0x6d, 0xe2, 0xb9, 0x12, 0xa4, 0x3a, 0x2, 0x7, 0x4e, 0x40, 0x2, 0xba, 0x7, 0xde, 0x9e, 0x6c, 0xc6, 0x52, 0x79, 0x51, 0xb2, 0xad, 0x5c, 0xd8, 0x6, 0xdc, 0x27, 0x83, 0xd5, 0x1f, 0x66, 0xf6, 0x89, 0x4f, 0xc4, 0x26, 0x88, 0x11, 0xb8, 0x3d, 0xa3, 0x95, 0xdb, 0x6, 0xe9, 0xc9, 0xe2, 0xd6, 0x35, 0xa9, 0x13, 0x93, 0xad, 0x1d, 0xae, 0x93, 0x42, 0x4e, 0x60, 0xc1, 0x83, 0x6c, 0x1, 0x3c, 0x9b, 0x96, 0xad, 0x76, 0xc5, 0x70, 0xe0, 0xb6, 0x73, 0x36, 0x45, 0x72, 0x4a, 0xb3, 0x7a, 0x57, 0xd7, 0xfc, 0x51, 0xf9, 0xe6, 0xfe, 0x7a, 0x9e, 0xe, 0xb0, 0xf4, 0xd9, 0xe3, 0xa5, 0x58, 0x28, 0xcb, 0xf2, 0x3c, 0xfd, 0x96, 0x9f, 0x77, 0x80, 0x70, 0xd5, 0x79, 0x66, 0x9e, 0x83, 0xeb, 0xe0, 0x34, 0xe3, 0x94, 0x53, 0x1e, 0xa, 0x91, 0x44, 0xca, 0x20, 0x0, 0x23, 0x17, 0x4d, 0x92, 0x2f, 0x8f, 0x32, 0xd1, 0x28, 0x3f, 0x9, 0x5f, 0xc4, 0x4d, 0x5a, 0xc6, 0xe9, 0x8d, 0xbd, 0xda, 0x3e, 0xbd, 0x92, 0x47, 0xc0, 0x63, 0x41, 0x53, 0x78, 0xa, 0xe9, 0x8f, 0x7e, 0x41, 0x96, 0x30, 0x41, 0x6, 0xad, 0x6b, 0x93, 0x18, 0x1d, 0xb1, 0x4e, 0xd5, 0x2f, 0x66, 0xf2, 0x82, 0x72, 0x1, 0xf1, 0xd0, 0x3c, 0xc, 0xce, 0x84, 0xb8, 0xe6, 0x9c, 0x31, 0xed, 0x8f, 0xac, 0xf3, 0x4a, 0xb6, 0xec, 0x3c, 0xa9, 0xd9, 0xcb, 0x2a, 0x8a, 0x93, 0x2a, 0x1d, 0x8e, 0x95, 0x9, 0xd, 0x8f, 0x20, 0xf1, 0x3e, 0x74, 0x22, 0xfd, 0x5a, 0xdf, 0xbd, 0xfb, 0xf9, 0x77, 0xfe, 0x43, 0x22, 0x10, 0xc, 0xe1, 0xe6, 0x53, 0x62
};
}
}
#endif /* TABLES_H */

54
lib/utilities.h 100644
Wyświetl plik

@ -0,0 +1,54 @@
#ifndef UTILITIES_H
#define UTILITIES_H
namespace gr {
namespace lora {
template <typename T>
std::string to_bin(T v, int element_len_bits) {
T mask = 0;
unsigned int maxpow = element_len_bits;
std::string result = "";
for(int i = 0; i < maxpow; i++) {
mask = pow(2, i);
//std::cout << (unsigned int)v << " AND " << mask << " is " << (v & mask) << std::endl;
if((v & mask) > 0) {
result += "1";
} else {
result += "0";
}
}
return result;
}
template <typename T>
inline void print_vector(std::vector<T>& v, std::string prefix, int element_len_bits) {
std::cout << prefix << ": ";
for(int i = 0; i < v.size(); i++) {
std::cout << to_bin(v[i], element_len_bits) << ", ";
}
std::cout << std::endl << std::flush;
}
bool check_parity(std::string word, bool even) {
int count = 0;
for(int i = 0; i < 7; i++) {
if(word[i] == '1')
count += 1;
}
if(even)
return ((count % 2) == 0);
else
return (((count+1) % 2) == 0);
}
}
}
#endif /* UTILITIES_H */

Wyświetl plik

@ -42,3 +42,4 @@ include(GrTest)
set(GR_TEST_TARGET_DEPS gnuradio-lora)
set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig)
GR_ADD_TEST(qa_receiver ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_receiver.py)

Wyświetl plik

@ -217,9 +217,13 @@ def shuffled_hamming(coded, prng):
for bit in bit_order:
deshuffle += coded[bit]
printd("S: " + str(deshuffle))
# Dewhiten
dewhiten = xor_byte(deshuffle, prng)
printd("W: " + str(dewhiten))
# Decode
decode, error = hamming_decode(dewhiten[:-1], powers_of_two_pos=[0, 1, 3], even=True)
@ -415,6 +419,9 @@ class lora_decoder(gr.basic_block):
self.demodulated = ""
self.state = LoRaState.FIND_SYNC
def calc_energy(self, samples):
return numpy.sum(numpy.square(numpy.abs(samples)))
def general_work(self, input_items, output_items):
in0 = input_items[0]
in1 = input_items[1]
@ -423,6 +430,8 @@ class lora_decoder(gr.basic_block):
num_output_items = len(output_items[0])
if self.state == LoRaState.FIND_SYNC:
#if self.calc_energy(in1[0:32]) > 0.08:
# print("Found packet")
smooth_function = numpy.convolve(signal.gaussian(32, std=12), in0, mode='same') / 32.0
for i in range(0, num_output_items):
out[i] = len(self.sync_buffer) / 10

Wyświetl plik

@ -24,35 +24,58 @@ from lora_decoder import lora_decoder
from gnuradio.filter import freq_xlating_fir_filter_ccf, firdes, fractional_resampler_cc
from gnuradio.analog import quadrature_demod_cf
from gnuradio.blocks import null_sink
import lora
class lora_receiver(gr.hier_block2):
"""
docstring for block lora_receiver
"""
def __init__(self, in_samp_rate, freq, offset):
def __init__(self, in_samp_rate, freq, offset, finetune, realtime):
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
# Parameters
self.finetune = finetune
self.offset = offset
self.in_samp_rate = in_samp_rate
self.realtime = realtime
bw = 125000
# Define blocks
null1 = null_sink(gr.sizeof_float)
null2 = null_sink(gr.sizeof_float)
if realtime:
self.c_decoder = lora.decoder(finetune)
out_samp_rate = 1000000
decimation = 1
else:
decoder = lora_decoder()
out_samp_rate = 10000000
bw = 125000
lpf = firdes.low_pass(1, out_samp_rate, bw, 10000, firdes.WIN_HAMMING, 6.67)
decimation = 10
lpf = firdes.low_pass(1, out_samp_rate, bw, 10000, firdes.WIN_HAMMING, 6.67)
qdemod = quadrature_demod_cf(1.0)
channelizer = freq_xlating_fir_filter_ccf(10, lpf, offset, out_samp_rate)
channelizer = freq_xlating_fir_filter_ccf(decimation, lpf, offset, out_samp_rate)
resampler = fractional_resampler_cc(0, in_samp_rate / float(out_samp_rate))
# Connect blocks
self.connect((self, 0), (resampler, 0))
self.connect((resampler, 0), (channelizer, 0))
if realtime:
self.connect((channelizer, 0), (self.c_decoder, 0))
else:
self.connect((channelizer, 0), (qdemod, 0))
self.connect((channelizer, 0), (decoder, 1))
self.connect((qdemod, 0), (decoder, 0))
self.connect((decoder, 0), (null1, 0))
self.connect((decoder, 1), (null2, 0))
def get_finetune(self):
return self.finetune
def set_finetune(self, finetune):
self.finetune = finetune
if self.realtime:
self.c_decoder.set_finetune(self.finetune)

Wyświetl plik

@ -0,0 +1,698 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# GNU GENERAL PUBLIC LICENSE
# Version 3, 29 June 2007
#
# Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
#
# Preamble
#
# The GNU General Public License is a free, copyleft license for
# software and other kinds of works.
#
# The licenses for most software and other practical works are designed
# to take away your freedom to share and change the works. By contrast,
# the GNU General Public License is intended to guarantee your freedom to
# share and change all versions of a program--to make sure it remains free
# software for all its users. We, the Free Software Foundation, use the
# GNU General Public License for most of our software; it applies also to
# any other work released this way by its authors. You can apply it to
# your programs, too.
#
# When we speak of free software, we are referring to freedom, not
# price. Our General Public Licenses are designed to make sure that you
# have the freedom to distribute copies of free software (and charge for
# them if you wish), that you receive source code or can get it if you
# want it, that you can change the software or use pieces of it in new
# free programs, and that you know you can do these things.
#
# To protect your rights, we need to prevent others from denying you
# these rights or asking you to surrender the rights. Therefore, you have
# certain responsibilities if you distribute copies of the software, or if
# you modify it: responsibilities to respect the freedom of others.
#
# For example, if you distribute copies of such a program, whether
# gratis or for a fee, you must pass on to the recipients the same
# freedoms that you received. You must make sure that they, too, receive
# or can get the source code. And you must show them these terms so they
# know their rights.
#
# Developers that use the GNU GPL protect your rights with two steps:
# (1) assert copyright on the software, and (2) offer you this License
# giving you legal permission to copy, distribute and/or modify it.
#
# For the developers' and authors' protection, the GPL clearly explains
# that there is no warranty for this free software. For both users' and
# authors' sake, the GPL requires that modified versions be marked as
# changed, so that their problems will not be attributed erroneously to
# authors of previous versions.
#
# Some devices are designed to deny users access to install or run
# modified versions of the software inside them, although the manufacturer
# can do so. This is fundamentally incompatible with the aim of
# protecting users' freedom to change the software. The systematic
# pattern of such abuse occurs in the area of products for individuals to
# use, which is precisely where it is most unacceptable. Therefore, we
# have designed this version of the GPL to prohibit the practice for those
# products. If such problems arise substantially in other domains, we
# stand ready to extend this provision to those domains in future versions
# of the GPL, as needed to protect the freedom of users.
#
# Finally, every program is threatened constantly by software patents.
# States should not allow patents to restrict development and use of
# software on general-purpose computers, but in those that do, we wish to
# avoid the special danger that patents applied to a free program could
# make it effectively proprietary. To prevent this, the GPL assures that
# patents cannot be used to render the program non-free.
#
# The precise terms and conditions for copying, distribution and
# modification follow.
#
# TERMS AND CONDITIONS
#
# 0. Definitions.
#
# "This License" refers to version 3 of the GNU General Public License.
#
# "Copyright" also means copyright-like laws that apply to other kinds of
# works, such as semiconductor masks.
#
# "The Program" refers to any copyrightable work licensed under this
# License. Each licensee is addressed as "you". "Licensees" and
# "recipients" may be individuals or organizations.
#
# To "modify" a work means to copy from or adapt all or part of the work
# in a fashion requiring copyright permission, other than the making of an
# exact copy. The resulting work is called a "modified version" of the
# earlier work or a work "based on" the earlier work.
#
# A "covered work" means either the unmodified Program or a work based
# on the Program.
#
# To "propagate" a work means to do anything with it that, without
# permission, would make you directly or secondarily liable for
# infringement under applicable copyright law, except executing it on a
# computer or modifying a private copy. Propagation includes copying,
# distribution (with or without modification), making available to the
# public, and in some countries other activities as well.
#
# To "convey" a work means any kind of propagation that enables other
# parties to make or receive copies. Mere interaction with a user through
# a computer network, with no transfer of a copy, is not conveying.
#
# An interactive user interface displays "Appropriate Legal Notices"
# to the extent that it includes a convenient and prominently visible
# feature that (1) displays an appropriate copyright notice, and (2)
# tells the user that there is no warranty for the work (except to the
# extent that warranties are provided), that licensees may convey the
# work under this License, and how to view a copy of this License. If
# the interface presents a list of user commands or options, such as a
# menu, a prominent item in the list meets this criterion.
#
# 1. Source Code.
#
# The "source code" for a work means the preferred form of the work
# for making modifications to it. "Object code" means any non-source
# form of a work.
#
# A "Standard Interface" means an interface that either is an official
# standard defined by a recognized standards body, or, in the case of
# interfaces specified for a particular programming language, one that
# is widely used among developers working in that language.
#
# The "System Libraries" of an executable work include anything, other
# than the work as a whole, that (a) is included in the normal form of
# packaging a Major Component, but which is not part of that Major
# Component, and (b) serves only to enable use of the work with that
# Major Component, or to implement a Standard Interface for which an
# implementation is available to the public in source code form. A
# "Major Component", in this context, means a major essential component
# (kernel, window system, and so on) of the specific operating system
# (if any) on which the executable work runs, or a compiler used to
# produce the work, or an object code interpreter used to run it.
#
# The "Corresponding Source" for a work in object code form means all
# the source code needed to generate, install, and (for an executable
# work) run the object code and to modify the work, including scripts to
# control those activities. However, it does not include the work's
# System Libraries, or general-purpose tools or generally available free
# programs which are used unmodified in performing those activities but
# which are not part of the work. For example, Corresponding Source
# includes interface definition files associated with source files for
# the work, and the source code for shared libraries and dynamically
# linked subprograms that the work is specifically designed to require,
# such as by intimate data communication or control flow between those
# subprograms and other parts of the work.
#
# The Corresponding Source need not include anything that users
# can regenerate automatically from other parts of the Corresponding
# Source.
#
# The Corresponding Source for a work in source code form is that
# same work.
#
# 2. Basic Permissions.
#
# All rights granted under this License are granted for the term of
# copyright on the Program, and are irrevocable provided the stated
# conditions are met. This License explicitly affirms your unlimited
# permission to run the unmodified Program. The output from running a
# covered work is covered by this License only if the output, given its
# content, constitutes a covered work. This License acknowledges your
# rights of fair use or other equivalent, as provided by copyright law.
#
# You may make, run and propagate covered works that you do not
# convey, without conditions so long as your license otherwise remains
# in force. You may convey covered works to others for the sole purpose
# of having them make modifications exclusively for you, or provide you
# with facilities for running those works, provided that you comply with
# the terms of this License in conveying all material for which you do
# not control copyright. Those thus making or running the covered works
# for you must do so exclusively on your behalf, under your direction
# and control, on terms that prohibit them from making any copies of
# your copyrighted material outside their relationship with you.
#
# Conveying under any other circumstances is permitted solely under
# the conditions stated below. Sublicensing is not allowed; section 10
# makes it unnecessary.
#
# 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
#
# No covered work shall be deemed part of an effective technological
# measure under any applicable law fulfilling obligations under article
# 11 of the WIPO copyright treaty adopted on 20 December 1996, or
# similar laws prohibiting or restricting circumvention of such
# measures.
#
# When you convey a covered work, you waive any legal power to forbid
# circumvention of technological measures to the extent such circumvention
# is effected by exercising rights under this License with respect to
# the covered work, and you disclaim any intention to limit operation or
# modification of the work as a means of enforcing, against the work's
# users, your or third parties' legal rights to forbid circumvention of
# technological measures.
#
# 4. Conveying Verbatim Copies.
#
# You may convey verbatim copies of the Program's source code as you
# receive it, in any medium, provided that you conspicuously and
# appropriately publish on each copy an appropriate copyright notice;
# keep intact all notices stating that this License and any
# non-permissive terms added in accord with section 7 apply to the code;
# keep intact all notices of the absence of any warranty; and give all
# recipients a copy of this License along with the Program.
#
# You may charge any price or no price for each copy that you convey,
# and you may offer support or warranty protection for a fee.
#
# 5. Conveying Modified Source Versions.
#
# You may convey a work based on the Program, or the modifications to
# produce it from the Program, in the form of source code under the
# terms of section 4, provided that you also meet all of these conditions:
#
# a) The work must carry prominent notices stating that you modified
# it, and giving a relevant date.
#
# b) The work must carry prominent notices stating that it is
# released under this License and any conditions added under section
# 7. This requirement modifies the requirement in section 4 to
# "keep intact all notices".
#
# c) You must license the entire work, as a whole, under this
# License to anyone who comes into possession of a copy. This
# License will therefore apply, along with any applicable section 7
# additional terms, to the whole of the work, and all its parts,
# regardless of how they are packaged. This License gives no
# permission to license the work in any other way, but it does not
# invalidate such permission if you have separately received it.
#
# d) If the work has interactive user interfaces, each must display
# Appropriate Legal Notices; however, if the Program has interactive
# interfaces that do not display Appropriate Legal Notices, your
# work need not make them do so.
#
# A compilation of a covered work with other separate and independent
# works, which are not by their nature extensions of the covered work,
# and which are not combined with it such as to form a larger program,
# in or on a volume of a storage or distribution medium, is called an
# "aggregate" if the compilation and its resulting copyright are not
# used to limit the access or legal rights of the compilation's users
# beyond what the individual works permit. Inclusion of a covered work
# in an aggregate does not cause this License to apply to the other
# parts of the aggregate.
#
# 6. Conveying Non-Source Forms.
#
# You may convey a covered work in object code form under the terms
# of sections 4 and 5, provided that you also convey the
# machine-readable Corresponding Source under the terms of this License,
# in one of these ways:
#
# a) Convey the object code in, or embodied in, a physical product
# (including a physical distribution medium), accompanied by the
# Corresponding Source fixed on a durable physical medium
# customarily used for software interchange.
#
# b) Convey the object code in, or embodied in, a physical product
# (including a physical distribution medium), accompanied by a
# written offer, valid for at least three years and valid for as
# long as you offer spare parts or customer support for that product
# model, to give anyone who possesses the object code either (1) a
# copy of the Corresponding Source for all the software in the
# product that is covered by this License, on a durable physical
# medium customarily used for software interchange, for a price no
# more than your reasonable cost of physically performing this
# conveying of source, or (2) access to copy the
# Corresponding Source from a network server at no charge.
#
# c) Convey individual copies of the object code with a copy of the
# written offer to provide the Corresponding Source. This
# alternative is allowed only occasionally and noncommercially, and
# only if you received the object code with such an offer, in accord
# with subsection 6b.
#
# d) Convey the object code by offering access from a designated
# place (gratis or for a charge), and offer equivalent access to the
# Corresponding Source in the same way through the same place at no
# further charge. You need not require recipients to copy the
# Corresponding Source along with the object code. If the place to
# copy the object code is a network server, the Corresponding Source
# may be on a different server (operated by you or a third party)
# that supports equivalent copying facilities, provided you maintain
# clear directions next to the object code saying where to find the
# Corresponding Source. Regardless of what server hosts the
# Corresponding Source, you remain obligated to ensure that it is
# available for as long as needed to satisfy these requirements.
#
# e) Convey the object code using peer-to-peer transmission, provided
# you inform other peers where the object code and Corresponding
# Source of the work are being offered to the general public at no
# charge under subsection 6d.
#
# A separable portion of the object code, whose source code is excluded
# from the Corresponding Source as a System Library, need not be
# included in conveying the object code work.
#
# A "User Product" is either (1) a "consumer product", which means any
# tangible personal property which is normally used for personal, family,
# or household purposes, or (2) anything designed or sold for incorporation
# into a dwelling. In determining whether a product is a consumer product,
# doubtful cases shall be resolved in favor of coverage. For a particular
# product received by a particular user, "normally used" refers to a
# typical or common use of that class of product, regardless of the status
# of the particular user or of the way in which the particular user
# actually uses, or expects or is expected to use, the product. A product
# is a consumer product regardless of whether the product has substantial
# commercial, industrial or non-consumer uses, unless such uses represent
# the only significant mode of use of the product.
#
# "Installation Information" for a User Product means any methods,
# procedures, authorization keys, or other information required to install
# and execute modified versions of a covered work in that User Product from
# a modified version of its Corresponding Source. The information must
# suffice to ensure that the continued functioning of the modified object
# code is in no case prevented or interfered with solely because
# modification has been made.
#
# If you convey an object code work under this section in, or with, or
# specifically for use in, a User Product, and the conveying occurs as
# part of a transaction in which the right of possession and use of the
# User Product is transferred to the recipient in perpetuity or for a
# fixed term (regardless of how the transaction is characterized), the
# Corresponding Source conveyed under this section must be accompanied
# by the Installation Information. But this requirement does not apply
# if neither you nor any third party retains the ability to install
# modified object code on the User Product (for example, the work has
# been installed in ROM).
#
# The requirement to provide Installation Information does not include a
# requirement to continue to provide support service, warranty, or updates
# for a work that has been modified or installed by the recipient, or for
# the User Product in which it has been modified or installed. Access to a
# network may be denied when the modification itself materially and
# adversely affects the operation of the network or violates the rules and
# protocols for communication across the network.
#
# Corresponding Source conveyed, and Installation Information provided,
# in accord with this section must be in a format that is publicly
# documented (and with an implementation available to the public in
# source code form), and must require no special password or key for
# unpacking, reading or copying.
#
# 7. Additional Terms.
#
# "Additional permissions" are terms that supplement the terms of this
# License by making exceptions from one or more of its conditions.
# Additional permissions that are applicable to the entire Program shall
# be treated as though they were included in this License, to the extent
# that they are valid under applicable law. If additional permissions
# apply only to part of the Program, that part may be used separately
# under those permissions, but the entire Program remains governed by
# this License without regard to the additional permissions.
#
# When you convey a copy of a covered work, you may at your option
# remove any additional permissions from that copy, or from any part of
# it. (Additional permissions may be written to require their own
# removal in certain cases when you modify the work.) You may place
# additional permissions on material, added by you to a covered work,
# for which you have or can give appropriate copyright permission.
#
# Notwithstanding any other provision of this License, for material you
# add to a covered work, you may (if authorized by the copyright holders of
# that material) supplement the terms of this License with terms:
#
# a) Disclaiming warranty or limiting liability differently from the
# terms of sections 15 and 16 of this License; or
#
# b) Requiring preservation of specified reasonable legal notices or
# author attributions in that material or in the Appropriate Legal
# Notices displayed by works containing it; or
#
# c) Prohibiting misrepresentation of the origin of that material, or
# requiring that modified versions of such material be marked in
# reasonable ways as different from the original version; or
#
# d) Limiting the use for publicity purposes of names of licensors or
# authors of the material; or
#
# e) Declining to grant rights under trademark law for use of some
# trade names, trademarks, or service marks; or
#
# f) Requiring indemnification of licensors and authors of that
# material by anyone who conveys the material (or modified versions of
# it) with contractual assumptions of liability to the recipient, for
# any liability that these contractual assumptions directly impose on
# those licensors and authors.
#
# All other non-permissive additional terms are considered "further
# restrictions" within the meaning of section 10. If the Program as you
# received it, or any part of it, contains a notice stating that it is
# governed by this License along with a term that is a further
# restriction, you may remove that term. If a license document contains
# a further restriction but permits relicensing or conveying under this
# License, you may add to a covered work material governed by the terms
# of that license document, provided that the further restriction does
# not survive such relicensing or conveying.
#
# If you add terms to a covered work in accord with this section, you
# must place, in the relevant source files, a statement of the
# additional terms that apply to those files, or a notice indicating
# where to find the applicable terms.
#
# Additional terms, permissive or non-permissive, may be stated in the
# form of a separately written license, or stated as exceptions;
# the above requirements apply either way.
#
# 8. Termination.
#
# You may not propagate or modify a covered work except as expressly
# provided under this License. Any attempt otherwise to propagate or
# modify it is void, and will automatically terminate your rights under
# this License (including any patent licenses granted under the third
# paragraph of section 11).
#
# However, if you cease all violation of this License, then your
# license from a particular copyright holder is reinstated (a)
# provisionally, unless and until the copyright holder explicitly and
# finally terminates your license, and (b) permanently, if the copyright
# holder fails to notify you of the violation by some reasonable means
# prior to 60 days after the cessation.
#
# Moreover, your license from a particular copyright holder is
# reinstated permanently if the copyright holder notifies you of the
# violation by some reasonable means, this is the first time you have
# received notice of violation of this License (for any work) from that
# copyright holder, and you cure the violation prior to 30 days after
# your receipt of the notice.
#
# Termination of your rights under this section does not terminate the
# licenses of parties who have received copies or rights from you under
# this License. If your rights have been terminated and not permanently
# reinstated, you do not qualify to receive new licenses for the same
# material under section 10.
#
# 9. Acceptance Not Required for Having Copies.
#
# You are not required to accept this License in order to receive or
# run a copy of the Program. Ancillary propagation of a covered work
# occurring solely as a consequence of using peer-to-peer transmission
# to receive a copy likewise does not require acceptance. However,
# nothing other than this License grants you permission to propagate or
# modify any covered work. These actions infringe copyright if you do
# not accept this License. Therefore, by modifying or propagating a
# covered work, you indicate your acceptance of this License to do so.
#
# 10. Automatic Licensing of Downstream Recipients.
#
# Each time you convey a covered work, the recipient automatically
# receives a license from the original licensors, to run, modify and
# propagate that work, subject to this License. You are not responsible
# for enforcing compliance by third parties with this License.
#
# An "entity transaction" is a transaction transferring control of an
# organization, or substantially all assets of one, or subdividing an
# organization, or merging organizations. If propagation of a covered
# work results from an entity transaction, each party to that
# transaction who receives a copy of the work also receives whatever
# licenses to the work the party's predecessor in interest had or could
# give under the previous paragraph, plus a right to possession of the
# Corresponding Source of the work from the predecessor in interest, if
# the predecessor has it or can get it with reasonable efforts.
#
# You may not impose any further restrictions on the exercise of the
# rights granted or affirmed under this License. For example, you may
# not impose a license fee, royalty, or other charge for exercise of
# rights granted under this License, and you may not initiate litigation
# (including a cross-claim or counterclaim in a lawsuit) alleging that
# any patent claim is infringed by making, using, selling, offering for
# sale, or importing the Program or any portion of it.
#
# 11. Patents.
#
# A "contributor" is a copyright holder who authorizes use under this
# License of the Program or a work on which the Program is based. The
# work thus licensed is called the contributor's "contributor version".
#
# A contributor's "essential patent claims" are all patent claims
# owned or controlled by the contributor, whether already acquired or
# hereafter acquired, that would be infringed by some manner, permitted
# by this License, of making, using, or selling its contributor version,
# but do not include claims that would be infringed only as a
# consequence of further modification of the contributor version. For
# purposes of this definition, "control" includes the right to grant
# patent sublicenses in a manner consistent with the requirements of
# this License.
#
# Each contributor grants you a non-exclusive, worldwide, royalty-free
# patent license under the contributor's essential patent claims, to
# make, use, sell, offer for sale, import and otherwise run, modify and
# propagate the contents of its contributor version.
#
# In the following three paragraphs, a "patent license" is any express
# agreement or commitment, however denominated, not to enforce a patent
# (such as an express permission to practice a patent or covenant not to
# sue for patent infringement). To "grant" such a patent license to a
# party means to make such an agreement or commitment not to enforce a
# patent against the party.
#
# If you convey a covered work, knowingly relying on a patent license,
# and the Corresponding Source of the work is not available for anyone
# to copy, free of charge and under the terms of this License, through a
# publicly available network server or other readily accessible means,
# then you must either (1) cause the Corresponding Source to be so
# available, or (2) arrange to deprive yourself of the benefit of the
# patent license for this particular work, or (3) arrange, in a manner
# consistent with the requirements of this License, to extend the patent
# license to downstream recipients. "Knowingly relying" means you have
# actual knowledge that, but for the patent license, your conveying the
# covered work in a country, or your recipient's use of the covered work
# in a country, would infringe one or more identifiable patents in that
# country that you have reason to believe are valid.
#
# If, pursuant to or in connection with a single transaction or
# arrangement, you convey, or propagate by procuring conveyance of, a
# covered work, and grant a patent license to some of the parties
# receiving the covered work authorizing them to use, propagate, modify
# or convey a specific copy of the covered work, then the patent license
# you grant is automatically extended to all recipients of the covered
# work and works based on it.
#
# A patent license is "discriminatory" if it does not include within
# the scope of its coverage, prohibits the exercise of, or is
# conditioned on the non-exercise of one or more of the rights that are
# specifically granted under this License. You may not convey a covered
# work if you are a party to an arrangement with a third party that is
# in the business of distributing software, under which you make payment
# to the third party based on the extent of your activity of conveying
# the work, and under which the third party grants, to any of the
# parties who would receive the covered work from you, a discriminatory
# patent license (a) in connection with copies of the covered work
# conveyed by you (or copies made from those copies), or (b) primarily
# for and in connection with specific products or compilations that
# contain the covered work, unless you entered into that arrangement,
# or that patent license was granted, prior to 28 March 2007.
#
# Nothing in this License shall be construed as excluding or limiting
# any implied license or other defenses to infringement that may
# otherwise be available to you under applicable patent law.
#
# 12. No Surrender of Others' Freedom.
#
# If conditions are imposed on you (whether by court order, agreement or
# otherwise) that contradict the conditions of this License, they do not
# excuse you from the conditions of this License. If you cannot convey a
# covered work so as to satisfy simultaneously your obligations under this
# License and any other pertinent obligations, then as a consequence you may
# not convey it at all. For example, if you agree to terms that obligate you
# to collect a royalty for further conveying from those to whom you convey
# the Program, the only way you could satisfy both those terms and this
# License would be to refrain entirely from conveying the Program.
#
# 13. Use with the GNU Affero General Public License.
#
# Notwithstanding any other provision of this License, you have
# permission to link or combine any covered work with a work licensed
# under version 3 of the GNU Affero General Public License into a single
# combined work, and to convey the resulting work. The terms of this
# License will continue to apply to the part which is the covered work,
# but the special requirements of the GNU Affero General Public License,
# section 13, concerning interaction through a network will apply to the
# combination as such.
#
# 14. Revised Versions of this License.
#
# The Free Software Foundation may publish revised and/or new versions of
# the GNU General Public License from time to time. Such new versions will
# be similar in spirit to the present version, but may differ in detail to
# address new problems or concerns.
#
# Each version is given a distinguishing version number. If the
# Program specifies that a certain numbered version of the GNU General
# Public License "or any later version" applies to it, you have the
# option of following the terms and conditions either of that numbered
# version or of any later version published by the Free Software
# Foundation. If the Program does not specify a version number of the
# GNU General Public License, you may choose any version ever published
# by the Free Software Foundation.
#
# If the Program specifies that a proxy can decide which future
# versions of the GNU General Public License can be used, that proxy's
# public statement of acceptance of a version permanently authorizes you
# to choose that version for the Program.
#
# Later license versions may give you additional or different
# permissions. However, no additional obligations are imposed on any
# author or copyright holder as a result of your choosing to follow a
# later version.
#
# 15. Disclaimer of Warranty.
#
# THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
# APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
# HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
# OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
# IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
# ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
#
# 16. Limitation of Liability.
#
# IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
# WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
# THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
# GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
# USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
# DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
# PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
# EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGES.
#
# 17. Interpretation of Sections 15 and 16.
#
# If the disclaimer of warranty and limitation of liability provided
# above cannot be given local legal effect according to their terms,
# reviewing courts shall apply local law that most closely approximates
# an absolute waiver of all civil liability in connection with the
# Program, unless a warranty or assumption of liability accompanies a
# copy of the Program in return for a fee.
#
# END OF TERMS AND CONDITIONS
#
# How to Apply These Terms to Your New Programs
#
# If you develop a new program, and you want it to be of the greatest
# possible use to the public, the best way to achieve this is to make it
# free software which everyone can redistribute and change under these terms.
#
# To do so, attach the following notices to the program. It is safest
# to attach them to the start of each source file to most effectively
# state the exclusion of warranty; and each file should have at least
# the "copyright" line and a pointer to where the full notice is found.
#
# {one line to give the program's name and a brief idea of what it does.}
# Copyright (C) {year} {name of author}
#
# This program 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 of the License, or
# (at your option) any later version.
#
# This program 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 program. If not, see <http://www.gnu.org/licenses/>.
#
# Also add information on how to contact you by electronic and paper mail.
#
# If the program does terminal interaction, make it output a short
# notice like this when it starts in an interactive mode:
#
# {project} Copyright (C) {year} {fullname}
# This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
# This is free software, and you are welcome to redistribute it
# under certain conditions; type `show c' for details.
#
# The hypothetical commands `show w' and `show c' should show the appropriate
# parts of the General Public License. Of course, your program's commands
# might be different; for a GUI interface, you would use an "about box".
#
# You should also get your employer (if you work as a programmer) or school,
# if any, to sign a "copyright disclaimer" for the program, if necessary.
# For more information on this, and how to apply and follow the GNU GPL, see
# <http://www.gnu.org/licenses/>.
#
# The GNU General Public License does not permit incorporating your program
# into proprietary programs. If your program is a subroutine library, you
# may consider it more useful to permit linking proprietary applications with
# the library. If this is what you want to do, use the GNU Lesser General
# Public License instead of this License. But first, please read
# <http://www.gnu.org/philosophy/why-not-lgpl.html>.
#
from gnuradio import gr, gr_unittest
from gnuradio import blocks
import lora_swig as lora
class qa_receiver (gr_unittest.TestCase):
def setUp (self):
self.tb = gr.top_block ()
def tearDown (self):
self.tb = None
def test_001_t (self):
# set up fg
self.tb.run ()
# check data
if __name__ == '__main__':
gr_unittest.run(qa_receiver, "qa_receiver.xml")

Wyświetl plik

@ -8,6 +8,9 @@
%include "lora_swig_doc.i"
%{
#include "lora/decoder.h"
%}
%include "lora/decoder.h"
GR_SWIG_BLOCK_MAGIC2(lora, decoder);