|
@@ -34,11 +34,11 @@ |
|
@@ -34,11 +34,11 @@ |
|
34
|
#include <windows.h>
|
34
|
#include <windows.h>
|
|
35
|
#include <commctrl.h>
|
35
|
#include <commctrl.h>
|
|
36
|
#include "mttty.h"
|
36
|
#include "mttty.h"
|
|
37
|
-
|
37
|
+#pragma comment(lib,"ws2_32.lib")
|
|
38
|
//
|
38
|
//
|
|
39
|
// Globals used in this file only
|
39
|
// Globals used in this file only
|
|
40
|
//
|
40
|
//
|
|
41
|
-HANDLE hFile;
|
41
|
+//HANDLE hFile;
|
|
42
|
HANDLE hTransferAbortEvent;
|
42
|
HANDLE hTransferAbortEvent;
|
|
43
|
HANDLE hTransferThread;
|
43
|
HANDLE hTransferThread;
|
|
44
|
UINT uTimerId;
|
44
|
UINT uTimerId;
|
|
@@ -50,9 +50,17 @@ char * lpBuf; |
|
@@ -50,9 +50,17 @@ char * lpBuf; |
|
50
|
DWORD WINAPI TransferThreadProc(LPVOID);
|
50
|
DWORD WINAPI TransferThreadProc(LPVOID);
|
|
51
|
HANDLE OpenTheFile( LPCTSTR );
|
51
|
HANDLE OpenTheFile( LPCTSTR );
|
|
52
|
HANDLE CreateTheFile( LPCTSTR );
|
52
|
HANDLE CreateTheFile( LPCTSTR );
|
|
53
|
-void CaptureFile( HANDLE, HWND );
|
53
|
+//void CaptureFile( HANDLE, HWND );
|
|
54
|
UINT CheckForMessages( void );
|
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,58 +81,58 @@ HISTORY: Date: Author: Comment: |
|
73
|
1/29/96 AllenD Wrote it
|
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,43 +148,43 @@ HISTORY: Date: Author: Comment: |
|
140
|
1/29/96 AllenD Wrote it
|
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,16 +199,12 @@ HISTORY: Date: Author: Comment: |
|
191
|
1/29/96 AllenD Wrote it
|
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,13 +228,6 @@ void TransferFileTextStart(LPCTSTR lpstrFileName) |
|
224
|
UINT MenuFlags ;
|
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
|
// modify transfer menu
|
231
|
// modify transfer menu
|
|
235
|
//
|
232
|
//
|
|
236
|
hMenu = GetMenu(ghwndMain);
|
233
|
hMenu = GetMenu(ghwndMain);
|
|
@@ -252,7 +249,7 @@ void TransferFileTextStart(LPCTSTR lpstrFileName) |
|
@@ -252,7 +249,7 @@ void TransferFileTextStart(LPCTSTR lpstrFileName) |
|
252
|
|
249
|
|
|
253
|
hTransferThread = CreateThread(NULL, 0,
|
250
|
hTransferThread = CreateThread(NULL, 0,
|
|
254
|
TransferThreadProc,
|
251
|
TransferThreadProc,
|
|
255
|
- (LPVOID) hFile, 0, &dwThreadId);
|
252
|
+ (LPVOID) g_appdata.hFileOfEarphoneBin, 0, &dwThreadId);
|
|
256
|
|
253
|
|
|
257
|
if (hTransferThread == NULL) {
|
254
|
if (hTransferThread == NULL) {
|
|
258
|
ErrorReporter("CreateThread (Transfer Thread)");
|
255
|
ErrorReporter("CreateThread (Transfer Thread)");
|
|
@@ -314,7 +311,7 @@ void TransferFileTextEnd() |
|
@@ -314,7 +311,7 @@ void TransferFileTextEnd() |
|
314
|
//
|
311
|
//
|
|
315
|
// close the file
|
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,7 +365,7 @@ void ReceiveFileText(LPCTSTR lpstrFileName) |
|
368
|
//
|
365
|
//
|
|
369
|
// send file until done or abort
|
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
|
// enable menu
|
371
|
// enable menu
|
|
@@ -470,7 +467,7 @@ HISTORY: Date: Author: Comment: |
|
@@ -470,7 +467,7 @@ HISTORY: Date: Author: Comment: |
|
470
|
10/27/95 AllenD Wrote it
|
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
|
BY_HANDLE_FILE_INFORMATION fi;
|
472
|
BY_HANDLE_FILE_INFORMATION fi;
|
|
476
|
|
473
|
|
|
@@ -486,12 +483,10 @@ BOOL GetTransferSizes(HANDLE hFile, DWORD * pdwDataPacketSize, DWORD * pdwNumPac |
|
@@ -486,12 +483,10 @@ BOOL GetTransferSizes(HANDLE hFile, DWORD * pdwDataPacketSize, DWORD * pdwNumPac |
|
486
|
|
483
|
|
|
487
|
//
|
484
|
//
|
|
488
|
// setup packet size, file size and compute the number of packets
|
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
|
MessageBox(ghwndMain, "File is too large for buffer size.", "File Transfer Error", MB_OK);
|
490
|
MessageBox(ghwndMain, "File is too large for buffer size.", "File Transfer Error", MB_OK);
|
|
496
|
return FALSE;
|
491
|
return FALSE;
|
|
497
|
}
|
492
|
}
|
|
@@ -598,224 +593,467 @@ HISTORY: Date: Author: Comment: |
|
@@ -598,224 +593,467 @@ HISTORY: Date: Author: Comment: |
|
598
|
10/27/95 AllenD Wrote it
|
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
|
|