修复一些BUG

This commit is contained in:
sunbeam 2022-05-18 14:06:44 +08:00
parent 2a5370e6e8
commit 534bebb6b7
7 changed files with 60 additions and 40 deletions

View File

@ -116,7 +116,7 @@ namespace usb2canfd{
//刷新硬件
FlashHw = function(){
import console;
if(DllHandle = null){
//DLL为空返回
AvailableHW = {}
@ -198,7 +198,6 @@ namespace usb2canfd{
//关闭设备
CloseDevice = function(){
//console.print("-----------------CloseDevice ---------")
if(Hwconnected == null){
return;
}

View File

@ -3,13 +3,15 @@ import win.ui;
mainForm = win.form(text="CAN_Bootloader";right=599;bottom=399;border="dialog frame";max=false)
mainForm.add(
btnConnect={cls="button";text="连接";left=204;top=64;right=289;bottom=90;z=4};
btnFlash={cls="button";text="开始刷写";left=147;top=198;right=246;bottom=226;z=9};
btnFlash={cls="button";text="开始刷写";left=148;top=197;right=247;bottom=225;z=9};
btnFresh={cls="button";text="刷新";left=204;top=28;right=288;bottom=54;z=2};
btnOpen={cls="button";text="打开文件";left=32;top=197;right=131;bottom=225;z=8};
btnReadF186={cls="button";text="读取当前会话";left=32;top=236;right=131;bottom=264;z=13};
btnReadHw={cls="button";text="读取硬件版本号";left=147;top=276;right=246;bottom=304;z=12};
btnReadSw={cls="button";text="读取软件版本号";left=32;top=276;right=131;bottom=304;z=10};
btnTest={cls="button";text="停止";left=147;top=237;right=246;bottom=265;z=11};
btnReadF186={cls="button";text="读取当前会话";left=33;top=228;right=132;bottom=256;z=13};
btnReadF198={cls="button";text="读取F198";left=33;top=291;right=132;bottom=319;z=19};
btnReadF199={cls="button";text="读取F199";left=148;top=291;right=247;bottom=319;z=20};
btnReadHw={cls="button";text="读取硬件版本号";left=148;top=261;right=247;bottom=289;z=12};
btnReadSw={cls="button";text="读取软件版本号";left=33;top=260;right=132;bottom=288;z=10};
btnTest={cls="button";text="停止";left=148;top=229;right=247;bottom=257;z=11};
cbbChannel={cls="combobox";left=58;top=64;right=191;bottom=90;edge=1;items={};mode="dropdown";z=3};
cbbDev={cls="combobox";left=58;top=27;right=191;bottom=53;edge=1;items={};mode="dropdown";z=1};
edFile={cls="richedit";left=8;top=131;right=288;bottom=187;border=1;disabled=1;edge=1;multiline=1;wrap=1;z=14};
@ -27,33 +29,34 @@ import win;
import usb2canfd;
import win.timer;
var boot_count = 0;
var boot_count = 0;//boot时间计数器
var bootstate = false;//boot状态标志
timer_bootcount = win.timer(mainForm,100);
timer_bootcount.onTimer = function(){
timer_bootcount.onTimer = function(){//boot时间定时器100ms间隔
boot_count++;
}
Display = function(str){
Display = function(str){//显示日志
mainForm.edit.print(tostring(time()) + " " + str);
}
mainForm.edFile.wrap = true;
CANHw = usb2canfd.USB2CANHW();
CANHw = usb2canfd.USB2CANHW();//尝试加载CAN dll
var ret = CANHw.LoadDll();
if(ret == 0){
Display("DLL加载成功");
}
//初始化界面
mainForm.cbbChannel.add("通道1");
mainForm.cbbChannel.add("通道2");
mainForm.cbbChannel.selIndex = 1
//刷新按键
mainForm.btnFresh.oncommand = function(id,event){
mainForm.cbbDev.clear();
var hwnum = CANHw.FlashHw();
mainForm.cbbDev.clear();//清空下拉框,防止反复刷新叠加
var hwnum = CANHw.FlashHw();//获取硬件数量
if(hwnum == 0){
mainForm.cbbDev.text = "未找到硬件"
}
@ -105,6 +108,7 @@ listener.$Connected = function(){
}
listener.$SendEnd = function(isSuccess){
timer_bootcount.disable();
bootstate = false;
if(isSuccess == true){
Display("刷写成功,用时 " + boot_count/10 + " S")
}
@ -160,6 +164,10 @@ mainForm.btnFlash.oncommand = function(id,event){
Display("请连接设备");
return;
}
if(bootstate == true){
return ;
}
bootstate = true;
mainForm.edit.text = "";
Display("开始刷写流程");
timer_bootcount.enable();
@ -173,6 +181,24 @@ mainForm.btnOpen.oncommand = function(id,event){
::PostThreadMessage(thrdId,104,0,0)//自定义消息-打开文件
}
//程序关闭
mainForm.onClose = function(hwnd,message,wParam,lParam){
::PostThreadMessage(thrdId,105,0,0)//自定义消息
thread.waitClose(thrdHandle);
//PLinHw.isConnected()///待完善
//console.print("线程已关闭")
//console.pause()
}
mainForm.btnReadF198.oncommand = function(id,event){
DiagReadDID(0xF198);
}
mainForm.btnReadF199.oncommand = function(id,event){
DiagReadDID(0xF199);
}
thrdHandle,thrdId = thread.create( CanThread )

BIN
res/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View File

@ -11,8 +11,6 @@ DiagGloableID = 0x18DB33F1;
stopflag = 0;
//注册一个消息钩子函数
FuncLoopMsg = function(msg){
//console.log( "收到消息",msg.message );
//console.dumpJson(msg);
select(msg.message) {
case 100 {//刷新硬件
FuncFreshHw();
@ -33,6 +31,9 @@ FuncLoopMsg = function(msg){
thread.command.$ShowPath(ret);
}
}
case 105 {//停止boot
thread.stop(0);
}
case 110 {//readDID
FuncReadDID(msg.wParam);
}
@ -103,8 +104,7 @@ loadcodex("\user\S19Decode.aardio");
RespState = 0;
FuncDiagPro = function(diagmsg){
//console.log("诊断服务")
//console.dumpJson(diagmsg);
select(diagmsg.sid) {
case 0x50 {
FuncDiag10Pro(table.slice(diagmsg.data,1,diagmsg.len))
@ -153,22 +153,23 @@ FuncStartBoot = function(){
boottimer.enable();
FuncDisplay("开始刷写");
stopflag = 0;
}
var PackNext = 0x21;
var Packdata = {};
var PackID = 0;
FuncSendPackage = function(){
var FuncSendPackage = function(){
while(#Packdata > 0)
{
sleep(0.3);
var data = {PackNext,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC};
var max = #Packdata > 7 ? 7 : #Packdata;
for(i=1;max;1){
data[i+1] = table.remove(Packdata);
}
CANHw.SendMsg(PackID,data);
sleep(0.3);
PackNext += 1;
if(PackNext > 0x2f){
PackNext = 0x20;
@ -213,7 +214,7 @@ timer1.onTimer = function(){
diagresp["next"] = 0x21;
table.append(diagresp["data"],table.slice(ret[i].data,4));
}
elseif(ret[i].data[1] <= 0x06){//单帧
elseif(ret[i].data[1] <= 0x07){//单帧
//console.dumpJson()
diagresp["sid"] = ret[i].data[2];
diagresp["len"] = ret[i].data[1]-1;

View File

@ -25,13 +25,20 @@ FuncDiag22Pro = function(data){
FuncDisplay("软件版本号");
FuncDisplay(string.pack(table.slice(data,3)));
}
case 0xF198 {
FuncDisplay("repair_shopcode");
FuncDisplay(string.pack(table.slice(data,3)));
}
case 0xF199 {
FuncDisplay("installation_date");
FuncDisplay(string.format("%x%X%x%x",data[3],data[4],data[5],data[6]));
}
case 0xF186 {
FuncDisplay("当前会话: " + tostring(data[3]));
}
case !=0 {
}
else {
FuncDisplay("未知DID - " + did);
}
}

View File

@ -31,7 +31,7 @@ FuncWait = function(sid){
}
bootcount += 1;
if(bootcount >= 400){
FuncDisplay("超时 " + tostring(sid,16));
FuncDisplay("步骤" + bootstate + "超时 " + tostring(sid,16));
thread.command.$SendEnd(false);
boottimer.disable();
return 3;//超时
@ -259,7 +259,7 @@ FuncBootSeq = function(){
case 9 {
if(sendstate == 0){
FuncClearState();
FuncDIDWriteStr(0xf198,"0123456789abcdef1234");//写入repair_shopcode
FuncDIDWriteStr(0xf198,"Daming_CANBootload ");//写入repair_shopcode
}
else {

View File

@ -1,4 +1,3 @@
import console;
var g_aes128_cbc_mask =
@ -236,14 +235,9 @@ AES128_CBC_XTIME = function(x){
showtab = function(tab,name){
console.log(name);
var str = name + " = ";
for(k,v in tab){
//console.log(tostring(v,16));
//str += tostring(v,16);
//str += " "
str = string.format("[%d] = %x",k,v );
console.log(str);
}
//console.log(str);
}
@ -272,10 +266,3 @@ GenerateKeyEx = function(seed,level){
//console.log("l_id = " + l_id)
}
/*
var ret = GenerateKeyEx({0xff,0xff,0xff,0xff},0x01);
console.log("结果")
showtab(ret,"key");
console.pause(true);
*/