catching unknown variable exceptions + using integer size

This commit is contained in:
fros4943 2008-02-11 14:03:19 +00:00
parent 47165456ca
commit afebaa9e97

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: VariableWatcher.java,v 1.5 2007/03/22 11:13:19 fros4943 Exp $
* $Id: VariableWatcher.java,v 1.6 2008/02/11 14:03:19 fros4943 Exp $
*/
package se.sics.cooja.plugins;
@ -39,12 +39,12 @@ import java.util.Collection;
import java.util.Vector;
import javax.swing.*;
import org.jdom.Element;
import se.sics.cooja.*;
import se.sics.cooja.AddressMemory.UnknownVariableException;
/**
* Variable Watcher enables a user to watch mote variables during a simulation.
* Variables can be read or written either as bytes, integers (4 bytes) or byte arrays.
* Variables can be read or written either as bytes, integers or byte arrays.
*
* User can also see which variables seems to be available on the selected node.
*
@ -102,8 +102,9 @@ public class VariableWatcher extends VisPlugin {
varName.setSelectedItem("[enter or pick name]");
String[] allPotentialVarNames = moteMemory.getVariableNames();
for (String aVarName: allPotentialVarNames)
for (String aVarName: allPotentialVarNames) {
varName.addItem(aVarName);
}
varName.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
@ -128,7 +129,7 @@ public class VariableWatcher extends VisPlugin {
varType = new JComboBox();
varType.addItem("Byte (1 byte)"); // BYTE_INDEX = 0
varType.addItem("Integer (4 bytes)"); // INT_INDEX = 1
varType.addItem("Integer (" + moteMemory.getIntegerLength() + " bytes)"); // INT_INDEX = 1
varType.addItem("Byte array (x bytes)"); // ARRAY_INDEX = 2
varType.addActionListener(new ActionListener() {
@ -203,7 +204,7 @@ public class VariableWatcher extends VisPlugin {
varValues[0].setValue(new Integer(val));
varName.setBackground(Color.WHITE);
writeButton.setEnabled(true);
} catch (Exception ex) {
} catch (UnknownVariableException ex) {
varName.setBackground(Color.RED);
writeButton.setEnabled(false);
}
@ -213,7 +214,7 @@ public class VariableWatcher extends VisPlugin {
varValues[0].setValue(new Integer(val));
varName.setBackground(Color.WHITE);
writeButton.setEnabled(true);
} catch (Exception ex) {
} catch (UnknownVariableException ex) {
varName.setBackground(Color.RED);
writeButton.setEnabled(false);
}
@ -221,11 +222,12 @@ public class VariableWatcher extends VisPlugin {
try {
int length = ((Number) varLength.getValue()).intValue();
byte[] vals = moteMemory.getByteArray((String) varName.getSelectedItem(), length);
for (int i=0; i < length; i++)
for (int i=0; i < length; i++) {
varValues[i].setValue(new Integer(vals[i]));
}
varName.setBackground(Color.WHITE);
writeButton.setEnabled(true);
} catch (Exception ex) {
} catch (UnknownVariableException ex) {
varName.setBackground(Color.RED);
writeButton.setEnabled(false);
}
@ -242,7 +244,7 @@ public class VariableWatcher extends VisPlugin {
byte val = (byte) ((Number) varValues[0].getValue()).intValue();
moteMemory.setByteValueOf((String) varName.getSelectedItem(), val);
varName.setBackground(Color.WHITE);
} catch (Exception ex) {
} catch (UnknownVariableException ex) {
varName.setBackground(Color.RED);
}
} else if (varType.getSelectedIndex() == INT_INDEX) {
@ -250,7 +252,7 @@ public class VariableWatcher extends VisPlugin {
int val = ((Number) varValues[0].getValue()).intValue();
moteMemory.setIntValueOf((String) varName.getSelectedItem(), val);
varName.setBackground(Color.WHITE);
} catch (Exception ex) {
} catch (UnknownVariableException ex) {
varName.setBackground(Color.RED);
}
} else if (varType.getSelectedIndex() == ARRAY_INDEX) {
@ -264,7 +266,7 @@ public class VariableWatcher extends VisPlugin {
moteMemory.setByteArray((String) varName.getSelectedItem(), vals);
varName.setBackground(Color.WHITE);
writeButton.setEnabled(true);
} catch (Exception ex) {
} catch (UnknownVariableException ex) {
varName.setBackground(Color.RED);
writeButton.setEnabled(false);
}