Added tab to set new collect parameters

This commit is contained in:
nifi 2010-09-28 23:12:16 +00:00
parent 55d61d317b
commit dde50b028a
2 changed files with 182 additions and 4 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: CollectServer.java,v 1.20 2010/09/26 21:48:21 nifi Exp $
* $Id: CollectServer.java,v 1.21 2010/09/28 23:12:16 nifi Exp $
*
* -----------------------------------------------------------------
*
@ -34,8 +34,8 @@
*
* Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008
* Updated : $Date: 2010/09/26 21:48:21 $
* $Revision: 1.20 $
* Updated : $Date: 2010/09/28 23:12:16 $
* $Revision: 1.21 $
*/
package se.sics.contiki.collect;
@ -59,9 +59,9 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
@ -85,6 +85,7 @@ import org.jfree.chart.axis.ValueAxis;
import se.sics.contiki.collect.gui.AggregatedTimeChartPanel;
import se.sics.contiki.collect.gui.BarChartPanel;
import se.sics.contiki.collect.gui.MapPanel;
import se.sics.contiki.collect.gui.NodeControl;
import se.sics.contiki.collect.gui.NodeInfoPanel;
import se.sics.contiki.collect.gui.SerialConsole;
import se.sics.contiki.collect.gui.TimeChartPanel;
@ -525,6 +526,7 @@ public class CollectServer {
}
},
new NodeInfoPanel(this, MAIN),
new NodeControl(this, MAIN),
serialConsole
};
for (int i = 0, n = visualizers.length; i < n; i++) {

View file

@ -0,0 +1,176 @@
/*
* Copyright (c) 2010, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: NodeControl.java,v 1.1 2010/09/28 23:12:18 nifi Exp $
*
* -----------------------------------------------------------------
*
* NodeControl
*
* Authors : Niclas Finne
* Created : 27 sep 2010
* Updated : $Date: 2010/09/28 23:12:18 $
* $Revision: 1.1 $
*/
package se.sics.contiki.collect.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import se.sics.contiki.collect.CollectServer;
import se.sics.contiki.collect.Node;
import se.sics.contiki.collect.SensorData;
import se.sics.contiki.collect.Visualizer;
/**
*
*/
public class NodeControl implements Visualizer {
private final String category;
private final JPanel panel;
public NodeControl(final CollectServer server, String category) {
this.category = category;
this.panel = new JPanel(new BorderLayout());
final JFormattedTextField intervalField = new JFormattedTextField(new Integer(60));
final JFormattedTextField randomField = new JFormattedTextField(new Integer(2));
final JFormattedTextField reportsField = new JFormattedTextField(new Integer(0));
final JLabel statusLabel = new JLabel("", JLabel.CENTER);
statusLabel.setOpaque(true);
JButton sendButton = new JButton("Send command to nodes");
sendButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int interval = (Integer)intervalField.getValue();
int random = (Integer)randomField.getValue();
int reports = (Integer)reportsField.getValue();
String cmd = "netcmd { repeat " + reports
+ " " + interval + " { randwait " + random
+ " sky-alldata | blink | send } }";
statusLabel.setBackground(Color.white);
statusLabel.setBorder(LineBorder.createBlackLineBorder());
if (server.sendToNode(cmd)) {
statusLabel.setForeground(Color.black);
statusLabel.setText("Sent command '" + cmd + "'");
} else {
statusLabel.setForeground(Color.red);
statusLabel.setText("Failed to send command. No serial connection.");
}
}
});
JPanel controlPanel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.insets.left = c.insets.right = c.insets.bottom = 3;
c.insets.top = 10;
c.gridy = 0;
c.gridwidth = 3;
JLabel label = new JLabel("Collect Settings", JLabel.CENTER);
controlPanel.add(label, c);
c.gridwidth = 1;
c.gridy++;
controlPanel.add(label = new JLabel("Report interval", JLabel.RIGHT), c);
label.setLabelFor(intervalField);
controlPanel.add(intervalField, c);
controlPanel.add(new JLabel("seconds"), c);
c.insets.top = 3;
c.gridy++;
controlPanel.add(label = new JLabel("Report randomness", JLabel.RIGHT), c);
label.setLabelFor(randomField);
controlPanel.add(randomField, c);
controlPanel.add(new JLabel("seconds"), c);
c.gridy++;
controlPanel.add(new JLabel("Number of reports", JLabel.RIGHT), c);
label.setLabelFor(reportsField);
controlPanel.add(reportsField, c);
controlPanel.add(new JLabel("(0 = report forever)"), c);
c.gridy++;
c.gridx = 1;
c.weightx = 0;
c.fill = GridBagConstraints.NONE;
c.insets.bottom = 50;
controlPanel.add(sendButton, c);
c.gridx = 0;
c.gridy++;
c.gridwidth = 3;
c.ipadx = c.ipady = 6;
controlPanel.add(statusLabel, c);
panel.add(controlPanel, BorderLayout.NORTH);
}
public String getCategory() {
return category;
}
public String getTitle() {
return "Node Control";
}
public Component getPanel() {
return panel;
}
public void nodesSelected(Node[] node) {
}
public void nodeAdded(Node node) {
}
public void nodeDataReceived(SensorData sensorData) {
}
public void clearNodeData() {
}
}