minor changes, new release

This commit is contained in:
Xavier Olive 2023-02-14 18:39:52 +01:00
parent 0d7a310007
commit 4e19ecdfa9
3 changed files with 36 additions and 32 deletions

View File

@ -1,9 +1,10 @@
import os import os
import shutil import shutil
import sys import sys
from distutils.core import Distribution, Extension
from distutils.command import build_ext from distutils.command import build_ext
from distutils.core import Distribution, Extension
# import pip
from Cython.Build import cythonize from Cython.Build import cythonize
@ -11,16 +12,7 @@ def build() -> None:
compile_args = [] compile_args = []
if sys.platform == "linux": if sys.platform == "linux":
compile_args += [ compile_args += ["-Wno-pointer-sign", "-Wno-unused-variable"]
# "-march=native",
# "-O3",
# "-msse",
# "-msse2",
# "-mfma",
# "-mfpmath=sse",
"-Wno-pointer-sign",
"-Wno-unused-variable",
]
extensions = [ extensions = [
Extension( Extension(

View File

@ -1,14 +1,22 @@
from __future__ import annotations
import time import time
import traceback import traceback
import numpy as np import numpy as np
import pyModeS as pms import pyModeS as pms
from typing import Any
import_msg = """
---------------------------------------------------------------------
Warning: pyrtlsdr not installed (required for using RTL-SDR devices)!
---------------------------------------------------------------------"""
try: try:
import rtlsdr # type: ignore import rtlsdr # type: ignore
except: except ImportError:
print("------------------------------------------------------------------------") print(import_msg)
print("! Warning: pyrtlsdr not installed (required for using RTL-SDR devices) !")
print("------------------------------------------------------------------------")
sampling_rate = 2e6 sampling_rate = 2e6
smaples_per_microsec = 2 smaples_per_microsec = 2
@ -24,9 +32,9 @@ th_amp_diff = 0.8 # signal amplitude threshold difference between 0 and 1 bit
class RtlReader(object): class RtlReader(object):
def __init__(self, **kwargs): def __init__(self, **kwargs) -> None:
super(RtlReader, self).__init__() 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 = rtlsdr.RtlSdr()
self.sdr.sample_rate = sampling_rate self.sdr.sample_rate = sampling_rate
self.sdr.center_freq = modes_frequency self.sdr.center_freq = modes_frequency
@ -39,7 +47,7 @@ class RtlReader(object):
self.exception_queue = None self.exception_queue = None
def _calc_noise(self): def _calc_noise(self) -> float:
"""Calculate noise floor""" """Calculate noise floor"""
window = smaples_per_microsec * 100 window = smaples_per_microsec * 100
total_len = len(self.signal_buffer) total_len = len(self.signal_buffer)
@ -50,7 +58,7 @@ class RtlReader(object):
) )
return min(means) return min(means)
def _process_buffer(self): def _process_buffer(self) -> list[list[Any]]:
"""process raw IQ data in the buffer""" """process raw IQ data in the buffer"""
# update noise floor # update noise floor
@ -70,17 +78,18 @@ class RtlReader(object):
i += 1 i += 1
continue continue
if self._check_preamble(self.signal_buffer[i : i + pbits * 2]): frame_start = i + pbits * 2
frame_start = i + pbits * 2 if self._check_preamble(self.signal_buffer[i:frame_start]):
frame_end = i + pbits * 2 + (fbits + 1) * 2
frame_length = (fbits + 1) * 2 frame_length = (fbits + 1) * 2
frame_end = frame_start + frame_length
frame_pulses = self.signal_buffer[frame_start:frame_end] frame_pulses = self.signal_buffer[frame_start:frame_end]
threshold = max(frame_pulses) * 0.2 threshold = max(frame_pulses) * 0.2
msgbin = [] msgbin: list[int] = []
for j in range(0, frame_length, 2): 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: if len(p2) < 2:
break break
@ -117,7 +126,7 @@ class RtlReader(object):
return messages return messages
def _check_preamble(self, pulses): def _check_preamble(self, pulses) -> bool:
if len(pulses) != 16: if len(pulses) != 16:
return False return False
@ -127,7 +136,7 @@ class RtlReader(object):
return True return True
def _check_msg(self, msg): def _check_msg(self, msg) -> bool:
df = pms.df(msg) df = pms.df(msg)
msglen = len(msg) msglen = len(msg)
if df == 17 and msglen == 28: if df == 17 and msglen == 28:
@ -137,8 +146,9 @@ class RtlReader(object):
return True return True
elif df in [4, 5, 11] and msglen == 14: elif df in [4, 5, 11] and msglen == 14:
return True return True
return False
def _debug_msg(self, msg): def _debug_msg(self, msg) -> None:
df = pms.df(msg) df = pms.df(msg)
msglen = len(msg) msglen = len(msg)
if df == 17 and msglen == 28: if df == 17 and msglen == 28:
@ -151,7 +161,7 @@ class RtlReader(object):
# print("[*]", msg) # print("[*]", msg)
pass pass
def _read_callback(self, data, rtlsdr_obj): def _read_callback(self, data, rtlsdr_obj) -> None:
amp = np.absolute(data) amp = np.absolute(data)
self.signal_buffer.extend(amp.tolist()) self.signal_buffer.extend(amp.tolist())
@ -159,16 +169,18 @@ class RtlReader(object):
messages = self._process_buffer() messages = self._process_buffer()
self.handle_messages(messages) self.handle_messages(messages)
def handle_messages(self, messages): def handle_messages(self, messages) -> None:
"""re-implement this method to handle the messages""" """re-implement this method to handle the messages"""
for msg, t in messages: for msg, t in messages:
# print("%15.9f %s" % (t, msg)) # print("%15.9f %s" % (t, msg))
pass pass
def stop(self, *args, **kwargs): def stop(self, *args, **kwargs) -> None:
self.sdr.close() 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.raw_pipe_in = raw_pipe_in
self.exception_queue = exception_queue self.exception_queue = exception_queue
self.stop_flag = stop_flag self.stop_flag = stop_flag

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "pyModeS" name = "pyModeS"
version = "2.15" version = "2.16"
description = "Python Mode-S and ADS-B Decoder" description = "Python Mode-S and ADS-B Decoder"
authors = ["Junzi Sun <j.sun-1@tudelft.nl>"] authors = ["Junzi Sun <j.sun-1@tudelft.nl>"]
license = "GNU GPL v3" license = "GNU GPL v3"