-
Notifications
You must be signed in to change notification settings - Fork 5
/
main_recording.py
242 lines (202 loc) · 11.5 KB
/
main_recording.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import json
import os
import subprocess
import time
import PySimpleGUI as sg
from fun_microDoppler_2243_complex import microDoppler
from helpers import convert_to_bytes
from datetime import datetime
fname = 'data/raw_data_Raw_0.bin'
sudo_password = '190396'
cwd = '/home/emre/Desktop/77ghz/CLI/Release'
radar_path = '/home/emre/Desktop/77ghz/open_radar/open_radar_initiative-new_receive_test/' \
'open_radar_initiative-new_receive_test/setup_radar/build'
leap_main_path = '/home/emre/PycharmProjects/LeapMotion/'
radar_fps = 25
radar_cmd = './setup_radar'
setup_leap = 'sudo leapd'.split()
export_cmd = 'LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$pwd'
os.environ["LD_LIBRARY_PATH"] = cwd # + ':' + os.getcwd() # error code 127 when not executed
dca = './DCA1000EVM_CLI_Control'
fpga_cmd = './DCA1000EVM_CLI_Control fpga cf.json'.split()
record_cmd = './DCA1000EVM_CLI_Control record cf.json'.split()
start_cmd = './DCA1000EVM_CLI_Control start_record cf.json'.split()
stop_cmd = './DCA1000EVM_CLI_Control stop_record cf.json'.split()
class_fname = 'classes.txt'
with open(class_fname) as f:
# lines = f.readlines() # ignore \n
lines = f.read().splitlines()
def time_as_int():
return int(round(time.time() * 100))
imsize = (500, 300)
fontsize = 15
sg.theme("DarkTeal2")
layout = [[sg.Text('Data Recording GUI', size=(50, 2), font=('courier', fontsize))],
[sg.Text('Sensors List:', size=(15, 2), font=('courier', fontsize)),
sg.Checkbox('77 Front', default=False, key="77_front_check", size=(15, 10), font=('courier', fontsize)),
sg.Checkbox('77 Corner', default=False, key="77_corner_check", size=(15, 10), font=('courier', fontsize)),
sg.Checkbox('77 Side', default=False, key="77_side_check", size=(15, 10), font=('courier', fontsize)),
sg.Checkbox('Leap Motion', default=False, key="leap_motion_check", size=(15, 10), font=('courier', fontsize)),
sg.Checkbox('Kinect', default=False, key="kinect_check", size=(15, 10), font=('courier', fontsize))],
[sg.Text('Subject:', size=(8, 2), font=('courier', fontsize)),
sg.InputText(size=(10, 5), key='subject', font=('courier', fontsize)),
sg.VSep(),
sg.Text('Class:', size=(7, 2), font=('courier', fontsize)),
sg.Combo(values=lines, default_value='TEST', key='class_list', size=(10, 10), font=('courier', fontsize)),
sg.VSep(),
sg.Text('Experiment:', size=(11, 2), font=('courier', fontsize)),
sg.Combo(values=['Exp1', 'Exp2', 'Exp3', 'Exp4'], default_value='TEST', key='exp_list', size=(5, 10),
font=('courier', fontsize)),
sg.VSep(),
sg.Text('Duration (sec):', size=(15, 2), font=('courier', fontsize)),
sg.InputText(size=(10, 5), key='duration', font=('courier', fontsize))],
[sg.Image('data/md.png', key='-IMAGE-', size=imsize),
sg.VSep(),
sg.Text(' TIME:', size=(15, 2), key='time', font=('courier', fontsize*4)),
[sg.Button('Setup Radar', button_color=('white', 'black'), size=(18, 2), font=('courier', fontsize)),
sg.Text('', key='setup_text', font=('courier', fontsize)),
sg.Button('Setup Leap Motion', button_color=('white', 'black'), size=(18, 2), font=('courier', fontsize))]],
[sg.Button('1. Start Recording', button_color=('white', 'green'), size=(18, 2), font=('courier', fontsize)),
sg.Text(' ', key='start_text', font=('courier', fontsize)),
sg.VSep(),
sg.Button('2. Stop Recording', button_color=('white', 'red'), size=(18, 2), font=('courier', fontsize)),
sg.Text(' ', key='stop_text', font=('courier', fontsize))],
[sg.Button('3. Micro-Doppler Signature', button_color=('white', 'blue'), size=(18, 2), font=('courier', fontsize)),
sg.Text(' ', key='md_text', font=('courier', fontsize)),
sg.VSep(),
sg.Exit(button_color=('white', 'black'), size=(18, 2), font=('courier', fontsize))]]
window = sg.Window('Radar GUI').Layout(layout)
while True: # Event Loop
event, values = window.Read()
if event in (None, 'Exit'):
break
if event == 'Setup Radar':
window['md_text'].update(' ')
window['stop_text'].update(' ')
window['start_text'].update(' ')
# std = subprocess.run(radar_cmd, cwd=radar_path, shell=True, stdin=subprocess.PIPE, # check=True,
# stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# print('setup_radar: ', std.stderr)
pwd = subprocess.Popen(['echo', sudo_password], cwd=radar_path, stdout=subprocess.PIPE)
pwd.wait()
print('sudopass: ', pwd.stdout.read())
cmd = subprocess.Popen(['sudo', '-S'] + [radar_cmd], cwd=radar_path, stdin=pwd.stdout,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd.wait()
print('setup_radar error return code: ', cmd.stderr.read())
cmd = subprocess.Popen(fpga_cmd, cwd=cwd, shell=False, stdin=subprocess.PIPE, text=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE) # , check=True)
cmd.wait()
print('fpga error return code: ', cmd.returncode)
print('fpga error2: ', cmd.stderr.read())
print('fpga stdout: ', cmd.stdout.read())
cmd = subprocess.Popen(record_cmd, cwd=cwd, shell=False, stdin=subprocess.PIPE, text=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE) # , check=True)
cmd.wait()
# cmd.stdin.write("record cf.json")
# cmd.wait()
print('record error return code: ', cmd.returncode)
print('record error2: ', cmd.stderr.read())
print('record stdout: ', cmd.stdout.read())
if cmd.returncode == 0:
window['setup_text'].update('Radar is ready to go!')
else:
window['setup_text'].update('Radar is set already!')
elif event == 'Setup Leap Motion':
pwd = subprocess.Popen(['echo', sudo_password], cwd=radar_path, stdout=subprocess.PIPE)
pwd.wait()
cmd_leap = subprocess.Popen(['sudo', '-S'] + setup_leap, cwd=cwd, stdin=pwd.stdout,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
elif event == '1. Start Recording':
window['-IMAGE-'].update('data/md.png', size=imsize)
window['md_text'].update(' ')
window['stop_text'].update(' ')
window['start_text'].update('Go! ')
# window['setup_text'].update(' ')
# _, values = window.read()
print('duration: ', values['duration'])
data_class = values['class_list'].split()[0]
now = datetime.now()
main_path = '/home/emre/PycharmProjects/RadarGUI/data/'
date_time = now.strftime("%Y_%m_%d_%H_%M_%S_")
fname = date_time + 'subj' + values['subject'] + '_' + values['exp_list'] + '_class' + data_class
filename = main_path + fname
if values['leap_motion_check']:
leap_cmd = 'python2 ' + leap_main_path + 'main.py --filename ' + filename + '.data' + \
' --duration ' + values['duration']
cmd = subprocess.Popen(leap_cmd.split(), cwd=cwd, shell=False, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE) # , check=True)
# print('leap')
json_file = cwd + '/cf.json'
a_file = open(json_file, "r")
json_object = json.load(a_file)
# print(json_object)
a_file.close()
# print(json_object['DCA1000Config']['captureConfig']['framesToCapture'])
# json_object['DCA1000Config']['captureConfig']['framesToCapture'] = radar_fps * int(values['duration'])
# json_object['DCA1000Config']['captureConfig']['captureStopMode'] = 'frames'
json_object['DCA1000Config']['captureConfig']['captureStopMode'] = 'duration'
json_object['DCA1000Config']['captureConfig']['durationToCapture_ms'] = int(values['duration']) * 1000
json_object['DCA1000Config']['captureConfig']['filePrefix'] = fname
a_file = open(json_file, "w")
json.dump(json_object, a_file)
a_file.close()
# time.sleep(1)
# print(json_object)
if values['77_front_check']:
print('starting...')
cmd = subprocess.Popen(start_cmd, cwd=cwd, shell=False, stdin=subprocess.PIPE, # text=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd.wait()
# cmd.stdin.write("start_record cf.json")
# cmd.wait()
print('start error return code: ', cmd.returncode)
print('start error2: ', cmd.stderr.read())
print('start stdout: ', cmd.stdout.read())
left_time = int(values['duration'])
for i in range(left_time):
window['time'].update(' TIME: ' + str(left_time))
window.refresh()
time.sleep(1)
left_time -= 1
window['time'].update(' Finished!')
window.refresh()
elif event == '2. Stop Recording':
window['stop_text'].update('Stopping... ')
window['md_text'].update(' ')
window['stop_text'].update('Done! ')
window['start_text'].update(' ')
# window['setup_text'].update(' ')
# cmd = subprocess.Popen(['sudo', '-S', 'kill', '`ps -e | grep -i gnome-terminal`'], cwd=cwd, shell=False,
# stdin=pwd.stdout, text=True,
# stdout=subprocess.PIPE, stderr=subprocess.PIPE) # , check=True)
# cmd.wait()
# time.sleep(2)
try:
pid = subprocess.check_output(['pgrep gnome-terminal'], shell=True) # , check=True)
print('pid stdoutstr: ' + str(pid.decode())[:-1] + '-')
cmd = subprocess.Popen(['kill', str(pid.decode())[:-1]], cwd=cwd, shell=False,
stdin=subprocess.PIPE, text=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE) # , check=True)
cmd.wait()
print('exit error return code: ', cmd.returncode)
print('exit error2: ', cmd.stderr.read())
print('exit stdout: ', cmd.stdout.read())
except:
print('No open command windows!')
cmd = subprocess.Popen(stop_cmd, cwd=cwd, shell=False, stdin=subprocess.PIPE, text=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE) # , check=True)
cmd.wait()
# cmd.stdin.write("stop_record cf.json")
# cmd.wait()
print('stop error return code: ', cmd.returncode)
print('stop error2: ', cmd.stderr.read())
print('stop stdout: ', cmd.stdout.read())
elif event == '3. Micro-Doppler Signature':
window['md_text'].update('Generating Micro-Doppler Signature...')
window.refresh()
microDoppler('data/' + fname + '_Raw_0.bin')
window['-IMAGE-'].update(data=convert_to_bytes('data/' + fname + '_Raw_0_py.png', resize=(700, 500)))
window['md_text'].update('Done! ')
window.refresh()
window.Close()