package main;
|
|
import javax.swing.JPanel;
|
|
import java.awt.BorderLayout;
|
|
import javax.swing.border.TitledBorder;
|
import javax.swing.filechooser.FileFilter;
|
import javax.swing.JTextField;
|
|
import java.awt.GridLayout;
|
|
import javax.swing.JButton;
|
import javax.swing.JComboBox;
|
import javax.swing.JCheckBox;
|
import javax.swing.JFileChooser;
|
import javax.swing.JOptionPane;
|
import javax.swing.JPasswordField;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTextArea;
|
import javax.swing.ScrollPaneConstants;
|
import javax.swing.JLabel;
|
import javax.swing.DefaultComboBoxModel;
|
|
import java.awt.event.ActionListener;
|
import java.awt.event.ActionEvent;
|
import java.io.File;
|
import java.awt.Font;
|
|
import javax.swing.ImageIcon;
|
|
import com.dev.bybb.CommBYBB;
|
import com.dev.fbs9600_mon.SPCommMon;
|
import com.dev.ntm.SPCommNTM;
|
|
public class page_dfu extends JPanel {
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
private JTextField tf_updatefile;
|
private JTextField tf_dfu_addr_start;
|
private JTextField tf_dfu_addr_end;
|
private JButton btn_update_stop;
|
private JButton btn_update_start;
|
public JTextArea ta_dfu_inf;
|
private JComboBox<Object> cb_dfu_bitrate;
|
public JCheckBox ckc_read_check;
|
private JFileChooser parseDir;
|
private JButton btn_openfile;
|
private int mDevType = 0;
|
private SPCommMon SerialComm_Mon = null;
|
private SPCommNTM SPComm_NTM = null;
|
private CommBYBB SPComm_BYBB = null;
|
|
/**
|
* Create the panel.
|
*/
|
public page_dfu() {
|
|
setLayout(new BorderLayout(0, 0));
|
|
JPanel panel = new JPanel();
|
add(panel, BorderLayout.NORTH);
|
panel.setLayout(new BorderLayout(0, 0));
|
|
JPanel panel_1 = new JPanel();
|
panel_1.setBorder(new TitledBorder(null, " \u7A0B\u5E8F\u6587\u4EF6\u8DEF\u5F84", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
panel.add(panel_1, BorderLayout.NORTH);
|
panel_1.setLayout(new BorderLayout(0, 0));
|
|
tf_updatefile = new JTextField();
|
panel_1.add(tf_updatefile, BorderLayout.CENTER);
|
tf_updatefile.setColumns(10);
|
|
JPanel panel_2 = new JPanel();
|
panel.add(panel_2, BorderLayout.SOUTH);
|
panel_2.setLayout(new GridLayout(0, 7, 4, 0));
|
|
btn_openfile = new JButton("\u5BFC\u5165\u6587\u4EF6");
|
btn_openfile.setIcon(new ImageIcon(page_dfu.class.getResource("/png_32x32/Button Add.png")));
|
btn_openfile.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(null == parseDir) {
|
parseDir = new JFileChooser();
|
}
|
|
parseDir.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
parseDir.setFileFilter(new FileFilter() {
|
@Override
|
public boolean accept(File f) {
|
if (f.isDirectory())
|
return true;
|
|
if((SPCommMon.DEV_TYPE_MON_SAMD09 == mDevType)
|
||(SPCommMon.DEV_TYPE_MON_SWM == mDevType)
|
|| (SPCommMon.DEV_TYPE_NTM == mDevType)) {
|
return (f.getName().toUpperCase().endsWith(".CIM")
|
|| f.getName().toUpperCase().endsWith(".SAM"));
|
} else if(SPCommMon.DEV_TYPE_MON_MSP430 == mDevType) {
|
return f.getName().toUpperCase().endsWith(".SPM");
|
} else {
|
return f.getName().toUpperCase().endsWith(".BIN");
|
}
|
}
|
|
@Override
|
public String getDescription() {
|
if((SPCommMon.DEV_TYPE_MON_SAMD09 == mDevType)
|
||(SPCommMon.DEV_TYPE_MON_SWM == mDevType)
|
|| (SPCommMon.DEV_TYPE_NTM == mDevType)) {
|
return "*.CIM;*.SAM";
|
} else if(SPCommMon.DEV_TYPE_MON_MSP430 == mDevType) {
|
return "*.SPM";
|
} else {
|
return "*.BIN";
|
}
|
}
|
});
|
parseDir.setDialogTitle("´ò¿ªÉý¼¶Îļþ!");
|
if(JFileChooser.APPROVE_OPTION == parseDir.showOpenDialog(null)) {
|
//String file_n = parseDir.getSelectedFile().getAbsolutePath();
|
//File f = new File(file_n);
|
//if(f.length() < ((1024*16-256-4096)+64)) {
|
tf_updatefile.setText(parseDir.getSelectedFile().getAbsolutePath());
|
//} else {
|
// JOptionPane.showMessageDialog(frmSerialport, "Îļþ³¤¶È³¬¹ýоƬ´æ´¢¿Õ¼ä, ÇëÑ¡ÔñÕýÈ·µÄÎļþ!");
|
//}
|
}
|
}
|
});
|
panel_2.add(btn_openfile);
|
|
JPanel panel_3 = new JPanel();
|
panel_3.setBorder(new TitledBorder(null, "DFU\u6CE2\u7279\u7387", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
panel_2.add(panel_3);
|
panel_3.setLayout(new BorderLayout(0, 0));
|
|
cb_dfu_bitrate = new JComboBox<Object>();
|
cb_dfu_bitrate.setModel(new DefaultComboBoxModel<Object>(new String[] {"4800", "9600", "19200", "38400", "57600", "115200"}));
|
panel_3.add(cb_dfu_bitrate);
|
|
JPanel panel_4 = new JPanel();
|
panel_4.setBorder(new TitledBorder(null, "\u8BFB\u53D6\u6821\u9A8C", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
panel_2.add(panel_4);
|
panel_4.setLayout(new BorderLayout(0, 0));
|
|
ckc_read_check = new JCheckBox("\u542F\u7528");
|
panel_4.add(ckc_read_check, BorderLayout.CENTER);
|
|
JPanel panel_5 = new JPanel();
|
panel_5.setBorder(new TitledBorder(null, "DFU\u8D77\u59CB\u5355\u4F53\u5730\u5740", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
panel_2.add(panel_5);
|
panel_5.setLayout(new BorderLayout(0, 0));
|
|
tf_dfu_addr_start = new JTextField();
|
panel_5.add(tf_dfu_addr_start);
|
tf_dfu_addr_start.setColumns(10);
|
|
JPanel panel_6 = new JPanel();
|
panel_6.setBorder(new TitledBorder(null, "DFU\u7ED3\u675F\u5355\u4F53\u5730\u5740", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
panel_2.add(panel_6);
|
panel_6.setLayout(new BorderLayout(0, 0));
|
|
tf_dfu_addr_end = new JTextField();
|
panel_6.add(tf_dfu_addr_end);
|
tf_dfu_addr_end.setColumns(10);
|
|
btn_update_start = new JButton("\u542F\u52A8");
|
btn_update_start.setIcon(new ImageIcon(page_dfu.class.getResource("/png_32x32/Button Play.png")));
|
btn_update_start.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(tf_updatefile.getText().trim().length() < 3) {
|
JOptionPane.showMessageDialog(null, "ÇëÏÈÊäÈëÉý¼¶³ÌÐòÎļþ!");
|
return;
|
}
|
|
if(null != SerialComm_Mon) {
|
//System.out.println("SerialComm_Mon");
|
//-------------------------------------------------------------//
|
boolean pwd_ch = true;
|
for(int len=0; len<SerialComm_Mon.dt_dfu_pwd.length; len++) {
|
if(SerialComm_Mon.dt_dfu_pwd_auto[len] != SerialComm_Mon.dt_dfu_pwd[len]) {
|
pwd_ch = false;
|
break;
|
}
|
}
|
//-------------------------------------------------------------//
|
if(false == pwd_ch) {
|
JPasswordField pw = new JPasswordField();
|
JOptionPane.showMessageDialog(null, pw, "ÇëÊäÈëÊÚȨÃÜÂë!", JOptionPane.PLAIN_MESSAGE);
|
char[] pass = pw.getPassword();
|
if(pass.length < 1) {
|
return;
|
}
|
if(pass.length != SerialComm_Mon.dt_dfu_pwd.length) {
|
JOptionPane.showMessageDialog(null, "ÃÜÂ볤¶È´íÎó!");
|
return;
|
}
|
pwd_ch = true;
|
for(int len=0; len<pass.length; len++) {
|
SerialComm_Mon.dt_dfu_pwd[len] = pass[len];
|
if(SerialComm_Mon.dt_dfu_pwd[len] != SerialComm_Mon.dt_dfu_pwd_auto[len]) {
|
pwd_ch = false;
|
break;
|
}
|
}
|
if(false == pwd_ch) {
|
for(int len=0; len<SerialComm_Mon.dt_dfu_pwd.length; len++) {
|
SerialComm_Mon.dt_dfu_pwd[len] = 0;
|
}
|
JOptionPane.showMessageDialog(null, "ÃÜÂë´íÎó!");
|
return;
|
}
|
}
|
//-------------------------------------------------------------//
|
|
int dfu_addr_start = 0;
|
int dfu_addr_end = 0;
|
try {
|
dfu_addr_start = Integer.parseInt(tf_dfu_addr_start.getText());
|
dfu_addr_end = Integer.parseInt(tf_dfu_addr_end.getText());
|
} catch (Exception e1) {
|
JOptionPane.showMessageDialog(null, "ÇëÏÈÊäÈëÄ¿±êÄ£¿éÆðʼµØÖ·ºÍ½áÊøµØÖ·!");
|
return;
|
}
|
|
if(dfu_addr_start > 255) {
|
dfu_addr_start = 255;
|
tf_dfu_addr_start.setText(String.valueOf(dfu_addr_start));
|
}
|
if(dfu_addr_end > 255) {
|
dfu_addr_end = 255;
|
tf_dfu_addr_end.setText(String.valueOf(dfu_addr_end));
|
}
|
|
SerialComm_Mon.setDfuCommAddr(dfu_addr_start, dfu_addr_end);
|
SerialComm_Mon.setUpdateCmd(true, ckc_read_check.isSelected(), parseDir.getSelectedFile().getAbsolutePath(),
|
Integer.parseInt((String) cb_dfu_bitrate.getSelectedItem()));
|
SerialComm_Mon.setCommCmd(SPCommMon.CMD_TYPE_WRITE, SPCommMon.UART_MonomerDFU_RegAddr,
|
(short)0x55AA, (short)0xAA55, (short)0x7F7F);
|
} else if(null != SPComm_NTM) {
|
SPComm_NTM.setUpdateCmd(true, parseDir.getSelectedFile().getAbsolutePath());
|
//System.out.println("SPComm_NTM");
|
} else if(null != SPComm_BYBB) {
|
if(JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(null, "È·¶¨ÒªÉý¼¶³ÌÐòÂð?",
|
"²Ù×÷È·ÈÏ", JOptionPane.YES_NO_OPTION)) {
|
return;
|
}
|
|
SPComm_BYBB.setCommCmd_DFU(true, parseDir.getSelectedFile().getAbsolutePath(), ta_dfu_inf);
|
}
|
}
|
});
|
panel_2.add(btn_update_start);
|
|
btn_update_stop = new JButton("\u505C\u6B62");
|
btn_update_stop.setIcon(new ImageIcon(page_dfu.class.getResource("/png_32x32/Button Stop.png")));
|
btn_update_stop.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(null != SerialComm_Mon) {
|
SerialComm_Mon.setUpdateCmd(false, false, "",
|
Integer.parseInt((String) cb_dfu_bitrate.getSelectedItem()));
|
} else if(null != SPComm_NTM) {
|
SPComm_NTM.setUpdateCmd(false, "");
|
} else if(null != SPComm_BYBB) {
|
SPComm_BYBB.setCommCmd_DFU(false, "", ta_dfu_inf);
|
}
|
}
|
});
|
panel_2.add(btn_update_stop);
|
|
JScrollPane scrollPane = new JScrollPane();
|
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
add(scrollPane, BorderLayout.CENTER);
|
|
ta_dfu_inf = new JTextArea();
|
ta_dfu_inf.setFont(new Font("Consolas", Font.PLAIN, 18));
|
scrollPane.setViewportView(ta_dfu_inf);
|
|
JLabel lblNewLabel = new JLabel("\u5347\u7EA7\u4FE1\u606F");
|
scrollPane.setColumnHeaderView(lblNewLabel);
|
|
setButttonState(false);
|
}
|
|
public void setDfu_Mon_Addr(String start_addr, String end_addr) {
|
tf_dfu_addr_start.setText(start_addr);
|
tf_dfu_addr_end.setText(end_addr);
|
}
|
|
public void setButttonState(boolean state) {
|
btn_openfile.setEnabled(state);
|
btn_update_start.setEnabled(state);
|
btn_update_stop.setEnabled(state);
|
}
|
|
public void set_SerialComm_Mon(SPCommMon sp_comm) {
|
SerialComm_Mon = sp_comm;
|
if(null != SerialComm_Mon) {
|
mDevType = SerialComm_Mon.m_DEV_TYPE;
|
}
|
}
|
|
public void setComm_NTM(SPCommNTM sp_comm) {
|
SPComm_NTM = sp_comm;
|
mDevType = SPCommMon.DEV_TYPE_NTM;
|
}
|
|
public void setComm_BYBB(CommBYBB sp_comm) {
|
SPComm_BYBB = sp_comm;
|
mDevType = SPCommMon.DEV_TYPE_MON_SAMD09;
|
}
|
}
|