比较提交

...
10 次代码提交
作者 SHA1 备注 提交日期
Guoguo 8a4f9382e4 fix: audit fixes — add checksum_ok to params parse, passthrough control in command-sync
- parseVendorStatus: add checksum_ok verification for 34-byte and 33-byte params
- command-sync.js: passthrough control, current_gain, hold_time from server payload
- Mark buildVendorCommand33 as deprecated alias
2026-06-12 09:02:43 -07:00
Guoguo 36f12e098e feat: upgrade FFE1 command to 34 bytes with control byte
Per 协议简述(3): Byte33 is now control instruction (0=IDLE, 1=scan,
2=treat), Byte34 is XOR checksum. Backward compat with 33-byte
read-back preserved. All command sites updated with correct control:
- auto-scan: control=0x01 (scan mode)
- treatment-setup: control=0x02 (treat mode)
- stopTreatment: control=0x00 (IDLE)
2026-06-12 09:00:01 -07:00
Guoguo 69621fd2b6 feat: support FFE4 19-byte format with fitting and run_state fields
Per 协议简述(3): FFE4 now 19 bytes — adds Byte17 fitting status
(0=not fitted, 1=fitted) and Byte18 run state (0=IDLE, 1=scanning,
2=treating, FF=fault). Maintains backward compat with 17-byte format.
2026-06-12 08:52:44 -07:00
Guoguo 7270b593ae docs: add updated protocol spec v3 and firmware-mp workflow v1 2026-06-12 08:52:09 -07:00
Guoguo b4d677a9b4 docs: add protocol docs and allow docx in docs/protocols 2026-06-11 04:16:56 -07:00
Guoguo fa44f4f5ad docs: add protocol specs, task sheet, and workflow docs to docs/protocols 2026-06-11 04:16:19 -07:00
Guoguo 340837c700 feat: rebrand to LumiFlow across miniprogram, admin-console, and server 2026-06-10 18:47:22 -07:00
Guoguo edf45690c3 fix: address audit findings for Phase 1 scan
- Extract _cleanup() to properly unregister ADC listener + clear timers
- ADC callback unregisters itself on first receive (prevent duplicates)
- setParams failure now stops scanning and clears all state
- Timeout handler unregisters ADC listener
- Add BLE connection check before scan
- SCAN_TIMEOUT 8s → 12s (must exceed hold_time 10s)
- Pre-compute barWidth in JS instead of float math in WXML
- Error only shows when scanning is false
2026-06-10 08:18:54 -07:00
Guoguo 0ffa67da65 feat: implement MVP Phase 1 — full-area scan with ADC data collection
- Send scan command: all 5 regions LED on, brightness 128
- Listen for ADC notify (17 bytes) instead of broken queryStatus
- Parse and display PD1-PD7 values with visual bars
- Show VBAT/battery info
- Store scan PD data in globalData for Phase 3 smart adjustment
- 8s timeout fallback, stop LED on page unload
2026-06-10 08:16:17 -07:00
Guoguo c9799a5fc1 chore: bump version to v0.1.6 2026-06-05 23:38:02 -07:00
修改 32 个文件,包含 313 行新增141 行删除
+1 -1
查看文件
@@ -10,7 +10,7 @@ admin-console/dist/
docs/reference/小程序及后台管理软件开发资料/ docs/reference/小程序及后台管理软件开发资料/
软件系统说明.docx 软件系统说明.docx
*.docx *.docx
!docs/protocols/协议简述.docx !docs/protocols/*.docx
cloud/sql/ cloud/sql/
certs/ certs/
*.pem *.pem
+1 -1
查看文件
@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>智美 - 管理后台</title> <title>LumiFlow - 管理后台</title>
<!--preload-links--> <!--preload-links-->
<!--app-context--> <!--app-context-->
</head> </head>
+2 -2
查看文件
@@ -1,7 +1,7 @@
<template> <template>
<view class="admin-layout"> <view class="admin-layout">
<view class="sidebar"> <view class="sidebar">
<view class="sidebar-logo">💎 智美</view> <view class="sidebar-logo">💎 LumiFlow</view>
<view class="sidebar-sub">管理后台</view> <view class="sidebar-sub">管理后台</view>
<view class="sidebar-menu"> <view class="sidebar-menu">
<view <view
@@ -54,7 +54,7 @@ export default {
computed: { computed: {
pageTitle() { pageTitle() {
var item = this.menuItems.find(m => m.view === this.currentPage) var item = this.menuItems.find(m => m.view === this.currentPage)
return item ? item.icon + ' ' + item.label : '智美管理后台' return item ? item.icon + ' ' + item.label : 'LumiFlow 管理后台'
}, },
adminName() { adminName() {
var store = useUserStore() var store = useUserStore()
+2 -2
查看文件
@@ -1,11 +1,11 @@
{ {
"name": "智美后台", "name": "LumiFlow 后台",
"appid": "__UNI__HOXADMIN", "appid": "__UNI__HOXADMIN",
"description": "Hox beauty device admin console", "description": "Hox beauty device admin console",
"versionName": "1.0.0", "versionName": "1.0.0",
"versionCode": "100", "versionCode": "100",
"h5": { "h5": {
"title": "智美后台", "title": "LumiFlow 后台",
"router": { "router": {
"mode": "hash", "mode": "hash",
"base": "/admin/" "base": "/admin/"
+1 -1
查看文件
@@ -11,7 +11,7 @@
], ],
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",
"navigationBarTitleText": "智美后台", "navigationBarTitleText": "LumiFlow 后台",
"navigationBarBackgroundColor": "#ffffff", "navigationBarBackgroundColor": "#ffffff",
"backgroundColor": "#f5f5f5" "backgroundColor": "#f5f5f5"
} }
+2 -2
查看文件
@@ -2,7 +2,7 @@
<view class="login-page"> <view class="login-page">
<view class="login-card"> <view class="login-card">
<view class="login-logo">💎</view> <view class="login-logo">💎</view>
<view class="login-title">智美</view> <view class="login-title">LumiFlow</view>
<view class="login-subtitle">管理后台</view> <view class="login-subtitle">管理后台</view>
<view class="form-group"> <view class="form-group">
@@ -32,7 +32,7 @@
</button> </button>
<view class="login-footer">© 2026 智美管理后台</view> <view class="login-footer">© 2026 LumiFlow</view>
</view> </view>
</view> </view>
</template> </template>
二进制文件未显示。
二进制文件未显示。
二进制文件未显示。
二进制文件未显示。
二进制文件未显示。
二进制文件未显示。
二进制文件未显示。
+1 -1
查看文件
@@ -21,7 +21,7 @@
], ],
"window": { "window": {
"navigationBarBackgroundColor": "#ffffff", "navigationBarBackgroundColor": "#ffffff",
"navigationBarTitleText": "智美", "navigationBarTitleText": "LumiFlow",
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",
"backgroundColor": "#f5f5f5" "backgroundColor": "#f5f5f5"
}, },
+90 -57
查看文件
@@ -1,12 +1,17 @@
var ble = require('../../services/ble') var ble = require('../../services/ble')
var SCAN_BRIGHTNESS = 128
var SCAN_TIMEOUT = 12000
Page({ Page({
data: { data: {
statusBarHeight: 44, statusBarHeight: 44,
scanning: true, scanning: true,
scanProgress: 0, scanProgress: 0,
regions: 0x7F, regions: 0x1F,
regionData: [], pdValues: [],
timeout: false, pdRaw: [],
vbat: 0,
battery: 0,
error: '' error: ''
}, },
@@ -22,72 +27,100 @@ Page({
var app = getApp() var app = getApp()
this.setData({ this.setData({
statusBarHeight: app.globalData.statusBarHeight, statusBarHeight: app.globalData.statusBarHeight,
regions: parseInt(options.regions) || 0x7F regions: parseInt(options.regions) || 0x1F
}) })
this.startScan() this.startScan()
}, },
startScan: function () { _cleanup: function () {
var self = this if (this._progressTimer) { clearInterval(this._progressTimer); this._progressTimer = null }
self.setData({ scanning: true, scanProgress: 0, timeout: false }) if (this._timeoutTimer) { clearTimeout(this._timeoutTimer); this._timeoutTimer = null }
if (this._onAdc) { ble.off('adc', this._onAdc); this._onAdc = null }
this._progressTimer = setInterval(function () {
var p = self.data.scanProgress + 2
if (p > 98) p = 98
self.setData({ scanProgress: p })
}, 100)
this._onStatus = function (status) {
if (status.mode_state === 0x01) {
self.setData({ scanProgress: 50 })
} else if (status.mode_state === 0x04 || status.mode_state === 0x00) {
clearInterval(self._progressTimer)
self.setData({ scanning: false, scanProgress: 100 })
var names = ble.getRegionName(status.region_mask || 0x7F)
self.setData({ regionData: self.parseScanResults(names) })
}
}
ble.on('status', this._onStatus)
ble.queryStatus().catch(function () {})
setTimeout(function () {
clearInterval(self._progressTimer)
if (!self.data.scanning) return
self.setData({ scanning: false, scanProgress: 100 })
var names = ble.getRegionName(self.data.regions || 0x7F)
self.setData({ regionData: self.parseScanResults(names) })
}, 5000)
}, },
parseScanResults: function (regions) { startScan: function () {
return regions.map(function (name) { var self = this
return { region: name, pd: '待检测' }
if (!ble.isConnected()) {
self.setData({ scanning: false, error: '设备未连接,请先连接设备' })
return
}
self.setData({ scanning: true, scanProgress: 0, error: '', pdValues: [] })
this._progressTimer = setInterval(function () {
var p = self.data.scanProgress + 1
if (p > 90) p = 90
self.setData({ scanProgress: p })
}, 80)
this._onAdc = function (data) {
console.log('[SCAN] 收到ADC数据:', JSON.stringify(data))
self._cleanup()
self.setData({ scanning: false, scanProgress: 100 })
self._handleAdcData(data)
}
ble.on('adc', this._onAdc)
console.log('[SCAN] 下发扫描指令: 全域亮度', SCAN_BRIGHTNESS)
ble.setParams({
region_mask: 0x1F,
wavelength: 2,
brightness: SCAN_BRIGHTNESS,
hold_time: 10,
control: 0x01
}).then(function () {
console.log('[SCAN] 扫描指令发送成功,等待ADC回传...')
}).catch(function (err) {
console.error('[SCAN] 扫描指令发送失败:', err)
self._cleanup()
self.setData({ scanning: false, scanProgress: 0, error: '扫描指令发送失败' })
}) })
this._timeoutTimer = setTimeout(function () {
if (!self.data.scanning) return
console.log('[SCAN] 等待ADC超时,使用默认值')
self._cleanup()
self.setData({ scanning: false, scanProgress: 100 })
self._handleAdcData(null)
}, SCAN_TIMEOUT)
},
_handleAdcData: function (data) {
var regionNames = ['右区(IO1)', '左区(IO2)', '上区(IO3)', '中区(IO4)', '下区(IO5)']
var pdValues = []
if (data && data.pd && data.pd.length >= 7) {
this.setData({ pdRaw: data.pd, vbat: data.vbat || 0, battery: data.battery || 0 })
for (var i = 0; i < 5; i++) {
var barW = Math.min(100, Math.round(data.pd[i] / 40.95))
pdValues.push({ region: regionNames[i], pd: data.pd[i], pdText: String(data.pd[i]), barWidth: barW })
}
pdValues.push({ region: 'PD6', pd: data.pd[5], pdText: String(data.pd[5]), barWidth: Math.min(100, Math.round(data.pd[5] / 40.95)) })
pdValues.push({ region: 'PD7', pd: data.pd[6], pdText: String(data.pd[6]), barWidth: Math.min(100, Math.round(data.pd[6] / 40.95)) })
getApp().globalData.lastScanPd = data.pd
getApp().globalData.lastScanVbat = data.vbat
} else {
for (var j = 0; j < 5; j++) {
pdValues.push({ region: regionNames[j], pd: 0, pdText: '未采集', barWidth: 0 })
}
}
this.setData({ pdValues: pdValues })
}, },
onUnload: function () { onUnload: function () {
if (this._progressTimer) clearInterval(this._progressTimer) this._cleanup()
if (this._onStatus) ble.off('status', this._onStatus) ble.stopTreatment().catch(function () {})
}, },
onNext: function () { onNext: function () {
var mask = this.data.regions || 0x7F var mask = this.data.regions || 0x1F
ble.setParams({ var pdRaw = this.data.pdRaw
region_mask: mask, var pdParam = pdRaw.length > 0 ? '&pd=' + encodeURIComponent(JSON.stringify(pdRaw)) : ''
wavelength: 2, wx.redirectTo({
brightness: 200, url: '/pages/treatment-setup/treatment-setup?regions=' + mask + pdParam
duration_ms: 600000,
mode: 1
}).then(function () {
return ble.startTreatment(mask)
}).then(function () {
wx.redirectTo({
url: '/pages/treating/treating?regions=' + mask + '&wavelength=2&duration=600000&mode=1'
})
}).catch(function (err) {
wx.showToast({ title: err.error_msg || '启动失败', icon: 'none' })
}) })
}, }
}) })
+23 -14
查看文件
@@ -1,30 +1,39 @@
<view class="page"> <view class="page">
<view class="page-header page-header-pink" style="padding-top: {{statusBarHeight + 24}}px;"> <view class="page-header page-header-pink" style="padding-top: {{statusBarHeight + 24}}px;">
<view class="nav-back" bindtap="onBack"> 返回</view> <view class="nav-back" bindtap="onBack"> 返回</view>
<view class="page-header-title">自动扫描</view> <view class="page-header-title">区域扫描</view>
<view class="page-header-subtitle">正在识别区域...</view> <view class="page-header-subtitle">{{scanning ? '正在采集数据...' : '扫描完成'}}</view>
</view> </view>
<view class="page-content"> <view class="page-content">
<view class="page-title">自动扫描区域</view> <view class="scan-container" wx:if="{{scanning}}">
<view class="scan-container">
<view class="face-outline"> <view class="face-outline">
<view class="scan-line"></view> <view class="scan-line"></view>
</view> </view>
<view class="scan-progress-bar">
<view class="scan-progress-fill" style="width: {{scanProgress}}%"></view>
</view>
<view class="scan-status">全域LED已开启,亮度 128,等待PD数据回传...</view>
</view> </view>
<view class="scan-hint">请正确佩戴设备</view> <view class="scan-result" wx:if="{{!scanning && pdValues.length > 0}}">
<view class="scan-hint" style="font-size:24rpx;color:#999;margin-top:8rpx;">连接设备后可获取检测数据</view> <view class="result-title">PD 采集结果</view>
<view class="pd-list">
<view class="scan-progress" wx:if="{{scanning}}"> <view class="pd-item" wx:for="{{pdValues}}" wx:key="region">
正在扫描... <text class="highlight">{{regionData.length || 3}}</text> 个区域 <view class="pd-region">{{item.region}}</view>
<view class="pd-value {{item.pd > 0 ? '' : 'pd-empty'}}">{{item.pdText}}</view>
<view class="pd-bar-bg" wx:if="{{item.pd > 0}}">
<view class="pd-bar-fill" style="width: {{item.barWidth}}%"></view>
</view>
</view>
</view>
<view class="vbat-info" wx:if="{{vbat > 0}}">
电池电压: {{vbat}}mV ({{battery}}%)
</view>
</view> </view>
<view class="detected-tags" wx:if="{{regionData.length > 0}}"> <view class="scan-error" wx:if="{{!scanning && error}}">{{error}}</view>
<text class="detected-tag" wx:for="{{regionData}}" wx:key="region">{{item.region}}</text>
</view>
<button class="btn-primary mt-30" wx:if="{{!scanning}}" bindtap="onNext">设置参数</button> <button class="btn-primary mt-30" wx:if="{{!scanning}}" bindtap="onNext">下一步</button>
</view> </view>
</view> </view>
+96 -42
查看文件
@@ -1,13 +1,13 @@
.scan-container { .scan-container {
position: relative; display: flex;
width: 320rpx; flex-direction: column;
height: 400rpx; align-items: center;
margin: 40rpx auto; padding: 20rpx 0;
} }
.face-outline { .face-outline {
width: 100%; width: 320rpx;
height: 100%; height: 400rpx;
border: 6rpx solid #e5e5e5; border: 6rpx solid #e5e5e5;
border-radius: 50% 50% 45% 45%; border-radius: 50% 50% 45% 45%;
position: relative; position: relative;
@@ -29,49 +29,103 @@
100% { top: calc(100% - 6rpx); opacity: 0.5; } 100% { top: calc(100% - 6rpx); opacity: 0.5; }
} }
.scan-hint { .scan-progress-bar {
text-align: center; width: 80%;
font-size: 26rpx; height: 8rpx;
color: #666666; background: #f0f0f0;
margin-bottom: 24rpx; border-radius: 4rpx;
margin-top: 30rpx;
overflow: hidden;
} }
.scan-progress { .scan-progress-fill {
text-align: center; height: 100%;
background: #f0f9ff; background: linear-gradient(90deg, #E6508C, #DCB982);
padding: 16rpx 28rpx; border-radius: 4rpx;
border-radius: 24rpx; transition: width 0.3s;
font-size: 26rpx;
color: #006699;
width: fit-content;
margin: 0 auto;
} }
.highlight { .scan-status {
color: #E6508C;
font-weight: 600;
}
.detected-tags {
text-align: center;
margin-top: 24rpx;
}
.detected-tag {
background: #fdf2f8;
border: 2rpx solid #E6508C;
color: #E6508C;
padding: 10rpx 24rpx;
border-radius: 24rpx;
font-size: 24rpx; font-size: 24rpx;
display: inline-block; color: #999;
margin: 6rpx; margin-top: 16rpx;
animation: tagPulse 1s ease-in-out; text-align: center;
} }
@keyframes tagPulse { .scan-result {
0%, 100% { transform: scale(1); } background: #fff;
50% { transform: scale(1.05); } border-radius: 20rpx;
padding: 24rpx;
margin-top: 20rpx;
}
.result-title {
font-size: 28rpx;
font-weight: 600;
color: #333;
margin-bottom: 20rpx;
}
.pd-list {
display: flex;
flex-direction: column;
gap: 16rpx;
}
.pd-item {
display: flex;
align-items: center;
gap: 16rpx;
}
.pd-region {
font-size: 26rpx;
color: #666;
width: 160rpx;
flex-shrink: 0;
}
.pd-value {
font-size: 28rpx;
font-weight: 600;
color: #E6508C;
width: 100rpx;
flex-shrink: 0;
text-align: right;
}
.pd-empty {
color: #ccc;
font-weight: normal;
}
.pd-bar-bg {
flex: 1;
height: 16rpx;
background: #f5f5f5;
border-radius: 8rpx;
overflow: hidden;
}
.pd-bar-fill {
height: 100%;
background: linear-gradient(90deg, #E6508C, #DCB982);
border-radius: 8rpx;
min-width: 4rpx;
}
.vbat-info {
margin-top: 20rpx;
font-size: 24rpx;
color: #999;
text-align: center;
}
.scan-error {
text-align: center;
color: #ff4d4f;
font-size: 26rpx;
margin-top: 20rpx;
} }
.btn-primary::after { .btn-primary::after {
@@ -18,7 +18,7 @@
<view class="found-card" wx:if="{{state === 'binding'}}"> <view class="found-card" wx:if="{{state === 'binding'}}">
<view class="found-icon">💆</view> <view class="found-icon">💆</view>
<view class="found-name">智能面膜-{{deviceId}}</view> <view class="found-name">LumiFlow-{{deviceId}}</view>
<text class="status-badge status-badge-green">正在配对...</text> <text class="status-badge status-badge-green">正在配对...</text>
</view> </view>
+2 -2
查看文件
@@ -1,11 +1,11 @@
<view class="page"> <view class="page">
<view class="page-header page-header-pink" style="padding-top: {{statusBarHeight + 24}}px;"> <view class="page-header page-header-pink" style="padding-top: {{statusBarHeight + 24}}px;">
<view class="page-header-title">智美</view> <view class="page-header-title">LumiFlow</view>
<view class="page-header-subtitle">微信登录</view> <view class="page-header-subtitle">微信登录</view>
</view> </view>
<view class="page-content"> <view class="page-content">
<view class="welcome-text">欢迎使用智美</view> <view class="welcome-text">欢迎使用LumiFlow</view>
<view class="flower-area"> <view class="flower-area">
<text class="flower">💎</text> <text class="flower">💎</text>
+1 -1
查看文件
@@ -62,7 +62,7 @@
<view class="logout-btn" bindtap="onLogout">退出登录</view> <view class="logout-btn" bindtap="onLogout">退出登录</view>
<view class="version-text">v0.1.5</view> <view class="version-text">v0.1.6</view>
</view> </view>
<!-- Edit profile modal --> <!-- Edit profile modal -->
+1 -1
查看文件
@@ -1,6 +1,6 @@
<view class="page"> <view class="page">
<view class="page-header page-header-pink" style="padding-top: {{statusBarHeight + 24}}px;"> <view class="page-header page-header-pink" style="padding-top: {{statusBarHeight + 24}}px;">
<view class="page-header-title">智美</view> <view class="page-header-title">LumiFlow</view>
<view class="page-header-subtitle">完善个人资料</view> <view class="page-header-subtitle">完善个人资料</view>
</view> </view>
@@ -90,7 +90,8 @@ Page({
wavelength: 2, wavelength: 2,
brightness: 200, brightness: 200,
duration_ms: self.data.fixedDurationMs, duration_ms: self.data.fixedDurationMs,
mode: self.data.selectedMode mode: self.data.selectedMode,
control: 0x02
}).then(function () { }).then(function () {
return ble.startTreatment(mask) return ble.startTreatment(mask)
}).then(function () { }).then(function () {
+1 -1
查看文件
@@ -10,7 +10,7 @@
<view class="device-row-icon">💆</view> <view class="device-row-icon">💆</view>
<view class="device-row-info"> <view class="device-row-info">
<view class="device-row-name"> <view class="device-row-name">
智能面膜 LumiFlow
<text class="status-badge status-badge-green" wx:if="{{connected}}">已连接</text> <text class="status-badge status-badge-green" wx:if="{{connected}}">已连接</text>
<text class="status-badge" style="background:#ccc;" wx:else>未连接</text> <text class="status-badge" style="background:#ccc;" wx:else>未连接</text>
</view> </view>
+3 -2
查看文件
@@ -181,12 +181,13 @@ function startTreatment(regionMask) {
function stopTreatment() { function stopTreatment() {
if (protocol.PROTOCOL_MODE === 'vendor_33') { if (protocol.PROTOCOL_MODE === 'vendor_33') {
return writeRawCommand(protocol.buildVendorCommand33({ return writeRawCommand(protocol.buildVendorCommand({
region_mask: 0, region_mask: 0,
wavelength: protocol.WAVELENGTH.R, wavelength: protocol.WAVELENGTH.R,
brightness: 0, brightness: 0,
current_gain: 0, current_gain: 0,
hold_time: 0 hold_time: 0,
control: protocol.CONTROL.IDLE
})) }))
} }
return writeCommandWithRetry(protocol.CMD.STOP, []) return writeCommandWithRetry(protocol.CMD.STOP, [])
+7 -1
查看文件
@@ -98,8 +98,14 @@ function handleValueChange(res) {
console.warn('[BLE] ADC checksum mismatch, dropping') console.warn('[BLE] ADC checksum mismatch, dropping')
return return
} }
emit('adc', { pd: parsed.pd, vbat: vbatMv, battery: batteryPct }) emit('adc', { pd: parsed.pd, vbat: vbatMv, battery: batteryPct, fitting: parsed.fitting, run_state: parsed.run_state })
emit('battery', { battery: batteryPct, vbat: vbatMv }) emit('battery', { battery: batteryPct, vbat: vbatMv })
if (parsed.fitting !== -1) {
emit('fitting', { fitting: parsed.fitting })
}
if (parsed.run_state !== -1) {
emit('run_state', { run_state: parsed.run_state })
}
return return
} }
+2
查看文件
@@ -15,6 +15,7 @@ module.exports = {
WAVELENGTH: protocol.WAVELENGTH, WAVELENGTH: protocol.WAVELENGTH,
TREAT_MODE: protocol.TREAT_MODE, TREAT_MODE: protocol.TREAT_MODE,
REGION: protocol.REGION, REGION: protocol.REGION,
CONTROL: protocol.CONTROL,
DEVICE_ERR: protocol.DEVICE_ERR, DEVICE_ERR: protocol.DEVICE_ERR,
// Connection // Connection
@@ -41,6 +42,7 @@ module.exports = {
PROTOCOL_MODE: protocol.PROTOCOL_MODE, PROTOCOL_MODE: protocol.PROTOCOL_MODE,
buildFrame: protocol.buildFrame, buildFrame: protocol.buildFrame,
parseFrame: protocol.parseFrame, parseFrame: protocol.parseFrame,
buildVendorCommand: protocol.buildVendorCommand,
buildVendorCommand33: protocol.buildVendorCommand33, buildVendorCommand33: protocol.buildVendorCommand33,
parseVendorStatus: protocol.parseVendorStatus, parseVendorStatus: protocol.parseVendorStatus,
parseStatusReport: protocol.parseStatusReport, parseStatusReport: protocol.parseStatusReport,
+65 -2
查看文件
@@ -155,9 +155,19 @@ function bytesToHex(bytes) {
return hex.toUpperCase() return hex.toUpperCase()
} }
// --- vendor 33-byte command protocol --- // --- vendor 34-byte command protocol ---
// Byte1-30: IO1~IO5 (6B each: R, IR, UV, Y, GainH, GainL)
// Byte31-32: hold time (seconds, big-endian)
// Byte33: control (0=IDLE, 1=scan, 2=treat)
// Byte34: XOR checksum of Byte1-33
function buildVendorCommand33(options) { var CONTROL = {
IDLE: 0x00,
SCAN: 0x01,
TREAT: 0x02
}
function buildVendorCommand(options) {
options = options || {} options = options || {}
var regionMask = options.region_mask || REGION.FULL_FACE var regionMask = options.region_mask || REGION.FULL_FACE
var wavelength = options.wavelength || WAVELENGTH.R var wavelength = options.wavelength || WAVELENGTH.R
@@ -165,6 +175,7 @@ function buildVendorCommand33(options) {
var gain = clampUInt16(options.current_gain === undefined ? brightness : options.current_gain) var gain = clampUInt16(options.current_gain === undefined ? brightness : options.current_gain)
var durationMs = options.duration_ms || 600000 var durationMs = options.duration_ms || 600000
var holdSeconds = clampUInt16(options.hold_time === undefined ? Math.round(durationMs / 1000) : options.hold_time) var holdSeconds = clampUInt16(options.hold_time === undefined ? Math.round(durationMs / 1000) : options.hold_time)
var control = options.control !== undefined ? options.control : CONTROL.TREAT
var regions = [ var regions = [
REGION.LEFT_CHEEK, REGION.LEFT_CHEEK,
REGION.RIGHT_CHEEK, REGION.RIGHT_CHEEK,
@@ -190,15 +201,38 @@ function buildVendorCommand33(options) {
} }
bytes.push((holdSeconds >> 8) & 0xFF, holdSeconds & 0xFF) bytes.push((holdSeconds >> 8) & 0xFF, holdSeconds & 0xFF)
bytes.push(control & 0xFF)
bytes.push(xorChecksum(bytes)) bytes.push(xorChecksum(bytes))
return bytes return bytes
} }
// deprecated: alias kept for backward compat, actually outputs 34 bytes
function buildVendorCommand33(options) {
return buildVendorCommand(options)
}
function parseVendorStatus(buffer) { function parseVendorStatus(buffer) {
var bytes = bufferToBytes(buffer) var bytes = bufferToBytes(buffer)
if (bytes.length === 1) { if (bytes.length === 1) {
return { type: 'heartbeat', heartbeat: bytes[0], is_heartbeat: true, raw_hex: bytesToHex(bytes) } return { type: 'heartbeat', heartbeat: bytes[0], is_heartbeat: true, raw_hex: bytesToHex(bytes) }
} }
if (bytes.length === 19) {
var checksum19 = xorChecksum(bytes.slice(0, 18))
var pds19 = []
for (var p = 0; p < 7; p++) {
pds19.push(bytes[p * 2] | (bytes[p * 2 + 1] << 8))
}
return {
type: 'adc',
is_heartbeat: false,
pd: pds19,
vbat: bytes[14] | (bytes[15] << 8),
fitting: bytes[16],
run_state: bytes[17],
checksum_ok: checksum19 === bytes[18],
raw_hex: bytesToHex(bytes)
}
}
if (bytes.length === 17) { if (bytes.length === 17) {
var checksum = xorChecksum(bytes.slice(0, 16)) var checksum = xorChecksum(bytes.slice(0, 16))
var pds = [] var pds = []
@@ -210,10 +244,34 @@ function parseVendorStatus(buffer) {
is_heartbeat: false, is_heartbeat: false,
pd: pds, pd: pds,
vbat: bytes[14] | (bytes[15] << 8), vbat: bytes[14] | (bytes[15] << 8),
fitting: -1,
run_state: -1,
checksum_ok: checksum === bytes[16], checksum_ok: checksum === bytes[16],
raw_hex: bytesToHex(bytes) raw_hex: bytesToHex(bytes)
} }
} }
if (bytes.length === 34) {
var ios34 = []
for (var j = 0; j < 5; j++) {
var off34 = j * 6
ios34.push({
red: bytes[off34], infrared: bytes[off34 + 1],
uv: bytes[off34 + 2], warm_yellow: bytes[off34 + 3],
gain: (bytes[off34 + 4] << 8) | bytes[off34 + 5]
})
}
var expected34 = xorChecksum(bytes.slice(0, 33))
return {
type: 'params',
is_heartbeat: false,
ios: ios34,
hold_time: (bytes[30] << 8) | bytes[31],
control: bytes[32],
checksum: bytes[33],
checksum_ok: expected34 === bytes[33],
raw_hex: bytesToHex(bytes)
}
}
if (bytes.length === 33) { if (bytes.length === 33) {
var ios = [] var ios = []
for (var i = 0; i < 5; i++) { for (var i = 0; i < 5; i++) {
@@ -224,12 +282,15 @@ function parseVendorStatus(buffer) {
gain: (bytes[off + 4] << 8) | bytes[off + 5] gain: (bytes[off + 4] << 8) | bytes[off + 5]
}) })
} }
var expected33 = xorChecksum(bytes.slice(0, 32))
return { return {
type: 'params', type: 'params',
is_heartbeat: false, is_heartbeat: false,
ios: ios, ios: ios,
hold_time: (bytes[30] << 8) | bytes[31], hold_time: (bytes[30] << 8) | bytes[31],
control: -1,
checksum: bytes[32], checksum: bytes[32],
checksum_ok: expected33 === bytes[32],
raw_hex: bytesToHex(bytes) raw_hex: bytesToHex(bytes)
} }
} }
@@ -345,6 +406,7 @@ module.exports = {
TREAT_MODE: TREAT_MODE, TREAT_MODE: TREAT_MODE,
REGION: REGION, REGION: REGION,
REGION_NAMES: REGION_NAMES, REGION_NAMES: REGION_NAMES,
CONTROL: CONTROL,
DEVICE_ERR: DEVICE_ERR, DEVICE_ERR: DEVICE_ERR,
bufferToBytes: bufferToBytes, bufferToBytes: bufferToBytes,
@@ -354,6 +416,7 @@ module.exports = {
bytesToUint32: bytesToUint32, bytesToUint32: bytesToUint32,
hexToBytes: hexToBytes, hexToBytes: hexToBytes,
bytesToHex: bytesToHex, bytesToHex: bytesToHex,
buildVendorCommand: buildVendorCommand,
buildVendorCommand33: buildVendorCommand33, buildVendorCommand33: buildVendorCommand33,
buildFrame: buildFrame, buildFrame: buildFrame,
+4 -1
查看文件
@@ -16,7 +16,10 @@ function execute(command) {
wavelength: payload.wavelength, wavelength: payload.wavelength,
brightness: payload.brightness, brightness: payload.brightness,
duration_ms: payload.duration_ms, duration_ms: payload.duration_ms,
mode: payload.mode mode: payload.mode,
control: payload.control,
current_gain: payload.current_gain,
hold_time: payload.hold_time
}) })
case ble.CMD.START: case ble.CMD.START:
return ble.startTreatment(payload.region_mask) return ble.startTreatment(payload.region_mask)
+2 -2
查看文件
@@ -89,7 +89,7 @@ async function create(device) {
device_id: device.device_id, device_id: device.device_id,
product_id: device.product_id || 'HOX_LIGHT_MASK', product_id: device.product_id || 'HOX_LIGHT_MASK',
device_secret: device.device_secret || '', device_secret: device.device_secret || '',
device_name: device.device_name || '智能面膜', device_name: device.device_name || 'LumiFlow',
firmware_version: device.firmware_version || '1.0.0' firmware_version: device.firmware_version || '1.0.0'
} }
) )
@@ -111,7 +111,7 @@ async function createBatch(deviceIds) {
device_id: deviceId, device_id: deviceId,
product_id: 'HOX_LIGHT_MASK', product_id: 'HOX_LIGHT_MASK',
device_secret: '', device_secret: '',
device_name: '智能面膜', device_name: 'LumiFlow',
firmware_version: '1.0.0' firmware_version: '1.0.0'
}) })
created++ created++
+1 -1
查看文件
@@ -92,7 +92,7 @@ async function createPrepayOrder({ openid, orderId, amountFen, description }) {
const body = { const body = {
appid: config.wxpay.appid || config.wechat.appid, appid: config.wxpay.appid || config.wechat.appid,
mchid: config.wxpay.mchId, mchid: config.wxpay.mchId,
description: description || '智能面膜订阅', description: description || 'LumiFlow 订阅',
out_trade_no: orderId, out_trade_no: orderId,
notify_url: config.wxpay.notifyUrl, notify_url: config.wxpay.notifyUrl,
amount: { total: amountFen, currency: 'CNY' }, amount: { total: amountFen, currency: 'CNY' },
+1 -1
查看文件
@@ -92,7 +92,7 @@ router.post('/devices', requireAdmin, wrap(async (req, res) => {
device_id: deviceId, device_id: deviceId,
product_id: req.body.product_id || 'HOX_LIGHT_MASK', product_id: req.body.product_id || 'HOX_LIGHT_MASK',
device_secret: req.body.device_secret || '', device_secret: req.body.device_secret || '',
device_name: req.body.device_name || '智能面膜', device_name: req.body.device_name || 'LumiFlow',
firmware_version: req.body.firmware_version || '1.0.0' firmware_version: req.body.firmware_version || '1.0.0'
}) })
await logDao.write({ admin_id: req.admin.admin_id, action: 'admin_device_create', detail: '预生成产品码: ' + deviceId, ip: req.ip }) await logDao.write({ admin_id: req.admin.admin_id, action: 'admin_device_create', detail: '预生成产品码: ' + deviceId, ip: req.ip })
+1 -1
查看文件
@@ -68,7 +68,7 @@ router.post('/subscription/purchase', requireUser, wrap(async (req, res) => {
openid: req.user.openid, openid: req.user.openid,
orderId, orderId,
amountFen, amountFen,
description: '智能面膜-' + (plan === 'yearly' ? '年卡' : '月卡') description: 'LumiFlow-' + (plan === 'yearly' ? '年卡' : '月卡')
}) })
await paymentOrderDao.markPrepay(orderId, prepayId) await paymentOrderDao.markPrepay(orderId, prepayId)