uav2.ipynb
1.85 KB
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
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import socket \n",
"import select \n",
"import os "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def removeAllFile(filePath):\n",
" if os.path.exists(filePath):\n",
" for file in os.scandir(filePath):\n",
" os.remove(file.path)\n",
" return 'Remove All File'\n",
" else:\n",
" return 'Directory Not Found'\n",
"\n",
"print(removeAllFile('/home/pi/capdesign/frames'))\n",
"address = ('192.168.51.1', 8083)\n",
"sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n",
"sock.bind(address)\n",
"\n",
"while True:\n",
" data, addr = sock.recvfrom(1024)\n",
" if data:\n",
" data = data.decode()\n",
" print(\"filename\", data)\n",
" file_name = data.strip()\n",
" \n",
" f = open('frames/{}'.format(file_name), 'wb')\n",
" \n",
" while True:\n",
" ready = select.select([sock], [], [], 3)\n",
" if ready[0]:\n",
" data, addr = sock.recvfrom(1024)\n",
" if(data == \"FINISH\".encode('utf-8')):\n",
" f.close()\n",
" break\n",
" else:\n",
" f.write(data) 2"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}