6 from threading
import Thread
12 import matplotlib.pyplot
as plt
13 import matplotlib.animation
as animation
30 self.server.nicla_disconnect =
False
34 packet = self.request.recv(65000)
35 print(
"LEN RECV: ", len(packet))
38 self.server.pdm_buffer.put_nowait(packet)
51 except Exception
as e:
52 print(f
"Exception: {e}")
53 self.server.receiving_buffer.queue.clear()
54 self.server.nicla_disconnect =
True
70 super().
__init__((server_ip, server_port), TCPHandler)
111 bytes_arr = bytes([])
125 print(
"SIZE: ", size)
129 print(
"BYTES LEN: ", len(bytes_arr))
131 if len(bytes_arr) >= size:
133 bytes_arr = bytes_arr[:size]
135 with open(
"my_file.txt",
"wb")
as binary_file:
138 binary_file.write(bytes_arr)
207 print(
"LEN: ", len(self.
numbers))
209 if len(self.
numbers) >= 10000 * 5:
215 with wave.open(
"audio.wav",
"w")
as wf:
218 wf.setframerate(10000)
219 wf.writeframes(self.
numbers.tobytes())
237 bkp_bytes_packets = bytes([])
244 timestamp = struct.unpack(
">d", bytes_packets[:8])[0]
245 bytes_packets = bytes_packets[8:]
248 bytes_packets = bytes([])
249 bkp_bytes_packets = bytes([])
253 bytes_packets = bkp_bytes_packets + bytes_packets
254 bkp_bytes_packets = bytes([])
256 if len(bytes_packets) < 9:
257 print(
"Got a packet from receiver less than header size!")
260 total_length = len(bytes_packets)
261 loop_termination_flag =
True
263 while loop_termination_flag:
264 size_packet = int.from_bytes(bytes_packets[:4],
"big")
266 if total_length - 4 >= size_packet:
267 packet = bytes_packets[4 : size_packet + 4]
268 bytes_packets = bytes_packets[size_packet + 4 :]
272 data_type = packet[4]
275 if data_type == RANGE_TYPE:
281 elif data_type == IMAGE_TYPE:
287 elif data_type == AUDIO_TYPE:
293 elif data_type == IMU_TYPE:
300 bkp_bytes_packets = bytes_packets
301 loop_termination_flag =
False
303 total_length = len(bytes_packets)
304 if total_length == 0:
305 loop_termination_flag =
False
341 if __name__ ==
"__main__":
353 nicla_receiver_server.serve()
354 except Exception
as e:
361 nicla_receiver_server.stop()