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