This commit is contained in:
M madrigal 2025-10-16 12:14:10 -04:00
parent 772c94204e
commit cba7c32c99
5 changed files with 33 additions and 63 deletions

View File

@ -17,7 +17,6 @@ from at_commands import (
get_modem_rsrp,
get_modem_rsrq,
get_modem_sinr,
set_configs,
)
from helper_functions import (
calculate_distance,
@ -76,8 +75,7 @@ def read_gps_data(
elif attempts >= 3:
gps_data = {}
break
except serial.SerialException as e:
# print(f"Serial communication error: {e}")
except serial.SerialException:
pass
except Exception as e:
print(f"Error: {e}")
@ -133,9 +131,7 @@ def get_current_location(dictionary={}):
# Ping base station
def ping_basestation(
address="10.45.0.1", dictionary={}
): # raspberry pi address 192.168.0.29, host1 is 0.30
def ping_basestation(address="10.45.0.1", name="10.45.0.1", dictionary={}) -> dict:
try:
result = subprocess.run(
["ping", "-c", "1", address], capture_output=True, text=True
@ -144,14 +140,14 @@ def ping_basestation(
if match:
time_value = match.group(1)
dictionary[f"{address}_ping_time"] = time_value
dictionary[f"{name}_ping_time"] = time_value
else:
dictionary[f"{address}_ping_time"] = "Not found"
dictionary[f"{name}_ping_time"] = "Not found"
dictionary[f"{address}_ping_stats"] = result.stdout
dictionary[f"{name}_ping_stats"] = result.stdout
except Exception as e:
dictionary["ping error"] = f"{e}"
dictionary[f"{name}_ping error"] = f"{e}"
return dictionary

View File

@ -105,7 +105,7 @@ def get_iperf_lists(data, ip_address):
reverse_sender.append(float(entry["sender_bitrate"]))
reverse_receiver.append(float(entry["receiver_bitrate"]))
reverse_distances.append(int(float(entry["start_distance"])))
except:
except Exception:
message = entry["iperf_full"]
bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message)
@ -117,7 +117,7 @@ def get_iperf_lists(data, ip_address):
sender.append(float(entry["sender_bitrate"]))
receiver.append(float(entry["receiver_bitrate"]))
distances.append(int(float(entry["start_distance"])))
except:
except Exception:
message = entry["iperf_full"]
bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message)

View File

@ -1,6 +1,4 @@
import os
import re
import subprocess
import threading
import time
@ -23,35 +21,12 @@ from communication import (
ping_basestation,
set_base_location,
)
from end_to_relay_client import collect_iperf_remote
from helper_functions import save_data_to_json
# Globals
running = False # To control start/stop
# Ping base station
def ping_basestation(address="10.45.0.1", name="10.45.0.1", dictionary={}) -> dict:
try:
result = subprocess.run(
["ping", "-c", "1", address], capture_output=True, text=True
)
match = re.search(r"time=([\d.]+)", result.stdout)
if match:
time_value = match.group(1)
dictionary[f"{name}_ping_time"] = time_value
else:
dictionary[f"{name}_ping_time"] = "Not found"
dictionary[f"{name}_ping_stats"] = result.stdout
except Exception as e:
dictionary[f"{name}_ping error"] = f"{e}"
return dictionary
def calculate_ping(
dictionary: dict, base_address: str, relay_address: str, name: str
) -> dict:
@ -91,10 +66,6 @@ def relay_iperf(
"stations": "er",
}
save_data_to_json(data=data, filename=filename)
# try:
# collect_iperf_remote(filename=filename)
# except Exception as e:
# print(f"Error collecting relay -> ground iperf: {e}")
# Collect and send data continuously
@ -133,7 +104,8 @@ def collect_data(
# Send to server
print(f"\nPing Time: {data.get('ping_time')}")
print(
f"RSRP: PRX: {data.get('RSRP PRX')} DRX: {data.get('RSRP DRX')} RX2: {data.get('RSRP RX2')} RX3: {data.get('RSRP RX3')}"
f"RSRP: PRX: {data.get('RSRP PRX')} DRX: {data.get('RSRP DRX')} \
RX2: {data.get('RSRP RX2')} RX3: {data.get('RSRP RX3')}"
)
print(f"Service: {data.get('network information')}")

View File

@ -47,7 +47,7 @@ def main():
# Send results back in chunks
for i in range(0, len(combined), BUFFER_SIZE):
sock.sendto(combined[i : i + BUFFER_SIZE].encode(), addr)
sock.sendto(combined[i: i + BUFFER_SIZE].encode(), addr)
print(f"[Relay] Sent results back to {addr}")

View File

@ -1,86 +1,88 @@
import socket
import struct
import zmq
import numpy as np
import argparse
import socket
import time
import numpy as np
import zmq
def send_0mq(args):
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_socket.bind(('127.0.0.1', 5588))
udp_socket.bind(("127.0.0.1", 5588))
# ZMQ setup with high-performance options
context = zmq.Context()
zmq_socket = context.socket(zmq.PUB)
zmq_socket.setsockopt(zmq.SNDHWM, 0) # Remove send buffer limit
zmq_socket.setsockopt(zmq.LINGER, 0) # Don't wait on close
zmq_socket.setsockopt(zmq.LINGER, 0) # Don't wait on close
zmq_socket.bind(f"tcp://127.0.0.1:{args.publisher}")
# Buffer for storing received samples
total_samples = args.n_vectors * args.vector_length
complex_values = np.empty(total_samples, dtype=np.complex64)
# Buffer for handling partial packets
leftover = None
start_time = time.perf_counter()
while True:
received = 0
# Process leftover data from previous iteration
if leftover is not None:
take = min(len(leftover), total_samples)
complex_values[:take] = leftover[:take]
received = take
# Update leftover
if take < len(leftover):
leftover = leftover[take:]
else:
leftover = None
# Receive new packets
while received < total_samples:
try:
# Calculate how much more we need
bytes_needed = (total_samples - received) * 8
data, _ = udp_socket.recvfrom(bytes_needed)
# Convert to complex array
num_bytes = len(data)
num_samples = num_bytes // 8
if num_samples == 0:
continue
# Convert to complex64 array
new_samples = np.frombuffer(data, dtype=np.float32).view(np.complex64)
# Calculate how many to copy
take = min(len(new_samples), total_samples - received)
# Copy to main buffer
complex_values[received:received+take] = new_samples[:take]
complex_values[received: received + take] = new_samples[:take]
received += take
# Save any leftover samples
if take < len(new_samples):
if leftover is None:
leftover = new_samples[take:]
else:
leftover = np.concatenate((leftover, new_samples[take:]))
except socket.error as e:
print(f"Socket error: {e}")
break
# Send only if we have a full buffer
if received == total_samples:
zmq_socket.send(complex_values.tobytes(), copy=False) # Zero-copy send
end_time = time.perf_counter()
print(f"Publish time: {end_time-start_time:.4f}s")
start_time = end_time
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--vector_length", "-v", type=int, default=1024)