Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions library/src/main/java/com/digi/xbee/api/CellularDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ public void setIOSamplingRate(int rate) throws TimeoutException,
}

/**
* @deprecated Operation not supported in Cellular protocol. This method
* will raise an {@link UnsupportedOperationException}.
* @deprecated Cellular protocol does not have node identifier.
*/
@Override
public String getNodeID() {
Expand Down
49 changes: 47 additions & 2 deletions library/src/main/java/com/digi/xbee/api/IPDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
*/
package com.digi.xbee.api;

import java.net.Inet4Address;
import java.net.UnknownHostException;

import com.digi.xbee.api.connection.IConnectionInterface;
import com.digi.xbee.api.connection.serial.SerialPortParameters;
import com.digi.xbee.api.exceptions.InterfaceNotOpenException;
Expand Down Expand Up @@ -185,6 +188,46 @@ public IP32BitAddress getIPAddress() {
return ipAddress;
}

/**
* Sets the destination IP address.
*
* @param address Destination IP address.
*
* @throws NullPointerException if {@code address == null}.
* @throws TimeoutException if there is a timeout setting the destination
* address.
* @throws XBeeException if there is any other XBee related exception.
*
* @see #getDestinationIPAddress()
* @see Inet4Address
*/
public void setDestinationIPAddress(Inet4Address address) throws TimeoutException, XBeeException {
if (address == null)
throw new NullPointerException("Destination IP address cannot be null.");

setParameter("DL", address.getAddress());
}

/**
* Returns the destination IP address.
*
* @return The configured destination IP address.
*
* @throws TimeoutException if there is a timeout reading the destination
* address.
* @throws XBeeException if there is any other XBee related exception.
*
* @see #setDestinationIPAddress(Inet4Address)
* @see Inet4Address
*/
public Inet4Address getDestinationIPAddress() throws TimeoutException, XBeeException {
try {
return (Inet4Address) Inet4Address.getByAddress(getParameter("DL"));
} catch (UnknownHostException e) {
throw new XBeeException(e);
}
}

/**
* @deprecated This protocol does not have an associated 16-bit address.
*/
Expand All @@ -195,7 +238,8 @@ public XBee16BitAddress get16BitAddress() {
}

/**
* @deprecated This protocol does not have not have a destination address.
* @deprecated Operation not supported in this protocol. Use
* {@link #getDestinationIPAddress()} instead.
* This method will raise an
* {@link UnsupportedOperationException}.
*/
Expand All @@ -207,7 +251,8 @@ public XBee64BitAddress getDestinationAddress() throws TimeoutException,
}

/**
* @deprecated This protocol does not have not have a destination address.
* @deprecated Operation not supported in this protocol. Use
* {@link #setDestinationIPAddress(IP32BitAddress)} instead.
* This method will raise an
* {@link UnsupportedOperationException}.
*/
Expand Down
195 changes: 195 additions & 0 deletions library/src/main/java/com/digi/xbee/api/WiFiDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
package com.digi.xbee.api;

import java.io.ByteArrayInputStream;
import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -25,6 +27,7 @@
import com.digi.xbee.api.listeners.IPacketReceiveListener;
import com.digi.xbee.api.models.ATCommandStatus;
import com.digi.xbee.api.models.AccessPoint;
import com.digi.xbee.api.models.IPAddressingMode;
import com.digi.xbee.api.models.WiFiAssociationIndicationStatus;
import com.digi.xbee.api.models.WiFiEncryptionType;
import com.digi.xbee.api.models.XBeeProtocol;
Expand Down Expand Up @@ -622,4 +625,196 @@ public void setWiFiReceiveTimeout(int wifiReceiveTimeout) {

this.wifiReceiveTimeout = wifiReceiveTimeout;
}

/**
* Sets the IP addressing mode.
*
* @param mode IP addressing mode.
*
* @throws NullPointerException if {@code mode == null}.
* @throws TimeoutException if there is a timeout setting the IP addressing
* mode.
* @throws XBeeException if there is any other XBee related exception.
*
* @see #getIPAddressingMode()
* @see IPAddressingMode
*/
public void setIPAddressingMode(IPAddressingMode mode) throws TimeoutException, XBeeException {
if (mode == null)
throw new NullPointerException("IP addressing mode cannot be null.");

setParameter("MA", ByteUtils.intToByteArray(mode.getID()));
}

/**
* Returns the IP addressing mode.
*
* @return The configured IP addressing mode.
*
* @throws TimeoutException if there is a timeout reading the IP addressing
* mode.
* @throws XBeeException if there is any other XBee related exception.
*
* @see #setIPAddressingMode(IPAddressingMode)
* @see IPAddressingMode
*/
public IPAddressingMode getIPAddressingMode() throws TimeoutException, XBeeException {
return IPAddressingMode.get(ByteUtils.byteArrayToInt(getParameter("MA")));
}

/**
* Sets the IP address of the module.
*
* <p>This method <b>can only be called</b> if the module is configured in
* {@link IPAddressingMode#STATIC} mode. Otherwise an {@code XBeeException}
* will be thrown.</p>
*
* @param address IP address.
*
* @throws NullPointerException if {@code address == null}.
* @throws TimeoutException if there is a timeout setting the IP address.
* @throws XBeeException if the module is in {@link IPAddressingMode#DHCP}
* mode or there is any other XBee related exception.
*
* @see #getIPAddress()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen this method (getIPAddress()) in the commit. Is it missing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That method is inherited from the IPDevice class.

* @see #getIPAddressingMode()
* @see Inet4Address
*/
public void setIPAddress(Inet4Address address) throws TimeoutException, XBeeException {
if (address == null)
throw new NullPointerException("IP address cannot be null.");

setParameter("MY", address.getAddress());
}

/**
* Sets the IP address subnet mask.
*
* <p>This method <b>can only be called</b> if the module is configured in
* {@link IPAddressingMode#STATIC} mode. Otherwise an {@code XBeeException}
* will be thrown.</p>
*
* @param address IP address subnet mask.
*
* @throws NullPointerException if {@code address == null}.
* @throws TimeoutException if there is a timeout setting the IP address
* mask.
* @throws XBeeException if the module is in {@link IPAddressingMode#DHCP}
* mode or there is any other XBee related exception.
*
* @see #getIPAddressingMode()
* @see #getIPAddressMask()
* @see Inet4Address
*/
public void setIPAddressMask(Inet4Address address) throws TimeoutException, XBeeException {
if (address == null)
throw new NullPointerException("Address mask cannot be null.");

setParameter("MK", address.getAddress());
}

/**
* Returns the IP address subnet mask.
*
* @return The configured IP address subnet mask.
*
* @throws TimeoutException if there is a timeout reading the IP address
* mask.
* @throws XBeeException if there is any other XBee related exception.
*
* @see #setIPAddressMask(Inet4Address)
* @see Inet4Address
*/
public Inet4Address getIPAddressMask() throws TimeoutException, XBeeException {
try {
return (Inet4Address) Inet4Address.getByAddress(getParameter("MK"));
} catch (UnknownHostException e) {
throw new XBeeException(e);
}
}

/**
* Sets the IP address of the gateway.
*
* <p>This method <b>can only be called</b> if the module is configured in
* {@link IPAddressingMode#STATIC} mode. Otherwise an {@code XBeeException}
* will be thrown.</p>
*
* @param address IP address of the gateway.
*
* @throws NullPointerException if {@code address == null}.
* @throws TimeoutException if there is a timeout setting the gateway IP
* address.
* @throws XBeeException if the module is in {@link IPAddressingMode#DHCP}
* mode or there is any other XBee related exception.
*
* @see #getGatewayIPAddress()
* @see #getIPAddressingMode()
* @see Inet4Address
*/
public void setGatewayIPAddress(Inet4Address address) throws TimeoutException, XBeeException {
if (address == null)
throw new NullPointerException("Gateway address cannot be null.");

setParameter("GW", address.getAddress());
}

/**
* Returns the IP address of the gateway.
*
* @return The configured IP address of the gateway.
*
* @throws TimeoutException if there is a timeout reading the gateway IP
* address.
* @throws XBeeException if there is any other XBee related exception.
*
* @see #setGatewayIPAddress(Inet4Address)
* @see Inet4Address
*/
public Inet4Address getGatewayIPAddress() throws TimeoutException, XBeeException {
try {
return (Inet4Address) Inet4Address.getByAddress(getParameter("GW"));
} catch (UnknownHostException e) {
throw new XBeeException(e);
}
}

/**
* Sets the IP address of domain name server.
*
* @param address DNS address.
*
* @throws NullPointerException if {@code address == null}.
* @throws TimeoutException if there is a timeout setting the DNS address.
* @throws XBeeException if there is any other XBee related exception.
*
* @see #getDNSAddress()
* @see Inet4Address
*/
public void setDNSAddress(Inet4Address address) throws TimeoutException, XBeeException {
if (address == null)
throw new NullPointerException("DNS address cannot be null.");

setParameter("NS", address.getAddress());
}

/**
* Returns the IP address of domain name server.
*
* @return The configured DNS address.
*
* @throws TimeoutException if there is a timeout reading the DNS address.
* @throws XBeeException if there is any other XBee related exception.
*
* @see #setDNSAddress(Inet4Address)
* @see Inet4Address
*/
public Inet4Address getDNSAddress() throws TimeoutException, XBeeException {
try {
return (Inet4Address) Inet4Address.getByAddress(getParameter("NS"));
} catch (UnknownHostException e) {
throw new XBeeException(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright (c) 2016 Digi International Inc.,
* All rights not expressly granted are reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
* =======================================================================
*/
package com.digi.xbee.api.models;

import java.util.HashMap;

/**
* Enumerates the different IP addressing modes.
*/
public enum IPAddressingMode {

// Enumeration types.
DHCP(0, "DHCP"),
STATIC(1, "Static");

// Variables.
private int id;

private String name;

private static HashMap<Integer, IPAddressingMode> lookupTable = new HashMap<Integer, IPAddressingMode>();

static {
for (IPAddressingMode mode:values())
lookupTable.put(mode.getID(), mode);
}

/**
* Class constructor. Instantiates a new {@code IPAddressingMode} enumeration
* entry with the given parameters.
*
* @param id IP addressing mode ID.
* @param name IP addressing mode name.
*/
private IPAddressingMode(int id, String name) {
this.id = id;
this.name = name;
}

/**
* Retrieves the IP addressing mode ID.
*
* @return IP addressing mode ID.
*/
public int getID() {
return id;
}

/**
* Retrieves the IP addressing mode name.
*
* @return IP addressing mode name.
*/
public String getName() {
return name;
}

/**
* Retrieves the IP addressing mode for the given ID.
*
* @param id ID to retrieve the IP addressing mode.
*
* @return The IP addressing mode associated with the given ID.
*/
public static IPAddressingMode get(int id) {
return lookupTable.get(id);
}

/*
* (non-Javadoc)
* @see java.lang.Enum#toString()
*/
@Override
public String toString() {
return name;
}
}
Loading