can_bootloader/user/DiagBootcode.aardio

194 lines
3.1 KiB
Plaintext
Raw Normal View History

2022-05-14 17:00:49 +08:00
var bootstate = 0;
var bootcount = 0;
var sendstate = 0;
FuncWait = function(sid){
if(RespState == (sid + 0x40)){//正响应
return 0;
}
errsid,errnrc = FuncGetNrc();
FuncClrNrc();
if(errsid == sid){
if(errnrc == 0x78){//等待
bootcount = 0;
return 0xff;
}
else {
2022-05-17 14:11:10 +08:00
FuncDisplay("刷写错误");
2022-05-14 17:00:49 +08:00
boottimer.disable();
return 1; //负响应
}
}
if(stopflag == 1){
FuncDisplay("停止");
boottimer.disable();
return 2;//停止命令
}
bootcount += 1;
if(bootcount >= 400){
2022-05-17 14:11:10 +08:00
FuncDisplay("超时 " + tostring(sid,16));
2022-05-14 17:00:49 +08:00
boottimer.disable();
return 3;//超时
}
}
FuncStopBoot = function(){
stopflag = 1;
}
FuncClearState = function(){
RespState = 0;
bootcount = 0;
sendstate = 1;
}
FuncInitBootState = function(){
bootstate = 0;
RespState = 0;
bootcount = 0;
sendstate = 0;
}
nextstate = function(val){
if(val == 0){
bootstate += 1;
sendstate = 0;
}
}
2022-05-17 14:11:10 +08:00
BCD_Conv = function(num){
if(num > 99){
return 0;
}
return (num/10)*16 + (num%10);
}
2022-05-14 17:00:49 +08:00
FuncBootSeq = function(){
select(bootstate) {
case 0 {
//读取当前会话
if(sendstate == 0){
FuncReadDID(0xF186);
FuncClearState();
}
else {
var ret = FuncWait(0x22);
nextstate(ret);
}
}
case 1 {
if(sendstate == 0){
FuncReadDID(0xF195);//读取软件版本
FuncClearState();
}
else {
var ret = FuncWait(0x22);
nextstate(ret);
}
}
case 2 {
if(sendstate == 0){
FuncReadDID(0xF192);//读取硬件版本
FuncClearState();
}
else {
var ret = FuncWait(0x22);
nextstate(ret);
}
}
case 3 {
if(sendstate == 0){
2022-05-17 14:11:10 +08:00
FuncReq10(true,0x03);//进入扩展会话
2022-05-14 17:00:49 +08:00
FuncClearState();
}
else {
var ret = FuncWait(0x10);
nextstate(ret);
}
}
case 4 {
if(sendstate == 0){
2022-05-17 14:11:10 +08:00
FuncReq85(0x02);//关闭DTC
2022-05-14 17:00:49 +08:00
FuncClearState();
}
else {
var ret = FuncWait(0x85);
nextstate(ret);
}
}
case 5 {
if(sendstate == 0){
2022-05-17 14:11:10 +08:00
FuncReq28(0x01,0x01);//禁止发送
2022-05-14 17:00:49 +08:00
FuncClearState();
}
else {
var ret = FuncWait(0x28);
nextstate(ret);
}
}
2022-05-17 14:11:10 +08:00
case 6 {
if(sendstate == 0){
FuncReq10(false,0x02);//进入编程会话
FuncClearState();
}
else {
var ret = FuncWait(0x10);
nextstate(ret);
}
}
case 7 {
if(sendstate == 0){
FuncReq27(01);//解密
FuncClearState();
}
else {
var ret = FuncWait(0x27);
nextstate(ret);
}
}
case 8 {
if(sendstate == 0){
//FuncReq27(02);//发送key
FuncClearState();
}
else {
var ret = FuncWait(0x27);
nextstate(ret);
}
}
case 9 {
if(sendstate == 0){
FuncDIDWriteStr(0xf198,"0123456789abcdef1234");
FuncClearState();
}
else {
var ret = FuncWait(0x2E);
nextstate(ret);
}
}
case 10 {
if(sendstate == 0){
var year1 = BCD_Conv(time.now().year/100);
var year2 = BCD_Conv(time.now().year%100);
var month = BCD_Conv(time.now().month);
var day = BCD_Conv(time.now().day);
FuncReq2E(0XF199,{year1,year2,month,day})
FuncClearState();
}
else {
var ret = FuncWait(0x2E);
nextstate(ret);
}
}
2022-05-14 17:00:49 +08:00
else {
2022-05-17 14:11:10 +08:00
FuncDisplay("刷写完成")
2022-05-14 17:00:49 +08:00
boottimer.disable();
}
}
}