Commit b9780963 by 刘航

Merge branch 'develop' of http://192.168.9.26/platform/tx1_box_serv into mybranch

2 parents 01071351 a57e89af
......@@ -23,9 +23,9 @@ def dataRecv():
data = request.get_data()
dataDic = json.loads(data)
if type(dataDic) is dict:
send_all_data ( sv_global.get_value (), data )
# res = etl.eventToLocal.saveEventToLocal(dataDic)
# print(res)
send_all_data(sv_global.get_value(),data)
#存入本地数据库
# save_alarm_data(data,res)
else:
......
......@@ -190,13 +190,13 @@ def make_task_info(task_index):
taski = tasks[1]
task.setdefault ( 'subtask_id', read_task_id ( os.path.join(taski +'task.xml' )))
mtask_path = tasks[2]
rtsp = read_rtsp ( os.path.join ( taski, 'scene.xml' ) )
rtsp,algo_type = read_rtsp ( os.path.join ( taski, 'scene.xml' ) )
if rtsp =='' or rtsp is None:
task.setdefault ( 'is_active', False)
else:
task.setdefault ( 'is_active', True )
task.setdefault('mtasks',make_mtasks(os.path.join(mtask_path,'calibration.xml'),os.path.join(mtask_path,'roi_1.xml'),tasks[3],os.path.join(mtask_path,'config.xml'), rtsp))
task.setdefault('mtasks',make_mtasks(os.path.join(mtask_path,'calibration.xml'),os.path.join(mtask_path,'roi_1.xml'),tasks[3],os.path.join(mtask_path,'config.xml'), rtsp,algo_type))
return task
def read_task_name(xmlPath):
......@@ -230,10 +230,21 @@ def read_rtsp(xmlPath):
"rtsp" )[0]
if scen_play_url is not None and len(scen_play_url.childNodes) > 0:
scen_play_url = scen_play_url.childNodes[0]
return scen_play_url.data
return ''
def make_mtasks(cal_path,roi_path,basconpath,conpath,rtsp):
scen_play_url = scen_play_url.data
else:
scen_play_url = ''
"""
获取算法类型
"""
algo_type = root.getElementsByTagName ( "scene1" )[0].getElementsByTagName ( "algo_type" )[0]
if algo_type is not None and len(algo_type.childNodes) > 0:
algo_type = algo_type.childNodes[0].data
else:
algo_type = 0
return scen_play_url,algo_type
return '',0
def make_mtasks(cal_path,roi_path,basconpath,conpath,rtsp,algo_type):
mtasks = []
scenes = []
cal = editXml.openXml( cal_path )
......@@ -245,7 +256,6 @@ def make_mtasks(cal_path,roi_path,basconpath,conpath,rtsp):
con = con.replace ( '\n', '' )
config = {}
config.setdefault('xml',con)
play_urls = {}
play_urls.setdefault('rtsp',rtsp)
......@@ -266,7 +276,8 @@ def make_mtasks(cal_path,roi_path,basconpath,conpath,rtsp):
sce.setdefault ( 'config', config )
sce.setdefault ( 'basicConfig', basConfig )
sce.setdefault ( 'play_urls', play_urls )
sce.setdefault('algo_type',0)
sce.setdefault('algo_type',algo_type)
scenes.append(sce)
mtask = {}
......
......@@ -29,7 +29,7 @@ class Server ():
self.sock.bind ( (h,p) ) # 监听端口
#self.sock.bind ( (config['HOST'], config['PORT']) ) # 监听端口
self.sock.listen ( config['LISTEN_CLIENT'] ) # 监听客户端数量
self.sock.setsockopt(SOL_SOCKET, SO_LINGER, 1)
# 所有监听的客户端
self.clients = {}
self.thrs = {}
......@@ -38,14 +38,15 @@ class Server ():
self.h=h
self.p=p
self.subtask_id=None
self.subtaskids={}
# 监听客户端连接
def listen_client(self):
while 1:
# time.sleep(500)
time.sleep(0.001)
# 循环监听
tcpClientSock, addr = self.sock.accept ()
address = addr[0] + ':' + str ( addr[1] ) # ip:port
# 握手
topInfo = tcpClientSock.recv ( 1024 )
headers = {}
......@@ -83,14 +84,27 @@ class Server ():
# config['PORT'] ) )
str_handshake = config['HANDSHAKE_STRING'].replace ( '{1}', res_key ).replace ( '{2}',self.h+ ':' + str (self.p) )
tcpClientSock.send ( str_handshake )
num = len ( self.clients )
if num > 0:
for i in range ( num ):
if len ( self.clients ) > 0:
for adr_pot in self.clients:
_index = adr_pot.index ( ':' )
adr = adr_pot[0:_index]
if addr[0] == adr:
self.close_client ( adr_pot )
break
# 握手成功 分配线程进行监听
print(address + '进来了')
#index = address.index(':')
#address = address[0:index]
#client = self.clients.pop(address)
#if client :
# client.close()
self.clients[address] = tcpClientSock
self.thrs[address] = threading.Thread ( target=self.readMsg, args=[address] )
self.thrs[address].start ()
time.sleep ( 0.001 )
#time.sleep(0.001)
# print(self.clients)
def readMsg(self, address):
......@@ -103,6 +117,7 @@ class Server ():
import select
time_out = 0
while 1:
time.sleep ( 0.001 )
# print(len(self.clients))
if address in self.stops:
self.close_client ( address )
......@@ -150,7 +165,7 @@ class Server ():
raw_str += chr ( ord ( d ) ^ ord ( masks[i % 4] ) )
# print(raw_str)
i += 1
print raw_str
# 获取到输入的数据 向所有的客户端发送
# 开启线程记录
......@@ -161,62 +176,69 @@ class Server ():
if type(da) is dict:
if da.has_key('subtask_id'):
self.subtask_id = da['subtask_id']
self.subtaskids[address]=da['subtask_id']
except Exception as e:
print e
time.sleep(0.001)
#t1 = threading.Thread ( target=self.send_data, args=[raw_str, address] )
#t1.start ()
def send_data(self, str_data, address):
#data = eval(data)
if type(str_data) is str:
data = json.loads (str_data)
if type(data) is dict:
if data.has_key('subtask_id'):
subtask_id = data['subtask_id']
if self.subtask_id and self.subtask_id == subtask_id:
import struct
from urllib import unquote
try:
username = unquote ( self.users[address] )
except:
username = '匿名用户'
# if data:
# data = str ( '【' + username + '说】' + data )
# else:
# return False
token = "\x81"
length = len ( str_data )
if length < 126:
print '126'
token += struct.pack ( "B", length )
elif length <= 0xFFFF:
print '0xFFFF'
token += struct.pack ( "!BH", 126, length )
else:
print '!BQ'
token += struct.pack ( "!BQ", 127, length )
print 'token=%s' % token
# struct为Python中处理二进制数的模块,二进制流为C,或网络流的形式。
str_data = '%s%s' % (token, str_data)
print str_data
try:
# for key, val in self.clients.iteritems ():
# print
# client = val
# try:
# print 'sned=%s' % data
# client.send(data)
# except:
# self.close_client ( key )
client = self.clients[address]
client.send ( str_data )
except:
pass
else:
pass
else:
pass
def send_data(self, data, address):
subtask_id=None
try:
if type(data) is str:
dict_data = json.loads (data)
if type(dict_data) is dict:
if dict_data.has_key('subtask_id'):
subtask_id = dict_data['subtask_id']
#if self.subtask_id is None or self.subtask_id != subtask_id:
# subtask_id = None
except:
subtask_id=None
try:
current_id=self.subtaskids[address]
except:
current_id=None
if subtask_id is None or current_id is None or current_id != subtask_id:
return
import struct
from urllib import unquote
try:
username = unquote ( self.users[address] )
except:
username = '匿名用户'
#if data:
# data = str ( '【' + username + '说】' + data )
#else:
# return False
token = "\x81"
length = len ( data )
if length < 126:
print '126'
token += struct.pack ( "B", length )
elif length <= 0xFFFF:
print '0xFFFF'
token += struct.pack ( "!BH", 126, length )
else:
print '!BQ'
token += struct.pack ( "!BQ", 127, length )
print 'token=%s' % token
# struct为Python中处理二进制数的模块,二进制流为C,或网络流的形式。
data = '%s%s' % (token, data)
#print data
try:
#for key, val in self.clients.iteritems ():
# print
# client = val
# try:
# print 'sned=%s' % data
# client.send(data)
# except:
# self.close_client ( key )
client = self.clients[address]
client.send ( data )
except:
pass
def close_client(self, address):
......@@ -224,7 +246,11 @@ class Server ():
client = self.clients.pop ( address )
self.stops.append ( address )
client.close ()
del self.users[address]
thr = self.thrs.pop ( address )
thr.join ()
self.subtaskids.pop(address)
except:
pass
......@@ -238,4 +264,4 @@ class Server ():
#if __name__ == '__main__':
# c = Server ()
# c.listen_client ()
\ No newline at end of file
# c.listen_client ()
No preview for this file type
......@@ -57,7 +57,7 @@ def init():
database._init()
dict_p._init()
dict_p.set_value(dictProperties)
con = fdb.connect ( host='192.168.9.239', database='/var/lib/firebird/2.5/data/little_star.fdb', user='VION_FDB',password='vion',charset='UTF8' )
con = fdb.connect ( host='192.168.88.189', database='/var/lib/firebird/2.5/data/little_star.fdb', user='SYSDBA',password='9512d49b',charset='UTF8' )
cur = con.cursor ()
print (con)
database.set_value(con)
......@@ -84,7 +84,7 @@ def init():
if __name__=='__main__':
dict_p._init ()
dict_p.set_value ( dictProperties )
init()
#init()
_h=dictProperties['tx1_host']
_p=int(dictProperties['tx1_ws_port'])
etl.eventToLocal.setRootPath(dictProperties['save_root_path'])
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!