Skip to content

Commit

Permalink
Only require 8 preamble bits instead of 20
Browse files Browse the repository at this point in the history
This matches the behaviour of a real receiver.
  • Loading branch information
argilo committed Jan 16, 2024
1 parent f98c322 commit b6fb676
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 50 deletions.
28 changes: 14 additions & 14 deletions secplus_rx.grc
Original file line number Diff line number Diff line change
Expand Up @@ -749,19 +749,19 @@ blocks:
\ if rising else 1)\n self.buffer.append(0 if rising else 1)\n \
\ else:\n self.buffer = []\n\n def process_buffer(self, current_sample):\n\
\ manchester = \"\".join(str(b) for b in self.buffer)\n start\
\ = manchester.find(\"1010101010101010101010101010101001010101\")\n if\
\ start == -1:\n return\n\n if manchester[start+44:start+48]\
\ == \"1010\":\n packet_length = 40\n elif manchester[start+44:start+48]\
\ == \"1001\":\n packet_length = 64\n else:\n return\n\
\n manchester = manchester[start:start+44+(packet_length*2)]\n \
\ baseband = []\n for i in range(0, len(manchester), 2):\n \
\ if manchester[i:i+2] == \"01\":\n baseband.append(1)\n \
\ elif manchester[i:i+2] == \"10\":\n baseband.append(0)\n\
\ else:\n return\n packet = baseband[22:]\n\
\n if baseband[20:22] == [0, 0]:\n frame_id = 0\n elif\
\ baseband[20:22] == [0, 1]:\n frame_id = 1\n else:\n \
\ return\n\n self.pair_time[frame_id] = current_sample\n\n \
\ if self.pair[frame_id] == packet:\n return\n\n self.pair[frame_id]\
\ = manchester.find(\"1010101001010101\")\n if start == -1:\n \
\ return\n\n if manchester[start+20:start+24] == \"1010\":\n \
\ packet_length = 40\n elif manchester[start+20:start+24] == \"\
1001\":\n packet_length = 64\n else:\n return\n\
\n manchester = manchester[start+16:start+20+(packet_length*2)]\n \
\ baseband = []\n for i in range(0, len(manchester), 2):\n \
\ if manchester[i:i+2] == \"01\":\n baseband.append(1)\n\
\ elif manchester[i:i+2] == \"10\":\n baseband.append(0)\n\
\ else:\n return\n packet = baseband[2:]\n\n\
\ if baseband[0:2] == [0, 0]:\n frame_id = 0\n elif\
\ baseband[0:2] == [0, 1]:\n frame_id = 1\n else:\n \
\ return\n\n self.pair_time[frame_id] = current_sample\n\n \
\ if self.pair[frame_id] == packet:\n return\n\n self.pair[frame_id]\
\ = packet\n \n if (self.pair[frame_id ^ 1] is not None) and (len(self.pair[frame_id\
\ ^ 1]) == packet_length):\n if self.pair_time[frame_id] - self.pair_time[frame_id\
\ ^ 1] < 0.35 * self.samp_rate:\n try:\n rolling,\
Expand Down Expand Up @@ -797,4 +797,4 @@ connections:

metadata:
file_format: 1
grc_version: 3.10.5.0
grc_version: 3.10.9.2
42 changes: 13 additions & 29 deletions secplus_rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,19 @@
#
# GNU Radio Python Flow Graph
# Title: Secplus Rx
# GNU Radio version: 3.10.5.0

from packaging.version import Version as StrictVersion

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()")
# GNU Radio version: 3.10.9.2

from PyQt5 import Qt
from PyQt5.QtCore import QObject, pyqtSlot
from gnuradio import qtgui
from gnuradio.filter import firdes
import sip
from PyQt5.QtCore import QObject, pyqtSlot
from gnuradio import blocks
from gnuradio import filter
from gnuradio.filter import firdes
from gnuradio import gr
from gnuradio.fft import window
import sys
import signal
from PyQt5 import Qt
from argparse import ArgumentParser
from gnuradio.eng_arg import eng_float, intx
from gnuradio import eng_notation
Expand All @@ -39,11 +27,10 @@
import time
import secplus_rx_secplus_decode as secplus_decode # embedded python block
import secplus_rx_secplus_v2_decode as secplus_v2_decode # embedded python block
import sip



from gnuradio import qtgui

class secplus_rx(gr.top_block, Qt.QWidget):

def __init__(self):
Expand All @@ -53,8 +40,8 @@ def __init__(self):
qtgui.util.check_set_qss()
try:
self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
except:
pass
except BaseException as exc:
print(f"Qt GUI: Could not set Icon: {str(exc)}", file=sys.stderr)
self.top_scroll_layout = Qt.QVBoxLayout()
self.setLayout(self.top_scroll_layout)
self.top_scroll = Qt.QScrollArea()
Expand All @@ -70,12 +57,11 @@ def __init__(self):
self.settings = Qt.QSettings("GNU Radio", "secplus_rx")

try:
if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
self.restoreGeometry(self.settings.value("geometry").toByteArray())
else:
self.restoreGeometry(self.settings.value("geometry"))
except:
pass
geometry = self.settings.value("geometry")
if geometry:
self.restoreGeometry(geometry)
except BaseException as exc:
print(f"Qt GUI: Could not restore geometry: {str(exc)}", file=sys.stderr)

##################################################
# Variables
Expand All @@ -89,6 +75,7 @@ def __init__(self):
##################################################
# Blocks
##################################################

# Create the options list
self._freq_options = [310150000, 315150000, 390150000]
# Create the labels list
Expand Down Expand Up @@ -265,9 +252,6 @@ def set_decim1(self, decim1):

def main(top_block_cls=secplus_rx, options=None):

if StrictVersion("4.5.0") <= StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
style = gr.prefs().get_string('qtgui', 'style', 'raster')
Qt.QApplication.setGraphicsSystem(style)
qapp = Qt.QApplication(sys.argv)

tb = top_block_cls()
Expand Down
14 changes: 7 additions & 7 deletions secplus_rx_secplus_v2_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ def process_edge(self, rising, samples):

def process_buffer(self, current_sample):
manchester = "".join(str(b) for b in self.buffer)
start = manchester.find("1010101010101010101010101010101001010101")
start = manchester.find("1010101001010101")
if start == -1:
return

if manchester[start+44:start+48] == "1010":
if manchester[start+20:start+24] == "1010":
packet_length = 40
elif manchester[start+44:start+48] == "1001":
elif manchester[start+20:start+24] == "1001":
packet_length = 64
else:
return

manchester = manchester[start:start+44+(packet_length*2)]
manchester = manchester[start+16:start+20+(packet_length*2)]
baseband = []
for i in range(0, len(manchester), 2):
if manchester[i:i+2] == "01":
Expand All @@ -93,11 +93,11 @@ def process_buffer(self, current_sample):
baseband.append(0)
else:
return
packet = baseband[22:]
packet = baseband[2:]

if baseband[20:22] == [0, 0]:
if baseband[0:2] == [0, 0]:
frame_id = 0
elif baseband[20:22] == [0, 1]:
elif baseband[0:2] == [0, 1]:
frame_id = 1
else:
return
Expand Down

0 comments on commit b6fb676

Please sign in to comment.