/// <summary> /// Worker thread to indicate received frames to upper layer sequentially. /// </summary> private void DataIndicationThread() { while (true) { _rxEvent.WaitOne(); if (_rxThreadExit) break; while (true) { Frame frame = null; lock (_rxFrameQueue) { frame = _rxFrameQueue.GetFrame(); } if (frame == null) break; byte lqi = frame.ReadByte(frame.LengthDataUsed - 1); // pull LQI from frame frame.DeleteFromBack(1); Header hdr = new Header(); if (hdr.ReadFromFrameHeader(frame, true)) { ReceiveData(hdr, ref frame, lqi); } Frame.Release(ref frame); } } }
/// <summary> /// process frame from Phy layer. FCS has been removed already. /// </summary> /// <param name="sender"></param> /// <param name="frame"></param> /// <param name="linkQuality"></param> public void PhyDataIndication( IPhyDataSap sender, ref Frame frame, Byte linkQuality) { Frames.Type type; bool ok = Header.GetType(frame, out type); if (ok && type == Frames.Type.Data) { frame.AllocBack(1); frame.Write(frame.LengthDataUsed - 1, linkQuality); lock (_rxFrameQueue) { _rxFrameQueue.AddFrame(ref frame); } _rxEvent.Set(); Frame.Release(ref frame); return; } Header hdr = new Header(); if (hdr.ReadFromFrameHeader(frame, true)) { switch (hdr.fcs.Type) { case Microsoft.SPOT.Wireless.IEEE_802_15_4.Mac.Frames.Type.Beacon: ReceiveBeacon(hdr, ref frame, linkQuality); break; case Microsoft.SPOT.Wireless.IEEE_802_15_4.Mac.Frames.Type.Cmd: ReceiveCommand(hdr, ref frame, linkQuality); break; default: // drop, data and ack frames are handled before break; } } }