Beispiel #1
0
        /**
         * Performs an energy scan and returns the quietest channel
         *
         * @param channelMask the channel mask on which to perform the scan.
         * @param scanDuration Sets the exponent of the number of scan periods, where a scan period is 960 symbols. The scan
         *            will occur for ((2^duration) + 1) scan periods.
         * @return a List of {@link EzspNetworkFoundHandler} on success. If there was an error during the scan, null is
         *         returned.
         */
        public List <EzspEnergyScanResultHandler> DoEnergyScan(int channelMask, int scanDuration)
        {
            EzspStartScanRequest energyScan = new EzspStartScanRequest();

            energyScan.SetChannelMask(channelMask);
            energyScan.SetDuration(scanDuration);
            energyScan.SetScanType(EzspNetworkScanType.EZSP_ENERGY_SCAN);

            HashSet <Type> relatedResponses = new HashSet <Type>()
            {
                typeof(EzspStartScanResponse), typeof(EzspEnergyScanResultHandler)
            };
            IEzspTransaction transaction = _protocolHandler.SendEzspTransaction(new EzspMultiResponseTransaction(energyScan, typeof(EzspScanCompleteHandler), relatedResponses));

            EzspScanCompleteHandler scanCompleteResponse = (EzspScanCompleteHandler)transaction.GetResponse();

            Log.Debug(scanCompleteResponse.ToString());

            List <EzspEnergyScanResultHandler> channels = new List <EzspEnergyScanResultHandler>();

            foreach (EzspFrameResponse network in transaction.GetResponses())
            {
                if (network is EzspEnergyScanResultHandler)
                {
                    channels.Add((EzspEnergyScanResultHandler)network);
                }
            }

            _lastStatus = scanCompleteResponse.GetStatus();

            return(channels);
        }
Beispiel #2
0
        /**
         * Perform an active scan. The radio will try to send beacon request on each channel.
         * <p>
         * During the scan, the CSMA/CA mechanism will be used to detect whether the radio channel is free at that moment.
         * If some of the radio channels in the environment are too busy for the device to perform the scan, the NCP returns
         * EMBER_MAC_COMMAND_TRANSMIT_FAILURE. A clearer RF environment might mitigate this issue.
         *
         * @param channelMask the channel mask on which to perform the scan.
         * @param scanDuration Sets the exponent of the number of scan periods, where a scan period is 960 symbols. The scan
         *            will occur for ((2^duration) + 1) scan periods.
         * @return a List of {@link EzspNetworkFoundHandler} on success. If there was an error during the scan, null is
         *         returned.
         */
        public ICollection <EzspNetworkFoundHandler> DoActiveScan(int channelMask, int scanDuration)
        {
            EzspStartScanRequest activeScan = new EzspStartScanRequest();

            activeScan.SetChannelMask(channelMask);
            activeScan.SetDuration(scanDuration);
            activeScan.SetScanType(EzspNetworkScanType.EZSP_ACTIVE_SCAN);

            HashSet <Type> relatedResponses = new HashSet <Type>()
            {
                typeof(EzspStartScanResponse), typeof(EzspNetworkFoundHandler)
            };
            IEzspTransaction        transaction = _protocolHandler.SendEzspTransaction(new EzspMultiResponseTransaction(activeScan, typeof(EzspScanCompleteHandler), relatedResponses));
            EzspScanCompleteHandler activeScanCompleteResponse = (EzspScanCompleteHandler)transaction.GetResponse();

            Log.Debug(activeScanCompleteResponse.ToString());

            if (activeScanCompleteResponse.GetStatus() != EmberStatus.EMBER_SUCCESS)
            {
                _lastStatus = activeScanCompleteResponse.GetStatus();
                Log.Debug("Error during active scan: {}", activeScanCompleteResponse);
                return(null);
            }

            Dictionary <ExtendedPanId, EzspNetworkFoundHandler> networksFound = new Dictionary <ExtendedPanId, EzspNetworkFoundHandler>();

            foreach (EzspFrameResponse response in transaction.GetResponses())
            {
                if (response is EzspNetworkFoundHandler)
                {
                    EzspNetworkFoundHandler network = (EzspNetworkFoundHandler)response;
                    networksFound[network.GetNetworkFound().GetExtendedPanId()] = network;
                }
            }

            return(networksFound.Values);
        }