Skip to content

Commit

Permalink
V3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvught committed Jul 31, 2023
1 parent 55fef4b commit fcb205b
Show file tree
Hide file tree
Showing 6 changed files with 453 additions and 31 deletions.
4 changes: 2 additions & 2 deletions FirmwareUpdateUI/build.num
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Mon Mar 14 14:23:59 CET 2022
build.number=3
#Mon Jul 31 15:46:39 CEST 2023
build.number=4
11 changes: 8 additions & 3 deletions FirmwareUpdateUI/src/org/gd32/dmx/FirmwareInstallation.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.net.InetAddress;
import java.net.InterfaceAddress;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
Expand All @@ -58,7 +59,7 @@ public class FirmwareInstallation extends JDialog {
private JCheckBox chckbxReboot;
private JTextField textVersion;

public FirmwareInstallation(Node node, FirmwareUpdateUI firmwareUpdateUI) throws Exception {
public FirmwareInstallation(Node node, FirmwareUpdateUI firmwareUpdateUI, InterfaceAddress interfaceAddress) throws Exception {
InitComponents();
CreateEvents();

Expand All @@ -80,7 +81,7 @@ public FirmwareInstallation(Node node, FirmwareUpdateUI firmwareUpdateUI) throws
if (!tftpServer.contains("On")) {
// Error
} else {
TFTPClient frame = new TFTPClient("", InetAddress.getByName(node.getIpAdress()));
TFTPClient frame = new TFTPClient("", InetAddress.getByName(node.getIpAdress()), interfaceAddress);
frame.setVisible(true);

Thread t = new Thread() {
Expand All @@ -104,7 +105,11 @@ public void run() {
e1.printStackTrace();
}

final String tftpServer = firmwareUpdateUI.requestUDP(node, "?tftp#");
String tftpServer;

do {
tftpServer = firmwareUpdateUI.requestUDP(node, "?tftp#");
} while (tftpServer.contains("ERROR"));

chckbxTFTPOff.setSelected(!tftpServer.contains("On"));

Expand Down
63 changes: 49 additions & 14 deletions FirmwareUpdateUI/src/org/gd32/dmx/FirmwareUpdateUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.InterfaceAddress;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
Expand Down Expand Up @@ -101,11 +102,17 @@ public class FirmwareUpdateUI extends JFrame {
private JMenuItem mntmVersion;
private JMenu mnWorkflow;
private JMenuItem mntmFirmwareInstallation;
private JMenu mnNetwork;
private JMenuItem mntmSelectInterface;

private static InterfaceAddress interfaceAddress;

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
NetworkInterfaces networkInterfaces = new NetworkInterfaces();
FirmwareUpdateUI.interfaceAddress = networkInterfaces.getInterfaceAddress();
FirmwareUpdateUI frame = new FirmwareUpdateUI();
frame.setVisible(true);
frame.constructTree();
Expand All @@ -119,17 +126,17 @@ public void run() {
public FirmwareUpdateUI() {
System.out.println(System.getProperty("os.name"));

setTitle("Firmware Update Manager");
setTitle(interfaceAddress.getAddress());

createReceiveSocket();
createSocket();

initComponents();
createEvents();
}

private void initComponents() {
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setBounds(100, 100, 338, 350);
setBounds(100, 100, 408, 350);

JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
Expand Down Expand Up @@ -184,6 +191,13 @@ private void initComponents() {
mntmFirmwareInstallation = new JMenuItem("Firmware installation");
mnWorkflow.add(mntmFirmwareInstallation);

mnNetwork = new JMenu("Network");
menuBar.add(mnNetwork);

mntmSelectInterface = new JMenuItem("Select Interface");
mntmSelectInterface.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_DOWN_MASK));
mnNetwork.add(mntmSelectInterface);

mnHelp = new JMenu("Help");
menuBar.add(mnHelp);

Expand Down Expand Up @@ -357,7 +371,7 @@ public void actionPerformed(ActionEvent e) {
final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) path.getPathComponent(1);
final Node node = (Node) treeNode.getUserObject();
try {
TFTPClient client = new TFTPClient("", InetAddress.getByName(node.getIpAdress()));
TFTPClient client = new TFTPClient("", InetAddress.getByName(node.getIpAdress()), getInterfaceAddress());
client.setVisible(true);
} catch (UnknownHostException e1) {
e1.printStackTrace();
Expand All @@ -384,7 +398,7 @@ public void actionPerformed(ActionEvent e) {
}

try {
FirmwareInstallation firmware = new FirmwareInstallation(node, getFirmwareUpdate());
FirmwareInstallation firmware = new FirmwareInstallation(node, getFirmwareUpdate(), interfaceAddress);
firmware.setVisible(true);
} catch (Exception ex) {
ex.printStackTrace();
Expand Down Expand Up @@ -424,6 +438,22 @@ public void mouseClicked(MouseEvent e) {
}
}
});

mntmSelectInterface.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doInterfaces();
}
});
}

private InterfaceAddress getInterfaceAddress() {
return FirmwareUpdateUI.interfaceAddress;
}

private void doInterfaces() {
NetworkInterfaces networkInterfaces;
networkInterfaces = new NetworkInterfaces(this);
networkInterfaces.Show();
}

private FirmwareUpdateUI getFirmwareUpdate() {
Expand Down Expand Up @@ -509,6 +539,16 @@ private boolean isRightClick(MouseEvent e) {
&& (e.getModifiers() & InputEvent.CTRL_MASK) != 0));
}

public void setTitle(InetAddress inetAddress) {
String text = inetAddress.getHostAddress();
setTitle("Firmware Update Manager " + text);
}

public void setInterfaceAddress(InterfaceAddress interfaceAddress) {
FirmwareUpdateUI.interfaceAddress = interfaceAddress;
createSocket();
}

public void constructTree() {
Graphics g = getGraphics();

Expand All @@ -522,14 +562,9 @@ public void constructTree() {

treeMap = new TreeMap<Integer, Node>();

for (int i = 0; i < 2; i++) {
for (int i = 0; i < 1; i++) {
try {
if (i == 0) {
broadcast("?list#*");
broadcast("?list#*");
} else {
broadcast("?list#");
}
broadcast("?list#");
while (true) {
byte[] buffer = new byte[BUFFERSIZE];
DatagramPacket dpack = new DatagramPacket(buffer, buffer.length);
Expand Down Expand Up @@ -647,13 +682,13 @@ public String requestUDP(Node node, String request) {
return new String("#ERROR - time out");
}

private void createReceiveSocket() {
private void createSocket() {
if (socketReceive != null) {
socketReceive.close();
}
try {
socketReceive = new DatagramSocket(null);
SocketAddress sockaddr = new InetSocketAddress(PORT);
SocketAddress sockaddr = new InetSocketAddress(interfaceAddress.getAddress(), PORT);
socketReceive.setBroadcast(true);
socketReceive.setSoTimeout(1000);
socketReceive.bind(sockaddr);
Expand Down
Loading

0 comments on commit fcb205b

Please sign in to comment.