Change how different sensor types ar handled

This commit is contained in:
2026-07-06 13:57:09 -06:00
parent 6eb2993391
commit 8fc5088c01
21 changed files with 320 additions and 124 deletions
+23 -16
View File
@@ -12,9 +12,10 @@ var awaiting_sensors = {}
var invalid_sensors = {}
var valid_sensors = {}
var use_thread: bool = false
var thread: Thread
var mutex: Mutex
var exit_thread = false
var exit_thread = true
var signal_queue = []
@@ -27,10 +28,16 @@ func _ready():
print('Listening on port: ', port)
mutex = Mutex.new()
thread = Thread.new()
thread.start(_thread_function)
if use_thread:
thread = Thread.new()
print('Starting UDP Server thread')
thread.start(_thread_function)
else:
print('UDP server running in single threaded mode')
func _process(delta: float) -> void:
if not use_thread:
_process_connections()
while signal_queue.size() > 0:
mutex.lock()
var signal_data = signal_queue.pop_front()
@@ -51,10 +58,11 @@ func _process(delta: float) -> void:
DataSignals.magnetometer_data_received.emit(signal_data[1], signal_data[2], signal_data[3])
func _exit_tree() -> void:
mutex.lock()
exit_thread = true
mutex.unlock()
thread.wait_to_finish()
if use_thread:
mutex.lock()
exit_thread = true
mutex.unlock()
thread.wait_to_finish()
func _on_sensor_approved(sensor_ip: String):
mutex.lock()
@@ -72,6 +80,7 @@ func _on_sensor_declined(sensor_ip: String):
mutex.unlock()
func _thread_function():
print('UDP Server thread started')
while true:
mutex.lock()
var should_exit = exit_thread
@@ -177,15 +186,13 @@ func _handle_new_peer_request(peer_ip: String, packet: PackedByteArray):
10 | 1 byte | bool | peer provides quaternion orientation
"""
mutex.lock()
awaiting_sensors[peer_ip] = [
#packet.decode_u8(4),
packet.decode_u8(5),
packet.decode_u8(6),
packet.decode_u8(7),
packet.decode_u8(8),
#packet.decode_u8(9),
#packet.decode_u8(10),
]
print(packet)
print(packet.get(4))
print(0xf1)
if packet.get(4) == 0xf1:
awaiting_sensors[peer_ip] = "VEHICLE"
elif packet.get(4) == 0x23:
awaiting_sensors[peer_ip] = "LIDAR_2D"
signal_queue.append(["sensor_request_received", peer_ip, awaiting_sensors[peer_ip]])
mutex.unlock()