Skip to content

Commit

Permalink
start the zcl timeout after module send
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Sep 19, 2023
1 parent ed76766 commit 2da433a
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/Af.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ class Af extends EventEmitter {
}
}

static async areqCancel(areq){
const a = areq.catch(ex => {
if (!ex || ex.message !== "canceled") throw ex
})
areq.cancel()
await a
}

async _zclFoundation(srcEp, dstEp, cId, cmd, zclData, cfg) {
var areq,
manufCode = 0,
Expand Down Expand Up @@ -460,7 +468,7 @@ class Af extends EventEmitter {
else // from local ep to remote ep
mandatoryEvent = 'ZCL:foundation:' + nwkAddr.toString(16) + ':' + dstEp.getEpId() + ':' + srcEp.getEpId() + ':' + seqNum;

areq = this.waitFor(mandatoryEvent, AreqTimeout)
areq = this.waitFor(mandatoryEvent)
}

var afOptions = cfg.afOptions !== undefined ? cfg.afOptions : {}
Expand All @@ -470,11 +478,7 @@ class Af extends EventEmitter {
rsp = await this.send(srcEp, dstEp, cId, zclBuffer, afOptions)
} catch (err) {
if (areq) {
const a = areq.catch(ex => {
if (!ex || ex.message !== "canceled") throw ex
})
areq.cancel()
await a
await Af.areqCancel(areq)
}
if (err.code == "ETIMEDOUT") {
err.message = "zclFoundation(" + cmd + ":" + seqNum + ") " + err.message
Expand All @@ -487,9 +491,12 @@ class Af extends EventEmitter {
}

try {
rsp = await areq
rsp = await Q.timeout(areq, AreqTimeout)
} catch (err) {
if (err.code == "ETIMEDOUT") {
if (areq) {
await Af.areqCancel(areq)
}
err.message = "zclFoundation(" + cmd + ":" + seqNum + ") " + err.message
}
throw err
Expand Down Expand Up @@ -551,7 +558,7 @@ class Af extends EventEmitter {
mandatoryEvent = 'ZCL:functional:' + dstEp.nwkAddr.toString(16) + ':' + dstEp.getEpId() + ':' + srcEp.getEpId() + ':' + seqNum;


areq = this.waitFor(mandatoryEvent, AreqTimeout)
areq = this.waitFor(mandatoryEvent)
}

var afOptions = cfg.afOptions !== undefined ? cfg.afOptions : {}
Expand All @@ -561,11 +568,7 @@ class Af extends EventEmitter {
rsp = await this.send(srcEp, dstEp, cId, zclBuffer, afOptions)
} catch (err) {
if (areq) {
const a = areq.catch(ex => {
if (!ex || ex.message !== "canceled") throw ex
})
areq.cancel()
await a
await Af.areqCancel(areq)
}
if (err.code == "ETIMEDOUT") {
err.message = "zclFunctional(" + cmd + ":" + seqNum + ") " + err.message
Expand All @@ -578,9 +581,12 @@ class Af extends EventEmitter {
}

try {
rsp = await areq
rsp = await Q.timeout(areq, AreqTimeout)
} catch (err) {
if (err.code == "ETIMEDOUT") {
if (areq) {
await Af.areqCancel(areq)
}
err.message = "zclFunctional(" + cmd + ":" + seqNum + ") " + err.message
}
throw err
Expand Down

0 comments on commit 2da433a

Please sign in to comment.