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)
Exemple #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)
    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)
Exemple #4
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
    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)
    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)
Exemple #7
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)
Exemple #8
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 ——————')
Exemple #9
0
    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)

    deal_data = list(map(read_value, data_content))
    data = list(map(data2hex, deal_data, data_len))