[cooja/serialsocket] SerialSocketServer: Applied some renames

This commit is contained in:
Enrico Joerns 2014-04-13 19:11:40 +02:00
parent 0d9698b908
commit 585db7df96

View file

@ -81,21 +81,22 @@ import org.contikios.cooja.interfaces.SerialPort;
@PluginType(PluginType.MOTE_PLUGIN) @PluginType(PluginType.MOTE_PLUGIN)
public class SerialSocketServer extends VisPlugin implements MotePlugin { public class SerialSocketServer extends VisPlugin implements MotePlugin {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(SerialSocketServer.class); private static final Logger logger = Logger.getLogger(SerialSocketServer.class);
private final static int STATUSBAR_WIDTH = 350; private final static int STATUSBAR_WIDTH = 350;
public final int LISTEN_PORT; private final int SERVER_DEFAULT_PORT;
private SerialPort serialPort; private final SerialPort serialPort;
private Observer serialDataObserver; private Observer serialDataObserver;
private JLabel statusLabel, inLabel, outLabel; private JLabel socketStatusLabel, socketToMoteLabel, moteToSocketLabel;
private JButton serverStartButton; private JButton serverStartButton;
private int inBytes = 0, outBytes = 0; private int inBytes = 0, outBytes = 0;
private ServerSocket server; private ServerSocket server;
private Socket client; private Socket clientSocket;
private DataInputStream in; private DataInputStream in;
private DataOutputStream out; private DataOutputStream out;
@ -107,7 +108,7 @@ public class SerialSocketServer extends VisPlugin implements MotePlugin {
updateTimer.start(); updateTimer.start();
LISTEN_PORT = 60000 + mote.getID(); SERVER_DEFAULT_PORT = 60000 + mote.getID();
/* GUI components */ /* GUI components */
if (Cooja.isVisualized()) { if (Cooja.isVisualized()) {
@ -130,7 +131,7 @@ public class SerialSocketServer extends VisPlugin implements MotePlugin {
nf.setGroupingUsed(false); nf.setGroupingUsed(false);
final JFormattedTextField serverPortField = new JFormattedTextField(new NumberFormatter(nf)); final JFormattedTextField serverPortField = new JFormattedTextField(new NumberFormatter(nf));
serverPortField.setColumns(5); serverPortField.setColumns(5);
serverPortField.setText(String.valueOf(LISTEN_PORT)); serverPortField.setText(String.valueOf(SERVER_DEFAULT_PORT));
c.gridx++; c.gridx++;
socketPanel.add(serverPortField, c); socketPanel.add(serverPortField, c);
@ -161,10 +162,10 @@ public class SerialSocketServer extends VisPlugin implements MotePlugin {
c.anchor = GridBagConstraints.EAST; c.anchor = GridBagConstraints.EAST;
connectionInfoPanel.add(label); connectionInfoPanel.add(label);
inLabel = new JLabel("0 bytes"); socketToMoteLabel = new JLabel("0 bytes");
c.gridx++; c.gridx++;
c.anchor = GridBagConstraints.WEST; c.anchor = GridBagConstraints.WEST;
connectionInfoPanel.add(inLabel); connectionInfoPanel.add(socketToMoteLabel);
label = new JLabel("mote -> socket: "); label = new JLabel("mote -> socket: ");
label.setHorizontalAlignment(JLabel.RIGHT); label.setHorizontalAlignment(JLabel.RIGHT);
@ -173,10 +174,10 @@ public class SerialSocketServer extends VisPlugin implements MotePlugin {
c.anchor = GridBagConstraints.EAST; c.anchor = GridBagConstraints.EAST;
connectionInfoPanel.add(label); connectionInfoPanel.add(label);
outLabel = new JLabel("0 bytes"); moteToSocketLabel = new JLabel("0 bytes");
c.gridx++; c.gridx++;
c.anchor = GridBagConstraints.WEST; c.anchor = GridBagConstraints.WEST;
connectionInfoPanel.add(outLabel); connectionInfoPanel.add(moteToSocketLabel);
add(BorderLayout.CENTER, connectionInfoPanel); add(BorderLayout.CENTER, connectionInfoPanel);
@ -194,9 +195,9 @@ public class SerialSocketServer extends VisPlugin implements MotePlugin {
label = new JLabel("Status: "); label = new JLabel("Status: ");
statusBarPanel.add(label); statusBarPanel.add(label);
statusLabel = new JLabel("Not started"); socketStatusLabel = new JLabel("Not started");
statusLabel.setForeground(Color.DARK_GRAY); socketStatusLabel.setForeground(Color.DARK_GRAY);
statusBarPanel.add(statusLabel); statusBarPanel.add(socketStatusLabel);
add(BorderLayout.SOUTH, statusBarPanel); add(BorderLayout.SOUTH, statusBarPanel);
@ -218,24 +219,24 @@ public class SerialSocketServer extends VisPlugin implements MotePlugin {
} }
try { try {
logger.info("Listening on port: " + LISTEN_PORT); logger.info("Listening on port: " + SERVER_DEFAULT_PORT);
if (Cooja.isVisualized()) { if (Cooja.isVisualized()) {
statusLabel.setText("Listening on port: " + LISTEN_PORT); socketStatusLabel.setText("Listening on port: " + SERVER_DEFAULT_PORT);
} }
server = new ServerSocket(LISTEN_PORT); server = new ServerSocket(SERVER_DEFAULT_PORT);
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
while (server != null) { while (server != null) {
try { try {
client = server.accept(); clientSocket = server.accept();
in = new DataInputStream(client.getInputStream()); in = new DataInputStream(clientSocket.getInputStream());
out = new DataOutputStream(client.getOutputStream()); out = new DataOutputStream(clientSocket.getOutputStream());
out.flush(); out.flush();
startSocketReadThread(in); startSocketReadThread(in);
if (Cooja.isVisualized()) { if (Cooja.isVisualized()) {
statusLabel.setText("Client connected: " + client.getInetAddress()); socketStatusLabel.setText("Client connected: " + clientSocket.getInetAddress());
} }
} catch (IOException e) { } catch (IOException e) {
logger.fatal("Listening thread shut down: " + e.getMessage()); logger.fatal("Listening thread shut down: " + e.getMessage());
@ -316,9 +317,9 @@ public class SerialSocketServer extends VisPlugin implements MotePlugin {
private void cleanupClient() { private void cleanupClient() {
try { try {
if (client != null) { if (clientSocket != null) {
client.close(); clientSocket.close();
client = null; clientSocket = null;
} }
} catch (IOException e1) { } catch (IOException e1) {
} }
@ -341,7 +342,7 @@ public class SerialSocketServer extends VisPlugin implements MotePlugin {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
statusLabel.setText("Listening on port: " + LISTEN_PORT); socketStatusLabel.setText("Listening on port: " + SERVER_DEFAULT_PORT);
} }
}); });
} }
@ -373,8 +374,8 @@ public class SerialSocketServer extends VisPlugin implements MotePlugin {
return; return;
} }
inLabel.setText(inBytes + " bytes"); socketToMoteLabel.setText(inBytes + " bytes");
outLabel.setText(outBytes + " bytes"); moteToSocketLabel.setText(outBytes + " bytes");
} }
}); });
} }