Ejemplo n.º 1
0
        public byte[] GetHeader()
        {
            byte[] destinationEndPoint = null;
            byte[] profileId           = null;
            if (m_endPoint == null)
            {
                destinationEndPoint = DESTINATION_ENDPOINT;
                profileId           = PROFILE_ID;
            }
            else
            {
                destinationEndPoint    = new byte[sizeof(byte)];
                destinationEndPoint[0] = m_endPoint.Id;
                profileId = AdapterHelper.ToXbeeFrame(m_endPoint.CommandProfileId);
            }
            // set destination (mac address and network address)
            byte[] macAddress     = null;
            byte[] networkAddress = null;
            if (null != m_destination)
            {
                // send to specific device
                macAddress     = AdapterHelper.ToXbeeFrame(m_destination.MacAddress);
                networkAddress = AdapterHelper.ToXbeeFrame(m_destination.NetworkAddress);
            }
            else
            {
                // broadcast
                macAddress     = AdapterHelper.ToXbeeFrame(AdapterHelper.BROADCAST_MAC_ADDRESS);
                networkAddress = AdapterHelper.ToXbeeFrame(AdapterHelper.UNKNOWN_NETWORK_ADDRESS);
            }

            // set cluster ID
            byte[] clusterId = AdapterHelper.ToXbeeFrame(m_clusterId);

            // create and set header buffer
            int offset     = 0;
            int headerSize = macAddress.Length + networkAddress.Length + SOURCE_ENDPOINT.Length + DESTINATION_ENDPOINT.Length +
                             clusterId.Length + PROFILE_ID.Length + BROADCAST_RADIUS.Length + TRANSMIT_OPTIONS.Length;

            byte[] header = new byte[headerSize];

            offset = AdapterHelper.AddByteToBuffer(ref header, ref macAddress, offset);
            offset = AdapterHelper.AddByteToBuffer(ref header, ref networkAddress, offset);
            offset = AdapterHelper.AddByteToBuffer(ref header, ref SOURCE_ENDPOINT, offset);
            offset = AdapterHelper.AddByteToBuffer(ref header, ref destinationEndPoint, offset);
            offset = AdapterHelper.AddByteToBuffer(ref header, ref clusterId, offset);
            offset = AdapterHelper.AddByteToBuffer(ref header, ref profileId, offset);
            offset = AdapterHelper.AddByteToBuffer(ref header, ref BROADCAST_RADIUS, offset);
            offset = AdapterHelper.AddByteToBuffer(ref header, ref TRANSMIT_OPTIONS, offset);

            return(header);
        }
Ejemplo n.º 2
0
        private int SetCommandHeader(ref byte[] buffer, int initialOffset, int commandSize, ref byte[] xbeeCommand, ref byte[] commandId)
        {
            int offset = initialOffset;

            // add headers (frame and at command)
            offset = AdapterHelper.AddByteToBuffer(ref buffer, ref COMMAND_PREFIX, offset);

            UInt16 tempWord = Convert.ToUInt16(commandSize);

            byte[] tempBytes = AdapterHelper.ToXbeeFrame(tempWord);
            offset = AdapterHelper.AddByteToBuffer(ref buffer, ref tempBytes, offset);

            offset = AdapterHelper.AddByteToBuffer(ref buffer, ref xbeeCommand, offset);
            offset = AdapterHelper.AddByteToBuffer(ref buffer, ref commandId, offset);

            return(offset);
        }