Commit a868642c40d756111d71ec8bb0e784955291ac83

Authored by xiemeng
1 parent b0a55e39

update 0305

... ... @@ -31,8 +31,11 @@
31 31
32 32 #include <windows.h>
33 33 #include <commctrl.h>
  34 +#include <stdio.h>
34 35 #include "mttty.h"
35 36
  37 +//#pragma comment(lib,"comctl32.lib")
  38 +
36 39 /*
37 40 Prototypes for functions called only within this file
38 41 */
... ...
... ... @@ -25,7 +25,7 @@ STD_LIBS = libcmt.lib kernel32.lib \
25 25 user32.lib gdi32.lib \
26 26 comdlg32.lib
27 27 EXTRA_LIBS = winmm.lib comctl32.lib
28   -GLOBAL_DEP = mttty.h ttyinfo.h
  28 +GLOBAL_DEP = mttty.h
29 29 RC_DEP = resource.h mttty.ico \
30 30 mttty2.ico mttty3.ico \
31 31 mttty4.ico
... ...
... ... @@ -19,9 +19,94 @@
19 19 //
20 20
21 21 #include "resource.h"
22   -#include "ttyinfo.h"
  22 +//#include "ttyinfo.h"
  23 +#pragma comment(lib,"ws2_32.lib")
  24 +//
  25 +
23 26
24 27 //
  28 +// constant definitions
  29 +//
  30 +
  31 +//
  32 +// hard coded maximum number of ports
  33 +//
  34 +#define MAXPORTS 32
  35 +
  36 +//
  37 +// terminal size
  38 +//
  39 +#define MAXROWS 50
  40 +#define MAXCOLS 80
  41 +
  42 +//
  43 +// cursor states
  44 +//
  45 +#define CS_HIDE 0x00
  46 +#define CS_SHOW 0x01
  47 +
  48 +//
  49 +// ascii definitions
  50 +//
  51 +#define ASCII_BEL 0x07
  52 +#define ASCII_BS 0x08
  53 +#define ASCII_LF 0x0A
  54 +#define ASCII_CR 0x0D
  55 +#define ASCII_XON 0x11
  56 +#define ASCII_XOFF 0x13
  57 +
  58 +//
  59 +// data structures
  60 +//
  61 +
  62 +#define MAX_DEVICES_NUM 1
  63 +
  64 +struct TTYInfoStruct
  65 +{
  66 + HANDLE hCommPort, hReaderStatus, hWriter ;
  67 + DWORD dwEventFlags;
  68 + CHAR Screen[MAXCOLS * MAXROWS];
  69 + CHAR chFlag, chXON, chXOFF;
  70 + WORD wXONLimit, wXOFFLimit;
  71 + DWORD fRtsControl;
  72 + DWORD fDtrControl;
  73 + BOOL fConnected, fTransferring, fRepeating,
  74 + fLocalEcho, fNewLine,
  75 + fDisplayErrors, fAutowrap,
  76 + fCTSOutFlow, fDSROutFlow, fDSRInFlow,
  77 + fXonXoffOutFlow, fXonXoffInFlow,
  78 + fTXafterXoffSent,
  79 + fNoReading, fNoWriting, fNoEvents, fNoStatus,
  80 + fDisplayTimeouts;
  81 + BYTE bPort, bByteSize, bParity, bStopBits ;
  82 + DWORD dwBaudRate ;
  83 + WORD wCursorState ;
  84 + HFONT hTTYFont ;
  85 + LOGFONT lfTTYFont ;
  86 + DWORD rgbFGColor ;
  87 + DWORD rgbBGColor ;
  88 + COMMTIMEOUTS timeoutsorig;
  89 + COMMTIMEOUTS timeoutsnew;
  90 + int xSize, ySize, xScroll, yScroll, xOffset, yOffset,
  91 + nColumn, nRow, xChar, yChar , nCharPos;
  92 + char szFileName[MAX_PATH];
  93 + BYTE unOpenedPortAry[255];
  94 + BOOL DownloadReday;
  95 + DWORD tickcountFinish; //完成下载的时间
  96 + HWND hBtnAbortSend[50];
  97 + HWND hprocessFlash[50];
  98 +
  99 + //HANDLE hFileOfDongleBin;
  100 + HANDLE hFileOfEarphoneBin;
  101 + DWORD BinSizeFileEarphone,MaxPackets;
  102 + char BufEarphoneBin[3*1024*1024];
  103 +
  104 +
  105 +} g_appdata;
  106 +
  107 +
  108 +
  109 +
25 110 // GLOBAL DEFINES
26 111 //输出buff size
27 112 #define TTY_BUFFER_SIZE MAXROWS * MAXCOLS
... ... @@ -213,9 +298,9 @@ DWORD WINAPI WriterProc( LPVOID );
213 298 //
214 299 // File transfer functions
215 300 //
216   -void CALLBACK TransferRepeatDo( UINT, UINT, DWORD, DWORD, DWORD );
217   -void TransferRepeatCreate( LPCSTR, DWORD );
218   -void TransferRepeatDestroy( void );
  301 +//void CALLBACK TransferRepeatDo( UINT, UINT, DWORD, DWORD, DWORD );
  302 +//void TransferRepeatCreate( LPCSTR, DWORD );
  303 +//void TransferRepeatDestroy( void );
219 304 void TransferFileTextStart( LPCSTR );
220 305 void TransferFileTextEnd( void );
221 306 // void TransferFileText( LPCTSTR );
... ...
... ... @@ -420,10 +420,6 @@
420 420 RelativePath="RESOURCE.H"
421 421 >
422 422 </File>
423   - <File
424   - RelativePath="TTYInfo.h"
425   - >
426   - </File>
427 423 </Filter>
428 424 <Filter
429 425 Name="Resource Files"
... ...
... ... @@ -164,147 +164,127 @@ DWORD WINAPI ReaderAndStatusProc(LPVOID lpV)
164 164 if ( fWaitingOnStat && fWaitingOnRead ) {
165 165 dwRes = WaitForMultipleObjects(NUM_READSTAT_HANDLES, hArray, FALSE, STATUS_CHECK_TIMEOUT);
166 166 switch(dwRes)
167   - {
168   - //
169   - // read completed
170   - //
171   - case WAIT_OBJECT_0:
172   - if (!GetOverlappedResult(g_appdata.hCommPort, &osReader, &dwRead, FALSE)) {
173   - if (GetLastError() == ERROR_OPERATION_ABORTED)
174   - UpdateStatus("Read aborted\r\n");
175   - else
176   - ErrorInComm("GetOverlappedResult (in Reader)");
177   - }
178   - else { // read completed successfully
179   - if ((dwRead != MAX_READ_BUFFER) && g_appdata.fDisplayTimeouts)
180   - UpdateStatus("Read timed out overlapped.\r\n");
181   -
182   - if (dwRead)
  167 + {
  168 + // read completed
  169 + case WAIT_OBJECT_0: if (!GetOverlappedResult(g_appdata.hCommPort, &osReader, &dwRead, FALSE))
  170 + {
  171 + if (GetLastError() == ERROR_OPERATION_ABORTED)
  172 + UpdateStatus("Read aborted\r\n");
  173 + else
  174 + ErrorInComm("GetOverlappedResult (in Reader)");
  175 + }
  176 + else
  177 + { // read completed successfully
  178 + if ((dwRead != MAX_READ_BUFFER) && g_appdata.fDisplayTimeouts)
  179 + UpdateStatus("Read timed out overlapped.\r\n");
  180 + if (dwRead)
  181 + {
  182 + int loop1, loop2;
  183 + loop2 = 0;
  184 + for (loop1 = 0; loop1 < AMOUNT_TO_READ; loop1++)
183 185 {
184   - int loop1,loop2;
185   - loop2 = 0;
186   - for (loop1 = 0;loop1 < AMOUNT_TO_READ;loop1++)
187   - {
188   - if (lpBuf_first[loop1] <0x0A || lpBuf_first[loop1] >= 0x7f)
189   - continue;
190   - else
191   - lpBuf[loop2++] = lpBuf_first[loop1];
192   - }
193   - lpBuf[loop2++] = '\r';
194   - lpBuf[loop2++] = '\n';
195   - lpBuf[loop2] = 0;
196   -
197   - if (strstr(lpBuf,"ROM boot"))
198   - {
199   - if (GetTickCount() - g_appdata.tickcountFinish <2000)
200   - {// 在很短的时间内收到PCB板的下载信号, 视为PCB板自动复位, 而不是合上夹具
201   - return;
202   - }
203   - g_appdata.rgbBGColor = RGB(255,255,255);
204   - OutputABuffer(hTTY, "进入下载模式\r\n", dwRead);
205   -
206   - g_appdata.DownloadReday = TRUE;
207   - if (strlen(g_appdata.szFileName) != 0)
208   - TransferFileTextStart(g_appdata.szFileName);
  186 + if (lpBuf_first[loop1] < 0x0A || lpBuf_first[loop1] >= 0x7f)
  187 + continue;
  188 + else
  189 + lpBuf[loop2++] = lpBuf_first[loop1];
  190 + }
  191 + lpBuf[loop2++] = '\r';
  192 + lpBuf[loop2++] = '\n';
  193 + lpBuf[loop2] = 0;
  194 + if (strstr(lpBuf, "ROM boot"))
  195 + {
  196 + if (GetTickCount() -g_appdata.tickcountFinish < 2000)
  197 + { // 在很短的时间内收到PCB板的下载信号, 视为PCB板自动复位, 而不是合上夹具
  198 + return 0;
209 199 }
210   - //
211   - else if (strstr(lpBuf,"Verify successful"))
  200 + g_appdata.rgbBGColor = RGB(255, 255, 255);
  201 + OutputABuffer(hTTY, "进入下载模式\r\n", dwRead);
  202 + g_appdata.DownloadReday = TRUE;
  203 + if (strlen(g_appdata.szFileName) != 0)
  204 + TransferFileTextStart(g_appdata.szFileName);
  205 + }
  206 + else if (strstr(lpBuf, "Verify successful"))
  207 + {
  208 + g_appdata.tickcountFinish = GetTickCount();
  209 + g_appdata.rgbBGColor = RGB(50, 255, 50);
  210 + OutputABuffer(hTTY, "下载完成\r\n", dwRead);
  211 + g_appdata.DownloadReday = FALSE;
  212 + }
  213 + else if (strstr(lpBuf, "Programming:"))
  214 + {
  215 + char * pchar_percent = strstr(lpBuf, "Programming:");
  216 + char ascbufpercent[64];
  217 + if (pchar_percent != NULL)
212 218 {
213 219 g_appdata.tickcountFinish = GetTickCount();
214   - g_appdata.rgbBGColor = RGB(50,255,50);
215   - OutputABuffer(hTTY, "下载完成\r\n", dwRead);
  220 + g_appdata.rgbBGColor = RGB(255, 255, 255);
  221 + memset(ascbufpercent, 0, 64);
  222 + strncpy(ascbufpercent, pchar_percent + 12, 2);
  223 + Flashed_percent = atoi(ascbufpercent);
  224 + sprintf(ascbufpercent, "下载已完成%d\r\n", Flashed_percent);
  225 + OutputABuffer(hTTY, ascbufpercent, dwRead);
216 226 g_appdata.DownloadReday = FALSE;
217 227 }
218   - else if (strstr(lpBuf,"Programming:"))
219   - {
220   - char *pchar_percent = strstr(lpBuf,"Programming:");
221   - char ascbufpercent[64];
222   - if(pchar_percent != NULL)
223   - {
224   - g_appdata.tickcountFinish = GetTickCount();
225   - g_appdata.rgbBGColor = RGB(255,255,255);
226   - memset(ascbufpercent,0,64);
227   - strncpy(ascbufpercent,pchar_percent+12,2);
228   - Flashed_percent = atoi(ascbufpercent);
229   - sprintf(ascbufpercent,"下载已完成%d\r\n",Flashed_percent);
230   - OutputABuffer(hTTY, ascbufpercent, dwRead);
231   - g_appdata.DownloadReday = FALSE;
232   - }
233   - }
234   - else if (strstr(lpBuf,"Verify fail"))
235   - {
236   - //g_appdata.tickcountFinish = GetTickCount();
237   - g_appdata.rgbBGColor = RGB(255,50,50);
238   - OutputABuffer(hTTY, "下载失败\r\n", dwRead);
239   -
240   - g_appdata.DownloadReday = FALSE;
241   - }
242   - else
243   - {
244   - g_appdata.rgbBGColor = RGB(255,255,255);
245   - OutputABuffer(hTTY, lpBuf, dwRead);
246   - g_appdata.DownloadReday = FALSE;
247   - }
248   -
249   -
250 228 }
251   - }
252   -
253   - fWaitingOnRead = FALSE;
254   - break;
255   -
256   - //
257   - // status completed
258   - //
259   - case WAIT_OBJECT_0 + 1:
260   - if (!GetOverlappedResult(g_appdata.hCommPort, &osStatus, &dwOvRes, FALSE)) {
261   - if (GetLastError() == ERROR_OPERATION_ABORTED)
262   - UpdateStatus("WaitCommEvent aborted\r\n");
263   - else
264   - ErrorInComm("GetOverlappedResult (in Reader)");
265   - }
266   - else // status check completed successfully
267   - ReportStatusEvent(dwCommEvent);
268   -
269   - fWaitingOnStat = FALSE;
270   - break;
271   -
272   - //
273   - // status message event
274   - //
275   - case WAIT_OBJECT_0 + 2:
276   - StatusMessage();
277   - break;
278   -
279   - //
280   - // thread exit event
281   - //
282   - case WAIT_OBJECT_0 + 3:
283   - fThreadDone = TRUE;
284   - break;
285   -
286   - case WAIT_TIMEOUT:
287   - //
288   - // timeouts are not reported because they happen too often
289   - // OutputDebugString("Timeout in Reader & Status checking\n\r");
290   - //
291   -
292   - //
293   - // if status checks are not allowed, then don't issue the
294   - // modem status check nor the com stat check
295   - //
296   - if (!g_appdata.fNoStatus) {
297   - CheckModemStatus(FALSE); // take this opportunity to do
298   - CheckComStat(FALSE); // a modem status check and
299   - // a comm status check
300   - }
301   -
302   - break;
303   -
304   - default:
305   - ErrorReporter("WaitForMultipleObjects(Reader & Status handles)");
306   - break;
307   - }
  229 + else if (strstr(lpBuf, "Verify fail"))
  230 + {
  231 + //g_appdata.tickcountFinish = GetTickCount();
  232 + g_appdata.rgbBGColor = RGB(255, 50, 50);
  233 + OutputABuffer(hTTY, "下载失败\r\n", dwRead);
  234 + g_appdata.DownloadReday = FALSE;
  235 + }
  236 + else
  237 + {
  238 + g_appdata.rgbBGColor = RGB(255, 255, 255);
  239 + OutputABuffer(hTTY, lpBuf, dwRead);
  240 + g_appdata.DownloadReday = FALSE;
  241 + }
  242 + }
  243 + }
  244 + fWaitingOnRead = FALSE;
  245 + break;
  246 + // status completed
  247 + case WAIT_OBJECT_0 + 1: if (!GetOverlappedResult(g_appdata.hCommPort, &osStatus, &dwOvRes, FALSE))
  248 + {
  249 + if (GetLastError() == ERROR_OPERATION_ABORTED)
  250 + UpdateStatus("WaitCommEvent aborted\r\n");
  251 + else
  252 + ErrorInComm("GetOverlappedResult (in Reader)");
  253 + }
  254 + else
  255 + // status check completed successfully
  256 + ReportStatusEvent(dwCommEvent);
  257 + fWaitingOnStat = FALSE;
  258 + break;
  259 + // status message event
  260 + case WAIT_OBJECT_0 + 2: StatusMessage();
  261 + break;
  262 + // thread exit event
  263 + case WAIT_OBJECT_0 + 3: fThreadDone = TRUE;
  264 + break;
  265 + case WAIT_TIMEOUT: //
  266 +
  267 + // timeouts are not reported because they happen too often
  268 + // OutputDebugString("Timeout in Reader & Status checking\n\r");
  269 + //
  270 + //
  271 + // if status checks are not allowed, then don't issue the
  272 + // modem status check nor the com stat check
  273 + //
  274 + if (!g_appdata.fNoStatus)
  275 + {
  276 + CheckModemStatus(FALSE); // take this opportunity to do
  277 + CheckComStat(FALSE); // a modem status check and
  278 +
  279 + // a comm status check
  280 + }
  281 + break;
  282 + default:
  283 + ErrorReporter("WaitForMultipleObjects(Reader & Status handles)");
  284 + break;
  285 + }
  286 +
  287 +
308 288 }
309 289 }
310 290
... ...
... ... @@ -538,6 +538,9 @@ BOOL CALLBACK ToolbarProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
538 538 break;
539 539 case IDC_BUTTON2_SEC_BINFILE:
540 540 {
  541 + DWORD dwFileSize,dwRead;
  542 + BOOL loadBinFile = FALSE;
  543 +
541 544 if (strlen(g_appdata.szFileName) == 0)
542 545 {
543 546 char * szFilter = "Text Files\0*.*\0";
... ... @@ -553,19 +556,35 @@ BOOL CALLBACK ToolbarProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
553 556 if (!GetOpenFileName(&ofn))
554 557 break;
555 558 strcpy(g_appdata.szFileName,szFileName);
  559 + g_appdata.hFileOfEarphoneBin = OpenTheFile(g_appdata.szFileName);
  560 + if (g_appdata.hFileOfEarphoneBin == INVALID_HANDLE_VALUE)
  561 + {
  562 + memset(g_appdata.szFileName,0,MAX_PATH);
  563 + return;
  564 + }
  565 + // set up transfer metrics
  566 + if (!GetTransferSizes(g_appdata.hFileOfEarphoneBin))
  567 + {
  568 + memset(g_appdata.szFileName,0,MAX_PATH);
  569 + return;
  570 + }
  571 + memset(g_appdata.BufEarphoneBin, 0, 3*1024*1024);
  572 + ReadFile(g_appdata.hFileOfEarphoneBin , g_appdata.BufEarphoneBin, g_appdata.BinSizeFileEarphone, &dwRead, NULL);
  573 + if (dwRead != g_appdata.BinSizeFileEarphone)
  574 + {
  575 + memset(g_appdata.szFileName,0,MAX_PATH);
  576 + CloseHandle(g_appdata.hFileOfEarphoneBin);
  577 + ErrorReporter("file err!\r\n");
  578 + return;
  579 + }
556 580 SetWindowText(GetDlgItem(hWndDlg, IDC_BUTTON2_SEC_BINFILE), "下载软件");
557   -
558 581 }
559 582 if (g_appdata.DownloadReday == FALSE)
560 583 {
561 584 MessageBox(ghwndMain, "请合上夹具", "提示!", MB_OK);
562   - return;
  585 + return FALSE;
563 586 }
564 587
565   -
566   - if (TRUE)
567   - TransferFileTextStart(g_appdata.szFileName);
568   -
569 588 }
570 589 break;
571 590 case IDC_BUTTON_CONNECT_UART: // font button pressed
... ...
... ... @@ -134,9 +134,10 @@ BOOL CALLBACK StatusDlgProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
134 134 {
135 135 case IDC_ABORTBTN:
136 136 // am I in a transfer repeat?
137   - if (g_appdata.fRepeating) TransferRepeatDestroy();
  137 + //if (g_appdata.fRepeating) TransferRepeatDestroy();
138 138 // am I in a normal recieve state, then stop sending
139   - else if (gdwReceiveState == RECEIVE_TTY)
  139 + //else
  140 + if (gdwReceiveState == RECEIVE_TTY)
140 141 TransferFileTextEnd();
141 142 // if I am not in a normal receive state, then stop capturing
142 143 else
... ...
... ... @@ -34,11 +34,11 @@
34 34 #include <windows.h>
35 35 #include <commctrl.h>
36 36 #include "mttty.h"
37   -
  37 +#pragma comment(lib,"ws2_32.lib")
38 38 //
39 39 // Globals used in this file only
40 40 //
41   -HANDLE hFile;
  41 +//HANDLE hFile;
42 42 HANDLE hTransferAbortEvent;
43 43 HANDLE hTransferThread;
44 44 UINT uTimerId;
... ... @@ -50,9 +50,17 @@ char * lpBuf;
50 50 DWORD WINAPI TransferThreadProc(LPVOID);
51 51 HANDLE OpenTheFile( LPCTSTR );
52 52 HANDLE CreateTheFile( LPCTSTR );
53   -void CaptureFile( HANDLE, HWND );
  53 +//void CaptureFile( HANDLE, HWND );
54 54 UINT CheckForMessages( void );
55   -BOOL GetTransferSizes( HANDLE, DWORD *, DWORD *, DWORD *);
  55 +BOOL GetTransferSizes( HANDLE, DWORD *, DWORD *);
  56 +
  57 +
  58 +DWORD upgrade_rf_test_buf = 0x703F0000;
  59 +DWORD upgrade_version_buf = 0x705f0000;
  60 +DWORD upgrade_rf_test_buf_len = 0;
  61 +HANDLE*upgrade_fp;
  62 +//char uart_upgrade_rf_test_bin[]?=?{'B','l','u','e','S','e','a','_','u','a','r','t','_','u','p','g','r','a','d','e','.','b','i','n',0x0};
  63 +
56 64
57 65
58 66 /*-----------------------------------------------------------------------------
... ... @@ -73,58 +81,58 @@ HISTORY: Date: Author: Comment:
73 81 1/29/96 AllenD Wrote it
74 82
75 83 -----------------------------------------------------------------------------*/
76   -void TransferRepeatCreate(LPCTSTR lpszFileName, DWORD dwFrequency)
77   -{
78   - HMENU hMenu;
79   - UINT MenuFlags;
80   - DWORD dwFileSize;
81   - DWORD dwMaxPackets;
82   - DWORD dwPacketSize;
83   - DWORD dwRead;
84   -
85   - // open the file
86   - hFile = OpenTheFile(lpszFileName);
87   - if (hFile == INVALID_HANDLE_VALUE)
88   - return;
89   - // modify transfer menu
90   - hMenu = GetMenu(ghwndMain);
91   - MenuFlags = MF_DISABLED | MF_GRAYED;
92   - EnableMenuItem(hMenu, ID_TRANSFER_RECEIVEFILETEXT, MenuFlags);
93   - // enable abort button and progress bar
94   - SetWindowText(GetDlgItem(ghWndStatusDlg, IDC_ABORTBTN), "Abort Tx");
95   - EnableWindow(GetDlgItem(ghWndStatusDlg, IDC_ABORTBTN), TRUE);
96   - if (!GetTransferSizes(hFile, &dwPacketSize, &dwMaxPackets, &dwFileSize))
97   - {
98   - TransferRepeatDestroy();
99   - return;
100   - }
101   - lpBuf = HeapAlloc(ghWriterHeap, 0, dwFileSize);
102   - if (lpBuf == NULL)
103   - {
104   - ErrorReporter("HeapAlloc (data block from writer heap).\r\nFile is too large");
105   - TransferRepeatDestroy();
106   - return;
107   - }
108   - if (!ReadFile(hFile, lpBuf, dwFileSize, &dwRead, NULL))
109   - {
110   - ErrorReporter("Can't read from file\n");
111   - TransferRepeatDestroy();
112   - }
113   - if (dwRead != dwFileSize)
114   - ErrorReporter("Didn't read entire file\n");
115   - mmTimer = timeSetEvent((UINT) dwFrequency, 10, TransferRepeatDo, dwRead, TIME_PERIODIC);
116   - if (mmTimer == (MMRESULT) NULL)
117   - {
118   - ErrorReporter("Could not create mm timer");
119   - TransferRepeatDestroy();
120   - }
121   - else
122   - {
123   - g_appdata.fRepeating = TRUE;
124   - OutputDebugString("Timer setup.\n");
125   - }
126   - return;
127   -}
  84 +//void TransferRepeatCreate(LPCTSTR lpszFileName, DWORD dwFrequency)
  85 +//{
  86 +// HMENU hMenu;
  87 +// UINT MenuFlags;
  88 +// DWORD dwFileSize;
  89 +// DWORD dwMaxPackets;
  90 +// DWORD dwPacketSize;
  91 +// DWORD dwRead;
  92 +//
  93 +// // open the file
  94 +// hFile = OpenTheFile(lpszFileName);
  95 +// if (hFile == INVALID_HANDLE_VALUE)
  96 +// return;
  97 +// // modify transfer menu
  98 +// hMenu = GetMenu(ghwndMain);
  99 +// MenuFlags = MF_DISABLED | MF_GRAYED;
  100 +// EnableMenuItem(hMenu, ID_TRANSFER_RECEIVEFILETEXT, MenuFlags);
  101 +// // enable abort button and progress bar
  102 +// SetWindowText(GetDlgItem(ghWndStatusDlg, IDC_ABORTBTN), "Abort Tx");
  103 +// EnableWindow(GetDlgItem(ghWndStatusDlg, IDC_ABORTBTN), TRUE);
  104 +// if (!GetTransferSizes(hFile, &dwPacketSize, &dwMaxPackets, &dwFileSize))
  105 +// {
  106 +// TransferRepeatDestroy();
  107 +// return;
  108 +// }
  109 +// lpBuf = HeapAlloc(ghWriterHeap, 0, dwFileSize);
  110 +// if (lpBuf == NULL)
  111 +// {
  112 +// ErrorReporter("HeapAlloc (data block from writer heap).\r\nFile is too large");
  113 +// TransferRepeatDestroy();
  114 +// return;
  115 +// }
  116 +// if (!ReadFile(hFile, lpBuf, dwFileSize, &dwRead, NULL))
  117 +// {
  118 +// ErrorReporter("Can't read from file\n");
  119 +// TransferRepeatDestroy();
  120 +// }
  121 +// if (dwRead != dwFileSize)
  122 +// ErrorReporter("Didn't read entire file\n");
  123 +// mmTimer = timeSetEvent((UINT) dwFrequency, 10, TransferRepeatDo, dwRead, TIME_PERIODIC);
  124 +// if (mmTimer == (MMRESULT) NULL)
  125 +// {
  126 +// ErrorReporter("Could not create mm timer");
  127 +// TransferRepeatDestroy();
  128 +// }
  129 +// else
  130 +// {
  131 +// g_appdata.fRepeating = TRUE;
  132 +// OutputDebugString("Timer setup.\n");
  133 +// }
  134 +// return;
  135 +//}
128 136
129 137
130 138
... ... @@ -140,43 +148,43 @@ HISTORY: Date: Author: Comment:
140 148 1/29/96 AllenD Wrote it
141 149
142 150 -----------------------------------------------------------------------------*/
143   -void TransferRepeatDestroy()
144   -{
145   - HMENU hMenu;
146   - DWORD MenuFlags;
147   - MMRESULT mmRes;
148   -
149   - if (mmTimer != (MMRESULT) NULL) {
150   - mmRes = timeKillEvent(mmTimer);
151   - if (mmRes != TIMERR_NOERROR)
152   - ErrorReporter("Can't kill mm timer");
153   - mmTimer = (MMRESULT) NULL;
154   - }
155   -
156   - // close the file
157   - CloseHandle(hFile);
158   -
159   - // inform writer to abort all pending write requests
160   - if (!WriterAddFirstNodeTimeout(WRITE_ABORT, 0, 0, NULL, NULL, NULL, 500))
161   - ErrorReporter("Couldn't inform writer to abort sending.");
162   -
163   - // free the buffer
164   - if (!HeapFree(ghWriterHeap, 0, lpBuf))
165   - ErrorReporter("HeapFree (data block from writer heap)");
166   -
167   - g_appdata.fRepeating = FALSE;
168   - OutputDebugString("Repeated transfer destroyed.\r\n");
169   -
170   - //
171   - // enable transfer menu
172   - //
173   - hMenu = GetMenu(ghwndMain);
174   - MenuFlags = MF_ENABLED;
175   - EnableMenuItem(hMenu, ID_TRANSFER_RECEIVEFILETEXT, MenuFlags);
176   - EnableWindow(GetDlgItem(ghWndStatusDlg, IDC_ABORTBTN), FALSE);
177   -
178   - return;
179   -}
  151 +//void TransferRepeatDestroy()
  152 +//{
  153 +// HMENU hMenu;
  154 +// DWORD MenuFlags;
  155 +// MMRESULT mmRes;
  156 +//
  157 +// if (mmTimer != (MMRESULT) NULL) {
  158 +// mmRes = timeKillEvent(mmTimer);
  159 +// if (mmRes != TIMERR_NOERROR)
  160 +// ErrorReporter("Can't kill mm timer");
  161 +// mmTimer = (MMRESULT) NULL;
  162 +// }
  163 +//
  164 +// // close the file
  165 +// CloseHandle(hFile);
  166 +//
  167 +// // inform writer to abort all pending write requests
  168 +// if (!WriterAddFirstNodeTimeout(WRITE_ABORT, 0, 0, NULL, NULL, NULL, 500))
  169 +// ErrorReporter("Couldn't inform writer to abort sending.");
  170 +//
  171 +// // free the buffer
  172 +// if (!HeapFree(ghWriterHeap, 0, lpBuf))
  173 +// ErrorReporter("HeapFree (data block from writer heap)");
  174 +//
  175 +// g_appdata.fRepeating = FALSE;
  176 +// OutputDebugString("Repeated transfer destroyed.\r\n");
  177 +//
  178 +// //
  179 +// // enable transfer menu
  180 +// //
  181 +// hMenu = GetMenu(ghwndMain);
  182 +// MenuFlags = MF_ENABLED;
  183 +// EnableMenuItem(hMenu, ID_TRANSFER_RECEIVEFILETEXT, MenuFlags);
  184 +// EnableWindow(GetDlgItem(ghWndStatusDlg, IDC_ABORTBTN), FALSE);
  185 +//
  186 +// return;
  187 +//}
180 188
181 189 /*-----------------------------------------------------------------------------
182 190
... ... @@ -191,16 +199,12 @@ HISTORY: Date: Author: Comment:
191 199 1/29/96 AllenD Wrote it
192 200
193 201 -----------------------------------------------------------------------------*/
194   -void CALLBACK TransferRepeatDo( UINT uTimerId,
195   - UINT uRes,
196   - DWORD dwFileSize,
197   - DWORD dwRes1,
198   - DWORD dwRes2)
199   -{
200   - if (!WriterAddNewNodeTimeout(WRITE_BLOCK, dwFileSize, 0, lpBuf, 0, 0, 10))
201   - PostMessage(ghWndStatusDlg, WM_COMMAND, IDC_ABORTBTN,0);
202   - return;
203   -}
  202 +//void CALLBACK TransferRepeatDo( UINT uTimerId, UINT uRes, DWORD dwFileSize, DWORD dwRes1, DWORD dwRes2)
  203 +//{
  204 +// if (!WriterAddNewNodeTimeout(WRITE_BLOCK, dwFileSize, 0, lpBuf, 0, 0, 10))
  205 +// PostMessage(ghWndStatusDlg, WM_COMMAND, IDC_ABORTBTN,0);
  206 +// return;
  207 +//}
204 208
205 209 /*-----------------------------------------------------------------------------
206 210
... ... @@ -224,13 +228,6 @@ void TransferFileTextStart(LPCTSTR lpstrFileName)
224 228 UINT MenuFlags ;
225 229
226 230 //
227   - // open the file
228   - //
229   - hFile = OpenTheFile(lpstrFileName);
230   - if (hFile == INVALID_HANDLE_VALUE)
231   - return;
232   -
233   - //
234 231 // modify transfer menu
235 232 //
236 233 hMenu = GetMenu(ghwndMain);
... ... @@ -252,7 +249,7 @@ void TransferFileTextStart(LPCTSTR lpstrFileName)
252 249
253 250 hTransferThread = CreateThread(NULL, 0,
254 251 TransferThreadProc,
255   - (LPVOID) hFile, 0, &dwThreadId);
  252 + (LPVOID) g_appdata.hFileOfEarphoneBin, 0, &dwThreadId);
256 253
257 254 if (hTransferThread == NULL) {
258 255 ErrorReporter("CreateThread (Transfer Thread)");
... ... @@ -314,7 +311,7 @@ void TransferFileTextEnd()
314 311 //
315 312 // close the file
316 313 //
317   - CloseHandle(hFile);
  314 + CloseHandle(g_appdata.hFileOfEarphoneBin);
318 315 }
319 316
320 317
... ... @@ -368,7 +365,7 @@ void ReceiveFileText(LPCTSTR lpstrFileName)
368 365 //
369 366 // send file until done or abort
370 367 //
371   - CaptureFile(ghFileCapture, GetDlgItem(ghWndStatusDlg, IDC_TRANSFERPROGRESS));
  368 +// CaptureFile(ghFileCapture, GetDlgItem(ghWndStatusDlg, IDC_TRANSFERPROGRESS));
372 369
373 370 //
374 371 // enable menu
... ... @@ -470,7 +467,7 @@ HISTORY: Date: Author: Comment:
470 467 10/27/95 AllenD Wrote it
471 468
472 469 -----------------------------------------------------------------------------*/
473   -BOOL GetTransferSizes(HANDLE hFile, DWORD * pdwDataPacketSize, DWORD * pdwNumPackets, DWORD * pdwFileSize)
  470 +BOOL GetTransferSizes(HANDLE hFile)
474 471 {
475 472 BY_HANDLE_FILE_INFORMATION fi;
476 473
... ... @@ -486,12 +483,10 @@ BOOL GetTransferSizes(HANDLE hFile, DWORD * pdwDataPacketSize, DWORD * pdwNumPac
486 483
487 484 //
488 485 // setup packet size, file size and compute the number of packets
489   - //
490   - *pdwDataPacketSize = MAX_WRITE_BUFFER;
491   - *pdwFileSize = fi.nFileSizeLow;
492   - *pdwNumPackets = *pdwFileSize / *pdwDataPacketSize;
  486 + g_appdata.BinSizeFileEarphone = fi.nFileSizeLow;
  487 + g_appdata.MaxPackets = g_appdata.BinSizeFileEarphone / MAX_WRITE_BUFFER;
493 488
494   - if (*pdwNumPackets > 65534) {
  489 + if (g_appdata.MaxPackets > 65534) {
495 490 MessageBox(ghwndMain, "File is too large for buffer size.", "File Transfer Error", MB_OK);
496 491 return FALSE;
497 492 }
... ... @@ -598,224 +593,467 @@ HISTORY: Date: Author: Comment:
598 593 10/27/95 AllenD Wrote it
599 594
600 595 -----------------------------------------------------------------------------*/
601   -void CaptureFile(HANDLE hFile, HWND hWndProgress)
602   -{
603   - UINT uMsgResult;
604   - gdwReceiveState = RECEIVE_CAPTURED;
605   -
606   - while ( !gfAbortTransfer ) {
  596 +//void CaptureFile(HANDLE hFile, HWND hWndProgress)
  597 +//{
  598 +// UINT uMsgResult;
  599 +// gdwReceiveState = RECEIVE_CAPTURED;
  600 +//
  601 +// while ( !gfAbortTransfer ) {
  602 +//
  603 +// uMsgResult = CheckForMessages();
  604 +//
  605 +// //
  606 +// // If WM_CLOSE is retrieved, then exit.
  607 +// // If no message is retrieved, then sleep a little.
  608 +// // If any other message is retrieved, check for another one.
  609 +// //
  610 +// switch(uMsgResult)
  611 +// {
  612 +// case WM_CLOSE: gfAbortTransfer = TRUE; break;
  613 +// case FALSE: Sleep(200); break;
  614 +// case TRUE: break;
  615 +// }
  616 +// }
  617 +//
  618 +// gdwReceiveState = RECEIVE_TTY;
  619 +//
  620 +// return;
  621 +//}
607 622
608   - uMsgResult = CheckForMessages();
609 623
610   - //
611   - // If WM_CLOSE is retrieved, then exit.
612   - // If no message is retrieved, then sleep a little.
613   - // If any other message is retrieved, check for another one.
614   - //
615   - switch(uMsgResult)
616   - {
617   - case WM_CLOSE: gfAbortTransfer = TRUE; break;
618   - case FALSE: Sleep(200); break;
619   - case TRUE: break;
620   - }
621   - }
  624 +/**********************************************/
  625 +/* fileCheck_fix_MACID锟斤拷锟斤拷 */
  626 +/* */
  627 +/*********************************************/
  628 +#define HEADER_START 0x44332211
  629 +#define BAUDRATE_DET_DATA 0xFFAAFF55
  630 +#define BAUDRATE_DET_DATA_LEN 0xB00
  631 +#define HEADER_LEN 0x20
  632 +#define MAC_ADDR_OFFSET 0x68000
622 633
623   - gdwReceiveState = RECEIVE_TTY;
  634 +#define U32 unsigned int
624 635
625   - return;
626   -}
  636 +enum {
  637 + READ_CPU_TICKS_ERR,
  638 + WRONG_FILE_FORMAT,
  639 + CHECKSUM_ERROR,
  640 + MACID_SUB_USELESS,
  641 + FILE_CHCK_SUCCESSFUL
  642 +};
627 643
628   -/*-----------------------------------------------------------------------------
  644 +typedef struct {
  645 + U32 rx_header_start;
  646 + U32 rx_copy_addr;
  647 + U32 rx_run_addr;
  648 + U32 rx_total_bytes;
  649 + U32 rx_bootloader_flag;
  650 + U32 rx_sflash_size;
  651 + U32 rx_checksum;
  652 + U32 rx_dummy_data_size;
  653 +} BOOT_HEADER;
629 654
630   -FUNCTION: TransferThreadProc(LPVOID)
  655 +const char dft_bdaddr[6] = { 0x00,0x00,0x00,0x3F,0x9f,0x94 };
631 656
632   -PURPOSE: Worker thread does all the file transfer work
  657 +char macid_sub[3] = {0x9e, 0x8b, 0x0};
633 658
634   -PARAMETERS:
635   - lpV - actually a HANDLE for the file
  659 +char macid_company[3] = {0x0, 0x1, 0x2};
636 660
637   -COMMENTS: Function allows the hTransferAbortEvent to
638   - signal an abort condition.
639   - If the thread finishes OK, then the thread
640   - calls the TransferFileTextEnd function itself.
641 661
642   -HISTORY: Date: Author: Comment:
643   - 1/26/96 AllenD Wrote it
644 662
645   ------------------------------------------------------------------------------*/
646   -DWORD WINAPI TransferThreadProc(LPVOID lpV)
  663 +//char *fData,
  664 +int fileCheck_fix_MACID(char *dataLen, const char macid_sub[3], const char macid_company[3])
647 665 {
648   - DWORD dwPacketSize, dwMaxPackets, dwFileSize;
649   - DWORD dwStartTime;
650   - HWND hWndProgress;
651   - HANDLE hFileHandle;
652   - HANDLE hDataHeap;
653   - BOOL fStarted = TRUE;
654   - BOOL fAborting = FALSE;
655   -
656   - hFileHandle = (HANDLE) lpV;
657   - hWndProgress = GetDlgItem(ghWndStatusDlg, IDC_TRANSFERPROGRESS);
658   -
659   - // set up transfer metrics
660   - if (!GetTransferSizes(hFileHandle, &dwPacketSize, &dwMaxPackets, &dwFileSize))
661   - fAborting = TRUE;
662   - else {
663   - SendMessage(hWndProgress, PBM_SETRANGE, 0, MAKELPARAM(0, dwMaxPackets+1));
664   - SendMessage(hWndProgress, PBM_SETSTEP, (WPARAM) 1, 0);
665   - SendMessage(hWndProgress, PBM_SETPOS, 0, 0);
666   - }
667   -
668   - // set up transfer heaps
669   - if (!fAborting) {
670   - SYSTEM_INFO sysInfo;
671   - GetSystemInfo(&sysInfo);
672   - hDataHeap = HeapCreate(0, sysInfo.dwPageSize * 2, sysInfo.dwPageSize * 10);
673   - if (hDataHeap == NULL) {
674   - ErrorReporter("HeapCreate (Data Heap)");
675   - fAborting = TRUE;
676   - }
677   - }
  666 + int i;
  667 + int ret = FILE_CHCK_SUCCESSFUL;
  668 + char *p = g_appdata.BufEarphoneBin + MAC_ADDR_OFFSET + BAUDRATE_DET_DATA_LEN + HEADER_LEN;
  669 + U32 *p1 = (U32 *)g_appdata.BufEarphoneBin;
  670 + unsigned char baaddr[6];
  671 + BOOT_HEADER *p_header = (BOOT_HEADER *)(g_appdata.BufEarphoneBin + BAUDRATE_DET_DATA_LEN);
  672 +
  673 + if ((macid_sub[0] == 0x9e) && (macid_sub[1] == 0x8b) && ((macid_sub[2] >= 0x0) && (macid_sub[2] <= 0x3f)))
  674 + {
  675 + ret = MACID_SUB_USELESS;
  676 + }
678 677
679   - // inform writer thread that a file is about to be transferred
680   - if (!fAborting) {
681   - if (!WriterAddNewNode(WRITE_FILESTART, dwFileSize, 0, NULL, NULL, NULL))
682   - fAborting = TRUE;
683   - }
  678 + memcpy(baaddr, macid_sub, sizeof(macid_sub));
  679 + memcpy(baaddr + (sizeof(macid_sub)), macid_company, sizeof(macid_company));
684 680
685   - OutputDebugString("Xfer: About to start sending data\n");
  681 + //memset(baaddr,0,sizeof(baaddr));
  682 + //app_lcd_device.display_char (" ", 0, 0);
  683 + //app_lcd_device.display_char (" ", 1, 0);
686 684
687   - // Get Transfer Start Time
688   - dwStartTime = GetTickCount();
  685 + /***********det data check*********************/
  686 + for (i = 0; i < BAUDRATE_DET_DATA_LEN / 4; i++)
  687 + {
  688 + if (*p1++ != BAUDRATE_DET_DATA)
  689 + {
  690 + ret = WRONG_FILE_FORMAT;
  691 + //app_lcd_device.display_char("wrong file",0,0);
  692 + break;
  693 + }
  694 + }
689 695
690   - if (WaitForSingleObject(hTransferAbortEvent, 0) == WAIT_OBJECT_0)
691   - fAborting = TRUE;
  696 + /***********header check*********************/
  697 + if (ret == FILE_CHCK_SUCCESSFUL)
  698 + {
  699 + if (p_header->rx_header_start != HEADER_START)
  700 + {
  701 + ret = WRONG_FILE_FORMAT;
  702 + //app_lcd_device.display_char("wrong file",0,0);
  703 + }
  704 + else if (p_header->rx_total_bytes != (dataLen - BAUDRATE_DET_DATA_LEN - sizeof(BOOT_HEADER)))
  705 + {
  706 + ret = WRONG_FILE_FORMAT;
  707 + //app_lcd_device.display_char("wrong file",0,0);
  708 + }
  709 + }
692 710
693   - while (!fAborting) {
694   - char * lpDataBuf;
695   - PWRITEREQUEST pWrite;
  711 + /***********checksum*********************/
  712 + if (ret == FILE_CHCK_SUCCESSFUL)
  713 + {
  714 + int checksum = 0;
  715 + p1 = (U32*)(g_appdata.BufEarphoneBin + BAUDRATE_DET_DATA_LEN + sizeof(BOOT_HEADER));
  716 + for (i = 0; i < (p_header->rx_total_bytes - 4) / 4; i++)
  717 + {
  718 + checksum += *p1++;
  719 + }
  720 +
  721 + if ((checksum != *p1) || (checksum != p_header->rx_checksum))
  722 + {
  723 + ret = CHECKSUM_ERROR;
  724 + //app_lcd_device.display_char("check err",0,0);
  725 + }
  726 + }
  727 + //BOOL QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount)
  728 + //LARGE_INTEGER ticks;
  729 +#if 0//
  730 + baaddr[0] = (unsigned char)(macid_0) & 0x000000ff;
  731 + baaddr[1] = (unsigned char)(macid_1) & 0x000000ff;
  732 + baaddr[2] = (unsigned char)(macid_2) & 0x000000ff;
  733 +
  734 + baaddr[3] = (unsigned char)(macid_3) & 0x000000ff;
  735 + baaddr[4] = (unsigned char)(macid_4) & 0x000000ff;
  736 + baaddr[5] = (unsigned char)(macid_5) & 0x000000ff;
  737 + //#else
  738 + U32 U32_ticks = read_ccount();
  739 + if (U32_ticks)
  740 + {
  741 + //char szMessage[70];
  742 + baaddr[0] = (unsigned char)(U32_ticks & 0x000000ff);
  743 + baaddr[1] = (unsigned char)(U32_ticks >> 8) & 0x000000ff;
  744 + baaddr[2] = (unsigned char)(U32_ticks >> 16) & 0x000000ff;
696 745
697   - // transfer file, loop until all blocks of file have been read
698   - lpDataBuf = HeapAlloc(hDataHeap, 0, dwPacketSize);
699   - pWrite = HeapAlloc(ghWriterHeap, 0, sizeof(WRITEREQUEST));
700   - if ((lpDataBuf != NULL) && (pWrite != NULL)) {
  746 + //wsprintf(szMessage, "bt bdaddr:0x%02x%02x%02x%02x%02x%02x\r\n",baaddr[5],baaddr[4],baaddr[3],baaddr[2],baaddr[1],baaddr[0]);
  747 + //UpdateStatus(szMessage);
  748 + }
  749 + else
  750 + {
  751 + ret = READ_CPU_TICKS_ERR;
  752 + app_lcd_device.display_char("read clk err", 0, 0);
  753 + }
  754 +#endif
  755 + // "Optek Bt\0\0"
  756 + *p++ = 'O';
  757 + *p++ = 'p';
  758 + *p++ = 't';
  759 + *p++ = 'e';
  760 + *p++ = 'k';
  761 + *p++ = ' ';
  762 + *p++ = 'B';
  763 + *p++ = 't';
  764 + // *p++ = 0;
  765 +
  766 + //u32 wr_cn;
  767 + *p++ = 0;
  768 + *p++ = 0;
  769 + *p++ = 0;
  770 + *p++ = 0;
  771 +
  772 + *p++ = 0;
  773 + *p++ = 0;
  774 + *p++ = 0;
  775 + *p++ = 0;
  776 +
  777 + // bt mac id
  778 + /* *p++ = 0x11;
  779 + *p++ = 0x12;
  780 + *p++ = 0x13;
  781 + *p++ = 0x14;
  782 + *p++ = 0x15;
  783 + *p++ = 0x16;*/
  784 + memcpy(p, baaddr, sizeof(baaddr));
  785 + p += 6;
  786 +
  787 +
  788 + p = g_appdata.BufEarphoneBin + MAC_ADDR_OFFSET + 0X1000 + 0xb20;
  789 +
  790 + // "Optek Bt\0\0"
  791 + *p++ = 'O';
  792 + *p++ = 'p';
  793 + *p++ = 't';
  794 + *p++ = 'e';
  795 + *p++ = 'k';
  796 + *p++ = ' ';
  797 + *p++ = 'B';
  798 + *p++ = 't';
  799 + // *p++ = 0;
  800 +
  801 + //u32 wr_cn;
  802 + *p++ = 0;
  803 + *p++ = 0;
  804 + *p++ = 0;
  805 + *p++ = 0;
  806 +
  807 + *p++ = 0;
  808 + *p++ = 0;
  809 + *p++ = 0;
  810 + *p++ = 0;
  811 + // bt mac id
  812 + /* *p++ = 0x11;
  813 + *p++ = 0x12;
  814 + *p++ = 0x13;
  815 + *p++ = 0x14;
  816 + *p++ = 0x15;
  817 + *p++ = 0x16;*/
  818 + memcpy(p, baaddr, sizeof(baaddr));
  819 + p += 6;
  820 +
  821 + //a-a5
  822 +/*
  823 + buf = buf+0xfc00c;
  824 + buf[0] = a;
  825 + buf[1] = a1;
  826 + buf[2] = a2;
  827 + buf[3] = a3;
  828 + buf[4] = a4;
  829 + buf[5] = a5;
  830 + buf = buf-0xfc00c;
  831 + */
  832 +
  833 + if (ret == FILE_CHCK_SUCCESSFUL)
  834 + {
  835 + int checksum = 0;
  836 + p1 = (U32*)(g_appdata.BufEarphoneBin + BAUDRATE_DET_DATA_LEN + sizeof(BOOT_HEADER));
  837 + for (i = 0; i < (p_header->rx_total_bytes - 4) / 4; i++)
  838 + {
  839 + checksum += *p1++;
  840 + }
  841 +
  842 + *p1 = checksum;
  843 + p_header->rx_checksum = checksum;
  844 + //app_lcd_device.display_char("check ok",0,0);
  845 + }
  846 + return ret;
  847 +}
701 848
702   - DWORD dwRead;
703 849
704   - // read from file into new buffer
705   - if (ReadFile(hFileHandle, lpDataBuf, dwPacketSize, &dwRead, NULL)) {
706   - WriterAddExistingNode(pWrite, WRITE_FILE, dwRead, 0, lpDataBuf, hDataHeap, hWndProgress);
707 850
708   - if (dwRead != dwPacketSize) // eof
709   - break;
710   - }
711   - }
712   - else {
713   - BOOL fRes;
714   - /*
715   - Either the data heap is full, or the writer heap is full.
716   - Free any allocated block, wait a little and try again.
717   -
718   - Waiting lets the writer thread send some blocks and free
719   - the data blocks from the data heap and the control
720   - blocks from the writer heap.
721   - */
722   - if (lpDataBuf) {
723   - EnterCriticalSection(&gcsDataHeap);
724   - fRes = HeapFree(hDataHeap, 0, lpDataBuf);
725   - LeaveCriticalSection(&gcsDataHeap);
726   - if (!fRes)
727   - ErrorReporter("HeapFree (Data block)");
728   - }
729   -
730   - if (pWrite) {
731   - EnterCriticalSection(&gcsWriterHeap);
732   - fRes = HeapFree(ghWriterHeap, 0, pWrite);
733   - LeaveCriticalSection(&gcsWriterHeap);
734   - if (!fRes)
735   - ErrorReporter("HeapFree (Writer block)");
736   - }
737   -
738   - OutputDebugString("Xfer: A heap is full. Waiting...\n");
739   -
740   - // wait a little
741   - // check for abort during the wait
742   - if (WaitForSingleObject(hTransferAbortEvent, 200) == WAIT_OBJECT_0)
743   - fAborting = TRUE;
744   - }
745 851
746   - // has the user aborted?
747   - if (WaitForSingleObject(hTransferAbortEvent, 0) == WAIT_OBJECT_0)
748   - fAborting = TRUE;
749   - }
  852 +/*-----------------------------------------------------------------------------
750 853
751   - OutputDebugString("Xfer: Done sending packets.\n");
  854 +FUNCTION: TransferThreadProc(LPVOID)
752 855
753   - if (fAborting) {
754   - // inform writer that transfer is aborting
  856 +PURPOSE: Worker thread does all the file transfer work
755 857
756   - OutputDebugString("Xfer: Sending Abort Packet to writer\n");
757   - WriterAddFirstNodeTimeout(WRITE_ABORT, dwFileSize, 0, NULL, NULL, NULL, 500);
758   - }
759   - else
760   - WriterAddNewNodeTimeout(WRITE_FILEEND, dwFileSize, 0, NULL, NULL, NULL, 500);
761   -
762   - {
763   - // wait til writer thread finishes with all blocks
764   - HANDLE hEvents[2];
765   - DWORD dwRes;
766   - BOOL fTransferComplete;
767   -
768   - hEvents[0] = ghTransferCompleteEvent;
769   - hEvents[1] = hTransferAbortEvent;
770   -
771   - OutputDebugString("Xfer: Waiting for transfer complete signal from writer\n");
772   - do {
773   - ResetEvent(hTransferAbortEvent);
774   -
775   - dwRes = WaitForMultipleObjects(2, hEvents, FALSE, INFINITE);
776   - switch(dwRes) {
777   - case WAIT_OBJECT_0:
778   - fTransferComplete = TRUE;
779   - OutputDebugString("Transfer complete signal rec'd\n");
780   - break;
781   - case WAIT_OBJECT_0 + 1:
782   - fAborting = TRUE;
783   - OutputDebugString("Transfer abort signal rec'd\n");
784   - OutputDebugString("Xfer: Sending Abort Packet to writer\n");
785   - if (!WriterAddFirstNodeTimeout(WRITE_ABORT, dwFileSize, 0, NULL, NULL, NULL, 500))
786   - ErrorReporter("Can't add abort packet\n");
787   - break;
788   - case WAIT_TIMEOUT: break;
789   - default:
790   - ErrorReporter("WaitForMultipleObjects(Transfer Complete Event and Transfer Abort Event)");
791   - fTransferComplete = TRUE;
792   - break;
793   - }
794   - } while (!fTransferComplete);
795   - }
  858 +PARAMETERS:
  859 + lpV - actually a HANDLE for the file
796 860
797   - OutputDebugString("Xfer: transfer complete\n");
  861 +COMMENTS: Function allows the hTransferAbortEvent to
  862 + signal an abort condition.
  863 + If the thread finishes OK, then the thread
  864 + calls the TransferFileTextEnd function itself.
798 865
799   - // report statistics
800   - if (!fAborting)
801   - ShowTransferStatistics(GetTickCount(), dwStartTime, dwFileSize);
  866 +HISTORY: Date: Author: Comment:
  867 + 1/26/96 AllenD Wrote it
802 868
803   - // break down metrics
804   - PostMessage(hWndProgress, PBM_SETPOS, 0, 0);
  869 +-----------------------------------------------------------------------------*/
  870 +DWORD WINAPI TransferThreadProc(LPVOID lpV)
  871 +{
  872 + DWORD dwFileSize;
  873 + DWORD dwStartTime;
  874 + HWND hWndProgress;
  875 + HANDLE hFileHandle;
  876 + HANDLE hDataHeap;
  877 + BOOL fStarted = TRUE;
  878 + BOOL fAborting = FALSE;
  879 + BOOL userAborting = TRUE;
  880 + char * pRead;
  881 + DWORD dwRead;
  882 + int err;
  883 + //hFileHandle = (HANDLE) lpV;
  884 + hWndProgress = GetDlgItem(ghWndStatusDlg, IDC_TRANSFERPROGRESS);
805 885
806   - // break down heaps
807   - if (hDataHeap != NULL) {
808   - if (!HeapDestroy(hDataHeap))
809   - ErrorReporter("HeapDestroy (data heap)");
810   - }
  886 + {
  887 + SendMessage(hWndProgress, PBM_SETRANGE, 0, MAKELPARAM(0, g_appdata.MaxPackets + 1));
  888 + SendMessage(hWndProgress, PBM_SETSTEP, (WPARAM) 1, 0);
  889 + SendMessage(hWndProgress, PBM_SETPOS, 0, 0);
  890 + }
811 891
812   - // If I am done without user intervention, then post the
813   - // "abort" message myself. This will cause the main thread to
814   - // clean up after the file transfer.
815   - //if (!fAborting) PostMessage(ghwndMain, WM_COMMAND, ID_TRANSFER_ABORTSENDING, 0);
  892 + // set up transfer heaps
  893 + if (!fAborting)
  894 + {
  895 + SYSTEM_INFO sysInfo;
  896 +
  897 + GetSystemInfo(&sysInfo);
  898 + hDataHeap = HeapCreate(0, sysInfo.dwPageSize * 2, sysInfo.dwPageSize * 10);
  899 + if (hDataHeap == NULL)
  900 + {
  901 + ErrorReporter("HeapCreate (Data Heap)");
  902 + fAborting = TRUE;
  903 + }
  904 + }
  905 +#if 1 //def check file
  906 + /**********************check file*********************************/
  907 + //lpfileBuf = HeapAlloc(hDataHeap, 0, dwFileSize);
  908 + pRead = g_appdata.BufEarphoneBin;
  909 + err = fileCheck_fix_MACID(dwFileSize, macid_sub, macid_company);
  910 + if (err == WRONG_FILE_FORMAT)
  911 + {
  912 + ErrorReporter("wrong file format!");
  913 + userAborting = FALSE;
  914 + fAborting = TRUE;
  915 + }
  916 + else if (err == CHECKSUM_ERROR)
  917 + {
  918 + ErrorReporter("check sum err!");
  919 + userAborting = FALSE;
  920 + fAborting = TRUE;
  921 + }
  922 + else if (err == READ_CPU_TICKS_ERR)
  923 + {
  924 + ErrorReporter("read cpu ticks error!");
  925 + userAborting = FALSE;
  926 + fAborting = TRUE;
  927 + }
  928 +#endif //check file
  929 + if (WaitForSingleObject(hTransferAbortEvent, 0) == WAIT_OBJECT_0)
  930 + fAborting = TRUE;
  931 + // inform writer thread that a file is about to be transferred
  932 + if (!fAborting)
  933 + {
  934 + if (!WriterAddNewNode(WRITE_FILESTART, dwFileSize, 0, NULL, NULL, NULL))
  935 + fAborting = TRUE;
  936 + }
  937 + OutputDebugString("Xfer: About to start sending data\n");
  938 + // Get Transfer Start Time
  939 + dwStartTime = GetTickCount();
  940 + //if (WaitForSingleObject(hTransferAbortEvent, 0) == WAIT_OBJECT_0)
  941 + // fAborting = TRUE;
  942 + while (!fAborting)
  943 + {
  944 + char * lpDataBuf;
  945 + PWRITEREQUEST pWrite;
  946 + // transfer file, loop until all blocks of file have been read
  947 + lpDataBuf = HeapAlloc(hDataHeap, 0, MAX_WRITE_BUFFER);
  948 + pWrite = HeapAlloc(ghWriterHeap, 0, sizeof(WRITEREQUEST));
  949 + if ((lpDataBuf != NULL) && (pWrite != NULL))
  950 + {
  951 + DWORD dwRead;
  952 + // read from file into new buffer
  953 + if (ReadFile(hFileHandle, lpDataBuf, MAX_WRITE_BUFFER, &dwRead, NULL))
  954 + {
  955 + WriterAddExistingNode(pWrite, WRITE_FILE, dwRead, 0, lpDataBuf, hDataHeap, hWndProgress);
  956 + if (dwRead != MAX_WRITE_BUFFER) break;
  957 + }
  958 + }
  959 + else
  960 + {
  961 + BOOL fRes;
  962 + /*
  963 + Either the data heap is full, or the writer heap is full.
  964 + Free any allocated block, wait a little and try again.
  965 + Waiting lets the writer thread send some blocks and free
  966 + the data blocks from the data heap and the control
  967 + blocks from the writer heap.
  968 + */
  969 + if (lpDataBuf)
  970 + {
  971 + EnterCriticalSection(&gcsDataHeap);
  972 + fRes = HeapFree(hDataHeap, 0, lpDataBuf);
  973 + LeaveCriticalSection(&gcsDataHeap);
  974 + if (!fRes) ErrorReporter("HeapFree (Data block)");
  975 + }
  976 + if (pWrite)
  977 + {
  978 + EnterCriticalSection(&gcsWriterHeap);
  979 + fRes = HeapFree(ghWriterHeap, 0, pWrite);
  980 + LeaveCriticalSection(&gcsWriterHeap);
  981 + if (!fRes)
  982 + ErrorReporter("HeapFree (Writer block)");
  983 + }
  984 + OutputDebugString("Xfer: A heap is full. Waiting...\n");
  985 + // wait a little
  986 + // check for abort during the wait
  987 + if (WaitForSingleObject(hTransferAbortEvent, 200) == WAIT_OBJECT_0)
  988 + fAborting = TRUE;
  989 + }
  990 + // has the user aborted?
  991 + if (WaitForSingleObject(hTransferAbortEvent, 0) == WAIT_OBJECT_0)
  992 + fAborting = TRUE;
  993 + }
  994 + OutputDebugString("Xfer: Done sending packets.\n");
  995 + if (fAborting)
  996 + {
  997 + // inform writer that transfer is aborting
  998 + OutputDebugString("Xfer: Sending Abort Packet to writer\n");
  999 + WriterAddFirstNodeTimeout(WRITE_ABORT, dwFileSize, 0, NULL, NULL, NULL, 500);
  1000 + }
  1001 + else
  1002 + WriterAddNewNodeTimeout(WRITE_FILEEND, dwFileSize, 0, NULL, NULL, NULL, 500);
  1003 + {
  1004 + // wait til writer thread finishes with all blocks
  1005 + HANDLE hEvents[2];
  1006 + DWORD dwRes;
  1007 + BOOL fTransferComplete;
  1008 + hEvents[0] = ghTransferCompleteEvent;
  1009 + hEvents[1] = hTransferAbortEvent;
  1010 + OutputDebugString("Xfer: Waiting for transfer complete signal from writer\n");
  1011 + do
  1012 + {
  1013 + ResetEvent(hTransferAbortEvent);
  1014 + dwRes = WaitForMultipleObjects(2, hEvents, FALSE, INFINITE);
  1015 + switch (dwRes)
  1016 + {
  1017 + case WAIT_OBJECT_0:
  1018 + fTransferComplete = TRUE;
  1019 + OutputDebugString("Transfer complete signal rec'd\n");
  1020 + break;
  1021 + case WAIT_OBJECT_0 + 1:
  1022 + fAborting = TRUE;
  1023 + OutputDebugString("Transfer abort signal rec'd\n");
  1024 + OutputDebugString("Xfer: Sending Abort Packet to writer\n");
  1025 + if (!WriterAddFirstNodeTimeout(WRITE_ABORT, dwFileSize, 0, NULL, NULL, NULL, 500))
  1026 + ErrorReporter("Can't add abort packet\n");
  1027 + break;
  1028 + case WAIT_TIMEOUT:
  1029 + break;
  1030 + default:
  1031 + ErrorReporter("WaitForMultipleObjects(Transfer Complete Event and Transfer Abort Event)");
  1032 + fTransferComplete = TRUE;
  1033 + break;
  1034 + }
  1035 + }
  1036 + while(!fTransferComplete);
  1037 + }
  1038 + OutputDebugString("Xfer: transfer complete\n");
  1039 + // report statistics
  1040 + if (!fAborting)
  1041 + ShowTransferStatistics(GetTickCount(), dwStartTime, dwFileSize);
  1042 + // break down metrics
  1043 + PostMessage(hWndProgress, PBM_SETPOS, 0, 0);
  1044 + // break down heaps
  1045 + if (hDataHeap != NULL)
  1046 + {
  1047 + if (!HeapDestroy(hDataHeap))
  1048 + ErrorReporter("HeapDestroy (data heap)");
  1049 + }
  1050 + // If I am done without user intervention, then post the
  1051 + // "abort" message myself. This will cause the main thread to
  1052 + // clean up after the file transfer.
  1053 + //if (!fAborting) PostMessage(ghwndMain, WM_COMMAND, ID_TRANSFER_ABORTSENDING, 0);
  1054 + // exit thread
  1055 + return 0;
  1056 +}
816 1057
817   - // exit thread
818 1058
819   - return 0;
820   -}
821 1059
... ...
1   -
2   -/*-----------------------------------------------------------------------------
3   - This is a part of the Microsoft Source Code Samples.
4   - Copyright (C) 1995 Microsoft Corporation.
5   - All rights reserved.
6   - This source code is only intended as a supplement to
7   - Microsoft Development Tools and/or WinHelp documentation.
8   - See these sources for detailed information regarding the
9   - Microsoft samples programs.
10   -
11   - MODULE: TTYINFO.h
12   -
13   - PURPOSE: Contains global definitions for the TTYINFO structure
14   -
15   ------------------------------------------------------------------------------*/
16   -
17   -//
18   -// constant definitions
19   -//
20   -
21   -//
22   -// hard coded maximum number of ports
23   -//
24   -#define MAXPORTS 32
25   -
26   -//
27   -// terminal size
28   -//
29   -#define MAXROWS 50
30   -#define MAXCOLS 80
31   -
32   -//
33   -// cursor states
34   -//
35   -#define CS_HIDE 0x00
36   -#define CS_SHOW 0x01
37   -
38   -//
39   -// ascii definitions
40   -//
41   -#define ASCII_BEL 0x07
42   -#define ASCII_BS 0x08
43   -#define ASCII_LF 0x0A
44   -#define ASCII_CR 0x0D
45   -#define ASCII_XON 0x11
46   -#define ASCII_XOFF 0x13
47   -
48   -//
49   -// data structures
50   -//
51   -
52   -#define MAX_DEVICES_NUM 1
53   -
54   -struct TTYInfoStruct
55   -{
56   - HANDLE hCommPort, hReaderStatus, hWriter ;
57   - DWORD dwEventFlags;
58   - CHAR Screen[MAXCOLS * MAXROWS];
59   - CHAR chFlag, chXON, chXOFF;
60   - WORD wXONLimit, wXOFFLimit;
61   - DWORD fRtsControl;
62   - DWORD fDtrControl;
63   - BOOL fConnected, fTransferring, fRepeating,
64   - fLocalEcho, fNewLine,
65   - fDisplayErrors, fAutowrap,
66   - fCTSOutFlow, fDSROutFlow, fDSRInFlow,
67   - fXonXoffOutFlow, fXonXoffInFlow,
68   - fTXafterXoffSent,
69   - fNoReading, fNoWriting, fNoEvents, fNoStatus,
70   - fDisplayTimeouts;
71   - BYTE bPort, bByteSize, bParity, bStopBits ;
72   - DWORD dwBaudRate ;
73   - WORD wCursorState ;
74   - HFONT hTTYFont ;
75   - LOGFONT lfTTYFont ;
76   - DWORD rgbFGColor ;
77   - DWORD rgbBGColor ;
78   - COMMTIMEOUTS timeoutsorig;
79   - COMMTIMEOUTS timeoutsnew;
80   - int xSize, ySize, xScroll, yScroll, xOffset, yOffset,
81   - nColumn, nRow, xChar, yChar , nCharPos;
82   - char szFileName[MAX_PATH];
83   - BYTE unOpenedPortAry[255];
84   - BOOL DownloadReday;
85   - DWORD tickcountFinish; //Íê³ÉÏÂÔØµÄʱ¼ä
86   - HWND hBtnAbortSend[50];
87   - HWND hprocessFlash[50];
88   -
89   -
90   -} g_appdata;
91   -
92   -//
93   -// macros ( for easier readability )
94   -//
95   -//#define COMDEV(g_appdata) (g_appdata.hCommPort)
96   -//#define CURSORSTATE(g_appdata) (g_appdata.wCursorState)
97   -//#define PORT(g_appdata) (g_appdata.bPort)
98   -//#define g_appdata.Screen (g_appdata.Screen)
99   -//#define CONNECTED(g_appdata) (g_appdata.fConnected)
100   -//#define g_appdata.fTransferring (g_appdata.fTransferring)
101   -//#define g_appdata.fRepeating (g_appdata.fRepeating)
102   -//#define g_appdata.fLocalEcho (g_appdata.fLocalEcho)
103   -//#define g_appdata.fNewLine (g_appdata.fNewLine)
104   -//#define g_appdata.fAutowrap g_appdata.fAutowrap
105   -//#define g_appdata.bByteSize g_appdata.bByteSize
106   -//#define g_appdata.bParity g_appdata.bParity
107   -//#define g_appdata.bStopBits g_appdata.bStopBits
108   -//#define g_appdata.dwBaudRate g_appdata.dwBaudRate
109   -//#define g_appdata.hTTYFont g_appdata.hTTYFont
110   -//#define g_appdata.lfTTYFont g_appdata.lfTTYFont
111   -//#define g_appdata.rgbFGColor g_appdata.rgbFGColor
112   -//#define g_appdata.rgbBGColor g_appdata.rgbBGColor
113   -//#define g_appdata.xSize g_appdata.xSize
114   -//#define g_appdata.ySize g_appdata.ySize
115   -//#define g_appdata.xScroll g_appdata.xScroll
116   -//#define g_appdata.yScroll g_appdata.yScroll
117   -//#define g_appdata.xOffset g_appdata.xOffset
118   -//#define g_appdata.yOffset g_appdata.yOffset
119   -//#define g_appdata.nColumn g_appdata.nColumn
120   -//#define g_appdata.nRow g_appdata.nRow
121   -//#define g_appdata.xChar g_appdata.xChar
122   -//#define g_appdata.yChar g_appdata.yChar
123   -//#define g_appdata.fDisplayErrors g_appdata.fDisplayErrors
124   -//#define g_appdata.timeoutsorig g_appdata.timeoutsorig
125   -//#define g_appdata.timeoutsnew g_appdata.timeoutsnew
126   -//#define g_appdata.hWriter g_appdata.hWriter
127   -//#define g_appdata.hReaderStatus g_appdata.hReaderStatus
128   -//#define g_appdata.dwEventFlags g_appdata.dwEventFlags
129   -//#define g_appdata.chFlag g_appdata.chFlag
130   -//#define SCREENCHAR( x, col, row ) g_appdata.Screen[row * MAXCOLS + col]
131   -
132   -//#define g_appdata.fDtrControl g_appdata.fDtrControl
133   -//#define g_appdata.fRtsControl g_appdata.fRtsControl
134   -//#define g_appdata.chXON g_appdata.chXON
135   -//#define g_appdata.chXOFF g_appdata.chXOFF
136   -//#define g_appdata.wXONLimit g_appdata.wXONLimit
137   -//#define g_appdata.wXOFFLimit g_appdata.wXOFFLimit
138   -//#define g_appdata.fCTSOutFlow g_appdata.fCTSOutFlow
139   -//#define g_appdata.fDSROutFlow g_appdata.fDSROutFlow
140   -//#define g_appdata.fDSRInFlow g_appdata.fDSRInFlow
141   -//#define g_appdata.fXonXoffOutFlow g_appdata.fXonXoffOutFlow
142   -//#define g_appdata.fXonXoffInFlow g_appdata.fXonXoffInFlow
143   -//#define g_appdata.fTXafterXoffSent g_appdata.fTXafterXoffSent
144   -//
145   -//#define g_appdata.fNoReading g_appdata.fNoReading
146   -//#define g_appdata.fNoWriting g_appdata.fNoWriting
147   -//#define g_appdata.fNoEvents g_appdata.fNoEvents
148   -//#define g_appdata.fNoStatus g_appdata.fNoStatus
149   -//#define g_appdata.fDisplayTimeouts g_appdata.fDisplayTimeouts)
150   -
151   -
152   -
153   -//---------------------------------------------------------------------------
154   -// End of File: ttyinfo.h
155   -//---------------------------------------------------------------------------
Please register or login to post a comment