This commit is contained in:
sunbeam 2022-05-14 17:00:49 +08:00
parent fe83261e37
commit 0b50dda660
6 changed files with 172 additions and 34 deletions

View File

@ -11,5 +11,6 @@
<file name="Diag85code.aardio" path="user\Diag85code.aardio" comment="user\Diag85code.aardio"/>
<file name="Diag7Fcode.aardio" path="user\Diag7Fcode.aardio" comment="user\Diag7Fcode.aardio"/>
<file name="Diag27code.aardio" path="user\Diag27code.aardio" comment="user\Diag27code.aardio"/>
<file name="DiagBootcode.aardio" path="user\DiagBootcode.aardio" comment="user\DiagBootcode.aardio"/>
</folder>
</project>

View File

@ -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 )

View File

@ -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(){

View File

@ -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);
}
}

View File

@ -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);
}
}

130
user/DiagBootcode.aardio Normal file
View File

@ -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();
}
}
}