Skip to content

Commit

Permalink
networkStatus resend handling performed by firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Feb 8, 2024
1 parent fd78fac commit 43e88ef
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
4 changes: 2 additions & 2 deletions lib/Af.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class Af extends EventEmitter {
if(ex.status == 178) { // ZApsTableFull
wf.cancel()
areqCancelable._cancels.delete(wf)
await Q.delay((Math.random() + 0.5) * 16000)
await Q.delay((Math.random() + 0.5) * 32000)

// in case the src rtg changed
const srcRtg = dstEp.getSrcRtg()
Expand Down Expand Up @@ -372,7 +372,7 @@ class Af extends EventEmitter {
if(ex.status == 178) { // ZApsTableFull
wf.cancel()
areqCancelable._cancels.delete(wf)
await Q.delay((Math.random() + 0.5) * 16000)
await Q.delay((Math.random() + 0.5) * 32000)
continue
}
throw ex
Expand Down
45 changes: 0 additions & 45 deletions lib/AfController.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,6 @@ class AfController extends EventEmitter {
}
/* eslint-enable no-unused-vars */

registerResend(dstAddr, interestedCodes = DefaultCodesOfInterest){
const afResendEvt = 'ZDO:networkStatus:' + dstAddr.toString(16)
let sendTime = Date.now()
const deferred = Q.defer()
let done = false

const handleResend = data=>{
if(done) return
if(interestedCodes.includes(data.code) && (Date.now() - sendTime) > 6500){
debug(`possible indirect expiration for 0x${dstAddr.toString(16)}, resending (status: 0x${data.code.toString(16)})`)
done = true
deferred.resolve(data.code)
} else {
this.removeListener(...eventArgs)
this.once(...eventArgs)
}
}

const eventArgs = [afResendEvt, handleResend] // declaration gets hoisted, handleResend can reference it

this.once(...eventArgs);

const cleanup = ()=>{
this.removeListener(...eventArgs)
deferred.resolve(null)
}

return {cleanup, promise: deferred.promise}
}
async indirectSend(sendFn, cfg){
const shouldIndirect = this.shouldSendIndrect(cfg.dstAddr)
let retries = cfg.retries || 4
Expand Down Expand Up @@ -97,10 +68,6 @@ class AfController extends EventEmitter {
if(cfg.signalTimeout){
promises.push(cfg.signalTimeout.promise)
}
if(shouldIndirect){
resend = this.registerResend(cfg.dstAddr)
promises.push(resend.promise.then(a=>a||'resend'))
}
const result = await Q.cancelledRace(promises)

// Handle results for any of the promises that might have returned
Expand All @@ -109,18 +76,6 @@ class AfController extends EventEmitter {
await Q.cancelledRace([Q.delay(5000), workPromise]) // Wait at-least 5 seconds after a module error
canSrcRtg = false
}
else if(typeof result === 'number') {
// network status code
if(result != 6 && i != retries) {
const waitTime = 3500 - (Date.now() - attemptStart)
if(waitTime > 0) await Q.cancelledRace([Q.delay(waitTime), workPromise])

// After a MTO failure we can still srcrtg, the coordinator will send a RReq
// NO_ROUTE_AVAIL occurs when the device has no free space for new routes
if(result != 0x0c) canSrcRtg = false
}
// if is 6 (INDIRECT_TRANS_EXPIRY) we continue
}
else if(result !== undefined) {
// should be the same as result
return await workPromise
Expand Down

0 comments on commit 43e88ef

Please sign in to comment.