Skip to content

Commit

Permalink
Fix router endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec committed Jul 8, 2024
1 parent e327f9e commit 4c7bb30
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.5

## `ember-zli router`

Use an NCP as a router and interact with the joined network.
Use a coordinator firwmare as a router and interact with the joined network.

```
USAGE
$ ember-zli router
DESCRIPTION
Use an NCP as a router and interact with the joined network.
Use a coordinator firwmare as a router and interact with the joined network.
EXAMPLES
$ ember-zli router
Expand Down
16 changes: 8 additions & 8 deletions src/commands/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import { Logger } from 'winston'
import { ZSpec, Zcl, Zdo } from 'zigbee-herdsman'
import { FIXED_ENDPOINTS } from 'zigbee-herdsman/dist/adapter/ember/adapter/endpoints.js'
import { EmberTokensManager } from 'zigbee-herdsman/dist/adapter/ember/adapter/tokensManager.js'
import { EMBER_MIN_BROADCAST_ADDRESS, STACK_PROFILE_ZIGBEE_PRO } from 'zigbee-herdsman/dist/adapter/ember/consts.js'
import {
Expand Down Expand Up @@ -48,6 +47,7 @@ import {
waitForStackStatus,
} from '../../utils/ember.js'
import { getPortConf } from '../../utils/port.js'
import { ROUTER_FIXED_ENDPOINTS } from '../../utils/router-endpoints.js'
import { StackConfig } from '../../utils/types.js'
import { browseToFile, loadStackConfig, toHex } from '../../utils/utils.js'

Expand Down Expand Up @@ -166,7 +166,7 @@ export default class Router extends Command {
this.stackConfig = loadStackConfig()

await emberNetworkConfig(this.ezsp, this.stackConfig, this.manufacturerCode)
await emberRegisterFixedEndpoints(this.ezsp, this.multicastTable /* IN/OUT */)
await emberRegisterFixedEndpoints(this.ezsp, this.multicastTable /* IN/OUT */, true)

let exit: boolean = false

Expand Down Expand Up @@ -566,8 +566,8 @@ export default class Router extends Command {
{
profileId: ZSpec.HA_PROFILE_ID,
clusterId: Zcl.Clusters.genBasic.ID,
sourceEndpoint: FIXED_ENDPOINTS[0].endpoint,
destinationEndpoint: FIXED_ENDPOINTS[0].endpoint,
sourceEndpoint: ROUTER_FIXED_ENDPOINTS[0].endpoint,
destinationEndpoint: ROUTER_FIXED_ENDPOINTS[0].endpoint,
options: DEFAULT_APS_OPTIONS,
groupId: 0,
sequence: 0,
Expand Down Expand Up @@ -887,8 +887,8 @@ export default class Router extends Command {
type === EmberIncomingMessageType.UNICAST &&
apsFrame.profileId === ZSpec.HA_PROFILE_ID &&
apsFrame.clusterId === Zcl.Clusters.genBasic.ID &&
apsFrame.destinationEndpoint === FIXED_ENDPOINTS[0].endpoint &&
apsFrame.sourceEndpoint === FIXED_ENDPOINTS[0].endpoint
apsFrame.destinationEndpoint === ROUTER_FIXED_ENDPOINTS[0].endpoint &&
apsFrame.sourceEndpoint === ROUTER_FIXED_ENDPOINTS[0].endpoint
) {
const header = Zcl.Header.fromBuffer(messageContents)

Expand Down Expand Up @@ -1012,8 +1012,8 @@ export default class Router extends Command {
const tableIdx = this.multicastTable.length
const multicastEntry: EmberMulticastTableEntry = {
multicastId: apsFrame.groupId,
endpoint: FIXED_ENDPOINTS[0].endpoint,
networkIndex: FIXED_ENDPOINTS[0].networkIndex,
endpoint: ROUTER_FIXED_ENDPOINTS[0].endpoint,
networkIndex: ROUTER_FIXED_ENDPOINTS[0].networkIndex,
}
// set immediately to avoid potential race
this.multicastTable.push(multicastEntry.multicastId)
Expand Down
5 changes: 3 additions & 2 deletions src/utils/ember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { lowHighBytes } from 'zigbee-herdsman/dist/adapter/ember/utils/math.js'

import { logger } from '../index.js'
import { NVM3ObjectKey } from './enums.js'
import { ROUTER_FIXED_ENDPOINTS } from './router-endpoints.js'
import { EmberFullVersion, PortConf, StackConfig } from './types.js'

const NS = { namespace: 'ember' }
Expand Down Expand Up @@ -164,8 +165,8 @@ export const emberNetworkConfig = async (ezsp: Ezsp, stackConf: StackConfig, man
await ezsp.ezspSetConfigurationValue(EzspConfigId.TRANSIENT_KEY_TIMEOUT_S, stackConf.TRANSIENT_KEY_TIMEOUT_S)
}

export const emberRegisterFixedEndpoints = async (ezsp: Ezsp, multicastTable: EmberMulticastId[]): Promise<void> => {
for (const ep of FIXED_ENDPOINTS) {
export const emberRegisterFixedEndpoints = async (ezsp: Ezsp, multicastTable: EmberMulticastId[], router: boolean = false): Promise<void> => {
for (const ep of router ? ROUTER_FIXED_ENDPOINTS : FIXED_ENDPOINTS) {
if (ep.networkIndex !== 0x00) {
logger.debug(`Multi-network not currently supported. Skipping endpoint ${JSON.stringify(ep)}.`, NS)
continue
Expand Down
54 changes: 54 additions & 0 deletions src/utils/router-endpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { ZSpec, Zcl } from 'zigbee-herdsman'
import { EmberMulticastId } from 'zigbee-herdsman/dist/adapter/ember/types.js'
import { ClusterId, ProfileId } from 'zigbee-herdsman/dist/zspec/tstypes.js'

type FixedEndpointInfo = {
/** Actual Zigbee endpoint number. uint8_t */
endpoint: number
/** Profile ID of the device on this endpoint. */
profileId: ProfileId
/** Device ID of the device on this endpoint. uint16_t */
deviceId: number
/** Version of the device. uint8_t */
deviceVersion: number
/** List of server clusters. */
inClusterList: readonly ClusterId[]
/** List of client clusters. */
outClusterList: readonly ClusterId[]
/** Network index for this endpoint. uint8_t */
networkIndex: number
/** Multicast group IDs to register in the multicast table */
multicastIds: readonly EmberMulticastId[]
}

/**
* List of endpoints to register.
*
* Index 0 is used as default and expected to be the primary network.
*/
export const ROUTER_FIXED_ENDPOINTS: readonly FixedEndpointInfo[] = [
{
// primary network
endpoint: 1,
profileId: ZSpec.HA_PROFILE_ID,
deviceId: 0x08, // HA-rangeextender
deviceVersion: 1,
inClusterList: [Zcl.Clusters.genBasic.ID, Zcl.Clusters.touchlink.ID],
outClusterList: [Zcl.Clusters.genOta.ID],
networkIndex: 0x00,
// - Cluster spec 3.7.2.4.1: group identifier 0x0000 is reserved for the global scene used by the OnOff cluster.
// - 901: defaultBindGroup
multicastIds: [0, 901],
},
{
// green power
endpoint: ZSpec.GP_ENDPOINT,
profileId: ZSpec.GP_PROFILE_ID,
deviceId: 0x66, // GP-combo-basic
deviceVersion: 1,
inClusterList: [Zcl.Clusters.greenPower.ID],
outClusterList: [Zcl.Clusters.greenPower.ID],
networkIndex: 0x00,
multicastIds: [0x0b84],
},
]

0 comments on commit 4c7bb30

Please sign in to comment.