Can finally do arbitrary message sizes

This commit is contained in:
30hours 2024-03-03 08:55:28 +00:00
parent 0b4a6a9695
commit 5b22ccdebd
6 changed files with 36 additions and 28 deletions

View file

@ -62,7 +62,8 @@ def serve_static(file):
def api():
api = request.query_string.decode('utf-8')
try:
reply = message_api_request.send_message(api)
reply_chunks = message_api_request.send_message(api)
reply = ''.join(reply_chunks)
print(reply, flush=True)
return reply
except Exception as e:

View file

@ -14,9 +14,8 @@ function event_ellipsoid() {
for (const key in data["ellipsoids"]) {
if (data["ellipsoids"].hasOwnProperty(key)) {
const points = data["ellipsoids"][key];
console.log(points);
removeEntitiesOlderThanAndFade("ellipsoids", 30, 0.5);
removeEntitiesOlderThanAndFade("ellipsoids", 30, 0.2);
for (const point in points) {
addPoint(
@ -46,7 +45,7 @@ function event_ellipsoid() {
}
var style_ellipsoid = {};
style_ellipsoid.color = 'rgba(0, 0, 255, 1.0)';
style_ellipsoid.color = 'rgba(0, 0, 255, 0.2)';
style_ellipsoid.pointSize = 16;
style_ellipsoid.type = "ellipsoids";
style_ellipsoid.timestamp = Date.now();

View file

@ -16,9 +16,6 @@ function event_radar() {
const target = data["detections_localised"][key];
const points = target["points"];
// console.log(target);
// console.log(points);
removeEntitiesOlderThanAndFade("detection", 60, 0.5);
for (const point in points) {

View file

@ -47,43 +47,54 @@ class Message:
thread.start()
def handle_client(self, conn, addr):
"""
@brief Handle communication with a connected client.
@param conn (socket.socket): The socket object for the connected client.
@param addr (tuple): The address (host, port) of the connected client.
@return None.
Handle communication with a connected client.
:param conn (socket.socket): The socket object for the connected client.
:param addr (tuple): The address (host, port) of the connected client.
:return None.
"""
with conn:
while True:
data = conn.recv(30000)
data = conn.recv(8096)
if not data:
break
decoded_data = data.decode()
# Process data in chunks
decoded_data = ""
while data:
chunk = data.decode()
decoded_data += chunk
data = conn.recv(8096)
# Call the callback function if set
if self.callback_message_received:
reply = asyncio.run(self.callback_message_received(decoded_data))
if reply:
conn.sendall(reply.encode())
# Send the reply in chunks
for i in range(0, len(reply), 8096):
conn.sendall(reply[i:i + 8096].encode())
def send_message(self, message):
"""
@brief Send a message to the specified host and port.
@param message (str): The message to be sent.
@return None.
Send a message to the specified host and port.
:param message (str): The message to be sent.
:return generator: A generator yielding chunks of the reply.
"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
client_socket.settimeout(3)
try:
client_socket.connect((self.host, self.port))
client_socket.sendall(message.encode())
reply = client_socket.recv(30000).decode()
return reply
# Send the message in chunks
for i in range(0, len(message), 8096):
client_socket.sendall(message[i:i + 8096].encode())
# Indicate the end of transmission
client_socket.shutdown(socket.SHUT_WR)
# Receive the reply in chunks
while True:
data = client_socket.recv(8096)
if not data:
break
yield data.decode()
except ConnectionRefusedError:
print(f"Connection to {self.host}:{self.port} refused.")

View file

@ -81,7 +81,7 @@ class EllipsoidParametric:
# find close points
radar_keys = list(target_samples[target].keys())
samples_intersect = {key: [] for key in radar_keys}
threshold = 200
threshold = 1500
for i in range(0, len(target_samples[target])-1):
for j in range(i+1, len(target_samples[target])):

View file

@ -133,9 +133,9 @@ async def event():
bsr = 12470
if radar == 'radar5.30hours.dev':
bsr = 1870
if radar == 'radar4.30hours.dev':
if radar == 'radar6.30hours.dev':
bsr = 5210
points = ellipsoidParametric.sample(ellipsoid, bsr, 10)
points = ellipsoidParametric.sample(ellipsoid, bsr, 50)
for i in range(len(points)):
lat, lon, alt = Geometry.ecef2lla(points[i][0], points[i][1], points[i][2])
points[i] = ([round(lat, 3), round(lon, 3), round(alt)])