📄 testsddlg.cpp
字号:
// TestSDDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TestSD.h"
#include "TestSDDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define FILESIZE (2601)
/////////////////////////////////////////////////////////////////////////////
// CTestSDDlg dialog
DWORD g_dwListCount;
DWORD g_dwCount;
DWORD g_dwCount2;
CTestSDDlg::CTestSDDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestSDDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestSDDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestSDDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestSDDlg)
DDX_Control(pDX, IDC_LIST2, m_sys_msg_error);
DDX_Control(pDX, IDC_LIST1, m_sys_msg);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestSDDlg, CDialog)
//{{AFX_MSG_MAP(CTestSDDlg)
ON_BN_CLICKED(IDC_TEST, OnTest)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestSDDlg message handlers
BOOL CTestSDDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
standFileName = L"\\SD_CheckFile.zip";
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestSDDlg::OnTest()
{
HANDLE hCopyFileThread = CreateThread(NULL,0,CopyFileThread,this,0,NULL);
CloseHandle(hCopyFileThread);
}
void CTestSDDlg::OnCancel()
{
CDialog::OnCancel();
}
DWORD CTestSDDlg::CopyFileThread(LPVOID lparam)
{
CTestSDDlg *pDlg = (CTestSDDlg*)lparam;
pDlg->GetDlgItem(IDC_TEST)->EnableWindow(FALSE);
LPCTSTR sdFileName = L"\\Storage Card\\NPU_SD_Test.zip";;
LPCTSTR nandFileName = L"\\NPU_SD_Test.zip";
BOOL ret = FALSE;
CString str;
UINT errtimes = 0;
UINT errortimes2 = 0;
UINT errorList = 0;
int nCount = 0;
SYSTEMTIME time;
GetLocalTime(&time);
CString stim;
stim.Format(L"Program start run time: %02d:%02d:%02d ",time.wHour,time.wMinute,time.wSecond);
pDlg->m_sys_msg.InsertString(g_dwListCount++,stim);
START:
//从SD卡拷贝文件到nandflash
SYSTEMTIME time1;
GetLocalTime(&time1);
stim.Format(_T("SD->SDRAM %ld Start"),g_dwCount+1);
pDlg->m_sys_msg.InsertString(g_dwListCount++,stim);
nCount = pDlg->m_sys_msg.GetCount();
pDlg->m_sys_msg.SetCurSel(nCount-1);
COPY_SD_TO_RAM:
//Copy File function
ret = CopyFile(sdFileName,nandFileName,FALSE);
if (ret == FALSE)
{
errtimes++;
if (errtimes == 4)
{
AfxMessageBox(L"SD->RAM Try 3 times,also error!");
return FALSE;
}
DWORD error = GetLastError();
str.Format(L"SD->SDRAM error! at %ld,error is %ld",g_dwCount+1,error);
pDlg->m_sys_msg_error.InsertString(errorList++,str);
nCount = pDlg->m_sys_msg_error.GetCount();
pDlg->m_sys_msg_error.SetCurSel(nCount-1);
goto COPY_SD_TO_RAM;
}
SYSTEMTIME time2;
GetLocalTime(&time2);
stim.Format(_T("SD->SDRAM %ld End"),g_dwCount+1);
pDlg->m_sys_msg.InsertString(g_dwListCount++,stim);
nCount = pDlg->m_sys_msg.GetCount();
pDlg->m_sys_msg.SetCurSel(nCount-1);
//SD->SDRAM 的速度粗略计算
stim.Format(_T("SD->SDRAM rate is %d KB/S"),FILESIZE/((time2.wHour-time1.wHour)*60*60
+(time2.wMinute-time1.wMinute)*60+(time2.wSecond-time1.wSecond)));
pDlg->m_sys_msg.InsertString(g_dwListCount++,stim);
nCount = pDlg->m_sys_msg.GetCount();
pDlg->m_sys_msg.SetCurSel(nCount-1);
//校验文件
pDlg->CheckFile(pDlg->standFileName,nandFileName);
//从SDRAM拷贝文件到SD卡
SYSTEMTIME time3;
GetLocalTime(&time3);
stim.Format(_T("SDRAM->SD %ld Start"),g_dwCount+1);
pDlg->m_sys_msg.InsertString(g_dwListCount++,stim);
nCount = pDlg->m_sys_msg.GetCount();
pDlg->m_sys_msg.SetCurSel(nCount-1);
COPY_RAM_TO_SD:
//Copy File function
ret = CopyFile(nandFileName,sdFileName,FALSE);
if (ret == FALSE)
{
errortimes2++;
if (errortimes2 == 4)
{
AfxMessageBox(L"Try 3 times also error!");
return FALSE;
}
DWORD error2 = GetLastError();
str.Format(L"SDRAM->SD error! at %ld ,error is %ld",g_dwCount+1,error2);
pDlg->m_sys_msg_error.InsertString(errorList++,str);
nCount = pDlg->m_sys_msg_error.GetCount();
pDlg->m_sys_msg.SetCurSel(nCount-1);
goto COPY_RAM_TO_SD;
}
SYSTEMTIME time4;
GetLocalTime(&time4);
stim.Format(_T("SDRAM->SD %ld End"),g_dwCount+1);
pDlg->m_sys_msg.InsertString(g_dwListCount++,stim);
nCount = pDlg->m_sys_msg.GetCount();
pDlg->m_sys_msg.SetCurSel(nCount-1);
//SDRAM->SD 的速度粗略计算
stim.Format(_T("SDRAM->SD rate is %d KB/S"),FILESIZE/((time4.wHour-time3.wHour)*60*60
+(time4.wMinute-time3.wMinute)*60+(time4.wSecond-time3.wSecond)));
pDlg->m_sys_msg.InsertString(g_dwListCount++,stim);
nCount = pDlg->m_sys_msg.GetCount();
pDlg->m_sys_msg.SetCurSel(nCount-1);
g_dwCount++;
goto START;
return TRUE;
}
DWORD CTestSDDlg::CheckFileThread(LPVOID lparam)
{
return TRUE;
}
BOOL CTestSDDlg::CheckFile(LPCTSTR fileName1, LPCTSTR fileName2)
{
CFile file1;
if (!file1.Open(fileName1,CFile::modeRead | CFile::typeBinary))
{
AfxMessageBox(_T("open file1 error!"));
return FALSE;
}
CFile file2;
if (!file2.Open(fileName2,CFile::modeRead | CFile::typeBinary))
{
AfxMessageBox(_T("open file2 error!"));
return FALSE;
}
DWORD fileLenth1 = file1.GetLength();
DWORD fileLenth2 = file2.GetLength();
CString str;
BYTE pdata1[4096];
BYTE pdata2[4096];
UINT nCount = fileLenth1/4096;
UINT nCount2 = fileLenth1-nCount*4096;
if (fileLenth1 == fileLenth2)
{
for (int i=0;i<nCount;i++)
{
file1.Read(pdata1,4096);
file2.Read(pdata2,4096);
for (int j=0;j<4096;j++)
{
if ((pdata1[j]) == (pdata2[j]))
{
continue;
}
else
{
str.Format(_T("two file are not same.......at %ld "),g_dwCount);
AfxMessageBox(str);
break;
}
}
}
file1.Read(pdata1,4096);
file2.Read(pdata2,4096);
for(int k=0;k<nCount2;k++)
{
if ((pdata1[k]) == (pdata2[k]))
{
continue;
}
else
{
str.Format(_T("two file are not same.......at %ld "),g_dwCount);
AfxMessageBox(str);
break;
}
}
}
else
{
str.Format(_T("two file are not same.......at %ld "),g_dwCount);
AfxMessageBox(str);
return FALSE;
}
str.Format(_T("check file success!....."));
m_sys_msg.InsertString(g_dwListCount++,str);
file1.Close();
file2.Close();
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -