增加自适应速度,增加重复尝试次数

This commit is contained in:
sunbeam 2024-09-21 13:33:06 +08:00
parent 927b90c4eb
commit 7e3e411ac1
3 changed files with 55 additions and 5 deletions

View File

@ -163,7 +163,7 @@ autoconnect.onTimer = function(){
sleep(20);
if(#thrdTable.设备 > 0){
Display(thrdTable.设备[1].name);
::PostThreadMessage(thrdId,101,1,0x00);//连接 0x80 -> CANFD
::PostThreadMessage(thrdId,101,1,0x80);//连接 0x80 -> CANFD
}
}
else {

View File

@ -80,6 +80,20 @@ FuncReadDeviceVersion = function(id){
}
}
var delay_const = 100000;
DelayTest = function(){
import time.performance;
var tk = time.performance.tick();
for(i=1;1000000;1)
{
}
var tk2 = time.performance.tick();
tk2 = tk2 - tk;
delay_const = math.ceil(1000000*(1/tk2));
FuncDisplay(delay_const);
//console.log(delay_const);
}
FuncSetCANID = function(req,resp){
@ -253,7 +267,7 @@ FuncStartBoot = function(id){
var delay = function(w){
while(w){
for(i=1;50000;1)
for(i=1;delay_const;1)
{
}
w -= 1;
@ -267,7 +281,7 @@ var FuncSendPackage = function(){
while(#Packdata > 0)
{
//sleep(1);
delay(2);
delay(1);
var data = {PackNext,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC};
var max = #Packdata > 7 ? 7 : #Packdata;
for(i=1;max;1){
@ -356,5 +370,5 @@ timer1.onTimer = function(){
FuncLoadAPPFile();
timer1.enable();
FuncDisplay("CAN线程正在运行");
DelayTest();

View File

@ -4,6 +4,7 @@ var bootstate = 0;
var bootcount = 0;
var sendstate = 0;
var senddataid = 0;
var repeat_times = 0;
FuncWait = function(sid){
if(RespState == (sid + 0x40)){//正响应
//bootcount = 0;
@ -37,6 +38,12 @@ FuncWait = function(sid){
boottimer.disable();
return 3;//超时
}
if(sid==0x2e && repeat_times < 5 && bootcount > 100){
repeat_times++;
bootcount = 0;
repeat_times++;
sendstate = 0;
}
return 0xff;
}
@ -54,6 +61,7 @@ FuncInitBootState = function(id){
bootcount = 0;
sendstate = 0;
senddataid = id;
repeat_times = 0;
}
@ -504,7 +512,7 @@ FuncBootSeq = function(){
//nextstate(0);
if(sendstate == 0){
FuncReq10(true,0x01);//进入默认会话
FuncReq10(false,0x01);//进入默认会话
FuncClearState();
}
else {
@ -513,6 +521,34 @@ FuncBootSeq = function(){
}
}
case 23 {
if(sendstate == 0){
FuncDisplay("读取版本");
FuncReadDID(0xF195);//读取软件版本
FuncClearState();
}
else {
delaycount++;
if(delaycount > 5){
nextstate(0);
delaycount = 0;
}
}
}
case 24 {
if(sendstate == 0){
FuncDisplay("读取软件日期");
FuncReadDID(0xF18A);//读取软件版本
FuncClearState();
}
else {
delaycount++;
if(delaycount > 5){
nextstate(0);
delaycount = 0;
}
}
}
else {
thread.command.$SendEnd(true);
//FuncDisplay("刷写完成,用时 " + boottime/100 + " S")