def main(args, testinfo, tp, link, mobile, extrainfo_id, idlist, wsid, deviceid, port, vehicle_id): pdict, sichuandict, ex808dict, sensordict, bluetoothdict = readcig.readtestfile( ) # 设置redis里程,传入车辆id,公共参数pdict setMileage.setto_redismel(vehicle_id, ex808dict, pdict['redishost'], pdict['db'], pdict['pwd']) excel_list = readexcel() alarmstatus = 0 for datalow in excel_list[0:7]: alarmstatus += datalow[1] * (2**datalow[2]) # print "vedio_alarm:"+str(alarmstatus) ex808dict['vedio_alarm'] = alarmstatus #给视频相关报警的变量赋值 ex808dict['vedio_signal'] = 3 ex808dict['memery'] = 2 ex808dict['abnormal_driving'] = 4 upload_location.location(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port) print "######### 普货报表数据准备完成 #######" pdict['vedio_alarm'] = 0 #恢复不报警状态
def main(args, testinfo, tp, link, mobile, extrainfo_id, idlist, wsid, deviceid, port, vehicle_id): pdict, sichuandict, ex808dict, sensordict, bluetoothdict = readcig.readtestfile( ) #每次都有testconfig中的初始值,不带上一个模块设置的值过来 # 设置redis里程,传入车辆id,公共参数pdict setMileage.setto_redismel(vehicle_id, ex808dict, pdict['redishost'], pdict['db'], pdict['pwd']) excel_list = readexcel() alarmstatus = 0 for datalow in excel_list[0:29]: alarmstatus += datalow[1] * (2**datalow[2]) pdict['alarm'] = alarmstatus if excel_list[30:31][0][1] == 1: sensordict['warn'] = excel_list[30:31][0][2] #温度 if excel_list[31:32][0][1] == 1: sensordict['warn'] = excel_list[31:32][0][2] #湿度 if excel_list[32:33][0][1] == 1: #里程超速 sensordict['speed'] = int(excel_list[32:33][0][2]) if excel_list[33:34][0][1] == 1: data = str(excel_list[33:34][0][2]).split('|') #油量,加油报警 sensordict['addoil'] = data[1] sensordict['Oil'] = data[0] if excel_list[35:36][0][1] == 1: #正反转 sensordict['zts'] = 2 sensordict['fx'] = 2 if excel_list[37:38][0][1] == 1: #载重 sensordict['datalen'] = 1 if excel_list[36:37][0][1] == 1: #工时 sensordict['gslen'] = '01' upload_location.location(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port) print "######### 报警报表数据准备完成 #######" pdict['alarm'] = 0 #恢复不报警状态
def main(args, testinfo, tp, link, mobile, extrainfo_id, idlist, wsid, deviceid, port, vehicle_id): pdict, sichuandict, ex808dict, sensordict, bluetoothdict = readcig.readtestfile( ) # 设置redis里程,传入车辆id,公共参数pdict setMileage.setto_redismel(vehicle_id, ex808dict, pdict['redishost'], pdict['db'], pdict['pwd']) # ex808dict['mel']=100 pdict['speed'] = 80 sensordict['oilsp'] = 10 print "######### 开始上传位置报表数据 #######" # 控制第x次通用应答响应 x = 0 k = 0 while True: # 控制发送位置报文间隔 t = int(time.strftime("%H%M%S", time.localtime())) if k > 100: print "######### 位置报表数据准备完成 #######" idlist = [] break while True: if k > 100: break if abs(int(time.strftime("%H%M%S", time.localtime())) - t) >= pdict['period']: if k < 10: sensordict['tio'] += 10 sensordict['oilsp'] += 2 pdict['speed'] += 1 ex808dict['mel'] += 1 elif k > 10 and k < 20: # 怠速 sensordict['tio'] += 2 sensordict['oilsp'] += 1 pdict['speed'] = 4 ex808dict['mel'] += 1 elif k > 20 and k < 30: # 行驶 if k == 21: pdict['speed'] = 50 sensordict['tio'] += 10 sensordict['oilsp'] += 2 pdict['speed'] += 1 ex808dict['mel'] += 1 elif k > 40 and k < 50: #怠速 sensordict['tio'] += 2 sensordict['oilsp'] += 1 pdict['speed'] = 3 ex808dict['mel'] += 1 elif k > 50 and k < 60: # 行驶 if k == 51: pdict['speed'] = 30 sensordict['tio'] += 10 sensordict['oilsp'] += 2 pdict['speed'] += 1 ex808dict['mel'] += 1 elif k > 60 and k < 70: # 怠速 sensordict['tio'] += 2 sensordict['oilsp'] += 1 pdict['speed'] = 3 ex808dict['mel'] += 1 elif k > 70 and k < 100: # 行驶 if k == 71: pdict['speed'] = 30 sensordict['tio'] += 10 sensordict['oilsp'] += 2 pdict['speed'] += 1 ex808dict['mel'] += 1 pdict['high'] += 1 pdict['jin'] += 0.001 pdict['wei'] += 0.001 upload_location.location(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port) k += 1 res = tp.receive_data(link) res = tp.dd(res) # 切割响应 list = ano_res(res) # 判断响应并根据响应id回复 for j in list: # 根据下发报文判断需要响应内容 id = res[2:6] # 应答流水号 if pdict['version'] == 0: answer_number = res[22:26] elif pdict['version'] == 1: answer_number = res[32:36] reno = "00" if id in ["8201", "8202", "8802", "8500"]: reply_position.reply_pos(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port, answer_number, res, id, reno) else: reply.reply(tp, link, res, mobile, id, answer_number, reno, pdict['version']) t = int(time.strftime("%H%M%S", time.localtime())) else: try: reno = "00" res = tp.receive_data(link) res = tp.dd(res) id = res[2:6] # 应答流水号 if pdict['version'] == 0: answer_number = res[22:26] elif pdict['version'] == 1: answer_number = res[32:36] # 切割响应 #list=ano_res(res) if id in ["8201", "8202", "8802", "8500"]: try: reply_position.reply_pos( tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port, answer_number, res, id, reno) except Exception as e: print e else: reply.reply(tp, link, res, mobile, id, answer_number, reno, pdict['version']) except: pass
def main(args, testinfo, tp, link, mobile, extrainfo_id, idlist, wsid, deviceid, port, vehicle_id): pdict, sichuandict, ex808dict, sensordict, bluetoothdict = readcig.readtestfile( ) # 设置redis里程,传入车辆id,公共参数pdict setMileage.setto_redismel(vehicle_id, ex808dict, pdict['redishost'], pdict['db'], pdict['pwd']) datalist = [] datalist = readexcel() print "datalist start:\n" print datalist statuslist = datalist[0][1:] jinlist = datalist[1][1:] weilist = datalist[2][1:] wnlist = datalist[3][1:] interrupt_num = datalist[4][1:] interrupt_drift = datalist[5][1:] lasttime = datalist[6][1:] jin = pdict['jin'] wei = pdict['wei'] pdict['status'] = statuslist[0] pdict['jin'] = jin if jinlist[0] == 1 else jinlist[0] pdict['wei'] = wei if weilist[0] == 1 else weilist[0] ex808dict['wn'] = wnlist[0] # ex808dict['mel']=177 print "######### 车辆定位统计数据准备开始 #######" #初始值完后上传一次位置 upload_location.location(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port) # 控制第x次通用应答响应 x = 0 mm = 0 kk = 0 isover = False while True: # 控制发送位置报文间隔 t = int(time.strftime("%H%M%S", time.localtime())) if isover == True: print "######### 车辆定位统计数据准备完成 #######" break while True: tomorrow = datetime.datetime.replace(datetime.datetime.now() + datetime.timedelta(days=1), hour=0, minute=0, second=0) if (tomorrow - datetime.datetime.now()).seconds == 0: #如果到每天零点,里程设为100 ex808dict['mel'] = 100 # ##持续超速统计 if abs(int(time.strftime("%H%M%S", time.localtime())) - t) >= pdict['period']: if interrupt_num[mm] != 0: pdict['status'] = 1 if interrupt_drift[ mm] != 0: ###如果有中断,经纬度变化大点以便离线位移时位移大于50km pdict['jin'] += 0.2 pdict['wei'] += 0.2 if kk * pdict['period'] % (30 * 60) == 0: pdict['status'] = 3 #变成定位 elif interrupt_drift[mm] == 0 and kk * pdict['period'] % ( 10 * 60) == 0: pdict['status'] = 3 # 变成定位 else: pdict['status'] = 1 # if kk*pdict['period']==(int(lasttime[mm]) * 60+pdict['period']): # pdict['speed'] = setspeed - 10 if kk * pdict['period'] == (int(lasttime[mm]) * 60 + pdict['period']): mm += 1 if pdict['jin'] != 0 and pdict['wei'] != 0: jin = pdict['jin'] #如果遍历完一种上传,下一种的经纬度从此经纬度开始 wei = pdict['wei'] if mm == len(statuslist): #如果已经遍历完了 print "上传数据结束了..." isover = True break print "######### 下一个阶段数据开始 #######" pdict['status'] = statuslist[mm] pdict['jin'] = jin if jinlist[mm] == 1 else float( jinlist[mm]) pdict['wei'] = wei if weilist[mm] == 1 else float( weilist[mm]) ex808dict['wn'] = wnlist[mm] kk = 0 if pdict['jin'] != 0 and pdict['wei'] != 0: pdict['jin'] += 0.001 pdict['wei'] += 0.001 ex808dict['mel'] += 0.5 upload_location.location(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port) kk += 1 res = tp.receive_data(link) res = tp.dd(res) # 切割响应 list = ano_res(res) # 判断响应并根据响应id回复 for j in list: # 根据下发报文判断需要响应内容 id = res[2:6] # 应答流水号 if pdict['version'] == 0: answer_number = res[22:26] elif pdict['version'] == 1: answer_number = res[32:36] reno = "00" if id in ["8201", "8202", "8802", "8500"]: reply_position.reply_pos(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port, answer_number, res, id, reno) else: reply.reply(tp, link, res, mobile, id, answer_number, reno, pdict['version']) t = int(time.strftime("%H%M%S", time.localtime())) else: try: reno = "00" res = tp.receive_data(link) res = tp.dd(res) id = res[2:6] # 应答流水号 if pdict['version'] == 0: answer_number = res[22:26] elif pdict['version'] == 1: answer_number = res[32:36] # 切割响应 #list=ano_res(res) if id in ["8201", "8202", "8802", "8500"]: try: reply_position.reply_pos( tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port, answer_number, res, id, reno) except Exception as e: print e else: reply.reply(tp, link, res, mobile, id, answer_number, reno, pdict['version']) except: pass
def main(args, testinfo, tp, link, mobile, extrainfo_id, idlist, wsid, deviceid, port, vehicle_id): pdict, sichuandict, ex808dict, sensordict, bluetoothdict = readcig.readtestfile( ) # 设置redis里程,传入车辆id,公共参数pdict setMileage.setto_redismel(vehicle_id, ex808dict, pdict['redishost'], pdict['db'], pdict['pwd']) datalist = readexcel() maxspeed = datalist[0][1] lasttime = datalist[1][1] pdict['speed'] = maxspeed tt = int(time.strftime("%H%M%S", time.localtime())) #初始值完后上传一次位置 upload_location.location(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port) # print sensordict # 控制第x次通用应答响应 x = 0 kk = 0 isover = False while True: # 控制发送位置报文间隔 t = int(time.strftime("%H%M%S", time.localtime())) if isover == True: print "######### 车辆异动统计数据准备完成 #######" break while True: # ##持续超速统计 if abs(int(time.strftime("%H%M%S", time.localtime())) - t) >= pdict['period']: if kk * pdict['period'] > (int(lasttime) * 60): isover = True break pdict['jin'] += 0.001 pdict['wei'] += 0.001 ex808dict['mel'] += 0.5 upload_location.location(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port) kk += 1 res = tp.receive_data(link) res = tp.dd(res) # 切割响应 list = ano_res(res) # 判断响应并根据响应id回复 for j in list: # 根据下发报文判断需要响应内容 id = res[2:6] # 应答流水号 if pdict['version'] == 0: answer_number = res[22:26] elif pdict['version'] == 1: answer_number = res[32:36] reno = "00" if id in ["8201", "8202", "8802", "8500"]: reply_position.reply_pos(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port, answer_number, res, id, reno) else: reply.reply(tp, link, res, mobile, id, answer_number, reno, pdict['version']) t = int(time.strftime("%H%M%S", time.localtime())) else: try: reno = "00" res = tp.receive_data(link) res = tp.dd(res) id = res[2:6] # 应答流水号 if pdict['version'] == 0: answer_number = res[22:26] elif pdict['version'] == 1: answer_number = res[32:36] # 切割响应 #list=ano_res(res) if id in ["8201", "8202", "8802", "8500"]: try: reply_position.reply_pos( tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port, answer_number, res, id, reno) except Exception as e: print e else: reply.reply(tp, link, res, mobile, id, answer_number, reno, pdict['version']) except: pass
def main(args, testinfo, tp, link, mobile, extrainfo_id, idlist, wsid, deviceid, port, vehicle_id): pdict, sichuandict, ex808dict, sensordict, bluetoothdict = readcig.readtestfile( ) # 设置redis里程,传入车辆id,公共参数pdict setMileage.setto_redismel(vehicle_id, ex808dict, pdict['redishost'], pdict['db'], pdict['pwd']) datalist = readexcel() #从excel中获取参数 drivertime = datalist[0][1:] driverspeed = datalist[1][1:] resttime = datalist[2][1:] restspeed = datalist[3][1:] print "驾驶时间" + str(drivertime[0]) print "驾驶速度" + str(driverspeed[0]) print "休息时间" + str(resttime[0]) print "休息速度" + str(restspeed[0]) print "上报间隔" + str(pdict['period']) pdict['speed'] = driverspeed[0] tt = int(time.strftime("%H%M%S", time.localtime())) #初始值完后上传一次位置 # upload_location.location(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, # extrainfo_id, idlist, wsid, deviceid, port) # print sensordict # 控制第x次通用应答响应 x = 0 k = 1 mm = 0 kk = 0 isover = False while True: # 控制发送位置报文间隔 t = int(time.strftime("%H%M%S", time.localtime())) print "开始时间" + str(t) if isover == True: print "######### 疲劳报警统计数据准备完成 #######" break while True: # 疲劳驾驶数据 if abs(int(time.strftime("%H%M%S", time.localtime())) - t) >= pdict['period']: print "开始发送数据" if kk * pdict['period'] > (int( drivertime[mm]) * 60): #如果驾驶持续时间大于设置的持续驾驶时间,将速度设置为休息速度 ti = int(drivertime[mm]) print("-------------司机已持续驾驶%d分钟,现在是休息状态--------" % ti) pdict['speed'] = restspeed[0] if (kk * pdict['period']) - (int(drivertime[mm]) * 60) > ( int(resttime[mm]) * 60): #如果休息时间大于设置的休息时间,将速度设置为驾驶速度 tii = int(resttime[mm]) print("----------司机已经休息%d分钟,现在是行驶状态——————" % tii) mm += 1 if mm == len(driverspeed): # 如果已经遍历完了 isover = True break pdict['speed'] = driverspeed[mm] kk = 0 elif kk * pdict['period'] <= (int(drivertime[mm]) * 60): print "驾驶时间未达到门限,继续行驶" pdict['jin'] += 0.001 pdict['wei'] += 0.001 ex808dict['mel'] += 0.5 n = 0 upload_location.location(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port) k += 1 kk += 1 print kk res = tp.receive_data(link) res = tp.dd(res) # 切割响应 list = ano_res(res) # 判断响应并根据响应id回复 for j in list: # 根据下发报文判断需要响应内容 id = res[2:6] # 应答流水号 if pdict['version'] == 0: answer_number = res[22:26] elif pdict['version'] == 1: answer_number = res[32:36] reno = "00" if id in ["8201", "8202", "8802", "8500"]: reply_position.reply_pos(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port, answer_number, res, id, reno) else: reply.reply(tp, link, res, mobile, id, answer_number, reno, pdict['version']) t = int(time.strftime("%H%M%S", time.localtime())) else: try: reno = "00" res = tp.receive_data(link) res = tp.dd(res) id = res[2:6] # 应答流水号 if pdict['version'] == 0: answer_number = res[22:26] elif pdict['version'] == 1: answer_number = res[32:36] # 切割响应 #list=ano_res(res) if id in ["8201", "8202", "8802", "8500"]: try: reply_position.reply_pos( tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port, answer_number, res, id, reno) except Exception as e: print e else: reply.reply(tp, link, res, mobile, id, answer_number, reno, pdict['version']) except: pass
def main(args, testinfo, tp, link, mobile, extrainfo_id, idlist, wsid, deviceid, port, vehicle_id): pdict, sichuandict, ex808dict, sensordict, bluetoothdict = readcig.readtestfile( ) # 设置redis里程,传入车辆id,公共参数pdict setMileage.setto_redismel(vehicle_id, ex808dict, pdict['redishost'], pdict['db'], pdict['pwd']) datalist = readexcel() keylist = [] start_value = [] change_value = [] max_value = [] ##设置初始值 for data in datalist: keylist.append(data[1]) start_value.append(data[2]) change_value.append(data[3]) max_value.append(data[4]) for m in range(len(keylist)): if re.findall(r'^\d+\.\d+$', str(start_value[m]), re.I) != []: sensordict[keylist[m]] = float(start_value[m]) else: sensordict[keylist[m]] = int(start_value[m]) #初始值完后上传一次位置 upload_location.location(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port) # print sensordict # 控制第x次通用应答响应 x = 0 k = 1 while True: # 控制发送位置报文间隔 t = int(time.strftime("%H%M%S", time.localtime())) if k > 20: print "######### 传感器报表数据准备完成 #######" break while True: if k > 20: break if abs(int(time.strftime("%H%M%S", time.localtime())) - t) >= pdict['period']: pdict['jin'] += 0.001 pdict['wei'] += 0.001 n = 0 ##变化值 for n in range(len(keylist)): if max_value[n] == '': sensordict[keylist[n]] += int(change_value[n]) elif sensordict[keylist[n]] < int(max_value[n]): sensordict[keylist[n]] += int(change_value[n]) else: if re.findall(r'^\d+\.\d+$', str(start_value[n]), re.I) != []: sensordict[keylist[n]] = float(start_value[n]) else: sensordict[keylist[n]] = int(start_value[n]) upload_location.location(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port) k += 1 res = tp.receive_data(link) res = tp.dd(res) # 切割响应 list = ano_res(res) # 判断响应并根据响应id回复 for j in list: # 根据下发报文判断需要响应内容 id = res[2:6] # 应答流水号 if pdict['version'] == 0: answer_number = res[22:26] elif pdict['version'] == 1: answer_number = res[32:36] reno = "00" if id in ["8201", "8202", "8802", "8500"]: reply_position.reply_pos(tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port, answer_number, res, id, reno) else: reply.reply(tp, link, res, mobile, id, answer_number, reno, pdict['version']) t = int(time.strftime("%H%M%S", time.localtime())) else: try: reno = "00" res = tp.receive_data(link) res = tp.dd(res) id = res[2:6] # 应答流水号 if pdict['version'] == 0: answer_number = res[22:26] elif pdict['version'] == 1: answer_number = res[32:36] # 切割响应 #list=ano_res(res) if id in ["8201", "8202", "8802", "8500"]: try: reply_position.reply_pos( tp, link, mobile, pdict, sichuandict, ex808dict, sensordict, bluetoothdict, extrainfo_id, idlist, wsid, deviceid, port, answer_number, res, id, reno) except Exception as e: print e else: reply.reply(tp, link, res, mobile, id, answer_number, reno, pdict['version']) except: pass