Esempio n. 1
0
        public void TestReceiveDump()
        {
            phy.SetPower(true);

            // page 0
            Status   status;
            PibValue value = new PibValue();

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

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

            // sniff
            phy.DataIndication = phy_DataIndicationDump;
            phy.SetTrxStateRequest(State.RxOn, out status);
            Assert(status == Status.RxOn);

            for (; ;)
            {
                Thread.Sleep(5000);
            }
        }
 public TaskSetRequest(
     PibAttribute attribute,
     int index,
     PibValue value,
     SetConfirmHandler handler)
     : base(TaskType.SetRequest)
 {
     this.attribute = attribute;
     this.index     = index;
     this.value     = value;
     this.handler   = handler;
 }
Esempio n. 3
0
        private void SetBeaconPayload()
        {
            Frame frame = Frame.GetFrame(8);

            frame.AllocBack(8);
            frame.WriteCanonical(0, NetworkLayer.cMeshId);

            PibValue value = new PibValue();

            value.Frame = frame;
            _net.Mac.SetRequest(PibAttribute.macBeaconPayload, 0, value, null);
        }
Esempio n. 4
0
        private void HandleAddressReply(
            MacAddress srcAddr,
            MacAddress dstAddr,
            ref Frame sdu)
        {
            Message.AddressReply arep = new Message.AddressReply();
            if (arep.ReadFromFrame(sdu))
            {
                if (dstAddr.Mode == MacAddressingMode.ExtendedAddress && dstAddr.ExtendedAddress == _addrExt)
                {
                    // address is for us
                    if (_addrShort == cUnallocatedShortAddr)
                    {
                        _addrShort = arep.ShortAddr;

                        PibValue value = new PibValue();
                        value.Int = _addrShort;
                        _mac.SetRequest(PibAttribute.macShortAddress, 0, value, null);

                        _getAddressEvent.Set();

                        SetDiscoveryTimer(arep.DiscoveryInterval);
                    }
                }
                else
                {
                    if (arep.HopsLeft > 0)
                    {
                        arep.HopsLeft--;
                        Frame frame = Frame.GetFrame(_macHeader, Message.AddressRequest.cLength + _macTailer);
                        if (arep.WriteToFrame(frame))
                        {
                            if (arep.BrokerAddr == _addrShort)
                            {
                                // we are the broker
                                MacDataRequest(arep.DeviceAddr, ref frame);
                            }
                            else
                            {
                                // forward to broker
                                _routingTable.DataRequest(arep.BrokerAddr, ref frame, 0, null, true);
                            }
                        }

                        Frame.Release(ref frame);
                    }
                }
            }
        }
Esempio n. 5
0
        public void SetRequest(
            PibAttribute attribute,
            int index,
            PibValue value,
            SetConfirmHandler handler)
        {
            TaskSetRequest task = new TaskSetRequest(
                attribute,
                index,
                value,
                handler);

            if (!_taskQueue.Add(task) && handler != null)
            {
                handler.Invoke(this, MacEnum.Congested, attribute, index);
            }
        }
Esempio n. 6
0
        // handler for MacGetRequest for supported channels
        private void HandlerChannelsSupported(
            IMacMgmtSap sender,
            MacEnum status,
            PibAttribute attribute,
            int attributeIndex,
            PibValue value)
        {
            if (!_scanning || attribute != PibAttribute.phyChannelsSupported)
            {
                return;
            }

            if (status != MacEnum.Success)
            {
                FinishScanning(Status.Error);
                return;
            }

            _scanChannels        = value.IntArray;
            _scanChannelsCurrent = 0;

            ScanNextPage();
        }
Esempio n. 7
0
        private void FinalizeStartup(Status result)
        {
            if (result == Status.Success)
            {
                _data.StartData(_addrShort);
                _neighbourTable.Start(_addrShort);

                // tune MAC attributes
                PibValue value = new PibValue();
                // set macMinBE (backoff exponent) to 1. SW-MAC is slow enough
                value.Int = 1;
                _mac.SetRequest(PibAttribute.macMinBE, 0, value, null);
                // set macMaxFrameRetries to 7. Agressive retries to avoid upper layer dealing with link errors
                value.Int = 7;
                _mac.SetRequest(PibAttribute.macMaxFrameRetries, 0, value, null);
            }
            else
            {
                _isRunning = false;
            }

            if (_startConfirmHandler != null)
                _startConfirmHandler.Invoke(this, result, _addrShort);
        }
Esempio n. 8
0
        public void TestReceive()
        {
            phy.SetPower(true);

            phy.DataIndication = phy_DataIndicationDummy;

            // EDRequest
            {
                Debug.Print("EDRequest");
                Status status;
                Byte energyLevel;

                phy.SetTrxStateRequest(State.TRxOff, out status);
                Assert(status == Status.TRxOff);

                phy.EDRequest(out status, out energyLevel);
                Assert(status == Status.TRxOff);

                phy.SetTrxStateRequest(State.RxOn, out status);
                Assert(status == Status.RxOn);

                for (int i = 0; i < 50; i++)
                {
                    leds.color = Leds.Color.Blue;
                    for (int channel = 11; channel <= 26; channel++)
                    {
                        PibValue value = new PibValue();
                        value.Int = channel;
                        phy.SetRequest(PibAttribute.phyCurrentChannel, value, out status);
                        Assert(status == Status.Success);

                        phy.EDRequest(out status, out energyLevel);
                        if (status == Status.Success)
                        {
                            String s = String.Empty;
                            s += "ED: " + energyLevel + " on " + channel;
                            Debug.Print(s);
                        }
                    }

                    leds.color = Leds.Color.Off;
                    System.Threading.Thread.Sleep(100);
                }
            }

            // CCARequest
            {
                Debug.Print("CCA");
                PibValue value = new PibValue();
                value.Int = 11;
                Status status;
                phy.SetRequest(PibAttribute.phyCurrentChannel, value, out status);
                Assert(status == Status.Success);

                phy.SetTrxStateRequest(State.RxOn, out status);
                Assert(status == Status.RxOn);

                DateTime start = DateTime.Now;
                TimeSpan duration = new TimeSpan(0, 0, 5);
                while(DateTime.Now-start < duration) {
                    phy.CCARequest(out status);
                    if (status == Status.Busy)
                        leds.color = Leds.Color.Yellow;
                    else
                        leds.color = Leds.Color.Off;
                }

                leds.color = Leds.Color.Off;
            }

            // DataIndication
            phy.SetAutoFCS(true);
            phy.SetAddressFilter(true, 2, 1, false); // ok, no recv for other short addr/pan id
            phy.SetAutoAck(true);

            phy.DataIndication = phy_DataIndicationFlash;
            {
                Status status;
                phy.SetTrxStateRequest(State.RxOn, out status);
                Assert(status == Status.RxOn);

                Thread.Sleep(5000);
            }
        }
        private void GetRequest(TaskGetRequest task)
        {
            if (task == null)
            {
                return;
            }
            if (task.handler == null)
            {
                return;
            }

            MacEnum  status = MacEnum.Success;
            PibValue value  = new PibValue();

            lock (_state)
            {
                switch (task.attribute)
                {
                case PibAttribute.phyCurrentChannel:
                case PibAttribute.phyChannelsSupported:
                case PibAttribute.phyTransmitPower:
                case PibAttribute.phyCCAMode:
                case PibAttribute.phyCurrentPage:
                case PibAttribute.phyMaxFrameDuration:
                case PibAttribute.phySHRDuration:
                case PibAttribute.phySymbolsPerOctet:
                {
                    Phy.Status   statusPhy;
                    Phy.PibValue valPhy;
                    _phy.GetRequest((Phy.PibAttribute)task.attribute, out statusPhy, out valPhy);

                    if (statusPhy == Phy.Status.Success)
                    {
                        switch (valPhy.Type)
                        {
                        case Phy.PibValue.ValueType.Int:
                            value.Int = valPhy.Int;
                            break;

                        case Phy.PibValue.ValueType.IntArray:
                            value.IntArray = valPhy.IntArray;
                            break;

                        case Phy.PibValue.ValueType.Float:
                            value.Float = valPhy.Float;
                            break;
                        }
                    }
                    else
                    {
                        status = MacEnum.UnsupportedAttribute;
                    }
                    break;
                }

                case PibAttribute.macBeaconPayload:
                {
                    Frame frame   = null;
                    Frame payload = _state.macBeaconPayload;
                    if (payload != null)
                    {
                        frame = Frame.GetFrame(payload.LengthDataUsed);
                        frame.WriteToBack(payload);
                    }

                    value.Frame = frame;
                    break;
                }

                case PibAttribute.macPanId:
                {
                    value.Int = _state.macPanId;
                    break;
                }

                case PibAttribute.macPromiscuousMode:
                {
                    value.Bool = _state.macPromiscousMode;
                    break;
                }

                case PibAttribute.macShortAddress:
                {
                    value.Int = _state.macShortAddr;
                    break;
                }

                case PibAttribute.macBeaconOrder:
                {
                    value.Int = _state.macBeaconOrder;
                    break;
                }

                case PibAttribute.macSuperframeOrder:
                {
                    value.Int = _state.macBeaconOrder;
                    break;
                }

                case PibAttribute.macMinBE:
                {
                    value.Int = _state.macMinBE;
                    break;
                }

                case PibAttribute.macMaxBE:
                {
                    value.Int = _state.macMaxBE;
                    break;
                }

                case PibAttribute.macMaxCSMABackoffs:
                {
                    value.Int = _state.macMaxCSMABackoffs;
                    break;
                }

                case PibAttribute.macMaxFrameRetries:
                {
                    value.Int = _state.macMaxFrameRetries;
                    break;
                }

                case PibAttribute.macAckWaitDuration:
                case PibAttribute.macAssociatedPANCoord:
                case PibAttribute.macAssociationPermit:
                case PibAttribute.macAutoRequest:
                case PibAttribute.macBattLifeExt:
                case PibAttribute.macBattLifeExtPeriods:
                case PibAttribute.macBeaconTxTime:
                case PibAttribute.macBSN:
                case PibAttribute.macCoordExtendedAddress:
                case PibAttribute.macCoordShortAddress:
                case PibAttribute.macDSN:
                case PibAttribute.macGTSPermit:
                case PibAttribute.macMaxFrameTotalWaitTime:
                case PibAttribute.macResponseWaitTime:
                case PibAttribute.macRxOnWhenIdle:
                case PibAttribute.macSecurityEnabled:
                case PibAttribute.macSyncSymbolOffset:
                case PibAttribute.macTimestampSupported:
                case PibAttribute.macTransactionPersistenceTime:
                    status = MacEnum.UnsupportedAttribute;
                    Trace.Print("MacGetRequest: unsupported attribute");
                    break;
                }
            }

            if (task.handler != null)
            {
                task.handler.Invoke(this, status, task.attribute, task.attributeIndex, value);
            }
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        public void TestReceiveDump()
        {
            phy.SetPower(true);

            // page 0
            Status status;
            PibValue value = new PibValue();
            value.Int = 0;
            phy.SetRequest(PibAttribute.phyCurrentPage, value, out status);
            Assert(status == Status.Success);

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

            // sniff
            phy.DataIndication = phy_DataIndicationDump;
            phy.SetTrxStateRequest(State.RxOn, out status);
            Assert(status == Status.RxOn);

            for(;;)
                Thread.Sleep(5000);
        }
Esempio n. 12
0
        public void TestReceive()
        {
            phy.SetPower(true);

            phy.DataIndication = phy_DataIndicationDummy;

            // EDRequest
            {
                Debug.Print("EDRequest");
                Status status;
                Byte   energyLevel;

                phy.SetTrxStateRequest(State.TRxOff, out status);
                Assert(status == Status.TRxOff);

                phy.EDRequest(out status, out energyLevel);
                Assert(status == Status.TRxOff);

                phy.SetTrxStateRequest(State.RxOn, out status);
                Assert(status == Status.RxOn);
                for (int i = 0; i < 5; i++)
                {
                    leds.color = Leds.Color.Blue;
                    for (int channel = 11; channel <= 26; channel++)
                    {
                        PibValue value = new PibValue();
                        value.Int = channel;
                        phy.SetRequest(PibAttribute.phyCurrentChannel, value, out status);
                        Assert(status == Status.Success);

                        phy.EDRequest(out status, out energyLevel);
                        if (status == Status.Success)
                        {
                            String s = String.Empty;
                            s += "ED: " + energyLevel + " on " + channel;
                            Debug.Print(s);
                        }
                    }

                    leds.color = Leds.Color.Off;
                    System.Threading.Thread.Sleep(100);
                }
            }

            // CCARequest
            {
                Debug.Print("CCA");
                PibValue value = new PibValue();
                value.Int = 11;
                Status status;
                phy.SetRequest(PibAttribute.phyCurrentChannel, value, out status);
                Assert(status == Status.Success);

                phy.SetTrxStateRequest(State.RxOn, out status);
                Assert(status == Status.RxOn);

                DateTime start    = DateTime.Now;
                TimeSpan duration = new TimeSpan(0, 0, 5);
                while (DateTime.Now - start < duration)
                {
                    phy.CCARequest(out status);
                    if (status == Status.Busy)
                    {
                        leds.color = Leds.Color.Yellow;
                    }
                    else
                    {
                        leds.color = Leds.Color.Off;
                    }
                }

                leds.color = Leds.Color.Off;
            }

            // DataIndication
            phy.SetAutoFCS(true);
            phy.SetAddressFilter(true, 2, 1, false); // ok, no recv for other short addr/pan id
            phy.SetAutoAck(true);

            phy.DataIndication = phy_DataIndicationFlash;
            {
                Status status;
                phy.SetTrxStateRequest(State.RxOn, out status);
                Assert(status == Status.RxOn);

                Thread.Sleep(5000);
            }
        }
Esempio n. 13
0
        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);
                // Assert(value.Int == -25); // min CC tx power

                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);
        }
Esempio n. 14
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);
            }
        }
Esempio n. 15
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);
            }
        }
Esempio n. 16
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);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// To start the network layer
        /// </summary>
        /// <param name="panId">Pan ID of the network to set on Mac layer</param>
        /// <param name="panCoordinator">True if this node is the network coordinator</param>
        /// <param name="logicalChannel">Logical channel to use</param>
        /// <param name="channelPage">Channel page to use</param>
        /// <param name="neighours">Set of neighbors to bootstrap. Not used when started as network coordinator</param>
        /// <param name="handler">Handler for confirmation message</param>
        public void Start(UInt16 panId, bool netCoordinator, byte logicalChannel, byte channelPage, UInt16[] neighours, StartConfirmHandler handler)
        {
            if (_isRunning)
            {
                if (handler != null)
                    handler.Invoke(this, Status.Busy, 0);
                return;
            }

            _isRunning = true;
            _panId = panId;
            _startConfirmHandler = handler;

            if (netCoordinator)
            {
                _addrShort = cCoordinatorShortAddr;
                _addrServer = new AddressAndDiscoveryServer(this); // always exists if isAddrServer is true
            }
            else
            {
                _addrShort = cUnallocatedShortAddr;
                _addrServer = null;
            }

            _isAddrServer = netCoordinator;
            _mac.DataIndication = MacDataIndHandler;
            _mac.GetDeviceAddress(out _addrExt);

            PibValue value = new PibValue();
            value.Int = _addrShort;
            _mac.SetRequest(PibAttribute.macShortAddress, 0, value, null);

            AutoResetEvent startEvent = new AutoResetEvent(false);
            Status result = Status.Error;
            _mac.StartRequest(_panId,
                logicalChannel,
                channelPage,
                0, 15, 0,
                netCoordinator,
                false, false,
                new SecurityOptions(), new SecurityOptions(), delegate(
                    IMacMgmtSap sender,
                    MacEnum status)
                    {
                        if (status == MacEnum.Success)
                            result = Status.Success;
                        startEvent.Set();
                    });

            startEvent.WaitOne();

            if (result == Status.Success && !_isAddrServer)
            {
                _getAddressNeighbors = neighours;
                _getAddressCancel = false;
                _getAddressEvent.Reset();
                _getAddressThread = new Thread(GetAddressThread);
#if !MICROFRAMEWORK
                _getAddressThread.IsBackground = true;
#endif
                _getAddressThread.Start();
            }
            else
            {
                FinalizeStartup(result);
            }
        }
Esempio n. 18
0
 public void SetRequest(
     PibAttribute attribute,
     int index,
     PibValue value,
     SetConfirmHandler handler)
 {
     TaskSetRequest task = new TaskSetRequest(
         attribute,
         index,
         value,
         handler);
     if (!_taskQueue.Add(task) && handler != null)
     {
         handler.Invoke(this, MacEnum.Congested, attribute, index);
     }
 }