Пример #1
0
def server_run():
    while True:
        try:
            re_byte = config.server_connection.recv(4096)
            re_text = ''.join(['%02X ' % x for x in re_byte])
            print(re_text)
        except Exception:
            traceback.print_exc()
            break
        if re_text != '':
            if config.is_auto_se_heartbeat is True and is_link_request(
                    re_text) is True:
                reply_link_text = reply_link_request(re_text)
                data = link_layer.data_format(reply_link_text)
                send_d = b''
                for char in data:
                    send_d += struct.pack('B', int(char, 16))
                config.server_connection.sendall(send_d)
            elif config.is_auto_se_confirm is True and is_rpt_notification(
                    re_text) is True:
                reply_link_text = reply_rpt_request(re_text)
                data = link_layer.data_format(reply_link_text)
                send_d = b''
                for char in data:
                    send_d += struct.pack('B', int(char, 16))
                config.server_connection.sendall(send_d)
            else:
                config.serial_window._receive_signal.emit(re_text)
        if config.server_check is False:
            stop_thread(config.server_accept_thread)
            print('server_run quit')
            break
Пример #2
0
 def send_trans(self):
     input_text = self.send_input_box.toPlainText()
     try:
         data_in = link_layer.data_format(input_text, auto_add_0=False)
         print('data_in', data_in)
         ret_dict = link_layer.all_translate(data_in)
         if ret_dict['res'] == 'ok':
             self.quick_fix_button.setText(
                 '修正地址' if self.is_good_linklayer() is False else
                 '修正校验码' if config.good_HCS is not None or config.
                 good_FCS is not None else '修正格式')
             if ret_dict['input_type'] == 'full' and config.auto_fix is True:
                 if self.is_good_linklayer() is False:
                     self.fix_addr()
                     input_text = self.send_input_box.toPlainText()
                     data_in = link_layer.data_format(input_text)
                     link_layer.all_translate(data_in)
             elif ret_dict['input_type'] == 'apdu':
                 input_text = link_layer.add_link_layer(input_text)
                 self.send_input_box.setText(input_text)
                 data_in = link_layer.data_format(input_text)
                 link_layer.all_translate(data_in)
         else:
             self.quick_fix_button.setText(
                 '修正长度域' if config.good_L is not None else '修正格式')
     except Exception:
         traceback.print_exc()
         output('\n\n报文解析过程出现问题,请检查报文。若报文无问题请反馈665593,谢谢!')
     self.send_output_box.setText(config.output_text)
     config.output_text = ''
Пример #3
0
 def re_DT_param(self, re_text):
     data = link_layer.data_format(re_text)
     offset = 0
     ret_dict = link_layer.get_SA_CA(data)
     offset += 5 + int(ret_dict['SA_len']) + 11
     if data[offset] == '01':
         self.res_b.setStyleSheet('color: green')
         self.res_b.setText('成功')
         offset += 2
         self.DT_mode_l.setCurrentIndex({
             '00': 0,
             '01': 1,
             '02': 2,
             'FF': 3
         }[data[offset]])
         offset += 9
         self.DT_tot_num_box.setText(str(int(data[offset], 16)))
         offset += 2
         self.DT_biggest_num_box.setText(str(int(data[offset], 16)))
         offset += 2
         self.DT_smallest_num_box.setText(str(int(data[offset], 16)))
         offset += 2
         self.DT_dly_max_box.setText(str(int(data[offset], 16)))
         offset += 2
         self.DT_valid_num_min_box.setText(str(int(data[offset], 16)))
         offset += 2
     else:
         self.res_b.setStyleSheet('color: red')
         self.res_b.setText('失败:' +
                            data_translate.dar_explain[data[offset + 1]])
     config.serial_window._receive_signal.disconnect()
     config.serial_window._receive_signal.connect(
         config.serial_window.re_text_to_box)
Пример #4
0
    def re_ip(self, re_text):
        data = link_layer.data_format(re_text)
        offset = 0
        ret_dict = link_layer.get_SA_CA(data)
        offset += 5 + int(ret_dict['SA_len']) + 10
        if data[offset] == '01':
            self.res_b.setStyleSheet('color: green')
            self.res_b.setText('成功')
            offset += 7
            ip_text = param.get_ip(data[offset:])
            self.S_ip_box.setText(ip_text)
            port_text = str(int(data[offset + 5] + data[offset + 6], 16))
            self.S_port_box.setText(port_text)

            if int(data[offset + 2 - 7], 16) > 1:
                offset += 11
                ip_text = param.get_ip(data[offset:])
                self.S_ip_box_2.setText(ip_text)
                port_text = str(int(data[offset + 5] + data[offset + 6], 16))
                self.S_port_box_2.setText(port_text)
        else:
            self.res_b.setStyleSheet('color: red')
            self.res_b.setText('失败:' +
                               data_translate.dar_explain[data[offset + 1]])
        config.serial_window._receive_signal.disconnect()
        config.serial_window._receive_signal.connect(
            config.serial_window.re_text_to_box)
Пример #5
0
 def re_local_net(self, re_text):
     data = link_layer.data_format(re_text)
     offset = 0
     ret_dict = link_layer.get_SA_CA(data)
     offset += 5 + int(ret_dict['SA_len']) + 10
     if data[offset] == '01':
         self.res_b.setStyleSheet('color: green')
         self.res_b.setText('成功')
         offset += 4
         self.local_ip_mode_l.setCurrentIndex({
             '00': 0,
             '01': 1,
             '02': 2
         }[data[offset]])
         offset += 3
         self.local_ip_box.setText(param.get_ip(data[offset:]))
         offset += 6
         self.local_mask_box.setText(param.get_ip(data[offset:]))
         offset += 6
         self.local_gate_addr_box.setText(param.get_ip(data[offset:]))
         offset += 4
         ret = param.get_octet(data[offset:])
         self.ppp_usr_box.setText(ret['octet'])
         offset += ret['offset']
         ret = param.get_octet(data[offset:])
         self.ppp_pw_box.setText(ret['octet'])
         offset += ret['offset']
     else:
         self.res_b.setStyleSheet('color: red')
         self.res_b.setText('失败:' +
                            data_translate.dar_explain[data[offset + 1]])
     config.serial_window._receive_signal.disconnect()
     config.serial_window._receive_signal.connect(
         config.serial_window.re_text_to_box)
Пример #6
0
 def re_esam_certi(self, re_text):
     data = link_layer.data_format(re_text)
     offset = 0
     ret_dict = link_layer.get_SA_CA(data)
     offset += 5 + int(ret_dict['SA_len']) + 7
     res_sum = True
     offset += 4
     if data[offset] == '01':
         offset += 1
         ret = param.get_octet(data[offset:])
         self.esam_certi_ver_box.setText(ret['octet'])
         offset += ret['offset']
     else:
         offset += 1
         res_sum = False
         self.esam_certi_ver_box.setText(
             '失败:' + data_translate.dar_explain[data[offset + 1]])
     offset += 4
     if data[offset] == '01':
         offset += 1
         ret = param.get_octet(data[offset:])
         self.esam_certi_box.setText(ret['octet'])
         self.esam_certi_len_box.setText(str(ret['len']) + '字节')
         offset += ret['offset']
     else:
         offset += 1
         res_sum = False
         self.esam_certi_box.setText(
             '失败:' + data_translate.dar_explain[data[offset + 1]])
     if res_sum is True:
         self.res_b.setStyleSheet('color: green')
         self.res_b.setText('成功')
Пример #7
0
 def quick_fix(self):
     if self.is_good_linklayer() is False:
         self.fix_addr()
         self.send_trans()
     else:
         input_text = self.send_input_box.toPlainText()
         data_in = link_layer.data_format(input_text)
         if config.good_L is not None:
             data_in[1], data_in[2] = config.good_L[0], config.good_L[1]
         else:
             if config.good_HCS is not None:
                 ret_dict = link_layer.get_SA_CA(data_in)
                 hcs_pos = 6 + int(ret_dict['SA_len'])
                 data_in[hcs_pos], data_in[
                     hcs_pos + 1] = config.good_HCS[0], config.good_HCS[1]
                 input_text = ''
                 for data in data_in:
                     input_text += data + ' '
                 print('input_text', input_text)
                 self.send_input_box.setText(input_text)
                 self.send_trans()
             if config.good_FCS is not None:
                 data_in[-3], data_in[-2] = config.good_FCS[
                     0], config.good_FCS[1]
         input_text = ''
         for data in data_in:
             input_text += data + ' '
         self.send_input_box.setText(input_text)
Пример #8
0
 def re_DT(self, re_text):
     data = link_layer.data_format(re_text)
     offset = 0
     ret_dict = link_layer.get_SA_CA(data)
     offset += 5 + int(ret_dict['SA_len']) + 10
     if data[offset] == '01':
         self.res_b.setStyleSheet('color: green')
         self.res_b.setText('成功')
         offset += 2
         DT_read = QtCore.QDateTime(
             (int(data[offset], 16) << 8) | int(data[offset + 1], 16),
             int(data[offset + 2], 16),
             int(data[offset + 3], 16),
             int(data[offset + 4], 16),
             int(data[offset + 5], 16),
             int(data[offset + 6], 16),
         )
         # print('DT_read', DT_read)
         self.DT_box.setDateTime(DT_read)
     else:
         self.res_b.setStyleSheet('color: red')
         self.res_b.setText('失败:' +
                            data_translate.dar_explain[data[offset + 1]])
     config.serial_window._receive_signal.disconnect()
     config.serial_window._receive_signal.connect(
         config.serial_window.re_text_to_box)
Пример #9
0
 def read_SA(self, re_text):
     data = link_layer.data_format(re_text)
     ret_dict = link_layer.get_SA_CA(data)
     self.SA_box.setText(ret_dict['SA'])
     self.SA_len_box.setText(ret_dict['SA_len'])
     self.read_SA_b.setText('成功')
     self._receive_signal.disconnect()
     self._receive_signal.connect(self.re_text_to_box)
Пример #10
0
 def receive_trans(self):
     input_text = self.receive_input_box.toPlainText()
     try:
         data_in = link_layer.data_format(input_text)
         link_layer.all_translate(data_in)
     except Exception as e:
         print(e)
         output('\n\n报文解析过程出现问题,请检查报文。若报文无问题请反馈665593,谢谢!')
     self.receive_output_box.setText(config.output_text)
     config.output_text = ''
Пример #11
0
def send(send_text):
    data = link_layer.data_format(send_text)
    send_d = b''
    for char in data:
        send_d += struct.pack('B', int(char, 16))
    if config.serial_check is True:
        config.serial.write(send_d)
    if config.socket_check is True:
        config.socket.sendall(send_d)
    if config.server_check is True:
        config.server_connection.sendall(send_d)
Пример #12
0
def reply_link_request(re_text):
    data = link_layer.data_format(re_text)
    SA_dict = link_layer.get_SA_CA(data)
    config.serial_window.SA_box.setText(SA_dict['SA'])
    config.serial_window.SA_len_box.setText(SA_dict['SA_len'])
    config.serial_window.read_SA_b.setText('已登录')
    config.serial_window.send_button.setEnabled(True)
    config.serial_window.read_SA_b.setEnabled(True)
    config.serial_window.calc_send_box_len()
    reply_text = link_layer.reply_link(data)
    return reply_text
Пример #13
0
 def re_evt(self, re_text):
     data = link_layer.data_format(re_text)
     offset = 0
     ret_dict = link_layer.get_SA_CA(data)
     offset += 5 + int(ret_dict['SA_len']) + 10
     if data[offset] == '01':
         self.res_b.setStyleSheet('color: green')
         self.res_b.setText('成功')
         offset += 4
         bit_string_len = int(data[offset], 16)
         byte_len = bit_string_len // 8 if bit_string_len % 8 == 0 else bit_string_len // 8 + 1
         offset += 1
         for byte_index in range(byte_len):
             byte_int = int(data[offset], 16)
             offset += 1
             for bit_index in range(8):
                 evt_no = byte_index * 8 + bit_index + 1
                 if evt_no <= 85:
                     if (byte_int >> (7 - bit_index)) & 0x01 == 1:
                         eval('self.valid_c_' + str(evt_no) +
                              '.setChecked(True)')
                     else:
                         eval('self.valid_c_' + str(evt_no) +
                              '.setChecked(False)')
         offset += 1
         bit_string_len = int(data[offset], 16)
         byte_len = bit_string_len // 8 if bit_string_len % 8 == 0 else bit_string_len // 8 + 1
         offset += 1
         for byte_index in range(byte_len):
             byte_int = int(data[offset], 16)
             offset += 1
             for bit_index in range(8):
                 evt_no = byte_index * 8 + bit_index + 1
                 if evt_no <= 85:
                     if (byte_int >> (7 - bit_index)) & 0x01 == 1:
                         eval('self.rpt_c_' + str(evt_no) +
                              '.setChecked(True)')
                     else:
                         eval('self.rpt_c_' + str(evt_no) +
                              '.setChecked(False)')
     else:
         self.res_b.setStyleSheet('color: red')
         self.res_b.setText('失败:' +
                            data_translate.dar_explain[data[offset + 1]])
     config.serial_window._receive_signal.disconnect()
     config.serial_window._receive_signal.connect(
         config.serial_window.re_text_to_box)
Пример #14
0
def read_set_dar(re_text):
    data = link_layer.data_format(re_text)
    offset = 0
    ret_dict = link_layer.get_SA_CA(data)
    offset += 5 + int(ret_dict['SA_len']) + 4
    if data[offset] == '01':
        offset += 6
        if data[offset] == '00':
            return 'ok'
        else:
            return data_translate.dar_explain[data[offset]]
    if data[offset] == '02':
        offset += 2
        dar_sum = int(data[offset], 16)
        offset += 5
        for _ in range(dar_sum):
            if data[offset] != '00':
                return data_translate.dar_explain[data[offset]]
            else:
                offset += 5
        return 'ok'
Пример #15
0
 def re_SA(self, re_text):
     data = link_layer.data_format(re_text)
     offset = 0
     ret_dict = link_layer.get_SA_CA(data)
     offset += 5 + int(ret_dict['SA_len']) + 10
     if data[offset] == '01':
         self.res_b.setStyleSheet('color: green')
         self.res_b.setText('成功')
         offset += 2
         SA_len = int(data[offset], 16)
         self.SA_len_box.setText(str(SA_len))
         SA_text = ''
         for d in data[offset + 1:offset + 1 + SA_len]:
             SA_text += d
         self.SA_box.setText(SA_text)
     else:
         self.res_b.setStyleSheet('color: red')
         self.res_b.setText('失败:' +
                            data_translate.dar_explain[data[offset + 1]])
     config.serial_window._receive_signal.disconnect()
     config.serial_window._receive_signal.connect(
         config.serial_window.re_text_to_box)
Пример #16
0
    def re_rpt(self, re_text):
        data = link_layer.data_format(re_text)
        offset = 0
        ret_dict = link_layer.get_SA_CA(data)
        offset += 5 + int(ret_dict['SA_len']) + 7
        res_sum = True
        offset += 4
        if data[offset] == '01':
            offset += 2
            self.rpt_follow_cb.setCurrentIndex(1 if data[offset] ==
                                               '01' else 0)
            offset += 1
        else:
            offset += 1
            res_sum = False
            self.esam_no_box.setText('失败:' +
                                     data_translate.dar_explain[data[offset +
                                                                     1]])
        offset += 4
        if data[offset] == '01':
            offset += 2
            self.rpt_cb.setCurrentIndex(1 if data[offset] == '01' else 0)
            offset += 1
        else:
            offset += 1
            res_sum = False
            self.esam_ver_box.setText('失败:' +
                                      data_translate.dar_explain[data[offset +
                                                                      1]])
        offset += 4
        if data[offset] == '01':
            offset += 2
            self.conn_sever_cb.setCurrentIndex(1 if data[offset] ==
                                               '01' else 0)
            offset += 1
        else:
            offset += 1
            res_sum = False
            self.esam_key_box.setText('失败:' +
                                      data_translate.dar_explain[data[offset +
                                                                      1]])
        offset += 4
        if data[offset] == '01':
            offset += 2
            array_sum = int(data[offset], 16)
            offset += 1
            channel = ''
            for array_count in range(array_sum):
                offset += 1
                channel += data[offset] + data[offset +
                                               1] + data[offset +
                                                         2] + data[offset + 3]
                if array_count < array_sum - 1:
                    channel += ','
                offset += 4
            self.rpt_channel_box.setText(channel)
        else:
            offset += 1
            res_sum = False
            self.esam_dialog_tm_box.setText(
                '失败:' + data_translate.dar_explain[data[offset + 1]])

        if res_sum is True:
            self.res_b.setStyleSheet('color: green')
            self.res_b.setText('成功')
        config.serial_window._receive_signal.disconnect()
        config.serial_window._receive_signal.connect(
            config.serial_window.re_text_to_box)
Пример #17
0
    def re_esam_info(self, re_text):
        data = link_layer.data_format(re_text)
        offset = 0
        ret_dict = link_layer.get_SA_CA(data)
        offset += 5 + int(ret_dict['SA_len']) + 7
        res_sum = True
        offset += 4
        if data[offset] == '01':
            offset += 1
            ret = param.get_octet(data[offset:])
            self.esam_no_box.setText(ret['octet'])
            offset += ret['offset']
        else:
            offset += 1
            res_sum = False
            self.esam_no_box.setText('失败:' +
                                     data_translate.dar_explain[data[offset +
                                                                     1]])
        offset += 4
        if data[offset] == '01':
            offset += 1
            ret = param.get_octet(data[offset:])
            self.esam_ver_box.setText(ret['octet'])
            offset += ret['offset']
        else:
            offset += 1
            res_sum = False
            self.esam_ver_box.setText('失败:' +
                                      data_translate.dar_explain[data[offset +
                                                                      1]])
        offset += 4
        if data[offset] == '01':
            offset += 1
            ret = param.get_octet(data[offset:])
            self.esam_key_box.setText(ret['octet'])
            offset += ret['offset']
        else:
            offset += 1
            res_sum = False
            self.esam_key_box.setText('失败:' +
                                      data_translate.dar_explain[data[offset +
                                                                      1]])
        offset += 4
        if data[offset] == '01':
            offset += 1
            self.esam_dialog_tm_box.setText(
                str(param.get_double_long_unsigned(data[offset:])))
            offset += 5
        else:
            offset += 1
            res_sum = False
            self.esam_dialog_tm_box.setText(
                '失败:' + data_translate.dar_explain[data[offset + 1]])
        offset += 4
        if data[offset] == '01':
            offset += 1
            self.esam_dialog_remain_box.setText(
                str(param.get_double_long_unsigned(data[offset:])))
            offset += 5
        else:
            offset += 1
            res_sum = False
            self.esam_dialog_remain_box.setText(
                '失败:' + data_translate.dar_explain[data[offset + 1]])
        offset += 4
        if data[offset] == '01':
            offset += 3
            self.esam_addr_ctr_box.setText(
                str(param.get_double_long_unsigned(data[offset:])))
            offset += 5
            self.esam_rpt_ctr_box.setText(
                str(param.get_double_long_unsigned(data[offset:])))
            offset += 5
            self.esam_app_radio_box.setText(
                str(param.get_double_long_unsigned(data[offset:])))
            offset += 5
        else:
            offset += 1
            res_sum = False
            self.esam_addr_ctr_box.setText(
                '失败:' + data_translate.dar_explain[data[offset + 1]])
            self.esam_rpt_ctr_box.setText(
                '失败:' + data_translate.dar_explain[data[offset + 1]])
            self.esam_app_radio_box.setText(
                '失败:' + data_translate.dar_explain[data[offset + 1]])
        offset += 4
        if data[offset] == '01':
            offset += 3
            ret = param.get_octet(data[offset:])
            self.esam_terminal_ver_box.setText(ret['octet'])
            offset += ret['offset']
            ret = param.get_octet(data[offset:])
            self.esam_host_ver_box.setText(ret['octet'])
            offset += ret['offset']
        else:
            offset += 1
            res_sum = False
            self.esam_terminal_ver_box.setText(
                '失败:' + data_translate.dar_explain[data[offset + 1]])
            self.esam_host_ver_box.setText(
                '失败:' + data_translate.dar_explain[data[offset + 1]])

        if res_sum is True:
            self.res_b.setStyleSheet('color: green')
            self.res_b.setText('成功')
        config.serial_window._receive_signal.disconnect()
        config.serial_window._receive_signal.connect(
            config.serial_window.re_text_to_box)
Пример #18
0
 def re_communication(self, re_text):
     data = link_layer.data_format(re_text)
     offset = 0
     ret_dict = link_layer.get_SA_CA(data)
     offset += 5 + int(ret_dict['SA_len']) + 10
     if data[offset] == '01':
         self.res_b.setStyleSheet('color: green')
         self.res_b.setText('成功')
         offset += 4
         self.C_work_mode_l.setCurrentIndex({
             '00': 0,
             '01': 1,
             '02': 2
         }[data[offset]])
         offset += 2
         self.C_online_mode_l.setCurrentIndex({
             '00': 0,
             '01': 1
         }[data[offset]])
         offset += 2
         self.C_connect_mode_l.setCurrentIndex({
             '00': 0,
             '01': 1
         }[data[offset]])
         offset += 2
         self.C_connect_app_mode_l.setCurrentIndex({
             '00': 0,
             '01': 1
         }[data[offset]])
         offset += 2
         array_num = int(data[offset], 16)
         offset += 1
         listen_port_text = ''
         for count in range(array_num):
             listen_port_text += str(param.get_long_unsigned(
                 data[offset:])) + ' '
             offset += 3
         self.C_listen_port_box.setText(listen_port_text)
         ret = param.get_visible(data[offset:])
         self.C_APN_box.setText(ret['visible'])
         offset += ret['offset']
         ret = param.get_visible(data[offset:])
         self.C_usr_box.setText(ret['visible'])
         offset += ret['offset']
         ret = param.get_visible(data[offset:])
         self.C_pw_box.setText(ret['visible'])
         offset += ret['offset']
         ret = param.get_octet(data[offset:])
         self.C_proxy_addr_box.setText(ret['octet'])
         offset += ret['offset']
         self.C_proxy_prot_box.setText(
             str(param.get_long_unsigned(data[offset:])))
         offset += 3
         offset += 1
         overtm_retry_num_byte = int(data[offset], 16)
         self.C_retry_box.setText(str(overtm_retry_num_byte >> 6))
         self.C_over_tm_box.setText(str(overtm_retry_num_byte & 0x3f))
         offset += 1
         print(data[offset:])
         self.C_heart_tm_box.setText(
             str(param.get_long_unsigned(data[offset:])))
         offset += 3
     else:
         self.res_b.setStyleSheet('color: red')
         self.res_b.setText('失败:' +
                            data_translate.dar_explain[data[offset + 1]])
     config.serial_window._receive_signal.disconnect()
     config.serial_window._receive_signal.connect(
         config.serial_window.re_text_to_box)
Пример #19
0
def reply_rpt_request(re_text):
    data = link_layer.data_format(re_text)
    reply_text = link_layer.reply_rpt(data)
    return reply_text