public PhySendReceive(State state, IPhy phy, SendReceiveCallbacks mac) { _state = state; _phy = phy; _mac = mac; _ackPending = false; _ackReceived = new AutoResetEvent(false); _phy.IsCapabilitySupported(Capabilities.AutoFcs, out _phyCapAutoFCS); if (_phyCapAutoFCS) { _phy.SetAutoFCS(true); } _phy.IsCapabilitySupported(Capabilities.AddressFilter, out _phyCapAddressFilter); _phy.IsCapabilitySupported(Capabilities.AutoAck, out _phyCapAutoAck); _phy.IsCapabilitySupported(Capabilities.TxCache, out _phyCapTxCache); _filterEnabled = false; }
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); } }
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); } }