示例#1
0
 def copy_to_clipboard(self):
     """copy_to_clipboard"""
     trans = Translate(self.msg_now)
     text = trans.get_clipboard_text(self.show_level_cb.isChecked(), self.show_dtype_cb.isChecked())
     clipboard = QtGui.QApplication.clipboard()
     clipboard.clear()
     clipboard.setText(text)
示例#2
0
 def trans_se_msg(self):
     """translate"""
     if len(self.msg_now) < 5:
         return
     trans = Translate(self.msg_now)
     structed_explain = trans.get_structed_explain(
         is_show_type=self.show_dtype_cb.isChecked(),
         has_linklayer=self.show_linklayer_cb.isChecked())
     self.explain_box.setText(r'%s' % structed_explain)
     self.se_send_b.setEnabled(True if trans.is_success else False)
     if self.se_send_b.isEnabled():
         self.apdu_text = trans.get_apdu_text()
     if trans.is_success:
         self.get_current_se_box().textChanged.disconnect(
             self.trans_msg_box)
         cursor = self.get_current_se_box().textCursor()
         cursor_pos = cursor.position()
         scroll_hpos = self.get_current_se_box().horizontalScrollBar(
         ).value()
         scroll_vpos = self.get_current_se_box().verticalScrollBar().value()
         self.get_current_se_box().setPlainText(
             trans.get_structed_msg(
                 has_linklayer=self.show_linklayer_cb.isChecked()))
         cursor = self.get_current_se_box().textCursor()
         cursor.setPosition(cursor_pos)
         self.get_current_se_box().setTextCursor(cursor)
         self.get_current_se_box().horizontalScrollBar().setValue(
             scroll_hpos)
         self.get_current_se_box().verticalScrollBar().setValue(scroll_vpos)
         self.get_current_se_box().textChanged.connect(self.trans_msg_box)
示例#3
0
 def send_se_msg(self):
     """send sendbox msg"""
     msg = self.get_current_se_box().toPlainText()
     if len(msg) < 5:
         return
     trans = Translate(msg)
     apdu_text = trans.get_apdu_text()
     self.se_apdu_signal.emit(apdu_text)
示例#4
0
 def start_trans(self):
     """start_trans"""
     if len(self.msg_box.toPlainText()) < 5:
         self.output_box.setText('请点选一条报文。\n若软件无法识别请手动复制到上方框中。')
         return
     trans = Translate(self.msg_box.toPlainText())
     brief = trans.get_brief()
     full = trans.get_full(self.show_level_cb.isChecked(),
                           self.show_dtype_cb.isChecked())
     self.output_box.setText(r'<b>【概览】</b><p>%s</p><hr><b>【完整】</b>%s' %
                             (brief, full))
示例#5
0
    def add_msg_table_row(self, m_text, chan_index, direction):
        """add message row"""
        trans = Translate(m_text)
        brief = trans.get_brief()
        # direction = trans.get_direction()
        client_addr = trans.get_CA()
        if config.IS_FILETER_CA and client_addr != '00' and client_addr != config.COMMU.master_addr:
            print('过滤报文:CA不匹配')
            return
        server_addr = trans.get_SA()
        logic_addr = trans.get_logic_addr()
        chan_text = {0: '串口', 1: '前置机', 2: '服务器'}.get(chan_index)

        # chk to add tmn addr to table
        if direction == '←':
            for row_num in range(self.tmn_table.rowCount()):
                if server_addr == self.tmn_table.item(row_num, 1).text()\
                and logic_addr == self.tmn_table.cellWidget(row_num, 2).value()\
                and chan_index == self.tmn_table.cellWidget(row_num, 3).currentIndex():
                    break
            else:
                is_cb_checked = False if chan_index == 1 else True
                self.add_tmn_table_row(tmn_addr=server_addr, logic_addr=logic_addr,\
                                        chan_index=chan_index, is_checked=is_cb_checked)

        text_color = QtGui.QColor(220, 226, 241) if direction == '→' else\
                    QtGui.QColor(227, 237, 205) if direction == '←' else QtGui.QColor(255, 255, 255)
        row_pos = self.msg_table.rowCount()
        self.msg_table.insertRow(row_pos)

        item = QtGui.QTableWidgetItem(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        # item.setBackground(text_color)
        self.msg_table.setItem(row_pos, 0, item)

        addr_text = '{SA}:{logic}'.format(SA=server_addr, logic=logic_addr)
        item = QtGui.QTableWidgetItem(addr_text)
        # item.setBackground(text_color)
        self.msg_table.setItem(row_pos, 1, item)

        item = QtGui.QTableWidgetItem(chan_text + direction)
        item.setBackground(text_color)
        self.msg_table.setItem(row_pos, 2, item)

        item = QtGui.QTableWidgetItem(brief)
        if brief == '无效报文':
            item.setTextColor(QtCore.Qt.red)
        if brief.find('(访问失败)') == 0:
            item.setTextColor(QtGui.QColor(255, 140, 0))
        self.msg_table.setItem(row_pos, 3, item)

        msg_text = common.format_text(m_text)
        item = QtGui.QTableWidgetItem(msg_text)
        # item.setBackground(text_color)
        self.msg_table.setItem(row_pos, 4, item)

        if row_pos > config.MSG_TABLE_ROW_MAX:
            self.msg_table.removeRow(0)

        self.msg_table.scrollToBottom()

        # log
        self.msg_log.add_log(addr_text, chan_text, direction, brief, msg_text)

        service = trans.get_service()
        if service == '01' and self.is_reply_link:
            reply_apdu_text = reply.get_link_replay_apdu(trans)
            self.send_apdu(reply_apdu_text, tmn_addr=server_addr,\
                            logic_addr=logic_addr, chan_index=chan_index, C_text='01')
        if service[:2] == '88' and self.is_reply_rpt:
            reply_apdu_text = reply.get_rpt_replay_apdu(trans)
            self.send_apdu(reply_apdu_text, tmn_addr=server_addr,\
                            logic_addr=logic_addr, chan_index=chan_index, C_text='03')
        if service == '8505' and self.is_reply_split and trans.is_access_successed:
            reply_apdu_text = reply.get_rpt_replay_split(trans)
            self.send_apdu(reply_apdu_text, tmn_addr=server_addr,\
                            logic_addr=logic_addr, chan_index=chan_index, C_text='43')