示例#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);
        }
示例#2
0
        /**
         * Gets the current network parameters, or an empty parameters class if there's an error
         *
         * @return {@link EzspGetNetworkParametersResponse}
         */
        public EzspGetNetworkParametersResponse GetNetworkParameters()
        {
            EzspGetNetworkParametersRequest request = new EzspGetNetworkParametersRequest();
            IEzspTransaction transaction            = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetNetworkParametersResponse)));

            return((EzspGetNetworkParametersResponse)transaction.GetResponse());
        }
示例#3
0
        /**
         * Gets the {@link IeeeAddress} of the local node
         *
         * @return the {@link IeeeAddress} of the local node
         */
        public IeeeAddress GetIeeeAddress()
        {
            EzspGetEui64Request  request     = new EzspGetEui64Request();
            IEzspTransaction     transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetEui64Response)));
            EzspGetEui64Response response    = (EzspGetEui64Response)transaction.GetResponse();

            return(response.GetEui64());
        }
示例#4
0
        /**
         * Detects if the standalone bootloader is installed, and if so returns the installed version. If not return 0xffff.
         * A returned version of 0x1234 would indicate version 1.2 build 34.
         *
         * @return the bootloader version. A returned version of 0x1234 would indicate version 1.2 build 34.
         */
        public int GetBootloaderVersion()
        {
            EzspGetStandaloneBootloaderVersionPlatMicroPhyRequest request = new EzspGetStandaloneBootloaderVersionPlatMicroPhyRequest();
            IEzspTransaction transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetStandaloneBootloaderVersionPlatMicroPhyResponse)));
            EzspGetStandaloneBootloaderVersionPlatMicroPhyResponse response = (EzspGetStandaloneBootloaderVersionPlatMicroPhyResponse)transaction.GetResponse();

            return((response == null) ? 0xFFFF : response.GetBootloaderVersion());
        }
示例#5
0
 public TransactionWaiter(IEzspTransaction ezspTransaction, AshFrameHandler frameHandler)
 {
     _ezspTransaction = ezspTransaction;
     _frameHandler    = frameHandler;
     //Without RunContinuationsAsynchronously, calling SetResult can block the calling thread, because the continuation is run synchronously
     //see https://stackoverflow.com/a/37492081
     _tcs = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);
 }
示例#6
0
        /**
         * Sets the radio output power at which a node is operating. Ember radios have discrete power settings. For a list
         * of available power settings, see the technical specification for the RF communication module in your Developer
         * Kit. Note: Care should be taken when using this API on a running network, as it will directly impact the
         * established link qualities neighboring nodes have with the node on which it is called. This can lead to
         * disruption of existing routes and erratic network behavior.
         *
         * @param power Desired radio output power, in dBm.
         * @return the response {@link EmberStatus} of the request
         */
        public EmberStatus SetRadioPower(int power)
        {
            EzspSetRadioPowerRequest request = new EzspSetRadioPowerRequest();

            request.SetPower(power);
            IEzspTransaction          transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspSetRadioPowerResponse)));
            EzspSetRadioPowerResponse response    = (EzspSetRadioPowerResponse)transaction.GetResponse();

            return(response.GetStatus());
        }
示例#7
0
        /**
         * Gets the {@link EmberLibraryStatus} of the requested {@link EmberLibraryId}
         *
         * @return the {@link EmberLibraryStatus} of the local node
         */
        public EmberLibraryStatus GetLibraryStatus(EmberLibraryId libraryId)
        {
            EzspGetLibraryStatusRequest request = new EzspGetLibraryStatusRequest();

            request.SetLibraryId(libraryId);
            IEzspTransaction             transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetLibraryStatusResponse)));
            EzspGetLibraryStatusResponse response    = (EzspGetLibraryStatusResponse)transaction.GetResponse();

            return(response.GetStatus());
        }
示例#8
0
        /**
         * Clears the key table on the NCP
         *
         * @return the {@link EmberStatus} or null on error
         */
        public EmberStatus ClearKeyTable()
        {
            EzspClearKeyTableRequest  request     = new EzspClearKeyTableRequest();
            IEzspTransaction          transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspClearKeyTableResponse)));
            EzspClearKeyTableResponse response    = (EzspClearKeyTableResponse)transaction.GetResponse();

            Log.Debug(response.ToString());
            _lastStatus = response.GetStatus();
            return(_lastStatus);
        }
示例#9
0
        /**
         * Retrieves Ember counters. See the EmberCounterType enumeration for the counter types.
         *
         * @return the array of counters
         */
        public int[] GetCounters()
        {
            EzspReadCountersRequest  request     = new EzspReadCountersRequest();
            IEzspTransaction         transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspReadCountersResponse)));
            EzspReadCountersResponse response    = (EzspReadCountersResponse)transaction.GetResponse();

            Log.Debug(response.ToString());
            _lastStatus = EmberStatus.UNKNOWN;
            return(response.GetValues());
        }
示例#10
0
        /**
         * Returns information about the children of the local node and the parent of the local node.
         *
         * @return the {@link EzspGetParentChildParametersResponse}
         */
        public EzspGetParentChildParametersResponse GetChildParameters()
        {
            EzspGetParentChildParametersRequest request = new EzspGetParentChildParametersRequest();
            IEzspTransaction transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetParentChildParametersResponse)));
            EzspGetParentChildParametersResponse response = (EzspGetParentChildParametersResponse)transaction.GetResponse();

            _lastStatus = EmberStatus.UNKNOWN;

            return(response);
        }
示例#11
0
        /**
         * Returns a value indicating whether the node is joining, joined to, or leaving a network.
         *
         * @return the {@link EmberNetworkStatus}
         */
        public EmberNetworkStatus GetNetworkState()
        {
            EzspNetworkStateRequest  request     = new EzspNetworkStateRequest();
            IEzspTransaction         transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspNetworkStateResponse)));
            EzspNetworkStateResponse response    = (EzspNetworkStateResponse)transaction.GetResponse();

            _lastStatus = EmberStatus.UNKNOWN;

            return(response.GetStatus());
        }
示例#12
0
        /**
         * Gets the current security state that is being used by a device that is joined in the network.
         *
         * @return the {@link EmberNetworkParameters} or null on error
         */
        public EmberCurrentSecurityState getCurrentSecurityState()
        {
            EzspGetCurrentSecurityStateRequest request = new EzspGetCurrentSecurityStateRequest();
            IEzspTransaction transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetCurrentSecurityStateResponse)));
            EzspGetCurrentSecurityStateResponse response = (EzspGetCurrentSecurityStateResponse)transaction.GetResponse();

            Log.Debug(response.ToString());
            _lastStatus = response.GetStatus();
            return(response.GetState());
        }
示例#13
0
        public Task <EzspFrame> SendEzspRequestAsync(IEzspTransaction ezspTransaction)
        {
            if (_parserCancellationToken.IsCancellationRequested)
            {
                Log.Debug("ASH: Handler is closed");
                return(null);
            }

            return(new TransactionWaiter(ezspTransaction, this).Wait());
        }
示例#14
0
        /**
         * Resume network operation after a reboot. The node retains its original type. This should be called on startup
         * whether or not the node was previously part of a network. EMBER_NOT_JOINED is returned if the node is not part of
         * a network.
         *
         * @return {@link EmberStatus} if success or failure
         */
        public EmberStatus NetworkInit()
        {
            EzspNetworkInitRequest  request     = new EzspNetworkInitRequest();
            IEzspTransaction        transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspNetworkInitResponse)));
            EzspNetworkInitResponse response    = (EzspNetworkInitResponse)transaction.GetResponse();

            Log.Debug(response.ToString());

            return(response.GetStatus());
        }
示例#15
0
        /**
         * Tells the stack whether or not the normal interval between retransmissions of a retried unicast message should be
         * increased by EMBER_INDIRECT_TRANSMISSION_TIMEOUT. The interval needs to be increased when sending to a sleepy
         * node so that the message is not retransmitted until the destination has had time to wake up and poll its parent.
         * The stack will automatically extend the timeout:
         * <ul>
         * <li>For our own sleepy children.
         * <li>When an address response is received from a parent on behalf of its child.
         * <li>When an indirect transaction expiry route error is received.
         * <li>When an end device announcement is received from a sleepy node.
         * </ul>
         *
         * @param remoteEui64 the {@link IeeeAddress} of the remote node
         * @param extendedTimeout true if the node should be set with an extended timeout
         * @return the {@link ZigBeeStatus} of the request
         */
        public ZigBeeStatus SetExtendedTimeout(IeeeAddress remoteEui64, bool extendedTimeout)
        {
            EzspSetExtendedTimeoutRequest request = new EzspSetExtendedTimeoutRequest();

            request.SetRemoteEui64(remoteEui64);
            request.SetExtendedTimeout(extendedTimeout);
            IEzspTransaction transaction            = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspSetExtendedTimeoutResponse)));
            EzspSetExtendedTimeoutResponse response = (EzspSetExtendedTimeoutResponse)transaction.GetResponse();

            return((response == null) ? ZigBeeStatus.FAILURE : ZigBeeStatus.SUCCESS);
        }
        private bool CheckNetworkJoined()
        {
            // Check if the network is initialised
            EzspNetworkStateRequest  networkStateRequest     = new EzspNetworkStateRequest();
            IEzspTransaction         networkStateTransaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(networkStateRequest, typeof(EzspNetworkStateResponse)));
            EzspNetworkStateResponse networkStateResponse    = (EzspNetworkStateResponse)networkStateTransaction.GetResponse();

            Log.Debug(networkStateResponse.ToString());
            Log.Debug("EZSP networkStateResponse {Status}", networkStateResponse.GetStatus());

            return(networkStateResponse.GetStatus() == EmberNetworkStatus.EMBER_JOINED_NETWORK);
        }
示例#17
0
        /**
         * Gets the 16 bit network node id of the local node
         *
         * @return the network address of the local node or 0xFFFE if the network address is not known
         */
        public int GetNwkAddress()
        {
            EzspGetNodeIdRequest  request     = new EzspGetNodeIdRequest();
            IEzspTransaction      transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetNodeIdResponse)));
            EzspGetNodeIdResponse response    = (EzspGetNodeIdResponse)transaction.GetResponse();

            if (response == null)
            {
                return(0xFFFE);
            }
            return(response.GetNodeId());
        }
示例#18
0
        /**
         * Gets the {@link EmberCertificate283k1Data} certificate currently stored in the node
         *
         * @return the {@link EmberCertificate283k1Data} certificate
         */
        public EmberCertificate283k1Data GetCertificate283k1Data()
        {
            EzspGetCertificate283k1Request request   = new EzspGetCertificate283k1Request();
            IEzspTransaction transaction             = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetCertificate283k1Response)));
            EzspGetCertificate283k1Response response = (EzspGetCertificate283k1Response)transaction.GetResponse();

            _lastStatus = response.GetStatus();
            if (response.GetStatus() != EmberStatus.EMBER_SUCCESS)
            {
                Log.Debug("Error getting 283k1 certificate: {}", response);
                return(null);
            }

            return(response.GetLocalCert());
        }
示例#19
0
        /**
         * This function updates an existing entry in the key table or adds a new one. It first searches the table for an
         * existing entry that matches the passed EUI64 address. If no entry is found, it searches for the first free entry.
         * If successful, it updates the key data and resets the associated incoming frame counter. If it fails to find an
         * existing entry and no free one exists, it returns a failure.
         *
         * @param address the {@link IeeeAddress}
         * @param key the {@link ZigBeeKey}
         * @param linkKey This indicates whether the key is a Link or a Master Key
         * @return the returned {@link EmberStatus} of the request
         */
        public EmberStatus AddOrUpdateKeyTableEntry(IeeeAddress address, ZigBeeKey key, bool linkKey)
        {
            EmberKeyData keyData = new EmberKeyData();

            keyData.SetContents(Array.ConvertAll(key.Key, c => (int)c));

            EzspAddOrUpdateKeyTableEntryRequest request = new EzspAddOrUpdateKeyTableEntryRequest();

            request.SetAddress(address);
            request.SetKeyData(keyData);
            request.SetLinkKey(linkKey);
            IEzspTransaction transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspAddOrUpdateKeyTableEntryResponse)));
            EzspAddOrUpdateKeyTableEntryResponse response = (EzspAddOrUpdateKeyTableEntryResponse)transaction.GetResponse();

            return(response.GetStatus());
        }
示例#20
0
        /**
         * Set a configuration value
         *
         * @param configId the {@link EzspConfigId} to set
         * @param value the value to set
         * @return the {@link EzspStatus} of the response
         */
        public EzspStatus SetConfiguration(EzspConfigId configId, int value)
        {
            EzspSetConfigurationValueRequest request = new EzspSetConfigurationValueRequest();

            request.SetConfigId(configId);
            request.SetValue(value);
            Log.Debug(request.ToString());

            IEzspTransaction transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspSetConfigurationValueResponse)));
            EzspSetConfigurationValueResponse response = (EzspSetConfigurationValueResponse)transaction.GetResponse();

            _lastStatus = EmberStatus.UNKNOWN;
            Log.Debug(response.ToString());

            return(response.GetStatus());
        }
示例#21
0
        /**
         * Returns information about a child of the local node.
         *
         * @param childId the ID of the child to get information on
         * @return the {@link EzspGetChildDataResponse} of the requested childId or null on error
         */
        public EzspGetChildDataResponse GetChildInformation(int childId)
        {
            EzspGetChildDataRequest request = new EzspGetChildDataRequest();

            request.SetIndex(childId);
            IEzspTransaction         transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetChildDataResponse)));
            EzspGetChildDataResponse response    = (EzspGetChildDataResponse)transaction.GetResponse();

            Log.Debug(response.ToString());
            _lastStatus = response.GetStatus();
            if (_lastStatus != EmberStatus.EMBER_SUCCESS)
            {
                return(null);
            }

            return(response);
        }
示例#22
0
        /**
         * Configures endpoint information on the NCP. The NCP does not remember these settings after a reset. Endpoints can
         * be added by the Host after the NCP has reset. Once the status of the stack changes to EMBER_NETWORK_UP, endpoints
         * can no longer be added and this command will respond with EZSP_ERROR_INVALID_CALL.
         *
         * @param endpointId the endpoint number to add
         * @param deviceId the device id for the endpoint
         * @param profileId the profile id
         * @param inputClusters an array of input clusters supported by the endpoint
         * @param outputClusters an array of output clusters supported by the endpoint
         * @return the {@link EzspStatus} of the response
         */
        public EzspStatus AddEndpoint(int endpointId, int deviceId, int profileId, int[] inputClusters, int[] outputClusters)
        {
            EzspAddEndpointRequest request = new EzspAddEndpointRequest();

            request.SetEndpoint(endpointId);
            request.SetDeviceId(deviceId);
            request.SetProfileId(profileId);
            request.SetInputClusterList(inputClusters);
            request.SetOutputClusterList(outputClusters);
            IEzspTransaction        transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspAddEndpointResponse)));
            EzspAddEndpointResponse response    = (EzspAddEndpointResponse)transaction.GetResponse();

            Log.Debug(response.ToString());
            _lastStatus = EmberStatus.UNKNOWN;

            return(response.GetStatus());
        }
示例#23
0
        /**
         * Gets a Security Key based on the passed key type.
         *
         * @param index the index of the key to get
         * @return the {@link EmberKeyStruct} of the requested key or null on error
         */
        public EmberKeyStruct GetKeyTableEntry(int index)
        {
            EzspGetKeyTableEntryRequest request = new EzspGetKeyTableEntryRequest();

            request.SetIndex(index);
            IEzspTransaction             transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetKeyTableEntryResponse)));
            EzspGetKeyTableEntryResponse response    = (EzspGetKeyTableEntryResponse)transaction.GetResponse();

            Log.Debug(response.ToString());
            _lastStatus = response.GetStatus();
            if (_lastStatus != EmberStatus.EMBER_SUCCESS)
            {
                return(null);
            }

            return(response.GetKeyStruct());
        }
示例#24
0
        /**
         * Get a policy used by the NCP to make fast decisions.
         *
         * @param policyId the {@link EzspPolicyId} to set
         * @return the returned {@link EzspDecisionId} if the policy was retrieved successfully or null if there was an
         *         error
         */
        public EzspDecisionId GetPolicy(EzspPolicyId policyId)
        {
            EzspGetPolicyRequest getPolicyRequest = new EzspGetPolicyRequest();

            getPolicyRequest.SetPolicyId(policyId);
            IEzspTransaction      transaction       = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(getPolicyRequest, typeof(EzspGetPolicyResponse)));
            EzspGetPolicyResponse getPolicyResponse = (EzspGetPolicyResponse)transaction.GetResponse();

            _lastStatus = EmberStatus.UNKNOWN;
            Log.Debug(getPolicyResponse.ToString());
            if (getPolicyResponse.GetStatus() != EzspStatus.EZSP_SUCCESS)
            {
                Log.Debug("Error getting policy: {}", getPolicyResponse);
                return(EzspDecisionId.UNKNOWN);
            }

            return(getPolicyResponse.GetDecisionId());
        }
示例#25
0
        /**
         * Get a configuration value
         *
         * @param configId the {@link EzspConfigId} to set
         * @return the configuration value as {@link Integer} or null on error
         */
        public int?GetConfiguration(EzspConfigId configId)
        {
            EzspGetConfigurationValueRequest request = new EzspGetConfigurationValueRequest();

            request.SetConfigId(configId);
            IEzspTransaction transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetConfigurationValueResponse)));
            EzspGetConfigurationValueResponse response = (EzspGetConfigurationValueResponse)transaction.GetResponse();

            _lastStatus = EmberStatus.UNKNOWN;
            Log.Debug(response.ToString());

            if (response.GetStatus() != EzspStatus.EZSP_SUCCESS)
            {
                return(null);
            }

            return(response.GetValue());
        }
示例#26
0
        /**
         * The command allows the Host to specify the desired EZSP version and must be sent before any other command. The
         * response provides information about the firmware running on the NCP.
         *
         * @param desiredVersion the requested version we support
         * @return the {@link EzspVersionResponse}
         */
        public EzspVersionResponse GetVersion(int desiredVersion)
        {
            EzspVersionRequest request = new EzspVersionRequest();

            request.SetDesiredProtocolVersion(EzspFrame.GetEzspVersion());
            IEzspTransaction    transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspVersionResponse)));
            EzspVersionResponse response    = (EzspVersionResponse)transaction.GetResponse();

            if (response == null)
            {
                Log.Debug("No response from ezspVersion command");
                return(null);
            }
            Log.Debug(response.ToString());
            _lastStatus = EmberStatus.UNKNOWN;

            return(response);
        }
示例#27
0
        /**
         * Get a memory value from the NCP
         *
         * @param valueId the {@link EzspValueId} to set
         * @return the returned value as int[]
         */
        public int[] GetValue(EzspValueId valueId)
        {
            EzspGetValueRequest request = new EzspGetValueRequest();

            request.SetValueId(valueId);
            IEzspTransaction     transaction = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspGetValueResponse)));
            EzspGetValueResponse response    = (EzspGetValueResponse)transaction.GetResponse();

            _lastStatus = EmberStatus.UNKNOWN;
            Log.Debug(response.ToString());
            if (response.GetStatus() != EzspStatus.EZSP_SUCCESS)
            {
                Log.Debug("Error getting value: {}", response);
                return(null);
            }

            return(response.GetValue());
        }
示例#28
0
        /**
         * Adds a transient link key to the NCP
         *
         * @param partner the {@link IeeeAddress} to set
         * @param transientKey the {@link ZigBeeKey} to set
         * @return the {@link EmberStatus} of the response
         */
        public EmberStatus AddTransientLinkKey(IeeeAddress partner, ZigBeeKey transientKey)
        {
            EmberKeyData emberKey = new EmberKeyData();

            emberKey.SetContents(Array.ConvertAll(transientKey.Key, c => (int)c));
            EzspAddTransientLinkKeyRequest request = new EzspAddTransientLinkKeyRequest();

            request.SetPartner(partner);
            request.SetTransientKey(emberKey);
            IEzspTransaction transaction             = _protocolHandler.SendEzspTransaction(new EzspSingleResponseTransaction(request, typeof(EzspAddTransientLinkKeyResponse)));
            EzspAddTransientLinkKeyResponse response = (EzspAddTransientLinkKeyResponse)transaction.GetResponse();

            _lastStatus = response.GetStatus();
            Log.Debug(response.ToString());
            if (response.GetStatus() != EmberStatus.EMBER_SUCCESS)
            {
                Log.Debug("Error setting transient key: {}", response);
            }

            return(response.GetStatus());
        }
示例#29
0
        public IEzspTransaction SendEzspTransaction(IEzspTransaction ezspTransaction)
        {
            try
            {
                Log.Debug("TX EZSP: {Request}", ezspTransaction.GetRequest());

                Task transactionTask = SendEzspRequestAsync(ezspTransaction);
                if (transactionTask == null)
                {
                    Log.Debug("ASH: Error sending EZSP transaction task is null");
                    return(null);
                }
                transactionTask.Wait();
            }
            catch (Exception ex)
            {
                Log.Debug(ex, "ASH: Error while sending EZSP transaction {Request}", ezspTransaction.GetRequest());
            }


            return(ezspTransaction);
        }
示例#30
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);
        }