Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Starts a new network as coordinator. There shall be only one coordinator per network.
        /// In the current implementation, the PAN-ID is derived from the lower 16 bits of the network ID.
        /// The channel is automatically selected.
        /// </summary>
        /// <param name="netId">unique network ID</param>
        /// <param name="handler">handlder for result</param>
        public void StartRequest(
            UInt16 panId,
            StartConfirmHandler handler)
        {
            if (_running || _scanning)
            {
                if (handler != null)
                    handler.Invoke(_net, Status.Busy, 0, 0, 0);
                return;
            }

            _running = true;
            _panId = panId;
            _startConfirmHandler = handler;
            StartScanning(ScanHandlerStartRequest);
        }
Esempio n. 3
0
        /// <summary>
        /// Starts a new network as coordinator. There shall be only one coordinator per network.
        /// In the current implementation, the PAN-ID is derived from the lower 16 bits of the network ID.
        /// The channel is automatically selected.
        /// </summary>
        /// <param name="netId">unique network ID</param>
        /// <param name="handler">handlder for result</param>
        public void StartRequest(
            UInt16 panId,
            StartConfirmHandler handler)
        {
            if (_running || _scanning)
            {
                if (handler != null)
                {
                    handler.Invoke(_net, Status.Busy, 0, 0, 0);
                }
                return;
            }

            _running             = true;
            _panId               = panId;
            _startConfirmHandler = handler;
            StartScanning(ScanHandlerStartRequest);
        }
Esempio n. 4
0
 private void StartHandlerStartRequest(
     Routing sender,
     Status status,
     UInt16 shortAddr)
 {
     if (!_running)
     {
         return;
     }
     if (status == Status.Success)
     {
         SetBeaconPayload();
     }
     if (_startConfirmHandler != null)
     {
         _startConfirmHandler.Invoke(_net, status, shortAddr, _logicalChannel, _channelPage);
     }
     if (status != Status.Success)
     {
         _running = false;
     }
 }
Esempio n. 5
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. 6
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. 7
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);
     }
 }