This commit is contained in:
Silent YANG 2024-05-08 22:47:06 +08:00
parent cafe42297e
commit a08cb86ab0
3 changed files with 119 additions and 17 deletions

View File

@ -1110,9 +1110,62 @@ async function eeprom_reboot(port) {
return true;
}
async function check_eeprom(port) {
alert('TODO')
return null;
async function check_eeprom(port, protocol = "official") {
let eepromSize = 0;
const random = [
Math.round(Math.random() * 256),
Math.round(Math.random() * 256),
Math.round(Math.random() * 256),
Math.round(Math.random() * 256),
Math.round(Math.random() * 256),
Math.round(Math.random() * 256),
Math.round(Math.random() * 256),
Math.round(Math.random() * 256)
]
await eeprom_init(port);
const rawEEPROM = new Uint8Array(random);
if(protocol == 'official'){
const bk1 = await eeprom_read(port, 0, 0x08, protocol);
await eeprom_write(port, 0, rawEEPROM, 0x08, protocol);
const check1 = await eeprom_read(port, 0, 0x08, protocol);
if(rawEEPROM.toString() == check1.toString()){
eepromSize = 0x2000
}
await eeprom_write(port, 0, bk1, 0x08, protocol);
}else{
const bk1 = await eeprom_read(port, 0, 0x08, protocol);
await eeprom_write(port, 0, rawEEPROM, 0x08, protocol);
const check1 = await eeprom_read(port, 0, 0x08, protocol);
if(rawEEPROM.toString() == check1.toString()){
eepromSize = 0x2000
}
await eeprom_write(port, 0, bk1, 0x08, protocol);
const bk2 = await eeprom_read(port, 0x1FFF8, 0x08, protocol);
await eeprom_write(port, 0x1FFF8, rawEEPROM, 0x08, protocol);
const check2 = await eeprom_read(port, 0x1FFF8, 0x08, protocol);
if(rawEEPROM.toString() == check2.toString()){
eepromSize = 0x20000
}
await eeprom_write(port, 0x1FFF8, bk2, 0x08, protocol);
const bk3 = await eeprom_read(port, 0x3FFF8, 0x08, protocol);
await eeprom_write(port, 0x3FFF8, rawEEPROM, 0x08, protocol);
const check3 = await eeprom_read(port, 0x3FFF8, 0x08, protocol);
if(rawEEPROM.toString() == check3.toString()){
eepromSize = 0x40000
}
await eeprom_write(port, 0x3FFF8, bk3, 0x08, protocol);
const bk4 = await eeprom_read(port, 0x7FFF8, 0x08, protocol);
await eeprom_write(port, 0x7FFF8, rawEEPROM, 0x08, protocol);
const check4 = await eeprom_read(port, 0x7FFF8, 0x08, protocol);
if(rawEEPROM.toString() == check4.toString()){
eepromSize = 0x80000
}
await eeprom_write(port, 0x7FFF8, bk4, 0x08, protocol);
}
return eepromSize;
}
function uint8ArrayToString(uint8Array, charset = "official") {

View File

@ -30,12 +30,24 @@
<a-button type="text" @click="checkEeprom">自动检测</a-button>
</a-space>
</a-tab-pane>
<a-tab-pane key="3" title="清空数据">
<a-space>
<a-button type="primary" @click="showClearDialog">清空数据</a-button>
</a-space>
</a-tab-pane>
</a-tabs>
<a-divider />
<div id="statusArea" style="height: 20em; background-color: azure; color: silver; overflow: auto; padding: 20px" v-html="state.status"></div>
</a-card>
</a-col>
</a-row>
<t-dialog
v-model:visible="state.showDialog"
theme="warning"
:header="state.dialogTitle >= 3 ? '第 ' + state.dialogTitle + ' 次警告(最后警告)' : '第 ' + state.dialogTitle + ' 次警告'"
body="这将会清空 EEPROM 所有内容,包括配置及校准数据!!!"
@confirm="onClickConfirm"
/>
</div>
</template>
@ -50,12 +62,59 @@ const state = reactive({
status: "点击备份按钮将生成 EEPROM 备份文件<br/><br/>",
eepromType: "",
showHide: 0,
startInfo: "0x00"
startInfo: "0x00",
showDialog: false,
dialogTitle: 1
})
const onClickConfirm = () => {
if(state.dialogTitle >= 3){
state.showDialog = false;
clearEEPROM();
return;
}
state.dialogTitle += 1;
}
const showClearDialog = () => {
state.dialogTitle = 1;
state.showDialog = true;
}
const checkEeprom = async () => {
if(appStore.connectState != true){alert('请先连接手台!'); return;};
await check_eeprom();
const eepromSize = await check_eeprom(appStore.connectPort, appStore.configuration?.uart);
switch(eepromSize){
case 0x2000:
state.eepromType = "1";
break;
case 0x20000:
state.eepromType = "2";
break;
case 0x40000:
state.eepromType = "3";
break;
case 0x80000:
state.eepromType = "4";
break;
default:
break;
}
}
const clearEEPROM = async () => {
if(appStore.connectState != true){alert('请先连接手台!'); return;};
const eepromSize = await check_eeprom(appStore.connectPort, appStore.configuration?.uart);
let rawEEPROM = new Uint8Array(0x80);
for (let i = 0; i < eepromSize; i += 0x80) {
await eeprom_write(appStore.connectPort, i, rawEEPROM, 0x80, appStore.configuration?.uart);
state.status = state.status + "清空进度:" + (((i - 0) / eepromSize) * 100).toFixed(1) + "%<br/>";
nextTick(()=>{
const textarea = document?.getElementById('statusArea');
if(textarea)textarea.scrollTop = textarea?.scrollHeight;
})
}
await eeprom_reboot(appStore.connectPort);
}
const backupRange = async (start: any, end: any, name: any = new Date() + '_backup.bin') =>{

View File

@ -36,10 +36,6 @@
</a-col>
</a-row>
<t-pagination style="margin: 10px;" :total="6" showPageNumber :showPageSize="false" />
<a-tabs :active-key="state.activeKey" @change="(e)=>{state.activeKey = e}">
<a-tab-pane :key="1" title="LOSEHU 117"></a-tab-pane>
<a-tab-pane :key="2" title="LOSEHU 118+"></a-tab-pane>
</a-tabs>
<div id="canvasDiv" style="zoom: 250%;"></div>
<br>
<a-space>
@ -62,11 +58,9 @@ import { eeprom_write, eeprom_reboot, eeprom_init } from '@/utils/serial.js';
const appStore = useAppStore();
const state : {
activeKey: any,
binaryFile: any,
loading: boolean
} = reactive({
activeKey: 1,
binaryFile: undefined,
loading: false
})
@ -197,17 +191,13 @@ const flashIt = async () => {
alert('固件版本不匹配');
return;
}
if(state.activeKey == 2 && appStore.configuration?.charset != "gb2312"){
alert('固件版本不匹配');
return;
}
if(state.activeKey == 1 && appStore.configuration?.charset != "losehu"){
if(appStore.configuration?.charset != "losehu" && appStore.configuration?.charset != "gb2312"){
alert('固件版本不匹配');
return;
}
state.loading = true
let position = 0x1E350;
if(state.activeKey == 2)position = 0x2080;
if(appStore.configuration?.charset == "gb2312")position = 0x2080;
await eeprom_init(appStore.connectPort);
const rawEEPROM = state.binaryFile;
for (let i = position; i < rawEEPROM.length + position; i += 0x80) {