avoid exception if rime address does not exist + removed obsolete methods

This commit is contained in:
fros4943 2010-02-03 10:14:46 +00:00
parent 1965dcf754
commit fd2a377666
2 changed files with 29 additions and 64 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: IPAddress.java,v 1.7 2009/10/28 15:58:43 fros4943 Exp $ * $Id: IPAddress.java,v 1.8 2010/02/03 10:14:46 fros4943 Exp $
*/ */
package se.sics.cooja.interfaces; package se.sics.cooja.interfaces;
@ -34,7 +34,6 @@ package se.sics.cooja.interfaces;
import java.util.Collection; import java.util.Collection;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import java.util.Vector;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -42,10 +41,16 @@ import javax.swing.JPanel;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.*; import se.sics.cooja.AddressMemory;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
import se.sics.cooja.MoteInterface;
import se.sics.cooja.MoteTimeEvent;
import se.sics.cooja.Simulation;
import se.sics.cooja.TimeEvent;
/** /**
* IPv4 or IPv6 address. * Read-only interface to IPv4 or IPv6 address.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ -53,7 +58,6 @@ import se.sics.cooja.*;
public class IPAddress extends MoteInterface { public class IPAddress extends MoteInterface {
private static Logger logger = Logger.getLogger(IPAddress.class); private static Logger logger = Logger.getLogger(IPAddress.class);
private AddressMemory moteMem; private AddressMemory moteMem;
private static boolean warnedNotImplemented = false;
public IPAddress(final Mote mote) { public IPAddress(final Mote mote) {
moteMem = (AddressMemory) mote.getMemory(); moteMem = (AddressMemory) mote.getMemory();
@ -88,7 +92,6 @@ public class IPAddress extends MoteInterface {
* Returns IP address string. * Returns IP address string.
* Supports both IPv4 and IPv6 addresses. * Supports both IPv4 and IPv6 addresses.
* *
* @see #setIPString(String)
* @return IP address string * @return IP address string
*/ */
public String getIPString() { public String getIPString() {
@ -140,53 +143,6 @@ public class IPAddress extends MoteInterface {
return moteMem.variableExists("uip_netif_physical_if"); return moteMem.variableExists("uip_netif_physical_if");
} }
/**
* Set IPv4 address: a.b.c.d.
*
* @param a First byte
* @param b Second byte
* @param c Third byte
* @param d Fourth byte
*/
public void setIPv4Address(int a, int b, int c, int d) {
/* TODO Implement */
if (!warnedNotImplemented) {
warnedNotImplemented = true;
logger.warn("Changing IP addresses is no longer supported.");
logger.warn("The IP address is instead determined by Contiki, for example based on the MAC/Rime address, or the node ID.");
}
}
/**
* Set IPv6 address.
*
* @param address 16 element IP address array
*/
public void setIPv6Address(int[] address) {
/* TODO Implement */
if (!warnedNotImplemented) {
warnedNotImplemented = true;
logger.warn("Changing IP addresses is no longer supported.");
logger.warn("The IP address is instead determined by Contiki, for example based on the MAC/Rime address, or the node ID.");
}
}
/**
* Set IP address.
* Supports both IPv4 and IPv6 addresses.
*
* @see #getIPString()
* @param ipString IP address string
*/
public void setIPString(String ipString) {
/* TODO Implement */
if (!warnedNotImplemented) {
warnedNotImplemented = true;
logger.warn("Changing IP addresses is no longer supported.");
logger.warn("The IP address is instead determined by Contiki, for example based on the MAC/Rime address, or the node ID.");
}
}
public JPanel getInterfaceVisualizer() { public JPanel getInterfaceVisualizer() {
JPanel panel = new JPanel(); JPanel panel = new JPanel();
final JLabel ipLabel = new JLabel(); final JLabel ipLabel = new JLabel();
@ -245,8 +201,4 @@ public class IPAddress extends MoteInterface {
} }
return s; return s;
} }
public double energyConsumption() {
return 0;
}
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: RimeAddress.java,v 1.4 2009/10/28 15:58:43 fros4943 Exp $ * $Id: RimeAddress.java,v 1.5 2010/02/03 10:14:46 fros4943 Exp $
*/ */
package se.sics.cooja.interfaces; package se.sics.cooja.interfaces;
@ -41,7 +41,13 @@ import javax.swing.JPanel;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.*; import se.sics.cooja.AddressMemory;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
import se.sics.cooja.MoteInterface;
import se.sics.cooja.MoteTimeEvent;
import se.sics.cooja.Simulation;
import se.sics.cooja.TimeEvent;
/** /**
* Read-only interface to Rime address read from Contiki variable: rimeaddr_node_addr. * Read-only interface to Rime address read from Contiki variable: rimeaddr_node_addr.
@ -63,6 +69,10 @@ public class RimeAddress extends MoteInterface {
/* Detect startup address (only zeroes) */ /* Detect startup address (only zeroes) */
TimeEvent updateWhenAddressReady = new MoteTimeEvent(mote, 0) { TimeEvent updateWhenAddressReady = new MoteTimeEvent(mote, 0) {
public void execute(long t) { public void execute(long t) {
if (!hasRimeAddress()) {
return;
}
String addrString = getAddressString(); String addrString = getAddressString();
addrString = addrString.replace(".", ""); addrString = addrString.replace(".", "");
addrString = addrString.replace("0", ""); addrString = addrString.replace("0", "");
@ -82,7 +92,15 @@ public class RimeAddress extends MoteInterface {
updateWhenAddressReady.execute(0); updateWhenAddressReady.execute(0);
} }
public boolean hasRimeAddress() {
return moteMem.variableExists("rimeaddr_node_addr");
}
public String getAddressString() { public String getAddressString() {
if (!hasRimeAddress()) {
return null;
}
String addrString = ""; String addrString = "";
byte[] addr = moteMem.getByteArray("rimeaddr_node_addr", RIME_ADDR_LENGTH); byte[] addr = moteMem.getByteArray("rimeaddr_node_addr", RIME_ADDR_LENGTH);
for (int i=0; i < RIME_ADDR_LENGTH-1; i++) { for (int i=0; i < RIME_ADDR_LENGTH-1; i++) {
@ -122,15 +140,10 @@ public class RimeAddress extends MoteInterface {
this.deleteObserver(observer); this.deleteObserver(observer);
} }
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
return null; return null;
} }
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) { public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
} }
public double energyConsumption() {
return 0;
}
} }