v0.5更新

This commit is contained in:
sunbeam 2024-10-29 17:16:03 +08:00
parent f12c067215
commit 6e473f070e
6 changed files with 239 additions and 52 deletions

View File

@ -11,6 +11,8 @@ static={cls="static";text="Static";left=21;top=17;right=458;bottom=340;transpare
V0.1_20230320: 初版 V0.1_20230320: 初版
V0.2_20240921: 中英文版本 V0.2_20240921: 中英文版本
v0.3_20241009: 增加日志记录;增加VIN记录; v0.3_20241009: 增加日志记录;增加VIN记录;
v0.4_20241019: VIN记录方式更改
v0.5_20241029: 限制刷写前的软件版本为SW0302
*/ */
winform.button.oncommand = function(id,event){ winform.button.oncommand = function(id,event){

View File

@ -205,6 +205,20 @@ namespace usb2canfd{
return ret,DeviceInfo,funcstr; return ret,DeviceInfo,funcstr;
} }
//获取设备信息
GetNowInfo = function(){
if(Hwconnected == null){
return 0;
}
//DllHandle.USB_OpenDevice(Hwconnected);
var DeviceInfo = ..usb2canfd.DEVICE_INFO();
var funcstr = ..raw.buffer(100);
var ret = DllHandle.DEV_GetDeviceInfo(Hwconnected,DeviceInfo,funcstr);
return ret,DeviceInfo,funcstr;
}
//获取有效硬件 //获取有效硬件
GetAvailableHW = function(){ GetAvailableHW = function(){
return AvailableHW; return AvailableHW;
@ -290,7 +304,7 @@ namespace usb2canfd{
} }
else { else {
Hwconnected = null //Hwconnected = null
Chconntected = null; Chconntected = null;
} }

View File

@ -1,24 +1,29 @@
import fonts.fontAwesome; import fonts.fontAwesome;
import win.ui; import win.ui;
/*DSG{{*/ /*DSG{{*/
mainForm = win.form(text="CAN_Bootloader";right=699;bottom=473;border="dialog frame";max=false) mainForm = win.form(text="CAN_Bootloader";right=799;bottom=599;border="dialog frame";max=false)
mainForm.add( mainForm.add(
btnFlashLeft={cls="button";text="左侧刷写 btnConfirmVIN={cls="button";text="确认 / confirm";left=263;top=137;right=402;bottom=171;disabled=1;z=16};
Left side flashing";left=30;top=129;right=168;bottom=243;z=2}; btnFlashLeft={cls="button";text="1.左侧刷写
btnFlashRight={cls="button";text="右侧刷写 1.Left side flashing";left=34;top=198;right=214;bottom=298;disabled=1;z=2};
Right side flashing";left=181;top=131;right=319;bottom=245;z=7}; btnFlashRight={cls="button";text="2.右侧刷写
2.Right side flashing";left=224;top=198;right=404;bottom=298;disabled=1;z=7};
btnStopBoot={cls="button";text="停止 btnStopBoot={cls="button";text="停止
Stop";left=29;top=272;right=319;bottom=346;z=3}; Stop";left=31;top=396;right=405;bottom=470;z=3};
edit={cls="edit";left=361;top=19;right=692;bottom=401;autovscroll=false;edge=1;multiline=1;vscroll=1;z=1}; btnVerifyVersion={cls="button";text="3.验证
3.verify";left=31;top=310;right=404;bottom=384;disabled=1;z=13};
edVIN={cls="edit";text="000000";left=91;top=137;right=258;bottom=172;disabled=1;edge=1;font=LOGFONT(h=-16);z=14};
edit={cls="edit";left=421;top=21;right=792;bottom=510;autovscroll=false;edge=1;multiline=1;vscroll=1;z=1};
plus={cls="plus";text="等待刷写 plus={cls="plus";text="等待刷写
Waiting for flashing";left=33;top=375;right=316;bottom=460;bgcolor=12639424;z=10}; Waiting for flashing";left=34;top=485;right=403;bottom=570;bgcolor=12639424;z=10};
progress={cls="progress";left=361;top=435;right=689;bottom=463;edge=1;max=100;min=0;z=4}; progress={cls="progress";left=420;top=546;right=791;bottom=574;edge=1;max=100;min=0;z=4};
static={cls="static";text='\uF127';left=43;top=30;right=114;bottom=98;align="center";center=1;color=255;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=8}; static={cls="static";text='\uF127';left=43;top=30;right=114;bottom=98;align="center";center=1;color=255;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=8};
static2={cls="static";text="设备未连接,请先连接设备";left=126;top=42;right=326;bottom=91;transparent=1;z=9}; static2={cls="static";text="设备未连接,请先连接设备";left=126;top=34;right=326;bottom=83;transparent=1;z=9};
static3={cls="static";text="刷写进度 Flashing writing progress";left=361;top=410;right=688;bottom=430;transparent=1;z=5}; static3={cls="static";text="刷写进度 Flashing writing progress";left=422;top=521;right=749;bottom=541;transparent=1;z=5};
static4={cls="static";text="no.";left=39;top=102;right=141;bottom=122;align="right";transparent=1;z=11}; static4={cls="static";text="no.";left=39;top=102;right=141;bottom=122;align="right";transparent=1;z=11};
static5={cls="static";text="V0.3_20241009";left=545;top=1;right=689;bottom=17;align="right";center=1;notify=1;transparent=1;z=6}; static5={cls="static";text="V0.5_20241029";left=648;top=2;right=792;bottom=18;align="right";center=1;notify=1;transparent=1;z=6};
static6={cls="static";text="00000";left=145;top=102;right=203;bottom=120;transparent=1;z=12} static6={cls="static";text="00000";left=145;top=102;right=203;bottom=120;transparent=1;z=12};
static7={cls="static";text="VIN";left=31;top=137;right=78;bottom=172;align="right";center=1;font=LOGFONT(h=-16);transparent=1;z=15}
) )
/*}}*/ /*}}*/
@ -184,6 +189,7 @@ import thread.table;
thrdTable = thread.table("多线程共享数据"); thrdTable = thread.table("多线程共享数据");
thrdTable.设备连接状态 = 0; thrdTable.设备连接状态 = 0;
thrdTable.设备 = {}; thrdTable.设备 = {};
thrdTable.DIDdata = null;
thrdTable.test = "123" thrdTable.test = "123"
thrdTable["文件加载状态"] = false; thrdTable["文件加载状态"] = false;
thrdTable["电源电压"] = 0; thrdTable["电源电压"] = 0;
@ -235,19 +241,7 @@ mainForm.btnFlashLeft.oncommand = function(id,event){
"); ");
return; return;
} }
// 创建一个输入对话框
var inputBox = win.inputBox();
inputBox.info.text = "请输入VIN码";
inputBox.input.text = VINCODE;
inputBox.text = "输入VIN码";
// 显示输入对话框并获取用户输入
var result = inputBox.doModal();
if(result == null){
Display('请输入正确的VIN');
Display('Please enter the correct VIN\n')
return;
}
VINCODE = result;
side_now = "L"; side_now = "L";
bootstate = true; bootstate = true;
mainForm.edit.text = ""; mainForm.edit.text = "";
@ -267,7 +261,7 @@ mainForm.onClose = function(hwnd,message,wParam,lParam){
autoconnect = win.timer(mainForm,100); autoconnect = win.timer(mainForm,300);
var autoconnect_state = 0; var autoconnect_state = 0;
var power_err_count = 0; var power_err_count = 0;
autoconnect.onTimer = function(){ autoconnect.onTimer = function(){
@ -323,6 +317,8 @@ autoconnect.onTimer = function(){
mainForm.static2.text = "设备已连接,可以开始刷写 The device is connected and can start flashing"; mainForm.static2.text = "设备已连接,可以开始刷写 The device is connected and can start flashing";
::PostThreadMessage(thrdId,115,1,0);//连接 ::PostThreadMessage(thrdId,115,1,0);//连接
autoconnect_state = 4; autoconnect_state = 4;
mainForm.edVIN.disabled = false;
mainForm.btnConfirmVIN.disabled = false;
} }
else { else {
mainForm.static2.text = "文件已损坏,请重新获取烧录上位机"; mainForm.static2.text = "文件已损坏,请重新获取烧录上位机";
@ -333,7 +329,15 @@ autoconnect.onTimer = function(){
} }
case 4 { case 4 {
//... if(thrdTable.设备连接状态 == 0){
autoconnect_state = 0;
thrdTable.设备 = {};
mainForm.edVIN.disabled = true;
mainForm.btnFlashLeft.disabled = true;
mainForm.btnFlashRight.disabled = true;
mainForm.btnConfirmVIN.disabled = true;
mainForm.btnVerifyVersion.disabled = true;
}
} }
else { else {
} }
@ -358,19 +362,6 @@ mainForm.btnFlashRight.oncommand = function(id,event){
"); ");
return; return;
} }
// 创建一个输入对话框
var inputBox = win.inputBox();
inputBox.info.text = "请输入VIN码";
//inputBox.input.text = VINCODE;
inputBox.text = "输入VIN码";
// 显示输入对话框并获取用户输入
var result = inputBox.doModal();
if(result == null ){
Display('请输入正确的VIN');
Display('Please enter the correct VIN\n')
return;
}
VINCODE = result;
side_now = "R"; side_now = "R";
bootstate = true; bootstate = true;
@ -379,8 +370,7 @@ mainForm.btnFlashRight.oncommand = function(id,event){
::PostThreadMessage(thrdId,106,0x710,0x610);//自定义消息 ::PostThreadMessage(thrdId,106,0x710,0x610);//自定义消息
Display(tostring(currentDate)); Display(tostring(currentDate));
Display("右侧开始刷写流程"); Display("右侧开始刷写流程");
Display("Start flashing process Display('Start flashing process \n');
");
starttime = time.now(); starttime = time.now();
DiagBootReq(2);// DiagBootReq(2);//
} }
@ -389,7 +379,7 @@ mainForm.btnStopBoot.oncommand = function(id,event){
DiagStopReq(); DiagStopReq();
} }
autoconnect.enable();
//import console; //import console;
//console.log("io.exis = ",io.exist("\res\P417_SWTL_20240709.S19")); //console.log("io.exis = ",io.exist("\res\P417_SWTL_20240709.S19"));
@ -404,6 +394,150 @@ mainForm.static5.oncommand = function(id,event){
} }
} }
mainForm.btnConfirmVIN.oncommand = function(id,event){
var vinstr = mainForm.edVIN.text;
if(vinstr == null || string.len(vinstr)!=6){
Display("请输入VIN后6位数字");
Display('Please enter the last 6 digits of VIN \n');
}
else {
mainForm.btnFlashLeft.disabled = false;
mainForm.btnFlashRight.disabled = false;
mainForm.btnVerifyVersion.disabled = false;
mainForm.btnConfirmVIN.disabled = true;
mainForm.edVIN.disabled = true;
VINCODE = vinstr;
}
}
ReadDIDdata = function(did){
thrdTable.DIDdata = null;
::PostThreadMessage(thrdId,110,did,0);
//sleep(100);
//return thrdTable.DIDdata;
}
verifyTimerState = 0;
verifyTimer = win.timer(,100);
left_repeat_times = 0;
right_repeat_times = 0;
verifyTimer.onTimer = function(){
select(verifyTimerState) {
case 0 {
left_repeat_times = 0;
right_repeat_times = 0;
verifyTimerState += 1;
}
case 1 {
::PostThreadMessage(thrdId,106,0x720,0x620);//自定义消息
Display('读取左侧开关版本号');
Display('Read left SW Version: \n');
ReadDIDdata(0xf195);
verifyTimerState += 1;
}
case 2 {
swl = thrdTable.DIDdata;
if(swl != null){
if(string.cmp(swl,"SW0303",6) == 0){
Display('左侧版本号正确');
Display('left SW Version correct \n');
verifyTimerState += 1;
}
else {
Display('左侧版本号错误');
Display('left SW Version incorrect \n');
verifyTimerState = 6;
verifyTimer.disable();
}
}
else {//读到空数据
left_repeat_times+=1;
if(left_repeat_times > 3){
Display('左侧版本号错误');
Display('left SW Version incorrect \n');
verifyTimerState = 6;
verifyTimer.disable();
}
else {
verifyTimerState = 1;
}
}
}
case 3 {
::PostThreadMessage(thrdId,106,0x710,0x610);//自定义消息
Display('读取右侧开关版本号');
Display('Read right SW Version: \n');
ReadDIDdata(0xf195);
verifyTimerState += 1;
}
case 4 {
swr = thrdTable.DIDdata;
if(swr != null){
if(string.cmp(swr,"SW0303",6) == 0){
Display('右侧版本号正确');
Display('right SW Version correct \n');
verifyTimerState += 1;
}
else {
Display('右侧版本号错误');
Display('right SW Version incorrect \n');
verifyTimerState = 6;
verifyTimer.disable();
}
}
else {//读到空数据
right_repeat_times+=1;
if(right_repeat_times > 3){
Display('右侧版本号错误');
Display('right SW Version incorrect \n');
verifyTimerState = 6;
verifyTimer.disable();
}
else {
verifyTimerState = 3;
}
}
}
case 5{
Display('软件升级成功');
Display('Software upgrade successful \n');
mainForm.btnFlashLeft.disabled = true;
mainForm.btnFlashRight.disabled = true;
mainForm.edVIN.text = "";
mainForm.edVIN.disabled = false;
mainForm.btnVerifyVersion.disabled = true;
mainForm.btnConfirmVIN.disabled = false;
verifyTimerState += 1;
verifyTimer.disable();
if(VINCODE != null){
var savestr = string.format('VIN:%s ,time:%s ,success \n',VINCODE,tostring(time.now()));
string.save("\验证成功VIN记录.txt",savestr,true);
}
}
case 6{
}
else {
}
}
}
mainForm.btnVerifyVersion.oncommand = function(id,event){
verifyTimerState = 0;
verifyTimer.enable();
}
thrdHandle,thrdId = thread.create( CanThread ); thrdHandle,thrdId = thread.create( CanThread );
autoconnect.enable();
//console.log(thrdId);
mainForm.show(); mainForm.show();
return win.loopMessage(); return win.loopMessage();

View File

@ -314,6 +314,22 @@ FuncPushPackage = function(ID,data){
} }
disconnected_detect = win.timer(,200);
disconnected_detect.onTimer = function(){
if(CANHw.isConnected() == false){
return ;
}
var ret,DeviceInfo,str = CANHw.GetNowInfo();
if(ret == 0){
thrdTable.设备连接状态 = 0;
//console.log(DeviceInfo);
//console.log(str);
}
}
disconnected_detect.enable();
boottimer = win.timer(,10); boottimer = win.timer(,10);
boottimer.onTimer = function(){ boottimer.onTimer = function(){

View File

@ -44,13 +44,14 @@ FuncDiag22Pro = function(data){
if(data[3] != 0){ if(data[3] != 0){
var str = string.pack(table.slice(data,3,len+3)); var str = string.pack(table.slice(data,3,len+3));
FuncDisplay("软件版本号:" ++ str); FuncDisplay("软件版本号:" ++ str);
FuncDisplay("Software Version:" ++ str++" FuncDisplay("Software Version:" ++ str++'\n');
"); thrdTable.DIDdata = str;
//console.log(str);
//console.dump(thrdTable.DIDdata);
} }
else { else {
FuncDisplay("软件版本号未读到"); FuncDisplay("软件版本号未读到");
FuncDisplay("Software version number not read FuncDisplay('Software version number not read \n');
");
} }
} }
case 0xF198 { case 0xF198 {
@ -68,8 +69,7 @@ FuncDiag22Pro = function(data){
} }
case 0xF18A { case 0xF18A {
FuncDisplay("软件日期:"++string.pack(table.slice(data,3))); FuncDisplay("软件日期:"++string.pack(table.slice(data,3)));
FuncDisplay("Software date:"++string.pack(table.slice(data,3))++" FuncDisplay("Software date:"++string.pack(table.slice(data,3))++'\n');
");
} }
case 0xF197 { case 0xF197 {

View File

@ -209,7 +209,7 @@ FuncSendBlockFlashDriver = function(){
} }
} }
} }
var err_version = 0;
var delaycount = 0; var delaycount = 0;
//boot总流程 //boot总流程
var boottime = 0; var boottime = 0;
@ -218,6 +218,7 @@ FuncBootSeq = function(){
select(bootstate) { select(bootstate) {
case 0 { case 0 {
boottime = 1; boottime = 1;
err_version = 0;
nextstate(0); nextstate(0);
delaycount = 0; delaycount = 0;
if(DiagReqID == 0x720){ if(DiagReqID == 0x720){
@ -280,6 +281,26 @@ FuncBootSeq = function(){
} }
} }
case 3 { case 3 {
//FuncDisplay('step3:');
//FuncDisplay(thrdTable.DIDdata);
if(thrdTable.DIDdata != null){
if(string.cmp(thrdTable.DIDdata,"SW0302",6) == 0){
err_version = 0;
}
else {
err_version = 1;
}
}
else {
err_version = 1;
}
if(err_version == 1){
FuncDisplay("版本号错误");
FuncDisplay('wrong version \n');
boottimer.disable();
thread.command.$SendEnd(false);
}
nextstate(0); nextstate(0);
/* /*
if(sendstate == 0){ if(sendstate == 0){