zigbee-herdsman
Version:
An open source ZigBee gateway solution with node.js.
896 lines • 160 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
import EventEmitter from "events";
import { SerialPortOptions } from "../../tstype";
import { EmberOutgoingMessageType, EmberCounterType, EmberDutyCycleState, EmberEntropySource, EmberEventUnits, EmberLibraryId, EmberLibraryStatus, EmberMultiPhyNwkConfig, EmberNetworkStatus, EmberNodeType, EmberStatus, EzspNetworkScanType, EzspStatus, SLStatus, EmberIncomingMessageType, EmberSourceRouteDiscoveryMode, EmberMacPassthroughType, EmberKeyStatus, SecManFlag, EmberDeviceUpdate, EmberJoinDecision, EzspZllNetworkOperation, EmberGpSecurityLevel, EmberGpKeyType, EmberTXPowerMode, EmberExtendedSecurityBitmask, EmberStackError } from "../enums";
import { EmberVersion, EmberEUI64, EmberPanId, EmberBeaconData, EmberBeaconIterator, EmberBindingTableEntry, EmberChildData, EmberDutyCycleLimits, EmberMultiPhyRadioParameters, EmberNeighborTableEntry, EmberNetworkInitStruct, EmberNetworkParameters, EmberNodeId, EmberPerDeviceDutyCycle, EmberRouteTableEntry, EmberApsFrame, EmberMulticastTableEntry, EmberBeaconClassificationParams, EmberInitialSecurityState, EmberCurrentSecurityState, SecManContext, SecManKey, SecManNetworkKeyInfo, SecManAPSKeyMetadata, EmberKeyData, EmberAesMmoHashContext, EmberPublicKeyData, EmberCertificateData, EmberSmacData, EmberPublicKey283k1Data, EmberCertificate283k1Data, EmberMessageDigest, EmberSignatureData, EmberSignature283k1Data, EmberPrivateKeyData, EmberZllNetwork, EmberZllInitialSecurityState, EmberZllDeviceInfoRecord, EmberZllAddressAssignment, EmberTokTypeStackZllData, EmberTokTypeStackZllSecurity, EmberGpAddress, EmberGpProxyTableEntry, EmberGpSinkTableEntry, EmberTokenInfo, EmberTokenData, EmberZigbeeNetwork } from "../types";
import { EmberLeaveReason, EmberRejoinReason, EzspConfigId, EzspEndpointFlag, EzspExtendedValueId, EzspMfgTokenId, EzspPolicyId, EzspValueId } from "./enums";
import { UartAsh } from "../uart/ash";
export declare enum EzspEvents {
ncpNeedsResetAndInit = "ncpNeedsResetAndInit",
/** params => status: EmberZdoStatus, sender: EmberNodeId, apsFrame: EmberApsFrame, payload: { cluster-dependent @see zdo.ts } */
ZDO_RESPONSE = "ZDO_RESPONSE",
/** params => type: EmberIncomingMessageType, apsFrame: EmberApsFrame, lastHopLqi: number, sender: EmberNodeId, messageContents: Buffer */
INCOMING_MESSAGE = "INCOMING_MESSAGE",
/** params => sourcePanId: EmberPanId, sourceAddress: EmberEUI64, groupId: number | null, lastHopLqi: number, messageContents: Buffer */
TOUCHLINK_MESSAGE = "TOUCHLINK_MESSAGE",
/** params => sender: EmberNodeId, apsFrame: EmberApsFrame, payload: EndDeviceAnnouncePayload */
END_DEVICE_ANNOUNCE = "END_DEVICE_ANNOUNCE",
/** params => status: EmberStatus */
STACK_STATUS = "STACK_STATUS",
/** params => newNodeId: EmberNodeId, newNodeEui64: EmberEUI64, status: EmberDeviceUpdate, policyDecision: EmberJoinDecision, parentOfNewNodeId: EmberNodeId */
TRUST_CENTER_JOIN = "TRUST_CENTER_JOIN",
/** params => type: EmberOutgoingMessageType, indexOrDestination: number, apsFrame: EmberApsFrame, messageTag: number */
/** params => type: EmberOutgoingMessageType, indexOrDestination: number, apsFrame: EmberApsFrame, messageTag: number */
MESSAGE_SENT_DELIVERY_FAILED = "MESSAGE_SENT_DELIVERY_FAILED",
/** params => sequenceNumber: number, commandIdentifier: number, sourceId: number, frameCounter: number, gpdCommandId: number, gpdCommandPayload: Buffer, gpdLink: number */
GREENPOWER_MESSAGE = "GREENPOWER_MESSAGE"
}
/**
* Host EZSP layer.
*
* Provides functions that allow the Host application to send every EZSP command to the NCP.
*
* Commands to send to the serial>ASH layers all are named `ezsp${CommandName}`.
* They do nothing but build the command, send it and return the value(s).
* Callers are expected to handle errors appropriately.
* - They will throw `EzspStatus` if `sendCommand` fails or the returned value(s) by NCP are invalid (wrong length, etc).
* - Most will return `EmberStatus` given by NCP (some `EzspStatus`, some `SLStatus`...).
*
* @event 'ncpNeedsResetAndInit(EzspStatus)' An error was detected that requires resetting the NCP.
*/
export declare class Ezsp extends EventEmitter {
private readonly tickInterval;
readonly ash: UartAsh;
private readonly buffalo;
/** The contents of the current EZSP frame. CAREFUL using this guy, it's pre-allocated. */
private readonly frameContents;
/** The total Length of the incoming frame */
private frameLength;
private initialVersionSent;
/** True if a command is in the process of being sent. */
private sendingCommand;
/** EZSP frame sequence number. Used in EZSP_SEQUENCE_INDEX byte. */
private frameSequence;
/** Sequence used for EZSP send() tagging. static uint8_t */
private sendSequence;
/** If if a command is currently waiting for a response. Used to manage async CBs vs command responses */
private waitingForResponse;
/** Awaiting response resolve/timer struct. If waitingForResponse is not true, this should not be used. */
private responseWaiter;
/** Counter for Queue Full errors */
counterErrQueueFull: number;
/** Handle used to tick for possible received callbacks */
private tickHandle;
constructor(tickInterval: number, options: SerialPortOptions);
/**
* Returns the number of EZSP responses that have been received by the serial
* protocol and are ready to be collected by the EZSP layer via
* responseReceived().
*/
get pendingResponseCount(): number;
/**
* Create a string representation of the last frame in storage (sent or received).
*/
get frameToString(): string;
private initVariables;
start(): Promise<EzspStatus>;
/**
* Cleanly close down the serial protocol (UART).
* After this function has been called, init() must be called to resume communication with the NCP.
*/
stop(): Promise<void>;
/**
* Check if connected.
* If not, attempt to restore the connection.
*
* @returns
*/
checkConnection(): boolean;
private onAshFatalError;
private onAshFrame;
/**
* Event from the EZSP layer indicating that the transaction with the NCP could not be completed due to a
* serial protocol error or that the response received from the NCP reported an error.
* The status parameter provides more information about the error.
*
* @param status
*/
ezspErrorHandler(status: EzspStatus): void;
/**
* The Host application must call this function periodically to allow the EZSP layer to handle asynchronous events.
*/
private tick;
private nextFrameSequence;
private startCommand;
/**
* Sends the current EZSP command frame. Returns EZSP_SUCCESS if the command was sent successfully.
* Any other return value means that an error has been detected by the serial protocol layer.
*
* if ezsp.sendCommand fails early, this will be:
* - EzspStatus.ERROR_INVALID_CALL
* - EzspStatus.NOT_CONNECTED
* - EzspStatus.ERROR_COMMAND_TOO_LONG
*
* if ezsp.sendCommand fails, this will be whatever ash.send returns:
* - EzspStatus.SUCCESS
* - EzspStatus.NO_TX_SPACE
* - EzspStatus.DATA_FRAME_TOO_SHORT
* - EzspStatus.DATA_FRAME_TOO_LONG
* - EzspStatus.NOT_CONNECTED
*
* if ezsp.sendCommand times out, this will be EzspStatus.ASH_ACK_TIMEOUT (XXX: for now)
*
* if ezsp.sendCommand resolves, this will be whatever ezsp.responseReceived returns:
* - EzspStatus.NO_RX_DATA (should not happen if command was sent (since we subscribe to frame event to trigger function))
* - status from EzspFrameID.INVALID_COMMAND status byte
* - EzspStatus.ERROR_UNSUPPORTED_CONTROL
* - EzspStatus.ERROR_WRONG_DIRECTION
* - EzspStatus.ERROR_TRUNCATED
* - EzspStatus.SUCCESS
*/
private sendCommand;
/**
* Checks whether a new EZSP response frame has been received.
* If any, the response payload is stored in frameContents/frameLength.
* Any other return value means that an error has been detected by the serial protocol layer.
* @returns NO_RX_DATA if no new response has been received.
* @returns SUCCESS if a new response has been received.
*/
checkResponseReceived(): EzspStatus;
/**
* Check if a response was received and sets the stage for parsing if valid (indexes buffalo to params index).
* @returns
*/
responseReceived(): EzspStatus;
/**
* Dispatches callback frames handlers.
*/
callbackDispatch(): void;
/**
*
* @returns uint8_t
*/
private nextSendSequence;
/**
* Calls ezspSend${x} based on type and takes care of tagging message.
*
* Alias types expect `alias` & `sequence` params, along with `apsFrame.radius`.
*
* @param type Specifies the outgoing message type.
* @param indexOrDestination uint16_t Depending on the type of addressing used, this is either the EmberNodeId of the destination,
* an index into the address table, or an index into the binding table.
* Unused for multicast types.
* This must be one of the three ZigBee broadcast addresses for broadcast.
* @param apsFrame [IN/OUT] EmberApsFrame * The APS frame which is to be added to the message.
* @param message uint8_t * Content of the message.
* @param alias The alias source address
* @param sequence uint8_t The alias sequence number
* @returns Result of the ezspSend${x} call or EmberStatus.BAD_ARGUMENT if type not supported.
* @returns apsSequence as returned by ezspSend${x} command
* @returns messageTag Tag used for ezspSend${x} command
*/
send(type: EmberOutgoingMessageType, indexOrDestination: number, apsFrame: EmberApsFrame, message: Buffer, alias: EmberNodeId, sequence: number): Promise<[EmberStatus, messageTag: number]>;
/**
* Retrieving the new version info.
* Wrapper for `ezspGetValue`.
* @returns Send status
* @returns EmberVersion*, null if status not SUCCESS.
*/
ezspGetVersionStruct(): Promise<[EzspStatus, version: EmberVersion]>;
/**
* Function for manipulating the endpoints flags on the NCP.
* Wrapper for `ezspGetExtendedValue`
* @param endpoint uint8_t
* @param flags EzspEndpointFlags
* @returns EzspStatus
*/
ezspSetEndpointFlags(endpoint: number, flags: EzspEndpointFlag): Promise<EzspStatus>;
/**
* Function for manipulating the endpoints flags on the NCP.
* Wrapper for `ezspGetExtendedValue`.
* @param endpoint uint8_t
* @returns EzspStatus
* @returns flags
*/
ezspGetEndpointFlags(endpoint: number): Promise<[EzspStatus, flags: EzspEndpointFlag]>;
/**
* Wrapper for `ezspGetExtendedValue`.
* @param EmberNodeId
* @param destination
* @returns EzspStatus
* @returns overhead uint8_t
*/
ezspGetSourceRouteOverhead(destination: EmberNodeId): Promise<[EzspStatus, overhead: number]>;
/**
* Wrapper for `ezspGetExtendedValue`.
* @returns EzspStatus
* @returns reason
* @returns nodeId EmberNodeId*
*/
ezspGetLastLeaveReason(): Promise<[EzspStatus, reason: EmberLeaveReason, nodeId: EmberNodeId]>;
/**
* Wrapper for `ezspGetValue`.
* @returns EzspStatus
* @returns reason
*/
ezspGetLastRejoinReason(): Promise<[EzspStatus, reason: EmberRejoinReason]>;
/**
* Wrapper for `ezspSetValue`.
* @param mask
* @returns
*/
ezspSetExtendedSecurityBitmask(mask: EmberExtendedSecurityBitmask): Promise<EzspStatus>;
/**
* Wrapper for `ezspGetValue`.
* @returns
*/
ezspGetExtendedSecurityBitmask(): Promise<[EzspStatus, mask: EmberExtendedSecurityBitmask]>;
/**
* Wrapper for `ezspSetValue`.
* @returns
*/
ezspStartWritingStackTokens(): Promise<EzspStatus>;
/**
* Wrapper for `ezspSetValue`.
* @returns
*/
ezspStopWritingStackTokens(): Promise<EzspStatus>;
/**
* 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 desiredProtocolVersion uint8_t The EZSP version the Host wishes to use.
* To successfully set the version and allow other commands, this must be same as EZSP_PROTOCOL_VERSION.
* @return
* - uint8_t The EZSP version the NCP is using.
* - uint8_t * The type of stack running on the NCP (2).
* - uint16_t * The version number of the stack.
*/
ezspVersion(desiredProtocolVersion: number): Promise<[protocolVersion: number, stackType: number, stackVersion: number]>;
/**
* Reads a configuration value from the NCP.
*
* @param configId Identifies which configuration value to read.
* @returns
* - EzspStatus.SUCCESS if the value was read successfully,
* - EzspStatus.ERROR_INVALID_ID if the NCP does not recognize configId.
* - uint16_t * The configuration value.
*/
ezspGetConfigurationValue(configId: EzspConfigId): Promise<[EzspStatus, value: number]>;
/**
* Writes a configuration value to the NCP. Configuration values can be modified
* by the Host after the NCP has reset. Once the status of the stack changes to
* EMBER_NETWORK_UP, configuration values can no longer be modified and this
* command will respond with EzspStatus.ERROR_INVALID_CALL.
*
* @param configId Identifies which configuration value to change.
* @param value uint16_t The new configuration value.
* @returns EzspStatus
* - EzspStatus.SUCCESS if the configuration value was changed,
* - EzspStatus.ERROR_OUT_OF_MEMORY if the new value exceeded the available memory,
* - EzspStatus.ERROR_INVALID_VALUE if the new value was out of bounds,
* - EzspStatus.ERROR_INVALID_ID if the NCP does not recognize configId,
* - EzspStatus.ERROR_INVALID_CALL if configuration values can no longer be modified.
*/
ezspSetConfigurationValue(configId: EzspConfigId, value: number): Promise<EzspStatus>;
/**
* Read attribute data on NCP endpoints.
* @param endpoint uint8_t Endpoint
* @param cluster uint16_t Cluster.
* @param attributeId uint16_t Attribute ID.
* @param mask uint8_t Mask.
* @param manufacturerCode uint16_t Manufacturer code.
* @returns
* - An EmberStatus value indicating success or the reason for failure.
* - uint8_t * Attribute data type.
* - uint8_t * Length of attribute data.
* - uint8_t * Attribute data.
*/
ezspReadAttribute(endpoint: number, cluster: number, attributeId: number, mask: number, manufacturerCode: number, readLength: number): Promise<[EmberStatus, dataType: number, outReadLength: number, data: number[]]>;
/**
* Write attribute data on NCP endpoints.
* @param endpoint uint8_t Endpoint
* @param cluster uint16_t Cluster.
* @param attributeId uint16_t Attribute ID.
* @param mask uint8_t Mask.
* @param manufacturerCode uint16_t Manufacturer code.
* @param overrideReadOnlyAndDataType Override read only and data type.
* @param justTest Override read only and data type.
* @param dataType uint8_t Attribute data type.
* @param data uint8_t * Attribute data.
* @returns EmberStatus An EmberStatus value indicating success or the reason for failure.
*/
ezspWriteAttribute(endpoint: number, cluster: number, attributeId: number, mask: number, manufacturerCode: number, overrideReadOnlyAndDataType: boolean, justTest: boolean, dataType: number, data: Buffer): Promise<EmberStatus>;
/**
* 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 EzspStatus.ERROR_INVALID_CALL.
* @param endpoint uint8_t The application endpoint to be added.
* @param profileId uint16_t The endpoint's application profile.
* @param deviceId uint16_t The endpoint's device ID within the application profile.
* @param deviceVersion uint8_t The endpoint's device version.
* @param inputClusterList uint16_t * Input cluster IDs the endpoint will accept.
* @param outputClusterList uint16_t * Output cluster IDs the endpoint may send.
* @returns EzspStatus
* - EzspStatus.SUCCESS if the endpoint was added,
* - EzspStatus.ERROR_OUT_OF_MEMORY if there is not enough memory available to add the endpoint,
* - EzspStatus.ERROR_INVALID_VALUE if the endpoint already exists,
* - EzspStatus.ERROR_INVALID_CALL if endpoints can no longer be added.
*/
ezspAddEndpoint(endpoint: number, profileId: number, deviceId: number, deviceVersion: number, inputClusterList: number[], outputClusterList: number[]): Promise<EzspStatus>;
/**
* Allows the Host to change the policies used by the NCP to make fast
* decisions.
* @param policyId Identifies which policy to modify.
* @param decisionId The new decision for the specified policy.
* @returns
* - EzspStatus.SUCCESS if the policy was changed,
* - EzspStatus.ERROR_INVALID_ID if the NCP does not recognize policyId.
*/
ezspSetPolicy(policyId: EzspPolicyId, decisionId: number): Promise<EzspStatus>;
/**
* Allows the Host to read the policies used by the NCP to make fast decisions.
* @param policyId Identifies which policy to read.
* @returns
* - EzspStatus.SUCCESS if the policy was read successfully,
* - EzspStatus.ERROR_INVALID_ID if the NCP does not recognize policyId.
* - EzspDecisionId * The current decision for the specified policy.
*/
ezspGetPolicy(policyId: EzspPolicyId): Promise<[EzspStatus, number]>;
/**
* Triggers a pan id update message.
* @param The new Pan Id
* @returns true if the request was successfully handed to the stack, false otherwise
*/
ezspSendPanIdUpdate(newPan: EmberPanId): Promise<boolean>;
/**
* Reads a value from the NCP.
* @param valueId Identifies which value to read.
* @returns
* - EzspStatus.SUCCESS if the value was read successfully,
* - EzspStatus.ERROR_INVALID_ID if the NCP does not recognize valueId,
* - EzspStatus.ERROR_INVALID_VALUE if the length of the returned value exceeds the size of local storage allocated to receive it.
* - uint8_t * Both a command and response parameter.
* On command, the maximum in bytes of local storage allocated to receive the returned value.
* On response, the actual length in bytes of the returned value.
* - uint8_t * The value.
*/
ezspGetValue(valueId: EzspValueId, valueLength: number): Promise<[EzspStatus, outValueLength: number, outValue: number[]]>;
/**
* Reads a value from the NCP but passes an extra argument specific to the value
* being retrieved.
* @param valueId Identifies which extended value ID to read.
* @param characteristics uint32_t Identifies which characteristics of the extended value ID to read. These are specific to the value being read.
* @returns
* - EzspStatus.SUCCESS if the value was read successfully,
* - EzspStatus.ERROR_INVALID_ID if the NCP does not recognize valueId,
* - EzspStatus.ERROR_INVALID_VALUE if the length of the returned value exceeds the size of local storage allocated to receive it.
* - uint8_t * Both a command and response parameter.
* On command, the maximum in bytes of local storage allocated to receive the returned value.
* On response, the actual length in bytes of the returned value.
* - uint8_t * The value.
*/
ezspGetExtendedValue(valueId: EzspExtendedValueId, characteristics: number, valueLength: number): Promise<[EzspStatus, outValueLength: number, outValue: number[]]>;
/**
* Writes a value to the NCP.
* @param valueId Identifies which value to change.
* @param valueLength uint8_t The length of the value parameter in bytes.
* @param value uint8_t * The new value.
* @returns EzspStatus
* - EzspStatus.SUCCESS if the value was changed,
* - EzspStatus.ERROR_INVALID_VALUE if the new value was out of bounds,
* - EzspStatus.ERROR_INVALID_ID if the NCP does not recognize valueId,
* - EzspStatus.ERROR_INVALID_CALL if the value could not be modified.
*/
ezspSetValue(valueId: EzspValueId, valueLength: number, value: number[]): Promise<EzspStatus>;
/**
* Allows the Host to control the broadcast behaviour of a routing device used
* by the NCP.
* @param config uint8_t Passive ack config enum.
* @param minAcksNeeded uint8_t The minimum number of acknowledgments (re-broadcasts) to wait for until
* deeming the broadcast transmission complete.
* @returns EmberStatus An EmberStatus value indicating success or the reason for failure.
*/
ezspSetPassiveAckConfig(config: number, minAcksNeeded: number): Promise<EmberStatus>;
/**
* A command which does nothing. The Host can use this to set the sleep mode or to check the status of the NCP.
*/
ezspNop(): Promise<void>;
/**
* Variable length data from the Host is echoed back by the NCP. This command
* has no other effects and is designed for testing the link between the Host and NCP.
* @param data uint8_t * The data to be echoed back.
* @returns
* - The length of the echo parameter in bytes.
* - echo uint8_t * The echo of the data.
*/
ezspEcho(data: Buffer): Promise<Buffer>;
/**
* Allows the NCP to respond with a pending callback.
*/
ezspCallback(): Promise<void>;
/**
* Callback
* Indicates that there are currently no pending callbacks.
*/
ezspNoCallbacks(): void;
/**
* Sets a token (8 bytes of non-volatile storage) in the Simulated EEPROM of the NCP.
* @param tokenId uint8_t Which token to set
* @param tokenData uint8_t * The data to write to the token.
* @returns EmberStatus An EmberStatus value indicating success or the reason for failure.
*/
ezspSetToken(tokenId: number, tokenData: number[]): Promise<EmberStatus>;
/**
* Retrieves a token (8 bytes of non-volatile storage) from the Simulated EEPROM of the NCP.
* @param tokenId uint8_t Which token to read
* @returns
* - An EmberStatus value indicating success or the reason for failure.
* - uint8_t * The contents of the token.
*/
ezspGetToken(tokenId: number): Promise<[EmberStatus, tokenData: number[]]>;
/**
* Retrieves a manufacturing token from the Flash Information Area of the NCP
* (except for EZSP_STACK_CAL_DATA which is managed by the stack).
* @param Which manufacturing token to read.
* @returns
* - uint8_t The length of the tokenData parameter in bytes.
* - uint8_t * The manufacturing token data.
*/
ezspGetMfgToken(tokenId: EzspMfgTokenId): Promise<[number, tokenData: number[]]>;
/**
* Sets a manufacturing token in the Customer Information Block (CIB) area of
* the NCP if that token currently unset (fully erased). Cannot be used with
* EZSP_STACK_CAL_DATA, EZSP_STACK_CAL_FILTER, EZSP_MFG_ASH_CONFIG, or
* EZSP_MFG_CBKE_DATA token.
* @param tokenId Which manufacturing token to set.
* @param tokenData uint8_t * The manufacturing token data.
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspSetMfgToken(tokenId: EzspMfgTokenId, tokenData: Buffer): Promise<EmberStatus>;
/**
* Callback
* A callback invoked to inform the application that a stack token has changed.
* @param tokenAddress uint16_t The address of the stack token that has changed.
*/
ezspStackTokenChangedHandler(tokenAddress: number): void;
/**
* Returns a pseudorandom number.
* @returns
* - Always returns EMBER_SUCCESS.
* - uint16_t * A pseudorandom number.
*/
ezspGetRandomNumber(): Promise<[EmberStatus, value: number]>;
/**
* Sets a timer on the NCP. There are 2 independent timers available for use by the Host.
* A timer can be cancelled by setting time to 0 or units to EMBER_EVENT_INACTIVE.
* @param timerId uint8_t Which timer to set (0 or 1).
* @param time uint16_t The delay before the timerHandler callback will be generated.
* Note that the timer clock is free running and is not synchronized with this command.
* This means that the actual delay will be between time and (time - 1). The maximum delay is 32767.
* @param units The units for time.
* @param repeat If true, a timerHandler callback will be generated repeatedly. If false, only a single timerHandler callback will be generated.
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspSetTimer(timerId: number, time: number, units: EmberEventUnits, repeat: boolean): Promise<EmberStatus>;
/**
* Gets information about a timer. The Host can use this command to find out how
* much longer it will be before a previously set timer will generate a
* callback.
* @param timerId uint8_t Which timer to get information about (0 or 1).
* @returns
* - uint16_t The delay before the timerHandler callback will be generated.
* - EmberEventUnits * The units for time.
* - bool * True if a timerHandler callback will be generated repeatedly. False if only a single timerHandler callback will be generated.
*/
ezspGetTimer(timerId: number): Promise<[number, units: EmberEventUnits, repeat: boolean]>;
/**
* Callback
* A callback from the timer.
* @param timerId uint8_t Which timer generated the callback (0 or 1).
*/
ezspTimerHandler(timerId: number): void;
/**
* Sends a debug message from the Host to the Network Analyzer utility via the NCP.
* @param binaryMessage true if the message should be interpreted as binary data, false if the message should be interpreted as ASCII text.
* @param messageContents uint8_t * The binary message.
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspDebugWrite(binaryMessage: boolean, messageContents: Buffer): Promise<EmberStatus>;
/**
* Retrieves and clears Ember counters. See the EmberCounterType enumeration for the counter types.
* @returns uint16_t * A list of all counter values ordered according to the EmberCounterType enumeration.
*/
ezspReadAndClearCounters(): Promise<number[]>;
/**
* Retrieves Ember counters. See the EmberCounterType enumeration for the counter types.
* @returns uint16_t * A list of all counter values ordered according to the EmberCounterType enumeration.
*/
ezspReadCounters(): Promise<number[]>;
/**
* Callback
* This call is fired when a counter exceeds its threshold
* @param type Type of Counter
*/
ezspCounterRolloverHandler(type: EmberCounterType): void;
/**
* Used to test that UART flow control is working correctly.
* @param delay uint16_t Data will not be read from the host for this many milliseconds.
*/
ezspDelayTest(delay: number): Promise<void>;
/**
* This retrieves the status of the passed library ID to determine if it is compiled into the stack.
* @param libraryId The ID of the library being queried.
* @returns The status of the library being queried.
*/
ezspGetLibraryStatus(libraryId: EmberLibraryId): Promise<EmberLibraryStatus>;
/**
* Allows the HOST to know whether the NCP is running the XNCP library. If so,
* the response contains also the manufacturer ID and the version number of the
* XNCP application that is running on the NCP.
* @returns
* - EMBER_SUCCESS if the NCP is running the XNCP library,
* - EMBER_INVALID_CALL otherwise.
* - manufacturerId uint16_t * The manufactured ID the user has defined in the XNCP application.
* - versionNumber uint16_t * The version number of the XNCP application.
*/
ezspGetXncpInfo(): Promise<[EmberStatus, manufacturerId: number, versionNumber: number]>;
/**
* Provides the customer a custom EZSP frame. On the NCP, these frames are only
* handled if the XNCP library is included. On the NCP side these frames are
* handled in the emberXNcpIncomingCustomEzspMessageCallback() callback
* function.
* @param uint8_t * The payload of the custom frame (maximum 119 bytes).
* @param uint8_t The expected length of the response.
* @returns
* - The status returned by the custom command.
* - uint8_t *The response.
*/
ezspCustomFrame(payload: Buffer, replyLength: number): Promise<[EmberStatus, outReply: Buffer]>;
/**
* Callback
* A callback indicating a custom EZSP message has been received.
* @param payloadLength uint8_t The length of the custom frame payload.
* @param payload uint8_t * The payload of the custom frame.
*/
ezspCustomFrameHandler(payloadLength: number, payload: number[]): void;
/**
* Returns the EUI64 ID of the local node.
* @returns The 64-bit ID.
*/
ezspGetEui64(): Promise<EmberEUI64>;
/**
* Returns the 16-bit node ID of the local node.
* @returns The 16-bit ID.
*/
ezspGetNodeId(): Promise<EmberNodeId>;
/**
* Returns number of phy interfaces present.
* @returns uint8_t Value indicate how many phy interfaces present.
*/
ezspGetPhyInterfaceCount(): Promise<number>;
/**
* Returns the entropy source used for true random number generation.
* @returns Value indicates the used entropy source.
*/
ezspGetTrueRandomEntropySource(): Promise<EmberEntropySource>;
/**
* Sets the manufacturer code to the specified value.
* The manufacturer code is one of the fields of the node descriptor.
* @param code uint16_t The manufacturer code for the local node.
*/
ezspSetManufacturerCode(code: number): Promise<void>;
/**
* Sets the power descriptor to the specified value. The power descriptor is a
* dynamic value. Therefore, you should call this function whenever the value
* changes.
* @param descriptor uint16_t The new power descriptor for the local node.
*/
ezspSetPowerDescriptor(descriptor: number): Promise<void>;
/**
* 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. This command accepts options to control the network initialization.
* @param networkInitStruct EmberNetworkInitStruct * An EmberNetworkInitStruct containing the options for initialization.
* @returns An EmberStatus value that indicates one of the following: successful
* initialization, EMBER_NOT_JOINED if the node is not part of a network, or the
* reason for failure.
*/
ezspNetworkInit(networkInitStruct: EmberNetworkInitStruct): Promise<EmberStatus>;
/**
* Returns a value indicating whether the node is joining, joined to, or leaving a network.
* @returns Command send status.
* @returns An EmberNetworkStatus value indicating the current join status.
*/
ezspNetworkState(): Promise<EmberNetworkStatus>;
/**
* Callback
* A callback invoked when the status of the stack changes. If the status
* parameter equals EMBER_NETWORK_UP, then the getNetworkParameters command can
* be called to obtain the new network parameters. If any of the parameters are
* being stored in nonvolatile memory by the Host, the stored values should be
* updated.
* @param status Stack status
*/
ezspStackStatusHandler(status: EmberStatus): void;
/**
* This function will start a scan.
* @param scanType Indicates the type of scan to be performed. Possible values are: EZSP_ENERGY_SCAN and EZSP_ACTIVE_SCAN.
* For each type, the respective callback for reporting results is: energyScanResultHandler and networkFoundHandler.
* The energy scan and active scan report errors and completion via the scanCompleteHandler.
* @param channelMask uint32_t Bits set as 1 indicate that this particular channel should be scanned.
* Bits set to 0 indicate that this particular channel should not be scanned. For example, a channelMask value of 0x00000001
* would indicate that only channel 0 should be scanned. Valid channels range from 11 to 26 inclusive.
* This translates to a channel mask value of 0x07FFF800.
* As a convenience, a value of 0 is reinterpreted as the mask for the current channel.
* @param duration uint8_t 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.
* @returns
* - SL_STATUS_OK signals that the scan successfully started. Possible error responses and their meanings:
* - SL_STATUS_MAC_SCANNING, we are already scanning;
* - SL_STATUS_BAD_SCAN_DURATION, we have set a duration value that is not 0..14 inclusive;
* - SL_STATUS_MAC_INCORRECT_SCAN_TYPE, we have requested an undefined scanning type;
* - SL_STATUS_INVALID_CHANNEL_MASK, our channel mask did not specify any valid channels.
*/
ezspStartScan(scanType: EzspNetworkScanType, channelMask: number, duration: number): Promise<SLStatus>;
/**
* Callback
* Reports the result of an energy scan for a single channel. The scan is not
* complete until the scanCompleteHandler callback is called.
* @param channel uint8_t The 802.15.4 channel number that was scanned.
* @param maxRssiValue int8_t The maximum RSSI value found on the channel.
*/
ezspEnergyScanResultHandler(channel: number, maxRssiValue: number): void;
/**
* Callback
* Reports that a network was found as a result of a prior call to startScan.
* Gives the network parameters useful for deciding which network to join.
* @param networkFound EmberZigbeeNetwork * The parameters associated with the network found.
* @param lastHopLqi uint8_t The link quality from the node that generated this beacon.
* @param lastHopRssi int8_t The energy level (in units of dBm) observed during the reception.
*/
ezspNetworkFoundHandler(networkFound: EmberZigbeeNetwork, lastHopLqi: number, lastHopRssi: number): void;
/**
* Callback
* @param channel uint8_t The channel on which the current error occurred. Undefined for the case of EMBER_SUCCESS.
* @param status The error condition that occurred on the current channel. Value will be EMBER_SUCCESS when the scan has completed.
* Returns the status of the current scan of type EZSP_ENERGY_SCAN or
* EZSP_ACTIVE_SCAN. EMBER_SUCCESS signals that the scan has completed. Other
* error conditions signify a failure to scan on the channel specified.
*/
ezspScanCompleteHandler(channel: number, status: EmberStatus): void;
/**
* Callback
* This function returns an unused panID and channel pair found via the find
* unused panId scan procedure.
* @param The unused panID which has been found.
* @param channel uint8_t The channel that the unused panID was found on.
*/
ezspUnusedPanIdFoundHandler(panId: EmberPanId, channel: number): void;
/**
* This function starts a series of scans which will return an available panId.
* @param channelMask uint32_t The channels that will be scanned for available panIds.
* @param duration uint8_t The duration of the procedure.
* @returns The error condition that occurred during the scan. Value will be
* EMBER_SUCCESS if there are no errors.
*/
ezspFindUnusedPanId(channelMask: number, duration: number): Promise<EmberStatus>;
/**
* Terminates a scan in progress.
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspStopScan(): Promise<EmberStatus>;
/**
* Forms a new network by becoming the coordinator.
* @param parameters EmberNetworkParameters * Specification of the new network.
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspFormNetwork(parameters: EmberNetworkParameters): Promise<EmberStatus>;
/**
* Causes the stack to associate with the network using the specified network
* parameters. It can take several seconds for the stack to associate with the
* local network. Do not send messages until the stackStatusHandler callback
* informs you that the stack is up.
* @param nodeType Specification of the role that this node will have in the network.
* This role must not be EMBER_COORDINATOR. To be a coordinator, use the formNetwork command.
* @param parameters EmberNetworkParameters * Specification of the network with which the node should associate.
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspJoinNetwork(nodeType: EmberNodeType, parameters: EmberNetworkParameters): Promise<EmberStatus>;
/**
* Causes the stack to associate with the network using the specified network
* parameters in the beacon parameter. It can take several seconds for the stack
* to associate with the local network. Do not send messages until the
* stackStatusHandler callback informs you that the stack is up. Unlike
* ::emberJoinNetwork(), this function does not issue an active scan before
* joining. Instead, it will cause the local node to issue a MAC Association
* Request directly to the specified target node. It is assumed that the beacon
* parameter is an artifact after issuing an active scan. (For more information,
* see emberGetBestBeacon and emberGetNextBeacon.)
* @param localNodeType Specifies the role that this node will have in the network. This role must not be EMBER_COORDINATOR.
* To be a coordinator, use the formNetwork command.
* @param beacon EmberBeaconData * Specifies the network with which the node should associate.
* @param radioTxPower int8_t The radio transmit power to use, specified in dBm.
* @param clearBeaconsAfterNetworkUp If true, clear beacons in cache upon join success. If join fail, do nothing.
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspJoinNetworkDirectly(localNodeType: EmberNodeType, beacon: EmberBeaconData, radioTxPower: number, clearBeaconsAfterNetworkUp: boolean): Promise<EmberStatus>;
/**
* Causes the stack to leave the current network. This generates a
* stackStatusHandler callback to indicate that the network is down. The radio
* will not be used until after sending a formNetwork or joinNetwork command.
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspLeaveNetwork(): Promise<EmberStatus>;
/**
* The application may call this function when contact with the network has been
* lost. The most common usage case is when an end device can no longer
* communicate with its parent and wishes to find a new one. Another case is
* when a device has missed a Network Key update and no longer has the current
* Network Key. The stack will call ezspStackStatusHandler to indicate that the
* network is down, then try to re-establish contact with the network by
* performing an active scan, choosing a network with matching extended pan id,
* and sending a ZigBee network rejoin request. A second call to the
* ezspStackStatusHandler callback indicates either the success or the failure
* of the attempt. The process takes approximately 150 milliseconds per channel
* to complete.
* @param haveCurrentNetworkKey This parameter tells the stack whether to try to use the current network key.
* If it has the current network key it will perform a secure rejoin (encrypted). If this fails the device should try an unsecure rejoin.
* If the Trust Center allows the rejoin then the current Network Key will be sent encrypted using the device's Link Key.
* @param channelMask uint32_t A mask indicating the channels to be scanned. See emberStartScan for format details.
* A value of 0 is reinterpreted as the mask for the current channel.
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspFindAndRejoinNetwork(haveCurrentNetworkKey: boolean, channelMask: number): Promise<EmberStatus>;
/**
* Tells the stack to allow other nodes to join the network with this node as
* their parent. Joining is initially disabled by default.
* @param duration uint8_t A value of 0x00 disables joining. A value of 0xFF enables joining.
* Any other value enables joining for that number of seconds.
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspPermitJoining(duration: number): Promise<EmberStatus>;
/**
* Callback
* Indicates that a child has joined or left.
* @param index uint8_t The index of the child of interest.
* @param joining True if the child is joining. False the child is leaving.
* @param childId The node ID of the child.
* @param childEui64 The EUI64 of the child.
* @param childType The node type of the child.
*/
ezspChildJoinHandler(index: number, joining: boolean, childId: EmberNodeId, childEui64: EmberEUI64, childType: EmberNodeType): void;
/**
* Sends a ZDO energy scan request. This request may only be sent by the current
* network manager and must be unicast, not broadcast. See ezsp-utils.h for
* related macros emberSetNetworkManagerRequest() and
* emberChangeChannelRequest().
* @param target The network address of the node to perform the scan.
* @param scanChannels uint32_t A mask of the channels to be scanned
* @param scanDuration uint8_t How long to scan on each channel.
* Allowed values are 0..5, with the scan times as specified by 802.15.4 (0 = 31ms, 1 = 46ms, 2 = 77ms, 3 = 138ms, 4 = 261ms, 5 = 507ms).
* @param scanCount uint16_t The number of scans to be performed on each channel (1..8).
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspEnergyScanRequest(target: EmberNodeId, scanChannels: number, scanDuration: number, scanCount: number): Promise<EmberStatus>;
/**
* Returns the current network parameters.
* @returns An EmberStatus value indicating success or the reason for failure.
* @returns EmberNodeType * An EmberNodeType value indicating the current node type.
* @returns EmberNetworkParameters * The current network parameters.
*/
ezspGetNetworkParameters(): Promise<[EmberStatus, nodeType: EmberNodeType, parameters: EmberNetworkParameters]>;
/**
* Returns the current radio parameters based on phy index.
* @param phyIndex uint8_t Desired index of phy interface for radio parameters.
* @returns An EmberStatus value indicating success or the reason for failure.
* @returns EmberMultiPhyRadioParameters * The current radio parameters based on provided phy index.
*/
ezspGetRadioParameters(phyIndex: number): Promise<[EmberStatus, parameters: EmberMultiPhyRadioParameters]>;
/**
* Returns information about the children of the local node and the parent of
* the local node.
* @returns uint8_t The number of children the node currently has.
* @returns The parent's EUI64. The value is undefined for nodes without parents (coordinators and nodes that are not joined to a network).
* @returns EmberNodeId * The parent's node ID. The value is undefined for nodes without parents
* (coordinators and nodes that are not joined to a network).
*/
ezspGetParentChildParameters(): Promise<[number, parentEui64: EmberEUI64, parentNodeId: EmberNodeId]>;
/**
* Returns information about a child of the local node.
* @param uint8_t The index of the child of interest in the child table. Possible indexes range from zero to EMBER_CHILD_TABLE_SIZE.
* @returns EMBER_SUCCESS if there is a child at index. EMBER_NOT_JOINED if there is no child at index.
* @returns EmberChildData * The data of the child.
*/
ezspGetChildData(index: number): Promise<[EmberStatus, childData: EmberChildData]>;
/**
* Sets child data to the child table token.
* @param index uint8_t The index of the child of interest in the child table. Possible indexes range from zero to (EMBER_CHILD_TABLE_SIZE - 1).
* @param childData EmberChildData * The data of the child.
* @returns EMBER_SUCCESS if the child data is set successfully at index. EMBER_INDEX_OUT_OF_RANGE if provided index is out of range.
*/
ezspSetChildData(index: number, childData: EmberChildData): Promise<EmberStatus>;
/**
* Convert a child index to a node ID
* @param childIndex uint8_t The index of the child of interest in the child table. Possible indexes range from zero to EMBER_CHILD_TABLE_SIZE.
* @returns The node ID of the child or EMBER_NULL_NODE_ID if there isn't a child at the childIndex specified
*/
ezspChildId(childIndex: number): Promise<EmberNodeId>;
/**
* Convert a node ID to a child index
* @param childId The node ID of the child
* @returns uint8_t The child index or 0xFF if the node ID doesn't belong to a child
*/
ezspChildIndex(childId: EmberNodeId): Promise<number>;
/**
* Returns the source route table total size.
* @returns uint8_t Total size of source route table.
*/
ezspGetSourceRouteTableTotalSize(): Promise<number>;
/**
* Returns the number of filled entries in source route table.
* @returns uint8_t The number of filled entries in source route table.
*/
ezspGetSourceRouteTableFilledSize(): Promise<number>;
/**
* Returns information about a source route table entry
* @param index uint8_t The index of the entry of interest in the source route table.
* Possible indexes range from zero to SOURCE_ROUTE_TABLE_FILLED_SIZE.
* @returns EMBER_SUCCESS if there is source route entry at index. EMBER_NOT_FOUND if there is no source route at index.
* @returns EmberNodeId * The node ID of the destination in that entry.
* @returns uint8_t * The closer node index for this source route table entry
*/
ezspGetSourceRouteTableEntry(index: number): Promise<[EmberStatus, destination: EmberNodeId, closerIndex: number]>;
/**
* Returns the neighbor table entry at the given index. The number of active
* neighbors can be obtained using the neighborCount command.
* @param index uint8_t The index of the neighbor of interest. Neighbors are stored in ascending order by node id,
* with all unused entries at the end of the table.
* @returns EMBER_ERR_FATAL if the index is greater or equal to the number of active neighbors, or if the device is an end device.
* Returns EMBER_SUCCESS otherwise.
* @returns EmberNeighborTableEntry * The contents of the neighbor table entry.
*/
ezspGetNeighbor(index: number): Promise<[EmberStatus, value: EmberNeighborTableEntry]>;
/**
* Return EmberStatus depending on whether the frame counter of the node is
* found in the neighbor or child table. This function gets the last received
* frame counter as found in the Network Auxiliary header for the specified
* neighbor or child
* @param eui64 eui64 of the node
* @returns Return EMBER_NOT_FOUND if the node is not found in the neighbor or child table. Returns EMBER_SUCCESS otherwise
* @returns uint32_t * Return the frame counter of the node from the neighbor or child table
*/
ezspGetNeighborFrameCounter(eui64: EmberEUI64): Promise<[EmberStatus, returnFrameCounter: number]>;
/**
* Sets the frame counter for the neighbour or child.
* @param eui64 eui64 of the node
* @param frameCounter uint32_t Return the frame counter of the node from the neighbor or child table
* @returns
* - EMBER_NOT_FOUND if the node is not found in the neighbor or child table.
* - EMBER_SUCCESS otherwise
*/
ezspSetNeighborFrameCounter(eui64: EmberEUI64, frameCounter: number): Promise<EmberStatus>;
/**
* Sets the routing shortcut threshold to directly use a neighbor instead of
* performing routing.
* @param costThresh uint8_t The routing shortcut threshold to configure.
* @returns An EmberStatus value indicating success or the reason for failure.
*/
ezspSetRoutingShortcutThreshold(costThresh: number): Promise<EmberStatus>;
/**
* Gets the routing shortcut threshold used to differentiate between directly
* using a neighbor vs. performing routing.
* @returns uint8_t The routing shortcut threshold
*/
ezspGetRoutingShortcutThreshold(): Promise<number>;
/**
* Returns the number of active entries in the neighbor table.
* @returns uint8_t The number of active entries in the neighbor table.
*/
ezspNeighborCount(): Promise<number>;
/**
* Returns the route ta