当前位置: 首页>>代码示例>>C#>>正文


C# Frame.ReadUInt16方法代码示例

本文整理汇总了C#中Frame.ReadUInt16方法的典型用法代码示例。如果您正苦于以下问题:C# Frame.ReadUInt16方法的具体用法?C# Frame.ReadUInt16怎么用?C# Frame.ReadUInt16使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Frame的用法示例。


在下文中一共展示了Frame.ReadUInt16方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadFromFrame

 /// <summary>
 /// Decode message from frame
 /// </summary>
 /// <param name="frame">Frame containing message</param>
 /// <returns>True on success</returns>
 public bool ReadFromFrame(Frame frame)
 {
     if (frame == null || frame.LengthDataUsed != cLength)
         return false;
     byte Header = frame.ReadByte(0);
     if ((Type)(Header >> 2) != Type.AddressReply)
         return false;
     HopsLeft = frame.ReadByte(1);
     BrokerAddr = frame.ReadUInt16Canonical(2);
     DeviceAddr = frame.ReadUInt64Canonical(4);
     ShortAddr = frame.ReadUInt16Canonical(12);
     DiscoveryInterval = frame.ReadUInt16(14);
     return true;
 }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:19,代码来源:Messages_custom.cs

示例2: HandleLowerLayerDataIndication

        public void HandleLowerLayerDataIndication(object sender, ushort originatorShortAddr, ushort targetShortAddr, Frame sdu)
        {
            FragmentationMessage fragMsg = null;
            FragmentHeader header;

            lock (_lock)
            {
                if ((!_started) || (sdu.LengthDataUsed < 2))
                {
                    Frame.Release(ref sdu);
                    return;
                }

                // extract fragment header.
                header = FragmentHeader.Decode(sdu.ReadUInt16(0));
                sdu.DeleteFromFront(2);
                FragmentationMessageAssociationSet associations;
                switch (header.Type)
                {
                    case FragmentType.DATA:
                        associations = _inboundAssociations;
                        if (associations == null)
                        {
                            Frame.Release(ref sdu);
                            return;
                        }

                        fragMsg = (InboundFragmentationMessage)associations.GetFragmentationMessage(originatorShortAddr, targetShortAddr);
                        if (fragMsg != null)
                        {
                            // there is already one message with this peer. Check freshness.
                            if (fragMsg.MessageNumber != header.MessageSeqNumber)
                            {
                                int sqnOld = (int)fragMsg.MessageNumber;
                                int sqnNew = (int)header.MessageSeqNumber;
                                int diff = (sqnNew > sqnOld) ? sqnNew - sqnOld : sqnNew - sqnOld + 256;
                                if ((header.MessageSeqNumber == 0) || (diff < 128))
                                {
                                    // data received is most recent.
                                    fragMsg.Dispose();
                                    fragMsg = null;
                                }
                                else
                                {
                                    // data received is old stuff.
                                    Frame.Release(ref sdu);
                                    return;
                                }
                            }
                        }

                        if (fragMsg == null)
                        {
                            // new message must be started
                            fragMsg = new InboundFragmentationMessage(originatorShortAddr, targetShortAddr,
                                header.MessageSeqNumber, _lowerLayerDataRequest, _lowerMtu, _lowerHead, _lowerTail, _timer);
                            fragMsg.FragmentationMessageTerminated += this.HandleFragmentationMessageTerminated;
                            associations.SetFragmentationMessage(originatorShortAddr, targetShortAddr, fragMsg);
                        }
                        break;
                    case FragmentType.ACK:
                        associations = _outboundAssociations;
                        if (associations == null)
                        {
                            Frame.Release(ref sdu);
                            return;
                        }

                        fragMsg = (OutboundFragmentationMessage)associations.GetFragmentationMessage(targetShortAddr, originatorShortAddr);
                        if ((fragMsg == null) || (fragMsg.MessageNumber != header.MessageSeqNumber))
                        {
                            //no one waiting for this segment. Discard.
#if DEBUG
                            Trace.Print("No one waiting for this segment. Discard.");
#endif

                            Frame.Release(ref sdu);
                            return;
                        }
                        break;
                    default:
                        break;
                }
            }

            // release the lock before calling method in FragmentMessage class
            if (fragMsg != null)
            {
                fragMsg.HandleReceivedFragment(header, ref sdu);

            }
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:92,代码来源:Fragmentation.cs


注:本文中的Frame.ReadUInt16方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。