From 66e041cf738d6064d5b49610a9ead1293c3ad5b1 Mon Sep 17 00:00:00 2001 From: Christos Falas Date: Tue, 31 Dec 2024 16:08:32 +0000 Subject: [PATCH] allow different ports --- src/__main__.py | 4 ++-- src/config.py | 15 ++++++--------- src/ingest.py | 22 ++++++++++++---------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index 87b8f53..1e258a2 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -15,14 +15,14 @@ logging.basicConfig( class Receiver(NamedTuple): - ip: str + ip: ingest.Host receiver: ingest.FeitReceiver queue: "mp.Queue[ingest.CSI]" receivers = [ Receiver(ip, ingest.FeitReceiver(ip), mp.Queue(config.SAMPLE_RATE)) - for ip in config.RECEIVE_IP_ADDRESS_LIST + for ip in config.RECEIVE_HOSTS ] # Start injecting CSI frames diff --git a/src/config.py b/src/config.py index 05614ca..f1b7129 100644 --- a/src/config.py +++ b/src/config.py @@ -1,5 +1,3 @@ -import os - PREPROCESSING_SHORT_TERM_WINDOW_SIZE = 5 PREPROCESSING_LONG_TERM_ALPHA = 0.01 @@ -8,15 +6,14 @@ PREPROCESSING_BANDPASS_HIGH_CUTOFF = 40 AOA_SLIDING_WINDOW_SIZE = 40 -RECEIVE_IP_ADDRESS_LIST = ["10.0.12.64", "10.0.12.62"] -INJECT_IP_ADDRESS = os.getenv("INJECT_IP_ADDRESS", "10.0.12.63") -FEITCSI_PORT = 8008 +RECEIVE_HOSTS = [("cfalas.com", 10001), ("cfalas.com", 10002)] +INJECT_HOST = ("cfalas.com", 10003) ANTENNA_ORDER = [ - ("10.0.12.62", 0), - ("10.0.12.64", 1), - ("10.0.12.64", 0), - ("10.0.12.62", 1), + (("cfalas.com", 10001), 0), + (("cfalas.com", 10002), 1), + (("cfalas.com", 10002), 0), + (("cfalas.com", 10001), 1), ] SAMPLE_RATE = 100 # Hz diff --git a/src/ingest.py b/src/ingest.py index 9e413b7..579e27e 100644 --- a/src/ingest.py +++ b/src/ingest.py @@ -10,13 +10,15 @@ from .csi import CSI from .aoa import AoA from .preprocess import Preprocessor from . import config -from . import visualise + + +Host = tuple[str, int] class FeitTransmitter: def __init__(self): self.inject_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - self.inject_server.connect((config.INJECT_IP_ADDRESS, config.FEITCSI_PORT)) + self.inject_server.connect(config.INJECT_HOST) inject_start_string = ( f"feitcsi --frequency {config.CENTRAL_FREQUENCY_MHZ} " f"--channel-width {config.CHANNEL_WIDTH} " @@ -29,10 +31,10 @@ class FeitTransmitter: class FeitReceiver: - def __init__(self, host: str): + def __init__(self, host: Host): self.host = host self.server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - self.server.connect((self.host, config.FEITCSI_PORT)) + self.server.connect(host) self.start_string = ( f"feitcsi --frequency {config.CENTRAL_FREQUENCY_MHZ} " f"--channel-width {config.CHANNEL_WIDTH} " @@ -66,10 +68,10 @@ class FeitReceiver: class CSIProcessor: def __init__( self, - receiver_connections: dict[str, "mp.Queue[CSI]"], + receiver_connections: dict[Host, "mp.Queue[CSI]"], webserver: "mp.Queue[AoA]", ): - self.pending_data: dict[str, tuple[datetime, CSI]] = {} + self.pending_data: dict[Host, tuple[datetime, CSI]] = {} self.pending_data_lock = mp.Lock() self.logger = logging.getLogger(f"{__name__}.{self.__class__.__name__}") self.last_processed = datetime.now() @@ -80,7 +82,7 @@ class CSIProcessor: self.connections = receiver_connections self.webserver = webserver - def add_data(self, host: str, data: CSI): + def add_data(self, host: Host, data: CSI): if ( host in self.pending_data and self.last_processed < self.pending_data[host][0] @@ -101,10 +103,10 @@ class CSIProcessor: self.logger.debug("Antenna RSSI values: {}".format(rssis)) def is_ready(self): - for ip in config.RECEIVE_IP_ADDRESS_LIST: + for host in config.RECEIVE_HOSTS: if ( - ip not in self.pending_data - or self.pending_data[ip][0] <= self.last_processed + host not in self.pending_data + or self.pending_data[host][0] <= self.last_processed ): return False return True