def parse_register_su_ter(data): # 2019修改项 logger.debug('—————— 收到注册请求 ——————') if conf.jt808_version == 2011: serial_no = data[10:12] state = '00' auth_code = 'test' msg_body = '%s%s%s' % (byte2str(serial_no), state, str2hex( auth_code, 4)) body = '%s%s%s%s%s' % ('8100', num2big(int( len(msg_body) / 2)), GlobalVar.DEVICEID, num2big(GlobalVar.get_serial_no()), msg_body) data = '%s%s%s%s' % ('7E', body, calc_check_code(body), '7E') elif conf.jt808_version == 2019: serial_no = data[10:12] state = '00' auth_code = 'test' msg_body = byte2str(serial_no) + state + str2hex(auth_code, 4) body = '8100' + num2big(int(len(msg_body) / 2) | 0x4000 ) + '01' + GlobalVar.DEVICEID + num2big( GlobalVar.get_serial_no()) + msg_body data = '7E' + body + calc_check_code(body) + '7E' send_queue.put(data)
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)
def register_all_face_youwei(self): for x in os.listdir(self.face_path): face_name = x.split('.')[0] person_id = int(face_name.split('_')[0]) image_id = int(face_name.split('_')[1]) image_path = os.path.join(self.face_path, x) with open(image_path, 'rb') as f: img_content = f.read() size = len(img_content) piece = 2048 r = size % piece pkg_num = size // piece if r == 0 else (size // piece) + 1 for x in range(pkg_num): offset = x * piece if x == pkg_num - 1: piece = piece if r == 0 else r file_content_piece = img_content[offset:offset + piece] logger.debug( '—————— 文件大小 {} 偏移量 {} 数据长度 {} ——————'.format(size, offset, piece)) msg_body = '033D' + '65' + 'B4' + num2big(person_id, 4) + num2big(image_id, 4) + num2big(size, 4) + num2big( offset, 4) + num2big(piece) + byte2str(file_content_piece) data = '7E' + calc_check_code(msg_body) + num2big(GlobalVar.get_serial_no()) + msg_body + '7E' send_queue.put(data) event_youwei.wait() time.sleep(1)
def send_tts(): if conf.get_protocol_type() == 3: tts_ = e_tts.get() tts_flag_ = e_tts_flag.get() if tts_: if tts_flag_: tts_flag_ = num2big(int(tts_flag_), 1) else: tts_flag_ = '08' msg_body = tts_flag_ + byte2str(tts_.encode('gbk')) body = '8300' + num2big(int(len(msg_body) / 2)) + GlobalVar.DEVICEID + \ num2big(GlobalVar.get_serial_no()) + msg_body data = '7E' + body + calc_check_code(body) + '7E' send_queue.put(data) elif conf.get_protocol_type() == 4: tts_ = e_tts.get() if tts_: msg_flag = '08' msg_content = byte2str(tts_.encode('utf-8')) if len(msg_content) > 2048: msg_content = msg_content[:2048] else: n = 2048 - len(msg_content) msg_content += '0' * n msg_body = msg_flag + msg_content service = num2big((9 << 6) + (4 << 1), 2) + calc_lens_sf(msg_body) timestamp = num2big(int(round(time.time() * 1000)), 8) pro_id = num2big(1744, 2) other = '800000' body = other + timestamp + pro_id + service + msg_body data = '55' + '41' + calc_lens_sf(body) + body + '55' send_queue.put(data)
def send_server_command_su_ter(alarm_flag): logger.debug('—————— 下发服务器地址 ——————') server = conf.get_file_address_su_ter() port = conf.get_file_port_su_ter() control = '00' if control == 'AA': upload = '05' else: upload = '00' alarm_num = str(int(time.time() * 1000000)) logger.debug('下发报警编号为 {}'.format(alarm_num * 2)) msg_body = num2big(len(server), 1) + str2hex(server, len(server)).upper() + num2big(port, 2) + '0000' + alarm_flag + \ str2hex(alarm_num, 16)*2 + control + upload + '00' * 14 serial_num = num2big(GlobalVar.get_serial_no()) # 2019修改项 if conf.jt808_version == 2011: body = '9208' + num2big(int( len(msg_body) / 2)) + GlobalVar.DEVICEID + serial_num + msg_body elif conf.jt808_version == 2019: body = '9208' + num2big( int(len(msg_body) / 2) | 0x4000) + '01' + GlobalVar.DEVICEID + serial_num + msg_body data = '7E' + body + calc_check_code(body) + '7E' GlobalVar.send_address_dict[serial_num] = data send_queue.put(data) GlobalVar.send_address_time_out = 10
def comm_reply_jt808(data, reply_result): msg_id = data[1:3] serial_num = data[11:13] result = reply_result body = '8001' + '0005' + GlobalVar.DEVICEID + num2big(GlobalVar.get_serial_no()) + byte2str(serial_num) + byte2str(msg_id) + result data = '7E' + body + calc_check_code(body) + '7E' return data
def send_take_photo(): take_photo_ = e_take_photo.get() if take_photo_: msg_body = num2big(int(take_photo_), 1) + '00' * 11 body = '8801' + '000C' + GlobalVar.DEVICEID + num2big( GlobalVar.get_serial_no()) + msg_body data = '7E' + body + calc_check_code(body) + '7E' send_queue.put(data)
def send_upgrade_command(filename, flag, upgrade_type, hw, fw, sw, url): with open(filename, 'rb') as f: package_len = len(f.read()) msg_body = num2big(flag, 1) + num2big(upgrade_type, 1) + num2big(package_len, 4) + get_md5(filename) + \ num2big(32, 1) + str2hex(hw, 32) + num2big(32, 1) + str2hex(fw, 32) + num2big(32, 1) + str2hex(sw, 32) \ + num2big(len(url), 1) + str2hex(url, len(url)) # 2019修改项 if conf.jt808_version == 2011: body = '8FA1' + num2big(int( len(msg_body) / 2)) + GlobalVar.DEVICEID + num2big( GlobalVar.get_serial_no()) + msg_body elif conf.jt808_version == 2019: body = '8FA1' + num2big(int(len(msg_body) / 2) | 0x4000 ) + '01' + GlobalVar.DEVICEID + num2big( GlobalVar.get_serial_no()) + msg_body data = '7E' + body + calc_check_code(body) + '7E' send_queue.put(data)
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)
def parse_media_upload_finish_su_ter(data, rec_obj): loss_pkg_list = [] name_len = data[13:14] media_name = data[14:14 + big2num(byte2str(name_len))].split( b'\x00')[0].decode('utf-8') media_type = byte2str(data[-7:-6]) media_size = big2num(byte2str(data[-6:-2])) quotient = media_size // 65536 remainder = media_size % 65536 log_event.debug('{} —————— 告警结束 ——————'.format(rec_obj.client_address)) log_event.debug('{} 文件名 {}'.format(rec_obj.client_address, media_name)) log_event.debug('{} 文件类型 {} '.format(rec_obj.client_address, media_type)) log_event.debug('{} 文件大小 {}'.format(rec_obj.client_address, media_size)) log_event.debug('{} —————— END ——————'.format(rec_obj.client_address)) filename_length = data[13:14] file_name = data[14:14 + big2num(byte2str(filename_length))] file_type = data[-7:-6] offset_data = name_offset_data.get(media_name) if offset_data: # if len(offset_data) > 1: # offset_data[0] = None # offset_data[65536] = None for x in offset_data.keys(): if not offset_data.get(x): loss_pkg_list.append(x) if not loss_pkg_list: msg_body = byte2str(filename_length) + byte2str( file_name) + byte2str(file_type) + '00' + '00' for x in sorted(offset_data.keys()): media_queue.put(offset_data.get(x)) name_offset_data.pop(media_name) else: loss_pkg = '' loss_len = len(loss_pkg_list) log_event.info("{} {} 多媒体数据丢包,丢包偏移量为 {}".format( rec_obj.client_address, media_name, loss_pkg_list)) if quotient in loss_pkg_list: loss_pkg_list.pop(quotient) for x in loss_pkg_list: loss_pkg += num2big(x, 4) + num2big(65536, 4) loss_pkg += num2big(quotient, 4) + num2big(remainder, 4) else: for x in loss_pkg_list: loss_pkg += num2big(x, 4) + num2big(65536, 4) msg_body = byte2str(filename_length) + byte2str( file_name) + byte2str(file_type) + '01' + num2big(loss_len, 1) + loss_pkg else: msg_body = byte2str(filename_length) + byte2str(file_name) + byte2str( file_type) + '00' + '00' body = '%s%s%s%s%s' % ('9212', num2big(int( len(msg_body) / 2)), GlobalVar.DEVICEID, num2big(GlobalVar.get_serial_no()), msg_body) data = '%s%s%s%s' % ('7E', body, calc_check_code(body), '7E') return data
def comm_reply_su_ter(data, reply_result): # 2019修改项 if conf.jt808_version == 2011: msg_id = data[0:2] serial_no = data[10:12] result = reply_result msg_body = num2big(GlobalVar.get_serial_no()) + byte2str( serial_no) + byte2str(msg_id) + result body = '8001' + '0005' + GlobalVar.DEVICEID + msg_body data = '7E' + body + calc_check_code(body) + '7E' elif conf.jt808_version == 2019: msg_id = data[0:2] serial_no = data[15:17] result = reply_result msg_body = num2big(GlobalVar.get_serial_no()) + byte2str( serial_no) + byte2str(msg_id) + result body = '8001' + '4005' + '01' + GlobalVar.DEVICEID + msg_body data = '7E' + body + calc_check_code(body) + '7E' return data
def parse_register_jt808(data): logger.debug('—————— 收到注册请求 ——————') serial_num = data[11:13] state = '00' auth_code = 'test' msg_body = '%s%s%s' % (byte2str(serial_num), state, str2hex(auth_code, 4)) # msg_body = '%s%s' % (byte2str(serial_num), state) body = '%s%s%s%s%s' % ('8100', num2big(int(len(msg_body) / 2)), GlobalVar.DEVICEID, num2big( GlobalVar.get_serial_no()), msg_body) data = '%s%s%s%s' % ('7E', body, calc_check_code(body), '7E') send_queue.put(data)
def query_face(self): logger.debug('—————— 驾驶员身份信息库查询 ——————') if conf.get_protocol_type() == 1: # 数据内容拼接:厂商编码 + 外设编号 + 功能码 + 设置类型 msg_body = '033D' + '65' + 'E4' # 报文格式拼接 data = '7E' + calc_check_code(msg_body) + num2big(GlobalVar.get_serial_no()) + msg_body + '7E' # 发文发送 send_queue.put(data) elif conf.get_protocol_type() == 5: msg_body = '' body = '8E12' + num2big(int(len(msg_body) / 2)) + GlobalVar.DEVICEID + num2big(GlobalVar.get_serial_no()) + msg_body data = '7E' + body + calc_check_code(body) + '7E' send_queue.put(data)
def re_trans(): media_id_ = e_media_id.get() if int(media_id_) in GlobalVar.media_finish: GlobalVar.media_finish.pop(int(media_id_)) media_type_ = e_media_type.get() alarm_type_ = e_alarm_type.get() speed_ = e_speed.get() alarm_time_ = e_alarm_time.get() msg_body = num2big(int(media_id_), 4) + num2big(int(media_type_), 1) + num2big(int(alarm_type_), 1) + \ num2big(int(speed_), 2) + alarm_time_ body = '8938' + num2big(int(len(msg_body) / 2), 2) + GlobalVar.DEVICEID + \ num2big(GlobalVar.get_serial_no()) + msg_body data = '7E' + body + calc_check_code(body) + '7E' send_queue.put(data)
def query_pro(): logger.debug('—————— 查询终端属性 ——————') if conf.get_protocol_type() == 3 or conf.get_protocol_type() == 5: body = '8107' + '0000' + GlobalVar.DEVICEID + num2big( GlobalVar.get_serial_no()) data = '7E' + body + calc_check_code(body) + '7E' send_queue.put(data) elif conf.get_protocol_type() == 4: msg_body = '' service = num2big((12 << 6) + (4 << 1), 2) + calc_lens_sf(msg_body) timestamp = num2big(int(round(time.time() * 1000)), 8) pro_id = num2big(1744, 2) other = '800000' body = other + timestamp + pro_id + service data = '55' + '41' + calc_lens_sf(body) + body + '55' send_queue.put(data)
def parse_get_media_su(data): serial_num = data[2:4] peripheral = data[6:7] media_type = data[8:9] media_id = data[9:13] pkg_total = data[13:15] pkg_num = data[15:17] if byte2str(pkg_total) == '0000' and byte2str(pkg_num) == '0000': if byte2str(media_type) == '02': logger.info('—————— 告警视频未录制完 {} ——————'.format( byte2str(data))) query_media_body = '%s%s%s%s%s' % ( COMPANY_NO, byte2str(peripheral), '50', byte2str(media_type), byte2str(media_id)) query_media = '%s%s%s%s%s' % ( SU_FLAG, calc_check_code(query_media_body), num2big( GlobalVar.get_serial_no()), query_media_body, SU_FLAG) query_msg_queue.put(query_media) send_queue.put(query_msg_queue.get(block=False)) elif byte2str(media_type) == '00': logger.error('—————— 告警数据不存在 {} ——————'.format( byte2str(data))) else: return_state = '00' img_return_body = '%s%s%s%s%s%s%s%s' % ( COMPANY_NO, byte2str(peripheral), '51', byte2str(media_type), byte2str(media_id), byte2str(pkg_total), byte2str(pkg_num), return_state) img_return = '%s%s%s%s%s' % ( SU_FLAG, calc_check_code(img_return_body), byte2str(serial_num), img_return_body, SU_FLAG) send_queue.put(img_return) media_queue.put(data) total_pkg = int(byte2str(data[13:15]), 16) rec_pkg = int(byte2str(data[15:17]), 16) if rec_pkg == total_pkg - 1: try: send_queue.put(query_msg_queue.get(block=False)) except queue.Empty: global fetch_media_flag fetch_media_flag = True
def send_server_command_su_ter(alarm_flag): logger.debug('—————— 下发服务器地址 ——————') server = conf.get_file_address_su_ter() port = conf.get_file_port_su_ter() control = '00' if control == 'AA': upload = '05' else: upload = '00' alarm_num = str(int(time.time() * 1000000)) logger.debug('下发报警编号为 {}'.format(alarm_num * 2)) msg_body = num2big(len(server), 1) + str2hex(server, len(server)).upper() + num2big(port, 2) + '0000' + alarm_flag + \ str2hex(alarm_num, 16)*2 + control + upload + '00' * 14 serial_num = num2big(GlobalVar.get_serial_no()) body = '%s%s%s%s%s' % ('9208', num2big(int( len(msg_body) / 2)), GlobalVar.DEVICEID, serial_num, msg_body) data = '%s%s%s%s' % ('7E', body, calc_check_code(body), '7E') GlobalVar.send_address_dict[serial_num] = data send_queue.put(data) GlobalVar.send_address_time_out = 10
def reboot(): body = '8F01' + '0000' + GlobalVar.DEVICEID + num2big( GlobalVar.get_serial_no()) data = '7E' + body + calc_check_code(body) + '7E' send_queue.put(data)
def set_para(): if conf.get_protocol_type() == 3 or conf.get_protocol_type() == 5: txt = '修改参数 : ' list_num = 0 address_ = e_address.get() port_ = e_port.get() limit_speed_ = e_limit_speed.get() adas_speed_ = e_adas_speed.get() vol_ = e_vol.get() mode_ = e_mode.get() msg_body = '' if address_: list_num += 1 ip_len = len(address_) msg_body += '00000013' + num2big(ip_len, 1) + str2hex( address_, ip_len) txt += '服务器 {} '.format(address_) if port_: list_num += 1 msg_body += '00000018' + '04' + num2big(int(port_), 4) txt += '端口号 {} '.format(port_) if limit_speed_: list_num += 1 msg_body += '00000055' + '04' + num2big(int(limit_speed_), 4) txt += '最高速度 {} '.format(limit_speed_) if adas_speed_: list_num += 1 msg_body += '0000F091' + '01' + num2big(int(adas_speed_), 1) txt += 'ADAS激活速度 {} '.format(adas_speed_) if vol_: list_num += 1 msg_body += '0000F092' + '01' + num2big(int(vol_), 1) txt += '告警音量 {} '.format(vol_) if mode_: list_num += 1 msg_body += '0000F094' + '01' + num2big(int(mode_), 1) txt += '工作模式 {} '.format(mode_) if list_num: msg_body = num2big(list_num, 1) + msg_body body = '8103' + num2big(int(len(msg_body) / 2), 2) + GlobalVar.DEVICEID + \ num2big(GlobalVar.get_serial_no()) + msg_body data = '7E' + body + calc_check_code(body) + '7E' logger.debug('—————— 设置终端参数 ——————') logger.debug('—————— ' + txt + ' ——————') send_queue.put(data) elif conf.get_protocol_type() == 4: address_ = e_address.get() port_ = e_port.get() limit_speed_ = e_limit_speed.get() adas_speed_ = e_adas_speed.get() vol_ = e_vol.get() mode_ = e_mode.get() product_ = e_product.get() para_list = [] para_dic = {} if address_: para_list.append({"1": address_}) if port_: para_list.append({"2": port_}) if product_: para_list.append({"3": product_}) if limit_speed_: para_list.append({"4": limit_speed_}) if adas_speed_: para_list.append({"5": adas_speed_}) if vol_: para_list.append({"6": vol_}) if mode_: para_list.append({"7": mode_}) para_dic["TerminalParameter"] = para_list if para_dic: msg_body = str2hex(json.dumps(para_dic), 1024) service = num2big((11 << 6) + (4 << 1), 2) + calc_lens_sf(msg_body) timestamp = num2big(int(round(time.time() * 1000)), 8) pro_id = num2big(1744, 2) other = '800000' body = other + timestamp + pro_id + service + msg_body data = '55' + '41' + calc_lens_sf(body) + body + '55' send_queue.put(data)
def parse_identify_result_upload_su_ter(data): global time_img global time_serial global loss_pkg serial_no = byte2str(data[10:12]) # 消息体属性 msg_property = big2num(byte2str(data[2:4])) # 确定是否有分包数据 if 0x2000 & msg_property == 0x2000: msg_body = data[16:-1] total_pkg = big2num(byte2str(data[12:14])) pkg_no = big2num(byte2str(data[14:16])) result = byte2str(msg_body[0:1]) similarity_threshold = big2num(byte2str(msg_body[1:2])) similarity = big2num(byte2str(msg_body[2:4])) cp_type = byte2str(msg_body[4:5]) cp_face_id_len = big2num(byte2str(msg_body[5:6])) cp_face_id = msg_body[6:6 + cp_face_id_len].decode("gbk") location_info = msg_body[6 + cp_face_id_len:6 + cp_face_id_len + 28] img_type = byte2str(msg_body[34 + cp_face_id_len:35 + cp_face_id_len]) alarm_flag = byte2str(location_info[0:4]) state = byte2str(location_info[4:8]) latitude = big2num(byte2str(location_info[8:12])) longitude = big2num(byte2str(location_info[12:16])) speed = big2num(byte2str(location_info[18:20])) / 10 alarm_time = byte2str(location_info[22:]) # if result == "00" or result == '01' or result == '06': # img_data = msg_body[35 + cp_face_id_len:] if pkg_no == 1: # 记录告警时刻(标识告警的唯一性)对应的流水号,后续重传时用到 time_serial[alarm_time] = serial_no time_img[alarm_time] = {} time_img[alarm_time][pkg_no] = data loss_pkg[alarm_time] = [] # 收到第一个包打印告警相关信息 logger.debug('———————————————— 驾驶员身份识别上报 ————————————————') logger.debug('比对结果 {}'.format(result)) logger.debug('比对相似度阈值 {}'.format(similarity_threshold)) logger.debug('比对相似度 {}'.format(similarity)) logger.debug('比对类型 {}'.format(cp_type)) logger.debug('比对人脸ID {}'.format(cp_face_id)) logger.debug('图片格式 {}'.format(img_type)) logger.debug( '—————— 报警标识 {} 状态 {} 速度 {} km/h 纬度 {} 经度 {} 时间 {} ——————'. format(alarm_flag, state, speed, latitude, longitude, alarm_time)) logger.debug('———————————————— END ————————————————') # 如果接收到的不是第一个分片包也不是最后一个分片包,则将该分片包存储进media_id_data elif not pkg_no == total_pkg: time_img[alarm_time][pkg_no] = data # 如果是最后一个分片包,如果该分片包对应的告警ID的数据未获取完成,则将该分片包加入time_img中 else: time_img[alarm_time][pkg_no] = data for x in list(time_img[alarm_time].keys()): if x not in list(range(total_pkg + 1))[1:]: loss_pkg.get(alarm_time).append(x) if not loss_pkg.get(alarm_time): retrans_serial_no = time_serial.get(alarm_time) msg_body = retrans_serial_no + "0000" body = '8E10' + num2big(int( len(msg_body) / 2)) + GlobalVar.DEVICEID + num2big( GlobalVar.get_serial_no()) + msg_body data = '7E' + body + calc_check_code(body) + '7E' send_queue.put(data) for x in sorted(list(time_img.get(alarm_time).keys())): media_queue.put(time_img.get(alarm_time).get(x)) loss_pkg.pop(alarm_time) time_img.pop(alarm_time) time_serial.pop(alarm_time) else: retrans_serial_no = time_serial.get(alarm_time) pkg_sum = num2big(len(loss_pkg.get(alarm_time)), 2) retrans_pkg = ''.join( [num2big(x, 2) for x in loss_pkg.get(alarm_time)]) msg_body = retrans_serial_no + pkg_sum + retrans_pkg body = '8E10' + num2big(int( len(msg_body) / 2)) + GlobalVar.DEVICEID + num2big( GlobalVar.get_serial_no()) + msg_body data = '7E' + body + calc_check_code(body) + '7E' send_queue.put(data) else: msg_body = data[12:-1] result = byte2str(msg_body[0:1]) similarity_threshold = big2num(byte2str(msg_body[1:2])) similarity = big2num(byte2str(msg_body[2:4])) cp_type = byte2str(msg_body[4:5]) cp_face_id_len = big2num(byte2str(msg_body[5:6])) cp_face_id = msg_body[6:6 + cp_face_id_len].decode("gbk") location_info = msg_body[6 + cp_face_id_len:6 + cp_face_id_len + 28] img_type = byte2str(msg_body[34 + cp_face_id_len:35 + cp_face_id_len]) alarm_flag = byte2str(location_info[0:4]) state = byte2str(location_info[4:8]) latitude = big2num(byte2str(location_info[8:12])) longitude = big2num(byte2str(location_info[12:16])) speed = big2num(byte2str(location_info[18:20])) / 10 alarm_time = byte2str(location_info[22:]) logger.debug('———————————————— 驾驶员身份识别上报 ————————————————') logger.debug('比对结果 {}'.format(result)) logger.debug('比对相似度阈值 {}'.format(similarity_threshold)) logger.debug('比对相似度 {}'.format(similarity)) logger.debug('比对类型 {}'.format(cp_type)) logger.debug('比对人脸ID {}'.format(cp_face_id)) logger.debug('图片格式 {}'.format(img_type)) logger.debug( '—————— 报警标识 {} 状态 {} 速度 {} km/h 纬度 {} 经度 {} 时间 {} ——————'.format( alarm_flag, state, speed, latitude, longitude, alarm_time)) logger.debug('———————————————— END ————————————————')
def modify_info(self): if conf.get_protocol_type() == 1: mask = 0b00000000 if self.face_mask.get(): mask = mask | 0b00000001 if self.certificate_mask.get(): mask = mask | 0b00000010 if self.name_mask.get(): mask = mask | 0b00000100 if mask: logger.debug('—————— 修改人脸信息 ——————') send_face_thread = SendFace('【 Data Server 】 SendFace Thread Start ...', 3, mask, self.face_case_path) send_face_thread.start() elif conf.get_protocol_type() == 5: logger.debug('—————— 修改人脸信息 ——————') if self.face_case_path: face_case_name = self.face_case_path else: face_case_name = r'.\TestData\Face_suter\修改人脸.xls' rs = xlrd.open_workbook(face_case_name) table = rs.sheets()[0] cols = table.ncols face_num = (cols+1)//4 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:] deal_data = list(map(read_value, data_content)) data = list(map(data2hex, deal_data, data_len)) face_info_list += ''.join(data) msg_body = '03' + num2big(face_num, 1) + face_info_list body = '8E11' + num2big(int(len(msg_body) / 2)) + GlobalVar.DEVICEID + num2big(GlobalVar.get_serial_no()) + msg_body data = '7E' + body + calc_check_code(body) + '7E' send_queue.put(data)
def query_all_youwei(self): msg_body = '033D' + '65' + 'B3' + '00000000' data = '7E' + calc_check_code(msg_body) + num2big(GlobalVar.get_serial_no()) + msg_body + '7E' send_queue.put(data)
def catch_photo_register_youwei(self): person_id = int(self.person_id_cont1.get()) msg_body = '033D' + '65' + 'B4' + num2big(person_id, 4) + '00000000' data = '7E' + calc_check_code(msg_body) + num2big(GlobalVar.get_serial_no()) + msg_body + '7E' send_queue.put(data)
def parse_media_upload(data): jt808_serial_no = big2num(byte2str(data[11:13])) # 消息体属性 msg_property = big2num(byte2str(data[3:5])) # 确定是否有分包数据 if 0x2000 & msg_property == 0x2000: total_pkg = big2num(byte2str(data[13:15])) pkg_no = big2num(byte2str(data[15:17])) # 收到第一个包打印告警相关信息 if pkg_no == 1: GetMediaThread.current_media_id = big2num(byte2str( data[17:21])) channel = big2num(byte2str(data[24:25])) logger.debug('——————正在获取ID为 {} 的多媒体数据 ——————'.format( GetMediaThread.current_media_id)) if channel == 1: channel = 'DSM' elif channel == 2: channel = 'ADAS' else: channel = '其他' # alarm_flag = byte2str(data[25:29]) state = byte2str(data[29:33]) latitude = big2num(byte2str(data[33:37])) longitude = big2num(byte2str(data[37:41])) speed = big2num(byte2str(data[43:45])) alarm_time = byte2str(data[47:53]) logger.debug( '—————— 通道 {} 状态 {} 速度 {} km/h 纬度 {} 经度 {} 时间 {} ——————'. format(channel, state, speed, latitude, longitude, alarm_time)) # 如果当前告警ID不在已接收完成的多媒体列表(media_finish)中,则将该ID添加到进去,并且将值置为False # 记录最后一个分片包对应的流水号和告警ID的键值对,存入last_pkg_media_id # 计算出该ID对应的分片包范围,并且添加到记录告警ID和多媒体数据的列表中(media_id_data) if GetMediaThread.current_media_id not in GlobalVar.media_finish: media_finish[GetMediaThread.current_media_id] = False GetMediaThread.last_pkg = jt808_serial_no + total_pkg - 1 GlobalVar.last_pkg_media_id[ GetMediaThread. last_pkg] = GetMediaThread.current_media_id GlobalVar.pkg_list = range(1, total_pkg + 1) GlobalVar.media_id_data[pkg_no] = data # 如果接收到的不是第一个分片包也不是最后一个分片包,则将该分片包存储进media_id_data elif not pkg_no == total_pkg: GlobalVar.media_id_data[pkg_no] = data # 如果是最后一个分片包,如果该分片包对应的告警ID的数据未获取完成,则将该分片包加入media_id_data中 else: if not media_finish.get( last_pkg_media_id.get(jt808_serial_no)): GlobalVar.media_id_data[pkg_no] = data GetMediaThread.rec_pkg_list = list( GlobalVar.media_id_data.keys()) loss_pkg_list = [ x for x in GlobalVar.pkg_list if x not in GetMediaThread.rec_pkg_list ] if not loss_pkg_list: logger.debug('—————— 多媒体ID ' + str(GetMediaThread.current_media_id) + ' ---------- 接收数据完成 ——————') msg_body = num2big(GetMediaThread.current_media_id, 4) + '00' body = '%s%s%s%s%s' % ( '8800', num2big(int(len(msg_body) / 2)), DEVICEID, num2big(GlobalVar.get_serial_no()), msg_body) data = '%s%s%s%s' % ('7E', body, calc_check_code(body), '7E') send_queue.put(data) for x in sorted(GetMediaThread.rec_pkg_list): media_queue.put(GlobalVar.media_id_data.get(x)) GlobalVar.serial_no_list = [] media_finish[GetMediaThread.current_media_id] = True GlobalVar.pkg_list = [] GlobalVar.media_id_data = {} GetMediaThread.rec_pkg_list = [] GetMediaThread.last_pkg = 0 GetMediaThread.current_media_id = 0 else: loss_pkg_list.append(total_pkg) loss_num = len(loss_pkg_list) quotient = loss_num // 125 remainder = loss_num % 125 for x in range(1, quotient + 1): loss_id_list = ''.join([ num2big(y, 2) for y in loss_pkg_list[(x - 1) * 125:x * 125] ]) msg_body = num2big( GetMediaThread.current_media_id, 4) + num2big( 125, 1) + loss_id_list body = '%s%s%s%s%s' % ( '8800', num2big(int( len(msg_body) / 2)), DEVICEID, num2big(GlobalVar.get_serial_no()), msg_body) data = '%s%s%s%s' % ('7E', body, calc_check_code(body), '7E') send_queue.put(data) loss_id_list = ''.join([ num2big(y, 2) for y in loss_pkg_list[quotient * 125:] ]) msg_body = num2big( GetMediaThread.current_media_id, 4) + num2big( remainder, 1) + loss_id_list body = '%s%s%s%s%s' % ( '8800', num2big(int( len(msg_body) / 2)), GlobalVar.DEVICEID, num2big(GlobalVar.get_serial_no()), msg_body) data = '%s%s%s%s' % ('7E', body, calc_check_code(body), '7E') send_queue.put(data)
def parse_alarm(data): if conf.get_protocol_type() == 1: peripheral = data[6:7] function_no = data[7:8] serial_num = data[2:4] alarm_return_body = '%s%s%s' % (COMPANY_NO, byte2str(peripheral), byte2str(function_no)) alarm_return = '%s%s%s%s%s' % ( SU_FLAG, calc_check_code(alarm_return_body), byte2str(serial_num), alarm_return_body, SU_FLAG) send_queue.put(alarm_return) num = int(byte2str(data[38:39]), 16) alarm_type = data[13:14] video_id = data[-5:-1] speed = data[19:20] height = data[20:22] latitude = data[22:26] longitude = data[26:30] alarm_time = data[30:36] state = data[36:38] if peripheral == b'\x65': logger.debug('') logger.debug('========== 收到DSM告警信息 ==========') logger.debug('') logger.debug( '—————— 视频ID {} 告警类型 -------------------- {} ——————'. format(byte2str(video_id), alarm_type_code_su_dsm.get(alarm_type))) elif peripheral == b'\x64': logger.debug('') logger.debug('========== 收到ADAS告警信息 ==========') logger.debug('') logger.debug( '—————— 视频ID {} 告警类型 -------------------- {} ——————'. format(byte2str(video_id), alarm_type_code_su_adas.get(alarm_type))) logger.debug( '—————— 速度 {} 高程 {} 纬度 {} 经度 {} 告警时间 {} 车辆状态 {} ——————'.format( big2num(byte2str(speed)), big2num(byte2str(height)), big2num(byte2str(latitude)), big2num(byte2str(longitude)), byte2str(alarm_time), byte2str(state))) if conf.get_get_media_flag(): for x in range(num): media_id = byte2str(data[39 + x * 5 + 1:39 + x * 5 + 5]) media_type = byte2str(data[39 + x * 5:39 + x * 5 + 1]) media_alarm_code[media_id] = alarm_type if data[6:8] == DSM_ALARM_SU: if media_type == '00' or '02': query_media_body = '%s%s%s%s' % ( COMPANY_NO, '6550', media_type, media_id) else: logger.error('数据解析出错{}'.format(byte2str(data))) elif data[6:8] == ADAS_ALARM_SU: if media_type == '00' or '02': query_media_body = '%s%s%s%s' % ( COMPANY_NO, '6450', media_type, media_id) else: logger.error('数据解析出错{}'.format(byte2str(data))) else: logger.error('不存在的告警{}'.format(byte2str(data))) query_media = '%s%s%s%s%s' % ( SU_FLAG, calc_check_code(query_media_body), num2big(GlobalVar.get_serial_no()), query_media_body, SU_FLAG) query_msg_queue.put(query_media) global fetch_media_flag if fetch_media_flag: fetch_media_flag = False if not query_msg_queue.empty(): send_queue.put(query_msg_queue.get(block=False))