Ejemplo n.º 1
0
 /// <summary>
 /// Enabled receiving of frames from Phy
 /// </summary>
 public void Start()
 {
     if (!_running)
     {
         _running            = true;
         _phy.DataIndication = PhyDataIndicationHandler;
         Phy.Status status;
         _phy.SetTrxStateRequest(Phy.State.RxOn, out status);
     }
 }
Ejemplo n.º 2
0
        public void TestSend(bool bSendData)
        {
            phy.SetPower(true);
            phy.SetAutoFCS(true);
            int mtu, head, tail;

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

            PibValue value = new PibValue();
            Status   status;

            value.Int = 11;
            phy.SetRequest(PibAttribute.phyCurrentChannel, value, out status);
            Assert(status == Status.Success);

            value.Int = 0;
            phy.SetRequest(PibAttribute.phyTransmitPower, value, out status);
            Assert(status == Status.Success);

            if (bSendData)
            {   // Sends data continously. Dummy processing.
                phy.DataIndication = phy_DataIndicationDummy;
            }
            else
            {   // Does not send data. During receive pings data back.
                phy.DataIndication = phy_DataIndicationAqc;
            }

            phy.SetTrxStateRequest(State.RxOn, out status);
            byte[] packetData = new byte[100];

            DateTime prevTime = DateTime.Now;

            byte[] b = new byte[128];

            Thread.Sleep(10);

            if (!bSendData)
            {
                return;
            }

            for (int i = 0; ; ++i)
            {
                // build custom frame

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

                ushort u = (ushort)(1 << 0) | // m_frame type: data
                           (0 << 3) |         // security: none
                           (0 << 4) |         // m_frame 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
                b[++cInd] = (byte)(u & 0xFF);
                b[++cInd] = (byte)(u >> 8);
                // Append sequence number.
                b[++cInd] = (byte)i; // seq no
                u         = 1;       // pan id
                b[++cInd] = (byte)(u & 0xFF);
                b[++cInd] = (byte)(u >> 8);
                u         = 2;
                b[++cInd] = (byte)(u & 0xFF);
                b[++cInd] = (byte)(u >> 8);
                u         = 3;
                b[++cInd] = (byte)(u & 0xFF);
                b[++cInd] = (byte)(u >> 8);
                b[++cInd] = 0xDE;
                b[++cInd] = 0xAD;
                b[++cInd] = 0xBE;
                b[++cInd] = 0xEF;                           // dead beef
                m_frame.AppendToBack(b, 0, cInd + 1 + 100); // payload
                do
                {
                    phy.DataRequest(m_frame, out status);
                } while (status != Status.Success);
                DateTime curTime = DateTime.Now;
                Debug.Print("Frame " + (byte)i + " is sent at " + curTime.Second + ":" + curTime.Millisecond);

                Thread.Sleep(2000);
            }
        }
Ejemplo n.º 3
0
        public void TestSend()
        {
            phy.SetPower(true);
            phy.SetAutoFCS(true);
            int mtu, head, tail;

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

            PibValue value = new PibValue();
            Status   status;

            value.Int = 11;
            phy.SetRequest(PibAttribute.phyCurrentChannel, value, out status);
            Assert(status == Status.Success);

            value.Int = 0;
            phy.SetRequest(PibAttribute.phyTransmitPower, value, out status);
            Assert(status == Status.Success);

            phy.DataIndication = phy_DataIndicationDummy;
            phy.SetTrxStateRequest(State.RxOn, out status);
            byte[]   packetData = new byte[100];
            Frame    frame      = Frame.GetFrame(115);
            DateTime prevTime   = DateTime.Now;

            byte[] b = new byte[128];

            Thread.Sleep(10);

            for (int i = 0;; ++i)
            {
                // build custom frame

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

                ushort u = (ushort)(1 << 0) | // frame type: data
                           (0 << 3) |         // security: none
                           (0 << 4) |         // frame 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
                b[++cInd] = (byte)(u & 0xFF);
                b[++cInd] = (byte)(u >> 8);
                // Append sequence number.
                b[++cInd] = (byte)i;    // seq no
                if (b[cInd] == 0)
                {
                    DateTime curTime = DateTime.Now;
                    TimeSpan diff    = curTime - prevTime;
                    prevTime = curTime;
                    Debug.Print("New Frame " + i + " Frames per second: " + 2560000000L / diff.Ticks + " Time " + curTime.Second);
                }

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