Example #1
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'])
    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  #恢复不报警状态
Example #2
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  #恢复不报警状态
Example #3
0
def test1(ip,
          port,
          mobile,
          deviceid,
          vnum,
          name,
          qualification,
          attach,
          filepath,
          i=0,
          tal=0):

    ip = str(ip)
    port = str(port)
    mobile = str(mobile)
    deviceid = str(deviceid)

    #读取传感器参数
    pdict, sichuandict, ex808dict, sensordict, bluetoothdict = readcig.readtestfile(
    )
    """
    需要上传的附加信息或基于0200的扩展信息;十进制数,0或不填写表示不上传对应附加信息
    1.extrainfo_id:为808附加信息及音视频报警扩展信息
    2.idlist:外设及传感器附加信息
    3.wsid:主动安全报警附加信息
    """
    extrainfo_id = [
        1, 2, 3, 20, 21, 22, 23, 24, 48, 49
    ]  #[1,48,49]  # [1,2,3,20,21,22,23,24,48,49]#传入需要组装的附件信息ID,不传表示无附加信息;1:里程,2:油量,3:速度,48:信号强度,49:卫星颗数,20:视频相关报警,21:视频信号丢失报警状态,22:视频信号遮挡报警状态,23:存储器故障报警状态,24:异常驾驶行为报警详细描述

    #上传wifi数据时,必须同时上传基站数据,上传基站数据,0200状态要为未定位
    idlist = [
        8
    ]  # [34, 39, 65,69,79,80,81,83,112,128],传入需要组装的传感器ID,十进制数;33,34,35,36,37:温度;38,39,40,41:湿度;65,66,67,68:油量、液位;69,70:油耗;79:电量检测,80:终端检测;81:正反转;83:里程;84:蓝牙信标;112,113:载重;128,129:工时;8:基站数据;8、9:wifi数据
    wsid = [225]  # 上传的主动安全报警类型;0: 表示不带主动安全数据;
    # 北京主动安全数据:81,82;
    # 中位主动安全数据:225-231
    # 冀标主动安全数据:100、101
    # 川标主动安全数据:100:驾驶辅助功能报警信息;101:驾驶员行为监测功能报警信息;102:轮胎状态监测报警信息;103:盲区监测报警信息;112:激烈驾驶报警信息;(平台不支持--113:卫星定位系统报警信息);
    # 桂标主动安全数据:100驾驶辅助、101驾驶员行为监测、102轮胎状态监测、112激烈驾驶(平台不支持103盲区监测)
    # 苏标主动安全数据:100驾驶辅助、101驾驶员行为监测、102轮胎状态监测、103盲区监测
    # 浙标主动安全数据:
    # 吉标主动安全数据:
    # 陕标主动安全数据:
    # 沪标主动安全数据:100驾驶辅助、101驾驶员行为监测、103盲区监测、104不按规定上下客及超员检测(808-2019协议)
    # 赣标主动安全数据:100驾驶辅助、101驾驶员行为监测、103盲区监测 (102协议中没有对应格式,不支持)

    link = tp.tcp_link(ip, port)
    # 注册、鉴权、心跳
    upload_location.initial(tp, link, deviceid, vnum, mobile, pdict['version'])

    tal = int(tal) + 30
    time1 = ''
    c = threading.RLock()

    def f():
        with c:
            date = datetime.datetime.strptime(
                pdict['detester'], "%Y-%m-%d %H:%M:%S"
            )  # _strptime方法不支持多线程,运行时会报错:AttributeError: _strptime
            time1 = (
                date +
                datetime.timedelta(seconds=int(tal))).strftime("%y%m%d%H%M%S")

    # 发送驾驶员信息
    statu = 1  #0x01:从业资格证 IC 卡插入(驾驶员上班); 0x02:从业资格证 IC 卡拔出(驾驶员下班)
    result = 0  #0x00:IC 卡读卡成功;0x01:读卡失败,原因为卡片密钥认证未通过;0x02:读卡失败,原因为卡片已被锁定; 0x03:读卡失败,原因为卡片被拔出; 0x04:读卡失败,原因为数据校验错误。
    institutions = "重庆市渝中区大坪"  #发证机构名称

    ###########     需要补传驾驶员信息,最后一个参数为time1,实时上传改为0或去掉 #############################
    drivers = tp.driver_information(mobile, statu, result, name, qualification,
                                    institutions, pdict['version'], 0)
    tp.send_data(link, drivers)

    #设置redis里程,传入车辆id,公共参数ex808dict
    vehicle_id = getmysql_vehicleid.get_vehicleid('192.168.24.142', 'root',
                                                  'Zwkj@123Mysql', 'clbs',
                                                  vnum)
    print vehicle_id
    # setMileage.setto_redismel(vehicle_id,ex808dict,pdict['redishost'],pdict['db'],pdict['pwd'])
    # print "redis mel: "+str(ex808dict['mel'])

    #获取redis15分区namespace GROUPINFO->10000下的数据
    rd = getdb_value.get_15partition_keys('192.168.24.105', 15, pdict['pwd'],
                                          'GROUPINFO:10000:53552631119085568')
    print rd
    #数据库操作    # dbop = db_operation.interface_db.interface_db()
    # print dbop.mysqldata('select * from paas_monitorInfo')

    auto = 0
    # 为0不跑自动化脚本,为1要跑自动化脚本
    aa = 0
    if auto == 1:  # auto == 1,则要跑自动化脚本
        auto_test(tp, link, mobile, vnum)
    elif (pdict['ti'] != 0):  # 补传数据
        wsid1 = []
        wsid1, excel_list_k = buchuan1.deal_data(
            pdict, sichuandict, ex808dict, sensordict, bluetoothdict, wsid1,
            i)  #读取excel表格数据,改变速度、初始里程、报警事件
        buchuan1.upload(tp, link, mobile, pdict, sichuandict, ex808dict,
                        sensordict, bluetoothdict, extrainfo_id, idlist, wsid1,
                        excel_list_k, deviceid, port, tal)

    elif aa == 1:  #数据准备,也要根据情况设置extrainfo_id,idlist ,wsid,该绑定传感器的要到平台绑定传感器
        print "数据准备开始"
        dataready_test.datatest(tp, link, mobile, extrainfo_id, idlist, wsid,
                                deviceid, port, vehicle_id)
        print "准备数据完成"

    else:  # 正常上传位置信息
        upload_location.location(tp, link, mobile, pdict, sichuandict,
                                 ex808dict, sensordict, bluetoothdict,
                                 extrainfo_id, idlist, wsid, deviceid, port)
        res = tp.receive_data(link)
        print "上线成功,维持中"
        time.sleep(1)

    print "ok"

    # 控制第x次通用应答响应
    x = 0
    while True:
        # 控制发送位置报文间隔
        t = int(time.strftime("%H%M%S", time.localtime()))
        while True:
            if abs(int(time.strftime("%H%M%S", time.localtime())) -
                   t) >= pdict['period']:
                ex808dict['mel'] += 1
                sensordict['AD'] += 1
                sensordict['Oil'] += 1
                pdict['high'] += 1
                pdict['jin'] += 0.001
                pdict['wei'] += 0.001
                sichuandict['event'] += 1
                if (sichuandict['event'] == 9):
                    sichuandict['event'] = 16
                elif (sichuandict['event'] == 19):
                    sichuandict['event'] = 1
                    if (wsid[0] == 100):
                        wsid[0] = 101
                    elif (wsid[0] == 101):
                        wsid[0] = 112
                    elif (wsid[0] == 112):
                        wsid[0] = 100
                    #如果是中位标准,可以先注释以上6行代码,开启下面的判断
                    # if (wsid[0] == 225):
                    #     wsid[0] = 226
                    # elif (wsid[0] == 226):
                    #     wsid[0] = 227
                    # elif (wsid[0] == 227):
                    #     wsid[0] = 228
                    # elif (wsid[0]) == 228:
                    #     wsid[0] == 225
                upload_location.location(tp, link, mobile, pdict, sichuandict,
                                         ex808dict, sensordict, bluetoothdict,
                                         extrainfo_id, idlist, wsid, deviceid,
                                         port)
                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, ex808dict, sensordict, info, extrainfo_id,idlist, wsid, answer_number, res, id, reno)
                        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, i, 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
                    elif id == '9208':
                        th = threading.Thread(
                            target=attach_upload.attach_upload,
                            args=(ip, tp, res, mobile, attach, filepath,
                                  pdict['version']))
                        th.start()

                    else:
                        reply.reply(tp, link, res, mobile, id, answer_number,
                                    reno, pdict['version'])

                except:
                    pass
    tp.close(link)
Example #4
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
Example #6
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'])
    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
Example #7
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'])
    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
Example #8
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'])
    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