Пример #1
0
        private void StartRequest(TaskStartRequest task)
        {
            if (task == null)
                return;

            MacEnum status = MacEnum.Success;
            lock (_state)
            {
                // test short addr
                if (status == MacEnum.Success)
                {
                    if (_state.macShortAddr == State.cReservedShortAddr)
                    {
                        status = MacEnum.NoShortAddress;
                    }
                }

                // test beacon
                if (status == MacEnum.Success)
                {
                    // need to check if beacon does not exceed size when applying given security.
                    // as security is not yet implemented, nothing to do here
                    //MacEnum.FrameTooLong
                }

                // set page
                if (status == MacEnum.Success)
                {
                    if (_state.phyChannelPage != task.channelPage)
                    {
                        int channelPage = task.channelPage;
                        Phy.Status statusPhy;
                        Phy.PibValue value = new Phy.PibValue();
                        value.Int = channelPage;
                        _phy.SetRequest(Phy.PibAttribute.phyCurrentPage, value, out statusPhy);
                        if (statusPhy == Phy.Status.Success)
                        {
                            _state.phyChannelPage = task.channelPage;
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                    }
                }

                // set channel
                if (status == MacEnum.Success)
                {
                    if (_state.phyChannelNumber != task.logicalChannel)
                    {
                        Phy.Status statusPhy;
                        Phy.PibValue value = new Phy.PibValue();
                        value.Int = task.logicalChannel;
                        _phy.SetRequest(Phy.PibAttribute.phyCurrentChannel, value, out statusPhy);
                        if (statusPhy == Phy.Status.Success)
                        {
                            _state.phyChannelNumber = task.logicalChannel;
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                    }
                }

                // FIXME: ignoring various parameters for now
                //UInt16 startTime;
                //byte beaconOrder;
                //byte superframeOrder;
                //bool batteryLifeExtension;
                //bool coordRealignment;
                //SecurityOptions coordRealignSecutiryOptions;
                //SecurityOptions beaconSecurityOptions;

                if (status == MacEnum.Success)
                {
                    _state.macPanId = task.panId;
                    _state.panCoordinator = task.panCoordinator;
                    _state.autoBeacon = true;
                    _sendReceive.Start();
                }
            }

            if (task.handler != null)
                task.handler.Invoke(this, status);
        }
Пример #2
0
 public void StartRequest(
     UInt16 panId,
     Byte logicalChannel,
     Byte channelPage,
     UInt16 startTime,
     byte beaconOrder,
     byte superframeOrder,
     bool panCoordinator,
     bool batteryLifeExtension,
     bool coordRealignment,
     SecurityOptions coordRealignSecutiryOptions,
     SecurityOptions beaconSecurityOptions,
     StartConfirmHandler handler)
 {
     TaskStartRequest task = new TaskStartRequest(
         panId,
         logicalChannel,
         channelPage,
         startTime,
         beaconOrder,
         superframeOrder,
         panCoordinator,
         batteryLifeExtension,
         coordRealignment,
         coordRealignSecutiryOptions,
         beaconSecurityOptions,
         handler);
     if (!_taskQueue.Add(task) && handler != null)
     {
         handler.Invoke(this, MacEnum.Congested);
     }
 }
Пример #3
0
        private void StartRequest(TaskStartRequest task)
        {
            if (task == null)
            {
                return;
            }

            MacEnum status = MacEnum.Success;

            lock (_state)
            {
                // test short addr
                if (status == MacEnum.Success)
                {
                    if (_state.macShortAddr == State.cReservedShortAddr)
                    {
                        status = MacEnum.NoShortAddress;
                    }
                }

                // test beacon
                if (status == MacEnum.Success)
                {
                    // need to check if beacon does not exceed size when applying given security.
                    // as security is not yet implemented, nothing to do here
                    //MacEnum.FrameTooLong
                }

                // set page
                if (status == MacEnum.Success)
                {
                    if (_state.phyChannelPage != task.channelPage)
                    {
                        int          channelPage = task.channelPage;
                        Phy.Status   statusPhy;
                        Phy.PibValue value = new Phy.PibValue();
                        value.Int = channelPage;
                        _phy.SetRequest(Phy.PibAttribute.phyCurrentPage, value, out statusPhy);
                        if (statusPhy == Phy.Status.Success)
                        {
                            _state.phyChannelPage = task.channelPage;
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                    }
                }

                // set channel
                if (status == MacEnum.Success)
                {
                    if (_state.phyChannelNumber != task.logicalChannel)
                    {
                        Phy.Status   statusPhy;
                        Phy.PibValue value = new Phy.PibValue();
                        value.Int = task.logicalChannel;
                        _phy.SetRequest(Phy.PibAttribute.phyCurrentChannel, value, out statusPhy);
                        if (statusPhy == Phy.Status.Success)
                        {
                            _state.phyChannelNumber = task.logicalChannel;
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                    }
                }

                // FIXME: ignoring various parameters for now
                //UInt16 startTime;
                //byte beaconOrder;
                //byte superframeOrder;
                //bool batteryLifeExtension;
                //bool coordRealignment;
                //SecurityOptions coordRealignSecutiryOptions;
                //SecurityOptions beaconSecurityOptions;

                if (status == MacEnum.Success)
                {
                    _state.macPanId       = task.panId;
                    _state.panCoordinator = task.panCoordinator;
                    _state.autoBeacon     = true;
                    _sendReceive.Start();
                }
            }

            if (task.handler != null)
            {
                task.handler.Invoke(this, status);
            }
        }