Skip to content

Commit 97ae5af

Browse files
committed
Serial Reader half complete
1 parent 3339416 commit 97ae5af

File tree

4 files changed

+94
-7
lines changed

4 files changed

+94
-7
lines changed

SerialReader.py

+51-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
1-
import Frame
2-
import SerialInterface
1+
# Serial Reader Threaded class
2+
#
3+
#
4+
#
5+
import struct
6+
from multiprocessing import Queue
7+
from threading import Thread
8+
from Frame import ShortRangeRadarFrameHeader, Frame, FrameError
9+
from SerialInterface import SerialInterface
10+
11+
12+
class SerialReader:
13+
def __init__(self, file, control, data):
14+
self.interface = SerialInterface(control, data, frame_type=ShortRangeRadarFrameHeader)
15+
self.file = file
16+
17+
self.running = False
18+
19+
self.received_queue = Queue()
20+
21+
self.receiving_process = Thread(target=self.process_receiving)
22+
self.storing_process = Thread(target=self.process_storing)
23+
24+
def process_receiving(self):
25+
while self.running:
26+
frame = self.interface.recv_item(self.interface.data_rx_queue)
27+
28+
if frame:
29+
try:
30+
frame = Frame(frame, frame_type=self.interface.frame_type)
31+
pass
32+
except(KeyError, struct.error, IndexError, FrameError, OverflowError) as e:
33+
print('Exception occurred: ', e)
34+
print('Skipping frame')
35+
36+
def process_storing(self):
37+
while self.running:
38+
pass
39+
40+
def send_profile(self, profile_file):
41+
with open(profile_file) as f:
42+
for line in f.readlines():
43+
if line.startswith('%'):
44+
continue
45+
else:
46+
self.interface.send_item(self.interface.control_tx_queue, line)
47+
48+
def stop(self):
49+
self.running = False
50+
51+
self.receiving_process.join()

UartSaver.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,10 @@ def process_frame():
145145
# Some data got in the wrong place, just skip the frame
146146
print('Exception occurred: ', e)
147147
print("Skipping frame due to error...")
148+
# Sleep to allow other threads to run
149+
time.sleep(0.001)
148150

149151

150-
# Sleep to allow other threads to run
151-
time.sleep(0.001)
152-
153152
if __name__ == "__main__":
154153
import argparse
155154

collect_data.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,44 @@
2121
# save_frame()
2222

2323

24-
import threading
24+
from threading import Thread
2525
import SerialReader
2626
import CameraReader
2727

28+
29+
def open_files():
30+
pass
31+
32+
33+
def watch_camera():
34+
with open('' + args.output_name + '.mp4', mode='wb+') as vid:
35+
# Create an instance of CameraReader and pass the file to it
36+
pass
37+
38+
pass
39+
40+
41+
def watch_serial():
42+
with open('' + args.output_name + '.csv', mode='w+') as csv:
43+
# Create an instance of SerialReader and pass the file to it
44+
pass
45+
pass
46+
47+
48+
async def watch():
49+
camera_thread = Thread(target=watch_camera)
50+
serial_thread = Thread(target=watch_serial)
51+
52+
53+
if __name__ == '__main__':
54+
import argparse
55+
56+
parser = argparse.ArgumentParser(description='Run the data collection pipeline')
57+
parser.add_help = True
58+
parser.add_argument('--control_port', help='COM port for configuration, control')
59+
parser.add_argument('--data_port', help='COM port for radar data transfer')
60+
parser.add_argument('--output_name', help='Name of the output collection of files')
61+
parser.add_argument('--prof', help='Radar Chirp profile to use')
62+
args = parser.parse_args()
63+
64+
await watch()

requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
matplotlib~=3.4.3
22
numpy~=1.21.4
33
pyserial~=3.5
4-
plotly~=5.6.0
4+
plotly~=5.6.0
5+
opencv-python~=4.5.5
6+
aiofiles~=0.8.0

0 commit comments

Comments
 (0)