Commit a6b8318180277d1beb297d9e1476d70008294514

Authored by xiemeng
1 parent a01030be

检测Rom boot消息, 自动下载

根据下载进度显示不同颜色
防止下载完成之后 自动重新下载
@@ -50,11 +50,11 @@ DWORD WaitForThreads( DWORD ); @@ -50,11 +50,11 @@ DWORD WaitForThreads( DWORD );
50 COMMTIMEOUTS gTimeoutsDefault = { 0x01, 0, 0, 0, 0 }; 50 COMMTIMEOUTS gTimeoutsDefault = { 0x01, 0, 0, 0, 0 };
51 51
52 #ifdef __OPTEK_EDIT__ 52 #ifdef __OPTEK_EDIT__
53 -extern char szFileName[MAX_PATH]; 53 +//extern char szFileName[MAX_PATH];
54 54
55 void oem_init(void) 55 void oem_init(void)
56 { 56 {
57 - memset(szFileName,0,sizeof(szFileName)); 57 + memset(TTYInfo.szFileName,0,sizeof(TTYInfo.szFileName));
58 } 58 }
59 #endif 59 #endif
60 60
@@ -198,7 +198,9 @@ void InitNewFont(LOGFONT LogFont, COLORREF rgbColor) @@ -198,7 +198,9 @@ void InitNewFont(LOGFONT LogFont, COLORREF rgbColor)
198 LFTTYFONT(TTYInfo) = LogFont; 198 LFTTYFONT(TTYInfo) = LogFont;
199 HTTYFONT(TTYInfo) = CreateFontIndirect(&(LFTTYFONT(TTYInfo))); 199 HTTYFONT(TTYInfo) = CreateFontIndirect(&(LFTTYFONT(TTYInfo)));
200 FGCOLOR(TTYInfo) = rgbColor; 200 FGCOLOR(TTYInfo) = rgbColor;
201 - 201 +#ifdef __TOPWELL_EDIT__
  202 + TTYInfo.rgbBGColor = RGB(255,255,255);
  203 +#endif
202 hDC = GetDC( ghwndMain ) ; 204 hDC = GetDC( ghwndMain ) ;
203 SelectObject( hDC, HTTYFONT( TTYInfo ) ) ; 205 SelectObject( hDC, HTTYFONT( TTYInfo ) ) ;
204 GetTextMetrics( hDC, &tm ) ; 206 GetTextMetrics( hDC, &tm ) ;
@@ -317,7 +319,10 @@ BOOL InitTTYInfo() @@ -317,7 +319,10 @@ BOOL InitTTYInfo()
317 LFTTYFONT( TTYInfo ).lfClipPrecision = CLIP_DEFAULT_PRECIS ; 319 LFTTYFONT( TTYInfo ).lfClipPrecision = CLIP_DEFAULT_PRECIS ;
318 LFTTYFONT( TTYInfo ).lfQuality = DEFAULT_QUALITY ; 320 LFTTYFONT( TTYInfo ).lfQuality = DEFAULT_QUALITY ;
319 LFTTYFONT( TTYInfo ).lfPitchAndFamily = FIXED_PITCH | FF_MODERN ; 321 LFTTYFONT( TTYInfo ).lfPitchAndFamily = FIXED_PITCH | FF_MODERN ;
320 - strcpy( LFTTYFONT( TTYInfo ).lfFaceName, "FixedSys" ) ; 322 +#ifdef __TOPWELL_EDIT__
  323 + TTYInfo.DownloadReday = FALSE;
  324 +#endif
  325 + strcpy( LFTTYFONT( TTYInfo ).lfFaceName, "FixedSys" ) ;
321 326
322 InitNewFont( LFTTYFONT(TTYInfo), RGB(0,0,0)); 327 InitNewFont( LFTTYFONT(TTYInfo), RGB(0,0,0));
323 328
@@ -47,7 +47,7 @@ BOOL VersionCheck(); @@ -47,7 +47,7 @@ BOOL VersionCheck();
47 BOOL PaintTTY( HWND ); 47 BOOL PaintTTY( HWND );
48 48
49 #ifdef __OPTEK_EDIT__ 49 #ifdef __OPTEK_EDIT__
50 -char szFileName[MAX_PATH]; 50 +//char szFileName[MAX_PATH];
51 #endif 51 #endif
52 /*----------------------------------------------------------------------------- 52 /*-----------------------------------------------------------------------------
53 53
@@ -390,7 +390,7 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam) @@ -390,7 +390,7 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam)
390 ofn.lStructSize = sizeof(OPENFILENAME); 390 ofn.lStructSize = sizeof(OPENFILENAME);
391 ofn.hwndOwner = hwnd; 391 ofn.hwndOwner = hwnd;
392 ofn.lpstrFilter = szFilter; 392 ofn.lpstrFilter = szFilter;
393 - ofn.lpstrFile = szFileName; 393 + ofn.lpstrFile = TTYInfo.szFileName;
394 ofn.nMaxFile = MAX_PATH; 394 ofn.nMaxFile = MAX_PATH;
395 #ifdef __OPTEK_EDIT__ 395 #ifdef __OPTEK_EDIT__
396 ofn.lpstrTitle = "Select file"; 396 ofn.lpstrTitle = "Select file";
@@ -403,10 +403,10 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam) @@ -403,10 +403,10 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam)
403 break; 403 break;
404 404
405 #ifdef __OPTEK_EDIT__ 405 #ifdef __OPTEK_EDIT__
406 - UpdateStatus(szFileName); 406 + UpdateStatus(TTYInfo.szFileName);
407 #else 407 #else
408 if (TRUE) 408 if (TRUE)
409 - TransferFileTextStart(szFileName); 409 + TransferFileTextStart(TTYInfo.szFileName);
410 #endif 410 #endif
411 } 411 }
412 break; 412 break;
@@ -419,7 +419,7 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam) @@ -419,7 +419,7 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam)
419 ofn.lStructSize = sizeof(OPENFILENAME); 419 ofn.lStructSize = sizeof(OPENFILENAME);
420 ofn.hwndOwner = hwnd; 420 ofn.hwndOwner = hwnd;
421 ofn.lpstrFilter = szFilter; 421 ofn.lpstrFilter = szFilter;
422 - ofn.lpstrFile = szFileName; 422 + ofn.lpstrFile = TTYInfo.szFileName;
423 ofn.nMaxFile = MAX_PATH; 423 ofn.nMaxFile = MAX_PATH;
424 ofn.lpstrTitle = "Receive File"; 424 ofn.lpstrTitle = "Receive File";
425 ofn.Flags = OFN_OVERWRITEPROMPT; 425 ofn.Flags = OFN_OVERWRITEPROMPT;
@@ -427,7 +427,7 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam) @@ -427,7 +427,7 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam)
427 if (!GetSaveFileName(&ofn)) 427 if (!GetSaveFileName(&ofn))
428 break; 428 break;
429 429
430 - ReceiveFileText(szFileName); 430 + ReceiveFileText(TTYInfo.szFileName);
431 } 431 }
432 break; 432 break;
433 433
@@ -458,7 +458,7 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam) @@ -458,7 +458,7 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam)
458 ofn.lStructSize = sizeof(OPENFILENAME); 458 ofn.lStructSize = sizeof(OPENFILENAME);
459 ofn.hwndOwner = hwnd; 459 ofn.hwndOwner = hwnd;
460 ofn.lpstrFilter = szFilter; 460 ofn.lpstrFilter = szFilter;
461 - ofn.lpstrFile = szFileName; 461 + ofn.lpstrFile = TTYInfo.szFileName;
462 ofn.nMaxFile = MAX_PATH; 462 ofn.nMaxFile = MAX_PATH;
463 ofn.lpstrTitle = "Send File Repeatedly"; 463 ofn.lpstrTitle = "Send File Repeatedly";
464 ofn.Flags = OFN_FILEMUSTEXIST; 464 ofn.Flags = OFN_FILEMUSTEXIST;
@@ -468,7 +468,7 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam) @@ -468,7 +468,7 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam)
468 468
469 dwFreq = GetAFrequency(); 469 dwFreq = GetAFrequency();
470 470
471 - TransferRepeatCreate(szFileName, dwFreq); 471 + TransferRepeatCreate(TTYInfo.szFileName, dwFreq);
472 } 472 }
473 break; 473 break;
474 474
@@ -727,7 +727,11 @@ BOOL NEAR PaintTTY( HWND hWnd ) @@ -727,7 +727,11 @@ BOOL NEAR PaintTTY( HWND hWnd )
727 hDC = BeginPaint( hWnd, &ps ) ; 727 hDC = BeginPaint( hWnd, &ps ) ;
728 hOldFont = SelectObject( hDC, HTTYFONT( TTYInfo ) ) ; 728 hOldFont = SelectObject( hDC, HTTYFONT( TTYInfo ) ) ;
729 SetTextColor( hDC, FGCOLOR( TTYInfo ) ) ; 729 SetTextColor( hDC, FGCOLOR( TTYInfo ) ) ;
  730 +#ifdef __TOPWELL_EDIT__
  731 + SetBkColor( hDC, TTYInfo.rgbBGColor ) ;
  732 +#else
730 SetBkColor( hDC, GetSysColor( COLOR_WINDOW ) ) ; 733 SetBkColor( hDC, GetSysColor( COLOR_WINDOW ) ) ;
  734 +#endif
731 rect = ps.rcPaint ; 735 rect = ps.rcPaint ;
732 nRow = 736 nRow =
733 min( MAXROWS - 1, 737 min( MAXROWS - 1,
@@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
21 #include "resource.h" 21 #include "resource.h"
22 //#include "ttyinfo.h" 22 //#include "ttyinfo.h"
23 #define __OPTEK_EDIT__ 23 #define __OPTEK_EDIT__
  24 +#define __TOPWELL_EDIT__
24 25
25 #ifdef __OPTEK_EDIT__ 26 #ifdef __OPTEK_EDIT__
26 #pragma comment(lib,"comctl32.lib") 27 #pragma comment(lib,"comctl32.lib")
@@ -93,7 +94,12 @@ struct TTYInfoStruct @@ -93,7 +94,12 @@ struct TTYInfoStruct
93 COMMTIMEOUTS timeoutsnew; 94 COMMTIMEOUTS timeoutsnew;
94 int xSize, ySize, xScroll, yScroll, xOffset, yOffset, 95 int xSize, ySize, xScroll, yScroll, xOffset, yOffset,
95 nColumn, nRow, xChar, yChar , nCharPos; 96 nColumn, nRow, xChar, yChar , nCharPos;
96 - 97 +#ifdef __TOPWELL_EDIT__
  98 + DWORD rgbBGColor ;
  99 + BOOL DownloadReday;
  100 + DWORD tickcountFinish; //Íê³ÉÏÂÔØµÄʱ¼ä
  101 + char szFileName[MAX_PATH];
  102 + #endif
97 } TTYInfo; 103 } TTYInfo;
98 104
99 // 105 //
@@ -361,7 +367,7 @@ DWORD GetAFrequency( void ); @@ -361,7 +367,7 @@ DWORD GetAFrequency( void );
361 // Buffer manipulation functions 367 // Buffer manipulation functions
362 // 368 //
363 void OutputABufferToWindow( HWND, char *, DWORD ); 369 void OutputABufferToWindow( HWND, char *, DWORD );
364 -void OutputABuffer( HWND, char *, DWORD ); 370 +void OutputABuffer( HWND, char * );
365 BOOL ClearTTYContents( void ); 371 BOOL ClearTTYContents( void );
366 372
367 // 373 //
@@ -155,7 +155,7 @@ void OutputABufferToFile(HANDLE hFile, char * lpBuf, DWORD dwBufLen) @@ -155,7 +155,7 @@ void OutputABufferToFile(HANDLE hFile, char * lpBuf, DWORD dwBufLen)
155 155
156 /*----------------------------------------------------------------------------- 156 /*-----------------------------------------------------------------------------
157 157
158 -FUNCTION: OutputABuffer(HWND, char *, DWORD) 158 +FUNCTION: OutputABuffer(HWND, char *)
159 159
160 PURPOSE: Send a rec'd buffer to the approprate location 160 PURPOSE: Send a rec'd buffer to the approprate location
161 161
@@ -170,8 +170,9 @@ HISTORY: Date: Author: Comment: @@ -170,8 +170,9 @@ HISTORY: Date: Author: Comment:
170 10/27/95 AllenD Wrote it 170 10/27/95 AllenD Wrote it
171 171
172 -----------------------------------------------------------------------------*/ 172 -----------------------------------------------------------------------------*/
173 -void OutputABuffer(HWND hTTY, char * lpBuf, DWORD dwBufLen) 173 +void OutputABuffer(HWND hTTY, char * lpBuf)
174 { 174 {
  175 + DWORD dwBufLen =strlen(lpBuf);
175 if (dwBufLen == 0) { 176 if (dwBufLen == 0) {
176 OutputDebugString("NULL Buffer in OutputABuffer\n\r"); 177 OutputDebugString("NULL Buffer in OutputABuffer\n\r");
177 return; 178 return;
@@ -58,6 +58,10 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV) @@ -58,6 +58,10 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV)
58 BOOL fWaitingOnStat = FALSE; 58 BOOL fWaitingOnStat = FALSE;
59 BOOL fThreadDone = FALSE; 59 BOOL fThreadDone = FALSE;
60 char lpBuf[AMOUNT_TO_READ]; 60 char lpBuf[AMOUNT_TO_READ];
  61 +#ifdef __TOPWELL_EDIT__
  62 + char lpBuf_first[AMOUNT_TO_READ];
  63 + char Flashed_percent;
  64 +#endif
61 HWND hTTY; 65 HWND hTTY;
62 66
63 hTTY = (HANDLE) lpV; 67 hTTY = (HANDLE) lpV;
@@ -105,7 +109,12 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV) @@ -105,7 +109,12 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV)
105 // if no read is outstanding, then issue another one 109 // if no read is outstanding, then issue another one
106 // 110 //
107 if (!fWaitingOnRead) { 111 if (!fWaitingOnRead) {
108 - if (!ReadFile(COMDEV(TTYInfo), lpBuf, AMOUNT_TO_READ, &dwRead, &osReader)) { 112 +#ifdef __TOPWELL_EDIT__
  113 + if (!ReadFile(COMDEV(TTYInfo), lpBuf_first, AMOUNT_TO_READ, &dwRead, &osReader))
  114 +#else
  115 + if (!ReadFile(COMDEV(TTYInfo), lpBuf, AMOUNT_TO_READ, &dwRead, &osReader))
  116 +#endif
  117 + {
109 if (GetLastError() != ERROR_IO_PENDING) // read not delayed? 118 if (GetLastError() != ERROR_IO_PENDING) // read not delayed?
110 ErrorInComm("ReadFile in ReaderAndStatusProc"); 119 ErrorInComm("ReadFile in ReaderAndStatusProc");
111 120
@@ -116,7 +125,7 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV) @@ -116,7 +125,7 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV)
116 UpdateStatus("Read timed out immediately.\r\n"); 125 UpdateStatus("Read timed out immediately.\r\n");
117 126
118 if (dwRead) 127 if (dwRead)
119 - OutputABuffer(hTTY, lpBuf, dwRead); 128 + OutputABuffer(hTTY, lpBuf);
120 } 129 }
121 } 130 }
122 131
@@ -167,7 +176,8 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV) @@ -167,7 +176,8 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV)
167 // read completed 176 // read completed
168 // 177 //
169 case WAIT_OBJECT_0: 178 case WAIT_OBJECT_0:
170 - if (!GetOverlappedResult(COMDEV(TTYInfo), &osReader, &dwRead, FALSE)) { 179 + if (!GetOverlappedResult(COMDEV(TTYInfo), &osReader, &dwRead, FALSE))
  180 + {
171 if (GetLastError() == ERROR_OPERATION_ABORTED) 181 if (GetLastError() == ERROR_OPERATION_ABORTED)
172 UpdateStatus("Read aborted\r\n"); 182 UpdateStatus("Read aborted\r\n");
173 else 183 else
@@ -177,8 +187,80 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV) @@ -177,8 +187,80 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV)
177 if ((dwRead != MAX_READ_BUFFER) && SHOWTIMEOUTS(TTYInfo)) 187 if ((dwRead != MAX_READ_BUFFER) && SHOWTIMEOUTS(TTYInfo))
178 UpdateStatus("Read timed out overlapped.\r\n"); 188 UpdateStatus("Read timed out overlapped.\r\n");
179 189
  190 +#ifdef __TOPWELL_EDIT__
180 if (dwRead) 191 if (dwRead)
181 - OutputABuffer(hTTY, lpBuf, dwRead); 192 + {
  193 + int loop1, loop2;
  194 + loop2 = 0;
  195 + for (loop1 = 0; loop1 < AMOUNT_TO_READ; loop1++)
  196 + {
  197 + if (lpBuf_first[loop1] < 0x0A || lpBuf_first[loop1] >= 0x7f)
  198 + continue;
  199 + else
  200 + lpBuf[loop2++] = lpBuf_first[loop1];
  201 + }
  202 + lpBuf[loop2++] = '\r';
  203 + lpBuf[loop2++] = '\n';
  204 + lpBuf[loop2] = 0;
  205 + if (strstr(lpBuf, "ROM boot"))
  206 + {
  207 + if (GetTickCount() -TTYInfo.tickcountFinish < 2000)
  208 + { // 在很短的时间内收到PCB板的下载信号, 视为PCB板自动复位, 而不是合上夹具
  209 + return 0;
  210 + }
  211 + TTYInfo.rgbBGColor = RGB(255, 255, 255);
  212 + OutputABuffer(hTTY, "进入下载模式\r\n");
  213 + TTYInfo.DownloadReday = TRUE;
  214 + if (strlen(TTYInfo.szFileName) != 0)
  215 + TransferFileTextStart(TTYInfo.szFileName);
  216 + else
  217 + {
  218 + TTYInfo.rgbBGColor = RGB(255, 201, 14);
  219 + OutputABuffer(hTTY, "还未选择软件\r\n");
  220 + return 0;
  221 + }
  222 + }
  223 + else if (strstr(lpBuf, "Verify successful"))
  224 + {
  225 + TTYInfo.tickcountFinish = GetTickCount();
  226 + TTYInfo.rgbBGColor = RGB(50, 255, 50);
  227 + OutputABuffer(hTTY, "下载完成\r\n");
  228 + TTYInfo.DownloadReday = FALSE;
  229 + }
  230 + else if (strstr(lpBuf, "Programming:"))
  231 + {
  232 + char * pchar_percent = strstr(lpBuf, "Programming:");
  233 + char ascbufpercent[64];
  234 + if (pchar_percent != NULL)
  235 + {
  236 + TTYInfo.tickcountFinish = GetTickCount();
  237 + TTYInfo.rgbBGColor = RGB(255, 255, 255);
  238 + memset(ascbufpercent, 0, 64);
  239 + strncpy(ascbufpercent, pchar_percent + 12, 2);
  240 + Flashed_percent = atoi(ascbufpercent);
  241 + sprintf(ascbufpercent, "下载已完成%d\r\n", Flashed_percent);
  242 + OutputABuffer(hTTY, ascbufpercent);
  243 + TTYInfo.DownloadReday = FALSE;
  244 + }
  245 + }
  246 + else if (strstr(lpBuf, "Verify fail"))
  247 + {
  248 + //TTYInfo.tickcountFinish = GetTickCount();
  249 + TTYInfo.rgbBGColor = RGB(255, 50, 50);
  250 + OutputABuffer(hTTY, "下载失败\r\n");
  251 + TTYInfo.DownloadReday = FALSE;
  252 + }
  253 + else
  254 + {
  255 + TTYInfo.rgbBGColor = RGB(255, 255, 255);
  256 + OutputABuffer(hTTY, lpBuf);
  257 + TTYInfo.DownloadReday = FALSE;
  258 + }
  259 + }
  260 +#else
  261 + if (dwRead)
  262 + OutputABuffer(hTTY, lpBuf);
  263 +#endif
182 } 264 }
183 265
184 fWaitingOnRead = FALSE; 266 fWaitingOnRead = FALSE;
@@ -188,7 +270,8 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV) @@ -188,7 +270,8 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV)
188 // status completed 270 // status completed
189 // 271 //
190 case WAIT_OBJECT_0 + 1: 272 case WAIT_OBJECT_0 + 1:
191 - if (!GetOverlappedResult(COMDEV(TTYInfo), &osStatus, &dwOvRes, FALSE)) { 273 + if (!GetOverlappedResult(COMDEV(TTYInfo), &osStatus, &dwOvRes, FALSE))
  274 + {
192 if (GetLastError() == ERROR_OPERATION_ABORTED) 275 if (GetLastError() == ERROR_OPERATION_ABORTED)
193 UpdateStatus("WaitCommEvent aborted\r\n"); 276 UpdateStatus("WaitCommEvent aborted\r\n");
194 else 277 else
@@ -722,7 +722,7 @@ BYTE GetbTTYItem(HWND hDlg, int idControl, char ** szString, DWORD * pTable, int @@ -722,7 +722,7 @@ BYTE GetbTTYItem(HWND hDlg, int idControl, char ** szString, DWORD * pTable, int
722 } 722 }
723 723
724 #ifdef __OPTEK_EDIT__ 724 #ifdef __OPTEK_EDIT__
725 -extern char szFileName[MAX_PATH]; 725 +//extern char szFileName[MAX_PATH];
726 726
727 int szFileName_check(char* fileName) 727 int szFileName_check(char* fileName)
728 { 728 {
@@ -825,10 +825,10 @@ BOOL CALLBACK ToolbarProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) @@ -825,10 +825,10 @@ BOOL CALLBACK ToolbarProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
825 fRet = FALSE; 825 fRet = FALSE;
826 break; 826 break;
827 } 827 }
828 - if (szFileName_check(szFileName)) 828 + if (szFileName_check(TTYInfo.szFileName))
829 { 829 {
830 EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_SENDBTN), FALSE); 830 EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_SENDBTN), FALSE);
831 - TransferFileTextStart(szFileName); 831 + TransferFileTextStart(TTYInfo.szFileName);
832 } 832 }
833 else 833 else
834 { 834 {
Please register or login to post a comment