001/** 002 * Copyright 2017, Digi International Inc. 003 * 004 * This Source Code Form is subject to the terms of the Mozilla Public 005 * License, v. 2.0. If a copy of the MPL was not distributed with this 006 * file, you can obtain one at http://mozilla.org/MPL/2.0/. 007 * 008 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 009 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 010 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 011 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 012 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 013 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 014 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 015 */ 016package com.digi.xbee.api.models; 017 018import com.digi.xbee.api.RemoteXBeeDevice; 019 020/** 021 * This class represents an Explicit XBee message containing the remote XBee 022 * device the message belongs to, the content (data) of the message, a flag 023 * indicating if the message is a broadcast message (was received or is being 024 * sent via broadcast) and all the application layer fields: source endpoint, 025 * destination endpoint, cluster ID and profile ID. 026 * 027 * <p>This class is used within the XBee Java Library to read explicit data 028 * sent by remote devices.</p> 029 */ 030public class ExplicitXBeeMessage extends XBeeMessage { 031 032 // Variables. 033 private final int sourceEndpoint; 034 private final int destEndpoint; 035 private final int clusterID; 036 private final int profileID; 037 038 /** 039 * Class constructor. Instantiates a new object of type 040 * {@code ExplicitXBeeMessage} with the given parameters. 041 * 042 * @param remoteXBeeDevice The remote XBee device the message belongs to. 043 * (device that sent the message) 044 * @param sourceEndpoint Endpoint of the source that initiated the 045 * transmission. 046 * @param destEndpoint Endpoint of the destination the message was 047 * addressed to. 048 * @param clusterID Cluster ID the packet was addressed to. 049 * @param profileID Profile ID the packet was addressed to. 050 * @param data Byte array containing the data of the message. 051 * 052 * @throws IllegalArgumentException if {@code sourceEndpoint < 0} or 053 * if {@code sourceEndpoint > 0xFF} or 054 * if {@code destEndpoint < 0} or 055 * if {@code destEndpoint > 0xFF} or 056 * if {@code clusterID < 0} or 057 * if {@code clusterID > 0xFFFF} or 058 * if {@code profileID < 0} or 059 * if {@code profileID > 0xFFFF}. 060 * @throws NullPointerException if {@code remoteXBeeDevice == null} or 061 * if {@code data == null}. 062 * 063 * @see com.digi.xbee.api.RemoteXBeeDevice 064 */ 065 public ExplicitXBeeMessage(RemoteXBeeDevice remoteXBeeDevice, int sourceEndpoint, int destEndpoint, int clusterID, int profileID, byte[] data) { 066 this(remoteXBeeDevice, sourceEndpoint, destEndpoint, clusterID, profileID, data, false); 067 } 068 069 /** 070 * Class constructor. Instantiates a new object of type 071 * {@code XBeeMessage} with the given parameters. 072 * 073 * @param remoteXBeeDevice The remote XBee device the message belongs to. 074 * (device that sent the message) 075 * @param sourceEndpoint Endpoint of the source that initiated the 076 * transmission. 077 * @param destEndpoint Endpoint of the destination the message was 078 * addressed to. 079 * @param clusterID Cluster ID the packet was addressed to. 080 * @param profileID Profile ID the packet was addressed to. 081 * @param data Byte array containing the data of the message. 082 * @param isBroadcast Indicates if the message was received via broadcast. 083 * 084 * @throws IllegalArgumentException if {@code sourceEndpoint < 0} or 085 * if {@code sourceEndpoint > 0xFF} or 086 * if {@code destEndpoint < 0} or 087 * if {@code destEndpoint > 0xFF} or 088 * if {@code clusterID < 0} or 089 * if {@code clusterID > 0xFFFF} or 090 * if {@code profileID < 0} or 091 * if {@code profileID > 0xFFFF}. 092 * @throws NullPointerException if {@code remoteXBeeDevice == null} or 093 * if {@code data == null}. 094 * 095 * @see com.digi.xbee.api.RemoteXBeeDevice 096 */ 097 public ExplicitXBeeMessage(RemoteXBeeDevice remoteXBeeDevice, int sourceEndpoint, int destEndpoint, int clusterID, int profileID, byte[] data, boolean isBroadcast) { 098 super(remoteXBeeDevice, data, isBroadcast); 099 100 if (sourceEndpoint < 0 || sourceEndpoint > 0xFF) 101 throw new IllegalArgumentException("Source endpoint must be between 0 and 0xFF."); 102 if (destEndpoint < 0 || destEndpoint > 0xFF) 103 throw new IllegalArgumentException("Destination endpoint must be between 0 and 0xFF."); 104 if (clusterID < 0 || clusterID > 0xFFFF) 105 throw new IllegalArgumentException("Cluster ID must be between 0 and 0xFF."); 106 if (profileID < 0 || profileID > 0xFFFF) 107 throw new IllegalArgumentException("Profile ID must be between 0 and 0xFF."); 108 109 this.sourceEndpoint = sourceEndpoint; 110 this.destEndpoint = destEndpoint; 111 this.clusterID = clusterID; 112 this.profileID = profileID; 113 } 114 115 /** 116 * Returns the endpoint of the source that initiated the transmission. 117 * 118 * @return The endpoint of the source that initiated the transmission. 119 */ 120 public int getSourceEndpoint() { 121 return sourceEndpoint; 122 } 123 124 /** 125 * Returns the endpoint of the destination the message was addressed to. 126 * 127 * @return The endpoint of the destination the message was addressed to. 128 */ 129 public int getDestinationEndpoint() { 130 return destEndpoint; 131 } 132 133 /** 134 * Returns the cluster ID the packet was addressed to. 135 * 136 * @return The cluster ID the packet was addressed to. 137 */ 138 public int getClusterID() { 139 return clusterID; 140 } 141 142 /** 143 * Returns the profile ID the packet was addressed to. 144 * 145 * @return The profile ID the packet was addressed to. 146 */ 147 public int getProfileID() { 148 return profileID; 149 } 150}