예제 #1
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);
            }
        }
예제 #2
0
        private void SetRequest(TaskSetRequest task)
        {
            if (task == null)
                return;

            MacEnum status = MacEnum.Success;
            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 value = new Phy.PibValue();
                            switch (task.value.Type)
                            {
                                case PibValue.ValueType.Int:
                                    value.Int = task.value.Int;
                                    break;
                                case PibValue.ValueType.IntArray:
                                    value.IntArray = task.value.IntArray;
                                    break;
                                case PibValue.ValueType.Float:
                                    value.Float = task.value.Float;
                                    break;
                            }

                            _phy.SetRequest((Phy.PibAttribute)task.attribute, value, out statusPhy);

                            if (statusPhy != Phy.Status.Success)
                            {
                                if (statusPhy == Phy.Status.InvalidParam)
                                    status = MacEnum.InvalidParameter;
                                else
                                    status = MacEnum.UnsupportedAttribute;
                            }
                            break;
                        }
                    case PibAttribute.macBeaconPayload:
                        if (task.value.Type == PibValue.ValueType.Frame)
                        {
                            Frame.Release(ref _state.macBeaconPayload);
                            _state.macBeaconPayload = task.value.Frame;
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                        break;
                    case PibAttribute.macPanId:
                        if (task.value.Type == PibValue.ValueType.Int)
                        {
                            _state.macPanId = (UInt16)task.value.Int;
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                        break;
                    case PibAttribute.macPromiscuousMode:
                        if (task.value.Type == PibValue.ValueType.Bool)
                        {
                            _state.macPromiscousMode = task.value.Bool;
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                        break;
                    case PibAttribute.macShortAddress:
                        if (task.value.Type == PibValue.ValueType.Int)
                        {
                            _state.macShortAddr = (UInt16)task.value.Int;
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                        break;
                    case PibAttribute.macBeaconOrder:
                        if (task.value.Type == PibValue.ValueType.Int)
                        {
                            _state.macBeaconOrder = FixParameter((byte)task.value.Int, 0, 15);
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                        break;
                    case PibAttribute.macSuperframeOrder:
                        if (task.value.Type == PibValue.ValueType.Int)
                        {
                            _state.macSuperframeOrder = FixParameter((byte)task.value.Int, 0, 15);
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                        break;
                    case PibAttribute.macMinBE:
                        if (task.value.Type == PibValue.ValueType.Int)
                        {
                            _state.macMinBE = FixParameter((byte)task.value.Int, 0, _state.macMaxBE);
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                        break;
                    case PibAttribute.macMaxBE:
                        if (task.value.Type == PibValue.ValueType.Int)
                        {
                            _state.macMaxBE = FixParameter((byte)task.value.Int, 3, 8);
                            if (_state.macMinBE > _state.macMaxBE)
                                _state.macMinBE = _state.macMaxBE;
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                        break;
                    case PibAttribute.macMaxCSMABackoffs:
                        if (task.value.Type == PibValue.ValueType.Int)
                        {
                            _state.macMaxCSMABackoffs = FixParameter((byte)task.value.Int, 0, 5);
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                        break;
                    case PibAttribute.macMaxFrameRetries:
                        if (task.value.Type == PibValue.ValueType.Int)
                        {
                            _state.macMaxFrameRetries = FixParameter((byte)task.value.Int, 0, 7);
                        }
                        else
                        {
                            status = MacEnum.InvalidParameter;
                        }
                        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("Mac: SetRequest: unsupported attribute");
                        break;
                }
            }

            if (task.handler != null)
            {
                task.handler.Invoke(this, status, task.attribute, task.index);
            }
        }
예제 #3
0
파일: Mac.cs 프로젝트: prabby/miniclr
 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);
     }
 }
        private void SetRequest(TaskSetRequest task)
        {
            if (task == null)
            {
                return;
            }

            MacEnum status = MacEnum.Success;

            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 value = new Phy.PibValue();
                    switch (task.value.Type)
                    {
                    case PibValue.ValueType.Int:
                        value.Int = task.value.Int;
                        break;

                    case PibValue.ValueType.IntArray:
                        value.IntArray = task.value.IntArray;
                        break;

                    case PibValue.ValueType.Float:
                        value.Float = task.value.Float;
                        break;
                    }

                    _phy.SetRequest((Phy.PibAttribute)task.attribute, value, out statusPhy);

                    if (statusPhy != Phy.Status.Success)
                    {
                        if (statusPhy == Phy.Status.InvalidParam)
                        {
                            status = MacEnum.InvalidParameter;
                        }
                        else
                        {
                            status = MacEnum.UnsupportedAttribute;
                        }
                    }
                    break;
                }

                case PibAttribute.macBeaconPayload:
                    if (task.value.Type == PibValue.ValueType.Frame)
                    {
                        Frame.Release(ref _state.macBeaconPayload);
                        _state.macBeaconPayload = task.value.Frame;
                    }
                    else
                    {
                        status = MacEnum.InvalidParameter;
                    }
                    break;

                case PibAttribute.macPanId:
                    if (task.value.Type == PibValue.ValueType.Int)
                    {
                        _state.macPanId = (UInt16)task.value.Int;
                    }
                    else
                    {
                        status = MacEnum.InvalidParameter;
                    }
                    break;

                case PibAttribute.macPromiscuousMode:
                    if (task.value.Type == PibValue.ValueType.Bool)
                    {
                        _state.macPromiscousMode = task.value.Bool;
                    }
                    else
                    {
                        status = MacEnum.InvalidParameter;
                    }
                    break;

                case PibAttribute.macShortAddress:
                    if (task.value.Type == PibValue.ValueType.Int)
                    {
                        _state.macShortAddr = (UInt16)task.value.Int;
                    }
                    else
                    {
                        status = MacEnum.InvalidParameter;
                    }
                    break;

                case PibAttribute.macBeaconOrder:
                    if (task.value.Type == PibValue.ValueType.Int)
                    {
                        _state.macBeaconOrder = FixParameter((byte)task.value.Int, 0, 15);
                    }
                    else
                    {
                        status = MacEnum.InvalidParameter;
                    }
                    break;

                case PibAttribute.macSuperframeOrder:
                    if (task.value.Type == PibValue.ValueType.Int)
                    {
                        _state.macSuperframeOrder = FixParameter((byte)task.value.Int, 0, 15);
                    }
                    else
                    {
                        status = MacEnum.InvalidParameter;
                    }
                    break;

                case PibAttribute.macMinBE:
                    if (task.value.Type == PibValue.ValueType.Int)
                    {
                        _state.macMinBE = FixParameter((byte)task.value.Int, 0, _state.macMaxBE);
                    }
                    else
                    {
                        status = MacEnum.InvalidParameter;
                    }
                    break;

                case PibAttribute.macMaxBE:
                    if (task.value.Type == PibValue.ValueType.Int)
                    {
                        _state.macMaxBE = FixParameter((byte)task.value.Int, 3, 8);
                        if (_state.macMinBE > _state.macMaxBE)
                        {
                            _state.macMinBE = _state.macMaxBE;
                        }
                    }
                    else
                    {
                        status = MacEnum.InvalidParameter;
                    }
                    break;

                case PibAttribute.macMaxCSMABackoffs:
                    if (task.value.Type == PibValue.ValueType.Int)
                    {
                        _state.macMaxCSMABackoffs = FixParameter((byte)task.value.Int, 0, 5);
                    }
                    else
                    {
                        status = MacEnum.InvalidParameter;
                    }
                    break;

                case PibAttribute.macMaxFrameRetries:
                    if (task.value.Type == PibValue.ValueType.Int)
                    {
                        _state.macMaxFrameRetries = FixParameter((byte)task.value.Int, 0, 7);
                    }
                    else
                    {
                        status = MacEnum.InvalidParameter;
                    }
                    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("Mac: SetRequest: unsupported attribute");
                    break;
                }
            }

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