|
@@ -57,6 +57,12 @@ Page({
|
|
|
buttonTips: "更新失败,再试一次"
|
|
|
});
|
|
|
break;
|
|
|
+ case 5:
|
|
|
+ this.setData({
|
|
|
+ otaStatus: 4,
|
|
|
+ buttonTips: "更新完成"
|
|
|
+ });
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -78,6 +84,9 @@ Page({
|
|
|
})
|
|
|
return;
|
|
|
}
|
|
|
+ if (this.data.otaStatus != 1 || this.data.otaStatus != 4) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
let _this = this
|
|
|
wx.showModal({
|
|
@@ -100,6 +109,57 @@ Page({
|
|
|
// btHelper.ota(this.data.otaData.file_url)
|
|
|
|
|
|
},
|
|
|
+ sendWiFiInfo(wifiName, pwd) {
|
|
|
+ // [0x22, (wifiList.length + pwdList.length + 6), 0x33, (wifiList.length), (wifiList), 0x44, (pwdList)];
|
|
|
+
|
|
|
+ let result = [];
|
|
|
+
|
|
|
+ // 字母*6 +
|
|
|
+ let wifiList = this.string2ListInt(wifiName);
|
|
|
+
|
|
|
+ // 数字*3 +
|
|
|
+ let pwdList = this.string2ListInt(pwd);
|
|
|
+
|
|
|
+ // 16进制
|
|
|
+ result.push(0x22);
|
|
|
+ result.push(this.int2Hex(wifiList.length + pwdList.length + 6));
|
|
|
+
|
|
|
+ // 账号
|
|
|
+ result.push(0x33);
|
|
|
+ result.push(this.int2Hex(wifiList.length));
|
|
|
+
|
|
|
+ let p = result[3] + 4;
|
|
|
+ let j = 0;
|
|
|
+ for (let i = 4; i < p; i++) {
|
|
|
+ result.splice(i, 0, wifiList[j++]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 密码
|
|
|
+ result.splice(p, 0, 0x44);
|
|
|
+ result.splice(++p, 0, this.int2Hex(pwdList.length));
|
|
|
+ p++;
|
|
|
+ j = 0;
|
|
|
+ // for (let i = p; i < p + pwdList.length; i++) {
|
|
|
+ // result.splice(i, 0, pwdList[j++]);
|
|
|
+ // }
|
|
|
+ // result.push(...pwdList);
|
|
|
+ result.concat(pwdList)
|
|
|
+
|
|
|
+ console.log("发送wifi账号密码:", result.toString());
|
|
|
+ // _ble.send({ cmd: result });
|
|
|
+ const btHelper = BtHelper.getInstance();
|
|
|
+ btHelper.otaData(result)
|
|
|
+ },
|
|
|
+ int2Hex(num) {
|
|
|
+ return parseInt(num, 16);
|
|
|
+ },
|
|
|
+
|
|
|
+ // string转换为List<int>
|
|
|
+ string2ListInt(text) {
|
|
|
+ let code = Array.from(text).map(char => char.charCodeAt(0));
|
|
|
+ console.log("string转换为List<int>", code)
|
|
|
+ return code
|
|
|
+ },
|
|
|
startDownloadFile() {
|
|
|
|
|
|
var urlPath = this.data.otaData.url ?? "";
|
|
@@ -113,6 +173,8 @@ Page({
|
|
|
console.log(list, localFilePath)
|
|
|
|
|
|
let _this = this;
|
|
|
+ _this.setOtaStatus(2);
|
|
|
+
|
|
|
let localPath = `${wx.env.USER_DATA_PATH}/` + localFilePath
|
|
|
// 判断文件是否存在
|
|
|
fs.access({
|
|
@@ -125,7 +187,7 @@ Page({
|
|
|
_this.readFile(localPath);
|
|
|
|
|
|
} else {
|
|
|
-
|
|
|
+ _this.downloadOtaFile(urlPath, localPath)
|
|
|
}
|
|
|
}, fail(err) {
|
|
|
// 文件不存在或其他错误
|
|
@@ -149,41 +211,35 @@ Page({
|
|
|
// 下载成功,保存文件路径
|
|
|
const filePath = res.tempFilePath;
|
|
|
// _this.readFile(filePath);
|
|
|
- _this.readFile(filePath);
|
|
|
|
|
|
// 将下载的文件移动到本地路径
|
|
|
- // fs.rename({
|
|
|
- // oldPath: filePath,
|
|
|
- // newPath: localPath,
|
|
|
- // success: () => {
|
|
|
-
|
|
|
- // // this.setData({
|
|
|
- // // localFilePath: localFilePath
|
|
|
- // // });
|
|
|
-
|
|
|
- // // 调用 OTA 更新方法
|
|
|
- // // const btHelper = BtHelper.getInstance();
|
|
|
- // // btHelper.ota(localFilePath);
|
|
|
-
|
|
|
- // wx.showToast({
|
|
|
- // title: '文件下载成功',
|
|
|
- // });
|
|
|
- // _this.readFile(localPath);
|
|
|
- // },
|
|
|
- // fail: (err) => {
|
|
|
- // wx.showToast({
|
|
|
- // title: '下载文件失败,检查下手机内存吧',
|
|
|
- // });
|
|
|
- // console.error('文件移动失败:', err);
|
|
|
- // }
|
|
|
- // });
|
|
|
+ fs.rename({
|
|
|
+ oldPath: filePath,
|
|
|
+ newPath: localPath,
|
|
|
+ success: () => {
|
|
|
+ wx.showToast({
|
|
|
+ title: '文件下载成功',
|
|
|
+ });
|
|
|
+ _this.readFile(localPath);
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ _this.setOtaStatus(4);
|
|
|
+
|
|
|
+ wx.showToast({
|
|
|
+ title: '下载文件失败,检查下手机内存吧',
|
|
|
+ });
|
|
|
+ console.error('文件移动失败:', err);
|
|
|
+ }
|
|
|
+ });
|
|
|
} else {
|
|
|
+ _this.setOtaStatus(4);
|
|
|
wx.showToast({
|
|
|
title: '文件下载失败',
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
fail: (err) => {
|
|
|
+ _this.setOtaStatus(4);
|
|
|
wx.showToast({
|
|
|
title: '文件下载失败',
|
|
|
});
|
|
@@ -202,7 +258,6 @@ Page({
|
|
|
wx.showLoading({
|
|
|
title: '开始传输文件',
|
|
|
})
|
|
|
- this.setOtaStatus(2);
|
|
|
const fs = wx.getFileSystemManager();
|
|
|
|
|
|
let _this = this;
|
|
@@ -223,7 +278,9 @@ Page({
|
|
|
title: 'OTA文件下载失败',
|
|
|
});
|
|
|
console.error('文件读取失败:', err);
|
|
|
+ _this.setOtaStatus(4);
|
|
|
}
|
|
|
+
|
|
|
});
|
|
|
},
|
|
|
startSend(data) {
|
|
@@ -244,7 +301,7 @@ Page({
|
|
|
|
|
|
if (length === 0) {
|
|
|
wx.showToast({
|
|
|
- title: '图片裁剪失败',
|
|
|
+ title: '下载文件失败',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
_this.endOta(2)
|
|
@@ -265,23 +322,29 @@ Page({
|
|
|
let total = imageBuffer.length
|
|
|
let next = index + chunkSize;
|
|
|
const chunk = imageBuffer.slice(index, next);
|
|
|
- BtHelper.getInstance().wallPaperData(chunk, function (res) {
|
|
|
- console.log("发送OTA数据:", next)
|
|
|
- if (res) {
|
|
|
- _this.updateProgress(next, total);
|
|
|
-
|
|
|
- _this.sendOtaData(imageBuffer)
|
|
|
- } else {
|
|
|
- wx.showModal({
|
|
|
- title: 'OTA升级失败了',
|
|
|
- showCancel: false
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
+ // todo 改成设备wifi下载
|
|
|
+ // BtHelper.getInstance().wallPaperData(chunk, function (res) {
|
|
|
+ // console.log("发送OTA数据:", next)
|
|
|
+ // if (res) {
|
|
|
+ // _this.updateProgress(next, total);
|
|
|
+
|
|
|
+ // _this.sendOtaData(imageBuffer)
|
|
|
+ // } else {
|
|
|
+ // wx.showModal({
|
|
|
+ // title: 'OTA升级失败了',
|
|
|
+ // showCancel: false
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // })
|
|
|
|
|
|
},
|
|
|
endOta(value) {
|
|
|
BtHelper.getInstance().otaCmd(value)
|
|
|
+ if (value == 0) {
|
|
|
+ this.setOtaStatus(0);
|
|
|
+ } else {
|
|
|
+ this.setOtaStatus(4);
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
startProgress() {
|