本文整理汇总了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;
}
示例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);
}
}