|
...
|
...
|
@@ -15,6 +15,12 @@ static char THIS_FILE[] = __FILE__; |
|
15
|
15
|
/////////////////////////////////////////////////////////////////////////////
|
|
16
|
16
|
// CBlueFlashToolDlg dialog
|
|
17
|
17
|
|
|
|
18
|
+
|
|
|
19
|
+
|
|
|
20
|
+
|
|
|
21
|
+
|
|
|
22
|
+UINT BlueFlashThreadProc(LPVOID lParam);
|
|
|
23
|
+
|
|
18
|
24
|
CBlueFlashToolDlg::CBlueFlashToolDlg(CWnd* pParent /*=NULL*/)
|
|
19
|
25
|
: CDialog(CBlueFlashToolDlg::IDD, pParent)
|
|
20
|
26
|
{
|
|
...
|
...
|
@@ -27,8 +33,8 @@ CBlueFlashToolDlg::CBlueFlashToolDlg(CWnd* pParent /*=NULL*/) |
|
27
|
33
|
{
|
|
28
|
34
|
g_AppMainData.if_flash[BLUE_TYPE_EAR][i] = 0;
|
|
29
|
35
|
g_AppMainData.if_flash[BLUE_TYPE_USB][i] = 0;
|
|
30
|
|
- myBufferOfBin[BLUE_TYPE_EAR][i] = NULL;
|
|
31
|
|
- myBufferOfBin[BLUE_TYPE_USB][i] = NULL;
|
|
|
36
|
+ ifUartEnable[BLUE_TYPE_USB][i] = false;
|
|
|
37
|
+ ifUartEnable[BLUE_TYPE_EAR][i] = false;
|
|
32
|
38
|
}
|
|
33
|
39
|
}
|
|
34
|
40
|
|
|
...
|
...
|
@@ -60,8 +66,6 @@ void CBlueFlashToolDlg::DoDataExchange(CDataExchange* pDX) |
|
60
|
66
|
|
|
61
|
67
|
//}}AFX_DATA_MAP
|
|
62
|
68
|
DDX_Control(pDX, IDC_DEBUG_MESSAGE, mylistDebugInfo);
|
|
63
|
|
- DDX_Control(pDX, IDC_CHECK_EAR_ALL, mycheckEarAll);
|
|
64
|
|
- DDX_Control(pDX, IDC_CHECK_USB_ALL, mycheckUsbAll);
|
|
65
|
69
|
}
|
|
66
|
70
|
|
|
67
|
71
|
BEGIN_MESSAGE_MAP(CBlueFlashToolDlg, CDialog)
|
|
...
|
...
|
@@ -112,8 +116,6 @@ BEGIN_MESSAGE_MAP(CBlueFlashToolDlg, CDialog) |
|
112
|
116
|
ON_BN_CLICKED(IDC_BUTTON_START_EAR9, &CBlueFlashToolDlg::OnBnClickedButtonStartUsbEar)
|
|
113
|
117
|
ON_BN_CLICKED(IDC_BUTTON_START_EAR10, &CBlueFlashToolDlg::OnBnClickedButtonStartUsbEar)
|
|
114
|
118
|
|
|
115
|
|
- ON_BN_CLICKED(IDC_CHECK_EAR_ALL, &CBlueFlashToolDlg::OnBnClickedCheckEarUsbAll)
|
|
116
|
|
- ON_BN_CLICKED(IDC_CHECK_USB_ALL, &CBlueFlashToolDlg::OnBnClickedCheckEarUsbAll)
|
|
117
|
119
|
ON_WM_DESTROY()
|
|
118
|
120
|
END_MESSAGE_MAP()
|
|
119
|
121
|
|
|
...
|
...
|
@@ -138,6 +140,8 @@ BOOL CBlueFlashToolDlg::OnInitDialog() |
|
138
|
140
|
pButton[BLUE_TYPE_EAR][loop]->EnableWindow(FALSE);
|
|
139
|
141
|
pButton[BLUE_TYPE_USB][loop] = (CButton *)GetDlgItem(IDC_BUTTON_START_USB1+loop);
|
|
140
|
142
|
pButton[BLUE_TYPE_USB][loop]->EnableWindow(FALSE);
|
|
|
143
|
+ pProcess[BLUE_TYPE_EAR][loop] = (CProgressCtrl *)GetDlgItem(IDC_PROGRESS_EAR1+loop);
|
|
|
144
|
+ pProcess[BLUE_TYPE_USB][loop] = (CProgressCtrl *)GetDlgItem(IDC_PROGRESS_USB1+loop);
|
|
141
|
145
|
pStaticSn[loop] = (CStatic *)GetDlgItem(IDC_STATIC_GROUP1+loop);
|
|
142
|
146
|
}
|
|
143
|
147
|
pctrlMSComm[BLUE_TYPE_EAR][0]=&mycom01;
|
|
...
|
...
|
@@ -221,10 +225,30 @@ void CBlueFlashToolDlg::UpdateGroupsCaptions() |
|
221
|
225
|
|
|
222
|
226
|
for (loop = 0; loop < 10; loop++)
|
|
223
|
227
|
{
|
|
224
|
|
- if (g_AppMainData.ary_myComPort[BLUE_TYPE_EAR][loop] < 2)
|
|
|
228
|
+ if (g_AppMainData.ary_myComPort[BLUE_TYPE_EAR][loop] < 2
|
|
|
229
|
+ || ifUartEnable[BLUE_TYPE_EAR][loop] == false)
|
|
|
230
|
+ {
|
|
225
|
231
|
g_AppMainData.if_flash[BLUE_TYPE_EAR][loop] = 0;
|
|
226
|
|
- if (g_AppMainData.ary_myComPort[BLUE_TYPE_USB][loop] < 2)
|
|
|
232
|
+ pcheckButton[BLUE_TYPE_EAR][loop]->SetCheck(0);
|
|
|
233
|
+ pcheckButton[BLUE_TYPE_EAR][loop]->EnableWindow(FALSE);
|
|
|
234
|
+ }
|
|
|
235
|
+ else
|
|
|
236
|
+ {
|
|
|
237
|
+ pcheckButton[BLUE_TYPE_EAR][loop]->SetCheck(g_AppMainData.if_flash[BLUE_TYPE_EAR][loop]);
|
|
|
238
|
+ pcheckButton[BLUE_TYPE_EAR][loop]->EnableWindow(TRUE);
|
|
|
239
|
+ }
|
|
|
240
|
+ if (g_AppMainData.ary_myComPort[BLUE_TYPE_USB][loop] < 2
|
|
|
241
|
+ || ifUartEnable[BLUE_TYPE_USB][loop] == false)
|
|
|
242
|
+ {
|
|
227
|
243
|
g_AppMainData.if_flash[BLUE_TYPE_USB][loop] = 0;
|
|
|
244
|
+ pcheckButton[BLUE_TYPE_USB][loop]->SetCheck(0);
|
|
|
245
|
+ pcheckButton[BLUE_TYPE_USB][loop]->EnableWindow(FALSE);
|
|
|
246
|
+ }
|
|
|
247
|
+ else
|
|
|
248
|
+ {
|
|
|
249
|
+ pcheckButton[BLUE_TYPE_USB][loop]->SetCheck(g_AppMainData.if_flash[BLUE_TYPE_USB][loop]);
|
|
|
250
|
+ pcheckButton[BLUE_TYPE_USB][loop]->EnableWindow(TRUE);
|
|
|
251
|
+ }
|
|
228
|
252
|
if (g_AppMainData.if_flash[BLUE_TYPE_EAR][loop] +g_AppMainData.if_flash[BLUE_TYPE_USB][loop] > 0)
|
|
229
|
253
|
{
|
|
230
|
254
|
pStaticSn[loop]->EnableWindow(TRUE);
|
|
...
|
...
|
@@ -243,18 +267,8 @@ void CBlueFlashToolDlg::UpdateGroupsCaptions() |
|
243
|
267
|
pcheckButton[BLUE_TYPE_USB][loop]->SetCheck((BOOL) g_AppMainData.if_flash[BLUE_TYPE_USB][loop]);
|
|
244
|
268
|
}
|
|
245
|
269
|
sum_ear = g_AppMainData.if_flash[BLUE_TYPE_EAR][0] + g_AppMainData.if_flash[BLUE_TYPE_EAR][1] + g_AppMainData.if_flash[BLUE_TYPE_EAR][2] + g_AppMainData.if_flash[BLUE_TYPE_EAR][3] + g_AppMainData.if_flash[BLUE_TYPE_EAR][4] + g_AppMainData.if_flash[BLUE_TYPE_EAR][5] + g_AppMainData.if_flash[BLUE_TYPE_EAR][6] + g_AppMainData.if_flash[BLUE_TYPE_EAR][7] + g_AppMainData.if_flash[BLUE_TYPE_EAR][8] + g_AppMainData.if_flash[BLUE_TYPE_EAR][9];
|
|
246
|
|
- pbutton = (CButton *) GetDlgItem(IDC_CHECK_EAR_ALL);
|
|
247
|
|
- if (sum_ear > 0 && sum_ear < 10)
|
|
248
|
|
- pbutton->SetCheck(2);
|
|
249
|
|
- else
|
|
250
|
|
- pbutton->SetCheck((sum_ear / 10) & 0x01);
|
|
251
|
270
|
sum_usb = g_AppMainData.if_flash[BLUE_TYPE_USB][0] + g_AppMainData.if_flash[BLUE_TYPE_USB][1] + g_AppMainData.if_flash[BLUE_TYPE_USB][2] + g_AppMainData.if_flash[BLUE_TYPE_USB][3] + g_AppMainData.if_flash[BLUE_TYPE_USB][4] + g_AppMainData.if_flash[BLUE_TYPE_USB][5] + g_AppMainData.if_flash[BLUE_TYPE_USB][6] + g_AppMainData.if_flash[BLUE_TYPE_USB][7] + g_AppMainData.if_flash[BLUE_TYPE_USB][8] + g_AppMainData.if_flash[BLUE_TYPE_USB][9];
|
|
252
|
|
- pbutton = (CButton *) GetDlgItem(IDC_CHECK_USB_ALL);
|
|
253
|
|
- if (sum_usb > 0 && sum_usb < 10)
|
|
254
|
|
- pbutton->SetCheck(2);
|
|
255
|
|
- else
|
|
256
|
|
- pbutton->SetCheck((sum_usb / 10) & 0x01);
|
|
257
|
|
- GetDlgItem(IDC_BUTTON_INIT_COMPORT)->EnableWindow(sum_ear + sum_usb > 0 ? TRUE: FALSE);
|
|
|
271
|
+ GetDlgItem(IDC_START_ALL)->EnableWindow(sum_ear + sum_usb > 0 ? TRUE: FALSE);
|
|
258
|
272
|
}
|
|
259
|
273
|
|
|
260
|
274
|
|
|
...
|
...
|
@@ -276,13 +290,12 @@ void CBlueFlashToolDlg::OnCommMscommDebug() |
|
276
|
290
|
void CBlueFlashToolDlg::OnBnClickedButtonInitComport()
|
|
277
|
291
|
{
|
|
278
|
292
|
int loop = 0;
|
|
279
|
|
- for (loop = 0; loop < 10; ++loop)
|
|
|
293
|
+ for (loop = 0; loop < 10; loop++)
|
|
280
|
294
|
{
|
|
281
|
|
- if (g_AppMainData.if_flash[BLUE_TYPE_EAR][loop])
|
|
282
|
295
|
OpenComport(BLUE_TYPE_EAR,loop);
|
|
283
|
|
- if (g_AppMainData.if_flash[BLUE_TYPE_USB][loop])
|
|
284
|
296
|
OpenComport(BLUE_TYPE_USB,loop);
|
|
285
|
297
|
}
|
|
|
298
|
+ UpdateGroupsCaptions();
|
|
286
|
299
|
}
|
|
287
|
300
|
|
|
288
|
301
|
void CBlueFlashToolDlg::OnBnClickedCheckEarUsb()
|
|
...
|
...
|
@@ -301,50 +314,53 @@ void CBlueFlashToolDlg::OnBnClickedCheckEarUsb() |
|
301
|
314
|
void CBlueFlashToolDlg::OnBnClickedButtonStartUsbEar()
|
|
302
|
315
|
{
|
|
303
|
316
|
int currentID;
|
|
|
317
|
+ BLUE_DEVICE_TYPE aDeviceType;
|
|
|
318
|
+ int aIndex;
|
|
|
319
|
+ CString strText;
|
|
|
320
|
+
|
|
304
|
321
|
currentID = GetFocus()->GetDlgCtrlID();
|
|
305
|
322
|
if (currentID >= IDC_BUTTON_START_EAR1 && currentID <= IDC_BUTTON_START_EAR10)
|
|
306
|
|
- SendFileToComPort(BLUE_TYPE_EAR, currentID-IDC_BUTTON_START_EAR1);
|
|
|
323
|
+ {
|
|
|
324
|
+ aDeviceType = BLUE_TYPE_EAR;
|
|
|
325
|
+ aIndex = currentID - IDC_BUTTON_START_EAR1;
|
|
|
326
|
+ myThreadData[aDeviceType][aIndex].Filename = g_AppMainData.FilePathEar;
|
|
|
327
|
+ }
|
|
307
|
328
|
else if (currentID >= IDC_BUTTON_START_USB1 && currentID <= IDC_BUTTON_START_USB1)
|
|
308
|
|
- SendFileToComPort(BLUE_TYPE_USB, currentID-IDC_BUTTON_START_USB1);
|
|
309
|
|
-}
|
|
310
|
|
-
|
|
311
|
|
-
|
|
312
|
|
-void CBlueFlashToolDlg::OnBnClickedCheckEarUsbAll()
|
|
313
|
|
-{
|
|
314
|
|
- int loop,check_all;
|
|
315
|
|
- int currentID = GetFocus()->GetDlgCtrlID();
|
|
316
|
|
- CButton *pbutton = (CButton*)GetDlgItem(currentID);
|
|
317
|
|
- check_all = pbutton->GetCheck();
|
|
318
|
|
- if (check_all != 2 )
|
|
319
|
329
|
{
|
|
320
|
|
- for (loop=0;loop<10;loop++)
|
|
321
|
|
- {
|
|
322
|
|
- if (currentID == IDC_CHECK_EAR_ALL)
|
|
323
|
|
- g_AppMainData.if_flash[BLUE_TYPE_EAR][loop] = check_all;
|
|
324
|
|
- else
|
|
325
|
|
- g_AppMainData.if_flash[BLUE_TYPE_USB][loop] = check_all;
|
|
326
|
|
- }
|
|
327
|
|
- UpdateGroupsCaptions();
|
|
|
330
|
+ aDeviceType = BLUE_TYPE_USB;
|
|
|
331
|
+ aIndex = currentID - IDC_BUTTON_START_USB1;
|
|
|
332
|
+ myThreadData[aDeviceType][aIndex].Filename = g_AppMainData.FilePathUsb;
|
|
328
|
333
|
}
|
|
|
334
|
+ ((CWnd*)GetDlgItem(currentID))->GetWindowText(strText);
|
|
|
335
|
+ if (strText == "开始")
|
|
|
336
|
+ {
|
|
|
337
|
+ //pThreadData = new FLASH_THREAD_DATA;
|
|
|
338
|
+ myThreadData[aDeviceType][aIndex].pDlg = this;
|
|
|
339
|
+ myThreadData[aDeviceType][aIndex].blue_device_type = (BYTE)aDeviceType;
|
|
|
340
|
+ myThreadData[aDeviceType][aIndex].nIndex = aIndex;
|
|
|
341
|
+ myThreadData[aDeviceType][aIndex].StopThread = false;
|
|
|
342
|
+ myThreadData[aDeviceType][aIndex].pctrlMSComm = pctrlMSComm[aDeviceType][aIndex];
|
|
|
343
|
+ myThreadData[aDeviceType][aIndex].m_hThread = AfxBeginThread(BlueFlashThreadProc, &myThreadData[aDeviceType][aIndex]);
|
|
|
344
|
+ GetDlgItem(currentID)->SetWindowText("停止");
|
|
|
345
|
+ }
|
|
|
346
|
+ else if (strText == "停止")
|
|
|
347
|
+ {
|
|
|
348
|
+ //DWORD threadExitcode;
|
|
|
349
|
+ //GetExitCodeThread(m_hThread[aDeviceType][aIndex], &threadExitcode);
|
|
|
350
|
+ //if (threadExitcode == STILL_ACTIVE) TerminateThread(m_hThread[aDeviceType][aIndex], 0);
|
|
|
351
|
+ myThreadData[aDeviceType][aIndex].StopThread = true;
|
|
|
352
|
+ }
|
|
|
353
|
+
|
|
|
354
|
+
|
|
|
355
|
+
|
|
|
356
|
+
|
|
329
|
357
|
}
|
|
330
|
358
|
|
|
|
359
|
+
|
|
331
|
360
|
void CBlueFlashToolDlg::OnDestroy()
|
|
332
|
361
|
{
|
|
333
|
362
|
CDialog::OnDestroy();
|
|
334
|
363
|
|
|
335
|
|
- for (int loop =0;loop<10;loop++)
|
|
336
|
|
- {
|
|
337
|
|
- if (myBufferOfBin[BLUE_TYPE_EAR][loop] != NULL)
|
|
338
|
|
- {
|
|
339
|
|
- delete myBufferOfBin[BLUE_TYPE_EAR][loop];
|
|
340
|
|
- myBufferOfBin[BLUE_TYPE_EAR][loop] = NULL;
|
|
341
|
|
- }
|
|
342
|
|
- if (myBufferOfBin[BLUE_TYPE_EAR][loop] != NULL)
|
|
343
|
|
- {
|
|
344
|
|
- delete myBufferOfBin[BLUE_TYPE_USB][loop];
|
|
345
|
|
- myBufferOfBin[BLUE_TYPE_USB][loop] = NULL;
|
|
346
|
|
- }
|
|
347
|
|
- }
|
|
348
|
364
|
g_pmainapp->SaveConfigs();
|
|
349
|
365
|
|
|
350
|
366
|
}
|
|
...
|
...
|
@@ -357,11 +373,9 @@ bool CBlueFlashToolDlg::OpenComport(BLUE_DEVICE_TYPE earOrUsb, int index) |
|
357
|
373
|
int comopen_port;
|
|
358
|
374
|
CMSComm *pctrlComToOpen = pctrlMSComm[BLUE_TYPE_EAR][index];
|
|
359
|
375
|
|
|
360
|
|
- if(g_AppMainData.if_flash[BLUE_TYPE_EAR][loop] == 0) return false;
|
|
361
|
376
|
m_strSettings.Format("%d,n,8,1", g_AppMainData.com_config.aBandrate);
|
|
362
|
377
|
|
|
363
|
378
|
comopen_port =g_AppMainData.ary_myComPort[BLUE_TYPE_EAR][index] ;
|
|
364
|
|
- if (g_AppMainData.if_flash[BLUE_TYPE_EAR][loop] == 0) return false;
|
|
365
|
379
|
|
|
366
|
380
|
DBG_print("开始打开端口 %d",comopen_port);
|
|
367
|
381
|
if (comopen_port<2)
|
|
...
|
...
|
@@ -370,28 +384,39 @@ bool CBlueFlashToolDlg::OpenComport(BLUE_DEVICE_TYPE earOrUsb, int index) |
|
370
|
384
|
return false;
|
|
371
|
385
|
}
|
|
372
|
386
|
if (pctrlComToOpen->GetPortOpen())
|
|
373
|
|
- pctrlComToOpen->SetPortOpen(FALSE);
|
|
|
387
|
+ {
|
|
|
388
|
+ if (pctrlComToOpen->GetCommPort() == comopen_port)
|
|
|
389
|
+ {
|
|
|
390
|
+ DBG_print("该串口已打开,请勿重复打开!\r\n");
|
|
|
391
|
+ return TRUE;
|
|
|
392
|
+ }
|
|
|
393
|
+ }
|
|
|
394
|
+ //参数1表示每当串口接收缓冲区中有多于或等于1个字符时将引发一个接收数据的OnComm事件
|
|
374
|
395
|
pctrlComToOpen->SetCommPort(comopen_port); //选择com1
|
|
|
396
|
+ pctrlComToOpen->SetInputMode(1);
|
|
|
397
|
+ pctrlComToOpen->SetInputLen(512); //设置当前接收区数据长度为0
|
|
|
398
|
+ pctrlComToOpen->SetOutBufferSize(512);//设置当前接收区数据长度为0
|
|
|
399
|
+ pctrlComToOpen->SetSettings(m_strSettings); //波特率9600,无校验,8个数据位,1个停止位
|
|
|
400
|
+ DBG_print("设置串口配置 %s",m_strSettings );
|
|
|
401
|
+
|
|
375
|
402
|
if (!pctrlComToOpen->GetPortOpen())
|
|
376
|
403
|
{
|
|
377
|
|
- DBG_print("串口打开成功 %d",comopen_port);
|
|
378
|
|
- pctrlComToOpen->SetPortOpen(TRUE); //打开串口
|
|
|
404
|
+ if (QuerySingleSerialPortEx(comopen_port))
|
|
|
405
|
+ {
|
|
|
406
|
+ DBG_print("串口打开成功 %d",comopen_port);
|
|
|
407
|
+ pctrlComToOpen->SetPortOpen(TRUE); //打开串口
|
|
|
408
|
+ pctrlComToOpen->SetRThreshold(1);
|
|
|
409
|
+ ifUartEnable[earOrUsb][index] = true;
|
|
|
410
|
+ }
|
|
379
|
411
|
}
|
|
380
|
412
|
else
|
|
381
|
413
|
{
|
|
382
|
414
|
DBG_print("串口%d无法打开",comopen_port );
|
|
383
|
415
|
g_AppMainData.if_flash[BLUE_TYPE_EAR][loop] = 0;
|
|
384
|
416
|
g_AppMainData.ary_myComPort[BLUE_TYPE_EAR][loop]=0;
|
|
385
|
|
- UpdateGroupsCaptions();
|
|
|
417
|
+ ifUartEnable[earOrUsb][index] = false;
|
|
386
|
418
|
}
|
|
387
|
|
- pctrlComToOpen->SetSettings(m_strSettings); //波特率9600,无校验,8个数据位,1个停止位
|
|
388
|
|
- DBG_print("设置串口配置 %s",m_strSettings );
|
|
389
|
|
- pctrlComToOpen->SetRThreshold(1);
|
|
390
|
419
|
|
|
391
|
|
- //参数1表示每当串口接收缓冲区中有多于或等于1个字符时将引发一个接收数据的OnComm事件
|
|
392
|
|
- pctrlComToOpen->SetInputMode(1);
|
|
393
|
|
- pctrlComToOpen->SetInputLen(1024); //设置当前接收区数据长度为0
|
|
394
|
|
- pctrlComToOpen->SetOutBufferSize(4096);//设置当前接收区数据长度为0
|
|
395
|
420
|
|
|
396
|
421
|
pctrlComToOpen->GetInput(); //先预读缓冲区以清除残留数据
|
|
397
|
422
|
return true;
|
|
...
|
...
|
@@ -435,9 +460,176 @@ void CBlueFlashToolDlg::OnCommMscomm1() |
|
435
|
460
|
}
|
|
436
|
461
|
|
|
437
|
462
|
|
|
|
463
|
+UINT BlueFlashThreadProc(LPVOID lParam)
|
|
|
464
|
+{
|
|
|
465
|
+ FLASH_THREAD_DATA* pThreadData = (FLASH_THREAD_DATA*)lParam;
|
|
|
466
|
+ BLUE_DEVICE_TYPE aDeviceType ;//设备类型
|
|
|
467
|
+ int aIndex; //设备索引
|
|
|
468
|
+ BYTE ByteBuf_512[1 * 512]; //每次读取文件buf为512
|
|
|
469
|
+ CByteArray ByteArray_512; //每次发送文件array为512
|
|
|
470
|
+ DWORD Length; //文件长度
|
|
|
471
|
+ int numParts;// 文件被分割的块数
|
|
|
472
|
+ int Partsremain ;// 按512分割之后的尾数
|
|
|
473
|
+ int loop; //循环读取文件的计数器
|
|
|
474
|
+ CMSComm *pctrlMSComm;
|
|
|
475
|
+
|
|
|
476
|
+
|
|
|
477
|
+
|
|
|
478
|
+
|
|
|
479
|
+ if(lParam == NULL) return -1; //如果线程参数位空, 直接退出
|
|
|
480
|
+ aDeviceType = (BLUE_DEVICE_TYPE)pThreadData->blue_device_type;
|
|
|
481
|
+ aIndex = pThreadData->nIndex;
|
|
|
482
|
+ pctrlMSComm = pThreadData->pctrlMSComm;
|
|
|
483
|
+ if (pctrlMSComm == NULL) return -1;
|
|
|
484
|
+
|
|
|
485
|
+
|
|
|
486
|
+ CFile MyFile1(pThreadData->Filename,CFile::modeRead);
|
|
|
487
|
+ //获得文件大小
|
|
|
488
|
+ Length = MyFile1.GetLength();
|
|
|
489
|
+ numParts = Length/512; //文件按512分割块数
|
|
|
490
|
+ Partsremain = Length%512; //文件分割之后的尾数
|
|
|
491
|
+
|
|
|
492
|
+
|
|
|
493
|
+
|
|
|
494
|
+ for(loop=0;loop<numParts;loop++)
|
|
|
495
|
+ {
|
|
|
496
|
+ if (pThreadData->StopThread)
|
|
|
497
|
+ {// 检查是否有停止指令
|
|
|
498
|
+ MyFile1.Close();
|
|
|
499
|
+ ByteArray_512.RemoveAll();
|
|
|
500
|
+ pThreadData->pDlg->pButton[aDeviceType][aIndex]->SetWindowText("开始");
|
|
|
501
|
+ return 0;
|
|
|
502
|
+ }
|
|
|
503
|
+
|
|
|
504
|
+ MyFile1.Seek(loop*512,CFile::begin);
|
|
|
505
|
+ MyFile1.Read(ByteBuf_512,512);
|
|
|
506
|
+ ByteArray_512.SetSize(1 * 512);
|
|
|
507
|
+ for (int i= 0;i < 512; i++)
|
|
|
508
|
+ ByteArray_512.SetAt(i, ByteBuf_512[i]); //把buf的1k数据转化为十六进制到array中,用于串口发送
|
|
|
509
|
+ pctrlMSComm->SetOutput((COleVariant) ByteArray_512); //发送
|
|
|
510
|
+ Sleep (2); //等待接收端接收
|
|
|
511
|
+ ::SendMessage(pThreadData->pDlg->m_hWnd,WM_UPDATEPOS,pThreadData->blue_device_type*10+pThreadData->nIndex,loop*100/numParts);
|
|
|
512
|
+ }
|
|
|
513
|
+ if (Partsremain>0)
|
|
|
514
|
+ {
|
|
|
515
|
+ MyFile1.Seek(loop*512,CFile::begin);
|
|
|
516
|
+ MyFile1.Read(ByteBuf_512,Partsremain);
|
|
|
517
|
+ ByteArray_512.SetSize(1 * Partsremain);
|
|
|
518
|
+ for (int i= 0; i < 1 * Partsremain; i++)
|
|
|
519
|
+ ByteArray_512.SetAt(i, ByteBuf_512[i]); //把buf的1k数据转化为十六进制到array中,用于串口发送
|
|
|
520
|
+ pctrlMSComm->SetOutput((COleVariant) ByteArray_512); //发送
|
|
|
521
|
+ }
|
|
|
522
|
+ Sleep(1000); //等待接收端写30M数据到文件中
|
|
|
523
|
+ ::SendMessage(pThreadData->pDlg->m_hWnd,WM_UPDATEPOS,pThreadData->blue_device_type*10+pThreadData->nIndex,100);
|
|
|
524
|
+ //任务结束, 清理现场
|
|
|
525
|
+ MyFile1.Close();
|
|
|
526
|
+ ByteArray_512.RemoveAll();
|
|
|
527
|
+ pThreadData->pDlg->pButton[aDeviceType][aIndex]->SetWindowText("开始");
|
|
|
528
|
+ return 0;
|
|
|
529
|
+}
|
|
|
530
|
+
|
|
438
|
531
|
|
|
439
|
532
|
|
|
440
|
533
|
bool CBlueFlashToolDlg::SendFileToComPort(BLUE_DEVICE_TYPE earOrUsb, int index)
|
|
441
|
534
|
{
|
|
442
|
535
|
return false;
|
|
443
|
536
|
}
|
|
|
537
|
+
|
|
|
538
|
+#if xiemeng_othd
|
|
|
539
|
+
|
|
|
540
|
+
|
|
|
541
|
+void Funcfromnet(void)
|
|
|
542
|
+
|
|
|
543
|
+{
|
|
|
544
|
+ FILE * pSENDFILE = _wfopen(m_edit_chosefile, _T("rb")); //以二进制打开待发送文件的的文件指针
|
|
|
545
|
+
|
|
|
546
|
+ fseek(pSENDFILE, 0, SEEK_END);
|
|
|
547
|
+ int len = ftell(pSENDFILE);
|
|
|
548
|
+
|
|
|
549
|
+ fseek(pSENDFILE, 0, SEEK_SET);
|
|
|
550
|
+ if (len > (30 * 1024 * 1024)) //如果待发送文件大于30M
|
|
|
551
|
+ {
|
|
|
552
|
+ int bigloop = len / (30 * 1024 * 1024); //一共有bigloop个30M
|
|
|
553
|
+ int bigremain = len % (30 * 1024 * 1024); //发送bigloop个30M之后还bigremain个字节
|
|
|
554
|
+
|
|
|
555
|
+ for (int i = 0; i < bigloop; i++) //每次循环发送30M,循环结束代表发送完成了bigloop次30M文件
|
|
|
556
|
+ {
|
|
|
557
|
+ BYTE ByteBuf_1K[1 * 1024]; //每次读取文件buf为1k
|
|
|
558
|
+ CByteArray ByteArray_1K; //每次发送文件array为1k
|
|
|
559
|
+
|
|
|
560
|
+ ByteArray_1K.SetSize(1 * 1024);
|
|
|
561
|
+ for (int j = 0; j < (30 * 1024); j++) //这个循环实现发送30M文件
|
|
|
562
|
+ {
|
|
|
563
|
+ fread (ByteBuf_1K, 1 * 1024, 1, pSENDFILE); //从文件读取1k数据到buf中
|
|
|
564
|
+ for (int k = 0; k < 1 * 1024; k++) ByteArray_1K.SetAt(k, ByteBuf_1K[k]); //把buf的1k数据转化为十六进制到array中,用于串口发送
|
|
|
565
|
+ m_mscomm.put_Output((COleVariant) ByteArray_1K); //发送
|
|
|
566
|
+ Sleep (2); //等待接收端接收
|
|
|
567
|
+ }
|
|
|
568
|
+ Sleep(2000); //等待接收端写30M数据到文件中
|
|
|
569
|
+ }
|
|
|
570
|
+
|
|
|
571
|
+ /*发送bigloop次30M之后,如果剩余数据大于1K*/
|
|
|
572
|
+ if (bigremain > 1 * 1024)
|
|
|
573
|
+ {
|
|
|
574
|
+ int smallloop = bigremain / (1 * 1024); //需要发送loop次
|
|
|
575
|
+ int smallremain = bigremain % (1 * 1024); ///发送loop次之后还剩remain个字节
|
|
|
576
|
+ BYTE ByteBuf_1K[1 * 1024]; //这个buf用来存从待发送文件独读出来的数据
|
|
|
577
|
+ CByteArray ByteArray_1K; //这个array用来存待发送文件十六进制数据
|
|
|
578
|
+
|
|
|
579
|
+ ByteArray_1K.SetSize(1 * 1024); //一次发送1k数据
|
|
|
580
|
+ for (int i = 0; i < smallloop; i++)
|
|
|
581
|
+ {
|
|
|
582
|
+ fread(ByteBuf_1K, 1 * 1024, 1, pSENDFILE); //把待发送文件的第loop个4k以二进制读取在buf里
|
|
|
583
|
+ for (int k = 0; k < (1 * 1024); k++)
|
|
|
584
|
+ ByteArray_1K.SetAt(k, ByteBuf_1K[k]); //把buf里的字符以十六进制存在array里
|
|
|
585
|
+ m_mscomm.put_Output((COleVariant) ByteArray_1K); //发送
|
|
|
586
|
+ Sleep(2); //等待接收方写文件所需时间,否则会有乱码;这个时间过大会阻塞,过小会丢包
|
|
|
587
|
+ }
|
|
|
588
|
+
|
|
|
589
|
+ /*发送剩余的smallremain个字节*/
|
|
|
590
|
+ BYTE * bufremain;
|
|
|
591
|
+
|
|
|
592
|
+ bufremain = new BYTE[smallremain]; //new1个数组,发送剩余数据
|
|
|
593
|
+ CByteArray arrayremain; //装剩余数据的十六进制
|
|
|
594
|
+
|
|
|
595
|
+ arrayremain.SetSize(smallremain);
|
|
|
596
|
+ fread(bufremain, smallremain, 1, pSENDFILE); //读取剩余数据
|
|
|
597
|
+ for (int l = 0; l < smallremain; l++) //转换数据为CByteArray类型
|
|
|
598
|
+ arrayremain.SetAt(l, bufremain[l]);
|
|
|
599
|
+ m_mscomm.put_Output((COleVariant) arrayremain); //发送剩余数据
|
|
|
600
|
+ Sleep(200); //短暂休眠
|
|
|
601
|
+ delete bufremain; //回收bufremain
|
|
|
602
|
+ fclose(pSENDFILE); //关闭文件指针
|
|
|
603
|
+ }
|
|
|
604
|
+
|
|
|
605
|
+ /*发送bigloop次30M之后,如果剩余数据小于1K*/
|
|
|
606
|
+ else
|
|
|
607
|
+ {
|
|
|
608
|
+ BYTE * buf;
|
|
|
609
|
+
|
|
|
610
|
+ buf = new BYTE[bigremain]; //new一个buf来存从文件指针读取的数据
|
|
|
611
|
+ fread(buf, bigremain, 1, pSENDFILE); //读取待发送文件数据,存在buf里面
|
|
|
612
|
+ CByteArray array; //用来保存发送数据的十六进制形式
|
|
|
613
|
+
|
|
|
614
|
+ array.SetSize(bigremain); //给array设置大小,这个大小为待发送文件的字节数
|
|
|
615
|
+ for (int m = 0; m < bigremain; m++)
|
|
|
616
|
+ array.SetAt(m, buf[m]); //数据转十六进制
|
|
|
617
|
+ m_mscomm.put_Output((COleVariant) array); //发送数据
|
|
|
618
|
+ Sleep(200); //短暂睡眠,可以不取
|
|
|
619
|
+ delete buf; //回收
|
|
|
620
|
+ array.RemoveAll(); //关闭文件指针
|
|
|
621
|
+ fclose(pSENDFILE);
|
|
|
622
|
+ }
|
|
|
623
|
+ }
|
|
|
624
|
+}
|
|
|
625
|
+
|
|
|
626
|
+
|
|
|
627
|
+#endif
|
|
|
628
|
+
|
|
|
629
|
+LRESULT CBlueFlashToolDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
630
|
+{
|
|
|
631
|
+ //响应自定义消息
|
|
|
632
|
+ if(message == WM_UPDATEPOS)
|
|
|
633
|
+ pProcess[wParam/10][wParam%10]->SetPos(lParam);
|
|
|
634
|
+ return CDialog::WindowProc(message, wParam, lParam);
|
|
|
635
|
+} |
...
|
...
|
|