From 0ce3545e1ea239e0acc481cbf8fcaf4a64945ac2 Mon Sep 17 00:00:00 2001 From: Christos Falas Date: Thu, 26 Dec 2024 14:00:38 +0000 Subject: [PATCH] Convert to module --- src/__init__.py | 0 src/config.py | 23 +++++++++++++++++++++-- src/main.py | 38 ++++++++++++++++++++++++-------------- src/preprocess.py | 8 ++++++-- 4 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 src/__init__.py diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/config.py b/src/config.py index 916f4c7..d3c68ca 100644 --- a/src/config.py +++ b/src/config.py @@ -1,8 +1,27 @@ import os PREPROCESSING_SHORT_TERM_WINDOW_SIZE = 5 -PREPROCESSING_LONG_TERM_ALPHA = 0.1 +PREPROCESSING_LONG_TERM_ALPHA = 0.01 AOA_SLIDING_WINDOW_SIZE = 20 -FEITCSI_IP_ADDRESS = os.getenv("IP_ADDRESS", "10.0.12.62") +RECEIVE_IP_ADDRESS = os.getenv("IP_ADDRESS", "10.0.12.64") +INJECT_IP_ADDRESS = os.getenv("INJECT_IP_ADDRESS", "10.0.12.63") FEITCSI_PORT = 8008 + +SAMPLE_RATE = 100 # Hz + +EIGVAL_THRESHOLD = 1e4 + + +DELTA_F = 312_500 # Spacing between subcarriers in Hz +CENTRAL_FREQUENCY_MHZ = 6195 +CENTRAL_FREQUENCY_HZ = CENTRAL_FREQUENCY_MHZ * 1_000_000 + +ANTENNA_SPACING = 0.0285 +# ANTENNA_SPACING = 0.0285 * 3 + +CHANNEL_WIDTH = 20 +FRAME_FORMAT = "HT" + + +C = 299_792_458 diff --git a/src/main.py b/src/main.py index b060b82..6288dd4 100644 --- a/src/main.py +++ b/src/main.py @@ -1,13 +1,14 @@ import logging import socket from typing import Callable -from csi import CSI -from aoa import AoA -from preprocess import Preprocessor -import visualise import threading import struct -import config + +from .csi import CSI +from .aoa import AoA +from .preprocess import Preprocessor +from . import config +from . import visualise logging.basicConfig( level=logging.INFO, @@ -18,23 +19,31 @@ logging.basicConfig( class FeitServer: def __init__( self, - ip: str, - frequency: int = 5260, - channel_width: int = 80, - frame_format: str = "VHT", ): - self.ip = ip self.port = config.FEITCSI_PORT self.server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - self.server.connect((self.ip, self.port)) + self.server.connect((config.RECEIVE_IP_ADDRESS, self.port)) self.start_string = ( - f"feitcsi --frequency {frequency} " - f"--channel-width {channel_width} --format {frame_format} " + f"feitcsi --frequency {config.CENTRAL_FREQUENCY_MHZ} " + f"--channel-width {config.CHANNEL_WIDTH} " + f"--format {config.FRAME_FORMAT} " f"--mode measure" ) self.server.send(b"stop\n") self.server.send(self.start_string.encode()) + self.inject_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.inject_server.connect((config.INJECT_IP_ADDRESS, self.port)) + inject_start_string = ( + f"feitcsi --frequency {config.CENTRAL_FREQUENCY_MHZ} " + f"--channel-width {config.CHANNEL_WIDTH} " + f"--format {config.FRAME_FORMAT} " + f"--mode inject -s 1 --verbose " + f"--inject-delay {1_000_000 // config.SAMPLE_RATE}" + ) + self.inject_server.send(b"stop\n") + self.inject_server.send(inject_start_string.encode()) + def listen(self, callback: Callable[[CSI], None]): while True: # This is the max size of a UDP packet. The size of the actual CSI @@ -56,11 +65,12 @@ def process_data(data: CSI): if __name__ == "__main__": - server = FeitServer(config.FEITCSI_IP_ADDRESS) + server = FeitServer() preprocess = Preprocessor() aoa = AoA() # Start webapp in background thread + visualise.aoa = aoa webapp = threading.Thread(target=visualise.start) webapp.start() diff --git a/src/preprocess.py b/src/preprocess.py index 366215a..4a5c56d 100644 --- a/src/preprocess.py +++ b/src/preprocess.py @@ -1,13 +1,17 @@ import numpy as np -from csi import CSI +from .csi import CSI import logging from queue import Queue -import config +from . import config import numpy.typing as npt +from scipy.signal import correlate + logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) +np.seterr(invalid="ignore") + class Preprocessor: def __init__(self):