update compatibility

This commit is contained in:
Silent YANG 2024-11-06 02:07:17 +08:00
parent 58828b26dc
commit 0ac159910b
2 changed files with 26 additions and 5 deletions

View file

@ -1021,6 +1021,19 @@ async function readPacketNoVerify(port, timeout = 1000) {
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function chunkUint8Array(inputArray, chunkSize) {
const result = [];
for (let i = 0; i < inputArray.length; i += chunkSize) {
// 将每一部分切割成新的Uint8Array
result.push(inputArray.slice(i, i + chunkSize));
}
return result;
}
/**
* Sends a packet to the radio.
* @param {SerialPort} port - The serial port to write to.
@ -1041,7 +1054,12 @@ async function sendPacket(port, data) {
// send packet
//console.log('Sending packet:', packet);
await writer.write(packet);
const chunkedPacket = chunkUint8Array(packet, 64);
for(let i = 0; i < chunkedPacket.length; i++){
await writer.write(chunkedPacket[i]);
await sleep(1); // magic
}
// close writer
writer.releaseLock();
} catch (error) {

View file

@ -93,17 +93,20 @@ const flashIt = async () => {
if(state.protocol == 'Official'){
await readPacket(_connect, 0x18, 1000);
}
const rawVersion = unpackVersion(state.binaryFile);
const _data = new Uint8Array([0x30, 0x5, rawVersion.length, 0x0, ...rawVersion]);
// const rawVersion = unpackVersion(state.binaryFile);
// const _data = new Uint8Array([0x30, 0x5, rawVersion.length, 0x0, ...rawVersion]);
if(state.protocol == 'Official'){
await sendPacket(_connect, _data);
await sendPacket(_connect, [48,5,16,0,42,79,69,70,87,45,76,79,83,69,72,85,0,0,0,0]); // magic
await readPacket(_connect, 0x18);
}
const firmware = unpack(state.binaryFile);
if (firmware.length > 0xefff) throw new Error('Last resort boundary check failed. Whoever touched the code is an idiot.');
if (firmware.length > 0xf000) {
alert('最后的边界检查失败。不管是谁修改了代码,他都是个白痴。');
throw new Error('Last resort boundary check failed. Whoever touched the code is an idiot.');
}
for (let i = 0; i < firmware.length; i += 0x100) {
const data = firmware.slice(i, i + 0x100);