御坂19078吧 关注:1贴子:50
  • 2回复贴,共1
void CMyDlg::OnBTNCheckFile() {CFileDialog dlg(TRUE, NULL, _T(""), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("数据文件(*.DAT)|*.Dat|所有文件(*.*)|*.*||")); dlg.m_ofn.lStructSize = 88; if (dlg.DoModal() != IDCANCEL){CString fn;CString strTmp;CString rname;CString describes[15];CFile fpreport[2];CFile fp1, fp2;char lf[] = {0x0D, 0x0A, '\0'};int nn, iLen;int lostCnt,errorCnt;unsigned long lFrmCnt, lPFC,firstEB90=0;unsigned long lFrmCnt2, lPFC2,firstEB902=0;long i,flag146f=-2;bool zhenFlag=FALSE;bool zhenFlag2=FALSE;char buf[256];
HANDLEhFile;DWORDdwFileSize;PVOIDpvFile;HANDLEhFileMap;unsigned char* pData;fn = dlg.GetFileName();//步骤1: 打开文件hFile = CreateFile(fn, GENERIC_WRITE | GENERIC_READ,0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);if (hFile == INVALID_HANDLE_VALUE)// 文件打开失败返回句柄为-1{MessageBox("文件打开失败~!\n");return;}// 步骤2 建立内存映射文件dwFileSize = GetFileSize(hFile, NULL);hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0,NULL);if (hFileMap == NULL){MessageBox("内存映射文件创建失败~!\n");return;}// 步骤3:将文件数据映射到进程的地址空间pvFile = MapViewOfFile( hFileMap, FILE_MAP_WRITE, 0, 0, 0); if (pvFile == NULL){MessageBox("文件数据映射到进程的地址失败~!\n");return;}// 步骤4: 像操作内存一样操作文件pData = (unsigned char*)pvFile;
fn.MakeUpper();fn.Replace(_T(".DAT"), _T(".LOG"));
CFileFind finder;if (finder.FindFile(fn)){if(IDNO==MessageBox("检查结果已经存在!是否重新检查?",NULL,MB_YESNO)){ShellExecute(m_hWnd,"open","notepad.exe",fn,"",SW_SHOW );return;}
}
fp2.Open(fn, CFile::modeCreate | CFile::modeWrite);lPFC = -1;lFrmCnt=0;lostCnt = 0;lPFC2 = -1;lFrmCnt2=0;errorCnt = 0;SetDlgItemText(IDC_BTN_CheckFile, _T("正在检查"));UpdateWindow();for(nn=0;nn<1;nn++){rname.Format(_T("report%d.tmp"),nn);fpreport[nn].Open(rname, CFile::modeCreate | CFile::modeReadWrite);}for (i = 0; i < dwFileSize-600;i++){if((pData[i]==0x14)&&(pData[i+1]==0x6F)&&(pData[i+30+2]==0xEB)&&(pData[i+31+2]==0x90)&&(pData[i+510+2]==0x14)&&(pData[i+511+2]==0x6f))//146f +EB90+ 146f{lFrmCnt = 0x00000000;lFrmCnt += pData[i+470+2];lFrmCnt <<= 8;lFrmCnt += pData[i+471+2];lFrmCnt <<= 8;lFrmCnt += pData[i+502+2];lFrmCnt <<= 8;lFrmCnt += pData[i+503+2];if(zhenFlag){if (lFrmCnt != (lPFC + 1))//将丢帧的位置写入文件{lostCnt++;strTmp.Format(_T(" %s %8X%s%8X"),_T("不连续帧: 开始于:"), lPFC,_T("结束于:"),lFrmCnt);fpreport[0].Write(strTmp, strTmp.GetLength());fpreport[0].Write(lf, 2);}}else{firstEB90 = lFrmCnt;}i+=127;lPFC = lFrmCnt;zhenFlag=TRUE;}
}
describes[0].Format(_T("%s"),_T("一、帧计数范围:"));describes[1].Format(_T("%s"),_T("二、帧一不连续帧报告:"));describes[2].Format(_T("%s"),_T("三、帧二不连续帧报告:"));describes[5].Format(_T("%s"),_T(" 检查结果"));describes[6].Format(_T("%s%d"),_T("帧一不连续次数:"),lostCnt);describes[7].Format(_T("%s%d"),_T("帧二不连续次数:"),errorCnt);describes[8].Format(_T("%s"),_T(" 无 "));
for(i=5;i<7;i++){fp2.Write(describes[i],describes[i].GetLength());fp2.Write(lf, 2);}fp2.Write(lf, 2);fp2.Write(describes[0],describes[0].GetLength());fp2.Write(lf, 2);fp2.Write(lf, 2);strTmp.Format(_T("%s%X%s%X"),_T(" 帧一起始帧:"),firstEB90,_T(" 结束帧:"),lFrmCnt);fp2.Write(strTmp, strTmp.GetLength());fp2.Write(lf, 2);
for(i=0;i<1;i++)//只有一个帧{fp2.Write(lf, 2);fp2.Write(describes[i+1],describes[i+1].GetLength());fp2.Write(lf, 2);fp2.Write(lf, 2);if((i==0)&&(lostCnt==0)){fp2.Write(describes[8],describes[8].GetLength());fp2.Write(lf, 2);}else if((i==1)&&(errorCnt==0)){fp2.Write(describes[8],describes[8].GetLength());fp2.Write(lf, 2);}fpreport[i].Flush();fpreport[i].Seek(0,CFile::begin);do{iLen=fpreport[i].Read(buf,256);fp2.Write(buf,iLen);}while(iLen==256);
fpreport[i].Close();}for(i=0;i<1;i++){strTmp.Format(_T("report%d.tmp"),i);CFile::Remove(strTmp);}fp2.Close();UnmapViewOfFile(pvFile); // 释放内存映射文件的头指针CloseHandle(hFileMap); // 内存映射文件句柄CloseHandle(hFile); // 关闭文件SetDlgItemText(IDC_BTN_CheckFile, _T("检查数据"));ShellExecute(m_hWnd,"open","notepad.exe",fn,"",SW_SHOW );
}}
void CMyDlg::OutputJL(CString str){CTime t = CTime::GetCurrentTime();CString strtemp;strtemp.Format(_T("%02d.%02d.%02d.%02d.%02d.%02d : "), t.GetYear(), t.GetMonth(), t.GetDay(),t.GetHour(),t.GetMinute(),t.GetSecond());m_strJiLv = m_strJiLv + strtemp + str + _T("\r\n");UpdateData(false);}
void CMyDlg::OnSeleDiv1() {// TODO: Add your control notification handler code hereglobal.SeleDiv=1;if (global.DevChoice==1){global.KBLFileName = global.ExePathName + CString(_T("\\param\\5T_设备1.txt"));global.DVDD=5.36;}else{global.KBLFileName = global.ExePathName + CString(_T("\\param\\10T_设备1.txt"));}//GetDlgItem(IDC_DivShow)->SetWindowText("设备1");InitParamData();
}
void CMyDlg::OnSeleDiv2() {// TODO: Add your control notification handler code hereglobal.SeleDiv=2;if (global.DevChoice==1){global.KBLFileName = global.ExePathName + CString(_T("\\param\\5T_设备2.txt"));global.DVDD=5.346;}else{global.KBLFileName = global.ExePathName + CString(_T("\\param\\10T_设备2.txt"));}//GetDlgItem(IDC_DivShow)->SetWindowText("设备2");InitParamData();}void CMyDlg::OnSeleDiv3() {// TODO: Add your control notification handler code hereglobal.SeleDiv=3;if (global.DevChoice==1){global.KBLFileName = global.ExePathName + CString(_T("\\param\\5T_设备3.txt"));global.DVDD=5.299;}else{global.KBLFileName = global.ExePathName + CString(_T("\\param\\10T_设备3.txt"));}//GetDlgItem(IDC_DivShow)->SetWindowText("设备3");InitParamData();}
void CMyDlg::OnDestroy() {CDialog::OnDestroy();// TODO: Add your message handler code herem_DivShowFont.DeleteObject();}
void CMyDlg::On10t() {// TODO: Add your control notification handler code hereglobal.DevChoice=0;if (global.SeleDiv==1){global.KBLFileName = global.ExePathName + CString(_T("\\param\\10T_设备1.txt"));global.DVDD=5.36;}else if (global.SeleDiv==2){global.KBLFileName = global.ExePathName + CString(_T("\\param\\10T_设备2.txt"));global.DVDD=5.346;}else if (global.SeleDiv==3){global.KBLFileName = global.ExePathName + CString(_T("\\param\\10T_设备3.txt"));global.DVDD=5.299;}}
void CMyDlg::On5t() {// TODO: Add your control notification handler code hereglobal.DevChoice=1;if (global.SeleDiv==1){global.KBLFileName = global.ExePathName + CString(_T("\\param\\5T_设备1.txt"));global.DVDD=5.36;}else if (global.SeleDiv==2){global.KBLFileName = global.ExePathName + CString(_T("\\param\\5T_设备2.txt"));global.DVDD=5.346;}else if (global.SeleDiv==3){global.KBLFileName = global.ExePathName + CString(_T("\\param\\5T_设备3.txt"));global.DVDD=5.299;}}
void CMyDlg::OnYuanCHeng() {// TODO: Add your control notification handler code herem_mtype=0;}
void CMyDlg::OnBeiYong() {// TODO: Add your control notification handler code herem_mtype=1;}
void CMyDlg::OnHuiShou() {// TODO: Add your control notification handler code herem_mtype=2;}


IP属地:山西1楼2013-05-09 09:11回复


    来自iPhone客户端2楼2013-05-16 18:51
    回复
      信念提交下贴吧目录哩


      IP属地:安徽3楼2013-06-22 08:26
      回复