package index.JPanelMoudle;
|
|
import baowen.WriteReadAnchor;
|
import gnu.io.SerialPort;
|
import tools.ChuanKou.SerialPortUtil;
|
import tools.CustomProgressBar;
|
import tools.ShowMessage;
|
import ymodem.getFilesDataBytes;
|
import ymodem.YModemUpgradeThread;
|
|
import javax.swing.*;
|
import javax.swing.border.TitledBorder;
|
|
|
import java.awt.*;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.io.File;
|
|
|
public class versionUpgradeComp {
|
private static JPanel versionUpdate;//版本升级面板
|
private static JLabel label9;//空标签,进行占位
|
private static JTextField readVersion_jf;//读取扫描器版本文本框
|
private static JTextField chooseVersion_jf;//选择固件文本框
|
|
private static JButton chooseVersion;//选择固件按钮
|
private static JButton write_saoMiao;//写入扫描器按钮
|
public static boolean write=false;//写入扫描器按钮
|
public static boolean xinBiaoUp=false;//升级信标版本按钮
|
private static JButton readVersion_jb;//读取版本按钮
|
private static JButton updateAnchor_jb;//升级信标版本按钮
|
|
private static CustomProgressBar jindu_SaoMiaoQi;//写入扫描器进度条
|
private static CustomProgressBar updateAnchor_jf;//升级信标版本进度条
|
|
private static YModemUpgradeThread upgradeThread; // 保存线程引用
|
private static Color color = new Color(6, 176, 37);; // 保存线程引用
|
|
// 获取版本升级面板,若为空则创建
|
public static JPanel getVersionUpdate() {
|
if (versionUpdate == null) {
|
versionUpdate = new JPanel(); // 初始化该面板
|
versionUpdate.setBorder(new TitledBorder("固件升级"));
|
}
|
return versionUpdate;
|
}
|
|
// 获取空标签,若为空则创建
|
public static JLabel getLabel9() {
|
if (label9 == null) {
|
label9 = new JLabel(); // 初始化该标签
|
}
|
return label9;
|
}
|
|
|
|
// 获取 选择固件 按钮,若为空则创建
|
public static JButton getChooseVersion() {
|
if (chooseVersion == null) {
|
chooseVersion = new JButton("选择固件"); // 初始化该按钮
|
chooseVersion.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
// 打开文件选择对话框
|
String currentDirectory = System.getProperty("user.dir");
|
JFileChooser fileChooser = new JFileChooser();
|
// 设置文件选择对话框为可选择文件
|
fileChooser.setDialogTitle("选择固件");
|
fileChooser.setCurrentDirectory(new File(currentDirectory));
|
int result = fileChooser.showOpenDialog(readParamsComp.getReadAncParam_jp());
|
if (result == JFileChooser.APPROVE_OPTION) {
|
// 如果用户选择了文件
|
File selectedFile = fileChooser.getSelectedFile();
|
// 显示选择的文件路径
|
getChooseVersion_jf().setText(selectedFile.getPath());//文件名称);
|
}
|
}
|
});
|
}
|
return chooseVersion;
|
}
|
|
// 获取 写入扫描器 按钮,若为空则创建
|
public static JButton getWrite_saoMiao() {
|
if (write_saoMiao == null) {
|
write_saoMiao = new JButton("写入扫描器"); // 初始化该按钮
|
write_saoMiao.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if(!write) {
|
String filePath = getChooseVersion_jf().getText();
|
if (!ComMoudleComp.isChuankou()) {
|
ShowMessage.zidingyi("串口未识别");
|
return;
|
}
|
if (filePath == null || filePath.length() < 10) {
|
ShowMessage.zidingyi("固件不正确");
|
return;
|
}
|
SerialPort serialPort = ComMoudleComp.getSerialPort();
|
write = true;
|
byte[] bytes = WriteReadAnchor.write_lora((byte) 0x10, (byte) 0x2, 1);
|
YModemUpgradeThread.shengji(serialPort,filePath,bytes);
|
write_saoMiao.setText("取消写入");
|
jindu_SaoMiaoQi.setStringPainted(true); // 显示百分比文字
|
}else {
|
YModemUpgradeThread.setSendDataFlag(true);
|
exitUpgrade();
|
}
|
}
|
});
|
}
|
return write_saoMiao;
|
}
|
|
|
|
// 获取 读取扫描器版本 按钮,若为空则创建
|
public static JButton getReadVersion_jb() {
|
if (readVersion_jb == null) {
|
readVersion_jb = new JButton("读取扫描器版本"); // 初始化该按钮
|
readVersion_jb.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
|
if (!ComMoudleComp.isChuankou()) {
|
ShowMessage.zidingyi("串口未识别");
|
return;
|
}
|
ShowMessage.zidingyi("读取扫描器版本指令发送成功");
|
byte[] byt = WriteReadAnchor.ReadData((byte) 0x2, (byte) 0x50);
|
WriteReadAnchor.sendData(ComMoudleComp.getSerialPort(), byt);
|
}
|
|
});
|
}
|
return readVersion_jb;
|
}
|
|
// 获取 升级信标版本 按钮,若为空则创建
|
public static JButton getUpdateAnchor_jb() {
|
if (updateAnchor_jb == null) {
|
updateAnchor_jb = new JButton("升级信标版本"); // 初始化该按钮
|
updateAnchor_jb.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if (!xinBiaoUp) {
|
|
if (!ComMoudleComp.isChuankou()) {
|
ShowMessage.zidingyi("串口未识别");
|
return;
|
}
|
String text = readParamsComp.getAnchorId_jf().getText();
|
if (text.length() != 4) {
|
ShowMessage.zidingyi("信标ID不正确,请先读取信标参数");
|
return;
|
}
|
SerialPort serialPort = ComMoudleComp.getSerialPort();
|
xinBiaoUp=true;
|
updateAnchor_jb.setText("退出信标升级");
|
WriteReadAnchor.updateLora("0", (byte) 0xAA,(byte) 0x06, text,serialPort,(byte) 0x02);
|
}else {
|
exitUpgradeXinBiao();
|
}
|
}
|
});
|
}
|
return updateAnchor_jb;
|
}
|
|
|
// 获取 读取扫描器版本 文本框,若为空则创建
|
public static JTextField getReadVersion_jf() {
|
if (readVersion_jf == null) {
|
readVersion_jf = new JTextField(); // 初始化该文本框
|
}
|
return readVersion_jf;
|
}
|
|
// 获取 选择固件 文本框,若为空则创建
|
public static JTextField getChooseVersion_jf() {
|
if (chooseVersion_jf == null) {
|
chooseVersion_jf = new JTextField(); // 初始化该文本框
|
chooseVersion_jf.setEnabled(false);
|
}
|
return chooseVersion_jf;
|
}
|
|
// 获取 写入扫描器 进度条,若为空则创建
|
public static CustomProgressBar getJindu_SaoMiaoQi() {
|
if (jindu_SaoMiaoQi == null) {
|
jindu_SaoMiaoQi = new CustomProgressBar(); // 初始化该进度条
|
jindu_SaoMiaoQi.setForeground(color); // 设置进度条前景色为绿色
|
// 自定义UI来修改文本颜色
|
}
|
return jindu_SaoMiaoQi;
|
}
|
|
|
// 获取 升级信标版本 进度条,若为空则创建
|
public static CustomProgressBar getUpdateAnchor_jf() {
|
if (updateAnchor_jf == null) {
|
updateAnchor_jf = new CustomProgressBar(); // 初始化该进度条
|
updateAnchor_jf.setForeground(color); // 设置进度条前景色为绿色
|
}
|
return updateAnchor_jf;
|
}
|
|
|
public static boolean isWrite() {
|
return write;
|
}
|
|
public static void exitUpgrade() {
|
write=false;
|
write_saoMiao.setText("写入扫描器");
|
jindu_SaoMiaoQi.setValue(0); // 显示百分比文字
|
}
|
|
|
public static void exitUpgradeXinBiao() {
|
xinBiaoUp=false;
|
updateAnchor_jb.setText("升级信标版本");
|
updateAnchor_jf.setValue(0); // 显示百分比文字
|
}
|
}
|