can_bootloader/main.aardio

252 lines
7.5 KiB
Plaintext
Raw Permalink Normal View History

2022-05-14 15:57:52 +08:00
import win.ui;
/*DSG{{*/
2022-09-19 23:28:05 +08:00
mainForm = win.form(text="CAN_Bootloader";right=599;bottom=465;border="dialog frame";max=false)
2022-05-14 15:57:52 +08:00
mainForm.add(
btnConnect={cls="button";text="连接";left=204;top=64;right=289;bottom=90;z=4};
2022-10-13 16:47:51 +08:00
btnDiag={cls="button";text="诊断";left=149;top=350;right=248;bottom=375;z=25};
btnFlash={cls="button";text="开始刷写";left=37;top=315;right=136;bottom=343;z=9};
2022-05-14 15:57:52 +08:00
btnFresh={cls="button";text="刷新";left=204;top=28;right=288;bottom=54;z=2};
2022-10-13 16:47:51 +08:00
btnOpen={cls="button";text="打开文件";left=37;top=282;right=136;bottom=310;z=8};
btnOpenFlashdrv={cls="button";text="打开FlashDriver";left=149;top=282;right=248;bottom=310;z=24};
btnReadF186={cls="button";text="读取当前会话";left=37;top=349;right=136;bottom=377;z=13};
btnReadF198={cls="button";text="读取F198";left=37;top=415;right=136;bottom=443;z=19};
btnReadF199={cls="button";text="读取F199";left=149;top=415;right=248;bottom=443;z=20};
btnReadHw={cls="button";text="读取硬件版本号";left=149;top=381;right=248;bottom=409;z=12};
btnReadSw={cls="button";text="读取软件版本号";left=37;top=382;right=136;bottom=410;z=10};
btnTest={cls="button";text="停止";left=149;top=316;right=248;bottom=344;z=11};
2022-05-14 15:57:52 +08:00
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};
2024-03-04 10:03:50 +08:00
checkbox={cls="checkbox";text="CANFD设备";left=151;top=101;right=248;bottom=120;checked=1;z=21};
2022-05-18 10:43:03 +08:00
edFile={cls="richedit";left=8;top=131;right=288;bottom=187;border=1;disabled=1;edge=1;multiline=1;wrap=1;z=14};
2022-09-19 23:28:05 +08:00
edFile2={cls="richedit";left=8;top=213;right=288;bottom=269;border=1;disabled=1;edge=1;multiline=1;wrap=1;z=22};
edit={cls="edit";left=294;top=19;right=596;bottom=401;autovscroll=false;edge=1;multiline=1;vscroll=1;z=5};
progress={cls="progress";left=296;top=436;right=596;bottom=464;edge=1;max=100;min=0;z=15};
2022-05-14 15:57:52 +08:00
static={cls="static";text="设备";left=1;top=28;right=61;bottom=52;align="center";center=1;transparent=1;z=6};
2022-05-18 10:43:03 +08:00
static2={cls="static";text="通道";left=1;top=66;right=61;bottom=90;align="center";center=1;transparent=1;z=7};
2022-09-19 23:28:05 +08:00
static3={cls="static";text="刷写进度";left=296;top=409;right=349;bottom=429;transparent=1;z=16};
2022-05-18 10:43:03 +08:00
static4={cls="static";text="烧录APP";left=13;top=108;right=85;bottom=132;center=1;transparent=1;z=17};
2022-09-19 23:28:05 +08:00
static5={cls="static";text="V0.1_20220518";left=451;top=1;right=595;bottom=17;align="right";center=1;transparent=1;z=18};
static6={cls="static";text="FlashDriver";left=13;top=195;right=101;bottom=218;transparent=1;z=23}
2022-05-14 15:57:52 +08:00
)
/*}}*/
import win;
import usb2canfd;
2022-05-18 10:43:03 +08:00
import win.timer;
2022-05-18 14:06:44 +08:00
var boot_count = 0;//boot时间计数器
var bootstate = false;//boot状态标志
2022-10-05 09:17:27 +08:00
var starttime = time.now();
2022-05-18 10:43:03 +08:00
timer_bootcount = win.timer(mainForm,100);
2022-05-18 14:06:44 +08:00
timer_bootcount.onTimer = function(){//boot时间定时器100ms间隔
2022-05-18 10:43:03 +08:00
boot_count++;
}
2022-05-14 15:57:52 +08:00
2022-05-18 14:06:44 +08:00
Display = function(str){//显示日志
2023-02-28 20:45:28 +08:00
var nowtime = time();
nowtime.format="%H:%M:%S";
mainForm.edit.print(tostring(nowtime) + " " + str);
2022-05-14 15:57:52 +08:00
}
2022-09-19 23:28:05 +08:00
//遍历目录
import console;
2022-09-30 16:32:52 +08:00
/*
2022-09-19 23:28:05 +08:00
import fsys.fileInfo;
info = fsys.fileInfo("C:\Users\fcb19\Desktop\dll\libusb-1.0.dll");
console.log(info.writeTime);
execute("pause")
raw.loadDll("C:\Users\fcb19\Desktop\dll\libusb-1.0.dll");
2022-09-30 16:32:52 +08:00
*/
2022-05-18 14:06:44 +08:00
CANHw = usb2canfd.USB2CANHW();//尝试加载CAN dll
2022-05-14 15:57:52 +08:00
var ret = CANHw.LoadDll();
if(ret == 0){
Display("DLL加载成功");
}
2022-09-30 16:32:52 +08:00
else {
Display("DLL加载失败");
}
2022-05-14 15:57:52 +08:00
2022-05-18 14:06:44 +08:00
//初始化界面
2022-05-14 15:57:52 +08:00
mainForm.cbbChannel.add("通道1");
mainForm.cbbChannel.add("通道2");
mainForm.cbbChannel.selIndex = 1
2022-05-18 14:06:44 +08:00
//刷新按键
2022-05-14 15:57:52 +08:00
mainForm.btnFresh.oncommand = function(id,event){
2022-05-18 14:06:44 +08:00
mainForm.cbbDev.clear();//清空下拉框,防止反复刷新叠加
var hwnum = CANHw.FlashHw();//获取硬件数量
2022-05-14 15:57:52 +08:00
if(hwnum == 0){
mainForm.cbbDev.text = "未找到硬件"
}
else {
var allhw = CANHw.GetAvailableHW();
for(i=1;#allhw;1){
mainForm.cbbDev.add(allhw[i].name);
}
}
mainForm.cbbDev.selIndex = 1
::PostThreadMessage(thrdId,100,0,0)//自定义消息
}
mainForm.btnConnect.oncommand = function(id,event){
2022-09-30 16:32:52 +08:00
var canfd_check = mainForm.checkbox.checked?0x80:0x00;
::PostThreadMessage(thrdId,101,mainForm.cbbDev.selIndex,(mainForm.cbbChannel.selIndex - 1)|canfd_check)//自定义消息
2022-05-14 15:57:52 +08:00
/*
var ret = CANHw.OpenDevice(mainForm.cbbDev.selIndex,mainForm.cbbChannel.selIndex - 1);//通道为0和1
if(ret == 0){
Display("连接成功");
}
else {
Display("连接失败");
}
*/
}
//CAN通讯线程
import thread.command;
var listener = thread.command();
2022-05-18 10:43:03 +08:00
var flag_connected=0;
2022-05-14 15:57:52 +08:00
listener.$Display = function(str){
Display(str);
}
2022-05-17 16:34:44 +08:00
listener.$ShowPath = function(str){
mainForm.edFile.text = str;
}
2022-10-04 16:01:27 +08:00
listener.$ShowFlashDrvPath = function(str){
mainForm.edFile2.text = str;
}
2022-05-18 10:43:03 +08:00
listener.$SetProgress = function(pos){
if(pos >= 0 && pos <= 100){
mainForm.progress.pos = pos;
}
}
listener.$Connected = function(){
mainForm.btnConnect.disabled = true;
mainForm.btnFresh.disabled = true;
mainForm.cbbDev.disabled = true;
mainForm.cbbChannel.disabled = true;
flag_connected = 1;
}
listener.$SendEnd = function(isSuccess){
2022-10-05 09:17:27 +08:00
//timer_bootcount.disable();
var usetime = time.now().diffsecond(starttime);
2022-05-18 14:06:44 +08:00
bootstate = false;
2022-05-18 10:43:03 +08:00
if(isSuccess == true){
2022-10-05 09:17:27 +08:00
Display("刷写成功,用时 " + usetime + " S")
2022-05-18 10:43:03 +08:00
}
}
2022-05-14 15:57:52 +08:00
//线程函数
var CanThread = function(){
//线程函数内部要添加自已的import语句
import win;
import console;
2022-10-05 09:17:27 +08:00
//console.log("线程开始运行")
2022-05-14 15:57:52 +08:00
loadcodex("\user\CanThread.aardio");//加载线程程序
//在子线程启动消息循环
win.loopMessage(FuncLoopMsg)
}
2022-10-13 16:47:51 +08:00
DiagReadDID = function(did){
2022-05-14 15:57:52 +08:00
::PostThreadMessage(thrdId,110,did,0)//自定义消息
}
var Diag10Req = function(num){
::PostThreadMessage(thrdId,111,num,0)//自定义消息
}
2022-05-14 17:00:49 +08:00
var DiagBootReq = function(){
::PostThreadMessage(thrdId,102,0,0)//自定义消息
}
var DiagStopReq = function(){
::PostThreadMessage(thrdId,103,0,0)//自定义消息
}
2022-05-14 15:57:52 +08:00
mainForm.btnReadSw.oncommand = function(id,event){
2024-03-04 10:03:50 +08:00
DiagReadDID(0xF195);
2022-05-14 15:57:52 +08:00
}
mainForm.btnReadHw.oncommand = function(id,event){
2024-03-04 10:03:50 +08:00
DiagReadDID(0xF193);
2022-05-14 15:57:52 +08:00
}
mainForm.btnReadF186.oncommand = function(id,event){
DiagReadDID(0xF186);
}
mainForm.btnTest.oncommand = function(id,event){
2022-05-14 17:00:49 +08:00
DiagStopReq();
}
mainForm.btnFlash.oncommand = function(id,event){
2022-05-18 10:43:03 +08:00
if(io.exist(mainForm.edFile.text) == null){
2023-03-09 11:24:02 +08:00
Display("请打开烧写文件");
return;
}
if(io.exist(mainForm.edFile2.text) == null){
Display("请打开flashdriver文件");
2022-05-18 10:43:03 +08:00
return;
}
if(flag_connected == 0){
Display("请连接设备");
return;
}
2022-05-18 14:06:44 +08:00
if(bootstate == true){
return ;
}
bootstate = true;
2022-05-18 10:43:03 +08:00
mainForm.edit.text = "";
Display("开始刷写流程");
2022-10-10 08:19:50 +08:00
starttime = time.now();
2022-10-05 09:17:27 +08:00
//timer_bootcount.enable();
2022-05-18 10:43:03 +08:00
boot_count = 0;
2022-05-14 17:00:49 +08:00
DiagBootReq();
2022-05-18 10:43:03 +08:00
2022-05-14 15:57:52 +08:00
}
2022-05-17 16:34:44 +08:00
mainForm.btnOpen.oncommand = function(id,event){
2022-10-04 16:01:27 +08:00
::PostThreadMessage(thrdId,104,1,0)//自定义消息-打开文件
2022-05-17 16:34:44 +08:00
}
2022-05-18 14:06:44 +08:00
//程序关闭
mainForm.onClose = function(hwnd,message,wParam,lParam){
2022-09-19 23:28:05 +08:00
if(thrdId != null){
::PostThreadMessage(thrdId,105,0,0)//自定义消息
thread.waitClose(thrdHandle);
}
2022-05-18 14:06:44 +08:00
//PLinHw.isConnected()///待完善
//console.print("线程已关闭")
//console.pause()
}
mainForm.btnReadF198.oncommand = function(id,event){
2022-09-19 23:28:05 +08:00
DiagReadDID(0x1701);
2022-05-18 14:06:44 +08:00
}
mainForm.btnReadF199.oncommand = function(id,event){
2022-09-19 23:28:05 +08:00
DiagReadDID(0x1702);
2022-05-18 14:06:44 +08:00
}
2022-10-04 16:01:27 +08:00
mainForm.btnOpenFlashdrv.oncommand = function(id,event){
::PostThreadMessage(thrdId,104,0,0)//自定义消息-打开flashdriver
}
2022-10-13 16:47:51 +08:00
var frmChild = win.loadForm("\dlg\诊断子窗口.aardio");
frmChild.show(false);
2022-10-12 17:01:37 +08:00
mainForm.btnDiag.oncommand = function(id,event){
2022-10-13 16:47:51 +08:00
frmChild.show();
2022-10-12 17:01:37 +08:00
}
2022-09-30 16:32:52 +08:00
thrdHandle,thrdId = thread.create( CanThread )
2022-05-14 15:57:52 +08:00
mainForm.show();
return win.loopMessage();