コード例 #1
0
ファイル: Header.cs プロジェクト: aura1213/netmf-interpreter
        /// <summary>
        /// Encodes the header into the front of the frame
        /// </summary>
        /// <param name="frame">The header is placed at the front of this frame</param>
        /// <returns>True on success, false if the frame is too small or the header is invalid</returns>
        public bool WriteToFrameHeader(Frame frame)
        {
            int len = Length();
            if (frame.LengthHeaderAvail < len)
                return false;

            frame.AllocFront(len);
            frame.WriteCanonical(0, fcs.Value);
            frame.Write(2, seqNo);
            int offset = 3;
            AddressingMode dstMode = fcs.DstAddrMode;
            AddressingMode srcMode = fcs.SrcAddrMode;
            bool panIdCompression = fcs.PanIdCompression;

            if (dstMode == AddressingMode.Reserved || srcMode == AddressingMode.Reserved ||
                (panIdCompression && dstMode == AddressingMode.None))
                return false;

            if (dstMode != AddressingMode.None)
            { // dstPanId
                frame.WriteCanonical(offset, dstPanId);
                offset += 2;
            }

            if (dstMode == AddressingMode.Short)
            { // dstAddrShort
                frame.WriteCanonical(offset, dstAddrShort);
                offset += 2;
            }

            if (dstMode == AddressingMode.Extended)
            { // dstAddrShort
                frame.WriteCanonical(offset, dstAddrExt);
                offset += 8;
            }

            if (srcMode != AddressingMode.None && !panIdCompression)
            { // srcPanId
                frame.WriteCanonical(offset, srcPanId);
                offset += 2;
            }

            if (srcMode == AddressingMode.Short)
            { // dstAddrShort
                frame.WriteCanonical(offset, srcAddrShort);
                offset += 2;
            }

            if (srcMode == AddressingMode.Extended)
            { // dstAddrShort
                frame.WriteCanonical(offset, srcAddrExt);
                offset += 8;
            }

            // FIXME: secHeader
            return true;
        }