Skip to content

Commit

Permalink
minor changes, new release
Browse files Browse the repository at this point in the history
  • Loading branch information
xoolive committed Feb 14, 2023
1 parent 0d7a310 commit 4e19ecd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
14 changes: 3 additions & 11 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import os
import shutil
import sys
from distutils.core import Distribution, Extension
from distutils.command import build_ext
from distutils.core import Distribution, Extension

# import pip
from Cython.Build import cythonize


def build() -> None:
compile_args = []

if sys.platform == "linux":
compile_args += [
# "-march=native",
# "-O3",
# "-msse",
# "-msse2",
# "-mfma",
# "-mfpmath=sse",
"-Wno-pointer-sign",
"-Wno-unused-variable",
]
compile_args += ["-Wno-pointer-sign", "-Wno-unused-variable"]

extensions = [
Extension(
Expand Down
52 changes: 32 additions & 20 deletions pyModeS/extra/rtlreader.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
from __future__ import annotations

import time
import traceback
import numpy as np
import pyModeS as pms

from typing import Any


import_msg = """
---------------------------------------------------------------------
Warning: pyrtlsdr not installed (required for using RTL-SDR devices)!
---------------------------------------------------------------------"""

try:
import rtlsdr # type: ignore
except:
print("------------------------------------------------------------------------")
print("! Warning: pyrtlsdr not installed (required for using RTL-SDR devices) !")
print("------------------------------------------------------------------------")
except ImportError:
print(import_msg)

sampling_rate = 2e6
smaples_per_microsec = 2
Expand All @@ -24,9 +32,9 @@


class RtlReader(object):
def __init__(self, **kwargs):
def __init__(self, **kwargs) -> None:
super(RtlReader, self).__init__()
self.signal_buffer = [] # amplitude of the sample only
self.signal_buffer: list[float] = [] # amplitude of the sample only
self.sdr = rtlsdr.RtlSdr()
self.sdr.sample_rate = sampling_rate
self.sdr.center_freq = modes_frequency
Expand All @@ -39,7 +47,7 @@ def __init__(self, **kwargs):

self.exception_queue = None

def _calc_noise(self):
def _calc_noise(self) -> float:
"""Calculate noise floor"""
window = smaples_per_microsec * 100
total_len = len(self.signal_buffer)
Expand All @@ -50,7 +58,7 @@ def _calc_noise(self):
)
return min(means)

def _process_buffer(self):
def _process_buffer(self) -> list[list[Any]]:
"""process raw IQ data in the buffer"""

# update noise floor
Expand All @@ -70,17 +78,18 @@ def _process_buffer(self):
i += 1
continue

if self._check_preamble(self.signal_buffer[i : i + pbits * 2]):
frame_start = i + pbits * 2
frame_end = i + pbits * 2 + (fbits + 1) * 2
frame_start = i + pbits * 2
if self._check_preamble(self.signal_buffer[i:frame_start]):
frame_length = (fbits + 1) * 2
frame_end = frame_start + frame_length
frame_pulses = self.signal_buffer[frame_start:frame_end]

threshold = max(frame_pulses) * 0.2

msgbin = []
msgbin: list[int] = []
for j in range(0, frame_length, 2):
p2 = frame_pulses[j : j + 2]
j_2 = j + 2
p2 = frame_pulses[j:j_2]
if len(p2) < 2:
break

Expand Down Expand Up @@ -117,7 +126,7 @@ def _process_buffer(self):

return messages

def _check_preamble(self, pulses):
def _check_preamble(self, pulses) -> bool:
if len(pulses) != 16:
return False

Expand All @@ -127,7 +136,7 @@ def _check_preamble(self, pulses):

return True

def _check_msg(self, msg):
def _check_msg(self, msg) -> bool:
df = pms.df(msg)
msglen = len(msg)
if df == 17 and msglen == 28:
Expand All @@ -137,8 +146,9 @@ def _check_msg(self, msg):
return True
elif df in [4, 5, 11] and msglen == 14:
return True
return False

def _debug_msg(self, msg):
def _debug_msg(self, msg) -> None:
df = pms.df(msg)
msglen = len(msg)
if df == 17 and msglen == 28:
Expand All @@ -151,24 +161,26 @@ def _debug_msg(self, msg):
# print("[*]", msg)
pass

def _read_callback(self, data, rtlsdr_obj):
def _read_callback(self, data, rtlsdr_obj) -> None:
amp = np.absolute(data)
self.signal_buffer.extend(amp.tolist())

if len(self.signal_buffer) >= buffer_size:
messages = self._process_buffer()
self.handle_messages(messages)

def handle_messages(self, messages):
def handle_messages(self, messages) -> None:
"""re-implement this method to handle the messages"""
for msg, t in messages:
# print("%15.9f %s" % (t, msg))
pass

def stop(self, *args, **kwargs):
def stop(self, *args, **kwargs) -> None:
self.sdr.close()

def run(self, raw_pipe_in=None, stop_flag=None, exception_queue=None):
def run(
self, raw_pipe_in=None, stop_flag=None, exception_queue=None
) -> None:
self.raw_pipe_in = raw_pipe_in
self.exception_queue = exception_queue
self.stop_flag = stop_flag
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyModeS"
version = "2.15"
version = "2.16"
description = "Python Mode-S and ADS-B Decoder"
authors = ["Junzi Sun <[email protected]>"]
license = "GNU GPL v3"
Expand Down

0 comments on commit 4e19ecd

Please sign in to comment.