Example #1
0
 public void GetRequest(
     PibAttribute attribute,
     int attributeIndex,
     GetConfirmHandler handler)
 {
     TaskGetRequest task = new TaskGetRequest(
         attribute,
         attributeIndex,
         handler);
     if (!_taskQueue.Add(task) && handler != null)
     {
         handler.Invoke(this, MacEnum.Congested, attribute, attributeIndex, new PibValue());
     }
 }
        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);
            }
        }