|
|
@@ -282,10 +282,139 @@ function onP9Btn12Click() {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+function disablePUpgradeButtons() {
|
|
|
+ document.getElementById("hmiFile").disabled = true;
|
|
|
+ document.getElementById("hmiUploadBtn").disabled = true;
|
|
|
+ document.getElementById("mcuFile").disabled = true;
|
|
|
+ document.getElementById("mcuUploadBtn").disabled = true;
|
|
|
+}
|
|
|
+
|
|
|
+function restorePUpgradeButtons() {
|
|
|
+ document.getElementById("hmiFile").disabled = false;
|
|
|
+ document.getElementById("hmiUploadBtn").disabled = false;
|
|
|
+ document.getElementById("mcuFile").disabled = false;
|
|
|
+ document.getElementById("mcuUploadBtn").disabled = false;
|
|
|
+}
|
|
|
+
|
|
|
+function enablePUpgradeButtons() {
|
|
|
+ var password = prompt("请输入操作密码:");
|
|
|
+ if (password === null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ fetch("/api/cbd/unlock", {
|
|
|
+ method: "POST",
|
|
|
+ headers: {
|
|
|
+ "X-Operation-Password": password
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(function (r) {
|
|
|
+ if (!r.ok) {
|
|
|
+ throw new Error(r.status === 401 ? "操作密码错误!" : "HTTP " + r.status);
|
|
|
+ }
|
|
|
+ restorePUpgradeButtons();
|
|
|
+ document.getElementById("p9UpgradeAuthBtn").disabled = true;
|
|
|
+ })
|
|
|
+ .catch(function (e) {
|
|
|
+ alert(e.message);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function onFirmwareFileChange(type) {
|
|
|
+ var file = document.getElementById(type + "File").files[0];
|
|
|
+ var status = document.getElementById(type + "Status");
|
|
|
+
|
|
|
+ status.textContent = file ? "已选择:" + file.name : "等待选择文件";
|
|
|
+}
|
|
|
+
|
|
|
+function uploadFirmware(type) {
|
|
|
+ if (type !== "hmi" && type !== "mcu") {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var fileInput = document.getElementById(type + "File");
|
|
|
+ var status = document.getElementById(type + "Status");
|
|
|
+ var file = fileInput.files[0];
|
|
|
+
|
|
|
+ if (!file) {
|
|
|
+ alert("请先选择固件文件");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var suffix = type === "hmi" ? ".zip" : ".rbl";
|
|
|
+ if (file.name.toLowerCase().slice(-suffix.length) !== suffix) {
|
|
|
+ alert("固件文件类型错误,只允许上传 " + suffix + " 文件");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (file.size > 100 * 1024 * 1024) {
|
|
|
+ alert("固件文件不能超过 100MB");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var name = type === "hmi" ? "串口屏" : "控制板";
|
|
|
+ if (!confirm("确定升级" + name + "吗?")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ disablePUpgradeButtons();
|
|
|
+
|
|
|
+ var formData = new FormData();
|
|
|
+ formData.append("file", file);
|
|
|
+
|
|
|
+ var xhr = new XMLHttpRequest();
|
|
|
+ xhr.open("POST", "/api/cbd/uploadFirmware?type=" + type, true);
|
|
|
+ xhr.timeout = 600000; // 10分钟
|
|
|
+
|
|
|
+ status.textContent = "正在上传:0%";
|
|
|
+
|
|
|
+ xhr.upload.onprogress = function (e) {
|
|
|
+ if (e.lengthComputable) {
|
|
|
+ var percent = Math.round(e.loaded / e.total * 100);
|
|
|
+ status.textContent = "正在上传:" + percent + "%";
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ xhr.upload.onload = function () {
|
|
|
+ status.textContent = "文件上传完成,正在执行固件升级...";
|
|
|
+ };
|
|
|
+
|
|
|
+ xhr.onload = function () {
|
|
|
+ if (xhr.status >= 200 && xhr.status < 300) {
|
|
|
+ try {
|
|
|
+ var data = JSON.parse(xhr.responseText);
|
|
|
+ if (data.result !== "success") {
|
|
|
+ throw new Error("返回结果异常");
|
|
|
+ }
|
|
|
+ status.textContent = "升级指令已发送,请等待升级完成";
|
|
|
+ } catch (e) {
|
|
|
+ status.textContent = "升级请求失败:" + e.message;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ status.textContent = "升级请求失败:" + (xhr.responseText || "HTTP " + xhr.status);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ xhr.onerror = function () {
|
|
|
+ status.textContent = "升级请求失败,请检查网络连接";
|
|
|
+ };
|
|
|
+
|
|
|
+ xhr.ontimeout = function () {
|
|
|
+ status.textContent = "升级请求超时,请稍后重新尝试";
|
|
|
+ };
|
|
|
+
|
|
|
+ xhr.onloadend = function () {
|
|
|
+ restorePUpgradeButtons();
|
|
|
+ };
|
|
|
+
|
|
|
+ xhr.send(formData);
|
|
|
+}
|
|
|
+
|
|
|
function initPage9() {
|
|
|
disableP9CtrlCmdButtons();
|
|
|
+ disablePUpgradeButtons();
|
|
|
startCBDWorkStatusRefresh();
|
|
|
- connectLog("yfkj-user-app.service", "text5");
|
|
|
+ connectLog("yfkj-user-app.service", "text4");
|
|
|
}
|
|
|
|
|
|
function exitPage9() {
|