mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2025-12-11 05:16:16 +00:00
ota suppor
This commit is contained in:
@@ -439,4 +439,47 @@ export class CharaDevice {
|
||||
async getRamBytesAvailable(): Promise<number> {
|
||||
return Number(await this.send(1, "RAM").then(([bytes]) => bytes));
|
||||
}
|
||||
|
||||
async updateFirmware(file: File): Promise<void> {
|
||||
const size = file.size;
|
||||
// use separate serial connection
|
||||
await this.port.open({ baudRate: this.baudRate });
|
||||
const decoderStream = new TextDecoderStream();
|
||||
this.port.readable!.pipeTo(decoderStream.writable);
|
||||
|
||||
const reader = decoderStream
|
||||
.readable!.pipeThrough(new TransformStream(new LineBreakTransformer()))
|
||||
.getReader();
|
||||
serialLog.update((it) => {
|
||||
it.push({
|
||||
type: "system",
|
||||
value: "Starting firmware update",
|
||||
});
|
||||
return it;
|
||||
});
|
||||
|
||||
const writer = this.port.writable!.getWriter();
|
||||
try {
|
||||
await writer.write(new TextEncoder().encode(`RST OTA\r\n`));
|
||||
} finally {
|
||||
writer.releaseLock();
|
||||
}
|
||||
|
||||
console.log((await reader.read()).value);
|
||||
|
||||
await file.stream().pipeTo(this.port.writable!);
|
||||
|
||||
console.log((await reader.read()).value);
|
||||
|
||||
await reader.cancel();
|
||||
reader.releaseLock();
|
||||
await this.port.close();
|
||||
serialLog.update((it) => {
|
||||
it.push({
|
||||
type: "system",
|
||||
value: "Success?",
|
||||
});
|
||||
return it;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
15
src/routes/(app)/ota-update/+page.svelte
Normal file
15
src/routes/(app)/ota-update/+page.svelte
Normal file
@@ -0,0 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { serialPort } from "$lib/serial/connection";
|
||||
|
||||
let files: FileList | null = $state(null);
|
||||
|
||||
$effect(() => {
|
||||
const file = files?.[0];
|
||||
if (file && $serialPort) {
|
||||
|
||||
$serialPort.updateFirmware(file);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<input type="file" accept=".bin" bind:files />
|
||||
Reference in New Issue
Block a user