@willieee802/zigbee-herdsman 0.18.2 → 0.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +67 -0
- package/dist/adapter/adapter.d.ts +61 -61
- package/dist/adapter/adapter.d.ts.map +1 -1
- package/dist/adapter/adapter.js +146 -146
- package/dist/adapter/deconz/adapter/deconzAdapter.d.ts +68 -68
- package/dist/adapter/deconz/adapter/deconzAdapter.js +1060 -1060
- package/dist/adapter/deconz/adapter/index.d.ts +2 -2
- package/dist/adapter/deconz/adapter/index.js +10 -10
- package/dist/adapter/deconz/driver/constants.d.ts +104 -104
- package/dist/adapter/deconz/driver/constants.js +55 -55
- package/dist/adapter/deconz/driver/driver.d.ts +81 -81
- package/dist/adapter/deconz/driver/driver.js +732 -732
- package/dist/adapter/deconz/driver/frame.d.ts +6 -6
- package/dist/adapter/deconz/driver/frame.js +13 -13
- package/dist/adapter/deconz/driver/frameParser.d.ts +2 -2
- package/dist/adapter/deconz/driver/frameParser.js +443 -443
- package/dist/adapter/deconz/driver/parser.d.ts +12 -12
- package/dist/adapter/deconz/driver/parser.js +61 -61
- package/dist/adapter/deconz/driver/writer.d.ts +8 -8
- package/dist/adapter/deconz/driver/writer.js +44 -44
- package/dist/adapter/events.d.ts +47 -47
- package/dist/adapter/events.js +14 -14
- package/dist/adapter/ezsp/adapter/backup.d.ts +9 -9
- package/dist/adapter/ezsp/adapter/backup.js +53 -53
- package/dist/adapter/ezsp/adapter/ezspAdapter.d.ts +59 -59
- package/dist/adapter/ezsp/adapter/ezspAdapter.d.ts.map +1 -1
- package/dist/adapter/ezsp/adapter/ezspAdapter.js +603 -585
- package/dist/adapter/ezsp/adapter/ezspAdapter.js.map +1 -1
- package/dist/adapter/ezsp/adapter/index.d.ts +2 -2
- package/dist/adapter/ezsp/adapter/index.js +10 -10
- package/dist/adapter/ezsp/driver/commands.d.ts +36 -36
- package/dist/adapter/ezsp/driver/commands.js +2359 -2359
- package/dist/adapter/ezsp/driver/consts.d.ts +10 -10
- package/dist/adapter/ezsp/driver/consts.js +13 -13
- package/dist/adapter/ezsp/driver/driver.d.ts +103 -103
- package/dist/adapter/ezsp/driver/driver.js +639 -639
- package/dist/adapter/ezsp/driver/ezsp.d.ts +96 -96
- package/dist/adapter/ezsp/driver/ezsp.js +586 -586
- package/dist/adapter/ezsp/driver/index.d.ts +3 -3
- package/dist/adapter/ezsp/driver/index.js +8 -8
- package/dist/adapter/ezsp/driver/multicast.d.ts +12 -12
- package/dist/adapter/ezsp/driver/multicast.js +74 -74
- package/dist/adapter/ezsp/driver/parser.d.ts +12 -12
- package/dist/adapter/ezsp/driver/parser.js +111 -111
- package/dist/adapter/ezsp/driver/types/basic.d.ts +62 -62
- package/dist/adapter/ezsp/driver/types/basic.js +208 -208
- package/dist/adapter/ezsp/driver/types/basic.js.map +1 -1
- package/dist/adapter/ezsp/driver/types/index.d.ts +9 -9
- package/dist/adapter/ezsp/driver/types/index.js +133 -133
- package/dist/adapter/ezsp/driver/types/named.d.ts +697 -697
- package/dist/adapter/ezsp/driver/types/named.js +1726 -1726
- package/dist/adapter/ezsp/driver/types/named.js.map +1 -1
- package/dist/adapter/ezsp/driver/types/struct.d.ts +251 -251
- package/dist/adapter/ezsp/driver/types/struct.js +708 -708
- package/dist/adapter/ezsp/driver/types/struct.js.map +1 -1
- package/dist/adapter/ezsp/driver/uart.d.ts +44 -44
- package/dist/adapter/ezsp/driver/uart.js +368 -368
- package/dist/adapter/ezsp/driver/utils/crc16ccitt.d.ts +2 -2
- package/dist/adapter/ezsp/driver/utils/crc16ccitt.js +55 -55
- package/dist/adapter/ezsp/driver/utils/index.d.ts +18 -18
- package/dist/adapter/ezsp/driver/utils/index.js +67 -67
- package/dist/adapter/ezsp/driver/writer.d.ts +13 -13
- package/dist/adapter/ezsp/driver/writer.js +88 -88
- package/dist/adapter/index.d.ts +4 -4
- package/dist/adapter/index.js +35 -35
- package/dist/adapter/serialPort.d.ts +8 -8
- package/dist/adapter/serialPort.js +22 -22
- package/dist/adapter/serialPort.js.map +1 -1
- package/dist/adapter/serialPortUtils.d.ts +12 -12
- package/dist/adapter/serialPortUtils.js +18 -18
- package/dist/adapter/socketPortUtils.d.ts +10 -10
- package/dist/adapter/socketPortUtils.js +16 -16
- package/dist/adapter/tstype.d.ts +85 -85
- package/dist/adapter/tstype.js +2 -2
- package/dist/adapter/z-stack/adapter/adapter-backup.d.ts +62 -62
- package/dist/adapter/z-stack/adapter/adapter-backup.d.ts.map +1 -1
- package/dist/adapter/z-stack/adapter/adapter-backup.js +460 -441
- package/dist/adapter/z-stack/adapter/adapter-backup.js.map +1 -1
- package/dist/adapter/z-stack/adapter/adapter-nv-memory.d.ts +150 -150
- package/dist/adapter/z-stack/adapter/adapter-nv-memory.js +258 -258
- package/dist/adapter/z-stack/adapter/endpoints.d.ts +11 -11
- package/dist/adapter/z-stack/adapter/endpoints.js +73 -73
- package/dist/adapter/z-stack/adapter/index.d.ts +2 -2
- package/dist/adapter/z-stack/adapter/index.js +8 -8
- package/dist/adapter/z-stack/adapter/manager.d.ts +86 -86
- package/dist/adapter/z-stack/adapter/manager.js +476 -476
- package/dist/adapter/z-stack/adapter/tstype.d.ts +6 -6
- package/dist/adapter/z-stack/adapter/tstype.js +10 -10
- package/dist/adapter/z-stack/adapter/zStackAdapter.d.ts +81 -81
- package/dist/adapter/z-stack/adapter/zStackAdapter.d.ts.map +1 -1
- package/dist/adapter/z-stack/adapter/zStackAdapter.js +868 -868
- package/dist/adapter/z-stack/adapter/zStackAdapter.js.map +1 -1
- package/dist/adapter/z-stack/constants/af.d.ts +23 -23
- package/dist/adapter/z-stack/constants/af.js +27 -27
- package/dist/adapter/z-stack/constants/common.d.ts +278 -278
- package/dist/adapter/z-stack/constants/common.js +289 -289
- package/dist/adapter/z-stack/constants/dbg.d.ts +22 -22
- package/dist/adapter/z-stack/constants/dbg.js +24 -24
- package/dist/adapter/z-stack/constants/index.d.ts +10 -10
- package/dist/adapter/z-stack/constants/index.js +47 -47
- package/dist/adapter/z-stack/constants/mac.d.ts +127 -127
- package/dist/adapter/z-stack/constants/mac.js +129 -129
- package/dist/adapter/z-stack/constants/sapi.d.ts +24 -24
- package/dist/adapter/z-stack/constants/sapi.js +26 -26
- package/dist/adapter/z-stack/constants/sys.d.ts +71 -71
- package/dist/adapter/z-stack/constants/sys.js +73 -73
- package/dist/adapter/z-stack/constants/util.d.ts +81 -81
- package/dist/adapter/z-stack/constants/util.js +83 -83
- package/dist/adapter/z-stack/constants/utils.d.ts +4 -4
- package/dist/adapter/z-stack/constants/utils.js +14 -14
- package/dist/adapter/z-stack/constants/zdo.d.ts +102 -102
- package/dist/adapter/z-stack/constants/zdo.js +104 -104
- package/dist/adapter/z-stack/models/index.d.ts +1 -1
- package/dist/adapter/z-stack/models/index.js +17 -17
- package/dist/adapter/z-stack/models/startup-options.d.ts +12 -12
- package/dist/adapter/z-stack/models/startup-options.js +2 -2
- package/dist/adapter/z-stack/structs/entries/address-manager-entry.d.ts +23 -23
- package/dist/adapter/z-stack/structs/entries/address-manager-entry.js +45 -45
- package/dist/adapter/z-stack/structs/entries/address-manager-table.d.ts +10 -10
- package/dist/adapter/z-stack/structs/entries/address-manager-table.js +22 -22
- package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.d.ts +10 -10
- package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.js +21 -21
- package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.d.ts +10 -10
- package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.js +23 -23
- package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.d.ts +10 -10
- package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.js +24 -24
- package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.d.ts +10 -10
- package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.js +23 -23
- package/dist/adapter/z-stack/structs/entries/channel-list.d.ts +8 -8
- package/dist/adapter/z-stack/structs/entries/channel-list.js +15 -15
- package/dist/adapter/z-stack/structs/entries/has-configured.d.ts +8 -8
- package/dist/adapter/z-stack/structs/entries/has-configured.js +16 -16
- package/dist/adapter/z-stack/structs/entries/index.d.ts +16 -16
- package/dist/adapter/z-stack/structs/entries/index.js +32 -32
- package/dist/adapter/z-stack/structs/entries/nib.d.ts +10 -10
- package/dist/adapter/z-stack/structs/entries/nib.js +68 -68
- package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.d.ts +10 -10
- package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.js +18 -18
- package/dist/adapter/z-stack/structs/entries/nwk-key.d.ts +8 -8
- package/dist/adapter/z-stack/structs/entries/nwk-key.js +15 -15
- package/dist/adapter/z-stack/structs/entries/nwk-pan-id.d.ts +8 -8
- package/dist/adapter/z-stack/structs/entries/nwk-pan-id.js +15 -15
- package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.d.ts +13 -13
- package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.js +23 -23
- package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.d.ts +10 -10
- package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.js +22 -22
- package/dist/adapter/z-stack/structs/entries/security-manager-entry.d.ts +20 -20
- package/dist/adapter/z-stack/structs/entries/security-manager-entry.js +36 -36
- package/dist/adapter/z-stack/structs/entries/security-manager-table.d.ts +10 -10
- package/dist/adapter/z-stack/structs/entries/security-manager-table.js +24 -24
- package/dist/adapter/z-stack/structs/index.d.ts +4 -4
- package/dist/adapter/z-stack/structs/index.js +20 -20
- package/dist/adapter/z-stack/structs/serializable-memory-object.d.ts +13 -13
- package/dist/adapter/z-stack/structs/serializable-memory-object.js +2 -2
- package/dist/adapter/z-stack/structs/struct.d.ts +99 -99
- package/dist/adapter/z-stack/structs/struct.js +295 -295
- package/dist/adapter/z-stack/structs/table.d.ts +94 -94
- package/dist/adapter/z-stack/structs/table.js +161 -161
- package/dist/adapter/z-stack/unpi/constants.d.ts +28 -28
- package/dist/adapter/z-stack/unpi/constants.js +41 -41
- package/dist/adapter/z-stack/unpi/frame.d.ts +16 -16
- package/dist/adapter/z-stack/unpi/frame.js +48 -48
- package/dist/adapter/z-stack/unpi/index.d.ts +5 -5
- package/dist/adapter/z-stack/unpi/index.js +37 -37
- package/dist/adapter/z-stack/unpi/parser.d.ts +10 -10
- package/dist/adapter/z-stack/unpi/parser.js +74 -74
- package/dist/adapter/z-stack/unpi/writer.d.ts +10 -10
- package/dist/adapter/z-stack/unpi/writer.js +44 -44
- package/dist/adapter/z-stack/utils/channel-list.d.ts +20 -20
- package/dist/adapter/z-stack/utils/channel-list.js +40 -40
- package/dist/adapter/z-stack/utils/index.d.ts +2 -2
- package/dist/adapter/z-stack/utils/index.js +18 -18
- package/dist/adapter/z-stack/utils/network-options.d.ts +8 -8
- package/dist/adapter/z-stack/utils/network-options.js +22 -22
- package/dist/adapter/z-stack/znp/buffaloZnp.d.ts +11 -11
- package/dist/adapter/z-stack/znp/buffaloZnp.js +113 -113
- package/dist/adapter/z-stack/znp/definition.d.ts +5 -5
- package/dist/adapter/z-stack/znp/definition.js +3050 -3050
- package/dist/adapter/z-stack/znp/index.d.ts +3 -3
- package/dist/adapter/z-stack/znp/index.js +10 -10
- package/dist/adapter/z-stack/znp/parameterType.d.ts +22 -22
- package/dist/adapter/z-stack/znp/parameterType.js +25 -25
- package/dist/adapter/z-stack/znp/tstype.d.ts +21 -21
- package/dist/adapter/z-stack/znp/tstype.js +2 -2
- package/dist/adapter/z-stack/znp/znp.d.ts +43 -43
- package/dist/adapter/z-stack/znp/znp.js +325 -325
- package/dist/adapter/z-stack/znp/zpiObject.d.ts +19 -19
- package/dist/adapter/z-stack/znp/zpiObject.js +96 -96
- package/dist/adapter/zigate/adapter/index.d.ts +2 -2
- package/dist/adapter/zigate/adapter/index.js +10 -10
- package/dist/adapter/zigate/adapter/zigateAdapter.d.ts +69 -69
- package/dist/adapter/zigate/adapter/zigateAdapter.js +678 -678
- package/dist/adapter/zigate/debug.d.ts +7 -7
- package/dist/adapter/zigate/debug.js +22 -22
- package/dist/adapter/zigate/driver/buffaloZiGate.d.ts +18 -18
- package/dist/adapter/zigate/driver/buffaloZiGate.js +139 -139
- package/dist/adapter/zigate/driver/commandType.d.ts +41 -41
- package/dist/adapter/zigate/driver/commandType.js +385 -385
- package/dist/adapter/zigate/driver/constants.d.ts +276 -276
- package/dist/adapter/zigate/driver/constants.js +371 -371
- package/dist/adapter/zigate/driver/frame.d.ts +26 -26
- package/dist/adapter/zigate/driver/frame.js +172 -172
- package/dist/adapter/zigate/driver/frame.js.map +1 -1
- package/dist/adapter/zigate/driver/messageType.d.ts +11 -11
- package/dist/adapter/zigate/driver/messageType.js +278 -278
- package/dist/adapter/zigate/driver/parameterType.d.ts +20 -20
- package/dist/adapter/zigate/driver/parameterType.js +23 -23
- package/dist/adapter/zigate/driver/ziGateObject.d.ts +23 -23
- package/dist/adapter/zigate/driver/ziGateObject.js +106 -106
- package/dist/adapter/zigate/driver/zigate.d.ts +49 -49
- package/dist/adapter/zigate/driver/zigate.js +303 -303
- package/dist/buffalo/buffalo.d.ts +50 -50
- package/dist/buffalo/buffalo.js +322 -322
- package/dist/buffalo/index.d.ts +3 -3
- package/dist/buffalo/index.js +33 -33
- package/dist/buffalo/tstype.d.ts +8 -8
- package/dist/buffalo/tstype.js +2 -2
- package/dist/controller/controller.d.ts +113 -110
- package/dist/controller/controller.d.ts.map +1 -1
- package/dist/controller/controller.js +619 -607
- package/dist/controller/controller.js.map +1 -1
- package/dist/controller/database.d.ts +18 -18
- package/dist/controller/database.js +93 -93
- package/dist/controller/events.d.ts +58 -55
- package/dist/controller/events.d.ts.map +1 -1
- package/dist/controller/events.js +101 -101
- package/dist/controller/events.js.map +1 -1
- package/dist/controller/greenPower.d.ts +12 -12
- package/dist/controller/greenPower.js +220 -220
- package/dist/controller/helpers/index.d.ts +2 -2
- package/dist/controller/helpers/index.js +28 -28
- package/dist/controller/helpers/request.d.ts +22 -22
- package/dist/controller/helpers/request.js +71 -71
- package/dist/controller/helpers/zclFrameConverter.d.ts +7 -7
- package/dist/controller/helpers/zclFrameConverter.js +31 -31
- package/dist/controller/helpers/zclTransactionSequenceNumber.d.ts +5 -5
- package/dist/controller/helpers/zclTransactionSequenceNumber.js +13 -13
- package/dist/controller/index.d.ts +5 -5
- package/dist/controller/index.js +8 -8
- package/dist/controller/logger-stub.d.ts +6 -6
- package/dist/controller/logger-stub.js +2 -2
- package/dist/controller/model/device.d.ts +133 -132
- package/dist/controller/model/device.d.ts.map +1 -1
- package/dist/controller/model/device.js +717 -708
- package/dist/controller/model/device.js.map +1 -1
- package/dist/controller/model/endpoint.d.ts +131 -131
- package/dist/controller/model/endpoint.d.ts.map +1 -1
- package/dist/controller/model/endpoint.js +816 -817
- package/dist/controller/model/endpoint.js.map +1 -1
- package/dist/controller/model/entity.d.ts +14 -14
- package/dist/controller/model/entity.js +26 -26
- package/dist/controller/model/group.d.ts +38 -38
- package/dist/controller/model/group.js +221 -221
- package/dist/controller/model/index.d.ts +5 -5
- package/dist/controller/model/index.js +14 -14
- package/dist/controller/touchlink.d.ts +19 -19
- package/dist/controller/touchlink.js +157 -157
- package/dist/controller/tstype.d.ts +21 -21
- package/dist/controller/tstype.js +9 -9
- package/dist/index.d.ts +3 -3
- package/dist/index.js +33 -33
- package/dist/models/backup-storage-legacy.d.ts +26 -26
- package/dist/models/backup-storage-legacy.js +2 -2
- package/dist/models/backup-storage-unified.d.ts +49 -49
- package/dist/models/backup-storage-unified.js +2 -2
- package/dist/models/backup.d.ts +37 -37
- package/dist/models/backup.js +2 -2
- package/dist/models/index.d.ts +4 -4
- package/dist/models/index.js +20 -20
- package/dist/models/network-options.d.ts +12 -12
- package/dist/models/network-options.js +2 -2
- package/dist/utils/assertString.d.ts +2 -2
- package/dist/utils/assertString.js +8 -8
- package/dist/utils/backup.d.ts +20 -20
- package/dist/utils/backup.js +187 -187
- package/dist/utils/equalsPartial.d.ts +2 -2
- package/dist/utils/equalsPartial.js +11 -11
- package/dist/utils/index.d.ts +9 -9
- package/dist/utils/index.js +45 -45
- package/dist/utils/isNumberArray.d.ts +2 -2
- package/dist/utils/isNumberArray.js +6 -6
- package/dist/utils/queue.d.ts +11 -11
- package/dist/utils/queue.js +50 -50
- package/dist/utils/realpathSync.d.ts +2 -2
- package/dist/utils/realpathSync.js +12 -12
- package/dist/utils/wait.d.ts +2 -2
- package/dist/utils/wait.js +8 -8
- package/dist/utils/waitress.d.ts +21 -21
- package/dist/utils/waitress.js +61 -61
- package/dist/zcl/buffaloZcl.d.ts +41 -41
- package/dist/zcl/buffaloZcl.js +591 -591
- package/dist/zcl/definition/buffaloZclDataType.d.ts +17 -17
- package/dist/zcl/definition/buffaloZclDataType.js +20 -20
- package/dist/zcl/definition/cluster.d.ts +29 -29
- package/dist/zcl/definition/cluster.js +5335 -5335
- package/dist/zcl/definition/dataType.d.ts +59 -59
- package/dist/zcl/definition/dataType.js +64 -64
- package/dist/zcl/definition/direction.d.ts +5 -5
- package/dist/zcl/definition/direction.js +8 -8
- package/dist/zcl/definition/endpointDeviceType.d.ts +4 -4
- package/dist/zcl/definition/endpointDeviceType.js +15 -15
- package/dist/zcl/definition/foundation.d.ts +11 -11
- package/dist/zcl/definition/foundation.js +167 -167
- package/dist/zcl/definition/frameControl.d.ts +10 -10
- package/dist/zcl/definition/frameControl.js +2 -2
- package/dist/zcl/definition/frameType.d.ts +5 -5
- package/dist/zcl/definition/frameType.js +8 -8
- package/dist/zcl/definition/index.d.ts +13 -13
- package/dist/zcl/definition/index.js +51 -51
- package/dist/zcl/definition/manufacturerCode.d.ts +1074 -1074
- package/dist/zcl/definition/manufacturerCode.js +1079 -1079
- package/dist/zcl/definition/powerSource.d.ts +4 -4
- package/dist/zcl/definition/powerSource.js +12 -12
- package/dist/zcl/definition/status.d.ts +38 -38
- package/dist/zcl/definition/status.js +41 -41
- package/dist/zcl/definition/tstype.d.ts +16 -16
- package/dist/zcl/definition/tstype.js +2 -2
- package/dist/zcl/index.d.ts +15 -15
- package/dist/zcl/index.js +55 -55
- package/dist/zcl/tstype.d.ts +56 -56
- package/dist/zcl/tstype.js +10 -10
- package/dist/zcl/utils.d.ts +6 -6
- package/dist/zcl/utils.js +165 -165
- package/dist/zcl/zclFrame.d.ts +45 -45
- package/dist/zcl/zclFrame.js +347 -347
- package/dist/zcl/zclStatusError.d.ts +5 -5
- package/dist/zcl/zclStatusError.js +13 -13
- package/package.json +6 -6
|
@@ -1,679 +1,679 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const Events = __importStar(require("../../events"));
|
|
30
|
-
const adapter_1 = __importDefault(require("../../adapter"));
|
|
31
|
-
const zcl_1 = require("../../../zcl");
|
|
32
|
-
const utils_1 = require("../../../utils");
|
|
33
|
-
const zigate_1 = __importDefault(require("../driver/zigate"));
|
|
34
|
-
const debug_1 = require("../debug");
|
|
35
|
-
const constants_1 = require("../driver/constants");
|
|
36
|
-
const buffalo_1 = require("../../../buffalo");
|
|
37
|
-
const debug = (0, debug_1.Debug)('adapter');
|
|
38
|
-
const default_bind_group = 901; // https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/lib/constants.js#L3
|
|
39
|
-
const channelsToMask = (channels) => channels.map((x) => 2 ** x).reduce((acc, x) => acc + x, 0);
|
|
40
|
-
class ZiGateAdapter extends adapter_1.default {
|
|
41
|
-
constructor(networkOptions, serialPortOptions, backupPath, adapterOptions, logger) {
|
|
42
|
-
super(networkOptions, serialPortOptions, backupPath, adapterOptions, logger);
|
|
43
|
-
this.joinPermitted = false;
|
|
44
|
-
this.driver = new zigate_1.default(serialPortOptions.path, serialPortOptions);
|
|
45
|
-
this.waitress = new utils_1.Waitress(this.waitressValidator, this.waitressTimeoutFormatter);
|
|
46
|
-
this.driver.on('received', this.zclDataListener.bind(this));
|
|
47
|
-
this.driver.on('receivedRaw', this.rawDataListener.bind(this));
|
|
48
|
-
this.driver.on('LeaveIndication', this.leaveIndicationListener.bind(this));
|
|
49
|
-
this.driver.on('DeviceAnnounce', this.deviceAnnounceListener.bind(this));
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Adapter methods
|
|
53
|
-
*/
|
|
54
|
-
async start() {
|
|
55
|
-
let startResult = 'resumed';
|
|
56
|
-
try {
|
|
57
|
-
await this.driver.open();
|
|
58
|
-
debug.log("Connected to ZiGate adapter successfully.");
|
|
59
|
-
const resetResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.Reset, {}, 5000);
|
|
60
|
-
if (resetResponse.code === constants_1.ZiGateMessageCode.RestartNonFactoryNew) {
|
|
61
|
-
startResult = 'resumed';
|
|
62
|
-
}
|
|
63
|
-
else if (resetResponse.code === constants_1.ZiGateMessageCode.RestartFactoryNew) {
|
|
64
|
-
startResult = 'reset';
|
|
65
|
-
}
|
|
66
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawMode, { enabled: 0x01 });
|
|
67
|
-
// @todo check
|
|
68
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetDeviceType, {
|
|
69
|
-
deviceType: constants_1.DEVICE_TYPE.coordinator
|
|
70
|
-
});
|
|
71
|
-
await this.initNetwork();
|
|
72
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.AddGroup, {
|
|
73
|
-
addressMode: constants_1.ADDRESS_MODE.short,
|
|
74
|
-
shortAddress: 0x0000,
|
|
75
|
-
sourceEndpoint: 0x01,
|
|
76
|
-
destinationEndpoint: 0x01,
|
|
77
|
-
groupAddress: default_bind_group
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
throw new Error("failed to connect to zigate adapter " + error.message);
|
|
82
|
-
}
|
|
83
|
-
const concurrent = this.adapterOptions && this.adapterOptions.concurrent ?
|
|
84
|
-
this.adapterOptions.concurrent : 2;
|
|
85
|
-
debug.log(`Adapter concurrent: ${concurrent}`);
|
|
86
|
-
this.queue = new utils_1.Queue(concurrent);
|
|
87
|
-
return startResult; // 'resumed' | 'reset' | 'restored'
|
|
88
|
-
}
|
|
89
|
-
async stop() {
|
|
90
|
-
this.closing = true;
|
|
91
|
-
await this.driver.close();
|
|
92
|
-
}
|
|
93
|
-
async getCoordinator() {
|
|
94
|
-
debug.log('getCoordinator');
|
|
95
|
-
const networkResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.GetNetworkState);
|
|
96
|
-
// @TODO deal hardcoded endpoints, made by analogy with deconz
|
|
97
|
-
// polling the coordinator on some firmware went into a memory leak, so we don't ask this info
|
|
98
|
-
const response = {
|
|
99
|
-
networkAddress: 0,
|
|
100
|
-
manufacturerID: 0,
|
|
101
|
-
ieeeAddr: networkResponse.payload.extendedAddress,
|
|
102
|
-
endpoints: constants_1.coordinatorEndpoints
|
|
103
|
-
};
|
|
104
|
-
debug.log('getCoordinator %o', response);
|
|
105
|
-
return response;
|
|
106
|
-
}
|
|
107
|
-
;
|
|
108
|
-
async getCoordinatorVersion() {
|
|
109
|
-
debug.log('getCoordinatorVersion');
|
|
110
|
-
return this.driver.sendCommand(constants_1.ZiGateCommandCode.GetVersion, {})
|
|
111
|
-
.then((result) => {
|
|
112
|
-
const meta = {
|
|
113
|
-
"transportrev": 0,
|
|
114
|
-
"product": 0,
|
|
115
|
-
"majorrel": parseInt(result.payload.major).toString(16),
|
|
116
|
-
"minorrel": parseInt(result.payload.minor).toString(16),
|
|
117
|
-
"maintrel": parseInt(result.payload.revision).toString(16),
|
|
118
|
-
"revision": parseInt(result.payload.revision).toString(16),
|
|
119
|
-
};
|
|
120
|
-
const version = {
|
|
121
|
-
type: 'zigate',
|
|
122
|
-
meta: meta,
|
|
123
|
-
};
|
|
124
|
-
return Promise.resolve(version);
|
|
125
|
-
})
|
|
126
|
-
.catch((e) => {
|
|
127
|
-
debug.error(e);
|
|
128
|
-
return Promise.reject(new Error("" + e));
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
;
|
|
132
|
-
async permitJoin(seconds, networkAddress) {
|
|
133
|
-
const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.PermitJoin, {
|
|
134
|
-
targetShortAddress: networkAddress || 0xFFFC,
|
|
135
|
-
interval: seconds,
|
|
136
|
-
TCsignificance: 0
|
|
137
|
-
});
|
|
138
|
-
// const result = await this.driver.sendCommand(ZiGateCommandCode.PermitJoinStatus, {});
|
|
139
|
-
// Suitable only for the coordinator, not the entire network or point-to-point for routers
|
|
140
|
-
this.joinPermitted = result.payload.status === 0;
|
|
141
|
-
}
|
|
142
|
-
;
|
|
143
|
-
async addInstallCode(ieeeAddress, key) {
|
|
144
|
-
return Promise.reject(new Error('Add install code is not supported'));
|
|
145
|
-
}
|
|
146
|
-
async reset(type) {
|
|
147
|
-
debug.log('reset %s', type);
|
|
148
|
-
if (type === 'soft') {
|
|
149
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.Reset, {}, 5000);
|
|
150
|
-
}
|
|
151
|
-
else if (type === 'hard') {
|
|
152
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.ErasePersistentData, {}, 5000);
|
|
153
|
-
}
|
|
154
|
-
return Promise.resolve();
|
|
155
|
-
}
|
|
156
|
-
;
|
|
157
|
-
async getNetworkParameters() {
|
|
158
|
-
debug.log('getNetworkParameters');
|
|
159
|
-
return this.driver.sendCommand(constants_1.ZiGateCommandCode.GetNetworkState, {}, 10000)
|
|
160
|
-
.then((NetworkStateResponse) => {
|
|
161
|
-
const resultPayload = {
|
|
162
|
-
panID: NetworkStateResponse.payload.PANID,
|
|
163
|
-
extendedPanID: NetworkStateResponse.payload.ExtPANID,
|
|
164
|
-
channel: NetworkStateResponse.payload.Channel
|
|
165
|
-
};
|
|
166
|
-
return Promise.resolve(resultPayload);
|
|
167
|
-
}).catch(() => Promise.reject(new Error("Get network parameters failed")));
|
|
168
|
-
}
|
|
169
|
-
;
|
|
170
|
-
/**
|
|
171
|
-
* https://zigate.fr/documentation/deplacer-le-pdm-de-la-zigate/
|
|
172
|
-
* pdm from host
|
|
173
|
-
*/
|
|
174
|
-
async supportsBackup() {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
;
|
|
178
|
-
async backup() {
|
|
179
|
-
throw new Error("This adapter does not support backup");
|
|
180
|
-
}
|
|
181
|
-
;
|
|
182
|
-
async setTransmitPower(value) {
|
|
183
|
-
debug.log('setTransmitPower, %o', arguments);
|
|
184
|
-
return this.driver.sendCommand(constants_1.ZiGateCommandCode.SetTXpower, { value: value })
|
|
185
|
-
.then(() => Promise.resolve()).catch(() => Promise.reject(new Error("Set transmitpower failed")));
|
|
186
|
-
}
|
|
187
|
-
;
|
|
188
|
-
async lqi(networkAddress) {
|
|
189
|
-
return this.queue.execute(async () => {
|
|
190
|
-
debug.log('lqi, %o', arguments);
|
|
191
|
-
const neighbors = [];
|
|
192
|
-
const add = (list) => {
|
|
193
|
-
for (const entry of list) {
|
|
194
|
-
const relationByte = entry.readUInt8(18);
|
|
195
|
-
const extAddr = entry.slice(8, 16);
|
|
196
|
-
neighbors.push({
|
|
197
|
-
linkquality: entry.readUInt8(21),
|
|
198
|
-
networkAddress: entry.readUInt16LE(16),
|
|
199
|
-
ieeeAddr: new buffalo_1.Buffalo(extAddr).readIeeeAddr(),
|
|
200
|
-
relationship: (relationByte >> 1) & ((1 << 3) - 1),
|
|
201
|
-
depth: entry.readUInt8(20)
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
const request = async (startIndex) => {
|
|
206
|
-
try {
|
|
207
|
-
const resultPayload = await this.driver.sendCommand(constants_1.ZiGateCommandCode.ManagementLQI, { targetAddress: networkAddress, startIndex: startIndex });
|
|
208
|
-
const data = resultPayload.payload.payload;
|
|
209
|
-
if (data[1] !== 0) { // status
|
|
210
|
-
throw new Error(`LQI for '${networkAddress}' failed`);
|
|
211
|
-
}
|
|
212
|
-
const tableList = [];
|
|
213
|
-
const response = {
|
|
214
|
-
status: data[1],
|
|
215
|
-
tableEntrys: data[2],
|
|
216
|
-
startIndex: data[3],
|
|
217
|
-
tableListCount: data[4],
|
|
218
|
-
tableList: tableList
|
|
219
|
-
};
|
|
220
|
-
let tableEntry = [];
|
|
221
|
-
let counter = 0;
|
|
222
|
-
for (let i = 5; i < ((response.tableListCount * 22) + 5); i++) { // one tableentry = 22 bytes
|
|
223
|
-
tableEntry.push(data[i]);
|
|
224
|
-
counter++;
|
|
225
|
-
if (counter === 22) {
|
|
226
|
-
response.tableList.push(Buffer.from(tableEntry));
|
|
227
|
-
tableEntry = [];
|
|
228
|
-
counter = 0;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
debug.log("LQI RESPONSE - addr: " + networkAddress.toString(16) + " status: "
|
|
232
|
-
+ response.status + " read " + (response.tableListCount + response.startIndex)
|
|
233
|
-
+ "/" + response.tableEntrys + " entrys");
|
|
234
|
-
return response;
|
|
235
|
-
}
|
|
236
|
-
catch (error) {
|
|
237
|
-
const msg = "LQI REQUEST FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
|
|
238
|
-
debug.log(msg);
|
|
239
|
-
return Promise.reject(new Error(msg));
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
let response = await request(0);
|
|
243
|
-
add(response.tableList);
|
|
244
|
-
let nextStartIndex = response.tableListCount;
|
|
245
|
-
while (neighbors.length < response.tableEntrys) {
|
|
246
|
-
response = await request(nextStartIndex);
|
|
247
|
-
add(response.tableList);
|
|
248
|
-
nextStartIndex += response.tableListCount;
|
|
249
|
-
}
|
|
250
|
-
return { neighbors };
|
|
251
|
-
}, networkAddress);
|
|
252
|
-
}
|
|
253
|
-
;
|
|
254
|
-
// @TODO
|
|
255
|
-
routingTable(networkAddress) {
|
|
256
|
-
debug.log('RoutingTable, %o', arguments);
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
;
|
|
260
|
-
async nodeDescriptor(networkAddress) {
|
|
261
|
-
return this.queue.execute(async () => {
|
|
262
|
-
debug.log('nodeDescriptor, \n %o', arguments);
|
|
263
|
-
try {
|
|
264
|
-
const nodeDescriptorResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.NodeDescriptor, {
|
|
265
|
-
targetShortAddress: networkAddress
|
|
266
|
-
});
|
|
267
|
-
const data = nodeDescriptorResponse.payload.payload;
|
|
268
|
-
const buf = data;
|
|
269
|
-
const logicaltype = (data[4] & 7);
|
|
270
|
-
let type = 'Unknown';
|
|
271
|
-
switch (logicaltype) {
|
|
272
|
-
case 1:
|
|
273
|
-
type = 'Router';
|
|
274
|
-
break;
|
|
275
|
-
case 2:
|
|
276
|
-
type = 'EndDevice';
|
|
277
|
-
break;
|
|
278
|
-
case 0:
|
|
279
|
-
type = 'Coordinator';
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
const manufacturer = buf.readUInt16LE(7);
|
|
283
|
-
debug.log("RECEIVING NODE_DESCRIPTOR - addr: 0x" + networkAddress.toString(16)
|
|
284
|
-
+ " type: " + type + " manufacturer: 0x" + manufacturer.toString(16));
|
|
285
|
-
return { manufacturerCode: manufacturer, type };
|
|
286
|
-
}
|
|
287
|
-
catch (error) {
|
|
288
|
-
const msg = "RECEIVING NODE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
|
|
289
|
-
debug.error(msg);
|
|
290
|
-
return Promise.reject(new Error(msg));
|
|
291
|
-
}
|
|
292
|
-
}, networkAddress);
|
|
293
|
-
}
|
|
294
|
-
;
|
|
295
|
-
async activeEndpoints(networkAddress) {
|
|
296
|
-
return this.queue.execute(async () => {
|
|
297
|
-
debug.log('ActiveEndpoints request');
|
|
298
|
-
const payload = {
|
|
299
|
-
targetShortAddress: networkAddress
|
|
300
|
-
};
|
|
301
|
-
try {
|
|
302
|
-
const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.ActiveEndpoint, payload);
|
|
303
|
-
const buf = Buffer.from(result.payload.payload);
|
|
304
|
-
const epCount = buf.readUInt8(4);
|
|
305
|
-
const epList = [];
|
|
306
|
-
for (let i = 5; i < (epCount + 5); i++) {
|
|
307
|
-
epList.push(buf.readUInt8(i));
|
|
308
|
-
}
|
|
309
|
-
const payloadAE = {
|
|
310
|
-
endpoints: epList
|
|
311
|
-
};
|
|
312
|
-
debug.log('ActiveEndpoints response: %o', payloadAE);
|
|
313
|
-
return payloadAE;
|
|
314
|
-
}
|
|
315
|
-
catch (error) {
|
|
316
|
-
debug.error("RECEIVING ActiveEndpoints FAILED, %o", error);
|
|
317
|
-
return Promise.reject(new Error("RECEIVING ActiveEndpoints FAILED " + error));
|
|
318
|
-
}
|
|
319
|
-
}, networkAddress);
|
|
320
|
-
}
|
|
321
|
-
;
|
|
322
|
-
async simpleDescriptor(networkAddress, endpointID) {
|
|
323
|
-
return this.queue.execute(async () => {
|
|
324
|
-
debug.log('SimpleDescriptor request: %o', arguments);
|
|
325
|
-
try {
|
|
326
|
-
const payload = {
|
|
327
|
-
targetShortAddress: networkAddress,
|
|
328
|
-
endpoint: endpointID
|
|
329
|
-
};
|
|
330
|
-
const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.SimpleDescriptor, payload);
|
|
331
|
-
const buf = result.payload.payload;
|
|
332
|
-
if (buf.length > 11) {
|
|
333
|
-
const inCount = buf.readUInt8(11);
|
|
334
|
-
const inClusters = [];
|
|
335
|
-
let cIndex = 12;
|
|
336
|
-
for (let i = 0; i < inCount; i++) {
|
|
337
|
-
inClusters[i] = buf.readUInt16LE(cIndex);
|
|
338
|
-
cIndex += 2;
|
|
339
|
-
}
|
|
340
|
-
const outCount = buf.readUInt8(12 + (inCount * 2));
|
|
341
|
-
const outClusters = [];
|
|
342
|
-
cIndex = 13 + (inCount * 2);
|
|
343
|
-
for (let l = 0; l < outCount; l++) {
|
|
344
|
-
outClusters[l] = buf.readUInt16LE(cIndex);
|
|
345
|
-
cIndex += 2;
|
|
346
|
-
}
|
|
347
|
-
const resultPayload = {
|
|
348
|
-
profileID: buf.readUInt16LE(6),
|
|
349
|
-
endpointID: buf.readUInt8(5),
|
|
350
|
-
deviceID: buf.readUInt16LE(8),
|
|
351
|
-
inputClusters: inClusters,
|
|
352
|
-
outputClusters: outClusters
|
|
353
|
-
};
|
|
354
|
-
return resultPayload;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
catch (error) {
|
|
358
|
-
const msg = "RECEIVING SIMPLE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16)
|
|
359
|
-
+ " EP:" + endpointID + " " + error;
|
|
360
|
-
debug.error(msg);
|
|
361
|
-
return Promise.reject(new Error(msg));
|
|
362
|
-
}
|
|
363
|
-
}, networkAddress);
|
|
364
|
-
}
|
|
365
|
-
;
|
|
366
|
-
async bind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
|
|
367
|
-
return this.queue.execute(async () => {
|
|
368
|
-
debug.log('bind %o', arguments);
|
|
369
|
-
let payload = {
|
|
370
|
-
targetExtendedAddress: sourceIeeeAddress,
|
|
371
|
-
targetEndpoint: sourceEndpoint,
|
|
372
|
-
clusterID: clusterID,
|
|
373
|
-
destinationAddressMode: (type === 'group') ? constants_1.ADDRESS_MODE.group : constants_1.ADDRESS_MODE.ieee,
|
|
374
|
-
destinationAddress: destinationAddressOrGroup,
|
|
375
|
-
};
|
|
376
|
-
if (typeof destinationEndpoint !== undefined) {
|
|
377
|
-
// @ts-ignore
|
|
378
|
-
payload['destinationEndpoint'] = destinationEndpoint;
|
|
379
|
-
}
|
|
380
|
-
const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.Bind, payload, null, { destinationNetworkAddress });
|
|
381
|
-
let data = result.payload.payload;
|
|
382
|
-
if (data[1] === 0) {
|
|
383
|
-
debug.log('Bind %s success', sourceIeeeAddress);
|
|
384
|
-
return Promise.resolve();
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
const msg = `Bind ${sourceIeeeAddress} failed`;
|
|
388
|
-
debug.error(msg);
|
|
389
|
-
return Promise.reject(new Error(msg));
|
|
390
|
-
}
|
|
391
|
-
}, destinationNetworkAddress);
|
|
392
|
-
}
|
|
393
|
-
;
|
|
394
|
-
async unbind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
|
|
395
|
-
return this.queue.execute(async () => {
|
|
396
|
-
debug.log('unbind %o', arguments);
|
|
397
|
-
let payload = {
|
|
398
|
-
targetExtendedAddress: sourceIeeeAddress,
|
|
399
|
-
targetEndpoint: sourceEndpoint,
|
|
400
|
-
clusterID: clusterID,
|
|
401
|
-
destinationAddressMode: (type === 'group') ? constants_1.ADDRESS_MODE.group : constants_1.ADDRESS_MODE.ieee,
|
|
402
|
-
destinationAddress: destinationAddressOrGroup,
|
|
403
|
-
};
|
|
404
|
-
if (typeof destinationEndpoint !== undefined) {
|
|
405
|
-
// @ts-ignore
|
|
406
|
-
payload['destinationEndpoint'] = destinationEndpoint;
|
|
407
|
-
}
|
|
408
|
-
const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.UnBind, payload, null, { destinationNetworkAddress });
|
|
409
|
-
let data = result.payload.payload;
|
|
410
|
-
if (data[1] === 0) {
|
|
411
|
-
debug.log('Unbind %s success', sourceIeeeAddress);
|
|
412
|
-
return Promise.resolve();
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
const msg = `Unbind ${sourceIeeeAddress} failed`;
|
|
416
|
-
debug.error(msg);
|
|
417
|
-
return Promise.reject(new Error(msg));
|
|
418
|
-
}
|
|
419
|
-
}, destinationNetworkAddress);
|
|
420
|
-
}
|
|
421
|
-
;
|
|
422
|
-
async removeDevice(networkAddress, ieeeAddr) {
|
|
423
|
-
return this.queue.execute(async () => {
|
|
424
|
-
const payload = {
|
|
425
|
-
shortAddress: networkAddress,
|
|
426
|
-
extendedAddress: ieeeAddr,
|
|
427
|
-
rejoin: 0,
|
|
428
|
-
removeChildren: 0
|
|
429
|
-
};
|
|
430
|
-
return this.driver.sendCommand(constants_1.ZiGateCommandCode.ManagementLeaveRequest, payload)
|
|
431
|
-
.then((Response) => {
|
|
432
|
-
return Promise.resolve();
|
|
433
|
-
}).catch(() => Promise.reject(new Error("ManagementLeaveRequest failed")));
|
|
434
|
-
}, networkAddress);
|
|
435
|
-
}
|
|
436
|
-
;
|
|
437
|
-
async sendZclFrameToEndpoint(ieeeAddr, networkAddress, endpoint, zclFrame, timeout, disableResponse, disableRecovery, sourceEndpoint) {
|
|
438
|
-
return this.queue.execute(async () => {
|
|
439
|
-
return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint || 1, zclFrame, timeout, disableResponse, disableRecovery, 0, 0, false, false);
|
|
440
|
-
}, networkAddress);
|
|
441
|
-
}
|
|
442
|
-
;
|
|
443
|
-
async sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt, dataRequestAttempt, checkedNetworkAddress, discoveredRoute) {
|
|
444
|
-
debug.info('sendZclFrameToEndpointInternal %s:%i/%i (%i,%i,%i)', ieeeAddr, networkAddress, endpoint, responseAttempt, dataRequestAttempt, this.queue.count());
|
|
445
|
-
let response = null;
|
|
446
|
-
const data = zclFrame.toBuffer();
|
|
447
|
-
const command = zclFrame.getCommand();
|
|
448
|
-
const payload = {
|
|
449
|
-
addressMode: constants_1.ADDRESS_MODE.short,
|
|
450
|
-
targetShortAddress: networkAddress,
|
|
451
|
-
sourceEndpoint: sourceEndpoint || 0x01,
|
|
452
|
-
destinationEndpoint: endpoint,
|
|
453
|
-
profileID: 0x0104,
|
|
454
|
-
clusterID: zclFrame.Cluster.ID,
|
|
455
|
-
securityMode: 0x02,
|
|
456
|
-
radius: 30,
|
|
457
|
-
dataLength: data.length,
|
|
458
|
-
data: data,
|
|
459
|
-
};
|
|
460
|
-
if (command.hasOwnProperty('response') && disableResponse === false) {
|
|
461
|
-
response = this.waitFor(networkAddress, endpoint, zclFrame.Header.frameControl.frameType, zcl_1.Direction.SERVER_TO_CLIENT, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, command.response, timeout);
|
|
462
|
-
}
|
|
463
|
-
else if (!zclFrame.Header.frameControl.disableDefaultResponse) {
|
|
464
|
-
response = this.waitFor(networkAddress, endpoint, zcl_1.FrameType.GLOBAL, zcl_1.Direction.SERVER_TO_CLIENT, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, zcl_1.Foundation.defaultRsp.ID, timeout);
|
|
465
|
-
}
|
|
466
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, disableResponse).catch((e) => {
|
|
467
|
-
if (responseAttempt < 1 && !disableRecovery) {
|
|
468
|
-
// @todo discover route
|
|
469
|
-
return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt + 1, dataRequestAttempt, checkedNetworkAddress, discoveredRoute);
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
// @TODO add dataConfirmResult
|
|
473
|
-
// @TODO if error codes route / no_resourses wait and resend
|
|
474
|
-
if (response !== null) {
|
|
475
|
-
try {
|
|
476
|
-
// @ts-ignore
|
|
477
|
-
return await response.promise;
|
|
478
|
-
// @todo discover route
|
|
479
|
-
}
|
|
480
|
-
catch (error) {
|
|
481
|
-
debug.error('Response error %s (%s:%d,%d)', error.toString(), ieeeAddr, networkAddress, responseAttempt);
|
|
482
|
-
if (responseAttempt < 1 && !disableRecovery) {
|
|
483
|
-
return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt + 1, dataRequestAttempt, checkedNetworkAddress, discoveredRoute);
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
throw error;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
return null;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
async sendZclFrameToAll(endpoint, zclFrame, sourceEndpoint) {
|
|
495
|
-
return this.queue.execute(async () => {
|
|
496
|
-
if (sourceEndpoint !== 0x01 /*&& sourceEndpoint !== 242*/) { // @todo on zigate firmware without gp causes hang
|
|
497
|
-
debug.error('source endpoint %d, not supported', sourceEndpoint);
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
const data = zclFrame.toBuffer();
|
|
501
|
-
const payload = {
|
|
502
|
-
addressMode: constants_1.ADDRESS_MODE.short,
|
|
503
|
-
targetShortAddress: 0xFFFD,
|
|
504
|
-
sourceEndpoint: sourceEndpoint,
|
|
505
|
-
destinationEndpoint: endpoint,
|
|
506
|
-
profileID: /*sourceEndpoint === 242 ? 0xa1e0 :*/ 0x0104,
|
|
507
|
-
clusterID: zclFrame.Cluster.ID,
|
|
508
|
-
securityMode: 0x02,
|
|
509
|
-
radius: 30,
|
|
510
|
-
dataLength: data.length,
|
|
511
|
-
data: data,
|
|
512
|
-
};
|
|
513
|
-
debug.log('sendZclFrameToAll %o', payload);
|
|
514
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, true);
|
|
515
|
-
await (0, utils_1.Wait)(200);
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
;
|
|
519
|
-
async sendZclFrameToGroup(groupID, zclFrame, sourceEndpoint) {
|
|
520
|
-
return this.queue.execute(async () => {
|
|
521
|
-
debug.log('sendZclFrameToGroup %o', arguments);
|
|
522
|
-
const data = zclFrame.toBuffer();
|
|
523
|
-
const payload = {
|
|
524
|
-
addressMode: constants_1.ADDRESS_MODE.group,
|
|
525
|
-
targetShortAddress: groupID,
|
|
526
|
-
sourceEndpoint: sourceEndpoint || 0x01,
|
|
527
|
-
destinationEndpoint: 0xFF,
|
|
528
|
-
profileID: 0x0104,
|
|
529
|
-
clusterID: zclFrame.Cluster.ID,
|
|
530
|
-
securityMode: 0x02,
|
|
531
|
-
radius: 30,
|
|
532
|
-
dataLength: data.length,
|
|
533
|
-
data: data,
|
|
534
|
-
};
|
|
535
|
-
debug.log('sendZclFrameToGroup: \n %o', payload);
|
|
536
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, true);
|
|
537
|
-
await (0, utils_1.Wait)(200);
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
;
|
|
541
|
-
/**
|
|
542
|
-
* Supplementary functions
|
|
543
|
-
*/
|
|
544
|
-
async initNetwork() {
|
|
545
|
-
debug.log(`Set channel mask ${this.networkOptions.channelList} key`);
|
|
546
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetChannelMask, { channelMask: channelsToMask(this.networkOptions.channelList) });
|
|
547
|
-
debug.log(`Set security key`);
|
|
548
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetSecurityStateKey, {
|
|
549
|
-
keyType: this.networkOptions.networkKeyDistribute ?
|
|
550
|
-
constants_1.ZPSNwkKeyState.ZPS_ZDO_DISTRIBUTED_LINK_KEY :
|
|
551
|
-
constants_1.ZPSNwkKeyState.ZPS_ZDO_PRECONFIGURED_LINK_KEY,
|
|
552
|
-
key: this.networkOptions.networkKey,
|
|
553
|
-
});
|
|
554
|
-
try {
|
|
555
|
-
// The block is wrapped in trapping because if the network is already created, the firmware does not accept the new key.
|
|
556
|
-
debug.log('Set EPanID %h', this.networkOptions.extendedPanID);
|
|
557
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetExtendedPANID, {
|
|
558
|
-
panId: this.networkOptions.extendedPanID,
|
|
559
|
-
});
|
|
560
|
-
await this.driver.sendCommand(constants_1.ZiGateCommandCode.StartNetwork, {});
|
|
561
|
-
}
|
|
562
|
-
catch (e) {
|
|
563
|
-
// @TODO Depending on the type of error, output clear text to the user
|
|
564
|
-
debug.error("%o", e);
|
|
565
|
-
}
|
|
566
|
-
return Promise.resolve();
|
|
567
|
-
}
|
|
568
|
-
waitFor(networkAddress, endpoint, frameType, direction, transactionSequenceNumber, clusterID, commandIdentifier, timeout) {
|
|
569
|
-
debug.log('waitForInternal %o', arguments);
|
|
570
|
-
const payload = {
|
|
571
|
-
address: networkAddress,
|
|
572
|
-
endpoint,
|
|
573
|
-
clusterID,
|
|
574
|
-
commandIdentifier,
|
|
575
|
-
frameType,
|
|
576
|
-
direction,
|
|
577
|
-
transactionSequenceNumber,
|
|
578
|
-
};
|
|
579
|
-
const waiter = this.waitress.waitFor(payload, timeout);
|
|
580
|
-
const cancel = () => this.waitress.remove(waiter.ID);
|
|
581
|
-
return { promise: waiter.start().promise, cancel };
|
|
582
|
-
}
|
|
583
|
-
;
|
|
584
|
-
static async isValidPath(path) {
|
|
585
|
-
return zigate_1.default.isValidPath(path);
|
|
586
|
-
}
|
|
587
|
-
static async autoDetectPath() {
|
|
588
|
-
return zigate_1.default.autoDetectPath();
|
|
589
|
-
}
|
|
590
|
-
/**
|
|
591
|
-
* InterPAN !!! not implemented
|
|
592
|
-
*/
|
|
593
|
-
async setChannelInterPAN(channel) {
|
|
594
|
-
debug.log('setChannelInterPAN', arguments);
|
|
595
|
-
return Promise.reject("Not supported");
|
|
596
|
-
}
|
|
597
|
-
;
|
|
598
|
-
async sendZclFrameInterPANToIeeeAddr(zclFrame, ieeeAddress) {
|
|
599
|
-
debug.log('sendZclFrameInterPANToIeeeAddr', arguments);
|
|
600
|
-
return Promise.reject("Not supported");
|
|
601
|
-
}
|
|
602
|
-
;
|
|
603
|
-
async sendZclFrameInterPANBroadcast(zclFrame, timeout) {
|
|
604
|
-
debug.log('sendZclFrameInterPANBroadcast', arguments);
|
|
605
|
-
return Promise.reject("Not supported");
|
|
606
|
-
}
|
|
607
|
-
;
|
|
608
|
-
restoreChannelInterPAN() {
|
|
609
|
-
debug.log('restoreChannelInterPAN', arguments);
|
|
610
|
-
return Promise.reject("Not supported");
|
|
611
|
-
}
|
|
612
|
-
;
|
|
613
|
-
deviceAnnounceListener(networkAddress, ieeeAddr) {
|
|
614
|
-
// @todo debounce
|
|
615
|
-
const payload = { networkAddress, ieeeAddr };
|
|
616
|
-
if (this.joinPermitted === true) {
|
|
617
|
-
this.emit(Events.Events.deviceJoined, payload);
|
|
618
|
-
}
|
|
619
|
-
else {
|
|
620
|
-
this.emit(Events.Events.deviceAnnounce, payload);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
zclDataListener(data) {
|
|
624
|
-
if (data.zclFrame instanceof zcl_1.ZclFrame) {
|
|
625
|
-
const payload = {
|
|
626
|
-
address: data.ziGateObject.payload.sourceAddress,
|
|
627
|
-
frame: data.zclFrame,
|
|
628
|
-
endpoint: data.ziGateObject.payload.sourceEndpoint,
|
|
629
|
-
linkquality: data.ziGateObject.frame.readRSSI(),
|
|
630
|
-
groupID: null,
|
|
631
|
-
wasBroadcast: false,
|
|
632
|
-
destinationEndpoint: data.ziGateObject.payload.destinationEndpoint,
|
|
633
|
-
};
|
|
634
|
-
this.waitress.resolve(payload);
|
|
635
|
-
this.emit(Events.Events.zclData, payload);
|
|
636
|
-
}
|
|
637
|
-
else {
|
|
638
|
-
debug.error('msg not zclFrame', data.zclFrame);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
rawDataListener(data) {
|
|
642
|
-
const payload = {
|
|
643
|
-
clusterID: data.ziGateObject.payload.clusterID,
|
|
644
|
-
data: data.ziGateObject.payload.payload,
|
|
645
|
-
address: data.ziGateObject.payload.sourceAddress,
|
|
646
|
-
endpoint: data.ziGateObject.payload.sourceEndpoint,
|
|
647
|
-
linkquality: data.ziGateObject.frame.readRSSI(),
|
|
648
|
-
groupID: null,
|
|
649
|
-
wasBroadcast: false,
|
|
650
|
-
destinationEndpoint: data.ziGateObject.payload.destinationEndpoint,
|
|
651
|
-
};
|
|
652
|
-
this.emit(Events.Events.rawData, payload);
|
|
653
|
-
}
|
|
654
|
-
leaveIndicationListener(data) {
|
|
655
|
-
debug.log('LeaveIndication %o', data);
|
|
656
|
-
const payload = {
|
|
657
|
-
networkAddress: data.ziGateObject.payload.extendedAddress,
|
|
658
|
-
ieeeAddr: data.ziGateObject.payload.extendedAddress
|
|
659
|
-
};
|
|
660
|
-
this.emit(Events.Events.deviceLeave, payload);
|
|
661
|
-
}
|
|
662
|
-
waitressTimeoutFormatter(matcher, timeout) {
|
|
663
|
-
return `Timeout - ${matcher.address} - ${matcher.endpoint}` +
|
|
664
|
-
` - ${matcher.transactionSequenceNumber} - ${matcher.clusterID}` +
|
|
665
|
-
` - ${matcher.commandIdentifier} after ${timeout}ms`;
|
|
666
|
-
}
|
|
667
|
-
waitressValidator(payload, matcher) {
|
|
668
|
-
const transactionSequenceNumber = payload.frame.Header.transactionSequenceNumber;
|
|
669
|
-
return (!matcher.address || payload.address === matcher.address) &&
|
|
670
|
-
matcher.endpoint === payload.endpoint &&
|
|
671
|
-
(!matcher.transactionSequenceNumber || transactionSequenceNumber === matcher.transactionSequenceNumber) &&
|
|
672
|
-
matcher.clusterID === payload.frame.Cluster.ID &&
|
|
673
|
-
matcher.frameType === payload.frame.Header.frameControl.frameType &&
|
|
674
|
-
matcher.commandIdentifier === payload.frame.Header.commandIdentifier &&
|
|
675
|
-
matcher.direction === payload.frame.Header.frameControl.direction;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
exports.default = ZiGateAdapter;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const Events = __importStar(require("../../events"));
|
|
30
|
+
const adapter_1 = __importDefault(require("../../adapter"));
|
|
31
|
+
const zcl_1 = require("../../../zcl");
|
|
32
|
+
const utils_1 = require("../../../utils");
|
|
33
|
+
const zigate_1 = __importDefault(require("../driver/zigate"));
|
|
34
|
+
const debug_1 = require("../debug");
|
|
35
|
+
const constants_1 = require("../driver/constants");
|
|
36
|
+
const buffalo_1 = require("../../../buffalo");
|
|
37
|
+
const debug = (0, debug_1.Debug)('adapter');
|
|
38
|
+
const default_bind_group = 901; // https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/lib/constants.js#L3
|
|
39
|
+
const channelsToMask = (channels) => channels.map((x) => 2 ** x).reduce((acc, x) => acc + x, 0);
|
|
40
|
+
class ZiGateAdapter extends adapter_1.default {
|
|
41
|
+
constructor(networkOptions, serialPortOptions, backupPath, adapterOptions, logger) {
|
|
42
|
+
super(networkOptions, serialPortOptions, backupPath, adapterOptions, logger);
|
|
43
|
+
this.joinPermitted = false;
|
|
44
|
+
this.driver = new zigate_1.default(serialPortOptions.path, serialPortOptions);
|
|
45
|
+
this.waitress = new utils_1.Waitress(this.waitressValidator, this.waitressTimeoutFormatter);
|
|
46
|
+
this.driver.on('received', this.zclDataListener.bind(this));
|
|
47
|
+
this.driver.on('receivedRaw', this.rawDataListener.bind(this));
|
|
48
|
+
this.driver.on('LeaveIndication', this.leaveIndicationListener.bind(this));
|
|
49
|
+
this.driver.on('DeviceAnnounce', this.deviceAnnounceListener.bind(this));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Adapter methods
|
|
53
|
+
*/
|
|
54
|
+
async start() {
|
|
55
|
+
let startResult = 'resumed';
|
|
56
|
+
try {
|
|
57
|
+
await this.driver.open();
|
|
58
|
+
debug.log("Connected to ZiGate adapter successfully.");
|
|
59
|
+
const resetResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.Reset, {}, 5000);
|
|
60
|
+
if (resetResponse.code === constants_1.ZiGateMessageCode.RestartNonFactoryNew) {
|
|
61
|
+
startResult = 'resumed';
|
|
62
|
+
}
|
|
63
|
+
else if (resetResponse.code === constants_1.ZiGateMessageCode.RestartFactoryNew) {
|
|
64
|
+
startResult = 'reset';
|
|
65
|
+
}
|
|
66
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawMode, { enabled: 0x01 });
|
|
67
|
+
// @todo check
|
|
68
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetDeviceType, {
|
|
69
|
+
deviceType: constants_1.DEVICE_TYPE.coordinator
|
|
70
|
+
});
|
|
71
|
+
await this.initNetwork();
|
|
72
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.AddGroup, {
|
|
73
|
+
addressMode: constants_1.ADDRESS_MODE.short,
|
|
74
|
+
shortAddress: 0x0000,
|
|
75
|
+
sourceEndpoint: 0x01,
|
|
76
|
+
destinationEndpoint: 0x01,
|
|
77
|
+
groupAddress: default_bind_group
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw new Error("failed to connect to zigate adapter " + error.message);
|
|
82
|
+
}
|
|
83
|
+
const concurrent = this.adapterOptions && this.adapterOptions.concurrent ?
|
|
84
|
+
this.adapterOptions.concurrent : 2;
|
|
85
|
+
debug.log(`Adapter concurrent: ${concurrent}`);
|
|
86
|
+
this.queue = new utils_1.Queue(concurrent);
|
|
87
|
+
return startResult; // 'resumed' | 'reset' | 'restored'
|
|
88
|
+
}
|
|
89
|
+
async stop() {
|
|
90
|
+
this.closing = true;
|
|
91
|
+
await this.driver.close();
|
|
92
|
+
}
|
|
93
|
+
async getCoordinator() {
|
|
94
|
+
debug.log('getCoordinator');
|
|
95
|
+
const networkResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.GetNetworkState);
|
|
96
|
+
// @TODO deal hardcoded endpoints, made by analogy with deconz
|
|
97
|
+
// polling the coordinator on some firmware went into a memory leak, so we don't ask this info
|
|
98
|
+
const response = {
|
|
99
|
+
networkAddress: 0,
|
|
100
|
+
manufacturerID: 0,
|
|
101
|
+
ieeeAddr: networkResponse.payload.extendedAddress,
|
|
102
|
+
endpoints: constants_1.coordinatorEndpoints
|
|
103
|
+
};
|
|
104
|
+
debug.log('getCoordinator %o', response);
|
|
105
|
+
return response;
|
|
106
|
+
}
|
|
107
|
+
;
|
|
108
|
+
async getCoordinatorVersion() {
|
|
109
|
+
debug.log('getCoordinatorVersion');
|
|
110
|
+
return this.driver.sendCommand(constants_1.ZiGateCommandCode.GetVersion, {})
|
|
111
|
+
.then((result) => {
|
|
112
|
+
const meta = {
|
|
113
|
+
"transportrev": 0,
|
|
114
|
+
"product": 0,
|
|
115
|
+
"majorrel": parseInt(result.payload.major).toString(16),
|
|
116
|
+
"minorrel": parseInt(result.payload.minor).toString(16),
|
|
117
|
+
"maintrel": parseInt(result.payload.revision).toString(16),
|
|
118
|
+
"revision": parseInt(result.payload.revision).toString(16),
|
|
119
|
+
};
|
|
120
|
+
const version = {
|
|
121
|
+
type: 'zigate',
|
|
122
|
+
meta: meta,
|
|
123
|
+
};
|
|
124
|
+
return Promise.resolve(version);
|
|
125
|
+
})
|
|
126
|
+
.catch((e) => {
|
|
127
|
+
debug.error(e);
|
|
128
|
+
return Promise.reject(new Error("" + e));
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
;
|
|
132
|
+
async permitJoin(seconds, networkAddress) {
|
|
133
|
+
const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.PermitJoin, {
|
|
134
|
+
targetShortAddress: networkAddress || 0xFFFC,
|
|
135
|
+
interval: seconds,
|
|
136
|
+
TCsignificance: 0
|
|
137
|
+
});
|
|
138
|
+
// const result = await this.driver.sendCommand(ZiGateCommandCode.PermitJoinStatus, {});
|
|
139
|
+
// Suitable only for the coordinator, not the entire network or point-to-point for routers
|
|
140
|
+
this.joinPermitted = result.payload.status === 0;
|
|
141
|
+
}
|
|
142
|
+
;
|
|
143
|
+
async addInstallCode(ieeeAddress, key) {
|
|
144
|
+
return Promise.reject(new Error('Add install code is not supported'));
|
|
145
|
+
}
|
|
146
|
+
async reset(type) {
|
|
147
|
+
debug.log('reset %s', type);
|
|
148
|
+
if (type === 'soft') {
|
|
149
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.Reset, {}, 5000);
|
|
150
|
+
}
|
|
151
|
+
else if (type === 'hard') {
|
|
152
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.ErasePersistentData, {}, 5000);
|
|
153
|
+
}
|
|
154
|
+
return Promise.resolve();
|
|
155
|
+
}
|
|
156
|
+
;
|
|
157
|
+
async getNetworkParameters() {
|
|
158
|
+
debug.log('getNetworkParameters');
|
|
159
|
+
return this.driver.sendCommand(constants_1.ZiGateCommandCode.GetNetworkState, {}, 10000)
|
|
160
|
+
.then((NetworkStateResponse) => {
|
|
161
|
+
const resultPayload = {
|
|
162
|
+
panID: NetworkStateResponse.payload.PANID,
|
|
163
|
+
extendedPanID: NetworkStateResponse.payload.ExtPANID,
|
|
164
|
+
channel: NetworkStateResponse.payload.Channel
|
|
165
|
+
};
|
|
166
|
+
return Promise.resolve(resultPayload);
|
|
167
|
+
}).catch(() => Promise.reject(new Error("Get network parameters failed")));
|
|
168
|
+
}
|
|
169
|
+
;
|
|
170
|
+
/**
|
|
171
|
+
* https://zigate.fr/documentation/deplacer-le-pdm-de-la-zigate/
|
|
172
|
+
* pdm from host
|
|
173
|
+
*/
|
|
174
|
+
async supportsBackup() {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
;
|
|
178
|
+
async backup() {
|
|
179
|
+
throw new Error("This adapter does not support backup");
|
|
180
|
+
}
|
|
181
|
+
;
|
|
182
|
+
async setTransmitPower(value) {
|
|
183
|
+
debug.log('setTransmitPower, %o', arguments);
|
|
184
|
+
return this.driver.sendCommand(constants_1.ZiGateCommandCode.SetTXpower, { value: value })
|
|
185
|
+
.then(() => Promise.resolve()).catch(() => Promise.reject(new Error("Set transmitpower failed")));
|
|
186
|
+
}
|
|
187
|
+
;
|
|
188
|
+
async lqi(networkAddress) {
|
|
189
|
+
return this.queue.execute(async () => {
|
|
190
|
+
debug.log('lqi, %o', arguments);
|
|
191
|
+
const neighbors = [];
|
|
192
|
+
const add = (list) => {
|
|
193
|
+
for (const entry of list) {
|
|
194
|
+
const relationByte = entry.readUInt8(18);
|
|
195
|
+
const extAddr = entry.slice(8, 16);
|
|
196
|
+
neighbors.push({
|
|
197
|
+
linkquality: entry.readUInt8(21),
|
|
198
|
+
networkAddress: entry.readUInt16LE(16),
|
|
199
|
+
ieeeAddr: new buffalo_1.Buffalo(extAddr).readIeeeAddr(),
|
|
200
|
+
relationship: (relationByte >> 1) & ((1 << 3) - 1),
|
|
201
|
+
depth: entry.readUInt8(20)
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const request = async (startIndex) => {
|
|
206
|
+
try {
|
|
207
|
+
const resultPayload = await this.driver.sendCommand(constants_1.ZiGateCommandCode.ManagementLQI, { targetAddress: networkAddress, startIndex: startIndex });
|
|
208
|
+
const data = resultPayload.payload.payload;
|
|
209
|
+
if (data[1] !== 0) { // status
|
|
210
|
+
throw new Error(`LQI for '${networkAddress}' failed`);
|
|
211
|
+
}
|
|
212
|
+
const tableList = [];
|
|
213
|
+
const response = {
|
|
214
|
+
status: data[1],
|
|
215
|
+
tableEntrys: data[2],
|
|
216
|
+
startIndex: data[3],
|
|
217
|
+
tableListCount: data[4],
|
|
218
|
+
tableList: tableList
|
|
219
|
+
};
|
|
220
|
+
let tableEntry = [];
|
|
221
|
+
let counter = 0;
|
|
222
|
+
for (let i = 5; i < ((response.tableListCount * 22) + 5); i++) { // one tableentry = 22 bytes
|
|
223
|
+
tableEntry.push(data[i]);
|
|
224
|
+
counter++;
|
|
225
|
+
if (counter === 22) {
|
|
226
|
+
response.tableList.push(Buffer.from(tableEntry));
|
|
227
|
+
tableEntry = [];
|
|
228
|
+
counter = 0;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
debug.log("LQI RESPONSE - addr: " + networkAddress.toString(16) + " status: "
|
|
232
|
+
+ response.status + " read " + (response.tableListCount + response.startIndex)
|
|
233
|
+
+ "/" + response.tableEntrys + " entrys");
|
|
234
|
+
return response;
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
const msg = "LQI REQUEST FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
|
|
238
|
+
debug.log(msg);
|
|
239
|
+
return Promise.reject(new Error(msg));
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
let response = await request(0);
|
|
243
|
+
add(response.tableList);
|
|
244
|
+
let nextStartIndex = response.tableListCount;
|
|
245
|
+
while (neighbors.length < response.tableEntrys) {
|
|
246
|
+
response = await request(nextStartIndex);
|
|
247
|
+
add(response.tableList);
|
|
248
|
+
nextStartIndex += response.tableListCount;
|
|
249
|
+
}
|
|
250
|
+
return { neighbors };
|
|
251
|
+
}, networkAddress);
|
|
252
|
+
}
|
|
253
|
+
;
|
|
254
|
+
// @TODO
|
|
255
|
+
routingTable(networkAddress) {
|
|
256
|
+
debug.log('RoutingTable, %o', arguments);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
;
|
|
260
|
+
async nodeDescriptor(networkAddress) {
|
|
261
|
+
return this.queue.execute(async () => {
|
|
262
|
+
debug.log('nodeDescriptor, \n %o', arguments);
|
|
263
|
+
try {
|
|
264
|
+
const nodeDescriptorResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.NodeDescriptor, {
|
|
265
|
+
targetShortAddress: networkAddress
|
|
266
|
+
});
|
|
267
|
+
const data = nodeDescriptorResponse.payload.payload;
|
|
268
|
+
const buf = data;
|
|
269
|
+
const logicaltype = (data[4] & 7);
|
|
270
|
+
let type = 'Unknown';
|
|
271
|
+
switch (logicaltype) {
|
|
272
|
+
case 1:
|
|
273
|
+
type = 'Router';
|
|
274
|
+
break;
|
|
275
|
+
case 2:
|
|
276
|
+
type = 'EndDevice';
|
|
277
|
+
break;
|
|
278
|
+
case 0:
|
|
279
|
+
type = 'Coordinator';
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
const manufacturer = buf.readUInt16LE(7);
|
|
283
|
+
debug.log("RECEIVING NODE_DESCRIPTOR - addr: 0x" + networkAddress.toString(16)
|
|
284
|
+
+ " type: " + type + " manufacturer: 0x" + manufacturer.toString(16));
|
|
285
|
+
return { manufacturerCode: manufacturer, type };
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
const msg = "RECEIVING NODE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
|
|
289
|
+
debug.error(msg);
|
|
290
|
+
return Promise.reject(new Error(msg));
|
|
291
|
+
}
|
|
292
|
+
}, networkAddress);
|
|
293
|
+
}
|
|
294
|
+
;
|
|
295
|
+
async activeEndpoints(networkAddress) {
|
|
296
|
+
return this.queue.execute(async () => {
|
|
297
|
+
debug.log('ActiveEndpoints request');
|
|
298
|
+
const payload = {
|
|
299
|
+
targetShortAddress: networkAddress
|
|
300
|
+
};
|
|
301
|
+
try {
|
|
302
|
+
const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.ActiveEndpoint, payload);
|
|
303
|
+
const buf = Buffer.from(result.payload.payload);
|
|
304
|
+
const epCount = buf.readUInt8(4);
|
|
305
|
+
const epList = [];
|
|
306
|
+
for (let i = 5; i < (epCount + 5); i++) {
|
|
307
|
+
epList.push(buf.readUInt8(i));
|
|
308
|
+
}
|
|
309
|
+
const payloadAE = {
|
|
310
|
+
endpoints: epList
|
|
311
|
+
};
|
|
312
|
+
debug.log('ActiveEndpoints response: %o', payloadAE);
|
|
313
|
+
return payloadAE;
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
debug.error("RECEIVING ActiveEndpoints FAILED, %o", error);
|
|
317
|
+
return Promise.reject(new Error("RECEIVING ActiveEndpoints FAILED " + error));
|
|
318
|
+
}
|
|
319
|
+
}, networkAddress);
|
|
320
|
+
}
|
|
321
|
+
;
|
|
322
|
+
async simpleDescriptor(networkAddress, endpointID) {
|
|
323
|
+
return this.queue.execute(async () => {
|
|
324
|
+
debug.log('SimpleDescriptor request: %o', arguments);
|
|
325
|
+
try {
|
|
326
|
+
const payload = {
|
|
327
|
+
targetShortAddress: networkAddress,
|
|
328
|
+
endpoint: endpointID
|
|
329
|
+
};
|
|
330
|
+
const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.SimpleDescriptor, payload);
|
|
331
|
+
const buf = result.payload.payload;
|
|
332
|
+
if (buf.length > 11) {
|
|
333
|
+
const inCount = buf.readUInt8(11);
|
|
334
|
+
const inClusters = [];
|
|
335
|
+
let cIndex = 12;
|
|
336
|
+
for (let i = 0; i < inCount; i++) {
|
|
337
|
+
inClusters[i] = buf.readUInt16LE(cIndex);
|
|
338
|
+
cIndex += 2;
|
|
339
|
+
}
|
|
340
|
+
const outCount = buf.readUInt8(12 + (inCount * 2));
|
|
341
|
+
const outClusters = [];
|
|
342
|
+
cIndex = 13 + (inCount * 2);
|
|
343
|
+
for (let l = 0; l < outCount; l++) {
|
|
344
|
+
outClusters[l] = buf.readUInt16LE(cIndex);
|
|
345
|
+
cIndex += 2;
|
|
346
|
+
}
|
|
347
|
+
const resultPayload = {
|
|
348
|
+
profileID: buf.readUInt16LE(6),
|
|
349
|
+
endpointID: buf.readUInt8(5),
|
|
350
|
+
deviceID: buf.readUInt16LE(8),
|
|
351
|
+
inputClusters: inClusters,
|
|
352
|
+
outputClusters: outClusters
|
|
353
|
+
};
|
|
354
|
+
return resultPayload;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
const msg = "RECEIVING SIMPLE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16)
|
|
359
|
+
+ " EP:" + endpointID + " " + error;
|
|
360
|
+
debug.error(msg);
|
|
361
|
+
return Promise.reject(new Error(msg));
|
|
362
|
+
}
|
|
363
|
+
}, networkAddress);
|
|
364
|
+
}
|
|
365
|
+
;
|
|
366
|
+
async bind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
|
|
367
|
+
return this.queue.execute(async () => {
|
|
368
|
+
debug.log('bind %o', arguments);
|
|
369
|
+
let payload = {
|
|
370
|
+
targetExtendedAddress: sourceIeeeAddress,
|
|
371
|
+
targetEndpoint: sourceEndpoint,
|
|
372
|
+
clusterID: clusterID,
|
|
373
|
+
destinationAddressMode: (type === 'group') ? constants_1.ADDRESS_MODE.group : constants_1.ADDRESS_MODE.ieee,
|
|
374
|
+
destinationAddress: destinationAddressOrGroup,
|
|
375
|
+
};
|
|
376
|
+
if (typeof destinationEndpoint !== undefined) {
|
|
377
|
+
// @ts-ignore
|
|
378
|
+
payload['destinationEndpoint'] = destinationEndpoint;
|
|
379
|
+
}
|
|
380
|
+
const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.Bind, payload, null, { destinationNetworkAddress });
|
|
381
|
+
let data = result.payload.payload;
|
|
382
|
+
if (data[1] === 0) {
|
|
383
|
+
debug.log('Bind %s success', sourceIeeeAddress);
|
|
384
|
+
return Promise.resolve();
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
const msg = `Bind ${sourceIeeeAddress} failed`;
|
|
388
|
+
debug.error(msg);
|
|
389
|
+
return Promise.reject(new Error(msg));
|
|
390
|
+
}
|
|
391
|
+
}, destinationNetworkAddress);
|
|
392
|
+
}
|
|
393
|
+
;
|
|
394
|
+
async unbind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
|
|
395
|
+
return this.queue.execute(async () => {
|
|
396
|
+
debug.log('unbind %o', arguments);
|
|
397
|
+
let payload = {
|
|
398
|
+
targetExtendedAddress: sourceIeeeAddress,
|
|
399
|
+
targetEndpoint: sourceEndpoint,
|
|
400
|
+
clusterID: clusterID,
|
|
401
|
+
destinationAddressMode: (type === 'group') ? constants_1.ADDRESS_MODE.group : constants_1.ADDRESS_MODE.ieee,
|
|
402
|
+
destinationAddress: destinationAddressOrGroup,
|
|
403
|
+
};
|
|
404
|
+
if (typeof destinationEndpoint !== undefined) {
|
|
405
|
+
// @ts-ignore
|
|
406
|
+
payload['destinationEndpoint'] = destinationEndpoint;
|
|
407
|
+
}
|
|
408
|
+
const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.UnBind, payload, null, { destinationNetworkAddress });
|
|
409
|
+
let data = result.payload.payload;
|
|
410
|
+
if (data[1] === 0) {
|
|
411
|
+
debug.log('Unbind %s success', sourceIeeeAddress);
|
|
412
|
+
return Promise.resolve();
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
const msg = `Unbind ${sourceIeeeAddress} failed`;
|
|
416
|
+
debug.error(msg);
|
|
417
|
+
return Promise.reject(new Error(msg));
|
|
418
|
+
}
|
|
419
|
+
}, destinationNetworkAddress);
|
|
420
|
+
}
|
|
421
|
+
;
|
|
422
|
+
async removeDevice(networkAddress, ieeeAddr) {
|
|
423
|
+
return this.queue.execute(async () => {
|
|
424
|
+
const payload = {
|
|
425
|
+
shortAddress: networkAddress,
|
|
426
|
+
extendedAddress: ieeeAddr,
|
|
427
|
+
rejoin: 0,
|
|
428
|
+
removeChildren: 0
|
|
429
|
+
};
|
|
430
|
+
return this.driver.sendCommand(constants_1.ZiGateCommandCode.ManagementLeaveRequest, payload)
|
|
431
|
+
.then((Response) => {
|
|
432
|
+
return Promise.resolve();
|
|
433
|
+
}).catch(() => Promise.reject(new Error("ManagementLeaveRequest failed")));
|
|
434
|
+
}, networkAddress);
|
|
435
|
+
}
|
|
436
|
+
;
|
|
437
|
+
async sendZclFrameToEndpoint(ieeeAddr, networkAddress, endpoint, zclFrame, timeout, disableResponse, disableRecovery, sourceEndpoint) {
|
|
438
|
+
return this.queue.execute(async () => {
|
|
439
|
+
return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint || 1, zclFrame, timeout, disableResponse, disableRecovery, 0, 0, false, false);
|
|
440
|
+
}, networkAddress);
|
|
441
|
+
}
|
|
442
|
+
;
|
|
443
|
+
async sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt, dataRequestAttempt, checkedNetworkAddress, discoveredRoute) {
|
|
444
|
+
debug.info('sendZclFrameToEndpointInternal %s:%i/%i (%i,%i,%i)', ieeeAddr, networkAddress, endpoint, responseAttempt, dataRequestAttempt, this.queue.count());
|
|
445
|
+
let response = null;
|
|
446
|
+
const data = zclFrame.toBuffer();
|
|
447
|
+
const command = zclFrame.getCommand();
|
|
448
|
+
const payload = {
|
|
449
|
+
addressMode: constants_1.ADDRESS_MODE.short,
|
|
450
|
+
targetShortAddress: networkAddress,
|
|
451
|
+
sourceEndpoint: sourceEndpoint || 0x01,
|
|
452
|
+
destinationEndpoint: endpoint,
|
|
453
|
+
profileID: 0x0104,
|
|
454
|
+
clusterID: zclFrame.Cluster.ID,
|
|
455
|
+
securityMode: 0x02,
|
|
456
|
+
radius: 30,
|
|
457
|
+
dataLength: data.length,
|
|
458
|
+
data: data,
|
|
459
|
+
};
|
|
460
|
+
if (command.hasOwnProperty('response') && disableResponse === false) {
|
|
461
|
+
response = this.waitFor(networkAddress, endpoint, zclFrame.Header.frameControl.frameType, zcl_1.Direction.SERVER_TO_CLIENT, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, command.response, timeout);
|
|
462
|
+
}
|
|
463
|
+
else if (!zclFrame.Header.frameControl.disableDefaultResponse) {
|
|
464
|
+
response = this.waitFor(networkAddress, endpoint, zcl_1.FrameType.GLOBAL, zcl_1.Direction.SERVER_TO_CLIENT, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, zcl_1.Foundation.defaultRsp.ID, timeout);
|
|
465
|
+
}
|
|
466
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, disableResponse).catch((e) => {
|
|
467
|
+
if (responseAttempt < 1 && !disableRecovery) {
|
|
468
|
+
// @todo discover route
|
|
469
|
+
return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt + 1, dataRequestAttempt, checkedNetworkAddress, discoveredRoute);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
// @TODO add dataConfirmResult
|
|
473
|
+
// @TODO if error codes route / no_resourses wait and resend
|
|
474
|
+
if (response !== null) {
|
|
475
|
+
try {
|
|
476
|
+
// @ts-ignore
|
|
477
|
+
return await response.promise;
|
|
478
|
+
// @todo discover route
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
debug.error('Response error %s (%s:%d,%d)', error.toString(), ieeeAddr, networkAddress, responseAttempt);
|
|
482
|
+
if (responseAttempt < 1 && !disableRecovery) {
|
|
483
|
+
return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt + 1, dataRequestAttempt, checkedNetworkAddress, discoveredRoute);
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
throw error;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
async sendZclFrameToAll(endpoint, zclFrame, sourceEndpoint) {
|
|
495
|
+
return this.queue.execute(async () => {
|
|
496
|
+
if (sourceEndpoint !== 0x01 /*&& sourceEndpoint !== 242*/) { // @todo on zigate firmware without gp causes hang
|
|
497
|
+
debug.error('source endpoint %d, not supported', sourceEndpoint);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const data = zclFrame.toBuffer();
|
|
501
|
+
const payload = {
|
|
502
|
+
addressMode: constants_1.ADDRESS_MODE.short,
|
|
503
|
+
targetShortAddress: 0xFFFD,
|
|
504
|
+
sourceEndpoint: sourceEndpoint,
|
|
505
|
+
destinationEndpoint: endpoint,
|
|
506
|
+
profileID: /*sourceEndpoint === 242 ? 0xa1e0 :*/ 0x0104,
|
|
507
|
+
clusterID: zclFrame.Cluster.ID,
|
|
508
|
+
securityMode: 0x02,
|
|
509
|
+
radius: 30,
|
|
510
|
+
dataLength: data.length,
|
|
511
|
+
data: data,
|
|
512
|
+
};
|
|
513
|
+
debug.log('sendZclFrameToAll %o', payload);
|
|
514
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, true);
|
|
515
|
+
await (0, utils_1.Wait)(200);
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
;
|
|
519
|
+
async sendZclFrameToGroup(groupID, zclFrame, sourceEndpoint) {
|
|
520
|
+
return this.queue.execute(async () => {
|
|
521
|
+
debug.log('sendZclFrameToGroup %o', arguments);
|
|
522
|
+
const data = zclFrame.toBuffer();
|
|
523
|
+
const payload = {
|
|
524
|
+
addressMode: constants_1.ADDRESS_MODE.group,
|
|
525
|
+
targetShortAddress: groupID,
|
|
526
|
+
sourceEndpoint: sourceEndpoint || 0x01,
|
|
527
|
+
destinationEndpoint: 0xFF,
|
|
528
|
+
profileID: 0x0104,
|
|
529
|
+
clusterID: zclFrame.Cluster.ID,
|
|
530
|
+
securityMode: 0x02,
|
|
531
|
+
radius: 30,
|
|
532
|
+
dataLength: data.length,
|
|
533
|
+
data: data,
|
|
534
|
+
};
|
|
535
|
+
debug.log('sendZclFrameToGroup: \n %o', payload);
|
|
536
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, true);
|
|
537
|
+
await (0, utils_1.Wait)(200);
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
;
|
|
541
|
+
/**
|
|
542
|
+
* Supplementary functions
|
|
543
|
+
*/
|
|
544
|
+
async initNetwork() {
|
|
545
|
+
debug.log(`Set channel mask ${this.networkOptions.channelList} key`);
|
|
546
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetChannelMask, { channelMask: channelsToMask(this.networkOptions.channelList) });
|
|
547
|
+
debug.log(`Set security key`);
|
|
548
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetSecurityStateKey, {
|
|
549
|
+
keyType: this.networkOptions.networkKeyDistribute ?
|
|
550
|
+
constants_1.ZPSNwkKeyState.ZPS_ZDO_DISTRIBUTED_LINK_KEY :
|
|
551
|
+
constants_1.ZPSNwkKeyState.ZPS_ZDO_PRECONFIGURED_LINK_KEY,
|
|
552
|
+
key: this.networkOptions.networkKey,
|
|
553
|
+
});
|
|
554
|
+
try {
|
|
555
|
+
// The block is wrapped in trapping because if the network is already created, the firmware does not accept the new key.
|
|
556
|
+
debug.log('Set EPanID %h', this.networkOptions.extendedPanID);
|
|
557
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetExtendedPANID, {
|
|
558
|
+
panId: this.networkOptions.extendedPanID,
|
|
559
|
+
});
|
|
560
|
+
await this.driver.sendCommand(constants_1.ZiGateCommandCode.StartNetwork, {});
|
|
561
|
+
}
|
|
562
|
+
catch (e) {
|
|
563
|
+
// @TODO Depending on the type of error, output clear text to the user
|
|
564
|
+
debug.error("%o", e);
|
|
565
|
+
}
|
|
566
|
+
return Promise.resolve();
|
|
567
|
+
}
|
|
568
|
+
waitFor(networkAddress, endpoint, frameType, direction, transactionSequenceNumber, clusterID, commandIdentifier, timeout) {
|
|
569
|
+
debug.log('waitForInternal %o', arguments);
|
|
570
|
+
const payload = {
|
|
571
|
+
address: networkAddress,
|
|
572
|
+
endpoint,
|
|
573
|
+
clusterID,
|
|
574
|
+
commandIdentifier,
|
|
575
|
+
frameType,
|
|
576
|
+
direction,
|
|
577
|
+
transactionSequenceNumber,
|
|
578
|
+
};
|
|
579
|
+
const waiter = this.waitress.waitFor(payload, timeout);
|
|
580
|
+
const cancel = () => this.waitress.remove(waiter.ID);
|
|
581
|
+
return { promise: waiter.start().promise, cancel };
|
|
582
|
+
}
|
|
583
|
+
;
|
|
584
|
+
static async isValidPath(path) {
|
|
585
|
+
return zigate_1.default.isValidPath(path);
|
|
586
|
+
}
|
|
587
|
+
static async autoDetectPath() {
|
|
588
|
+
return zigate_1.default.autoDetectPath();
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* InterPAN !!! not implemented
|
|
592
|
+
*/
|
|
593
|
+
async setChannelInterPAN(channel) {
|
|
594
|
+
debug.log('setChannelInterPAN', arguments);
|
|
595
|
+
return Promise.reject("Not supported");
|
|
596
|
+
}
|
|
597
|
+
;
|
|
598
|
+
async sendZclFrameInterPANToIeeeAddr(zclFrame, ieeeAddress) {
|
|
599
|
+
debug.log('sendZclFrameInterPANToIeeeAddr', arguments);
|
|
600
|
+
return Promise.reject("Not supported");
|
|
601
|
+
}
|
|
602
|
+
;
|
|
603
|
+
async sendZclFrameInterPANBroadcast(zclFrame, timeout) {
|
|
604
|
+
debug.log('sendZclFrameInterPANBroadcast', arguments);
|
|
605
|
+
return Promise.reject("Not supported");
|
|
606
|
+
}
|
|
607
|
+
;
|
|
608
|
+
restoreChannelInterPAN() {
|
|
609
|
+
debug.log('restoreChannelInterPAN', arguments);
|
|
610
|
+
return Promise.reject("Not supported");
|
|
611
|
+
}
|
|
612
|
+
;
|
|
613
|
+
deviceAnnounceListener(networkAddress, ieeeAddr) {
|
|
614
|
+
// @todo debounce
|
|
615
|
+
const payload = { networkAddress, ieeeAddr };
|
|
616
|
+
if (this.joinPermitted === true) {
|
|
617
|
+
this.emit(Events.Events.deviceJoined, payload);
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
this.emit(Events.Events.deviceAnnounce, payload);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
zclDataListener(data) {
|
|
624
|
+
if (data.zclFrame instanceof zcl_1.ZclFrame) {
|
|
625
|
+
const payload = {
|
|
626
|
+
address: data.ziGateObject.payload.sourceAddress,
|
|
627
|
+
frame: data.zclFrame,
|
|
628
|
+
endpoint: data.ziGateObject.payload.sourceEndpoint,
|
|
629
|
+
linkquality: data.ziGateObject.frame.readRSSI(),
|
|
630
|
+
groupID: null,
|
|
631
|
+
wasBroadcast: false,
|
|
632
|
+
destinationEndpoint: data.ziGateObject.payload.destinationEndpoint,
|
|
633
|
+
};
|
|
634
|
+
this.waitress.resolve(payload);
|
|
635
|
+
this.emit(Events.Events.zclData, payload);
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
debug.error('msg not zclFrame', data.zclFrame);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
rawDataListener(data) {
|
|
642
|
+
const payload = {
|
|
643
|
+
clusterID: data.ziGateObject.payload.clusterID,
|
|
644
|
+
data: data.ziGateObject.payload.payload,
|
|
645
|
+
address: data.ziGateObject.payload.sourceAddress,
|
|
646
|
+
endpoint: data.ziGateObject.payload.sourceEndpoint,
|
|
647
|
+
linkquality: data.ziGateObject.frame.readRSSI(),
|
|
648
|
+
groupID: null,
|
|
649
|
+
wasBroadcast: false,
|
|
650
|
+
destinationEndpoint: data.ziGateObject.payload.destinationEndpoint,
|
|
651
|
+
};
|
|
652
|
+
this.emit(Events.Events.rawData, payload);
|
|
653
|
+
}
|
|
654
|
+
leaveIndicationListener(data) {
|
|
655
|
+
debug.log('LeaveIndication %o', data);
|
|
656
|
+
const payload = {
|
|
657
|
+
networkAddress: data.ziGateObject.payload.extendedAddress,
|
|
658
|
+
ieeeAddr: data.ziGateObject.payload.extendedAddress
|
|
659
|
+
};
|
|
660
|
+
this.emit(Events.Events.deviceLeave, payload);
|
|
661
|
+
}
|
|
662
|
+
waitressTimeoutFormatter(matcher, timeout) {
|
|
663
|
+
return `Timeout - ${matcher.address} - ${matcher.endpoint}` +
|
|
664
|
+
` - ${matcher.transactionSequenceNumber} - ${matcher.clusterID}` +
|
|
665
|
+
` - ${matcher.commandIdentifier} after ${timeout}ms`;
|
|
666
|
+
}
|
|
667
|
+
waitressValidator(payload, matcher) {
|
|
668
|
+
const transactionSequenceNumber = payload.frame.Header.transactionSequenceNumber;
|
|
669
|
+
return (!matcher.address || payload.address === matcher.address) &&
|
|
670
|
+
matcher.endpoint === payload.endpoint &&
|
|
671
|
+
(!matcher.transactionSequenceNumber || transactionSequenceNumber === matcher.transactionSequenceNumber) &&
|
|
672
|
+
matcher.clusterID === payload.frame.Cluster.ID &&
|
|
673
|
+
matcher.frameType === payload.frame.Header.frameControl.frameType &&
|
|
674
|
+
matcher.commandIdentifier === payload.frame.Header.commandIdentifier &&
|
|
675
|
+
matcher.direction === payload.frame.Header.frameControl.direction;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
exports.default = ZiGateAdapter;
|
|
679
679
|
//# sourceMappingURL=zigateAdapter.js.map
|