sync
This commit is contained in:
31
webpage/src/lib/protocol/commands/PlayFile.ts
Normal file
31
webpage/src/lib/protocol/commands/PlayFile.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { bus } from '../../bus/SerialBus';
|
||||
import { Command, FrameType } from '../constants';
|
||||
|
||||
export class PlayFileCommand {
|
||||
async execute(path: string): Promise<boolean | null> {
|
||||
try {
|
||||
const p = new TextEncoder().encode(path);
|
||||
// Wir brauchen: 1 Byte Flags + 1 Byte Länge + Pfad
|
||||
const req = new Uint8Array(p.length + 2);
|
||||
|
||||
req[0] = 0x01; // 1. Byte: Flags (LSB: 1 = sofort abspielen)
|
||||
req[1] = p.length; // 2. Byte: Länge für get_path() im C-Code
|
||||
req.set(p, 2); // Ab 3. Byte: Der Pfad-String
|
||||
|
||||
await bus.sendRequest(Command.PLAY, req);
|
||||
|
||||
// Warten auf das ACK vom Board
|
||||
if (await bus.waitForSync()) {
|
||||
const typeArr = await bus.readExact(1);
|
||||
if (typeArr[0] === FrameType.ACK) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("PlayFileCommand failed:", e);
|
||||
} finally {
|
||||
bus.releaseReadLock();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user