diff --git a/default.aproj b/default.aproj index 09c5116..e5a8044 100644 --- a/default.aproj +++ b/default.aproj @@ -11,5 +11,6 @@ + diff --git a/main.aardio b/main.aardio index 56a9299..ea60dac 100644 --- a/main.aardio +++ b/main.aardio @@ -95,7 +95,12 @@ var DiagReadDID = function(did){ var Diag10Req = function(num){ ::PostThreadMessage(thrdId,111,num,0)//自定义消息 } - +var DiagBootReq = function(){ + ::PostThreadMessage(thrdId,102,0,0)//自定义消息 +} +var DiagStopReq = function(){ + ::PostThreadMessage(thrdId,103,0,0)//自定义消息 +} mainForm.btnReadSw.oncommand = function(id,event){ DiagReadDID(0xF195); @@ -111,7 +116,11 @@ mainForm.btnReadF186.oncommand = function(id,event){ } mainForm.btnTest.oncommand = function(id,event){ - Diag10Req(0x03); + DiagStopReq(); +} + +mainForm.btnFlash.oncommand = function(id,event){ + DiagBootReq(); } thrdHandle,thrdId = thread.create( CanThread ) diff --git a/user/CanThread.aardio b/user/CanThread.aardio index 81889b1..bf17d0f 100644 --- a/user/CanThread.aardio +++ b/user/CanThread.aardio @@ -7,7 +7,8 @@ CANHw.LoadDll(); DiagReqID = 0x18dadff1; DiagRespID = 0x18daf1df; - +DiagGloableID = 0x18DB33F1; +stopflag = 0; //注册一个消息钩子函数 FuncLoopMsg = function(msg){ //console.log( "收到消息",msg.message ); @@ -20,7 +21,7 @@ FuncLoopMsg = function(msg){ FuncConnect(msg.wParam,msg.lParam); } case 102 { - FuncBootload(); + FuncStartBoot(); } case 103 { FuncStop(); @@ -79,8 +80,11 @@ loadcodex("\user\Diag22code.aardio"); loadcodex("\user\Diag85code.aardio"); loadcodex("\user\Diag28code.aardio"); loadcodex("\user\Diag7Fcode.aardio"); +loadcodex("\user\Diag27code.aardio"); -var RespState = 0; +loadcodex("\user\DiagBootcode.aardio"); + +RespState = 0; FuncDiagPro = function(diagmsg){ //console.log("诊断服务") @@ -113,39 +117,33 @@ FuncDiagPro = function(diagmsg){ RespState = diagmsg.sid; } -FuncStop = function(){ - stopflag = 1; + + + + + + +FuncStartBoot = function(){ + FuncInitBootState(); + boottimer.enable(); + + FuncDisplay("开始刷写"); + } -FuncWait = function(sid){ - for(i=1;40;1){ - sleep(100); - if(RespState == (sid + 0x40)){//正响应 - return 0; - } - errsid,errnrc = FuncGetNrc() - if(errsid == sid){ - if(errnrc == 0x78){ - FuncClrNrc();//等待 - i = 1; - } - else { - return 1; //负响应 - } - - } + + + +boottimer = win.timer(,10); +boottimer.onTimer = function(){ + if(CANHw.isConnected() == false){ + boottimer.disable(); + return; } - + FuncBootSeq(); } -FuncBootload = function(){ - -} - - - - timer1 = win.timer(,1); diagresp = {} timer1.onTimer = function(){ diff --git a/user/Diag28code.aardio b/user/Diag28code.aardio index e1ba67b..c6a9883 100644 --- a/user/Diag28code.aardio +++ b/user/Diag28code.aardio @@ -3,7 +3,7 @@ FuncReq28 = function(num){ if(num >= 1 && num <= 3){ var data = {0x02,0x28,num,0,0,0,0,0}; - CANHw.SendMsg(DiagReqID,data); + CANHw.SendMsg(DiagGloableID,data); } } diff --git a/user/Diag85code.aardio b/user/Diag85code.aardio index b3975b0..d9f7940 100644 --- a/user/Diag85code.aardio +++ b/user/Diag85code.aardio @@ -3,7 +3,7 @@ FuncReq85 = function(num){ if(num >= 1 && num <= 3){ var data = {0x02,0x85,num,0,0,0,0,0}; - CANHw.SendMsg(DiagReqID,data); + CANHw.SendMsg(DiagGloableID,data); } } diff --git a/user/DiagBootcode.aardio b/user/DiagBootcode.aardio new file mode 100644 index 0000000..b0986b8 --- /dev/null +++ b/user/DiagBootcode.aardio @@ -0,0 +1,130 @@ + + +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 { + FuncDisplay("错误"); + boottimer.disable(); + return 1; //负响应 + } + + } + if(stopflag == 1){ + FuncDisplay("停止"); + boottimer.disable(); + return 2;//停止命令 + } + bootcount += 1; + if(bootcount >= 400){ + FuncDisplay("超时"); + 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; + } +} + + +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){ + FuncReq10(0x03);//进入扩展会话 + FuncClearState(); + } + else { + var ret = FuncWait(0x10); + nextstate(ret); + } + } + case 4 { + if(sendstate == 0){ + FuncReq85(0x02);//进入扩展会话 + FuncClearState(); + } + else { + var ret = FuncWait(0x85); + nextstate(ret); + } + } + case 5 { + if(sendstate == 0){ + FuncReq28(0x01);//进入扩展会话 + FuncClearState(); + } + else { + var ret = FuncWait(0x28); + nextstate(ret); + } + } + else { + FuncDisplay("停止") + boottimer.disable(); + } + } +} \ No newline at end of file