[cooja] interfaces/IPAddress: Indention cleanup

This commit is contained in:
Enrico Joerns 2014-08-29 12:11:10 +02:00
parent e5653ac150
commit d5c5198171

View File

@ -26,7 +26,6 @@
* 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.
*/ */
package org.contikios.cooja.interfaces; package org.contikios.cooja.interfaces;
import java.util.Collection; import java.util.Collection;
@ -53,6 +52,7 @@ import org.contikios.cooja.mote.memory.VarMemory;
*/ */
@ClassDescription("IP Address") @ClassDescription("IP Address")
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 final VarMemory moteMem; private final VarMemory moteMem;
@ -95,7 +95,7 @@ public class IPAddress extends MoteInterface {
if (isVersion4()) { if (isVersion4()) {
String ipString = ""; String ipString = "";
byte[] ip = moteMem.getByteArray("uip_hostaddr", 4); byte[] ip = moteMem.getByteArray("uip_hostaddr", 4);
for (int i=0; i < 3; i++) { for (int i = 0; i < 3; i++) {
ipString += (0xFF & ip[i]) + "."; ipString += (0xFF & ip[i]) + ".";
} }
ipString += (0xFF & ip[3]); ipString += (0xFF & ip[3]);
@ -134,22 +134,23 @@ public class IPAddress extends MoteInterface {
} }
/* TODO No need to copy the entire array! */ /* TODO No need to copy the entire array! */
byte[] structData = moteMem.getByteArray("uip_ds6_if", byte[] structData = moteMem.getByteArray(
ipv6NetworkInterfaceAddressOffset+IPv6_MAX_ADDRESSES*ipv6AddressStructSize); "uip_ds6_if",
ipv6NetworkInterfaceAddressOffset + IPv6_MAX_ADDRESSES * ipv6AddressStructSize);
ipv6AddressIndex = -1; ipv6AddressIndex = -1;
for (int addressIndex=0; addressIndex < IPv6_MAX_ADDRESSES; addressIndex++) { for (int addressIndex = 0; addressIndex < IPv6_MAX_ADDRESSES; addressIndex++) {
int offset = ipv6NetworkInterfaceAddressOffset+addressIndex*ipv6AddressStructSize; int offset = ipv6NetworkInterfaceAddressOffset + addressIndex * ipv6AddressStructSize;
byte isUsed = structData[offset]; byte isUsed = structData[offset];
if (isUsed == 0) { if (isUsed == 0) {
continue; continue;
} }
byte[] addressData = new byte[16]; byte[] addressData = new byte[16];
System.arraycopy( System.arraycopy(
structData, offset+2/* ipaddr offset */, structData, offset + 2/* ipaddr offset */,
addressData, 0, 16); addressData, 0, 16);
if (addressData[0] == (byte)0xFE && addressData[1] == (byte)0x80) { if (addressData[0] == (byte) 0xFE && addressData[1] == (byte) 0x80) {
ipv6IsGlobal = false; ipv6IsGlobal = false;
} else { } else {
ipv6IsGlobal = true; ipv6IsGlobal = true;
@ -170,10 +171,10 @@ public class IPAddress extends MoteInterface {
public static String getUncompressedIPv6AddressString(byte[] ip) { public static String getUncompressedIPv6AddressString(byte[] ip) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i=0; i < 14; i+=2) { for (int i = 0; i < 14; i += 2) {
sb.append(String.format("%02x%02x:", 0xFF&ip[i+0], 0xFF&ip[i+1])); sb.append(String.format("%02x%02x:", 0xFF & ip[i + 0], 0xFF & ip[i + 1]));
} }
sb.append(String.format("%02x%02x", 0xFF&ip[14], 0xFF&ip[15])); sb.append(String.format("%02x%02x", 0xFF & ip[14], 0xFF & ip[15]));
return sb.toString(); return sb.toString();
} }
@ -196,10 +197,9 @@ public class IPAddress extends MoteInterface {
* @return True if mote has an IPv6 address * @return True if mote has an IPv6 address
*/ */
public boolean isVersion6() { public boolean isVersion6() {
return return moteMem.variableExists("uip_ds6_netif_addr_list_offset")
moteMem.variableExists("uip_ds6_netif_addr_list_offset") && && moteMem.variableExists("uip_ds6_addr_size")
moteMem.variableExists("uip_ds6_addr_size") && && moteMem.variableExists("uip_ds6_if");
moteMem.variableExists("uip_ds6_if");
} }
public void removed() { public void removed() {
@ -225,8 +225,8 @@ public class IPAddress extends MoteInterface {
if (isVersion4()) { if (isVersion4()) {
ipLabel.setText("IPv4 address: " + getIPString()); ipLabel.setText("IPv4 address: " + getIPString());
} else if (isVersion6()) { } else if (isVersion6()) {
ipLabel.setText((ipv6IsGlobal?"Global":"Local") + ipLabel.setText((ipv6IsGlobal ? "Global" : "Local")
" IPv6 address(#" + ipv6AddressIndex + "): " + getIPString()); + " IPv6 address(#" + ipv6AddressIndex + "): " + getIPString());
} else { } else {
ipLabel.setText("Unknown IP"); ipLabel.setText("Unknown IP");
} }