更新100J

This commit is contained in:
微微一笑
2026-03-27 10:13:52 +08:00
parent 553e24886f
commit 4c6704ba8a
2 changed files with 99 additions and 30 deletions

View File

@ -663,7 +663,20 @@ class HBY100JProtocol {
const DELAY_PACKET = 80; // 数据包间延时(ms)参考6155
const toHex = (arr) => Array.from(arr).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
console.log('[100J-蓝牙] 语音下发总大小:', total, '字节, fileType=', ft);
if (onProgress) onProgress(1);
// 进度单调递增:前段固定 2→8数据段占 8~95结束包 99→100避免先 5% 再掉回 1% 的错觉
let progressPeak = 0;
const emitProgress = (raw) => {
const n = Math.round(Number(raw));
if (!Number.isFinite(n)) return;
const v = Math.min(100, Math.max(progressPeak, n));
progressPeak = v;
if (onProgress) onProgress(v);
};
if (total <= 0) {
emitProgress(100);
return Promise.resolve({ code: 200, msg: '语音文件已通过蓝牙上传' });
}
emitProgress(2);
const bleToolPromise = import('@/utils/BleHelper.js').then(m => m.default.getBleTool());
let bleRef = null;
const send = (dataBytes, label = '') => {
@ -688,26 +701,30 @@ class HBY100JProtocol {
bleRef = ble;
ble.setVoiceUploading(true);
return send(startData, ' 开始包')
.then(() => { if (onProgress) onProgress(3); return waitPromise; })
.then(() => { if (onProgress) onProgress(5); return delay(DELAY_AFTER_START); })
.then(() => waitPromise)
.then(() => delay(DELAY_AFTER_START))
.then(() => {
emitProgress(8);
let seq = 0;
const sendNext = (offset) => {
if (offset >= total) {
return delay(DELAY_PACKET).then(() => send([ft, 2], ' 结束包'));
return delay(DELAY_PACKET)
.then(() => send([ft, 2], ' 结束包'))
.then(() => { emitProgress(99); });
}
const chunk = bytes.slice(offset, Math.min(offset + chunkSize, total));
const chunkData = [ft, 1, seq & 0xFF, (seq >> 8) & 0xFF, ...chunk];
return send(chunkData, ` #${seq} 数据包`).then(() => {
seq++;
if (onProgress) onProgress(Math.min(100, Math.floor((offset + chunk.length) / total * 100)));
const doneRatio = (offset + chunk.length) / total;
emitProgress(8 + Math.round(doneRatio * 87));
return delay(DELAY_PACKET).then(() => sendNext(offset + chunk.length));
});
};
return sendNext(0);
})
.then(() => {
if (onProgress) onProgress(100);
emitProgress(100);
return { code: 200, msg: '语音文件已通过蓝牙上传' };
});
};