Skip to content
This repository has been archived by the owner on Jul 5, 2019. It is now read-only.

Commit

Permalink
Add converter to new format
Browse files Browse the repository at this point in the history
The source of truth will now be the denormalized deduplicated format
This also includes the responsibilities of `zcl_meta` from `zcl-packet`
Also fixed some missing information discovered
  • Loading branch information
qm3ster committed Jan 18, 2019
1 parent 8ab4a09 commit ae4ea77
Show file tree
Hide file tree
Showing 5 changed files with 1,760 additions and 15 deletions.
22 changes: 22 additions & 0 deletions Hacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,31 @@ If you know of any hacks that aren't listed here, please submit a PR to this doc
However, [parsing-framing tests](https://github.com/zigbeer/zcl-packet/blob/351c4204ab64a21668b01f8da68063a50835fe9c/test/zcl.test.js#L175-L177) suggest that these fields end up in an object under the `attrData` field, and so should be accessible on the event without this modification.

**Solution**:

1. Revert commit https://github.com/ZigBeans/zcl-packet/commit/a2b39c1b5239317bf8cd58ebf665319a5c039456#diff-9f0b814c660e5e38b20eed3e82ba2512R731
2. Try to access this value in the event handler.

1. [@splitice] added multiple zcl_meta entries for the same command, `imageBlockRsp`
```json
"imageBlockRspSuccess": {
"params": [
{ "status": "uint8" },
{ "manufacturerCode": "uint16" },
{ "imageType": "uint16" },
{ "fileVersion": "uint32" },
{ "fileOffset": "uint32" },
{ "dataLen": "preLenUint8" },
{ "data": "dynUint8" }
],
"dir": 1
},
"imageBlockRspAbort": {
"params": [{ "status": "uint8" }],
"dir": 1
},
```
**Solution**:
Make the structure of `params` suitable for variable data shapes.

[@splitice]: https://github.com/splitice
[@kirovilya]: https://github.com/kirovilya
Expand Down
31 changes: 17 additions & 14 deletions src/definitions/cluster_defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,24 @@
"calcPeriod": { "id": 22, "type": "uint16" },
"numRSSIMeasurements": { "id": 23, "type": "uint16" }
},
"cmd": { "setAbsolute": 0, "setDevCfg": 1, "getDevCfg": 2, "getData": 3 },
"cmd": {
"setAbsolute": 0,
"setDevCfg": 1,
"getDevCfg": 2,
"getData": 3,
"rssiRsp": 4,
"sendPings": 5,
"anchorNodeAnnounce": 6
},
"cmdRsp": {
"devCfgRsp": 0,
"dataRsp": 1,
"dataNotif": 2,
"compactDataNotif": 3,
"rssiPing": 4
"rssiPing": 4,
"rssiReq": 5,
"reportRssiMeas": 6,
"reqOwnLocation": 7
}
},
"genAnalogInput": {
Expand Down Expand Up @@ -405,27 +416,17 @@
"imageStamp": { "id": 10, "type": "uint32" }
},
"cmd": {
"imageNotify": 0,
"queryNextImageReq": 1,
"queryNextImageRsp": 2,
"imageBlockReq": 3,
"imagePageReq": 4,
"imageBlockRsp": 5,
"upgradeEndReq": 6,
"upgradeEndRsp": 7,
"querySpecificFileReq": 8,
"querySpecificFileRsp": 9
"querySpecificFileReq": 8
},
"cmdRsp": {
"imageNotify": 0,
"queryNextImageReq": 1,
"queryNextImageRsp": 2,
"imageBlockReq": 3,
"imagePageReq": 4,
"imageBlockRsp": 5,
"upgradeEndReq": 6,
"upgradeEndRsp": 7,
"querySpecificFileReq": 8,
"querySpecificFileRsp": 9
}
},
Expand Down Expand Up @@ -789,7 +790,9 @@
"enhancedStepHue": 66,
"enhancedMoveToHueAndSaturation": 67,
"colorLoopSet": 68,
"stopMoveStep": 71
"stopMoveStep": 71,
"moveColorTemp": 75,
"stepColorTemp": 76
}
},
"lightingBallastCfg": {
Expand Down
141 changes: 141 additions & 0 deletions src/definitions/convert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { writeFile as _writeFile } from "fs"
import { promisify } from "util"
const writeFile = promisify(_writeFile)

import common = require("./common.json")
import zclMeta = require("./zcl_meta.json")
import clusterDefs = require("./cluster_defs.json")
const { foundation, clusterId: clusterIDs, ...newCommon } = common
const { foundation: foundation2, functional } = zclMeta

writeFile(__dirname + "/_common.json", JSON.stringify(newCommon, undefined, 2))

const newFoundation: Record<
string,
{ id: number; params: [string, string][] } | { id: number; TODO: 1 }
> = {}
for (const fCmdName in foundation) {
const id = foundation[fCmdName as keyof typeof foundation]
const f2 = foundation2[fCmdName as keyof typeof foundation2]
if (f2) {
let { params: oldParams, knownBufLen } = f2
let len = 0
const params = (oldParams as (typeof oldParams)[keyof typeof oldParams][]).map(
x => {
const entry: [string, string] = Object.entries(x)[0]
if (entry[1] == "uint8") len += 1
if (entry[1] == "uint16") len += 2
return entry
}
)
if (len !== knownBufLen)
throw new Error(
`Wrong knownBufLen: expected ${knownBufLen} got ${len} in ${fCmdName}`
)
newFoundation[fCmdName] = {
id,
params
}
} else {
newFoundation[fCmdName] = {
id,
TODO: 1
}
}
}
writeFile(
__dirname + "/_foundation.json",
JSON.stringify(newFoundation, undefined, 2)
)

for (const clName in clusterDefs) {
if (!clusterIDs.hasOwnProperty(clName))
throw new Error(`${clName} in cluster_defs but not in common`)
}
for (const clName in functional) {
if (!clusterIDs.hasOwnProperty(clName))
throw new Error(`${clName} in zcl_meta but not in common`)
}

interface ClusterDef {
id: number
attrs?: { id: number; type: string }[]
cmd?: Record<
string,
{ id: number; params: [string, string][] } | { id: number; TODO: 1 }
>
cmdRsp?: Record<
string,
{ id: number; params: [string, string][] } | { id: number; TODO: 1 }
>
}
const newClusterDefs: Record<string, ClusterDef | { id: number; TODO: 2 }> = {}
for (const clName in clusterIDs) {
const id = clusterIDs[clName as keyof typeof clusterIDs]
const cl1 = clusterDefs[clName as keyof typeof clusterDefs]
const cl2 = functional[clName as keyof typeof functional]
if (!cl1) {
newClusterDefs[clName] = { id, TODO: 2 }
continue
}
const newClusterDef: ClusterDef = { id, attrs: cl1.attrId as any }
for (const fnCmdName in cl2) {
const missing1 = cl1.cmd && !cl1.cmd.hasOwnProperty(fnCmdName)
const missing2 = cl1.cmdRsp && !cl1.cmdRsp.hasOwnProperty(fnCmdName)
if (
(missing1 && missing2) ||
(!cl1.cmd && missing2) ||
(!cl1.cmdRsp && missing1)
)
throw new Error(`${fnCmdName} in zcl_meta but not in cluster_defs`)
}
if (cl1.cmd) {
newClusterDef.cmd = {}
for (const fnCmdName in cl1.cmd) {
const id = cl1.cmd[fnCmdName as keyof typeof cl1.cmd]!
if (!cl2) {
newClusterDef.cmd[fnCmdName] = { id, TODO: 1 }
continue
}
const desc = cl2[fnCmdName as keyof typeof cl2]
if (!desc) {
newClusterDef.cmd[fnCmdName] = { id, TODO: 1 }
continue
}
const { params: oldParams, dir } = desc
const params = (oldParams as (typeof oldParams)[keyof typeof oldParams][]).map(
x => Object.entries(x)[0] as [string, string]
)
if (dir !== 0) throw new Error(`Dir not 0 on ${clName} / ${fnCmdName}`)
newClusterDef.cmd[fnCmdName] = { id, params }
}
}
if (cl1.cmdRsp) {
newClusterDef.cmdRsp = {}
for (const fnCmdName in cl1.cmdRsp) {
const id = cl1.cmdRsp[fnCmdName as keyof typeof cl1.cmdRsp]!
if (!cl2) {
newClusterDef.cmdRsp[fnCmdName] = { id, TODO: 1 }
continue
}
const desc = cl2[fnCmdName as keyof typeof cl2]
if (!desc) {
newClusterDef.cmdRsp[fnCmdName] = { id, TODO: 1 }
continue
}
const { params: oldParams, dir } = desc

const params = (oldParams as (typeof oldParams)[keyof typeof oldParams][]).map(
x => Object.entries(x)[0] as [string, string]
)
if (dir !== 1) throw new Error(`Dir not 1 on ${clName}/${fnCmdName}`)
newClusterDef.cmdRsp[fnCmdName] = { id, params }
}
}
newClusterDefs[clName] = newClusterDef
}

writeFile(
__dirname + "/_cluster_defs.json",
JSON.stringify(clusterIDs, undefined, 2)
)
Loading

0 comments on commit ae4ea77

Please sign in to comment.