📄 umain.pas
字号:
begin
frmAbout.imgAVRUBDMouseDown(Sender, mbLeft, [ssLeft, ssShift], 0, 0);
end;
if Shift = [ssAlt, ssShift] then
begin
if CompareText(cfg.Language, 'Chinese') = 0 then
begin
mmoHex.Text := #13#10 + tipcn[Random(MAXTIPCN)];
end
else
begin
mmoHex.Text := #13#10 + tipen[Random(MAXTIPEN)];
end;
end;
end;
VK_SCROLL: //reload default value
begin
if Shift = [ssAlt] then
begin
if DeleteFile(ExtractFilePath(Application.ExeName) + 'avrubd.ini') then
loadcfg;
end;
end;
Ord('A'):
if Shift = [ssAlt] then
btnAboutClick(Sender);
end;
end;
procedure TfrmMain.mnMCUClick(Sender: TObject);
begin
HWD := frmOption.Handle;
frmOption.pgctOption.ActivePageIndex := 0;
btnOptionClick(Sender);
HWD := frmMain.Handle;
end;
procedure TfrmMain.mnSystemClick(Sender: TObject);
begin
HWD := frmOption.Handle;
frmOption.pgctOption.ActivePageIndex := 1;
btnOptionClick(Sender);
HWD := frmMain.Handle;
end;
procedure TfrmMain.mnComPortSetupClick(Sender: TObject);
begin
HWD := frmOption.Handle;
frmOption.pgctOption.ActivePageIndex := 2;
btnOptionClick(Sender);
HWD := frmMain.Handle;
end;
procedure TfrmMain.mnContentClick(Sender: TObject);
var
hlp: string;
begin
hlp := ExtractFilePath(Application.ExeName) + cfg.Language + '.hlp';
if not FileExists(hlp) then
begin
hlp := ExtractFilePath(Application.ExeName) + 'English.hlp';
if not FileExists(hlp) then
Exit;
end;
Application.HelpFile := hlp;
Application.HelpCommand(HELP_CONTENTS, 0);
end;
procedure TfrmMain.pmLangEnglishClick(Sender: TObject);
begin
if Sender is TMenuItem then
begin
cfg.Language := TMenuItem(Sender).Caption;
loadlanguage(cfg.Language);
end;
end;
procedure TfrmMain.HisFileClick(Sender: TObject);
var
FileName: string;
begin
FileName := pmHisFile.Items[TMenuItem(Sender).MenuIndex].Caption;
if FileExists(FileName) then
begin
OpenFile(FileName);
dlgOpen.FileName := FileName;
end;
end;
procedure TfrmMain.tmrSmartMouseTimer(Sender: TObject);
var
mousekey: Byte;
rect: TRect;
begin
GetCursorPos(mp);
if (Abs(msx - mp.X) > 2) or (Abs(msy - mp.Y) > 2) then
begin
msx := mp.X;
msy := mp.Y;
tmrSmartMouse.Tag := 990 div tmrSmartMouse.Interval;
Exit;
end;
if tmrSmartMouse.Tag > 0 then
tmrSmartMouse.Tag := tmrSmartMouse.Tag - 1;
//get mouse status
mousekey := 0;
if (GetKeyState(VK_LBUTTON) and $80) = $80 then
mousekey := mousekey or $01;
if (GetKeyState(VK_RBUTTON) and $80) = $80 then
mousekey := mousekey or $02;
if (GetKeyState(VK_MBUTTON) and $80) = $80 then
mousekey := mousekey or $04;
//No mouse button pressed
if mousekey <> 0 then
tmrSmartMouse.Tag := 0;
if tmrSmartMouse.Tag = 1 then
begin
//If active window is used form
if GetForegroundWindow <> HWD then
Exit;
//Get form size
GetWindowRect(HWD, rect);
if (msx < rect.Left) or (msx > rect.Right) or (msy < rect.Top) or (msy > rect.Bottom) then
Exit;
mouse_event(MOUSEEVENTF_LEFTDOWN or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
end;
end;
procedure TfrmMain.tmrClockTimer(Sender: TObject);
begin
tmrClock.Tag := tmrClock.Tag + 1;
if tmrClock.Tag > 4 then
begin
tmrClock.Tag := 0;
ClockCnt := ClockCnt + 1;
if (not Debug) and (ClockCnt > 4) then
ClockCnt := 0;
end;
case ClockCnt of
1: //Date
stat.Panels[1].Text := FormatDateTime('hh:nn:ss', Now - TS);
2: //elapse time
stat.Panels[1].Text := FormatDateTime('yyyy-mmm-dd', Now);
3: //Down counter
stat.Panels[1].Text := Format('%d/%d, %d/%d', [StaSum.sum - StaSum.fail, StaSum.sum, StaToday.sum - StaToday.fail, StaToday.sum]);
4: //version
stat.Panels[1].Text := 'AVRUBD v3.1';
5: //run counter
stat.Panels[1].Text := IntToStr(cfg.run);
6: //comport configure
stat.Panels[1].Text := ComPort.Port + ',' + BaudRateToStr(ComPort.BaudRate) + ',' + DataBitsToStr(ComPort.DataBits) + ',' + StopBitsToStr(ComPort.StopBits);
7: //Font
stat.Panels[1].Text := cfg.FontName + ',' + IntToStr(cfg.FontSize);
8: //Language
stat.Panels[1].Text := cfg.Language;
else
//Time
stat.Panels[1].Text := FormatDateTime('hh:nn:ss', Now);
ClockCnt := 0;
end;
end;
//click panel[1] will change to next status
procedure TfrmMain.statMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if X > (stat.Panels[0].Width + 1 + 2 + 1) then
begin
if Button = mbLeft then
ClockCnt := ClockCnt + 1;
if Button = mbRight then
begin
ClockCnt := ClockCnt - 1;
end;
if Debug then
begin
if ClockCnt > 8 then
ClockCnt := 0;
if ClockCnt < 0 then
ClockCnt := 8;
end
else
begin
if ClockCnt > 4 then
ClockCnt := 0;
if ClockCnt < 0 then
ClockCnt := 4;
end;
if Button = mbMiddle then
tmrClock.Tag := -2147483647
else
tmrClock.Tag := -5;
tmrClockTimer(Sender);
end
else
tbMenuMouseDown(Sender, Button, Shift, X, Y);
end;
procedure TfrmMain.OpenFile(FileName: string);
var
i, j: Integer;
addr, len, seg: Integer;
jy: Byte;
s: string;
hf: TMenuItem;
stream: TMemoryStream;
buf: CBuf;
aub: TFastIniFile;
begin
//avoid reload
mmoBin.Tag := 12;
//Disable download function
btnDownload.Enabled := False;
mnDownLoad.Enabled := False;
DataSize := 0;
seg := 0; //HEX's segment, when data size > 64K
//fill buffer with config value
if cfg.fillunused then
begin
FormatHexStr(cfg.filldata, buf);
len := (Length(cfg.filldata) + 2) div 3;
for i := 0 to 1024 * 1024 - 1 do
begin
DataBuf[i] := buf[i mod len];
end;
end
else
begin
for i := 0 to 1024 * 1024 - 1 do
DataBuf[i] := $FF;
end;
mmoHex.Clear;
mmoBin.DataSize := 0;
stream := TMemoryStream.Create;
try
if CompareText('.aub', ExtractFileExt(FileName)) = 0 then
begin
aub := TFastIniFile.Create(FileName);
try
s := aub.ReadString('target', 'id', '');
if s <> 'aub' then
begin
Application.MessageBox(PChar(lang.msgFmtErr + ': [ ' + FileName + ' ]'), PChar(lang.msgError), MB_OK + MB_ICONSTOP);
Exit;
end;
s := aub.ReadString('buf', 'data', '');
DataSize := Length(s) div 2;
for i := 0 to DataSize - 1 do
begin
DataBuf[i] := CharToByte(s[i * 2 + 1], s[i * 2 + 2]);
end;
mmoBin.LoadFromBuffer(DataBuf, DataSize);
cfg.Protocol := aub.ReadInteger('cfg', 'protocol', 0);
cfg.FrameLen := aub.ReadInteger('cfg', 'FrameLen', 128);
cfg.SendTime := aub.ReadInteger('cfg', 'Timeout', 500);
cfg.BootCnt := aub.ReadInteger('cfg', 'BootCnt', 10);
cfg.FlashSize := aub.ReadInteger('cfg', 'FlashSize', 2);
cfg.keyMode := aub.ReadInteger('cfg', 'KeyMode', 1);
cfg.keyASC := aub.ReadString('cfg', 'KeyASC', 'd');
cfg.keyHEX := aub.ReadString('cfg', 'KeyHEX', '64');
cfg.filldata := aub.ReadString('cfg', 'FillData', 'FF CF');
cfg.fillunused := aub.ReadBoolean('cfg', 'Fill', True);
cfg.AutoSize := aub.ReadBoolean('cfg', 'AutoSize', True);
cfg.SendRST := aub.ReadBoolean('cfg', 'SendRST', False);
cfg.CmdRST := aub.ReadString('cfg', 'CmdRST', '7E');
cfg.RTS := aub.ReadBoolean('cfg', 'RTS', False);
cfg.DTR := aub.ReadBoolean('cfg', 'DTR', False);
ComPort.BaudRate := StrToBaudRate(aub.ReadString('cfg', 'BaudRate', '19200'));
ComPort.DataBits := StrToDataBits(aub.ReadString('cfg', 'DataBits', '8'));
ComPort.StopBits := StrToStopBits(aub.ReadString('cfg', 'StopBits', '1'));
ComPort.Parity.Bits := StrToParity(aub.ReadString('cfg', 'Parity', 'None'));
ComPort.FlowControl.FlowControl := StrToFlowControl(aub.ReadString('cfg', 'FlowControl', 'None'));
pgctMain.ActivePage := tsBin;
finally
aub.Free;
end;
end
else
if CompareText('.hex', ExtractFileExt(FileName)) = 0 then
begin
//HEX
mmoHex.Lines.LoadFromFile(FileName);
for i := 0 to mmoHex.Lines.Count - 1 do
begin
s := mmoHex.Lines[i];
if Length(s) = 0 then
continue;
if s[1] <> ':' then
begin
mmoHex.TopLine := i + 1;
Application.MessageBox(PChar(lang.msgLoadFileFail + ': [ ' + FileName + ' ]' + #13#10 + lang.msgLines + ': ' + IntToStr(i + 1)), PChar(lang.msgError), MB_OK + MB_ICONSTOP);
loginfo('');
loginfo('X ' + lang.msgLoadFileFail + ': [ ' + FileName + ' ]');
loginfo('> ' + lang.msgLines + ': ' + IntToStr(i + 1));
Exit;
end;
len := CharToByte(s[2], s[3]);
if Length(s) <> (len * 2 + 11) then
begin
mmoHex.TopLine := i + 1;
Application.MessageBox(PChar(lang.msgLoadFileFail + ': [ ' + FileName + ' ]' + #13#10 + lang.msgLines + ': ' + IntToStr(i + 1)), PChar(lang.msgError + ': ' + lang.msgLength), MB_OK + MB_ICONSTOP);
loginfo('');
loginfo('X ' + lang.msgLoadFileFail + ': [ ' + FileName + ' ]: ' + lang.msgLength);
loginfo('> ' + lang.msgLines + ': ' + IntToStr(i + 1));
Exit;
end;
jy := 0;
for j := 0 to len + 4 do
begin
buf[j] := CharToByte(s[j + j + 2], s[j + j + 3]);
jy := jy + buf[j];
end;
if jy <> 0 then
begin
mmoHex.TopLine := i + 1;
Application.MessageBox(PChar(lang.msgLoadFileFail + ': [ ' + FileName + ' ]' + #13#10 + lang.msgLines + ': ' + IntToStr(i + 1)), PChar(lang.msgError + ': ' + lang.msgChecksum), MB_OK + MB_ICONSTOP);
loginfo('');
loginfo('X ' + lang.msgLoadFileFail + ': [ ' + FileName + ' ]: ' + lang.msgChecksum);
loginfo('> ' + lang.msgLines + ': ' + IntToStr(i + 1));
Exit;
end;
case CharToByte(s[8], s[9]) of
0: //Data
begin
addr := CharToByte(s[4], s[5]) * 256 + CharToByte(s[6], s[7]) + seg;
for j := 0 to len - 1 do
DataBuf[addr + j] := buf[4 + j];
if DataSize < (addr + len) then
DataSize := addr + len;
end;
1: //End
begin
end;
2: //Segment
begin
seg := (CharToByte(s[10], s[11]) * 256 + CharToByte(s[12], s[13])) * (Longword(16));
end;
4: //32bit address
begin
mmoHex.TopLine := i + 1;
Application.MessageBox(PChar(lang.msgLoadFileFail + ': [ ' + FileName + ' ]' + #13#10 + lang.msgLines + ': ' + IntToStr(i + 1)), PChar(lang.msgError + ': ' + lang.msgUnsupport32BitAddress), MB_OK + MB_ICONWARNING);
loginfo('');
loginfo('X ' + lang.msgLoadFileFail + ': [ ' + FileName + ' ]: ' + lang.msgUnsupport32BitAddress);
loginfo('> ' + lang.msgLines + ': ' + IntToStr(i + 1));
Exit;
end;
else //other
end;
end;
mmoBin.LoadFromBuffer(DataBuf, 1024 * 1024);
pgctMain.ActivePage := tsHex;
end
else
begin
//BIN
mmoBin.LoadFromFile(FileName);
DataSize := mmoBin.DataSize;
//fill unused cell
mmoBin.SaveToBuffer(DataBuf, DataSize);
mmoBin.LoadFromBuffer(DataBuf, 1024 * 1024);
stream.Clear;
stream.Seek(0, soFromBeginning);
for i := 0 to ((DataSize + 15) div 16) - 1 do
begin
if (i > 0) and (((i * 16) mod 65536) = 0) then
begin
//segment address
s := ':02000002100000 ';
j := (i * 16 * 16) div 65536;
s[10] := DateToChar(j div 16);
s[11] := DateToChar(j mod 16);
jy := 4 + CharToByte(s[10], s[11]);
jy := -jy;
s[14] := DateToChar(jy div 16);
s[15] := DateToChar(jy mod 16);
s[16] := #13;
s[17] := #10;
stream.WriteBuffer(s[1], 17);
end;
SetLength(s, 45);
s[1] := ':';
s[2] := '1';
s[3] := '0';
jy := (i * 16) div 256;
s[4] := DateToChar(jy div 16);
s[5] := DateToChar(jy mod 16);
jy := (i * 16) mod 256;
s[6] := DateToChar(jy div 16);
s[7] := DateToChar(jy mod 16);
s[8] := '0';
s[9] := '0';
jy := $10 + ((i * 16) div 256) + ((i * 16) mod 256);
//fill data
for j := 0 to 15 do
begin
jy := jy + DataBuf[i * 16 + j];
s[j * 2 + 10] := DateToChar(DataBuf[i * 16 + j] div 16);
s[j * 2 + 11] := DateToChar(DataBuf[i * 16 + j] mod 16);
end;
//calc checksum
jy := -jy;
s[42] := DateToChar(jy div 16);
s[43] := DateToChar(jy mod 16);
s[44] := #13;
s[45] := #10;
stream.WriteBuffer(s[1], 45);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -