Linting
This commit is contained in:
parent
772c94204e
commit
cba7c32c99
|
|
@ -17,7 +17,6 @@ from at_commands import (
|
||||||
get_modem_rsrp,
|
get_modem_rsrp,
|
||||||
get_modem_rsrq,
|
get_modem_rsrq,
|
||||||
get_modem_sinr,
|
get_modem_sinr,
|
||||||
set_configs,
|
|
||||||
)
|
)
|
||||||
from helper_functions import (
|
from helper_functions import (
|
||||||
calculate_distance,
|
calculate_distance,
|
||||||
|
|
@ -76,8 +75,7 @@ def read_gps_data(
|
||||||
elif attempts >= 3:
|
elif attempts >= 3:
|
||||||
gps_data = {}
|
gps_data = {}
|
||||||
break
|
break
|
||||||
except serial.SerialException as e:
|
except serial.SerialException:
|
||||||
# print(f"Serial communication error: {e}")
|
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
|
|
@ -133,9 +131,7 @@ def get_current_location(dictionary={}):
|
||||||
|
|
||||||
|
|
||||||
# Ping base station
|
# Ping base station
|
||||||
def ping_basestation(
|
def ping_basestation(address="10.45.0.1", name="10.45.0.1", dictionary={}) -> dict:
|
||||||
address="10.45.0.1", dictionary={}
|
|
||||||
): # raspberry pi address 192.168.0.29, host1 is 0.30
|
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["ping", "-c", "1", address], capture_output=True, text=True
|
["ping", "-c", "1", address], capture_output=True, text=True
|
||||||
|
|
@ -144,14 +140,14 @@ def ping_basestation(
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
time_value = match.group(1)
|
time_value = match.group(1)
|
||||||
dictionary[f"{address}_ping_time"] = time_value
|
dictionary[f"{name}_ping_time"] = time_value
|
||||||
else:
|
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:
|
except Exception as e:
|
||||||
dictionary["ping error"] = f"{e}"
|
dictionary[f"{name}_ping error"] = f"{e}"
|
||||||
|
|
||||||
return dictionary
|
return dictionary
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ def get_iperf_lists(data, ip_address):
|
||||||
reverse_sender.append(float(entry["sender_bitrate"]))
|
reverse_sender.append(float(entry["sender_bitrate"]))
|
||||||
reverse_receiver.append(float(entry["receiver_bitrate"]))
|
reverse_receiver.append(float(entry["receiver_bitrate"]))
|
||||||
reverse_distances.append(int(float(entry["start_distance"])))
|
reverse_distances.append(int(float(entry["start_distance"])))
|
||||||
except:
|
except Exception:
|
||||||
message = entry["iperf_full"]
|
message = entry["iperf_full"]
|
||||||
bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message)
|
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"]))
|
sender.append(float(entry["sender_bitrate"]))
|
||||||
receiver.append(float(entry["receiver_bitrate"]))
|
receiver.append(float(entry["receiver_bitrate"]))
|
||||||
distances.append(int(float(entry["start_distance"])))
|
distances.append(int(float(entry["start_distance"])))
|
||||||
except:
|
except Exception:
|
||||||
message = entry["iperf_full"]
|
message = entry["iperf_full"]
|
||||||
bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message)
|
bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message)
|
||||||
|
|
||||||
|
|
|
||||||
32
relay.py
32
relay.py
|
|
@ -1,6 +1,4 @@
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import subprocess
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
@ -23,35 +21,12 @@ from communication import (
|
||||||
ping_basestation,
|
ping_basestation,
|
||||||
set_base_location,
|
set_base_location,
|
||||||
)
|
)
|
||||||
from end_to_relay_client import collect_iperf_remote
|
|
||||||
from helper_functions import save_data_to_json
|
from helper_functions import save_data_to_json
|
||||||
|
|
||||||
# Globals
|
# Globals
|
||||||
running = False # To control start/stop
|
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(
|
def calculate_ping(
|
||||||
dictionary: dict, base_address: str, relay_address: str, name: str
|
dictionary: dict, base_address: str, relay_address: str, name: str
|
||||||
) -> dict:
|
) -> dict:
|
||||||
|
|
@ -91,10 +66,6 @@ def relay_iperf(
|
||||||
"stations": "er",
|
"stations": "er",
|
||||||
}
|
}
|
||||||
save_data_to_json(data=data, filename=filename)
|
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
|
# Collect and send data continuously
|
||||||
|
|
@ -133,7 +104,8 @@ def collect_data(
|
||||||
# Send to server
|
# Send to server
|
||||||
print(f"\nPing Time: {data.get('ping_time')}")
|
print(f"\nPing Time: {data.get('ping_time')}")
|
||||||
print(
|
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')}")
|
print(f"Service: {data.get('network information')}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ def main():
|
||||||
|
|
||||||
# Send results back in chunks
|
# Send results back in chunks
|
||||||
for i in range(0, len(combined), BUFFER_SIZE):
|
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}")
|
print(f"[Relay] Sent results back to {addr}")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
import socket
|
|
||||||
import struct
|
|
||||||
import zmq
|
|
||||||
import numpy as np
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import socket
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import zmq
|
||||||
|
|
||||||
|
|
||||||
def send_0mq(args):
|
def send_0mq(args):
|
||||||
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
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
|
# ZMQ setup with high-performance options
|
||||||
context = zmq.Context()
|
context = zmq.Context()
|
||||||
|
|
@ -59,7 +60,7 @@ def send_0mq(args):
|
||||||
take = min(len(new_samples), total_samples - received)
|
take = min(len(new_samples), total_samples - received)
|
||||||
|
|
||||||
# Copy to main buffer
|
# Copy to main buffer
|
||||||
complex_values[received:received+take] = new_samples[:take]
|
complex_values[received: received + take] = new_samples[:take]
|
||||||
received += take
|
received += take
|
||||||
|
|
||||||
# Save any leftover samples
|
# Save any leftover samples
|
||||||
|
|
@ -81,6 +82,7 @@ def send_0mq(args):
|
||||||
print(f"Publish time: {end_time-start_time:.4f}s")
|
print(f"Publish time: {end_time-start_time:.4f}s")
|
||||||
start_time = end_time
|
start_time = end_time
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--vector_length", "-v", type=int, default=1024)
|
parser.add_argument("--vector_length", "-v", type=int, default=1024)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user