コード例 #1
0
 /// <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;
 }
コード例 #2
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;
        }