fix website
This commit is contained in:
@@ -191,72 +191,36 @@ export class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uploadNewFirmware(file: File) {
|
uploadNewFirmware(file: File) {
|
||||||
const reader = new FileReader();
|
let current = 0;
|
||||||
reader.onload = () => {
|
let max = 100;
|
||||||
const arrayBuffer = reader.result as ArrayBuffer;
|
controller.progressview.addProgress("ota_upload", (current / max) * 100, "Uploading firmeware (" + current + "/" + max + ")")
|
||||||
const data = new Uint8Array(arrayBuffer);
|
const ajax = new XMLHttpRequest();
|
||||||
const crc = this.crc32(data);
|
ajax.upload.addEventListener("progress", event => {
|
||||||
const size = data.length;
|
current = event.loaded / 1000;
|
||||||
|
max = event.total / 1000;
|
||||||
console.log("Uploading new firmware with size " + size + " and crc " + crc + "")
|
|
||||||
|
|
||||||
const payload = new Uint8Array(size + 8);
|
|
||||||
const view = new DataView(payload.buffer);
|
|
||||||
view.setUint32(0, size, true);
|
|
||||||
view.setUint32(4, crc, true);
|
|
||||||
payload.set(data, 8);
|
|
||||||
|
|
||||||
let current = 0;
|
|
||||||
let max = 100;
|
|
||||||
controller.progressview.addProgress("ota_upload", (current / max) * 100, "Uploading firmeware (" + current + "/" + max + ")")
|
controller.progressview.addProgress("ota_upload", (current / max) * 100, "Uploading firmeware (" + current + "/" + max + ")")
|
||||||
const ajax = new XMLHttpRequest();
|
}, false);
|
||||||
ajax.upload.addEventListener("progress", event => {
|
ajax.addEventListener("load", () => {
|
||||||
current = event.loaded / 1000;
|
controller.progressview.removeProgress("ota_upload")
|
||||||
max = event.total / 1000;
|
const status = ajax.status;
|
||||||
controller.progressview.addProgress("ota_upload", (current / max) * 100, "Uploading firmeware (" + current + "/" + max + ")")
|
if (status >= 200 && status < 300) {
|
||||||
}, false);
|
controller.reboot();
|
||||||
ajax.addEventListener("load", () => {
|
} else {
|
||||||
controller.progressview.removeProgress("ota_upload")
|
const statusText = ajax.statusText || "";
|
||||||
const status = ajax.status;
|
const body = ajax.responseText || "";
|
||||||
if (status >= 200 && status < 300) {
|
toast.error(`OTA update error (${status}${statusText ? ' ' + statusText : ''}): ${body}`);
|
||||||
controller.reboot();
|
|
||||||
} else {
|
|
||||||
const statusText = ajax.statusText || "";
|
|
||||||
const body = ajax.responseText || "";
|
|
||||||
toast.error(`OTA update error (${status}${statusText ? ' ' + statusText : ''}): ${body}`);
|
|
||||||
}
|
|
||||||
}, false);
|
|
||||||
ajax.addEventListener("error", () => {
|
|
||||||
controller.progressview.removeProgress("ota_upload")
|
|
||||||
toast.error("OTA upload failed due to a network error.");
|
|
||||||
}, false);
|
|
||||||
ajax.addEventListener("abort", () => {
|
|
||||||
controller.progressview.removeProgress("ota_upload")
|
|
||||||
toast.error("OTA upload was aborted.");
|
|
||||||
}, false);
|
|
||||||
ajax.open("POST", PUBLIC_URL + "/ota");
|
|
||||||
ajax.send(payload);
|
|
||||||
};
|
|
||||||
reader.onerror = () => {
|
|
||||||
toast.error("Error reading firmware file.");
|
|
||||||
};
|
|
||||||
reader.readAsArrayBuffer(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
private crc32(data: Uint8Array): number {
|
|
||||||
let crc = 0xFFFFFFFF;
|
|
||||||
for (let i = 0; i < data.length; i++) {
|
|
||||||
let byte = data[i];
|
|
||||||
crc ^= byte;
|
|
||||||
for (let j = 0; j < 8; j++) {
|
|
||||||
if (crc & 1) {
|
|
||||||
crc = (crc >>> 1) ^ 0xEDB88320;
|
|
||||||
} else {
|
|
||||||
crc = crc >>> 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}, false);
|
||||||
return (crc ^ 0xFFFFFFFF) >>> 0;
|
ajax.addEventListener("error", () => {
|
||||||
|
controller.progressview.removeProgress("ota_upload")
|
||||||
|
toast.error("OTA upload failed due to a network error.");
|
||||||
|
}, false);
|
||||||
|
ajax.addEventListener("abort", () => {
|
||||||
|
controller.progressview.removeProgress("ota_upload")
|
||||||
|
toast.error("OTA upload was aborted.");
|
||||||
|
}, false);
|
||||||
|
ajax.open("POST", PUBLIC_URL + "/ota");
|
||||||
|
ajax.send(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
async version(): Promise<void> {
|
async version(): Promise<void> {
|
||||||
@@ -415,9 +379,9 @@ export class Controller {
|
|||||||
|
|
||||||
var pretty = JSON.stringify(detection, undefined, 1);
|
var pretty = JSON.stringify(detection, undefined, 1);
|
||||||
|
|
||||||
fetch(PUBLIC_URL + "/detect_sensors", { method: "POST", body: pretty })
|
fetch(PUBLIC_URL + "/detect_sensors", {method: "POST", body: pretty})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then (json => json as Detection)
|
.then(json => json as Detection)
|
||||||
.then(json => {
|
.then(json => {
|
||||||
clearTimeout(timerId);
|
clearTimeout(timerId);
|
||||||
controller.progressview.removeProgress("detect_sensors");
|
controller.progressview.removeProgress("detect_sensors");
|
||||||
@@ -568,7 +532,7 @@ export class Controller {
|
|||||||
|
|
||||||
private setCanPower(checked: boolean) {
|
private setCanPower(checked: boolean) {
|
||||||
var body: CanPower = {
|
var body: CanPower = {
|
||||||
state : checked
|
state: checked
|
||||||
}
|
}
|
||||||
var pretty = JSON.stringify(body, undefined, 1);
|
var pretty = JSON.stringify(body, undefined, 1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user