fix: address audit findings — fitting trigger, race guards, state conflicts
wear-check: - Send weak pulse light (brightness=26) to trigger FFE4 fitting report - Timeout degrades to pass (backward compat with 17-byte firmware) - Sync _resolved flag prevents double-resolve treating: - Only treat run_state=0x00 as completion after seeing run_state=0x02 (prevents false completion on startup) - Sync _finishing flag replaces async data.completed for race prevention - onStatus preserves paused state during fitting loss (|| fittingLost) - Remove dead _fittingTimer reference from onUnload auto-scan: - Sync _completed flag in _scanComplete prevents double-build
这个提交包含在:
@@ -84,7 +84,6 @@ Page({
|
||||
if (this._onFitting) ble.off('fitting', this._onFitting)
|
||||
if (this._onRunState) ble.off('run_state', this._onRunState)
|
||||
if (this._localTimer) clearInterval(this._localTimer)
|
||||
if (this._fittingTimer) clearTimeout(this._fittingTimer)
|
||||
},
|
||||
|
||||
onFitting: function (data) {
|
||||
@@ -99,10 +98,15 @@ Page({
|
||||
},
|
||||
|
||||
onRunState: function (data) {
|
||||
if (this.data.completed) return
|
||||
if (this._finishing) return
|
||||
console.log('[TREAT] run_state:', data.run_state)
|
||||
|
||||
if (data.run_state === 0xFF) {
|
||||
if (data.run_state === 0x02) {
|
||||
this._seenTreating = true
|
||||
}
|
||||
|
||||
if (data.run_state === 0xFF && !this._finishing) {
|
||||
this._finishing = true
|
||||
this.setData({ deviceFault: true })
|
||||
var self = this
|
||||
wx.showModal({
|
||||
@@ -114,7 +118,7 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
if (data.run_state === 0x00 && !this.data.paused && !this.data.fittingLost) {
|
||||
if (data.run_state === 0x00 && this._seenTreating && !this.data.fittingLost) {
|
||||
this.finishAsComplete()
|
||||
}
|
||||
},
|
||||
@@ -170,7 +174,7 @@ Page({
|
||||
this.setData({
|
||||
battery: status.battery || this.data.battery,
|
||||
temperature: status.temperature || this.data.temperature,
|
||||
paused: status.mode_state === 0x03
|
||||
paused: status.mode_state === 0x03 || this.data.fittingLost
|
||||
})
|
||||
this.syncCommands()
|
||||
},
|
||||
@@ -239,7 +243,8 @@ Page({
|
||||
},
|
||||
|
||||
finishAsComplete: function () {
|
||||
if (this.data.completed) return
|
||||
if (this._finishing) return
|
||||
this._finishing = true
|
||||
var elapsed = Math.min(this.data.duration, Date.now() - this.data.startedAt)
|
||||
this.syncTreatmentEnd(elapsed)
|
||||
this.onComplete({
|
||||
|
||||
在新工单中引用
屏蔽一个用户