コード例 #1
0
    def alarm_file_info(self):
        device_id = str2hex(communication_id[-7:], 7)
        info_type = '00'
        attachment_num = '04'
        file_info_list = ''
        alarm_type = alarm_flag_alarm_type.get(self.alarm_flag)
        if alarm_type:
            alarm_flag_alarm_type.pop(self.alarm_flag)
        self.file_path = os.path.join(self.file_path, alarm_type)
        self.file_list = os.listdir(self.file_path)
        for file in self.file_list:
            name, file_type = file.split('.')
            name_list = name.split('_')
            name_list[1] = alarm_type[:2]
            name_list[2] = alarm_type
            name_list[-1] = bytes.fromhex(self.alarm_no).decode('gbk')
            new_file = '_'.join(name_list)
            new_file = new_file + '.' + file_type
            os.rename(os.path.join(self.file_path, file),
                      os.path.join(self.file_path, new_file))
            index = self.file_list.index(file)
            self.file_list[index] = new_file
            file_name_len = len(new_file)
            file_name = str2hex(new_file, file_name_len)
            file_size = os.path.getsize(os.path.join(self.file_path, new_file))
            file_info_list += num2big(file_name_len, 1) + file_name + num2big(
                file_size, 4)

        msg_body = device_id + self.alarm_flag + self.alarm_no + info_type + attachment_num + file_info_list
        body = '1210' + calc_length_su_ter(
            msg_body) + communication_id + num2big(get_serial_no()) + msg_body
        data = '7E' + body + calc_check_code(body) + '7E'
        log_file.debug('—————— 报警附件信息 ——————')
        send_queue_file.put(data)
コード例 #2
0
def parse_query_terminal_para(data):
    msg_body = data[12:-1]
    serial_no = data[10:12]

    para_num = big2num(byte2str(msg_body[0:1]))
    para_body = msg_body[1:]
    para_id_list = []
    para_data_list = ''
    for n in range(para_num):
        para_id = byte2str(para_body[n * 4:(n + 1) * 4])
        para_id_list.append(para_id)
        para_data = para_data_content.get(para_id)
        para_data_list = para_data_list + para_id + num2big(
            len(para_data) // 2, 1) + para_data

    log_data.debug('—————— 查询终端参数 ——————')
    log_data.debug('参数总数 {}'.format(para_num))
    log_data.debug('参数列表 {}'.format(', '.join(para_id_list)))
    log_data.debug('—————— END ——————')

    msg_body = byte2str(serial_no) + num2big(para_num, 1) + para_data_list
    body = '0104' + calc_length_su_ter(msg_body) + communication_id + num2big(
        get_serial_no()) + msg_body
    data = '7E' + body + calc_check_code(body) + '7E'
    send_queue.put(data)
コード例 #3
0
 def run(self):
     log_data.debug(threading.current_thread().getName())
     while True:
         while not location_queue.empty():
             location_data = location_queue.get_nowait()
             status, latitude, longitude, speed, report_time, mileage = location_data
             alarm_flag = '00000000'
             height = '0000'
             direction = '0000'
             # status = '00000003'
             # latitude = '0157CB96'
             # longitude = '06CA9628'
             # speed = num2big(880, 2)
             # report_time = '200206221122'
             msg_body = alarm_flag + status + latitude + longitude + height + speed + direction + report_time + '0104' + mileage
             body = '0200' + calc_length_su_ter(
                 msg_body) + self.device_id + num2big(
                     get_serial_no()) + msg_body
             data = '7E' + body + calc_check_code(body) + '7E'
             send_queue.put(data)
             msg_body = ''
             body = '0002' + calc_length_su_ter(
                 msg_body) + self.device_id + num2big(
                     get_serial_no()) + msg_body
             data = '7E' + body + calc_check_code(body) + '7E'
             send_queue.put(data)
             time.sleep(0.1)
コード例 #4
0
 def send_driver_face_info(self):
     rs = xlrd.open_workbook(self.face_case_name)
     table = rs.sheets()[0]
     cols = table.ncols
     face_info_list = ''
     for n in range(1, cols + 1, 4):
         data_len = table.col_values(n)[1:]
         data_content = table.col_values(n + 1)[1:]
         self.file_list.append(data_content[5])
         deal_data = list(map(read_value, data_content))
         data = list(map(data2hex, deal_data, data_len))
         if self.modify_info_mask:
             face_info_list += num2big(self.modify_info_mask, 1)
         face_info_list += ''.join(data)
     if self.modify_info_mask == 0:
         msg_body = '033D' + '65' + 'E9' + '00' + num2big(
             len(self.file_list), 2) + face_info_list
         data = '7E' + calc_check_code(msg_body) + num2big(
             GlobalVar.get_serial_no()) + msg_body + '7E'
         send_queue.put(data)
     else:
         msg_body = '033D' + '65' + 'E9' + '03' + num2big(
             len(self.file_list), 2) + face_info_list
         data = '7E' + calc_check_code(msg_body) + num2big(
             GlobalVar.get_serial_no()) + msg_body + '7E'
         send_queue.put(data)
コード例 #5
0
    def file_info_upload(self, file):
        file_name_len = len(file)
        file_name = str2hex(file, file_name_len)
        file_type = os.path.splitext(file)[-1]
        if file_type == '.jpg':
            file_type = '00'
        elif file_type == '.mp4':
            file_type = '02'
        file_size = os.path.getsize(os.path.join(self.file_path, file))

        msg_body = num2big(file_name_len, 1) + file_name + file_type + num2big(
            file_size, 4)
        body = '1211' + calc_length_su_ter(
            msg_body) + communication_id + num2big(get_serial_no()) + msg_body
        data = '7E' + body + calc_check_code(body) + '7E'
        log_file.debug('—————— 文件信息上传 {} ——————'.format(file))
        send_queue_file.put(data)
コード例 #6
0
    def send_driver_face_data(self, file):
        file_name_len = num2big(len(file), 1)
        file_name = byte2str(file.encode('utf-8'))
        file_type = '00'
        path = os.path.join(self.file_path, file)
        with open(path, 'rb') as f:
            file_content = f.read()
            file_size = num2big(len(file_content), 4)
            code = num2big(sum(file_content))[-2:]
        msg_body = '033D' + '65' + 'E8' + file_name_len + file_name + file_type + file_size + code
        data = '7E' + calc_check_code(msg_body) + num2big(
            GlobalVar.get_serial_no()) + msg_body + '7E'
        send_queue.put(data)
        event.clear()
        event.wait()

        file_size_int = big2num(file_size)
        piece = 65536
        r = file_size_int % piece
        pkg_num = file_size_int // piece if r == 0 else (file_size_int //
                                                         piece) + 1

        for x in range(pkg_num):
            offset = x * piece
            if x == pkg_num - 1:
                piece = piece if r == 0 else r
            pkg_no = x
            file_content_piece = file_content[offset:offset + piece]
            msg_body = '033D' + '65' + 'E7' + file_name_len + file_name + num2big(
                pkg_num,
                2) + num2big(pkg_no, 2) + num2big(offset, 4) + num2big(
                    piece, 4) + byte2str(file_content_piece)
            data = '7E' + calc_check_code(msg_body) + num2big(
                GlobalVar.get_serial_no()) + msg_body + '7E'

            logger.debug(
                '—————— 人脸数据下发 {}   文件大小 {} 包总数 {} 包序号 {} 偏移量 {} 数据长度 {} ——————'
                .format(file, file_size_int, pkg_num, pkg_no, offset, piece))
            send_queue.put(data)

        time.sleep(0.1)
        msg_body = '033D' + '65' + 'E6' + file_name_len + file_name + file_type + file_size
        data = '7E' + calc_check_code(msg_body) + num2big(
            GlobalVar.get_serial_no()) + msg_body + '7E'
        send_queue.put(data)
コード例 #7
0
def comm_reply_su_ter(data, reply_result):
    device_id = data[4:10]
    msg_id = data[0:2]
    serial_no = data[10:12]
    result = reply_result
    msg_body = byte2str(serial_no) + byte2str(msg_id) + result
    body = '0001' + calc_length_su_ter(msg_body) + byte2str(
        device_id) + num2big(get_serial_no()) + msg_body
    data = '7E' + body + calc_check_code(body) + '7E'
    return data
コード例 #8
0
def parse_query_terminal_property():

    log_data.debug('—————— 查询终端属性 ——————')

    terminal_type = '0000'
    maker_id = str2hex('recon', 5)
    terminal_model = str2hex('Reconova_P500', 20)
    terminal_id = str2hex('12_0107', 7)
    sim_iccid = str2hex('1351101122', 10)
    hw_len = 32
    hw = str2hex('This is HardWare.0107', hw_len)
    fw_len = 32
    fw = str2hex('This is FirmWare.', fw_len)
    gnss = '00'
    comm_pro = '00'

    msg_body = terminal_type + maker_id + terminal_model + terminal_id + sim_iccid + num2big(hw_len, 1) + hw + \
               num2big(fw_len, 1) + fw + gnss + comm_pro
    body = '0107' + calc_length_su_ter(msg_body) + communication_id + num2big(
        get_serial_no()) + msg_body
    data = '7E' + body + calc_check_code(body) + '7E'
    send_queue.put(data)
コード例 #9
0
    def file_data_upload(self, file):
        file_size = os.path.getsize(os.path.join(self.file_path, file))
        piece = 65536
        n = file_size // piece
        r = file_size % piece
        with open(os.path.join(self.file_path, file), 'rb') as f:
            file_data = f.read()
        for x in range(n):
            offset = x * piece
            file_data_piece = file_data[offset:offset + piece]
            data = '30316364' + str2hex(file, 50) + num2big(
                offset, 4) + num2big(piece, 4) + byte2str(file_data_piece)
            log_file.debug('—————— 文件数据上传 {}   偏移量 {} 数据长度 {} ——————'.format(
                file, offset, piece))
            send_queue_file.put(data)
        offset = n * piece
        if r:
            piece = r
            file_data_piece = file_data[offset:offset + piece]

            data = '30316364' + str2hex(file, 50) + num2big(
                offset, 4) + num2big(piece, 4) + byte2str(file_data_piece)
            log_file.debug('—————— 文件数据上传 {}   偏移量 {} 数据长度 {} ——————'.format(
                file, offset, piece))
            send_queue_file.put(data)

        file_name_len = len(file)
        file_name = str2hex(file, file_name_len)
        file_type = os.path.splitext(file)[-1]
        if file_type == '.jpg':
            file_type = '00'
        elif file_type == '.mp4':
            file_type = '02'

        import time
        time.sleep(0.5)

        msg_body = num2big(file_name_len, 1) + file_name + file_type + num2big(
            file_size, 4)
        body = '1212' + calc_length_su_ter(
            msg_body) + communication_id + num2big(get_serial_no()) + msg_body
        data = '7E' + body + calc_check_code(body) + '7E'
        log_file.debug('—————— 文件上传完成 {} ——————'.format(file))
        send_queue_file.put(data)
コード例 #10
0
    def run(self):
        log_data.debug(threading.current_thread().getName())
        self.rs = xlrd.open_workbook(self.filename)
        self.table = self.rs.sheets()[0]
        rows = self.table.nrows
        with open("num.txt", 'r') as f:
            num = f.read()
        if not num:
            num = 1
        else:
            num = int(num)
        for case in range(num, rows):
            # 获取字段长度列和字段值列
            data_row = self.table.row_values(case)
            # 获取excel行的数据
            status, latitude, longitude, speed, report_time, mileage = data_row
            if not status:
                status = "00000003"
                latitude = num2big(int(latitude * 1000000), 4)
                longitude = num2big(int(longitude * 1000000), 4)
            else:
                status = "00000001"
                latitude = num2big(0, 4)
                longitude = num2big(0, 4)

            speed = num2big(int(speed * 10), 2)

            if not report_time:
                report_time = datetime.datetime.now().strftime('%y%m%d%H%M%S')
            if not mileage:
                mileage = num2big(int(num), 4)
            location_queue.put(
                (status, latitude, longitude, speed, report_time, mileage))
            with open("num.txt", 'w') as f:
                num = int(num) + 1
                f.write(str(num))
            time.sleep(10)
コード例 #11
0
def parse_query_status(data):
    msg_body = data[12:-1]
    msg_type = byte2str(msg_body[:1])
    log_data.debug('—————— 查询基本信息 ——————')
    msg_num = big2num(byte2str(msg_body[1:2]))
    peripheral_id = byte2str(msg_body[2:3])
    if msg_type == 'F8':

        log_data.debug('参数总数 {}'.format(msg_num))
        log_data.debug('== 查询信息 ==')

        company_name_len = 32
        company_name = str2hex('Reconova', company_name_len)
        product_model_len = 32
        product_model = str2hex('RN-CA-P500', product_model_len)
        hw_len = 32
        hw = str2hex('This is HardWare.0900', hw_len)
        sw_len = 32
        sw = str2hex('This is SoftWare.', sw_len)
        device_id_len = 32
        device_id = str2hex('123456_F8', device_id_len)
        client_code_len = 32
        client_code = str2hex('ABCDEFG', client_code_len)

        msg_info = num2big(company_name_len, 1) + company_name + num2big(product_model_len, 1) + product_model + \
                   num2big(hw_len, 1) + hw + num2big(sw_len, 1) + sw + num2big(device_id_len, 1) + device_id + \
                   num2big(client_code_len, 1) + client_code
        msg_body = msg_type + '01' + peripheral_id + num2big(
            len(msg_info) // 2, 1) + msg_info
        body = '0900' + calc_length_su_ter(
            msg_body) + communication_id + num2big(get_serial_no()) + msg_body
        data = '7E' + body + calc_check_code(body) + '7E'

        send_queue.put(data)

    elif msg_type == 'F9':

        log_data.debug('参数总数 {}'.format(msg_num))
        log_data.debug('== 查询硬件信息 ==')

        msg_info = '00000000'
        msg_body = msg_type + '01' + peripheral_id + num2big(
            len(msg_info) // 2, 1) + msg_info
        body = '0900' + calc_length_su_ter(
            msg_body) + communication_id + num2big(get_serial_no()) + msg_body
        data = '7E' + body + calc_check_code(body) + '7E'

        send_queue.put(data)

    elif msg_type == 'FA':

        log_data.debug('参数总数 {}'.format(msg_num))
        log_data.debug('== 查询软件信息 ==')

        terminal_sim_len = 11
        terminal_sim = str2hex('13811111111', terminal_sim_len)
        signal_level = '00'
        mcu_len = 14
        mcu = str2hex('RN-CA-P500-MCU', mcu_len)
        device_id_len = 32
        device_id = str2hex('123456_FA', device_id_len)
        communicate_id_len = 32
        communicate_id = str2hex('123456', communicate_id_len)

        msg_info = num2big(terminal_sim_len, 1) + terminal_sim + signal_level + num2big(mcu_len, 1) + mcu + \
                   num2big(device_id_len, 1) + device_id + num2big(communicate_id_len, 1) + communicate_id
        msg_body = msg_type + '01' + peripheral_id + num2big(
            len(msg_info) // 2, 1) + msg_info
        body = '0900' + calc_length_su_ter(
            msg_body) + communication_id + num2big(get_serial_no()) + msg_body
        data = '7E' + body + calc_check_code(body) + '7E'

        send_queue.put(data)

    log_data.debug('—————— END ——————')
コード例 #12
0
    '00000001': lambda x: big2num(byte2str(x)),
    '00000002': lambda x: big2num(byte2str(x)),
    '00000003': lambda x: big2num(byte2str(x)),
    '00000013': lambda x: x.decode('gbk'),
    '00000017': lambda x: x.decode('gbk'),
    '00000018': lambda x: big2num(byte2str(x)),
    '00000019': lambda x: big2num(byte2str(x)),
    '00000055': lambda x: big2num(byte2str(x)),
    '00000056': lambda x: big2num(byte2str(x)),
    '00000057': lambda x: big2num(byte2str(x)),
    '00000084': lambda x: big2num(byte2str(x)),
}

# 回复0104应答参数查询时的内容
para_data_content = {
    '00000001': num2big(10, 4),
    '00000002': num2big(60, 4),
    '00000003': num2big(3, 4),
    '00000013': str2hex('119.23.49.157', 13),
    '00000017': str2hex('123.123.123.123', 15),
    '00000018': num2big(2083, 4),
    '00000019': num2big(0, 4),
    '00000055': num2big(60, 4),
    '00000056': num2big(10, 4),
    '00000057': num2big(14400, 4),
    '00000084': num2big(0, 4),
    # '0000F400': 'FFF0' * 4 + 'FFF1' * 3 + 'FFF2' * 2 + 'FF43' * 4 + 'FFF4' * 3 + '00' * 32,
    '0000F400': 'EFF0' * 16 + '00' * 32,
    '0000F401': '0000EFF0' * 24 + '00' * 32,
    '0000F402': '0000EFF0' * 24 + '00' * 32
}
コード例 #13
0
    deal_data = list(map(read_value, data_content))
    data = list(map(data2hex, deal_data, data_len))

    alarm_flag, status, latitude, longitude, height, speed, direction, report_time, alarm_id, alarm_flag_status, \
    alarm_type, alarm_level, fatigue_level, retain, alarm_speed, alarm_height, alarm_latitude, alarm_longitude, \
    alarm_report_time, car_status, device_id, alarm_report_time2, serial, attachment_num, last_retain = data

    basic_info = alarm_flag + status + latitude + longitude + height + speed + direction + report_time
    alarm_flag_no = device_id + alarm_report_time2 + serial + attachment_num + last_retain

    alarm_flag_alarm_type[alarm_flag_no] = '65' + alarm_type

    alarm_info = alarm_id + alarm_flag_status + alarm_type + alarm_level + fatigue_level + retain + alarm_speed + \
                 alarm_height + alarm_latitude + alarm_longitude + alarm_report_time + car_status + alarm_flag_no
    attach_info = '65' + num2big(int(len(alarm_info) / 2), 1) + alarm_info
    msg_body = basic_info + attach_info
    body = '0200' + calc_length_su_ter(msg_body) + communication_id + num2big(
        get_serial_no()) + msg_body
    data = '7E' + body + calc_check_code(body) + '7E'
    # print(data)
    send_queue.put(data)


def send_adas_alarm():
    case = r'.\TestData\前向预警.xls'
    rs = xlrd.open_workbook(case)
    table = rs.sheets()[0]
    data_len = table.col_values(1)
    data_content = table.col_values(2)