can_bootloader/user/DiagBootcode.aardio

375 lines
6.5 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)){//正响应
2022-05-17 16:34:44 +08:00
//bootcount = 0;
2022-05-14 17:00:49 +08:00
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-17 16:34:44 +08:00
var sendblockstate = 0;
var alldata = {};
var blocknum = 1;
FuncSendBlockInit = function(){
alldata = FuncGetAllData();
blocknum = 1;
if(alldata != null){
blocknum = 1;
2022-05-18 08:55:11 +08:00
FuncStartSendBlock(alldata[blocknum]["data"])
2022-05-17 16:34:44 +08:00
}
}
var FuncSendBlockApp_sendflag = 0
FuncSendBlockApp = function(){
select(sendblockstate) {
case 0{
if(FuncSendBlockApp_sendflag == 0){
2022-05-18 08:55:11 +08:00
FuncReq34(alldata[blocknum]["address"],#alldata[blocknum]["data"]);
2022-05-17 16:34:44 +08:00
FuncSendBlockApp_sendflag = 1;
RespState = 0;
bootcount = 0;
}
else {
if(FuncWait(0x34) == 0){
FuncSendBlockApp_sendflag = 0;
sendblockstate += 1;
}
}
}
case 1 {
2022-05-18 08:55:11 +08:00
FuncStartSendBlock(alldata[blocknum]["data"]);//初始化
2022-05-17 16:34:44 +08:00
FuncSendBlockApp_sendflag = 0;
sendblockstate += 1;
}
case 2 {
if(FuncSendBlockApp_sendflag == 0){
FuncSendNextBlock();
FuncSendBlockApp_sendflag = 1;
RespState = 0;
bootcount = 0;
}
else {
if(FuncWait(0x36) == 0){
FuncSendBlockApp_sendflag = 0;
if(FuncGetSendStatus() == true){//所有块发送完成
sendblockstate += 1;
}
}
}
}
case 3 {
if(FuncSendBlockApp_sendflag == 0){
FuncReq37();
FuncSendBlockApp_sendflag = 1;
RespState = 0;
bootcount = 0;
}
else {
if(FuncWait(0x37) == 0){
FuncSendBlockApp_sendflag = 0;
sendblockstate += 1;
}
}
}
else {
if(blocknum < #alldata){
blocknum += 1;
sendblockstate = 0;
}
else {
//所有数据发送完成
return 0;
}
}
}
return 1;
}
2022-05-14 17:00:49 +08:00
2022-05-17 16:34:44 +08:00
//boot总流程
2022-05-14 17:00:49 +08:00
FuncBootSeq = function(){
select(bootstate) {
case 0 {
//读取当前会话
2022-05-18 08:55:11 +08:00
/*
var bootdata = FuncGetAllData();
if(#bootdata < 1){
FuncDisplay("请打开文件");
boottimer.disable();
return 0;
}*/
2022-05-14 17:00:49 +08:00
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){
FuncClearState();
2022-05-18 08:55:11 +08:00
FuncDIDWriteStr(0xf198,"0123456789abcdef1234");//写入repair_shopcode
2022-05-17 14:11:10 +08:00
}
else {
var ret = FuncWait(0x2E);
nextstate(ret);
}
}
case 10 {
2022-05-17 16:34:44 +08:00
if(sendstate == 0){//写入installation_date
2022-05-17 14:11:10 +08:00
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();
2022-05-18 08:55:11 +08:00
console.log("写入installation_date")
2022-05-17 14:11:10 +08:00
}
else {
var ret = FuncWait(0x2E);
nextstate(ret);
}
}
2022-05-17 16:34:44 +08:00
case 11 {
if(sendstate == 0){//擦除flash
FuncReq31EraseFlash(0x00FE0000,0x00019FE0);//
FuncClearState();
}
else {
var ret = FuncWait(0x31);
nextstate(ret);
}
}
case 12 {
if(sendstate == 0){//发送数据
FuncSendBlockInit();
FuncClearState();
}
else {
var ret = FuncSendBlockApp();
nextstate(ret);
}
}
case 13 {
2022-05-18 08:55:11 +08:00
if(sendstate == 0){//CheckLogicBlock
FuncReq31CheckLogicBlock(0x00FE0000,0x00019FCC);
2022-05-17 16:34:44 +08:00
FuncClearState();
}
else {
2022-05-18 08:55:11 +08:00
var ret = FuncWait(0x31);
nextstate(ret);
}
}
case 14 {
if(sendstate == 0){////Programming Dependencies
FuncReq31CheckPD();
FuncClearState();
}
else {
var ret = FuncWait(0x31);
nextstate(ret);
}
}
case 15 {
if(sendstate == 0){//复位
FuncReq11(0x01);
FuncClearState();
}
else {
var ret = FuncWait(0x11);
2022-05-17 16:34:44 +08:00
nextstate(ret);
}
}
2022-05-17 14:11:10 +08:00
2022-05-18 08:55:11 +08:00
case 16 {
if(sendstate == 0){
FuncReq10(true,0x03);//进入扩展会话
FuncClearState();
}
else {
var ret = FuncWait(0x10);
nextstate(ret);
}
}
case 17 {
if(sendstate == 0){
FuncReq28(0x00,0x01);//开启发送
FuncClearState();
}
else {
var ret = FuncWait(0x28);
nextstate(ret);
}
}
case 18 {
if(sendstate == 0){
FuncReq85(0x01);//开启DTC
FuncClearState();
}
else {
var ret = FuncWait(0x85);
nextstate(ret);
}
}
case 19 {
if(sendstate == 0){
FuncReq10(true,0x01);//进入默认会话
FuncClearState();
}
else {
var ret = FuncWait(0x10);
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();
}
}
}