-
Notifications
You must be signed in to change notification settings - Fork 2
/
StayConnected.py
70 lines (60 loc) · 1.99 KB
/
StayConnected.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
# coding: utf-8
# In[1]:
from multiprocessing import Process, Pipe
from CamArrayControl import *
from time import sleep
import socket
def CameraArrayCommand_Parralell(camarrayopener,url):
threading= []
for iterid in range(0,len(camarrayopener)):
print 'creating thread!\n'
threading.append(Process(target=SendCmd, args=(camarrayopener[iterid],url,iterid)))
threading[iterid].start()
print 'thread created!\n'
def BuildCameraArrayOpener(camarray):
opener = []
for cam in camarray:
opener.append(cam.opener)
return opener
def SendCmd_test(opener,url,iterid):
print 'started!'
try:
result = opener.open(url, timeout=4).read()
except Exception,e:
print "cam %d: "%iterid + str(e)
def KeepAlive(camarray):
MESSAGE = "_GPHD_:%u:%u:%d:%1lf\n" % (0, 0, 2, 0)
UDP_IP = "10.5.5.9"
UDP_PORT = 8554
KEEP_ALIVE_PERIOD = 2500
while True:
for cam in camarray:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((cam.ip,8080))
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
sock.close()
sleep(KEEP_ALIVE_PERIOD/1000)
def StreamMultiCam(camarray):
for cam in camarray:
thread = Process(target=StartFFplay,args=(cam,))
thread.start()
def LoadJson(path):
with open(path,'r') as datasource:
data = json.load(datasource)
return data
if __name__=='__main__':
camarray = []
for id in range(1,17):
camarray.append(Camera(id,1))
#js = ReadJson('D:\gopro_multiview_gui')
cmddict = LoadJson('D:/gopro_multiview_gui/newcommand.json')
camarraycmd = CameraArrayCommand()
#f = open('D:\gopro_multiview_gui\command.json')
#cmddict = json.load(f)
#camarraycmd.RegisterMacs(camarray,js['mac_map'])
while(True):
for cam in camarray:
cam.SendUrlCmd(cmddict['GetStatus'])
sleep(1.5)
print "=================================================="
# In[2]: