diff --git a/.gitignore b/.gitignore index 678af657..2863048f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ bin /target /.settings /examples/*/*/.gitignore +*.orig diff --git a/examples/communication/ReceiveDataPollingSample/src/com/digi/xbee/api/receivedatapolling/MainApp.java b/examples/communication/ReceiveDataPollingSample/src/com/digi/xbee/api/receivedatapolling/MainApp.java index 7b891bcc..82578f00 100644 --- a/examples/communication/ReceiveDataPollingSample/src/com/digi/xbee/api/receivedatapolling/MainApp.java +++ b/examples/communication/ReceiveDataPollingSample/src/com/digi/xbee/api/receivedatapolling/MainApp.java @@ -15,6 +15,7 @@ import com.digi.xbee.api.exceptions.XBeeException; import com.digi.xbee.api.models.XBeeMessage; import com.digi.xbee.api.utils.HexUtils; +import com.digi.xbee.api.utils.StringUtils; /** * XBee Java Library Receive Data polling sample application. @@ -54,10 +55,11 @@ public static void main(String[] args) { while (true) { XBeeMessage xbeeMessage = myDevice.readData(); - if (xbeeMessage != null) + if (xbeeMessage != null) { System.out.format("From %s >> %s | %s%n", xbeeMessage.getDevice().get64BitAddress(), - HexUtils.prettyHexString(HexUtils.byteArrayToHexString(xbeeMessage.getData())), - new String(xbeeMessage.getData())); + HexUtils.prettyHexString(HexUtils.byteArrayToHexString(xbeeMessage.getData())), + StringUtils.byteArrayToString(xbeeMessage.getData())); + } } } } diff --git a/examples/communication/ReceiveDataSample/src/com/digi/xbee/api/receivedata/MyDataReceiveListener.java b/examples/communication/ReceiveDataSample/src/com/digi/xbee/api/receivedata/MyDataReceiveListener.java index ce2b4439..96468422 100644 --- a/examples/communication/ReceiveDataSample/src/com/digi/xbee/api/receivedata/MyDataReceiveListener.java +++ b/examples/communication/ReceiveDataSample/src/com/digi/xbee/api/receivedata/MyDataReceiveListener.java @@ -14,6 +14,7 @@ import com.digi.xbee.api.listeners.IDataReceiveListener; import com.digi.xbee.api.models.XBeeMessage; import com.digi.xbee.api.utils.HexUtils; +import com.digi.xbee.api.utils.StringUtils; /** * Class to manage the XBee received data that was sent by other modules in the @@ -34,7 +35,7 @@ public class MyDataReceiveListener implements IDataReceiveListener { @Override public void dataReceived(XBeeMessage xbeeMessage) { System.out.format("From %s >> %s | %s%n", xbeeMessage.getDevice().get64BitAddress(), - HexUtils.prettyHexString(HexUtils.byteArrayToHexString(xbeeMessage.getData())), - new String(xbeeMessage.getData())); + HexUtils.prettyHexString(HexUtils.byteArrayToHexString(xbeeMessage.getData())), + StringUtils.byteArrayToString(xbeeMessage.getData())); } } diff --git a/examples/communication/SendBroadcastDataSample/src/com/digi/xbee/api/sendbroadcastdata/MainApp.java b/examples/communication/SendBroadcastDataSample/src/com/digi/xbee/api/sendbroadcastdata/MainApp.java index 83647e1d..0796c293 100644 --- a/examples/communication/SendBroadcastDataSample/src/com/digi/xbee/api/sendbroadcastdata/MainApp.java +++ b/examples/communication/SendBroadcastDataSample/src/com/digi/xbee/api/sendbroadcastdata/MainApp.java @@ -13,6 +13,7 @@ import com.digi.xbee.api.XBeeDevice; import com.digi.xbee.api.exceptions.XBeeException; +import com.digi.xbee.api.utils.StringUtils; /** * XBee Java Library Send Broadcast Data sample application. @@ -44,12 +45,12 @@ public static void main(String[] args) { System.out.println(" +------------------------------------------------+\n"); XBeeDevice myDevice = new XBeeDevice(PORT, BAUD_RATE); - byte[] dataToSend = DATA_TO_SEND.getBytes(); + byte[] dataToSend = StringUtils.stringToByteArray(DATA_TO_SEND); try { myDevice.open(); - System.out.format("Sending broadcast data: '%s'...%n", new String(dataToSend)); + System.out.format("Sending broadcast data: '%s'...%n", StringUtils.byteArrayToString(dataToSend)); myDevice.sendBroadcastData(dataToSend); diff --git a/examples/communication/SendDataAsyncSample/src/com/digi/xbee/api/senddataasync/MainApp.java b/examples/communication/SendDataAsyncSample/src/com/digi/xbee/api/senddataasync/MainApp.java index b2abbad6..c1edaa98 100644 --- a/examples/communication/SendDataAsyncSample/src/com/digi/xbee/api/senddataasync/MainApp.java +++ b/examples/communication/SendDataAsyncSample/src/com/digi/xbee/api/senddataasync/MainApp.java @@ -16,6 +16,7 @@ import com.digi.xbee.api.XBeeNetwork; import com.digi.xbee.api.exceptions.XBeeException; import com.digi.xbee.api.utils.HexUtils; +import com.digi.xbee.api.utils.StringUtils; /** * XBee Java Library Send Data Asynchronously sample application. @@ -49,7 +50,7 @@ public static void main(String[] args) { System.out.println(" +---------------------------------------------------+\n"); XBeeDevice myDevice = new XBeeDevice(PORT, BAUD_RATE); - byte[] dataToSend = DATA_TO_SEND.getBytes(); + byte[] dataToSend = StringUtils.stringToByteArray(DATA_TO_SEND); try { myDevice.open(); @@ -64,7 +65,7 @@ public static void main(String[] args) { System.out.format("Sending data to %s >> %s | %s... ", remoteDevice.get64BitAddress(), HexUtils.prettyHexString(HexUtils.byteArrayToHexString(dataToSend)), - new String(dataToSend)); + StringUtils.byteArrayToString(dataToSend)); myDevice.sendDataAsync(remoteDevice, dataToSend); diff --git a/examples/communication/SendDataSample/src/com/digi/xbee/api/senddata/MainApp.java b/examples/communication/SendDataSample/src/com/digi/xbee/api/senddata/MainApp.java index 6ed85eb6..dcf1ffe1 100644 --- a/examples/communication/SendDataSample/src/com/digi/xbee/api/senddata/MainApp.java +++ b/examples/communication/SendDataSample/src/com/digi/xbee/api/senddata/MainApp.java @@ -16,6 +16,7 @@ import com.digi.xbee.api.XBeeNetwork; import com.digi.xbee.api.exceptions.XBeeException; import com.digi.xbee.api.utils.HexUtils; +import com.digi.xbee.api.utils.StringUtils; /** * XBee Java Library Send Data sample application. @@ -49,7 +50,7 @@ public static void main(String[] args) { System.out.println(" +--------------------------------------+\n"); XBeeDevice myDevice = new XBeeDevice(PORT, BAUD_RATE); - byte[] dataToSend = DATA_TO_SEND.getBytes(); + byte[] dataToSend = StringUtils.stringToByteArray(DATA_TO_SEND); try { myDevice.open(); @@ -64,7 +65,7 @@ public static void main(String[] args) { System.out.format("Sending data to %s >> %s | %s... ", remoteDevice.get64BitAddress(), HexUtils.prettyHexString(HexUtils.byteArrayToHexString(dataToSend)), - new String(dataToSend)); + StringUtils.byteArrayToString(dataToSend)); myDevice.sendData(remoteDevice, dataToSend); diff --git a/examples/configuration/SetAndGetParametersSample/src/com/digi/xbee/api/setgetparameters/MainApp.java b/examples/configuration/SetAndGetParametersSample/src/com/digi/xbee/api/setgetparameters/MainApp.java index f267291d..ec425d82 100644 --- a/examples/configuration/SetAndGetParametersSample/src/com/digi/xbee/api/setgetparameters/MainApp.java +++ b/examples/configuration/SetAndGetParametersSample/src/com/digi/xbee/api/setgetparameters/MainApp.java @@ -14,6 +14,7 @@ import com.digi.xbee.api.XBeeDevice; import com.digi.xbee.api.exceptions.XBeeException; import com.digi.xbee.api.utils.ByteUtils; +import com.digi.xbee.api.utils.StringUtils; /** * XBee Java Library Set and Get parameters sample application. @@ -62,7 +63,7 @@ public static void main(String[] args) { myDevice.open(); // Set parameters. - myDevice.setParameter(PARAM_NODE_ID, PARAM_VALUE_NODE_ID.getBytes()); + myDevice.setParameter(PARAM_NODE_ID, StringUtils.stringToByteArray(PARAM_VALUE_NODE_ID)); myDevice.setParameter(PARAM_PAN_ID, PARAM_VALUE_PAN_ID); myDevice.setParameter(PARAM_DEST_ADDRESS_H, ByteUtils.intToByteArray(PARAM_VALUE_DEST_ADDRESS_H)); myDevice.setParameter(PARAM_DEST_ADDRESS_L, ByteUtils.intToByteArray(PARAM_VALUE_DEST_ADDRESS_L)); @@ -74,7 +75,7 @@ public static void main(String[] args) { byte[] paramValueDL = myDevice.getParameter(PARAM_DEST_ADDRESS_L); // Compare the read parameter values with the values that were set. - if (!new String(paramValueNI).equals(PARAM_VALUE_NODE_ID)) { + if (!StringUtils.byteArrayToString(paramValueNI).equals(PARAM_VALUE_NODE_ID)) { System.out.println("NI parameter was not set correctly."); myDevice.close(); System.exit(1); diff --git a/library/src/main/java/com/digi/xbee/api/AbstractXBeeDevice.java b/library/src/main/java/com/digi/xbee/api/AbstractXBeeDevice.java index 49eaf531..5aa15ab0 100644 --- a/library/src/main/java/com/digi/xbee/api/AbstractXBeeDevice.java +++ b/library/src/main/java/com/digi/xbee/api/AbstractXBeeDevice.java @@ -66,6 +66,7 @@ import com.digi.xbee.api.packet.raw.TXStatusPacket; import com.digi.xbee.api.utils.ByteUtils; import com.digi.xbee.api.utils.HexUtils; +import com.digi.xbee.api.utils.StringUtils; /** * This class provides common functionality for all XBee devices. @@ -377,7 +378,7 @@ public void readDeviceInfo() throws TimeoutException, XBeeException { } // Get the Node ID. response = getParameter("NI"); - nodeID = new String(response); + nodeID = StringUtils.byteArrayToString(response); // Get the hardware version. if (hardwareVersion == null) { @@ -502,7 +503,7 @@ public void setNodeID(String nodeID) throws TimeoutException, XBeeException { if (nodeID.length() > 20) throw new IllegalArgumentException("Node ID length must be less than 21."); - setParameter("NI", nodeID.getBytes()); + setParameter("NI", StringUtils.stringToByteArray(nodeID)); this.nodeID = nodeID; } @@ -1114,27 +1115,32 @@ private IPacketReceiveListener createPacketReceivedListener(final XBeePacket sen @Override public void packetReceived(XBeePacket receivedPacket) { // Check if it is the packet we are waiting for. + if (!(receivedPacket instanceof XBeeAPIPacket)) + return; + if (!(sentPacket instanceof XBeeAPIPacket)) + return; if (((XBeeAPIPacket)receivedPacket).checkFrameID((((XBeeAPIPacket)sentPacket).getFrameID()))) { // Security check to avoid class cast exceptions. It has been observed that parallel processes // using the same connection but with different frame index may collide and cause this exception at some point. - if (sentPacket instanceof XBeeAPIPacket - && receivedPacket instanceof XBeeAPIPacket) { - XBeeAPIPacket sentAPIPacket = (XBeeAPIPacket)sentPacket; - XBeeAPIPacket receivedAPIPacket = (XBeeAPIPacket)receivedPacket; - - // If the packet sent is an AT command, verify that the received one is an AT command response and - // the command matches in both packets. - if (sentAPIPacket.getFrameType() == APIFrameType.AT_COMMAND) { - if (receivedAPIPacket.getFrameType() != APIFrameType.AT_COMMAND_RESPONSE) - return; + XBeeAPIPacket sentAPIPacket = (XBeeAPIPacket)sentPacket; + XBeeAPIPacket receivedAPIPacket = (XBeeAPIPacket)receivedPacket; + + // If the packet sent is an AT command, verify that the received one is an AT command response and + // the command matches in both packets. + if (sentAPIPacket.getFrameType() == APIFrameType.AT_COMMAND) { + if (receivedAPIPacket.getFrameType() != APIFrameType.AT_COMMAND_RESPONSE) + return; + if (sentAPIPacket instanceof ATCommandPacket && receivedPacket instanceof ATCommandResponsePacket) { if (!((ATCommandPacket)sentAPIPacket).getCommand().equalsIgnoreCase(((ATCommandResponsePacket)receivedPacket).getCommand())) return; } - // If the packet sent is a remote AT command, verify that the received one is a remote AT command response and - // the command matches in both packets. - if (sentAPIPacket.getFrameType() == APIFrameType.REMOTE_AT_COMMAND_REQUEST) { - if (receivedAPIPacket.getFrameType() != APIFrameType.REMOTE_AT_COMMAND_RESPONSE) - return; + } + // If the packet sent is a remote AT command, verify that the received one is a remote AT command response and + // the command matches in both packets. + if (sentAPIPacket.getFrameType() == APIFrameType.REMOTE_AT_COMMAND_REQUEST) { + if (receivedAPIPacket.getFrameType() != APIFrameType.REMOTE_AT_COMMAND_RESPONSE) + return; + if (sentAPIPacket instanceof RemoteATCommandPacket && receivedPacket instanceof RemoteATCommandResponsePacket) { if (!((RemoteATCommandPacket)sentAPIPacket).getCommand().equalsIgnoreCase(((RemoteATCommandResponsePacket)receivedPacket).getCommand())) return; } @@ -1145,7 +1151,7 @@ public void packetReceived(XBeePacket receivedPacket) { if (!sentPacket.equals(receivedPacket)) { responseList.add(receivedPacket); synchronized (responseList) { - responseList.notify(); + responseList.notifyAll(); } } } @@ -1826,7 +1832,7 @@ public IOSample readIOSample() throws TimeoutException, XBeeException { throw new InterfaceNotOpenException(); // Try to build an IO Sample from the sample payload. - byte[] samplePayload = null; + byte[] samplePayload; IOSample ioSample; // The response to the IS command in local 802.15.4 devices is empty, @@ -1893,13 +1899,16 @@ public void packetReceived(XBeePacket receivedPacket) { // Save the packet value (IO sample payload) switch (((XBeeAPIPacket)receivedPacket).getFrameType()) { case IO_DATA_SAMPLE_RX_INDICATOR: - ioPacketPayload = ((IODataSampleRxIndicatorPacket)receivedPacket).getRFData(); + if (receivedPacket instanceof IODataSampleRxIndicatorPacket) + ioPacketPayload = ((IODataSampleRxIndicatorPacket)receivedPacket).getRFData(); break; case RX_IO_16: - ioPacketPayload = ((RX16IOPacket)receivedPacket).getRFData(); + if (receivedPacket instanceof RX16IOPacket) + ioPacketPayload = ((RX16IOPacket)receivedPacket).getRFData(); break; case RX_IO_64: - ioPacketPayload = ((RX64IOPacket)receivedPacket).getRFData(); + if (receivedPacket instanceof RX64IOPacket) + ioPacketPayload = ((RX64IOPacket)receivedPacket).getRFData(); break; default: return; @@ -1909,7 +1918,7 @@ public void packetReceived(XBeePacket receivedPacket) { // Continue execution by notifying the lock object. synchronized (ioLock) { - ioLock.notify(); + ioLock.notifyAll(); } } }; diff --git a/library/src/main/java/com/digi/xbee/api/NodeDiscovery.java b/library/src/main/java/com/digi/xbee/api/NodeDiscovery.java index a8cf8389..f081100d 100644 --- a/library/src/main/java/com/digi/xbee/api/NodeDiscovery.java +++ b/library/src/main/java/com/digi/xbee/api/NodeDiscovery.java @@ -287,7 +287,8 @@ public void packetReceived(XBeePacket receivedPacket) { if (!discovering) return; RemoteXBeeDevice rdevice = null; - + if (!(receivedPacket instanceof XBeeAPIPacket)) + return; byte[] commandValue = getRemoteDeviceData((XBeeAPIPacket)receivedPacket); rdevice = parseDiscoveryAPIData(commandValue, xbeeDevice); @@ -458,8 +459,6 @@ private RemoteXBeeDevice parseDiscoveryAPIData(byte[] data, XBeeDevice localDevi // TODO role of the device: coordinator, router, end device or unknown. //XBeeDeviceType role = XBeeDeviceType.UNKNOWN; int signalStrength = 0; - byte[] profileID = null; - byte[] manufacturerID = null; ByteArrayInputStream inputStream = new ByteArrayInputStream(data); // Read 16 bit address. @@ -485,9 +484,9 @@ private RemoteXBeeDevice parseDiscoveryAPIData(byte[] data, XBeeDevice localDevi // Consume status byte, it is not used yet. ByteUtils.readBytes(1, inputStream); // Read profile ID. - profileID = ByteUtils.readBytes(2, inputStream); + byte[] profileID = ByteUtils.readBytes(2, inputStream); // Read manufacturer ID. - manufacturerID = ByteUtils.readBytes(2, inputStream); + byte[] manufacturerID = ByteUtils.readBytes(2, inputStream); logger.debug("{}Discovered {} device: 16-bit[{}], 64-bit[{}], id[{}], parent[{}], profile[{}], manufacturer[{}].", xbeeDevice.toString(), localDevice.getXBeeProtocol().getDescription(), addr16, diff --git a/library/src/main/java/com/digi/xbee/api/XBeeDevice.java b/library/src/main/java/com/digi/xbee/api/XBeeDevice.java index 9683ef86..1379dded 100644 --- a/library/src/main/java/com/digi/xbee/api/XBeeDevice.java +++ b/library/src/main/java/com/digi/xbee/api/XBeeDevice.java @@ -50,6 +50,7 @@ import com.digi.xbee.api.packet.raw.RX64Packet; import com.digi.xbee.api.packet.raw.TX64Packet; import com.digi.xbee.api.utils.HexUtils; +import com.digi.xbee.api.utils.StringUtils; /** * This class represents a local XBee device. @@ -413,9 +414,9 @@ private boolean enterATCommandMode() throws InvalidOperatingModeException, Timeo byte[] readData = new byte[256]; try { // Send the command mode sequence. - connectionInterface.writeData(COMMAND_MODE_CHAR.getBytes()); - connectionInterface.writeData(COMMAND_MODE_CHAR.getBytes()); - connectionInterface.writeData(COMMAND_MODE_CHAR.getBytes()); + connectionInterface.writeData(StringUtils.stringToByteArray(COMMAND_MODE_CHAR)); + connectionInterface.writeData(StringUtils.stringToByteArray(COMMAND_MODE_CHAR)); + connectionInterface.writeData(StringUtils.stringToByteArray(COMMAND_MODE_CHAR)); // Wait some time to let the module generate a response. Thread.sleep(TIMEOUT_ENTER_COMMAND_MODE); @@ -426,7 +427,7 @@ private boolean enterATCommandMode() throws InvalidOperatingModeException, Timeo throw new TimeoutException(); // Check if the read data is 'OK\r'. - String readString = new String(readData, 0, readBytes); + String readString = StringUtils.byteArrayToString(readData, 0, readBytes); if (!readString.contains(COMMAND_MODE_OK)) return false; @@ -1403,7 +1404,8 @@ private boolean waitForModemResetStatusPacket() { addModemStatusListener(resetStatusListener); synchronized (resetLock) { try { - resetLock.wait(TIMEOUT_RESET); + while (!modemStatusReceived) + resetLock.wait(TIMEOUT_RESET); } catch (InterruptedException e) { } } removeModemStatusListener(resetStatusListener); @@ -1435,7 +1437,7 @@ public void modemStatusEventReceived(ModemStatusEvent modemStatusEvent) { modemStatusReceived = true; // Continue execution by notifying the lock object. synchronized (resetLock) { - resetLock.notify(); + resetLock.notifyAll(); } } } @@ -1899,12 +1901,12 @@ private ExplicitXBeeMessage readExplicitDataPacket(RemoteXBeeDevice remoteXBeeDe // Obtain the necessary data from the packet. ExplicitRxIndicatorPacket explicitDataPacket = (ExplicitRxIndicatorPacket)xbeePacket; - RemoteXBeeDevice remoteDevice = getNetwork().getDevice(explicitDataPacket.get64BitSourceAddress()); + RemoteXBeeDevice remoteDevice = getNetwork().getDevice(explicitDataPacket.get64bitSourceAddress()); if (remoteDevice == null) { if (remoteXBeeDevice != null) remoteDevice = remoteXBeeDevice; else - remoteDevice = new RemoteXBeeDevice(this, explicitDataPacket.get64BitSourceAddress()); + remoteDevice = new RemoteXBeeDevice(this, explicitDataPacket.get64bitSourceAddress()); getNetwork().addRemoteDevice(remoteDevice); } int sourceEndpoint = explicitDataPacket.getSourceEndpoint(); diff --git a/library/src/main/java/com/digi/xbee/api/XBeeNetwork.java b/library/src/main/java/com/digi/xbee/api/XBeeNetwork.java index 9b1407c6..02c598e2 100644 --- a/library/src/main/java/com/digi/xbee/api/XBeeNetwork.java +++ b/library/src/main/java/com/digi/xbee/api/XBeeNetwork.java @@ -748,10 +748,12 @@ private XBee16BitAddress get16BitAddress(RemoteXBeeDevice device) { switch (device.getXBeeProtocol()) { case RAW_802_15_4: - address = ((RemoteRaw802Device)device).get16BitAddress(); + if (device instanceof RemoteRaw802Device) + address = ((RemoteRaw802Device)device).get16BitAddress(); break; case ZIGBEE: - address = ((RemoteZigBeeDevice)device).get16BitAddress(); + if (device instanceof RemoteZigBeeDevice) + address = ((RemoteZigBeeDevice)device).get16BitAddress(); break; default: // TODO should we allow this operation for general remote devices? diff --git a/library/src/main/java/com/digi/xbee/api/connection/DataReader.java b/library/src/main/java/com/digi/xbee/api/connection/DataReader.java index 5290787b..f207d4a1 100644 --- a/library/src/main/java/com/digi/xbee/api/connection/DataReader.java +++ b/library/src/main/java/com/digi/xbee/api/connection/DataReader.java @@ -363,13 +363,14 @@ public void run() { // Clear the list of read packets. xbeePacketsQueue.clearQueue(); try { - synchronized (connectionInterface) { - connectionInterface.wait(); - } while (running) { + synchronized (connectionInterface) { + while (connectionInterface.getInputStream() != null &&connectionInterface.getInputStream().available() == 0) + connectionInterface.wait(); + } if (!running) break; - if (connectionInterface.getInputStream() != null) { + if (connectionInterface.getInputStream() != null && connectionInterface.getInputStream().available() > 0) { switch (mode) { case AT: break; @@ -389,15 +390,9 @@ public void run() { default: break; } - } else if (connectionInterface.getInputStream() == null) - break; + } if (connectionInterface.getInputStream() == null) break; - else if (connectionInterface.getInputStream().available() > 0) - continue; - synchronized (connectionInterface) { - connectionInterface.wait(); - } } } catch (IOException e) { logger.error("Error reading from input stream.", e); @@ -490,8 +485,8 @@ private void packetReceived(XBeePacket packet) { clusterID == ExplicitRxIndicatorPacket.DATA_CLUSTER && profileID == ExplicitRxIndicatorPacket.DIGI_PROFILE) { notifyDataReceived(new XBeeMessage(remoteDevice, data, apiPacket.isBroadcast())); - xbeePacketsQueue.addPacket(new ReceivePacket(explicitDataPacket.get64BitSourceAddress(), - explicitDataPacket.get16BitSourceAddress(), + xbeePacketsQueue.addPacket(new ReceivePacket(explicitDataPacket.get64bitSourceAddress(), + explicitDataPacket.get16bitSourceAddress(), explicitDataPacket.getReceiveOptions(), explicitDataPacket.getRFData())); } @@ -548,43 +543,57 @@ public RemoteXBeeDevice getRemoteXBeeDeviceFromPacket(XBeeAPIPacket packet) thro switch(apiType) { case RECEIVE_PACKET: - ReceivePacket receivePacket = (ReceivePacket)apiPacket; - addr64 = receivePacket.get64bitSourceAddress(); - addr16 = receivePacket.get16bitSourceAddress(); - remoteDevice = network.getDevice(addr64); + if (apiPacket instanceof ReceivePacket) { + ReceivePacket receivePacket = (ReceivePacket)apiPacket; + addr64 = receivePacket.get64bitSourceAddress(); + addr16 = receivePacket.get16bitSourceAddress(); + remoteDevice = network.getDevice(addr64); + } break; case RX_64: - RX64Packet rx64Packet = (RX64Packet)apiPacket; - addr64 = rx64Packet.get64bitSourceAddress(); - remoteDevice = network.getDevice(addr64); + if (apiPacket instanceof RX64Packet) { + RX64Packet rx64Packet = (RX64Packet)apiPacket; + addr64 = rx64Packet.get64bitSourceAddress(); + remoteDevice = network.getDevice(addr64); + } break; case RX_16: - RX16Packet rx16Packet = (RX16Packet)apiPacket; - addr64 = XBee64BitAddress.UNKNOWN_ADDRESS; - addr16 = rx16Packet.get16bitSourceAddress(); - remoteDevice = network.getDevice(addr16); + if (apiPacket instanceof RX16Packet) { + RX16Packet rx16Packet = (RX16Packet)apiPacket; + addr64 = XBee64BitAddress.UNKNOWN_ADDRESS; + addr16 = rx16Packet.get16bitSourceAddress(); + remoteDevice = network.getDevice(addr16); + } break; case IO_DATA_SAMPLE_RX_INDICATOR: - IODataSampleRxIndicatorPacket ioSamplePacket = (IODataSampleRxIndicatorPacket)apiPacket; - addr64 = ioSamplePacket.get64bitSourceAddress(); - addr16 = ioSamplePacket.get16bitSourceAddress(); - remoteDevice = network.getDevice(addr64); + if (apiPacket instanceof IODataSampleRxIndicatorPacket) { + IODataSampleRxIndicatorPacket ioSamplePacket = (IODataSampleRxIndicatorPacket)apiPacket; + addr64 = ioSamplePacket.get64bitSourceAddress(); + addr16 = ioSamplePacket.get16bitSourceAddress(); + remoteDevice = network.getDevice(addr64); + } break; case RX_IO_64: - RX64IOPacket rx64IOPacket = (RX64IOPacket)apiPacket; - addr64 = rx64IOPacket.get64bitSourceAddress(); - remoteDevice = network.getDevice(addr64); + if (apiPacket instanceof RX64IOPacket) { + RX64IOPacket rx64IOPacket = (RX64IOPacket)apiPacket; + addr64 = rx64IOPacket.get64bitSourceAddress(); + remoteDevice = network.getDevice(addr64); + } break; case RX_IO_16: - RX16IOPacket rx16IOPacket = (RX16IOPacket)apiPacket; - addr64 = XBee64BitAddress.UNKNOWN_ADDRESS; - addr16 = rx16IOPacket.get16bitSourceAddress(); - remoteDevice = network.getDevice(addr16); + if (apiPacket instanceof RX16IOPacket) { + RX16IOPacket rx16IOPacket = (RX16IOPacket)apiPacket; + addr64 = XBee64BitAddress.UNKNOWN_ADDRESS; + addr16 = rx16IOPacket.get16bitSourceAddress(); + remoteDevice = network.getDevice(addr16); + } break; case EXPLICIT_RX_INDICATOR: + if (!(apiPacket instanceof ExplicitRxIndicatorPacket)) + return remoteDevice; ExplicitRxIndicatorPacket explicitDataPacket = (ExplicitRxIndicatorPacket)apiPacket; - addr64 = explicitDataPacket.get64BitSourceAddress(); - addr16 = explicitDataPacket.get16BitSourceAddress(); + addr64 = explicitDataPacket.get64bitSourceAddress(); + addr16 = explicitDataPacket.get16bitSourceAddress(); remoteDevice = network.getDevice(addr64); break; default: @@ -885,7 +894,7 @@ public boolean isRunning() { public void stopReader() { running = false; synchronized (connectionInterface) { - connectionInterface.notify(); + connectionInterface.notifyAll(); } logger.debug(connectionInterface.toString() + "Data reader stopped."); } diff --git a/library/src/main/java/com/digi/xbee/api/connection/serial/SerialPortRxTx.java b/library/src/main/java/com/digi/xbee/api/connection/serial/SerialPortRxTx.java index 90093ad4..e0a39a27 100644 --- a/library/src/main/java/com/digi/xbee/api/connection/serial/SerialPortRxTx.java +++ b/library/src/main/java/com/digi/xbee/api/connection/serial/SerialPortRxTx.java @@ -214,14 +214,12 @@ public void close() { } synchronized (lock) { if (serialPort != null) { - try { - serialPort.notifyOnDataAvailable(false); - serialPort.removeEventListener(); - portIdentifier.removePortOwnershipListener(this); - serialPort.close(); - serialPort = null; - connectionOpen = false; - } catch (Exception e) { } + serialPort.notifyOnDataAvailable(false); + serialPort.removeEventListener(); + portIdentifier.removePortOwnershipListener(this); + serialPort.close(); + serialPort = null; + connectionOpen = false; } } } @@ -242,7 +240,7 @@ public void serialEvent(SerialPortEvent event) { // Serial device has been disconnected. close(); synchronized (this) { - this.notify(); + this.notifyAll(); } break; } @@ -250,13 +248,15 @@ public void serialEvent(SerialPortEvent event) { try { if (getInputStream().available() > 0) { synchronized (this) { - this.notify(); + this.notifyAll(); } } } catch (Exception e) { logger.error(e.getMessage(), e); } break; + default: + break; } } @@ -389,6 +389,8 @@ public void ownershipChange(int nType) { case CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED: onSerialOwnershipRequested(null); break; + default: + break; } } @@ -405,7 +407,7 @@ private void onSerialOwnershipRequested(Object data) { StackTraceElement[] elems = e.getStackTrace(); String requester = elems[elems.length - 4].getClassName(); synchronized (this) { - this.notify(); + this.notifyAll(); } close(); String myPackage = this.getClass().getPackage().getName(); diff --git a/library/src/main/java/com/digi/xbee/api/io/IOSample.java b/library/src/main/java/com/digi/xbee/api/io/IOSample.java index 86a96234..b9d20550 100644 --- a/library/src/main/java/com/digi/xbee/api/io/IOSample.java +++ b/library/src/main/java/com/digi/xbee/api/io/IOSample.java @@ -138,7 +138,7 @@ public IOSample(byte[] ioSamplePayload) { if (ioSamplePayload.length < 5) throw new IllegalArgumentException("IO sample payload must be longer than 4."); - this.ioSamplePayload = ioSamplePayload; + this.ioSamplePayload = ioSamplePayload.clone(); if (ioSamplePayload.length % 2 != 0) parseRawIOSample(); else diff --git a/library/src/main/java/com/digi/xbee/api/models/ATCommand.java b/library/src/main/java/com/digi/xbee/api/models/ATCommand.java index b651772e..1fad59c2 100644 --- a/library/src/main/java/com/digi/xbee/api/models/ATCommand.java +++ b/library/src/main/java/com/digi/xbee/api/models/ATCommand.java @@ -11,6 +11,8 @@ */ package com.digi.xbee.api.models; +import com.digi.xbee.api.utils.StringUtils; + /** * This class represents an AT command used to read or set different properties * of the XBee device. @@ -57,7 +59,7 @@ public ATCommand(String command) { * @throws NullPointerException if {@code command == null}. */ public ATCommand(String command, String parameter) { - this(command, parameter == null ? null : parameter.getBytes()); + this(command, parameter == null ? null : StringUtils.stringToByteArray(parameter)); } /** @@ -80,7 +82,10 @@ public ATCommand(String command, byte[] parameter) { throw new IllegalArgumentException("Command lenght must be 2."); this.command = command; - this.parameter = parameter; + if (parameter != null) + this.parameter = parameter.clone(); + else + this.parameter = null; } /** @@ -99,7 +104,9 @@ public String getCommand() { * have a parameter. */ public byte[] getParameter() { - return parameter; + if (parameter != null) + return parameter.clone(); + return null; } /** @@ -111,7 +118,7 @@ public byte[] getParameter() { public String getParameterString() { if (parameter == null) return null; - return new String(parameter); + return StringUtils.byteArrayToString(parameter); } /** @@ -120,7 +127,7 @@ public String getParameterString() { * @param parameter The AT command parameter as string. */ public void setParameter(String parameter) { - this.parameter = parameter.getBytes(); + this.parameter = StringUtils.stringToByteArray(parameter); } /** @@ -129,6 +136,9 @@ public void setParameter(String parameter) { * @param parameter The AT command parameter as byte array. */ public void setParameter(byte[] parameter) { - this.parameter = parameter; + if (parameter != null) + this.parameter = parameter.clone(); + else + this.parameter = null; } } diff --git a/library/src/main/java/com/digi/xbee/api/models/ATCommandResponse.java b/library/src/main/java/com/digi/xbee/api/models/ATCommandResponse.java index 43caa95a..bf28fd89 100644 --- a/library/src/main/java/com/digi/xbee/api/models/ATCommandResponse.java +++ b/library/src/main/java/com/digi/xbee/api/models/ATCommandResponse.java @@ -11,6 +11,8 @@ */ package com.digi.xbee.api.models; +import com.digi.xbee.api.utils.StringUtils; + /** * This class represents the response of an AT Command sent by the connected * XBee device or by a remote device after executing an AT Command. @@ -99,7 +101,10 @@ public ATCommandResponse(ATCommand command, byte[] response, ATCommandStatus sta throw new NullPointerException("Status cannot be null."); this.command = command; - this.response = response; + if (response != null) + this.response = response.clone(); + else + this.response = null; this.status = status; } @@ -121,7 +126,9 @@ public ATCommand getCommand() { * {@code null} if there is not response data. */ public byte[] getResponse() { - return response; + if (response != null) + return response.clone(); + return null; } /** @@ -133,7 +140,7 @@ public byte[] getResponse() { public String getResponseString() { if (response == null) return null; - return new String(response); + return StringUtils.byteArrayToString(response); } /** diff --git a/library/src/main/java/com/digi/xbee/api/models/ATCommandStatus.java b/library/src/main/java/com/digi/xbee/api/models/ATCommandStatus.java index e6d50c34..b1709e2e 100644 --- a/library/src/main/java/com/digi/xbee/api/models/ATCommandStatus.java +++ b/library/src/main/java/com/digi/xbee/api/models/ATCommandStatus.java @@ -39,7 +39,7 @@ public enum ATCommandStatus { static { for (ATCommandStatus at:values()) - lookupTable.put(at.getId(), at); + lookupTable.put(at.getID(), at); } /** @@ -59,7 +59,7 @@ public enum ATCommandStatus { * * @return The AT Command Status ID. */ - public int getId() { + public int getID() { return id; } diff --git a/library/src/main/java/com/digi/xbee/api/models/ATStringCommands.java b/library/src/main/java/com/digi/xbee/api/models/ATStringCommands.java index 0119ddb7..8b4bd638 100644 --- a/library/src/main/java/com/digi/xbee/api/models/ATStringCommands.java +++ b/library/src/main/java/com/digi/xbee/api/models/ATStringCommands.java @@ -13,6 +13,8 @@ import java.util.HashMap; +import com.digi.xbee.api.utils.StringUtils; + /** * Enumerates several AT commands used to parse AT command packets. The list * of AT Command alias listed here represents those AT commands whose values @@ -66,6 +68,6 @@ public String getCommand() { * alias. */ public static ATStringCommands get(String command) { - return lookupTable.get(command.toUpperCase()); + return lookupTable.get(StringUtils.stringToUpperCase(command)); } } diff --git a/library/src/main/java/com/digi/xbee/api/models/ModemStatusEvent.java b/library/src/main/java/com/digi/xbee/api/models/ModemStatusEvent.java index ba362402..76335b4f 100644 --- a/library/src/main/java/com/digi/xbee/api/models/ModemStatusEvent.java +++ b/library/src/main/java/com/digi/xbee/api/models/ModemStatusEvent.java @@ -52,7 +52,7 @@ public enum ModemStatusEvent { static { for (ModemStatusEvent at:values()) - lookupTable.put(at.getId(), at); + lookupTable.put(at.getID(), at); } /** @@ -72,7 +72,7 @@ public enum ModemStatusEvent { * * @return The modem status ID. */ - public int getId() { + public int getID() { return id; } diff --git a/library/src/main/java/com/digi/xbee/api/models/XBeeDiscoveryStatus.java b/library/src/main/java/com/digi/xbee/api/models/XBeeDiscoveryStatus.java index 8a6c47a3..0640bb55 100644 --- a/library/src/main/java/com/digi/xbee/api/models/XBeeDiscoveryStatus.java +++ b/library/src/main/java/com/digi/xbee/api/models/XBeeDiscoveryStatus.java @@ -39,7 +39,7 @@ public enum XBeeDiscoveryStatus { static { for (XBeeDiscoveryStatus at:values()) - lookupTable.put(at.getId(), at); + lookupTable.put(at.getID(), at); } /** @@ -59,7 +59,7 @@ private XBeeDiscoveryStatus(int id, String description) { * * @return The discovery status identifier. */ - public int getId() { + public int getID() { return id; } diff --git a/library/src/main/java/com/digi/xbee/api/models/XBeeMessage.java b/library/src/main/java/com/digi/xbee/api/models/XBeeMessage.java index 8dbe45dd..bd59d344 100644 --- a/library/src/main/java/com/digi/xbee/api/models/XBeeMessage.java +++ b/library/src/main/java/com/digi/xbee/api/models/XBeeMessage.java @@ -12,6 +12,7 @@ package com.digi.xbee.api.models; import com.digi.xbee.api.RemoteXBeeDevice; +import com.digi.xbee.api.utils.StringUtils; /** * This class represents an XBee message containing the remote XBee device the @@ -65,7 +66,7 @@ public XBeeMessage(RemoteXBeeDevice remoteXBeeDevice, byte[] data, boolean isBro throw new NullPointerException("Data cannot be null."); this.remoteXBeeDevice = remoteXBeeDevice; - this.data = data; + this.data = data.clone(); this.isBroadcast = isBroadcast; } @@ -86,7 +87,7 @@ public RemoteXBeeDevice getDevice() { * @return A byte array containing the data of the message. */ public byte[] getData() { - return data; + return data.clone(); } /** @@ -95,7 +96,7 @@ public byte[] getData() { * @return The data of the message in string format. */ public String getDataString() { - return new String(data); + return StringUtils.byteArrayToString(data); } /** diff --git a/library/src/main/java/com/digi/xbee/api/models/XBeePacketsQueue.java b/library/src/main/java/com/digi/xbee/api/models/XBeePacketsQueue.java index 0fca0c81..5bfae6ae 100644 --- a/library/src/main/java/com/digi/xbee/api/models/XBeePacketsQueue.java +++ b/library/src/main/java/com/digi/xbee/api/models/XBeePacketsQueue.java @@ -384,7 +384,7 @@ private boolean addressesMatch(XBeePacket xbeePacket, RemoteXBeeDevice remoteXBe return true; break; case EXPLICIT_RX_INDICATOR: - if (((ExplicitRxIndicatorPacket)xbeePacket).get64BitSourceAddress().equals(remoteXBeeDevice.get64BitAddress())) + if (((ExplicitRxIndicatorPacket)xbeePacket).get64bitSourceAddress().equals(remoteXBeeDevice.get64BitAddress())) return true; break; default: diff --git a/library/src/main/java/com/digi/xbee/api/models/XBeeTransmitStatus.java b/library/src/main/java/com/digi/xbee/api/models/XBeeTransmitStatus.java index edadb5ac..b6d8db24 100644 --- a/library/src/main/java/com/digi/xbee/api/models/XBeeTransmitStatus.java +++ b/library/src/main/java/com/digi/xbee/api/models/XBeeTransmitStatus.java @@ -60,7 +60,7 @@ public enum XBeeTransmitStatus { static { for (XBeeTransmitStatus ts:values()) - lookupTable.put(ts.getId(), ts); + lookupTable.put(ts.getID(), ts); } /** @@ -80,7 +80,7 @@ private XBeeTransmitStatus(int id, String description) { * * @return Transmit status identifier. */ - public int getId() { + public int getID() { return id; } @@ -118,7 +118,7 @@ public static XBeeTransmitStatus get(int id) { */ @Override public String toString() { - if (id != SUCCESS.getId()) + if (id != SUCCESS.getID()) return String.format("Error: %s (0x%02X)", description, id); else return String.format("%s (0x%02X)", description, id); diff --git a/library/src/main/java/com/digi/xbee/api/packet/GenericXBeePacket.java b/library/src/main/java/com/digi/xbee/api/packet/GenericXBeePacket.java index 86749c7e..c0d7a04c 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/GenericXBeePacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/GenericXBeePacket.java @@ -79,7 +79,10 @@ public static GenericXBeePacket createPacket(byte[] payload) { */ public GenericXBeePacket(byte[] rfData) { super(APIFrameType.GENERIC); - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); + else + this.rfData = null; this.logger = LoggerFactory.getLogger(GenericXBeePacket.class); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/UnknownXBeePacket.java b/library/src/main/java/com/digi/xbee/api/packet/UnknownXBeePacket.java index 7841e613..181ba38c 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/UnknownXBeePacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/UnknownXBeePacket.java @@ -80,7 +80,10 @@ public static UnknownXBeePacket createPacket(byte[] payload) { */ public UnknownXBeePacket(int apiIDValue, byte[] rfData) { super(apiIDValue); - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); + else + this.rfData = null; this.logger = LoggerFactory.getLogger(UnknownXBeePacket.class); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/XBeeAPIPacket.java b/library/src/main/java/com/digi/xbee/api/packet/XBeeAPIPacket.java index 55a04326..da3e09fd 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/XBeeAPIPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/XBeeAPIPacket.java @@ -124,7 +124,7 @@ public byte[] getPacketData() { byte[] apiData = getAPIData(); if (apiData == null) apiData = new byte[0]; - if (apiData != null && apiData.length > 0) { + if (apiData.length > 0) { try { data.write(apiData); } catch (IOException e) { @@ -152,7 +152,7 @@ public byte[] getAPIData() { if (needsAPIFrameID()) data.write(frameID); - if (apiData != null && apiData.length > 0) { + if (apiData.length > 0) { try { data.write(apiData); } catch (IOException e) { diff --git a/library/src/main/java/com/digi/xbee/api/packet/XBeePacket.java b/library/src/main/java/com/digi/xbee/api/packet/XBeePacket.java index 0ba726e0..75a99b2e 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/XBeePacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/XBeePacket.java @@ -15,6 +15,7 @@ import java.io.ByteArrayOutputStream; import java.util.Arrays; import java.util.LinkedHashMap; +import java.util.Map; import com.digi.xbee.api.exceptions.InvalidPacketException; import com.digi.xbee.api.models.SpecialByte; @@ -206,11 +207,12 @@ public String toString() { * @return Pretty String representing the packet. */ public String toPrettyString() { - String value = "Packet: " + toString() + "\n"; + StringBuilder value = new StringBuilder(); + value.append("Packet: " + toString() + "\n"); LinkedHashMap parameters = getParameters(); - for (String parameter:parameters.keySet()) - value = value + parameter + ": " + parameters.get(parameter) + "\n"; - return value; + for (Map.Entry parameter:parameters.entrySet()) + value.append(parameter.getKey() + ": " + parameter.getValue() + "\n"); + return value.toString(); } /** diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandPacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandPacket.java index 9b587ca9..65901648 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandPacket.java @@ -23,6 +23,7 @@ import com.digi.xbee.api.packet.XBeeAPIPacket; import com.digi.xbee.api.packet.APIFrameType; import com.digi.xbee.api.utils.HexUtils; +import com.digi.xbee.api.utils.StringUtils; /** * This class represents an AT Command XBee packet. Packet is built @@ -83,7 +84,7 @@ public static ATCommandPacket createPacket(byte[] payload) { index = index + 1; // 2 bytes of AT command, starting at 2nd byte. - String command = new String(new byte[]{payload[index], payload[index + 1]}); + String command = StringUtils.byteArrayToString(new byte[]{payload[index], payload[index + 1]}); index = index + 2; // Get data. @@ -108,7 +109,7 @@ public static ATCommandPacket createPacket(byte[] payload) { * @throws NullPointerException if {@code command == null}. */ public ATCommandPacket(int frameID, String command, String parameter) { - this(frameID, command, parameter == null ? null : parameter.getBytes()); + this(frameID, command, parameter == null ? null : StringUtils.stringToByteArray(parameter)); } /** @@ -133,7 +134,10 @@ public ATCommandPacket(int frameID, String command, byte[] parameter) { this.frameID = frameID; this.command = command; - this.parameter = parameter; + if (parameter != null) + this.parameter = parameter.clone(); + else + this.parameter = null; this.logger = LoggerFactory.getLogger(ATCommandPacket.class); } @@ -145,7 +149,7 @@ public ATCommandPacket(int frameID, String command, byte[] parameter) { protected byte[] getAPIPacketSpecificData() { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { - os.write(command.getBytes()); + os.write(StringUtils.stringToByteArray(command)); if (parameter != null) os.write(parameter); } catch (IOException e) { @@ -181,7 +185,7 @@ public void setParameter(String parameter) { if (parameter == null) this.parameter = null; else - this.parameter = parameter.getBytes(); + this.parameter = StringUtils.stringToByteArray(parameter); } /** @@ -190,7 +194,10 @@ public void setParameter(String parameter) { * @param parameter The AT command parameter. */ public void setParameter(byte[] parameter) { - this.parameter = parameter; + if (parameter != null) + this.parameter = parameter.clone(); + else + this.parameter = null; } /** @@ -199,7 +206,9 @@ public void setParameter(byte[] parameter) { * @return The AT command parameter. */ public byte[] getParameter() { - return parameter; + if (parameter != null) + return parameter.clone(); + return null; } /** @@ -211,7 +220,7 @@ public byte[] getParameter() { public String getParameterAsString() { if (parameter == null) return null; - return new String(parameter); + return StringUtils.byteArrayToString(parameter); } /* @@ -230,10 +239,10 @@ public boolean isBroadcast() { @Override public LinkedHashMap getAPIPacketParameters() { LinkedHashMap parameters = new LinkedHashMap(); - parameters.put("AT Command", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(command.getBytes())) + " (" + command + ")"); + parameters.put("AT Command", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(StringUtils.stringToByteArray(command))) + " (" + command + ")"); if (parameter != null) { if (ATStringCommands.get(command) != null) - parameters.put("Parameter", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(parameter)) + " (" + new String(parameter) + ")"); + parameters.put("Parameter", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(parameter)) + " (" + StringUtils.byteArrayToString(parameter) + ")"); else parameters.put("Parameter", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(parameter))); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandQueuePacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandQueuePacket.java index 1c03086d..15ec36d9 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandQueuePacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandQueuePacket.java @@ -23,6 +23,7 @@ import com.digi.xbee.api.packet.XBeeAPIPacket; import com.digi.xbee.api.packet.APIFrameType; import com.digi.xbee.api.utils.HexUtils; +import com.digi.xbee.api.utils.StringUtils; /** * This class represents an AT Command Queue XBee packet. Packet is built @@ -89,7 +90,7 @@ public static ATCommandQueuePacket createPacket(byte[] payload) { index = index + 1; // 2 bytes of AT command, starting at 2nd byte. - String command = new String(new byte[]{payload[index], payload[index + 1]}); + String command = StringUtils.byteArrayToString(new byte[]{payload[index], payload[index + 1]}); index = index + 2; // Get data. @@ -114,7 +115,7 @@ public static ATCommandQueuePacket createPacket(byte[] payload) { * @throws NullPointerException if {@code command == null}. */ public ATCommandQueuePacket(int frameID, String command, String parameter) { - this(frameID, command, parameter == null ? null : parameter.getBytes()); + this(frameID, command, parameter == null ? null : StringUtils.stringToByteArray(parameter)); } /** @@ -139,7 +140,10 @@ public ATCommandQueuePacket(int frameID, String command, byte[] parameter) { this.frameID = frameID; this.command = command; - this.parameter = parameter; + if (parameter != null) + this.parameter = parameter.clone(); + else + this.parameter = null; this.logger = LoggerFactory.getLogger(ATCommandQueuePacket.class); } @@ -151,7 +155,7 @@ public ATCommandQueuePacket(int frameID, String command, byte[] parameter) { protected byte[] getAPIPacketSpecificData() { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { - os.write(command.getBytes()); + os.write(StringUtils.stringToByteArray(command)); if (parameter != null) os.write(parameter); } catch (IOException e) { @@ -187,7 +191,7 @@ public void setParameter(String parameter) { if (parameter == null) this.parameter = null; else - this.parameter = parameter.getBytes(); + this.parameter = StringUtils.stringToByteArray(parameter); } /** @@ -196,7 +200,10 @@ public void setParameter(String parameter) { * @param parameter The AT command parameter. */ public void setParameter(byte[] parameter) { - this.parameter = parameter; + if (parameter != null) + this.parameter = parameter.clone(); + else + this.parameter = null; } /** @@ -205,7 +212,9 @@ public void setParameter(byte[] parameter) { * @return The AT command parameter. */ public byte[] getParameter() { - return parameter; + if (parameter != null) + return parameter.clone(); + return null; } /** @@ -217,7 +226,7 @@ public byte[] getParameter() { public String getParameterAsString() { if (parameter == null) return null; - return new String(parameter); + return StringUtils.byteArrayToString(parameter); } /* @@ -236,10 +245,10 @@ public boolean isBroadcast() { @Override public LinkedHashMap getAPIPacketParameters() { LinkedHashMap parameters = new LinkedHashMap(); - parameters.put("AT Command", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(command.getBytes())) + " (" + command + ")"); + parameters.put("AT Command", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(StringUtils.stringToByteArray(command))) + " (" + command + ")"); if (parameter != null) { if (ATStringCommands.get(command) != null) - parameters.put("Parameter", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(parameter)) + " (" + new String(parameter) + ")"); + parameters.put("Parameter", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(parameter)) + " (" + StringUtils.byteArrayToString(parameter) + ")"); else parameters.put("Parameter", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(parameter))); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandResponsePacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandResponsePacket.java index 61aec022..255acd4e 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandResponsePacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/ATCommandResponsePacket.java @@ -23,6 +23,7 @@ import com.digi.xbee.api.packet.XBeeAPIPacket; import com.digi.xbee.api.packet.APIFrameType; import com.digi.xbee.api.utils.HexUtils; +import com.digi.xbee.api.utils.StringUtils; import com.digi.xbee.api.models.ATStringCommands; /** @@ -91,7 +92,7 @@ public static ATCommandResponsePacket createPacket(byte[] payload) { index = index + 1; // 2 bytes of AT command, starting at 2nd byte. - String command = new String(new byte[]{payload[index], payload[index + 1]}); + String command = StringUtils.byteArrayToString(new byte[]{payload[index], payload[index + 1]}); index = index + 2; // Status byte. @@ -136,7 +137,10 @@ public ATCommandResponsePacket(int frameID, ATCommandStatus status, String comma this.frameID = frameID; this.status = status; this.command = command; - this.commandValue = commandValue; + if (commandValue != null) + this.commandValue = commandValue.clone(); + else + this.commandValue = null; this.logger = LoggerFactory.getLogger(ATCommandResponsePacket.class); } @@ -148,8 +152,8 @@ public ATCommandResponsePacket(int frameID, ATCommandStatus status, String comma protected byte[] getAPIPacketSpecificData() { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { - os.write(command.getBytes()); - os.write(status.getId()); + os.write(StringUtils.stringToByteArray(command)); + os.write(status.getID()); if (commandValue != null) os.write(commandValue); } catch (IOException e) { @@ -196,7 +200,7 @@ public void setCommandValue(String commandValue) { if (commandValue == null) this.commandValue = null; else - this.commandValue = commandValue.getBytes(); + this.commandValue = StringUtils.stringToByteArray(commandValue); } /** @@ -205,7 +209,10 @@ public void setCommandValue(String commandValue) { * @param commandValue The AT command response value. */ public void setCommandValue(byte[] commandValue) { - this.commandValue = commandValue; + if (commandValue != null) + this.commandValue = commandValue.clone(); + else + this.commandValue = null; } /** @@ -214,7 +221,9 @@ public void setCommandValue(byte[] commandValue) { * @return The AT command response value. */ public byte[] getCommandValue() { - return commandValue; + if (commandValue != null) + return commandValue.clone(); + return null; } /** @@ -226,7 +235,7 @@ public byte[] getCommandValue() { public String getCommandValueAsString() { if (commandValue == null) return null; - return new String(commandValue); + return StringUtils.byteArrayToString(commandValue); } /* @@ -245,11 +254,11 @@ public boolean isBroadcast() { @Override public LinkedHashMap getAPIPacketParameters() { LinkedHashMap parameters = new LinkedHashMap(); - parameters.put("AT Command", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(command.getBytes())) + " (" + command + ")"); - parameters.put("Status", HexUtils.prettyHexString(HexUtils.integerToHexString(status.getId(), 1)) + " (" + status.getDescription() + ")"); + parameters.put("AT Command", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(StringUtils.stringToByteArray(command))) + " (" + command + ")"); + parameters.put("Status", HexUtils.prettyHexString(HexUtils.integerToHexString(status.getID(), 1)) + " (" + status.getDescription() + ")"); if (commandValue != null) { if (ATStringCommands.get(command) != null) - parameters.put("Response", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(commandValue)) + " (" + new String(commandValue) + ")"); + parameters.put("Response", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(commandValue)) + " (" + StringUtils.byteArrayToString(commandValue) + ")"); else parameters.put("Response", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(commandValue))); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/ExplicitAddressingPacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/ExplicitAddressingPacket.java index 33a71d6b..7de0742f 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/ExplicitAddressingPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/ExplicitAddressingPacket.java @@ -257,7 +257,8 @@ public ExplicitAddressingPacket(int frameID, XBee64BitAddress destAddress64, XBe this.profileID = profileID; this.broadcastRadius = broadcastRadius; this.transmitOptions = transmitOptions; - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); this.logger = LoggerFactory.getLogger(ExplicitAddressingPacket.class); } @@ -302,8 +303,8 @@ public boolean needsAPIFrameID() { */ @Override public boolean isBroadcast() { - if (get64BitDestinationAddress().equals(XBee64BitAddress.BROADCAST_ADDRESS) - || get16BitDestinationAddress().equals(XBee16BitAddress.BROADCAST_ADDRESS)) + if (get64bitDestinationAddress().equals(XBee64BitAddress.BROADCAST_ADDRESS) + || get16bitDestinationAddress().equals(XBee16BitAddress.BROADCAST_ADDRESS)) return true; return false; } @@ -315,7 +316,7 @@ public boolean isBroadcast() { * * @see com.digi.xbee.api.models.XBee64BitAddress */ - public XBee64BitAddress get64BitDestinationAddress() { + public XBee64BitAddress get64bitDestinationAddress() { return destAddress64; } @@ -326,7 +327,7 @@ public XBee64BitAddress get64BitDestinationAddress() { * * @see com.digi.xbee.api.models.XBee16BitAddress */ - public XBee16BitAddress get16BitDestinationAddress() { + public XBee16BitAddress get16bitDestinationAddress() { return destAddress16; } diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/ExplicitRxIndicatorPacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/ExplicitRxIndicatorPacket.java index c614e962..79b0e75a 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/ExplicitRxIndicatorPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/ExplicitRxIndicatorPacket.java @@ -202,7 +202,8 @@ public ExplicitRxIndicatorPacket(XBee64BitAddress sourceAddress64, XBee16BitAddr this.clusterID = clusterID; this.profileID = profileID; this.receiveOptions = receiveOptions; - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); this.logger = LoggerFactory.getLogger(ExplicitRxIndicatorPacket.class); } @@ -258,7 +259,7 @@ public boolean isBroadcast() { * * @see com.digi.xbee.api.models.XBee64BitAddress */ - public XBee64BitAddress get64BitSourceAddress() { + public XBee64BitAddress get64bitSourceAddress() { return sourceAddress64; } @@ -269,7 +270,7 @@ public XBee64BitAddress get64BitSourceAddress() { * * @see com.digi.xbee.api.models.XBee16BitAddress */ - public XBee16BitAddress get16BitSourceAddress() { + public XBee16BitAddress get16bitSourceAddress() { return sourceAddress16; } diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/IODataSampleRxIndicatorPacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/IODataSampleRxIndicatorPacket.java index a2fe4e0c..93219ea1 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/IODataSampleRxIndicatorPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/IODataSampleRxIndicatorPacket.java @@ -142,7 +142,8 @@ public IODataSampleRxIndicatorPacket(XBee64BitAddress sourceAddress64, XBee16Bit this.sourceAddress64 = sourceAddress64; this.sourceAddress16 = sourceAddress16; this.receiveOptions = receiveOptions; - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); if (rfData != null && rfData.length >= 5) ioSample = new IOSample(rfData); else @@ -276,10 +277,14 @@ public LinkedHashMap getAPIPacketParameters() { parameters.put("Digital channel mask", HexUtils.prettyHexString(HexUtils.integerToHexString(ioSample.getDigitalMask(), 2))); parameters.put("Analog channel mask", HexUtils.prettyHexString(HexUtils.integerToHexString(ioSample.getAnalogMask(), 1))); for (int i = 0; i < 16; i++) { + if (IOLine.getDIO(i) == null) + continue; if (ioSample.hasDigitalValue(IOLine.getDIO(i))) parameters.put(IOLine.getDIO(i).getName() + " digital value", ioSample.getDigitalValue(IOLine.getDIO(i)).getName()); } for (int i = 0; i < 6; i++) { + if (IOLine.getDIO(i) == null) + continue; if (ioSample.hasAnalogValue(IOLine.getDIO(i))) parameters.put(IOLine.getDIO(i).getName() + " analog value", HexUtils.prettyHexString(HexUtils.integerToHexString(ioSample.getAnalogValue(IOLine.getDIO(i)), 2))); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/ModemStatusPacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/ModemStatusPacket.java index 55f2caa2..1ff72254 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/ModemStatusPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/ModemStatusPacket.java @@ -93,7 +93,7 @@ public ModemStatusPacket(ModemStatusEvent modemStatusEvent) { @Override public byte[] getAPIPacketSpecificData() { byte[] data = new byte[1]; - data[0] = (byte)(modemStatusEvent.getId() & 0xFF); + data[0] = (byte)(modemStatusEvent.getID() & 0xFF); return data; } @@ -131,7 +131,7 @@ public boolean isBroadcast() { @Override public LinkedHashMap getAPIPacketParameters() { LinkedHashMap parameters = new LinkedHashMap(); - parameters.put("Status", HexUtils.prettyHexString(HexUtils.integerToHexString(modemStatusEvent.getId(), 1)) + " (" + modemStatusEvent.getDescription() + ")"); + parameters.put("Status", HexUtils.prettyHexString(HexUtils.integerToHexString(modemStatusEvent.getID(), 1)) + " (" + modemStatusEvent.getDescription() + ")"); return parameters; } } diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/ReceivePacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/ReceivePacket.java index e5de2ad9..74671bff 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/ReceivePacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/ReceivePacket.java @@ -139,7 +139,10 @@ public ReceivePacket(XBee64BitAddress sourceAddress64, XBee16BitAddress sourceAd this.sourceAddress64 = sourceAddress64; this.sourceAddress16 = sourceAddress16; this.receiveOptions = receiveOptions; - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); + else + this.rfData = null; this.logger = LoggerFactory.getLogger(ReceivePacket.class); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/RemoteATCommandPacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/RemoteATCommandPacket.java index 20938264..ca919018 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/RemoteATCommandPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/RemoteATCommandPacket.java @@ -24,8 +24,8 @@ import com.digi.xbee.api.models.XBee64BitAddress; import com.digi.xbee.api.packet.APIFrameType; import com.digi.xbee.api.packet.XBeeAPIPacket; -import com.digi.xbee.api.utils.ByteUtils; import com.digi.xbee.api.utils.HexUtils; +import com.digi.xbee.api.utils.StringUtils; /** * This class represents a Remote AT Command Request packet. Packet is built @@ -111,7 +111,7 @@ public static RemoteATCommandPacket createPacket(byte[] payload) { index = index + 1; // 2 bytes of AT command. - String command = new String(new byte[]{payload[index], payload[index + 1]}); + String command = StringUtils.byteArrayToString(new byte[]{payload[index], payload[index + 1]}); index = index + 2; // Get data. @@ -167,7 +167,7 @@ public RemoteATCommandPacket(int frameID, XBee64BitAddress destAddress64, XBee16 this.transmitOptions = transmitOptions; this.command = command; if (parameter != null) - this.parameter = parameter.getBytes(); + this.parameter = StringUtils.stringToByteArray(parameter); this.logger = LoggerFactory.getLogger(RemoteATCommandPacket.class); } @@ -214,7 +214,10 @@ public RemoteATCommandPacket(int frameID, XBee64BitAddress destAddress64, XBee16 this.destAddress16 = destAddress16; this.transmitOptions = transmitOptions; this.command = command; - this.parameter = parameter; + if (parameter != null) + this.parameter = parameter.clone(); + else + this.parameter = null; this.logger = LoggerFactory.getLogger(RemoteATCommandPacket.class); } @@ -229,7 +232,7 @@ protected byte[] getAPIPacketSpecificData() { data.write(destAddress64.getValue()); data.write(destAddress16.getValue()); data.write(transmitOptions); - data.write(ByteUtils.stringToByteArray(command)); + data.write(StringUtils.stringToByteArray(command)); if (parameter != null) data.write(parameter); } catch (IOException e) { @@ -308,7 +311,7 @@ public void setParameter(String parameter) { if (parameter == null) this.parameter = null; else - this.parameter = parameter.getBytes(); + this.parameter = StringUtils.stringToByteArray(parameter); } /** @@ -317,7 +320,10 @@ public void setParameter(String parameter) { * @param parameter The AT command parameter. */ public void setParameter(byte[] parameter) { - this.parameter = parameter; + if (parameter != null) + this.parameter = parameter.clone(); + else + this.parameter = null; } /** @@ -326,7 +332,9 @@ public void setParameter(byte[] parameter) { * @return The AT command parameter. */ public byte[] getParameter() { - return parameter; + if (parameter != null) + return parameter.clone(); + return null; } /** @@ -338,7 +346,7 @@ public byte[] getParameter() { public String getParameterAsString() { if (parameter == null) return null; - return new String(parameter); + return StringUtils.byteArrayToString(parameter); } /* @@ -351,10 +359,10 @@ public LinkedHashMap getAPIPacketParameters() { parameters.put("64-bit dest. address", HexUtils.prettyHexString(destAddress64.toString())); parameters.put("16-bit dest. address", HexUtils.prettyHexString(destAddress16.toString())); parameters.put("Command options", HexUtils.prettyHexString(HexUtils.integerToHexString(transmitOptions, 1))); - parameters.put("AT Command", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(command.getBytes())) + " (" + command + ")"); + parameters.put("AT Command", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(StringUtils.stringToByteArray(command))) + " (" + command + ")"); if (parameter != null) { if (ATStringCommands.get(command) != null) - parameters.put("Parameter", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(parameter)) + " (" + new String(parameter) + ")"); + parameters.put("Parameter", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(parameter)) + " (" + StringUtils.byteArrayToString(parameter) + ")"); else parameters.put("Parameter", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(parameter))); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/RemoteATCommandResponsePacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/RemoteATCommandResponsePacket.java index 0bdcfa2b..5f218724 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/RemoteATCommandResponsePacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/RemoteATCommandResponsePacket.java @@ -25,8 +25,8 @@ import com.digi.xbee.api.models.XBee64BitAddress; import com.digi.xbee.api.packet.APIFrameType; import com.digi.xbee.api.packet.XBeeAPIPacket; -import com.digi.xbee.api.utils.ByteUtils; import com.digi.xbee.api.utils.HexUtils; +import com.digi.xbee.api.utils.StringUtils; /** * This class represents a Remote AT Command Response packet. Packet is built @@ -108,7 +108,7 @@ public static RemoteATCommandResponsePacket createPacket(byte[] payload) { index = index + 2; // 2 bytes of AT command. - String command = new String(new byte[]{payload[index], payload[index + 1]}); + String command = StringUtils.byteArrayToString(new byte[]{payload[index], payload[index + 1]}); index = index + 2; // Status byte. @@ -168,7 +168,10 @@ public RemoteATCommandResponsePacket(int frameID, XBee64BitAddress sourceAddress this.sourceAddress16 = sourceAddress16; this.command = command; this.status = status; - this.commandValue = commandValue; + if (commandValue != null) + this.commandValue = commandValue.clone(); + else + this.commandValue = null; this.logger = LoggerFactory.getLogger(RemoteATCommandResponsePacket.class); } @@ -182,8 +185,8 @@ protected byte[] getAPIPacketSpecificData() { try { data.write(sourceAddress64.getValue()); data.write(sourceAddress16.getValue()); - data.write(ByteUtils.stringToByteArray(command)); - data.write(status.getId()); + data.write(StringUtils.stringToByteArray(command)); + data.write(status.getID()); if (commandValue != null) data.write(commandValue); } catch (IOException e) { @@ -252,7 +255,7 @@ public void setCommandValue(String commandValue) { if (commandValue == null) this.commandValue = null; else - this.commandValue = commandValue.getBytes(); + this.commandValue = StringUtils.stringToByteArray(commandValue); } /** @@ -261,7 +264,10 @@ public void setCommandValue(String commandValue) { * @param commandValue The AT command response value. */ public void setCommandValue(byte[] commandValue) { - this.commandValue = commandValue; + if (commandValue != null) + this.commandValue = commandValue.clone(); + else + this.commandValue = null; } /** @@ -270,7 +276,9 @@ public void setCommandValue(byte[] commandValue) { * @return The AT command response value. */ public byte[] getCommandValue() { - return commandValue; + if (commandValue != null) + return commandValue.clone(); + return null; } /** @@ -282,7 +290,7 @@ public byte[] getCommandValue() { public String getCommandValueAsString() { if (commandValue == null) return null; - return new String(commandValue); + return StringUtils.byteArrayToString(commandValue); } /* @@ -303,11 +311,11 @@ public LinkedHashMap getAPIPacketParameters() { LinkedHashMap parameters = new LinkedHashMap(); parameters.put("64-bit source address", HexUtils.prettyHexString(sourceAddress64.toString())); parameters.put("16-bit source address", HexUtils.prettyHexString(sourceAddress16.toString())); - parameters.put("AT Command", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(command.getBytes())) + " (" + command + ")"); - parameters.put("Status", HexUtils.prettyHexString(HexUtils.integerToHexString(status.getId(), 1)) + " (" + status.getDescription() + ")"); + parameters.put("AT Command", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(StringUtils.stringToByteArray(command))) + " (" + command + ")"); + parameters.put("Status", HexUtils.prettyHexString(HexUtils.integerToHexString(status.getID(), 1)) + " (" + status.getDescription() + ")"); if (commandValue != null) { if (ATStringCommands.get(command) != null) - parameters.put("Response", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(commandValue)) + " (" + new String(commandValue) + ")"); + parameters.put("Response", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(commandValue)) + " (" + StringUtils.byteArrayToString(commandValue) + ")"); else parameters.put("Response", HexUtils.prettyHexString(HexUtils.byteArrayToHexString(commandValue))); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/TransmitPacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/TransmitPacket.java index 267b4892..ff45fcc6 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/TransmitPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/TransmitPacket.java @@ -192,7 +192,10 @@ public TransmitPacket(int frameID, XBee64BitAddress destAddress64, XBee16BitAddr this.destAddress16 = destAddress16; this.broadcastRadius = broadcastRadius; this.transmitOptions = transmitOptions; - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); + else + this.rfData = null; this.logger = LoggerFactory.getLogger(TransmitPacket.class); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/common/TransmitStatusPacket.java b/library/src/main/java/com/digi/xbee/api/packet/common/TransmitStatusPacket.java index 54aecb6b..03b6b3b9 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/common/TransmitStatusPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/common/TransmitStatusPacket.java @@ -163,8 +163,8 @@ protected byte[] getAPIPacketSpecificData() { try { data.write(destAddress16.getValue()); data.write(tranmistRetryCount); - data.write(transmitStatus.getId()); - data.write(discoveryStatus.getId()); + data.write(transmitStatus.getID()); + data.write(discoveryStatus.getID()); } catch (IOException e) { logger.error(e.getMessage(), e); } @@ -243,10 +243,10 @@ public LinkedHashMap getAPIPacketParameters() { HexUtils.prettyHexString(HexUtils.integerToHexString(tranmistRetryCount, 1)) + " (" + tranmistRetryCount + ")"); parameters.put("Delivery status", - HexUtils.prettyHexString(HexUtils.integerToHexString(transmitStatus.getId(), 1)) + HexUtils.prettyHexString(HexUtils.integerToHexString(transmitStatus.getID(), 1)) + " (" + transmitStatus.getDescription() + ")"); parameters.put("Discovery status", - HexUtils.prettyHexString(HexUtils.integerToHexString(discoveryStatus.getId(), 1)) + HexUtils.prettyHexString(HexUtils.integerToHexString(discoveryStatus.getID(), 1)) + " (" + discoveryStatus.getDescription() + ")"); return parameters; } diff --git a/library/src/main/java/com/digi/xbee/api/packet/raw/RX16IOPacket.java b/library/src/main/java/com/digi/xbee/api/packet/raw/RX16IOPacket.java index 144ee7d4..cf3a9609 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/raw/RX16IOPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/raw/RX16IOPacket.java @@ -134,7 +134,8 @@ public RX16IOPacket(XBee16BitAddress sourceAddress16, int rssi, int receiveOptio this.sourceAddress16 = sourceAddress16; this.rssi = rssi; this.receiveOptions = receiveOptions; - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); if (rfData != null && rfData.length >= 5) ioSample = new IOSample(rfData); else @@ -267,10 +268,14 @@ public LinkedHashMap getAPIPacketParameters() { parameters.put("Digital channel mask", HexUtils.prettyHexString(HexUtils.integerToHexString(ioSample.getDigitalMask(), 2))); parameters.put("Analog channel mask", HexUtils.prettyHexString(HexUtils.integerToHexString(ioSample.getAnalogMask(), 2))); for (int i = 0; i < 16; i++) { + if (IOLine.getDIO(i) == null) + continue; if (ioSample.hasDigitalValue(IOLine.getDIO(i))) parameters.put(IOLine.getDIO(i).getName() + " digital value", ioSample.getDigitalValue(IOLine.getDIO(i)).getName()); } for (int i = 0; i < 6; i++) { + if (IOLine.getDIO(i) == null) + continue; if (ioSample.hasAnalogValue(IOLine.getDIO(i))) parameters.put(IOLine.getDIO(i).getName() + " analog value", HexUtils.prettyHexString(HexUtils.integerToHexString(ioSample.getAnalogValue(IOLine.getDIO(i)), 2))); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/raw/RX16Packet.java b/library/src/main/java/com/digi/xbee/api/packet/raw/RX16Packet.java index cd9562e3..68f20109 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/raw/RX16Packet.java +++ b/library/src/main/java/com/digi/xbee/api/packet/raw/RX16Packet.java @@ -135,7 +135,10 @@ public RX16Packet(XBee16BitAddress sourceAddress16, int rssi, int receiveOptions this.sourceAddress16 = sourceAddress16; this.rssi = rssi; this.receiveOptions = receiveOptions; - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); + else + this.rfData = null; this.logger = LoggerFactory.getLogger(RX16Packet.class); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/raw/RX64IOPacket.java b/library/src/main/java/com/digi/xbee/api/packet/raw/RX64IOPacket.java index 578c9ef9..ad83dce5 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/raw/RX64IOPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/raw/RX64IOPacket.java @@ -134,7 +134,8 @@ public RX64IOPacket(XBee64BitAddress sourceAddress64, int rssi, int receiveOptio this.sourceAddress64 = sourceAddress64; this.rssi = rssi; this.receiveOptions = receiveOptions; - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); if (rfData != null && rfData.length >= 5) ioSample = new IOSample(rfData); else @@ -228,7 +229,7 @@ public IOSample getIOSample() { * * @param rfData Received RF data. */ - public void setRFData(byte[] rfData){ + public void setRFData(byte[] rfData) { if (rfData == null) this.rfData = null; else @@ -246,7 +247,7 @@ public void setRFData(byte[] rfData){ * * @return Received RF data. */ - public byte[] getRFData(){ + public byte[] getRFData() { if (rfData == null) return null; return Arrays.copyOf(rfData, rfData.length); @@ -267,10 +268,14 @@ public LinkedHashMap getAPIPacketParameters() { parameters.put("Digital channel mask", HexUtils.prettyHexString(HexUtils.integerToHexString(ioSample.getDigitalMask(), 2))); parameters.put("Analog channel mask", HexUtils.prettyHexString(HexUtils.integerToHexString(ioSample.getAnalogMask(), 2))); for (int i = 0; i < 16; i++) { + if (IOLine.getDIO(i) == null) + continue; if (ioSample.hasDigitalValue(IOLine.getDIO(i))) parameters.put(IOLine.getDIO(i).getName() + " digital value", ioSample.getDigitalValue(IOLine.getDIO(i)).getName()); } for (int i = 0; i < 6; i++) { + if (IOLine.getDIO(i) == null) + continue; if (ioSample.hasAnalogValue(IOLine.getDIO(i))) parameters.put(IOLine.getDIO(i).getName() + " analog value", HexUtils.prettyHexString(HexUtils.integerToHexString(ioSample.getAnalogValue(IOLine.getDIO(i)), 2))); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/raw/RX64Packet.java b/library/src/main/java/com/digi/xbee/api/packet/raw/RX64Packet.java index 41754c0e..ee2bb76e 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/raw/RX64Packet.java +++ b/library/src/main/java/com/digi/xbee/api/packet/raw/RX64Packet.java @@ -135,7 +135,10 @@ public RX64Packet(XBee64BitAddress sourceAddress64, int rssi, int receiveOptions this.sourceAddress64 = sourceAddress64; this.rssi = rssi; this.receiveOptions = receiveOptions; - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); + else + this.rfData = null; this.logger = LoggerFactory.getLogger(RX64Packet.class); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/raw/TX16Packet.java b/library/src/main/java/com/digi/xbee/api/packet/raw/TX16Packet.java index 75771e3e..21b8cdae 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/raw/TX16Packet.java +++ b/library/src/main/java/com/digi/xbee/api/packet/raw/TX16Packet.java @@ -129,7 +129,10 @@ public TX16Packet(int frameID, XBee16BitAddress destAddress16, int transmitOptio this.frameID = frameID; this.destAddress16 = destAddress16; this.transmitOptions = transmitOptions; - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); + else + this.rfData = null; this.logger = LoggerFactory.getLogger(TX16Packet.class); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/raw/TX64Packet.java b/library/src/main/java/com/digi/xbee/api/packet/raw/TX64Packet.java index c5ebabea..39877a78 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/raw/TX64Packet.java +++ b/library/src/main/java/com/digi/xbee/api/packet/raw/TX64Packet.java @@ -129,7 +129,10 @@ public TX64Packet(int frameID, XBee64BitAddress destAddress64, int transmitOptio this.frameID = frameID; this.destAddress64 = destAddress64; this.transmitOptions = transmitOptions; - this.rfData = rfData; + if (rfData != null) + this.rfData = rfData.clone(); + else + this.rfData = null; this.logger = LoggerFactory.getLogger(TX64Packet.class); } diff --git a/library/src/main/java/com/digi/xbee/api/packet/raw/TXStatusPacket.java b/library/src/main/java/com/digi/xbee/api/packet/raw/TXStatusPacket.java index 5ec3c6d4..d57cfa10 100644 --- a/library/src/main/java/com/digi/xbee/api/packet/raw/TXStatusPacket.java +++ b/library/src/main/java/com/digi/xbee/api/packet/raw/TXStatusPacket.java @@ -109,7 +109,7 @@ public TXStatusPacket(int frameID, XBeeTransmitStatus transmitStatus) { */ @Override protected byte[] getAPIPacketSpecificData() { - return new byte[] {(byte)transmitStatus.getId()}; + return new byte[] {(byte)transmitStatus.getID()}; } /* @@ -149,7 +149,7 @@ public boolean isBroadcast() { public LinkedHashMap getAPIPacketParameters() { LinkedHashMap parameters = new LinkedHashMap(); parameters.put("Status", - HexUtils.prettyHexString(HexUtils.integerToHexString(transmitStatus.getId(), 1)) + HexUtils.prettyHexString(HexUtils.integerToHexString(transmitStatus.getID(), 1)) + " (" + transmitStatus.getDescription() + ")"); return parameters; } diff --git a/library/src/main/java/com/digi/xbee/api/utils/ByteUtils.java b/library/src/main/java/com/digi/xbee/api/utils/ByteUtils.java index f3b204eb..e6e1d81d 100644 --- a/library/src/main/java/com/digi/xbee/api/utils/ByteUtils.java +++ b/library/src/main/java/com/digi/xbee/api/utils/ByteUtils.java @@ -230,40 +230,6 @@ public static short byteArrayToShort(byte[] byteArray) { | values[1] & 0x00FF); } - /** - * Converts the given string into a byte array. - * - * @param value String to convert to byte array. - * - * @return Byte array of the given string. - * - * @throws NullPointerException if {@code value == null}. - * - * @see #byteArrayToString(byte[]) - */ - public static byte[] stringToByteArray(String value) { - if (value == null) - throw new NullPointerException("Value cannot be null."); - - return value.getBytes(); - } - - /** - * Converts the given byte array into a string. - * - * @param value Byte array to convert to string. - * - * @return Converted String. - * - * @throws NullPointerException if {@code value == null}. - */ - public static String byteArrayToString(byte[] value) { - if (value == null) - throw new NullPointerException("Byte array cannot be null."); - - return new String(value); - } - /** * Converts the given byte into an integer. * @@ -293,7 +259,7 @@ public static boolean isBitEnabled(int containerInteger, int bitPosition) { if (bitPosition < 0 || bitPosition > 31) throw new IllegalArgumentException("Bit position must be between 0 and 31."); - return (((containerInteger & 0xFFFFFFFF) >> bitPosition) & 0x01) == 0x01; + return ((containerInteger >> bitPosition) & 0x01) == 0x01; } /** diff --git a/library/src/main/java/com/digi/xbee/api/utils/HexUtils.java b/library/src/main/java/com/digi/xbee/api/utils/HexUtils.java index 1ec33f39..52e42132 100644 --- a/library/src/main/java/com/digi/xbee/api/utils/HexUtils.java +++ b/library/src/main/java/com/digi/xbee/api/utils/HexUtils.java @@ -11,6 +11,8 @@ */ package com.digi.xbee.api.utils; +import java.util.Locale; + /** * Utility class containing methods to work with hexadecimal values and several * data type conversions. @@ -104,7 +106,7 @@ public static boolean containsLetters(String parameter) { if (parameter == null) throw new NullPointerException("Parameter cannot be null."); - byte[] byteArray = parameter.getBytes(); + byte[] byteArray = StringUtils.stringToByteArray(parameter); for (int i = 0; i < byteArray.length; i++){ if (!((byteArray[i] >= '0') && (byteArray[i] <= '9'))) return true; @@ -146,19 +148,19 @@ public static String prettyHexString(String hexString) { if (hexString == null) throw new NullPointerException("Hexadecimal string cannot be null."); - String copy = hexString.toUpperCase(); + String copy = hexString.toUpperCase(Locale.getDefault()); for (final char c : copy.toCharArray()) { if (!HEXES.contains(""+c)) throw new IllegalArgumentException("Given string cannot contain non-hexadecimal characters."); } - String prettyHexString = ""; + StringBuilder prettyHexString = new StringBuilder(); if (copy.length() % 2 != 0) copy = "0" + copy; int iterations = copy.length() / 2; for (int i = 0; i < iterations; i++) - prettyHexString += copy.substring(2 * i, 2 * i + 2) + " "; - return prettyHexString.trim(); + prettyHexString.append(copy.substring(2 * i, 2 * i + 2) + " "); + return prettyHexString.toString().trim(); } /** diff --git a/library/src/main/java/com/digi/xbee/api/utils/StringUtils.java b/library/src/main/java/com/digi/xbee/api/utils/StringUtils.java new file mode 100644 index 00000000..63cf7968 --- /dev/null +++ b/library/src/main/java/com/digi/xbee/api/utils/StringUtils.java @@ -0,0 +1,98 @@ +package com.digi.xbee.api.utils; + +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.util.Locale; + +public class StringUtils { + + // Constants. + private final static String UTF8_CHARSET = "UTF-8"; + + /** + * Transforms the given string to upper case format. + * + * @param source String to transform to upper case. + * + * @return The given string in upper case. + * + * @throws NullPointerException if {@code source == null}. + */ + public static String stringToUpperCase(String source) { + if (source == null) + throw new NullPointerException("String cannot be null."); + + return source.toUpperCase(new Locale(UTF8_CHARSET)); + } + + /** + * Transforms the given string to the corresponding byte array. + * + * @param source The {@code String} to transform to a byte array. + * + * @return The given string as a byte array. + * + * @throws NullPointerException if {@code source == null}. + * + * @see #byteArrayToString(byte[]) + * @see #byteArrayToString(byte[], int, int) + */ + public static byte[] stringToByteArray(String source) { + if (source == null) + throw new NullPointerException("Value cannot be null."); + + byte[] byteArray; + try { + byteArray = source.getBytes(UTF8_CHARSET); + } catch (UnsupportedEncodingException e) { + byteArray = source.getBytes(Charset.defaultCharset()); + } + return byteArray; + } + + /** + * Transforms the given byte array to its corresponding string. + * + * @param byteArray The byte array to transform to string. + * + * @return The given byte array as string. + * + * @throws NullPointerException if {@code byteArray == null}. + * + * @see #stringToByteArray(String) + * @see #byteArrayToString(byte[], int, int) + */ + public static String byteArrayToString(byte[] byteArray) { + if (byteArray == null) + throw new NullPointerException("Byte array cannot be null."); + return byteArrayToString(byteArray, 0, byteArray.length); + } + + /** + * Transforms the given byte array to its corresponding string using the + * given parameters. + * + * @param byteArray The byte array to transform to string. + * @param offset Offset in the array to start reading bytes. + * @param numBytes Number of bytes to read from the array. + * + * @return The given byte array as string. + * + * @throws NullPointerException if {@code byteArray == null}. + * + * @see #byteArrayToString(byte[]) + * @see #stringToByteArray(String) + */ + public static String byteArrayToString(byte[] byteArray, int offset, int numBytes) { + if (byteArray == null) + throw new NullPointerException("Byte array cannot be null."); + + String value; + try { + value = new String(byteArray, offset, numBytes, UTF8_CHARSET); + } catch (UnsupportedEncodingException e) { + value = new String(byteArray, offset, numBytes, Charset.defaultCharset()); + } + return value; + } +} diff --git a/library/src/test/java/com/digi/xbee/api/XBeeDeviceReadDataTest.java b/library/src/test/java/com/digi/xbee/api/XBeeDeviceReadDataTest.java index 6ff58d72..bdce9d8c 100644 --- a/library/src/test/java/com/digi/xbee/api/XBeeDeviceReadDataTest.java +++ b/library/src/test/java/com/digi/xbee/api/XBeeDeviceReadDataTest.java @@ -5,6 +5,8 @@ import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertThat; +import java.io.ByteArrayInputStream; + import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -45,6 +47,8 @@ public class XBeeDeviceReadDataTest { private SerialPortRxTx mockConnectionInterface; + private ByteArrayInputStream dummyInputStream; + //private DataReader mockDataReader; private XBeePacketsQueue mockXBeePacketsQueue; @@ -59,23 +63,26 @@ public void setUp() throws Exception { addr64 = new XBee64BitAddress("0013A20040A820DB"); addr16 = new XBee16BitAddress("9634"); receivedData = "Received data"; + dummyInputStream = new ByteArrayInputStream(new byte[8]); mockConnectionInterface = Mockito.mock(SerialPortRxTx.class); Mockito.doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) throws Exception { - Mockito.when(mockConnectionInterface.isOpen()).thenReturn(true); + Mockito.doReturn(true).when(mockConnectionInterface).isOpen(); return null; } }).when(mockConnectionInterface).open(); Mockito.doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) throws Exception { - Mockito.when(mockConnectionInterface.isOpen()).thenReturn(false); + Mockito.doReturn(false).when(mockConnectionInterface).isOpen(); return null; } }).when(mockConnectionInterface).close(); + Mockito.doReturn(dummyInputStream).when(mockConnectionInterface).getInputStream(); + mockXBeePacketsQueue = Mockito.mock(XBeePacketsQueue.class); Mockito.doAnswer(new Answer() { @@ -114,7 +121,7 @@ public void tearDown() throws Exception { @Test public final void testReadDataInterfaceNotOpenException() { // Setup the resources for the test. - Mockito.when(xbeeDevice.isOpen()).thenReturn(false); + Mockito.doReturn(false).when(xbeeDevice).isOpen(); exception.expect(InterfaceNotOpenException.class); exception.expectMessage(is(equalTo("The connection interface is not open."))); @@ -131,7 +138,7 @@ public final void testReadDataInterfaceNotOpenException() { @Test public final void testReadData() throws Exception { // Setup the resources for the test. - + assertThat("Network should be empty", xbeeDevice.getNetwork().getNumberOfDevices(), is(equalTo(0))); // Call the method under test. @@ -321,7 +328,7 @@ public final void testReadDataFromTimeout() throws Exception { @Test public final void testReadDataPacketInterfaceNotOpenException() throws Exception { // Setup the resources for the test. - Mockito.when(xbeeDevice.isOpen()).thenReturn(false); + Mockito.doReturn(false).when(xbeeDevice).isOpen(); exception.expect(InterfaceNotOpenException.class); exception.expectMessage(is(equalTo("The connection interface is not open."))); diff --git a/library/src/test/java/com/digi/xbee/api/XBeeNetworkDiscoverDevicesListenerTest.java b/library/src/test/java/com/digi/xbee/api/XBeeNetworkDiscoverDevicesListenerTest.java index ec2b1abe..0eb1c214 100644 --- a/library/src/test/java/com/digi/xbee/api/XBeeNetworkDiscoverDevicesListenerTest.java +++ b/library/src/test/java/com/digi/xbee/api/XBeeNetworkDiscoverDevicesListenerTest.java @@ -35,7 +35,7 @@ public class XBeeNetworkDiscoverDevicesListenerTest { @Rule - public ExpectedException exception = ExpectedException.none(); + private ExpectedException exception = ExpectedException.none(); // Variables. private XBeeNetwork network; diff --git a/library/src/test/java/com/digi/xbee/api/listeners/IDataReceiveListenerXBeeTest.java b/library/src/test/java/com/digi/xbee/api/listeners/IDataReceiveListenerXBeeTest.java index b3b3c754..d31ed7e1 100644 --- a/library/src/test/java/com/digi/xbee/api/listeners/IDataReceiveListenerXBeeTest.java +++ b/library/src/test/java/com/digi/xbee/api/listeners/IDataReceiveListenerXBeeTest.java @@ -81,8 +81,8 @@ public static void setupOnce() throws Exception { explicitPacket = Mockito.mock(ExplicitRxIndicatorPacket.class); Mockito.when(explicitPacket.getFrameType()).thenReturn(APIFrameType.EXPLICIT_RX_INDICATOR); Mockito.when(explicitPacket.getRFData()).thenReturn(RECEIVED_DATA_BYTES); - Mockito.when(explicitPacket.get64BitSourceAddress()).thenReturn(XBEE_64BIT_ADDRESS); - Mockito.when(explicitPacket.get16BitSourceAddress()).thenReturn(XBee16BitAddress.UNKNOWN_ADDRESS); + Mockito.when(explicitPacket.get64bitSourceAddress()).thenReturn(XBEE_64BIT_ADDRESS); + Mockito.when(explicitPacket.get16bitSourceAddress()).thenReturn(XBee16BitAddress.UNKNOWN_ADDRESS); Mockito.when(explicitPacket.isBroadcast()).thenReturn(false); // Mock an invalid packet. diff --git a/library/src/test/java/com/digi/xbee/api/listeners/IExplicitDataReceiveListenerTest.java b/library/src/test/java/com/digi/xbee/api/listeners/IExplicitDataReceiveListenerTest.java index 18b4b23e..e775bbff 100644 --- a/library/src/test/java/com/digi/xbee/api/listeners/IExplicitDataReceiveListenerTest.java +++ b/library/src/test/java/com/digi/xbee/api/listeners/IExplicitDataReceiveListenerTest.java @@ -75,7 +75,7 @@ public static void setupOnce() throws Exception { // Mock Explicit Data Packet. explicitDataPacket = Mockito.mock(ExplicitRxIndicatorPacket.class); Mockito.when(explicitDataPacket.getFrameType()).thenReturn(APIFrameType.EXPLICIT_RX_INDICATOR); - Mockito.when(explicitDataPacket.get64BitSourceAddress()).thenReturn(XBEE_64BIT_ADDRESS); + Mockito.when(explicitDataPacket.get64bitSourceAddress()).thenReturn(XBEE_64BIT_ADDRESS); Mockito.when(explicitDataPacket.getSourceEndpoint()).thenReturn(RECEIVED_SOURCE_ENDPOINT); Mockito.when(explicitDataPacket.getDestinationEndpoint()).thenReturn(RECEIVED_DESTINATION_ENDPOINT); Mockito.when(explicitDataPacket.getClusterID()).thenReturn(RECEIVED_CLUSTER_ID); diff --git a/library/src/test/java/com/digi/xbee/api/models/ModemStatusEventTest.java b/library/src/test/java/com/digi/xbee/api/models/ModemStatusEventTest.java index 5485b9b4..1e28557d 100644 --- a/library/src/test/java/com/digi/xbee/api/models/ModemStatusEventTest.java +++ b/library/src/test/java/com/digi/xbee/api/models/ModemStatusEventTest.java @@ -29,14 +29,14 @@ public void setup() { } /** - * Test method for {@link com.digi.xbee.api.models.ModemStatusEvent#getId()}. + * Test method for {@link com.digi.xbee.api.models.ModemStatusEvent#getID()}. * *

Verify that the ID of each ModemStatusEvent entry is valid.

*/ @Test public void testModemStatusEventValues() { for (ModemStatusEvent modemStatusEvent:modemStatusEventValues) - assertTrue(modemStatusEvent.getId() >= 0); + assertTrue(modemStatusEvent.getID() >= 0); } /** @@ -74,7 +74,7 @@ public void testModemStatusEventDescriptions() { @Test public void testModemStatusEventStaticAccess() { for (ModemStatusEvent modemStatusEvent:modemStatusEventValues) - assertEquals(modemStatusEvent, ModemStatusEvent.get(modemStatusEvent.getId())); + assertEquals(modemStatusEvent, ModemStatusEvent.get(modemStatusEvent.getID())); } /** @@ -86,6 +86,6 @@ public void testModemStatusEventStaticAccess() { @Test public void testModemStatusEventToString() { for (ModemStatusEvent modemStatusEvent:modemStatusEventValues) - assertEquals(String.format("0x%02X: %s", modemStatusEvent.getId(), modemStatusEvent.getDescription()), modemStatusEvent.toString()); + assertEquals(String.format("0x%02X: %s", modemStatusEvent.getID(), modemStatusEvent.getDescription()), modemStatusEvent.toString()); } } diff --git a/library/src/test/java/com/digi/xbee/api/models/XBee64BitAddressTest.java b/library/src/test/java/com/digi/xbee/api/models/XBee64BitAddressTest.java index c3035721..121b17d4 100644 --- a/library/src/test/java/com/digi/xbee/api/models/XBee64BitAddressTest.java +++ b/library/src/test/java/com/digi/xbee/api/models/XBee64BitAddressTest.java @@ -204,13 +204,8 @@ public void testCreateWithInvalidParameters() { */ public void testCreateWithValidByteNumbers() { // Test with valid byte number values. - XBee64BitAddress address = null; - try { - address = new XBee64BitAddress(VALID_BYTE_ARRAY[0] & 0xFF, VALID_BYTE_ARRAY[1] & 0xFF, VALID_BYTE_ARRAY[2] & 0xFF, VALID_BYTE_ARRAY[3] & 0xFF, + XBee64BitAddress address = new XBee64BitAddress(VALID_BYTE_ARRAY[0] & 0xFF, VALID_BYTE_ARRAY[1] & 0xFF, VALID_BYTE_ARRAY[2] & 0xFF, VALID_BYTE_ARRAY[3] & 0xFF, (int)VALID_BYTE_ARRAY[4] & 0xFF, VALID_BYTE_ARRAY[5] & 0xFF, VALID_BYTE_ARRAY[6] & 0xFF, VALID_BYTE_ARRAY[7] & 0xFF); - } catch (Exception e) { - fail("This exception should have not been thrown."); - } assertArrayEquals(VALID_BYTE_ARRAY, address.getValue()); assertEquals(VALID_STRING_NO_PREFIX, address.toString()); diff --git a/library/src/test/java/com/digi/xbee/api/models/XBeeDiscoveryStatusTest.java b/library/src/test/java/com/digi/xbee/api/models/XBeeDiscoveryStatusTest.java index 31f276d5..c21d8278 100644 --- a/library/src/test/java/com/digi/xbee/api/models/XBeeDiscoveryStatusTest.java +++ b/library/src/test/java/com/digi/xbee/api/models/XBeeDiscoveryStatusTest.java @@ -63,13 +63,13 @@ public void tearDown() throws Exception { public void testGetWithASupportedValue() { // Setup the resources for the test. XBeeDiscoveryStatus expectedStatus = XBeeDiscoveryStatus.DISCOVERY_STATUS_EXTENDED_TIMEOUT_DISCOVERY; - int id = expectedStatus.getId(); + int id = expectedStatus.getID(); // Call the method under test. XBeeDiscoveryStatus status = XBeeDiscoveryStatus.get(id); // Verify the result. - assertThat("The identifier of both status does not have the same value", status.getId(), is(equalTo(id))); + assertThat("The identifier of both status does not have the same value", status.getID(), is(equalTo(id))); assertThat("Transmit status is not the expected", status, is(equalTo(expectedStatus))); } @@ -86,7 +86,7 @@ public void testGetWithANonSupportedValue() { XBeeDiscoveryStatus status = XBeeDiscoveryStatus.get(id); // Verify the result. - assertThat("The identifier of both status does not have the same value", status.getId(), is(equalTo(expectedStatus.getId()))); + assertThat("The identifier of both status does not have the same value", status.getID(), is(equalTo(expectedStatus.getID()))); assertThat("The description of both status does not have the same value", status.getDescription(), is(equalTo(expectedStatus.getDescription()))); assertThat("Transmit status is not the expected", status, is(equalTo(expectedStatus))); } @@ -99,7 +99,7 @@ public void testGetWithANonSupportedValue() { @Test public void testXBeeDiscoveryStatusValues() { for (XBeeDiscoveryStatus status: discoveryStatusValues) - assertTrue(status.getId() >= 0); + assertTrue(status.getID() >= 0); } /** @@ -137,6 +137,6 @@ public void testXBeeDiscoveryStatusDescriptions() { @Test public void testXBeeDiscoveryStatusStaticAccess() { for (XBeeDiscoveryStatus status: discoveryStatusValues) - assertEquals(status, XBeeDiscoveryStatus.get(status.getId())); + assertEquals(status, XBeeDiscoveryStatus.get(status.getID())); } } diff --git a/library/src/test/java/com/digi/xbee/api/models/XBeePacketsQueueTest.java b/library/src/test/java/com/digi/xbee/api/models/XBeePacketsQueueTest.java index 5d32c0a1..f5fe11b4 100644 --- a/library/src/test/java/com/digi/xbee/api/models/XBeePacketsQueueTest.java +++ b/library/src/test/java/com/digi/xbee/api/models/XBeePacketsQueueTest.java @@ -259,7 +259,7 @@ public void testGetFirstPacketFrom() { // Add 2 additional packets from different senders. Mockito.when(mockedRxIO64Packet.get64bitSourceAddress()).thenReturn(xbee64BitAddress2); xbeePacketsQueue.addPacket(mockedRxIO64Packet); - Mockito.when(mockedExplicitRxIndicatorPacket.get64BitSourceAddress()).thenReturn(xbee64BitAddress3); + Mockito.when(mockedExplicitRxIndicatorPacket.get64bitSourceAddress()).thenReturn(xbee64BitAddress3); xbeePacketsQueue.addPacket(mockedExplicitRxIndicatorPacket); // Request the first packet from the queue sent by the mocked remote device and @@ -335,7 +335,7 @@ public void testGetFirstDataPacketFrom() { // Add additional (non-data) packets from the same sender. Mockito.when(mockedRxIO64Packet.get64bitSourceAddress()).thenReturn(xbee64BitAddress1); xbeePacketsQueue.addPacket(mockedRxIO64Packet); - Mockito.when(mockedExplicitRxIndicatorPacket.get64BitSourceAddress()).thenReturn(xbee64BitAddress1); + Mockito.when(mockedExplicitRxIndicatorPacket.get64bitSourceAddress()).thenReturn(xbee64BitAddress1); xbeePacketsQueue.addPacket(mockedExplicitRxIndicatorPacket); // Request the first data packet from the queue sent by the mocked remote device and @@ -407,7 +407,7 @@ public void testGetFirstExplicitDataPacketFrom() { xbeePacketsQueue.addPacket(Mockito.mock(XBeePacket.class)); // Add an explicit data packet from the mocked 64-bit address. - Mockito.when(mockedExplicitRxIndicatorPacket.get64BitSourceAddress()).thenReturn(xbee64BitAddress1); + Mockito.when(mockedExplicitRxIndicatorPacket.get64bitSourceAddress()).thenReturn(xbee64BitAddress1); xbeePacketsQueue.addPacket(mockedExplicitRxIndicatorPacket); // Add a data packet from the mocked 64-bit address. diff --git a/library/src/test/java/com/digi/xbee/api/models/XBeeProtocolTest.java b/library/src/test/java/com/digi/xbee/api/models/XBeeProtocolTest.java index 5760a542..7b68511e 100644 --- a/library/src/test/java/com/digi/xbee/api/models/XBeeProtocolTest.java +++ b/library/src/test/java/com/digi/xbee/api/models/XBeeProtocolTest.java @@ -200,8 +200,9 @@ public void testDetermineProtocol() throws FileNotFoundException { // Generate the list of firmware entries from the firmware_entries_xctu.txt file. File firmwareEntriesFile = new File(getClass().getResource(FILE_FIRMWARE_ENTRIES).getFile()); - BufferedReader reader = new BufferedReader(new FileReader(firmwareEntriesFile.getAbsolutePath())); + BufferedReader reader = null; try { + reader = new BufferedReader(new FileReader(firmwareEntriesFile.getAbsolutePath())); String line = reader.readLine(); while (line != null) { // Skip empty lines. @@ -229,9 +230,13 @@ public void testDetermineProtocol() throws FileNotFoundException { line = reader.readLine(); } } catch (IOException e) { - try { - reader.close(); - } catch (IOException e1) { } + e.printStackTrace(); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e1) { } + } } // Verify that the determineProtocol method is able to determine the protocol of all the firmware entries of the list. diff --git a/library/src/test/java/com/digi/xbee/api/models/XBeeTransmitStatusTest.java b/library/src/test/java/com/digi/xbee/api/models/XBeeTransmitStatusTest.java index 3267bd80..62ab63fb 100644 --- a/library/src/test/java/com/digi/xbee/api/models/XBeeTransmitStatusTest.java +++ b/library/src/test/java/com/digi/xbee/api/models/XBeeTransmitStatusTest.java @@ -63,13 +63,13 @@ public void tearDown() throws Exception { public void testGetWithASupportedValue() { // Setup the resources for the test. XBeeTransmitStatus expectedStatus = XBeeTransmitStatus.ADDRESS_NOT_FOUND; - int id = expectedStatus.getId(); + int id = expectedStatus.getID(); // Call the method under test. XBeeTransmitStatus status = XBeeTransmitStatus.get(id); // Verify the result. - assertThat("The identifier of both status does not have the same value", status.getId(), is(equalTo(id))); + assertThat("The identifier of both status does not have the same value", status.getID(), is(equalTo(id))); assertThat("Transmit status is not the expected", status, is(equalTo(expectedStatus))); } @@ -86,7 +86,7 @@ public void testGetWithANonSupportedValue() { XBeeTransmitStatus status = XBeeTransmitStatus.get(id); // Verify the result. - assertThat("The identifier of both status does not have the same value", status.getId(), is(equalTo(expectedStatus.getId()))); + assertThat("The identifier of both status does not have the same value", status.getID(), is(equalTo(expectedStatus.getID()))); assertThat("The description of both status does not have the same value", status.getDescription(), is(equalTo(expectedStatus.getDescription()))); assertThat("Transmit status is not the expected", status, is(equalTo(expectedStatus))); } @@ -99,7 +99,7 @@ public void testGetWithANonSupportedValue() { @Test public void testXBeeTransmitStatusValues() { for (XBeeTransmitStatus status: transmitStatusValues) - assertTrue(status.getId() >= 0 || status.getId() == -1); + assertTrue(status.getID() >= 0 || status.getID() == -1); } /** @@ -137,6 +137,6 @@ public void testXBeeTransmitStatusDescriptions() { @Test public void testXBeeTransmitStatusStaticAccess() { for (XBeeTransmitStatus status: transmitStatusValues) - assertEquals(status, XBeeTransmitStatus.get(status.getId())); + assertEquals(status, XBeeTransmitStatus.get(status.getID())); } } diff --git a/library/src/test/java/com/digi/xbee/api/packet/common/ATCommandResponsePacketTest.java b/library/src/test/java/com/digi/xbee/api/packet/common/ATCommandResponsePacketTest.java index dfca9381..25a3a8d3 100644 --- a/library/src/test/java/com/digi/xbee/api/packet/common/ATCommandResponsePacketTest.java +++ b/library/src/test/java/com/digi/xbee/api/packet/common/ATCommandResponsePacketTest.java @@ -113,7 +113,7 @@ public final void testCreatePacketPayloadShorterThanNeeded() { int frameType = APIFrameType.AT_COMMAND_RESPONSE.getValue(); //int frameID = 0xE7; byte[] atCommand = "NI".getBytes(); - int status = ATCommandStatus.OK.getId(); + int status = ATCommandStatus.OK.getID(); byte[] payload = new byte[2 + atCommand.length]; payload[0] = (byte)frameType; @@ -139,7 +139,7 @@ public final void testCreatePacketPayloadNotIncludingFrameType() { // Setup the resources for the test. int frameID = 0xE7; byte[] atCommand = "NI".getBytes(); - int status = ATCommandStatus.OK.getId(); + int status = ATCommandStatus.OK.getID(); byte[] data = new byte[]{0x68, 0x6F, 0x6C, 0x61}; byte[] payload = new byte[2 + atCommand.length + data.length]; @@ -167,7 +167,7 @@ public final void testCreatePacketValidPayloadWithoutData() { int frameType = APIFrameType.AT_COMMAND_RESPONSE.getValue(); int frameID = 0xE7; byte[] atCommand = "NI".getBytes(); - int status = ATCommandStatus.OK.getId(); + int status = ATCommandStatus.OK.getID(); byte[] payload = new byte[3 + atCommand.length]; payload[0] = (byte)frameType; @@ -233,7 +233,7 @@ public final void testCreatePacketValidPayloadWithData() { int frameType = APIFrameType.AT_COMMAND_RESPONSE.getValue(); int frameID = 0xE7; byte[] atCommand = "NI".getBytes(); - int status = ATCommandStatus.OK.getId(); + int status = ATCommandStatus.OK.getID(); byte[] value = new byte[]{0x68, 0x6F, 0x6C, 0x61}; byte[] payload = new byte[3 + atCommand.length + value.length]; @@ -505,7 +505,7 @@ public final void testGetAPIDataATCommandParameterNull() { byte[] expectedData = new byte[expectedLength]; expectedData[0] = (byte)frameID; System.arraycopy(command.getBytes(), 0, expectedData, 1, command.length()); - expectedData[1 + command.length()] = (byte)status.getId(); + expectedData[1 + command.length()] = (byte)status.getID(); // Call the method under test. byte[] data = packet.getAPIData(); @@ -563,7 +563,7 @@ public final void testGetAPIDataATCommandParameterNotNull() { byte[] expectedData = new byte[expectedLength]; expectedData[0] = (byte)frameID; System.arraycopy(command.getBytes(), 0, expectedData, 1, command.length()); - expectedData[1 + command.length()] = (byte)status.getId(); + expectedData[1 + command.length()] = (byte)status.getID(); System.arraycopy(parameter, 0, expectedData, 2 + command.length(), parameter.length); // Call the method under test. @@ -621,7 +621,7 @@ public final void testGetAPIPacketParametersATCommandParameterNull() { ATCommandResponsePacket packet = new ATCommandResponsePacket(frameID, status, command, parameter); String expectedATCommand = HexUtils.prettyHexString(command.getBytes()) + " (" + command + ")"; - String expectedStatus = Integer.toHexString(status.getId()).toUpperCase() + " (" + status.getDescription() + ")"; + String expectedStatus = Integer.toHexString(status.getID()).toUpperCase() + " (" + status.getDescription() + ")"; // Call the method under test. LinkedHashMap packetParams = packet.getAPIPacketParameters(); @@ -683,7 +683,7 @@ public final void testGetAPIPacketParametersATCommandParameterNotNull() { ATCommandResponsePacket packet = new ATCommandResponsePacket(frameID, status, command, parameter); String expectedATCommand = HexUtils.prettyHexString(command.getBytes()) + " (" + command + ")"; - String expectedStatus = Integer.toHexString(status.getId()).toUpperCase() + " (" + status.getDescription() + ")"; + String expectedStatus = Integer.toHexString(status.getID()).toUpperCase() + " (" + status.getDescription() + ")"; String expectedATParameter = HexUtils.prettyHexString(parameter) + " (" + new String(parameter) + ")"; // Call the method under test. @@ -711,7 +711,7 @@ public final void testGetAPIPacketParametersATCommandParameterNotNullNonStringCm ATCommandResponsePacket packet = new ATCommandResponsePacket(frameID, status, command, parameter); String expectedATCommand = HexUtils.prettyHexString(command.getBytes()) + " (" + command + ")"; - String expectedStatus = Integer.toHexString(status.getId()).toUpperCase() + " (" + status.getDescription() + ")"; + String expectedStatus = Integer.toHexString(status.getID()).toUpperCase() + " (" + status.getDescription() + ")"; String expectedATParameter = HexUtils.prettyHexString(parameter); // Call the method under test. diff --git a/library/src/test/java/com/digi/xbee/api/packet/common/ExplicitAddressingPacketTest.java b/library/src/test/java/com/digi/xbee/api/packet/common/ExplicitAddressingPacketTest.java index 54bb3478..6d77a946 100644 --- a/library/src/test/java/com/digi/xbee/api/packet/common/ExplicitAddressingPacketTest.java +++ b/library/src/test/java/com/digi/xbee/api/packet/common/ExplicitAddressingPacketTest.java @@ -226,8 +226,8 @@ public final void testCreatePacketValidPayloadWithoutData() { // Verify the result. assertThat("Returned length is not the expected one", packet.getPacketLength(), is(equalTo(payload.length))); assertThat("Frame ID is not the expected one", packet.getFrameID(), is(equalTo(frameID))); - assertThat("Returned destination 64-bit address is not the expected one", packet.get64BitDestinationAddress(), is(equalTo(dest64Addr))); - assertThat("Returned destination 16-bit address is not the expected one", packet.get16BitDestinationAddress(), is(equalTo(dest16Addr))); + assertThat("Returned destination 64-bit address is not the expected one", packet.get64bitDestinationAddress(), is(equalTo(dest64Addr))); + assertThat("Returned destination 16-bit address is not the expected one", packet.get16bitDestinationAddress(), is(equalTo(dest16Addr))); assertThat("Returned source endpoint is not the expected one", packet.getSourceEndpoint(), is(equalTo(sourceEndpoint))); assertThat("Returned destination endpoint is not the expected one", packet.getDestinationEndpoint(), is(equalTo(destEndpoint))); assertThat("Returned cluster ID is not the expected one", packet.getClusterID(), is(equalTo(clusterID))); @@ -281,8 +281,8 @@ public final void testCreatePacketValidPayloadWithData() { // Verify the result. assertThat("Returned length is not the expected one", packet.getPacketLength(), is(equalTo(payload.length))); assertThat("Frame ID is not the expected one", packet.getFrameID(), is(equalTo(frameID))); - assertThat("Returned destination 64-bit address is not the expected one", packet.get64BitDestinationAddress(), is(equalTo(dest64Addr))); - assertThat("Returned destination 16-bit address is not the expected one", packet.get16BitDestinationAddress(), is(equalTo(dest16Addr))); + assertThat("Returned destination 64-bit address is not the expected one", packet.get64bitDestinationAddress(), is(equalTo(dest64Addr))); + assertThat("Returned destination 16-bit address is not the expected one", packet.get16bitDestinationAddress(), is(equalTo(dest16Addr))); assertThat("Returned source endpoint is not the expected one", packet.getSourceEndpoint(), is(equalTo(sourceEndpoint))); assertThat("Returned destination endpoint is not the expected one", packet.getDestinationEndpoint(), is(equalTo(destEndpoint))); assertThat("Returned cluster ID is not the expected one", packet.getClusterID(), is(equalTo(clusterID))); @@ -757,8 +757,8 @@ public final void testCreateExplicitAddressingPacketValidWithData() { // Verify the result. assertThat("Returned length is not the expected one", packet.getPacketLength(), is(equalTo(expectedLength))); assertThat("Frame ID is not the expected one", packet.getFrameID(), is(equalTo(frameID))); - assertThat("Returned destination 64-bit address is not the expected one", packet.get64BitDestinationAddress(), is(equalTo(dest64Addr))); - assertThat("Returned destination 16-bit address is not the expected one", packet.get16BitDestinationAddress(), is(equalTo(dest16Addr))); + assertThat("Returned destination 64-bit address is not the expected one", packet.get64bitDestinationAddress(), is(equalTo(dest64Addr))); + assertThat("Returned destination 16-bit address is not the expected one", packet.get16bitDestinationAddress(), is(equalTo(dest16Addr))); assertThat("Returned source endpoint is not the expected one", packet.getSourceEndpoint(), is(equalTo(sourceEndpoint))); assertThat("Returned destination endpoint is not the expected one", packet.getDestinationEndpoint(), is(equalTo(destEndpoint))); assertThat("Returned cluster ID is not the expected one", packet.getClusterID(), is(equalTo(clusterID))); @@ -797,8 +797,8 @@ public final void testCreateExplicitAddressingPacketValidWithoutData() { // Verify the result. assertThat("Returned length is not the expected one", packet.getPacketLength(), is(equalTo(expectedLength))); assertThat("Frame ID is not the expected one", packet.getFrameID(), is(equalTo(frameID))); - assertThat("Returned destination 64-bit address is not the expected one", packet.get64BitDestinationAddress(), is(equalTo(dest64Addr))); - assertThat("Returned destination 16-bit address is not the expected one", packet.get16BitDestinationAddress(), is(equalTo(dest16Addr))); + assertThat("Returned destination 64-bit address is not the expected one", packet.get64bitDestinationAddress(), is(equalTo(dest64Addr))); + assertThat("Returned destination 16-bit address is not the expected one", packet.get16bitDestinationAddress(), is(equalTo(dest16Addr))); assertThat("Returned source endpoint is not the expected one", packet.getSourceEndpoint(), is(equalTo(sourceEndpoint))); assertThat("Returned destination endpoint is not the expected one", packet.getDestinationEndpoint(), is(equalTo(destEndpoint))); assertThat("Returned cluster ID is not the expected one", packet.getClusterID(), is(equalTo(clusterID))); diff --git a/library/src/test/java/com/digi/xbee/api/packet/common/ExplicitRxIndicatorPacketTest.java b/library/src/test/java/com/digi/xbee/api/packet/common/ExplicitRxIndicatorPacketTest.java index 3e1131f6..2bfaa8b4 100644 --- a/library/src/test/java/com/digi/xbee/api/packet/common/ExplicitRxIndicatorPacketTest.java +++ b/library/src/test/java/com/digi/xbee/api/packet/common/ExplicitRxIndicatorPacketTest.java @@ -212,8 +212,8 @@ public final void testCreatePacketValidPayloadWithoutData() { // Verify the result. assertThat("Returned length is not the expected one", packet.getPacketLength(), is(equalTo(payload.length))); - assertThat("Returned source 64-bit address is not the expected one", packet.get64BitSourceAddress(), is(equalTo(source64Addr))); - assertThat("Returned source 16-bit address is not the expected one", packet.get16BitSourceAddress(), is(equalTo(source16Addr))); + assertThat("Returned source 64-bit address is not the expected one", packet.get64bitSourceAddress(), is(equalTo(source64Addr))); + assertThat("Returned source 16-bit address is not the expected one", packet.get16bitSourceAddress(), is(equalTo(source16Addr))); assertThat("Returned source endpoint is not the expected one", packet.getSourceEndpoint(), is(equalTo(sourceEndpoint))); assertThat("Returned destination endpoint is not the expected one", packet.getDestinationEndpoint(), is(equalTo(destEndpoint))); assertThat("Returned cluster ID is not the expected one", packet.getClusterID(), is(equalTo(clusterID))); @@ -261,8 +261,8 @@ public final void testCreatePacketValidPayloadWithData() { // Verify the result. assertThat("Returned length is not the expected one", packet.getPacketLength(), is(equalTo(payload.length))); - assertThat("Returned source 64-bit address is not the expected one", packet.get64BitSourceAddress(), is(equalTo(source64Addr))); - assertThat("Returned source 16-bit address is not the expected one", packet.get16BitSourceAddress(), is(equalTo(source16Addr))); + assertThat("Returned source 64-bit address is not the expected one", packet.get64bitSourceAddress(), is(equalTo(source64Addr))); + assertThat("Returned source 16-bit address is not the expected one", packet.get16bitSourceAddress(), is(equalTo(source16Addr))); assertThat("Returned source endpoint is not the expected one", packet.getSourceEndpoint(), is(equalTo(sourceEndpoint))); assertThat("Returned destination endpoint is not the expected one", packet.getDestinationEndpoint(), is(equalTo(destEndpoint))); assertThat("Returned cluster ID is not the expected one", packet.getClusterID(), is(equalTo(clusterID))); @@ -599,8 +599,8 @@ public final void testCreateExplicitRxIndicatorPacketValidWithData() { // Verify the result. assertThat("Returned length is not the expected one", packet.getPacketLength(), is(equalTo(expectedLength))); - assertThat("Returned source 64-bit address is not the expected one", packet.get64BitSourceAddress(), is(equalTo(source64Addr))); - assertThat("Returned source 16-bit address is not the expected one", packet.get16BitSourceAddress(), is(equalTo(source16Addr))); + assertThat("Returned source 64-bit address is not the expected one", packet.get64bitSourceAddress(), is(equalTo(source64Addr))); + assertThat("Returned source 16-bit address is not the expected one", packet.get16bitSourceAddress(), is(equalTo(source16Addr))); assertThat("Returned source endpoint is not the expected one", packet.getSourceEndpoint(), is(equalTo(sourceEndpoint))); assertThat("Returned destination endpoint is not the expected one", packet.getDestinationEndpoint(), is(equalTo(destEndpoint))); assertThat("Returned cluster ID is not the expected one", packet.getClusterID(), is(equalTo(clusterID))); @@ -635,8 +635,8 @@ public final void testCreateExplicitRxIndicatorPacketValidWithoutData() { // Verify the result. assertThat("Returned length is not the expected one", packet.getPacketLength(), is(equalTo(expectedLength))); - assertThat("Returned source 64-bit address is not the expected one", packet.get64BitSourceAddress(), is(equalTo(source64Addr))); - assertThat("Returned source 16-bit address is not the expected one", packet.get16BitSourceAddress(), is(equalTo(source16Addr))); + assertThat("Returned source 64-bit address is not the expected one", packet.get64bitSourceAddress(), is(equalTo(source64Addr))); + assertThat("Returned source 16-bit address is not the expected one", packet.get16bitSourceAddress(), is(equalTo(source16Addr))); assertThat("Returned source endpoint is not the expected one", packet.getSourceEndpoint(), is(equalTo(sourceEndpoint))); assertThat("Returned destination endpoint is not the expected one", packet.getDestinationEndpoint(), is(equalTo(destEndpoint))); assertThat("Returned cluster ID is not the expected one", packet.getClusterID(), is(equalTo(clusterID))); diff --git a/library/src/test/java/com/digi/xbee/api/packet/common/ModemStatusPacketTest.java b/library/src/test/java/com/digi/xbee/api/packet/common/ModemStatusPacketTest.java index dd729e0c..0ce8e3f2 100644 --- a/library/src/test/java/com/digi/xbee/api/packet/common/ModemStatusPacketTest.java +++ b/library/src/test/java/com/digi/xbee/api/packet/common/ModemStatusPacketTest.java @@ -136,7 +136,7 @@ public final void testCreatePacketPayloadInvalidFrameType() { byte[] payload = new byte[2]; payload[0] = (byte)frameType; - payload[1] = (byte)modemStatusEvent.getId(); + payload[1] = (byte)modemStatusEvent.getID(); exception.expect(IllegalArgumentException.class); exception.expectMessage(is(equalTo("Payload is not a Modem Status packet."))); @@ -158,7 +158,7 @@ public final void testCreatePacketValidPayload() { byte[] payload = new byte[2]; payload[0] = (byte)frameType; - payload[1] = (byte)modemStatusEvent.getId(); + payload[1] = (byte)modemStatusEvent.getID(); // Call the method under test. ModemStatusPacket packet = ModemStatusPacket.createPacket(payload); @@ -220,7 +220,7 @@ public final void testGetAPIData() { int expectedLength = 1 /* Modem status */; byte[] expectedData = new byte[expectedLength]; - expectedData[0] = (byte)modemStatusEvent.getId(); + expectedData[0] = (byte)modemStatusEvent.getID(); // Call the method under test. byte[] data = packet.getAPIData(); @@ -240,7 +240,7 @@ public final void testGetAPIPacketParameters() { ModemStatusEvent modemStatusEvent = ModemStatusEvent.STATUS_JOINED_NETWORK; ModemStatusPacket packet = new ModemStatusPacket(modemStatusEvent); - String expectedModemStatus = HexUtils.integerToHexString(modemStatusEvent.getId(), 1) + " (" + modemStatusEvent.getDescription() + ")"; + String expectedModemStatus = HexUtils.integerToHexString(modemStatusEvent.getID(), 1) + " (" + modemStatusEvent.getDescription() + ")"; // Call the method under test. LinkedHashMap packetParams = packet.getAPIPacketParameters(); diff --git a/library/src/test/java/com/digi/xbee/api/packet/common/RemoteATCommandResponsePacketTest.java b/library/src/test/java/com/digi/xbee/api/packet/common/RemoteATCommandResponsePacketTest.java index 659badb3..d3b62412 100644 --- a/library/src/test/java/com/digi/xbee/api/packet/common/RemoteATCommandResponsePacketTest.java +++ b/library/src/test/java/com/digi/xbee/api/packet/common/RemoteATCommandResponsePacketTest.java @@ -117,7 +117,7 @@ public final void testCreatePacketPayloadShorterThanNeeded() { XBee64BitAddress source64Addr = new XBee64BitAddress("0013A2004032D9AB"); XBee16BitAddress source16Addr = new XBee16BitAddress("B45C"); byte[] atCommand = "NI".getBytes(); - int status = ATCommandStatus.OK.getId(); + int status = ATCommandStatus.OK.getID(); byte[] payload = new byte[12 + atCommand.length]; payload[0] = (byte)frameType; @@ -147,7 +147,7 @@ public final void testCreatePacketPayloadNotIncludingFrameType() { XBee64BitAddress source64Addr = new XBee64BitAddress("0013A2004032D9AB"); XBee16BitAddress source16Addr = new XBee16BitAddress("B45C"); byte[] atCommand = "NI".getBytes(); - int status = ATCommandStatus.OK.getId(); + int status = ATCommandStatus.OK.getID(); byte[] data = new byte[]{0x68, 0x6F, 0x6C, 0x61}; byte[] payload = new byte[12 + atCommand.length + data.length]; @@ -179,7 +179,7 @@ public final void testCreatePacketValidPayloadWithoutData() { XBee64BitAddress source64Addr = new XBee64BitAddress("0013A2004032D9AB"); XBee16BitAddress source16Addr = new XBee16BitAddress("B45C"); byte[] atCommand = "NI".getBytes(); - int status = ATCommandStatus.OK.getId(); + int status = ATCommandStatus.OK.getID(); byte[] payload = new byte[13 + atCommand.length]; payload[0] = (byte)frameType; @@ -198,7 +198,7 @@ public final void testCreatePacketValidPayloadWithoutData() { assertThat("Returned source 64-bit address is not the expected one", packet.get64bitSourceAddress(), is(equalTo(source64Addr))); assertThat("Returned source 16-bit address is not the expected one", packet.get16bitSourceAddress(), is(equalTo(source16Addr))); assertThat("Returned AT Command is not the expected one", packet.getCommand(), is(equalTo(new String(atCommand)))); - assertThat("Returned status is not the expected one", packet.getStatus().getId(), is(equalTo(status))); + assertThat("Returned status is not the expected one", packet.getStatus().getID(), is(equalTo(status))); assertThat("Returned value is not the expected one", packet.getCommandValue(), is(nullValue())); assertThat("Returned payload array is not the expected one", packet.getPacketData(), is(equalTo(payload))); @@ -218,7 +218,7 @@ public final void testCreatePacketValidPayloadWithData() { XBee64BitAddress source64Addr = new XBee64BitAddress("0013A2004032D9AB"); XBee16BitAddress source16Addr = new XBee16BitAddress("B45C"); byte[] atCommand = "NI".getBytes(); - int status = ATCommandStatus.OK.getId(); + int status = ATCommandStatus.OK.getID(); byte[] value = new byte[]{0x68, 0x6F, 0x6C, 0x61}; byte[] payload = new byte[13 + atCommand.length + value.length]; @@ -239,7 +239,7 @@ public final void testCreatePacketValidPayloadWithData() { assertThat("Returned source 64-bit address is not the expected one", packet.get64bitSourceAddress(), is(equalTo(source64Addr))); assertThat("Returned source 16-bit address is not the expected one", packet.get16bitSourceAddress(), is(equalTo(source16Addr))); assertThat("Returned AT Command is not the expected one", packet.getCommand(), is(equalTo(new String(atCommand)))); - assertThat("Returned status is not the expected one", packet.getStatus().getId(), is(equalTo(status))); + assertThat("Returned status is not the expected one", packet.getStatus().getID(), is(equalTo(status))); assertThat("Returned Command value is not the expected one", packet.getCommandValue(), is(equalTo(value))); assertThat("Returned payload array is not the expected one", packet.getPacketData(), is(equalTo(payload))); @@ -471,7 +471,7 @@ public final void testGetAPIDataATCommandParameterNull() { System.arraycopy(source64Addr.getValue(), 0, expectedData, 1, source64Addr.getValue().length); System.arraycopy(source16Addr.getValue(), 0, expectedData, 9, source16Addr.getValue().length); System.arraycopy(command.getBytes(), 0, expectedData, 11, command.length()); - expectedData[13] = (byte)status.getId(); + expectedData[13] = (byte)status.getID(); // Call the method under test. byte[] data = packet.getAPIData(); @@ -502,7 +502,7 @@ public final void testGetAPIDataATCommandParameterNotNull() { System.arraycopy(source64Addr.getValue(), 0, expectedData, 1, source64Addr.getValue().length); System.arraycopy(source16Addr.getValue(), 0, expectedData, 9, source16Addr.getValue().length); System.arraycopy(command.getBytes(), 0, expectedData, 11, command.length()); - expectedData[13] = (byte)status.getId(); + expectedData[13] = (byte)status.getID(); System.arraycopy(parameter, 0, expectedData, 12 + command.length(), parameter.length); // Call the method under test. @@ -530,7 +530,7 @@ public final void testGetAPIPacketParametersATCommandParameterNull() { String expectedDest64Addr = HexUtils.prettyHexString(source64Addr.getValue()); String expectedDest16Addr = HexUtils.prettyHexString(source16Addr.getValue()); - String expectedStatus = HexUtils.prettyHexString(HexUtils.integerToHexString(status.getId(), 1)) + " (" + status.getDescription() + ")"; + String expectedStatus = HexUtils.prettyHexString(HexUtils.integerToHexString(status.getID(), 1)) + " (" + status.getDescription() + ")"; String expectedATCommand = HexUtils.prettyHexString(command.getBytes()) + " (" + command + ")"; // Call the method under test. @@ -563,7 +563,7 @@ public final void testGetAPIPacketParametersATCommandParameterNonNull() { String expectedDest64Addr = HexUtils.prettyHexString(source64Addr.getValue()); String expectedDest16Addr = HexUtils.prettyHexString(source16Addr.getValue()); - String expectedStatus = HexUtils.prettyHexString(HexUtils.integerToHexString(status.getId(), 1)) + " (" + status.getDescription() + ")"; + String expectedStatus = HexUtils.prettyHexString(HexUtils.integerToHexString(status.getID(), 1)) + " (" + status.getDescription() + ")"; String expectedATCommand = HexUtils.prettyHexString(command.getBytes()) + " (" + command + ")"; String expectedATParameter = HexUtils.prettyHexString(parameter) + " (" + new String(parameter) + ")"; @@ -597,7 +597,7 @@ public final void testGetAPIPacketParametersATCommandParameterByteArrayNonString String expectedDest64Addr = HexUtils.prettyHexString(source64Addr.getValue()); String expectedDest16Addr = HexUtils.prettyHexString(source16Addr.getValue()); - String expectedStatus = HexUtils.prettyHexString(HexUtils.integerToHexString(status.getId(), 1)) + " (" + status.getDescription() + ")"; + String expectedStatus = HexUtils.prettyHexString(HexUtils.integerToHexString(status.getID(), 1)) + " (" + status.getDescription() + ")"; String expectedATCommand = HexUtils.prettyHexString(command.getBytes()) + " (" + command + ")"; String expectedATParameter = HexUtils.prettyHexString(parameter); diff --git a/library/src/test/java/com/digi/xbee/api/packet/common/TransmitStatusPacketTest.java b/library/src/test/java/com/digi/xbee/api/packet/common/TransmitStatusPacketTest.java index 5e148929..65e88d4c 100644 --- a/library/src/test/java/com/digi/xbee/api/packet/common/TransmitStatusPacketTest.java +++ b/library/src/test/java/com/digi/xbee/api/packet/common/TransmitStatusPacketTest.java @@ -115,7 +115,7 @@ public final void testCreatePacketPayloadShorterThanNeeded() { int frameID = 0xE7; XBee16BitAddress address = new XBee16BitAddress("B45C"); int retryCount = 3; - int deliveryStatus = XBeeTransmitStatus.SUCCESS.getId(); + int deliveryStatus = XBeeTransmitStatus.SUCCESS.getID(); byte[] payload = new byte[6]; payload[0] = (byte)frameType; @@ -143,8 +143,8 @@ public final void testCreatePacketPayloadNotIncludingFrameType() { int frameID = 0xE7; XBee16BitAddress address = new XBee16BitAddress("B45C"); int retryCount = 3; - int deliveryStatus = XBeeTransmitStatus.SUCCESS.getId(); - int discoveryStatus = XBeeDiscoveryStatus.DISCOVERY_STATUS_NO_DISCOVERY_OVERHEAD.getId(); + int deliveryStatus = XBeeTransmitStatus.SUCCESS.getID(); + int discoveryStatus = XBeeDiscoveryStatus.DISCOVERY_STATUS_NO_DISCOVERY_OVERHEAD.getID(); byte[] payload = new byte[7]; payload[0] = (byte)frameID; @@ -173,8 +173,8 @@ public final void testCreatePacketValidPayload() { int frameID = 0xE7; XBee16BitAddress address = new XBee16BitAddress("B45C"); int retryCount = 3; - int deliveryStatus = XBeeTransmitStatus.SUCCESS.getId(); - int discoveryStatus = XBeeDiscoveryStatus.DISCOVERY_STATUS_NO_DISCOVERY_OVERHEAD.getId(); + int deliveryStatus = XBeeTransmitStatus.SUCCESS.getID(); + int discoveryStatus = XBeeDiscoveryStatus.DISCOVERY_STATUS_NO_DISCOVERY_OVERHEAD.getID(); byte[] payload = new byte[7]; payload[0] = (byte)frameType; @@ -192,8 +192,8 @@ public final void testCreatePacketValidPayload() { assertThat("Frame ID is not the expected one", packet.getFrameID(), is(equalTo(frameID))); assertThat("Returned destination 16-bit address is not the expected one", packet.get16bitDestinationAddress(), is(equalTo(address))); assertThat("Returned retry count is not the expected one", packet.getTransmitRetryCount(), is(equalTo(retryCount))); - assertThat("Returned delivery status is not the expected one", packet.getTransmitStatus().getId(), is(equalTo(deliveryStatus))); - assertThat("Returned discovery status is not the expected one", packet.getDiscoveryStatus().getId(), is(equalTo(discoveryStatus))); + assertThat("Returned delivery status is not the expected one", packet.getTransmitStatus().getID(), is(equalTo(deliveryStatus))); + assertThat("Returned discovery status is not the expected one", packet.getDiscoveryStatus().getID(), is(equalTo(discoveryStatus))); assertThat("Returned payload array is not the expected one", packet.getPacketData(), is(equalTo(payload))); } @@ -211,7 +211,7 @@ public final void testCreatePacketValidPayloadUnknownDeliveryStatus() { XBee16BitAddress address = new XBee16BitAddress("B45C"); int retryCount = 3; int deliveryStatus = 255; - int discoveryStatus = XBeeDiscoveryStatus.DISCOVERY_STATUS_NO_DISCOVERY_OVERHEAD.getId(); + int discoveryStatus = XBeeDiscoveryStatus.DISCOVERY_STATUS_NO_DISCOVERY_OVERHEAD.getID(); byte[] payload = new byte[7]; payload[0] = (byte)frameType; @@ -229,7 +229,7 @@ public final void testCreatePacketValidPayloadUnknownDeliveryStatus() { assertThat("Frame ID is not the expected one", packet.getFrameID(), is(equalTo(frameID))); assertThat("Returned destination 16-bit address is not the expected one", packet.get16bitDestinationAddress(), is(equalTo(address))); assertThat("Returned retry count is not the expected one", packet.getTransmitRetryCount(), is(equalTo(retryCount))); - assertThat("Returned delivery status id is not the expected one", packet.getTransmitStatus().getId(), is(equalTo(XBeeTransmitStatus.UNKNOWN.getId()))); + assertThat("Returned delivery status id is not the expected one", packet.getTransmitStatus().getID(), is(equalTo(XBeeTransmitStatus.UNKNOWN.getID()))); assertThat("Returned delivery status description is not the expected one", packet.getTransmitStatus().getDescription(), is(equalTo(XBeeTransmitStatus.UNKNOWN.getDescription()))); assertThat("Returned discovery status is not the expected one", packet.getDiscoveryStatus(), is(equalTo(XBeeDiscoveryStatus.DISCOVERY_STATUS_NO_DISCOVERY_OVERHEAD))); @@ -248,7 +248,7 @@ public final void testCreatePacketValidPayloadUnknownDiscoveryStatus() { int frameID = 0xE7; XBee16BitAddress address = new XBee16BitAddress("B45C"); int retryCount = 3; - int deliveryStatus = XBeeTransmitStatus.BROADCAST_FAILED.getId();; + int deliveryStatus = XBeeTransmitStatus.BROADCAST_FAILED.getID();; int discoveryStatus = 255; byte[] payload = new byte[7]; @@ -534,8 +534,8 @@ public final void testGetAPIData() { expectedData[0] = (byte)frameID; System.arraycopy(dest16Addr.getValue(), 0, expectedData, 1, dest16Addr.getValue().length); expectedData[3] = (byte)retryCount; - expectedData[4] = (byte)transmitStatus.getId(); - expectedData[5] = (byte)discoveryStatus.getId(); + expectedData[4] = (byte)transmitStatus.getID(); + expectedData[5] = (byte)discoveryStatus.getID(); // Call the method under test. byte[] apiData = packet.getAPIData(); @@ -557,7 +557,7 @@ public final void testGetAPIDataUnknownTransmitStatus() { XBee16BitAddress address = new XBee16BitAddress("B45C"); int retryCount = 3; int deliveryStatus = 255; - int discoveryStatus = XBeeDiscoveryStatus.DISCOVERY_STATUS_NO_DISCOVERY_OVERHEAD.getId(); + int discoveryStatus = XBeeDiscoveryStatus.DISCOVERY_STATUS_NO_DISCOVERY_OVERHEAD.getID(); byte[] payload = new byte[7]; payload[0] = (byte)frameType; @@ -591,7 +591,7 @@ public final void testGetAPIDataUnknownDiscoveryStatus() { int frameID = 0xE7; XBee16BitAddress address = new XBee16BitAddress("B45C"); int retryCount = 3; - int deliveryStatus = XBeeTransmitStatus.NO_ACK.getId(); + int deliveryStatus = XBeeTransmitStatus.NO_ACK.getID(); int discoveryStatus = 255; byte[] payload = new byte[7]; @@ -631,8 +631,8 @@ public final void testGetAPIPacketParameters() { String expectedDest16Addr = HexUtils.prettyHexString(dest16Addr.getValue()); String expectedRetryCount = HexUtils.prettyHexString(Integer.toHexString(retryCount)) + " (" + retryCount + ")"; - String expectedTransmitStatus = HexUtils.prettyHexString(Integer.toHexString(transmitStatus.getId())) + " (" + transmitStatus.getDescription() + ")"; - String expectedDiscoveryStatus = HexUtils.prettyHexString(Integer.toHexString(discoveryStatus.getId())) + " (" + discoveryStatus.getDescription() + ")"; + String expectedTransmitStatus = HexUtils.prettyHexString(Integer.toHexString(transmitStatus.getID())) + " (" + transmitStatus.getDescription() + ")"; + String expectedDiscoveryStatus = HexUtils.prettyHexString(Integer.toHexString(discoveryStatus.getID())) + " (" + discoveryStatus.getDescription() + ")"; // Call the method under test. LinkedHashMap packetParams = packet.getAPIPacketParameters(); @@ -658,7 +658,7 @@ public final void testGetAPIPacketParametersWithUnknownTransmitStatus() { XBee16BitAddress address = new XBee16BitAddress("B45C"); int retryCount = 3; int deliveryStatus = 255; - int discoveryStatus = XBeeDiscoveryStatus.DISCOVERY_STATUS_ADDRESS_DISCOVERY.getId(); + int discoveryStatus = XBeeDiscoveryStatus.DISCOVERY_STATUS_ADDRESS_DISCOVERY.getID(); byte[] payload = new byte[7]; payload[0] = (byte)frameType; @@ -698,7 +698,7 @@ public final void testGetAPIPacketParametersWithUnknownDiscoveryStatus() { int frameID = 0xE7; XBee16BitAddress address = new XBee16BitAddress("B45C"); int retryCount = 3; - int deliveryStatus = XBeeTransmitStatus.NO_ACK.getId(); + int deliveryStatus = XBeeTransmitStatus.NO_ACK.getID(); int discoveryStatus = 255; byte[] payload = new byte[7]; diff --git a/library/src/test/java/com/digi/xbee/api/packet/raw/TXStatusPacketTest.java b/library/src/test/java/com/digi/xbee/api/packet/raw/TXStatusPacketTest.java index bf15d950..b0814e08 100644 --- a/library/src/test/java/com/digi/xbee/api/packet/raw/TXStatusPacketTest.java +++ b/library/src/test/java/com/digi/xbee/api/packet/raw/TXStatusPacketTest.java @@ -133,7 +133,7 @@ public final void testCreatePacketPayloadShorterThanNeeded() { public final void testCreatePacketPayloadNotIncludingFrameType() { // Setup the resources for the test. int frameID = 0xE7; - int status = XBeeTransmitStatus.SUCCESS.getId(); + int status = XBeeTransmitStatus.SUCCESS.getID(); byte[] payload = new byte[3]; payload[0] = (byte)frameID; @@ -157,7 +157,7 @@ public final void testCreatePacketValidPayload() { // Setup the resources for the test. int frameType = APIFrameType.TX_STATUS.getValue(); int frameID = 0xE7; - int status = XBeeTransmitStatus.SUCCESS.getId(); + int status = XBeeTransmitStatus.SUCCESS.getID(); byte[] payload = new byte[3]; payload[0] = (byte)frameType; @@ -198,7 +198,7 @@ public final void testCreatePacketValidPayloadUnknownStatus() { // Verify the result. assertThat("Returned length is not the expected one", packet.getPacketLength(), is(equalTo(payload.length))); assertThat("Frame ID is not the expected one", packet.getFrameID(), is(equalTo(frameID))); - assertThat("Returned status id is not the expected one", packet.getTransmitStatus().getId(), is(equalTo(XBeeTransmitStatus.UNKNOWN.getId()))); + assertThat("Returned status id is not the expected one", packet.getTransmitStatus().getID(), is(equalTo(XBeeTransmitStatus.UNKNOWN.getID()))); assertThat("Returned status description is not the expected one", packet.getTransmitStatus().getDescription(), is(equalTo(XBeeTransmitStatus.UNKNOWN.getDescription()))); assertThat("Returned payload array is not the expected one", packet.getPacketData(), is(equalTo(payload))); @@ -322,7 +322,7 @@ public final void testGetAPIData() { int expectedLength = 1 /* Frame ID */ + 1 /* transmit status */; byte[] expectedData = new byte[expectedLength]; expectedData[0] = (byte)frameID; - expectedData[1] = (byte)transmitStatus.getId(); + expectedData[1] = (byte)transmitStatus.getID(); // Call the method under test. byte[] apiData = packet.getAPIData(); @@ -372,7 +372,7 @@ public final void testGetAPIPacketParameters() { XBeeTransmitStatus transmitStatus = XBeeTransmitStatus.SUCCESS; TXStatusPacket packet = new TXStatusPacket(frameID, transmitStatus); - String expectedTransmitStatus = HexUtils.prettyHexString(Integer.toHexString(transmitStatus.getId())) + " (" + transmitStatus.getDescription() + ")"; + String expectedTransmitStatus = HexUtils.prettyHexString(Integer.toHexString(transmitStatus.getID())) + " (" + transmitStatus.getDescription() + ")"; // Call the method under test. LinkedHashMap packetParams = packet.getAPIPacketParameters(); diff --git a/library/src/test/java/com/digi/xbee/api/utils/ByteUtilsTest.java b/library/src/test/java/com/digi/xbee/api/utils/ByteUtilsTest.java index c300f9cf..f4ca8c55 100644 --- a/library/src/test/java/com/digi/xbee/api/utils/ByteUtilsTest.java +++ b/library/src/test/java/com/digi/xbee/api/utils/ByteUtilsTest.java @@ -583,7 +583,7 @@ public final void testStringToByteArrayNullString() { exception.expectMessage(is(equalTo("Value cannot be null."))); // Call the method under test. - ByteUtils.stringToByteArray(s); + StringUtils.stringToByteArray(s); } /** @@ -595,7 +595,7 @@ public final void testStringToByteArrayEmptyString() { String s = ""; // Call the method under test. - byte[] result = ByteUtils.stringToByteArray(s); + byte[] result = StringUtils.stringToByteArray(s); // Verify the result. assertThat("Returned byte array must be empty", result.length, is(equalTo(0))); @@ -611,7 +611,7 @@ public final void testStringToByteArray() { byte[] expectedResult = new byte[]{'H', 'e', 'l', 'l', 'o'}; // Call the method under test. - byte[] result = ByteUtils.stringToByteArray(s); + byte[] result = StringUtils.stringToByteArray(s); // Verify the result. assertThat("Returned byte array must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); @@ -629,7 +629,7 @@ public final void testByteArrayToStringNullArray() { exception.expectMessage(is(equalTo("Byte array cannot be null."))); // Call the method under test. - ByteUtils.byteArrayToString(byteArray); + StringUtils.byteArrayToString(byteArray); } /** @@ -642,7 +642,7 @@ public final void testByteArrayToStringEmptyArray() { String expectedResult = ""; // Call the method under test. - String result = ByteUtils.byteArrayToString(byteArray); + String result = StringUtils.byteArrayToString(byteArray); // Verify the result. assertThat("Returned string must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); @@ -658,7 +658,7 @@ public final void testByteArrayToString() { String expectedResult = "Hello"; // Call the method under test. - String result = ByteUtils.byteArrayToString(byteArray); + String result = StringUtils.byteArrayToString(byteArray); // Verify the result. assertThat("Returned string must be equal to 'expectedResult'", result, is(equalTo(expectedResult))); @@ -674,7 +674,7 @@ public final void testStringToByteArrayAndByteArrayToString() { String s = "Hello"; // Call the method under test. - String result = ByteUtils.byteArrayToString(ByteUtils.stringToByteArray(s)); + String result = StringUtils.byteArrayToString(StringUtils.stringToByteArray(s)); // Verify the result. assertThat("Returned string must be equal to initial string", result, is(equalTo(s)));