uav2.py
975 Bytes
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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import socket
import select
import os
# In[ ]:
def removeAllFile(filePath):
if os.path.exists(filePath):
for file in os.scandir(filePath):
os.remove(file.path)
return 'Remove All File'
else:
return 'Directory Not Found'
print(removeAllFile('/home/pi/capdesign/frames'))
address = ('192.168.51.1', 8083)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(address)
while True:
data, addr = sock.recvfrom(1024)
if data:
data = data.decode()
print("filename", data)
file_name = data.strip()
f = open('frames/{}'.format(file_name), 'wb')
while True:
ready = select.select([sock], [], [], 3)
if ready[0]:
data, addr = sock.recvfrom(1024)
if(data == "FINISH".encode('utf-8')):
f.close()
break
else:
f.write(data)