|
|
|
|
@@ -191,72 +191,36 @@ export class Controller {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uploadNewFirmware(file: File) {
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
reader.onload = () => {
|
|
|
|
|
const arrayBuffer = reader.result as ArrayBuffer;
|
|
|
|
|
const data = new Uint8Array(arrayBuffer);
|
|
|
|
|
const crc = this.crc32(data);
|
|
|
|
|
const size = data.length;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
let current = 0;
|
|
|
|
|
let max = 100;
|
|
|
|
|
controller.progressview.addProgress("ota_upload", (current / max) * 100, "Uploading firmeware (" + current + "/" + max + ")")
|
|
|
|
|
const ajax = new XMLHttpRequest();
|
|
|
|
|
ajax.upload.addEventListener("progress", event => {
|
|
|
|
|
current = event.loaded / 1000;
|
|
|
|
|
max = event.total / 1000;
|
|
|
|
|
controller.progressview.addProgress("ota_upload", (current / max) * 100, "Uploading firmeware (" + current + "/" + max + ")")
|
|
|
|
|
const ajax = new XMLHttpRequest();
|
|
|
|
|
ajax.upload.addEventListener("progress", event => {
|
|
|
|
|
current = event.loaded / 1000;
|
|
|
|
|
max = event.total / 1000;
|
|
|
|
|
controller.progressview.addProgress("ota_upload", (current / max) * 100, "Uploading firmeware (" + current + "/" + max + ")")
|
|
|
|
|
}, false);
|
|
|
|
|
ajax.addEventListener("load", () => {
|
|
|
|
|
controller.progressview.removeProgress("ota_upload")
|
|
|
|
|
const status = ajax.status;
|
|
|
|
|
if (status >= 200 && status < 300) {
|
|
|
|
|
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);
|
|
|
|
|
ajax.addEventListener("load", () => {
|
|
|
|
|
controller.progressview.removeProgress("ota_upload")
|
|
|
|
|
const status = ajax.status;
|
|
|
|
|
if (status >= 200 && status < 300) {
|
|
|
|
|
controller.reboot();
|
|
|
|
|
} else {
|
|
|
|
|
const statusText = ajax.statusText || "";
|
|
|
|
|
const body = ajax.responseText || "";
|
|
|
|
|
toast.error(`OTA update error (${status}${statusText ? ' ' + statusText : ''}): ${body}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (crc ^ 0xFFFFFFFF) >>> 0;
|
|
|
|
|
}, 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(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async version(): Promise<void> {
|
|
|
|
|
@@ -415,9 +379,9 @@ export class Controller {
|
|
|
|
|
|
|
|
|
|
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 (json => json as Detection)
|
|
|
|
|
.then(json => json as Detection)
|
|
|
|
|
.then(json => {
|
|
|
|
|
clearTimeout(timerId);
|
|
|
|
|
controller.progressview.removeProgress("detect_sensors");
|
|
|
|
|
@@ -568,7 +532,7 @@ export class Controller {
|
|
|
|
|
|
|
|
|
|
private setCanPower(checked: boolean) {
|
|
|
|
|
var body: CanPower = {
|
|
|
|
|
state : checked
|
|
|
|
|
state: checked
|
|
|
|
|
}
|
|
|
|
|
var pretty = JSON.stringify(body, undefined, 1);
|
|
|
|
|
|
|
|
|
|
|