Ejemplo n.º 1
0
        void phy_DataIndicationFlash(IPhyDataSap sender, Frame frame, byte linkQuality)
        {
            byte[] b = new byte[2];
            frame.ReadBytes(b, 0, frame.LengthDataUsed - 2, 2);
            uint u = ((uint)(b[0] << 8)) | b[1];

            Frame.Release(ref frame);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// handler for data from Phy
        /// </summary>
        private void PhyDataIndicationHandler(
            IPhyDataSap sender,
            Frame frame,
            Byte linkQuality)
        {
            if (frame == null)
            {
                return;
            }

            if (frame.LengthDataUsed >= 3)
            { // min frame size
                // inspect frame type, light-weight decoding
                Frames.Type type;
                bool        ok = Header.GetType(frame, out type);

                if (ok)
                {
                    switch (type)
                    {
                    case Frames.Type.Ack:
                        if (_ackPending)
                        {
                            // All other subfields than fcs.pending shall be set to zero and ignored on reception
                            byte seqNo = frame.ReadByte(2);     // ack frame is FCF+seqNo
                            if (seqNo == _ackSeqNo)
                            {
                                _ackReceived.Set();
                            }
                        }
                        break;

                    case Frames.Type.Beacon:
                    case Frames.Type.Data:
                    case Frames.Type.Cmd:
                        lock (_state)
                        {     // keep state consistent while processing frame
                            if (_filterEnabled)
                            {
                                // FIXME: SW filter is not implemented
                            }
                            else
                            {
                                _mac.PhyDataIndication(sender, ref frame, linkQuality);
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            Frame.Release(ref frame);
        }
Ejemplo n.º 3
0
        void phy_DataIndicationAqc(IPhyDataSap sender, Frame frame, byte linkQuality)
        {
            byte[] bResp = new byte[128];

            int i = frame.buf[4];
            int mtu, head, tail;

            phy.GetMtuSize(out mtu, out head, out tail);
            Status status;

            m_RespFrame.ReserveHeader(head);
            int cInd = -1;

            ushort u = (ushort)(1 << 0) | // m_RespFrame type: data
                       (0 << 3) |         // security: none
                       (0 << 4) |         // m_RespFrame pending: none
                       (1 << 5) |         // ack request: true
                       (1 << 6) |         // pan id compression: true
                       (2 << 10) |        // dst addr: short addr
                       (2 << 14);         // src addr: short addr

            bResp[++cInd] = (byte)(u & 0xFF);
            bResp[++cInd] = (byte)(u >> 8);
            // Append sequence number.
            bResp[++cInd] = (byte)i; // seq no

            u             = 1;       // pan id
            bResp[++cInd] = (byte)(u & 0xFF);
            bResp[++cInd] = (byte)(u >> 8);
            u             = 2;
            bResp[++cInd] = (byte)(u & 0xFF);
            bResp[++cInd] = (byte)(u >> 8);
            u             = 3;
            bResp[++cInd] = (byte)(u & 0xFF);
            bResp[++cInd] = (byte)(u >> 8);
            bResp[++cInd] = 0xBE;
            bResp[++cInd] = 0xEF;
            bResp[++cInd] = 0xDE;
            bResp[++cInd] = 0xAD;                               // dead beef
            m_RespFrame.AppendToBack(bResp, 0, cInd + 1 + 100); // payload
            do
            {
                phy.DataRequest(m_RespFrame, out status);
            }while (status != Status.Success);

            DateTime curTime = DateTime.Now;

            Debug.Print("Response " + i + " is sent at " + curTime.Second + ":" + curTime.Millisecond);
            TimeSpan printTime = DateTime.Now - curTime;

            Debug.Print("Print Takes " + printTime);

            Frame.Release(ref frame);
        }
Ejemplo n.º 4
0
        void phy_DataIndicationFlash(IPhyDataSap sender, Frame frame, byte linkQuality)
        {
            leds.color = Leds.Color.Green;
            byte[] b = new byte[2];
            frame.ReadBytes(b, 0, frame.LengthDataUsed - 2, 2);
            uint u = ((uint)(b[0] << 8)) | b[1];

            // Debug.Print("received fcs no " + HexConverter.ConvertUintToHex(u, 4));

            Frame.Release(ref frame);
            leds.color = Leds.Color.Off;
        }
Ejemplo n.º 5
0
        void phy_DataIndicationDump(IPhyDataSap sender, Frame frame, byte linkQuality)
        {
            string s = "recv: ";

            for (int i = 0; i < frame.LengthDataUsed; i++)
            {
                byte b = frame.ReadByte(i);
                s += HexConverter.ConvertUintToHex(b, 2) + " ";
            }

            Debug.Print(s);
            Frame.Release(ref frame);
        }
Ejemplo n.º 6
0
        /// <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;
                }
            }
        }
Ejemplo n.º 7
0
        /// <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;
                }
            }
        }
Ejemplo n.º 8
0
        void phy_DataIndicationDump(IPhyDataSap sender, Frame frame, byte linkQuality)
        {
            leds.color = Leds.Color.Green;
            string s = "recv: ";
            for (int i = 0; i < frame.LengthDataUsed; i++)
            {
                byte b = frame.ReadByte(i);
                s += HexConverter.ConvertUintToHex(b, 2) + " ";
            }

            Debug.Print(s);
            Frame.Release(ref frame);
            leds.color = Leds.Color.Off;
        }
Ejemplo n.º 9
0
 void phy_DataIndicationFlash(IPhyDataSap sender, Frame frame, byte linkQuality)
 {
     leds.color = Leds.Color.Green;
     byte[] b = new byte[2];
     frame.ReadBytes(b, 0, frame.LengthDataUsed - 2, 2);
     uint u = ((uint)(b[0] << 8)) | b[1];
     Frame.Release(ref frame);
     leds.color = Leds.Color.Off;
 }
Ejemplo n.º 10
0
        void phy_DataIndicationAqc(IPhyDataSap sender, Frame frame, byte linkQuality)
        {
            byte[] bResp = new byte[128];

            int i = frame.buf[4];
            int mtu, head, tail;
            phy.GetMtuSize(out mtu, out head, out tail);
            Status status;

            m_RespFrame.ReserveHeader(head);
            int cInd = -1;

            ushort u = (ushort)(1 << 0) | // m_RespFrame type: data
                (0 << 3) | // security: none
                (0 << 4) | // m_RespFrame pending: none
                (1 << 5) | // ack request: true
                (1 << 6) | // pan id compression: true
                (2 << 10) | // dst addr: short addr
                (2 << 14);  // src addr: short addr
            bResp[++cInd] = (byte)(u & 0xFF);
            bResp[++cInd] = (byte)(u >> 8);
            // Append sequence number.
            bResp[++cInd] = (byte)i;    // seq no

            u = 1; // pan id
            bResp[++cInd] = (byte)(u & 0xFF);
            bResp[++cInd] = (byte)(u >> 8);
            u = 2;
            bResp[++cInd] = (byte)(u & 0xFF);
            bResp[++cInd] = (byte)(u >> 8);
            u = 3;
            bResp[++cInd] = (byte)(u & 0xFF);
            bResp[++cInd] = (byte)(u >> 8);
            bResp[++cInd] = 0xBE;
            bResp[++cInd] = 0xEF;
            bResp[++cInd] = 0xDE;
            bResp[++cInd] = 0xAD; // dead beef
            m_RespFrame.AppendToBack(bResp, 0, cInd + 1 + 100); // payload
            do
            {
                phy.DataRequest(m_RespFrame, out status);
            }

            while (status != Status.Success);

            DateTime curTime = DateTime.Now;
            Debug.Print("Response " + i + " is sent at " + curTime.Second + ":" + curTime.Millisecond);
            TimeSpan printTime = DateTime.Now - curTime;
            Debug.Print("Print Takes " + printTime);

            Frame.Release(ref frame);
        }
Ejemplo n.º 11
0
 void phy_DataIndicationDummy(IPhyDataSap sender, Frame frame, byte linkQuality)
 {
     Frame.Release(ref frame);
 }
Ejemplo n.º 12
0
 void phy_DataIndicationDummy(IPhyDataSap sender, Frame frame, byte linkQuality)
 {
     Frame.Release(ref frame);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// handler for data from Phy
        /// </summary>
        private void PhyDataIndicationHandler(
            IPhyDataSap sender,
            Frame frame,
            Byte linkQuality)
        {
            if (frame == null)
                return;

            if (frame.LengthDataUsed >= 3)
            { // min frame size
                // inspect frame type, light-weight decoding
                Frames.Type type;
                bool ok = Header.GetType(frame, out type);

                if (ok)
                {
                    switch (type)
                    {
                        case Frames.Type.Ack:
                            if (_ackPending)
                            {
                                // All other subfields than fcs.pending shall be set to zero and ignored on reception
                                byte seqNo = frame.ReadByte(2); // ack frame is FCF+seqNo
                                if (seqNo == _ackSeqNo)
                                    _ackReceived.Set();
                            }
                            break;
                        case Frames.Type.Beacon:
                        case Frames.Type.Data:
                        case Frames.Type.Cmd:
                            lock (_state)
                            { // keep state consistent while processing frame
                                if (_filterEnabled)
                                {
                                    // FIXME: SW filter is not implemented
                                }
                                else
                                {
                                    _mac.PhyDataIndication(sender, ref frame, linkQuality);
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
            }

            Frame.Release(ref frame);
        }
Ejemplo n.º 14
0
        void phy_DataIndicationFlash(IPhyDataSap sender, Frame frame, byte linkQuality)
        {
            leds.color = Leds.Color.Green;
            byte[] b = new byte[2];
            frame.ReadBytes(b, 0, frame.LengthDataUsed-2, 2);
            uint u = ((uint)(b[0] << 8)) | b[1];
            // Debug.Print("received fcs no " + HexConverter.ConvertUintToHex(u, 4));

             Frame.Release(ref frame);
            leds.color = Leds.Color.Off;
        }