ble.js
// 分包写入蓝牙
async sendWriteBLECharacteristicValue(
deviceId,
serviceId,
writeCharacteristicId,
readCharacteristicId,
buffer,
success, // 成功回调
failure, // 失败回调
) {
const offset = 500; // 偏移量
let pos = 0; // 位置
let bytes = buffer.byteLength; // 总字节
let that = this;
while (bytes > 0) {
let endPos = bytes > offset ? pos + offset : pos + bytes;
const tempBuffer = buffer.slice(pos, endPos);
pos += offset;
bytes -= offset;
// 延迟发送
await that.sendDelay(150, tempBuffer).then((buffer) => {
that.writeBLECharacteristicValue(
deviceId,
serviceId,
writeCharacteristicId,
buffer,
(res) => {
if (buffer.byteLength < offset) {
success(res);
}
},