/// <summary>
 /// Encode command frame
 /// </summary>
 /// <param name="frame">target buffer</param>
 /// <returns>True on success</returns>
 public bool WriteToFrame(Frame frame)
 {
     if (frame == null || frame.LengthDataAvail < _lengthMax || frame.LengthDataUsed != 0)
         return false;
     frame.ReserveHeader(frame.LengthHeaderAvail + 1); // increase header space by one byte
     frame.AllocBack(_lengthMax - 1); // reserve space without command type, so payload is at 0..n-1
     EncodePayload(frame);
     frame.AllocFront(1);
     frame.Write(0, (byte)_type);
     return true;
 }
Exemple #2
0
        public bool WriteToFrame(Frame frame)
        {
            int len = Length();
            if (frame == null || frame.LengthDataAvail < len)
                return false;
            frame.AllocBack(len);

            int offset = 0;
            frame.Write(offset, (byte)Message.Report);
            offset++;

            for (int i = 0; i < nodeCount; i++)
            {
                frame.Write(offset, nodes[i].addr);
                offset += 2;
                frame.Write(offset, nodes[i].rxBps);
                offset += 4;
            }

            return true;
        }
        /// <summary>
        /// Encode beacon into frame
        /// </summary>
        /// <param name="frame">target frame</param>
        /// <returns>True on success</returns>
        public bool WriteToFrame(Frame frame)
        {
            int len = Length();
            if (frame == null || frame.LengthDataAvail < len || frame.LengthDataUsed > 0)
                return false;
            if (payload != null)
                len -= payload.LengthDataUsed;
            frame.AllocBack(len);

            int offset = 0;

            // 7.2.2.1.2 Superframe Specification field
            int i;
            i = (beaconOrder & 0xf) |
                ((superframeOrder & 0xf) << 4) |
                ((finalCapSlot & 0xf) << 8) |
                ((batteryLifeExtension & 1) << 12) |
                ((panCoordinator & 1) << 14) |
                ((associationPermit & 1) << 15);
            frame.Write(offset, (UInt16)i);
            offset += 2;

            // 7.2.2.1.3 GTS Specification field
            if (gtsLength > 7)
                return false; // assert
            i = (gtsLength & 7) |
                 ((gtsPermit & 1) << 7);
            frame.Write(offset, (Byte)i);
            offset += 1;

            // 7.2.2.1.4 GTS Directions field
            if (gtsLength > 0)
            {
                i = (gtsDirectionsMask & 0x7F); // 7 bits
                frame.Write(offset, (Byte)i);
                offset += 1;
            }

            // 7.2.2.1.5 GTS List field
            for (int k = 0; k < gtsLength; k++)
            {
                frame.Write(offset, gtsDescriptor[k].deviceShortAddr);
                offset += 2;
                i = (gtsDescriptor[k].gtsStartingSlot & 0xF) |
                    ((gtsDescriptor[k].gtsLength & 0xF) << 4);
                frame.Write(offset, (Byte)i);
                offset++;
            }

            // 7.2.2.1.6 Pending Address Specification field
            i = (pendingShort & 7) |
                ((pendingExt & 7) << 4);
            frame.Write(offset, (Byte)i);
            offset++;

            // 7.2.2.1.7 Address List field
            for (int k = 0; k < pendingShort; k++)
            {
                frame.Write(offset, shortAddrPending[k]);
                offset += 2;
            }

            for (int k = 0; k < pendingExt; k++)
            {
                frame.Write(offset, extAddrPending[k]);
                offset += 8;
            }

            // 7.2.2.1.8 Beacon Payload field
            if (payload != null)
                frame.WriteToBack(payload);

            return true;
        }
Exemple #4
0
        public bool WriteToFrame(Frame frame)
        {
            int len = Length();
            if (frame == null || frame.LengthDataAvail < len)
                return false;
            frame.AllocBack(len);

            int offset = 0;
            frame.Write(offset, (byte)Message.Neighbors);
            offset++;

            for (int i = 0; i < neighborCount; i++)
            {
                frame.Write(offset, neighbors[i].shortAdr);
                offset += 2;
                frame.Write(offset, neighbors[i].lqi);
                offset += 1;
            }

            return true;
        }