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 State(StateCallbacks callback, IPhy phy) { _callback = callback; phy.GetDeviceAddress(out aExtendedAddress); int phyMtu; phy.GetMtuSize(out phyMtu, out phyFrameHead, out phyFrameTail); phy.IsCapabilitySupported(Capabilities.Ieee2006, out phySupports2006); Reset(); }
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; }
/// <summary> /// Get required header space for data frames to be sent /// </summary> public void GetMtuSize(out int mtu, out int head, out int tail) { _phy.GetMtuSize(out mtu, out head, out tail); bool b; _phy.IsCapabilitySupported(Capabilities.Ieee2006, out b); if (b) { // if header is small, payload can be larger mtu = State.aMaxMacPayloadSize; } else { mtu = State.aMaxMACSafePayloadSize; } head += State.aMaxFrameOverhead; tail += 2; // FCS }
private bool _rxThreadExit; // A flag that tells the receive thread to exit public MacLayer(IPhy phy) { // poweron Phy first _phy = phy; _phy.IsCapabilitySupported(Capabilities.PowerOff, out _phyCapPower); if (_phyCapPower) { _phy.SetPower(true); // should be on-demand } _state = new State(this, phy); _taskAddedEvent = new AutoResetEvent(false); _taskQueue = new TaskQueue(cQueueCmdSize, cQueueDataSize, _taskAddedEvent); _taskProcessorExit = false; _taskProcessor = new Thread(TaskProcessor); #if !MICROFRAMEWORK _taskProcessor.IsBackground = true; #endif _sendReceive = new PhySendReceive(_state, _phy, this); _scannedBeacons = new ArrayList(); ResetHandler(); // initialize channels Phy.Status status; Phy.PibValue value; _phy.GetRequest(Phy.PibAttribute.phyCurrentPage, out status, out value); _state.phyChannelPage = (Byte)value.Int; _phy.GetRequest(Phy.PibAttribute.phyCurrentChannel, out status, out value); _state.phyChannelNumber = (Byte)value.Int; _rxFrameQueue = new Frame.Queue(cQueueRxSize, true, 0); _rxThread = new Thread(DataIndicationThread); #if !MICROFRAMEWORK _rxThread.IsBackground = true; #endif _rxEvent = new AutoResetEvent(false); _rxThreadExit = false; _rxThread.Start(); _taskProcessor.Start(); }
private bool _rxThreadExit; // A flag that tells the receive thread to exit public MacLayer(IPhy phy) { // poweron Phy first _phy = phy; _phy.IsCapabilitySupported(Capabilities.PowerOff, out _phyCapPower); if (_phyCapPower) { _phy.SetPower(true); // should be on-demand } _state = new State(this, phy); _taskAddedEvent = new AutoResetEvent(false); _taskQueue = new TaskQueue(cQueueCmdSize, cQueueDataSize, _taskAddedEvent); _taskProcessorExit = false; _taskProcessor = new Thread(TaskProcessor); #if !MICROFRAMEWORK _taskProcessor.IsBackground = true; #endif _sendReceive = new PhySendReceive(_state, _phy, this); _scannedBeacons = new ArrayList(); ResetHandler(); // initialize channels Phy.Status status; Phy.PibValue value; _phy.GetRequest(Phy.PibAttribute.phyCurrentPage, out status, out value); _state.phyChannelPage = (Byte)value.Int; _phy.GetRequest(Phy.PibAttribute.phyCurrentChannel, out status, out value); _state.phyChannelNumber = (Byte)value.Int; _rxFrameQueue = new Frame.Queue(cQueueRxSize, true, 0); _rxThread = new Thread(DataIndicationThread); #if !MICROFRAMEWORK _rxThread.IsBackground = true; #endif _rxEvent = new AutoResetEvent(false); _rxThreadExit = false; _rxThread.Start(); _taskProcessor.Start(); }
public void TestCommon() { // GetFrameHeaders { int mtu, head, tail; phy.GetMtuSize(out mtu, out head, out tail); Assert(mtu == 127); Assert(head == 2); Assert(tail == 0); } // Capabilities { bool res; phy.IsCapabilitySupported(Capabilities.AddressFilter, out res); Assert(res == true); phy.IsCapabilitySupported(Capabilities.AutoAck, out res); Assert(res == true); phy.IsCapabilitySupported(Capabilities.AutoFcs, out res); Assert(res == true); phy.IsCapabilitySupported(Capabilities.PowerOff, out res); Assert(res == true); } phy.SetPower(true); // GetDeviceAddress { UInt64 mac; phy.GetDeviceAddress(out mac); String s = String.Empty; for (int i = 0; i < 8; i++) { if (i > 0) { s += ":"; } s += HexConverter.ConvertUintToHex((UInt32)((mac >> i * 8) & 0xFF), 2); } Debug.Print(s); } // GetRequest { Status status; PibValue value; // constants phy.GetRequest(PibAttribute.phyChannelsSupported, out status, out value); Assert(status == Status.Success); int[] res = value.IntArray; Assert(res != null); Assert(res.Length == 1); Assert((res[0] & 0xF8000000) == 0); // page 0 for (int i = 0; i <= 27; i++) { bool val = (res[0] & (1 << i)) != 0; bool expected = (i >= 11 && i <= 26); Assert(val == expected); } phy.GetRequest(PibAttribute.phyCCAMode, out status, out value); Assert(status == Status.Success); Assert(value.Int == 3); phy.GetRequest(PibAttribute.phyCurrentPage, out status, out value); Assert(status == Status.Success); Assert(value.Int == 0); phy.GetRequest(PibAttribute.phyMaxFrameDuration, out status, out value); Assert(status == Status.Success); Assert(value.Int == 1064); phy.GetRequest(PibAttribute.phySHRDuration, out status, out value); Assert(status == Status.Success); Assert(value.Int == 40); phy.GetRequest(PibAttribute.phySymbolsPerOctet, out status, out value); Assert(status == Status.Success); Assert(value.Float == 8); // defaults phy.GetRequest(PibAttribute.phyCurrentChannel, out status, out value); Assert(status == Status.Success); Assert(value.Int == 11); phy.GetRequest(PibAttribute.phyTransmitPower, out status, out value); Assert(status == Status.Success); Assert(value.Int == -1); } // SetRequest { // constants Status status; PibValue value = new PibValue(); int[] res = new int[1]; res[0] = 256; value.IntArray = res; phy.SetRequest(PibAttribute.phyChannelsSupported, value, out status); Assert(status == Status.ReadOnly); value.Int = 0; phy.SetRequest(PibAttribute.phyCCAMode, value, out status); Assert(status == Status.ReadOnly); phy.SetRequest(PibAttribute.phyMaxFrameDuration, value, out status); Assert(status == Status.ReadOnly); phy.SetRequest(PibAttribute.phySHRDuration, value, out status); Assert(status == Status.ReadOnly); phy.SetRequest(PibAttribute.phySymbolsPerOctet, value, out status); Assert(status == Status.ReadOnly); // page phy.SetRequest(PibAttribute.phyCurrentPage, value, out status); Assert(status == Status.Success); value.Int = 1; phy.SetRequest(PibAttribute.phyCurrentPage, value, out status); Assert(status == Status.InvalidParam); // channel for (int i = 0; i < 27; i++) { value.Int = i; phy.SetRequest(PibAttribute.phyCurrentChannel, value, out status); if (i >= 11 && i <= 26) { Assert(status == Status.Success); phy.GetRequest(PibAttribute.phyCurrentChannel, out status, out value); Assert(status == Status.Success); Assert(value.Int == i); } else { Assert(status == Status.InvalidParam); } } // power value.Int = -100; phy.SetRequest(PibAttribute.phyTransmitPower, value, out status); Assert(status == Status.InvalidParam); value.Int = -32; phy.SetRequest(PibAttribute.phyTransmitPower, value, out status); Assert(status == Status.Success); phy.GetRequest(PibAttribute.phyTransmitPower, out status, out value); Assert(status == Status.Success); value.Int = 1; phy.SetRequest(PibAttribute.phyTransmitPower, value, out status); Assert(status == Status.Success); phy.GetRequest(PibAttribute.phyTransmitPower, out status, out value); Assert(status == Status.Success); Assert(value.Int == 0); // max CC tx power value.Int = 64; phy.SetRequest(PibAttribute.phyTransmitPower, value, out status); Assert(status == Status.InvalidParam); } phy.SetPower(false); }
public State(StateCallbacks callback, IPhy phy) { _callback = callback; phy.GetDeviceAddress(out aExtendedAddress); int phyMtu; phy.GetMtuSize(out phyMtu, out phyFrameHead, out phyFrameTail); phy.IsCapabilitySupported(Capabilities.Ieee2006, out phySupports2006); Reset(); }