⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 想法.cpp

📁 cdma无线通信转发程序 用于电力调度数据的转发
💻 CPP
字号:
int fracountsum=0;
UINT afertproc (void *arg)
{
  static uint reset_count=0;	
  while (live_flag)
    {
    	for (int i=0;i<G_Channel.chan_num;i++) 
		{
		    if (live_flag==FALSE) break;
            if(G_Channel.systype==0)//接收端处理数据
			{
			  RXBUF * recreadbuff;       
              TXBUF *recfilebuff=new TXBUF;
			  memset(recfilebuff, 0, sizeof(TXBUF));
			  int    ptr = 0;
              short   len;
	          uchar   val;
              recreadbuff= &G_Channel.chan_data[i].recrx ;
	          LenRecQ(recreadbuff,&len);
	         if(len>6)
			 {	
                    
				if (len ==0) break;
                ptr = recreadbuff->headP;
				for(int j=0;j<len;j++)
                {		
					    int fracount=0;
						if (recreadbuff->buf[ptr+j]   == 0xeb && 
							recreadbuff->buf[ptr+j+1] == 0x90 &&
                            recreadbuff->buf[ptr+j+2] == 0xeb &&
							recreadbuff->buf[ptr+j+3] == 0x90 &&
							recreadbuff->buf[ptr+j+4] == 0xeb &&
							recreadbuff->buf[ptr+j+5] == 0x90)
						{
							if(j>0){
							for(int k=0;k<j;k++)
							{
							GetRecVal(recreadbuff, &val);
							EnterTrnQ(recfilebuff,val);
							}
							fracount++;
							len=len-j;
							}
							
						}
						else if(recreadbuff->buf[ptr]   == 0xD7 &&
							recreadbuff->buf[ptr+1] == 0x09 &&
							recreadbuff->buf[ptr+2] == 0xD7 &&
							recreadbuff->buf[ptr+3] == 0x09 &&
							recreadbuff->buf[ptr+4] == 0xD7 &&
							recreadbuff->buf[ptr+5] == 0x09)
						{	
							if(j>0){
							for(int k=0;k<j;k++)
							{
							GetRecVal(recreadbuff, &val);
							EnterTrnQ(recfilebuff,val);
							}
							fracount++;
							len=len-j;
							}
						}
					
						fracountsum=fracountsum+fracount;	
						
					}
			  	/*	
				    
				    for(int j=0;j<len;j++)
					{
						int fracount=0;
						if (recreadbuff->buf[ptr+j]   == 0xeb && 
							recreadbuff->buf[ptr+j+1] == 0x90 &&
                            recreadbuff->buf[ptr+j+2] == 0xeb &&
							recreadbuff->buf[ptr+j+3] == 0x90 &&
							recreadbuff->buf[ptr+j+4] == 0xeb &&
							recreadbuff->buf[ptr+j+5] == 0x90)
						{
							if (j>0) {
								for(int k =0;k<j; k++)
								{
									GetRecVal(recreadbuff, &val);
									EnterTrnQ(recfilebuff,val);
								}
								fracount++;
								
								len=len-j;
							}
						}
						else if(recreadbuff->buf[ptr+j]   == 0xD7 &&
							    recreadbuff->buf[ptr+j+1] == 0x09 &&
								recreadbuff->buf[ptr+j+2] == 0xD7 &&
								recreadbuff->buf[ptr+j+3] == 0x09 &&
								recreadbuff->buf[ptr+j+4] == 0xD7 &&
								recreadbuff->buf[ptr+j+5] == 0x09)
						{	
							if (j>0) {
								for(int k =0;k<j; k++)
								{
									GetRecVal(recreadbuff, &val);//这其实都执行了recreadbuff->headP=recreadbuff->headP+j;
									EnterTrnQ(recfilebuff,val);//能用数组??
								}
								fracount++;
								len=len-j;
							}
						}
                        fracountsum=fracountsum+fracount;
                       // recreadbuff->headP=recreadbuff->headP+j;*/					  			

		      
					}
				}
                
                CString str;
		        char strpath[50];
			    GetCurrentDirectory(MAX_PATH,strpath);
				//str.Format("%s\\channeldata\\通道%02d%s.txt",strpath,i,G_Channel.chan_data[i].chanName);//不能用fopen创建文件夹
                str.Format("%s\\通道%02d%s.txt",strpath,i,G_Channel.chan_data[i].chanName);
				if(fracountsum>5)// || fracount%(G_Channel.timeTrig/40) ==0)
				{
					int cnt=0;
			    	char writebuff[1080];
					while(recfilebuff->tailP != recfilebuff->headP)
					{
						uchar value = recfilebuff->buf[recfilebuff->headP];
						writebuff[cnt] = value;
						recfilebuff->headP = (recfilebuff->headP + 1) % TRNLength;
						cnt++;
					}
					if (cnt >0) {
						FILE *fp;//声明文件指针对象
						fp=fopen(str,"a+");
						//fp=fopen("C:\\Program Files\\test.txt","r+");
						if(fp!=NULL) 
						{
							fwrite(writebuff,sizeof(char),cnt,fp);
							fracountsum=0;
						}
						fclose(fp);
					}
			
				}
				delete recfilebuff;
			}
			else if(G_Channel.systype==1)//发送端处理数据(从文件读取数据到G_Channel.chan_data[i].sentx)
			{

				//TXBUF *sendwritebuff=0;
				CString str;
				char strpath[50];
			    GetCurrentDirectory(MAX_PATH,strpath);
				str.Format("%s\\channeldata\\通道%02d%s.txt",strpath,i,G_Channel.chan_data[i].chanName);
				char sendbuff[2048];
				
				FILE *fp;//声明文件指针对象
				fp=fopen(str,"r+");
				if(fp!=NULL) 
				{
					fread(sendbuff,sizeof(char),1080,fp);
				}
				fclose(fp);
				for(int t=0;t<2048;t++)
				{
                 G_Channel.chan_data[i].sentx.buf[t]=sendbuff[t];
				}
			}
			
		}
		Sleep(40);
    }
    return NULL;
}


//***********************************************************
//创建文件夹

一段我用过的代码:   
  CString   strFolderPath="c:\\test"   
  //   判断路径是否存在   
  if   (!PathIsDirectory(m_strFolderPath)   )   
  {   
      CString   strMsg;   
      strMsg.Format   ("指定路径\"%s\"不存在,是否创建?",   m_strFolderPath);   
      if   (AfxMessageBox(strMsg,   MB_YESNO)   ==   IDYES)   
      {   
          if   (!CreateDirectory(m_strFolderPath,   NULL   )   )   
          {   
                strMsg.Format   ("创建路径\"%s\"失败!是否继续?",   m_strFolderPath);   
                if   (AfxMessageBox(strMsg,   MB_YESNO)   ==   IDYES)   
                      return;   
            }   
      }   
  }   
  


一个标准的保存与另存为对话框

BOOL CMainFrame::SaveProject( int saveFlat )
{

 //源地址szResDir
 wchar_t szResDir[MAX_PATH] = {0};

 //目的地址
 wchar_t szDestDir[MAX_PATH] = {0};

 //已经存在的地址
 wchar_t szExistDir[MAX_PATH] = {0};

 

 //普通对话框结构体
 OPENFILENAME ofn;   

 //保存的文件名szFile    

 wchar_t szFile[260];            

 ZeroMemory(&ofn, sizeof(ofn));
 ofn.lStructSize = sizeof(ofn);

 //对话框的Handle,如(CFrameWnd*)AfxGetMainWnd()->m_hWnd

 ofn.hwndOwner = (CFrameWnd*)AfxGetMainWnd()->m_hWnd;
 ofn.lpstrFile = szFile;

 CString folderName = g_lpszXmlName;
 CString fmat;

 //保存文件的后缀
 CString extName;
 fmat.Format(L"%s",L".");
 int filterIndex = 1;

 //搜索是否存在"."
 int num = folderName.Find(fmat);
 fmat = folderName.Left(num);
 int stl = folderName.GetLength();
 int charCount = stl - num;
 extName = folderName.Right(charCount);

 if(saveFlat == 1)
 {
     wsprintf(ofn.lpstrFile,L"%s",L"Executor\0");
 }
 else
 {
  if(wcscmp(extName, L".vxml") == 0)
  {
   filterIndex = 1;
  }
  if(wcscmp(extName, L".xml") == 0)
  {
   filterIndex = 2;
  }
        wsprintf(ofn.lpstrFile,L"%s",fmat);
 }

 //文件路径的最大长度

 ofn.nMaxFile = sizeof(szFile);
 ofn.nFilterIndex = filterIndex;
 ofn.lpstrFileTitle = NULL;
 ofn.nMaxFileTitle = 0;
 ofn.lpstrInitialDir = NULL;

 //对话框类型
ofn.Flags = OFN_NOCHANGEDIR;//OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY

 if(saveFlat == 1)
 {

     //对话框标题
     fn.lpstrTitle = L"保存为";
 }
 else
 {
     ofn.lpstrTitle = L"另存为";
 }
 //对话框过滤器

ofn.lpstrFilter = L"VXML(*.vxml)\0*.vxml\0XML(*.xml)\0*.xml\0";

 //弹出保存对话框

if(GetSaveFileName(&ofn) != TRUE)
 {
  return FALSE;
 }

 wchar_t temp[MAX_PATH] = {0};

 //文件保存所在的驱动器,如C:
 wchar_t drive[_MAX_DRIVE];

 //不包含文件名与驱动器的文件路径
 wchar_t dir[_MAX_DIR];

 //文件名
 wchar_t fname[_MAX_FNAME];

 //文件后缀
 wchar_t ext[_MAX_EXT];
 wchar_t strExtName[MAX_PATH] = {0};
 int extFlat = 0;

 extFlat = ofn.nFilterIndex;

//解析包含文件名的路径szFile

_wsplitpath( szFile, drive, dir, fname, ext );


  if(extFlat == 1)
  {
   wsprintf(strExtName,L"%s",L".vxml");
  }
  else
  {
   wsprintf(strExtName,L"%s",L".xml");
  }


 wchar_t filePath[MAX_PATH] = {0};
 wsprintf(filePath,L"%s\%s",drive,dir);

 CString strSaveFileName = filePath;

 int i = strSaveFileName.GetLength();
 strSaveFileName = strSaveFileName.Left(i-1);

 wsprintf(szExistDir, L"%s\\%s%s",strSaveFileName,fname,strExtName);

//如果路径szExistDir已经存在

 if(_waccess(szExistDir, 0) == 0)
 {
  UINT ret =

::AfxMessageBox( L"此目录下已经存在有相同的数据文件名,是否覆盖现在数据?", MB_YESNO);
  if(ret != IDYES)
  {
   return FALSE;
   }
 }
 else
 {

 }


 wchar_t szResFile[MAX_PATH] = {0};
 wchar_t szDesFile[MAX_PATH] = {0};
 wchar_t xmlPath[MAX_PATH] = {0};
 wchar_t szExDestFile[MAX_PATH] = {0};
 wchar_t szExResFile[MAX_PATH] = {0};

 wsprintf(szDesFile, L"%s",szExistDir);

 //从源路径szResFile复制文件到目标路径szDestFile

 CopyFile(szResFile,szDestFile,FALSE);

 wsprintf(szDestDir, L"%s", strSaveFileName);

 if(saveFlat == 1)
 { 
  wsprintf(szResFile, L"%s\\%s", g_xmlPath, g_defualtXmlName);
  CopyFile(szResFile,szDesFile,FALSE);
  wsprintf(szResDir, L"%s\\%s", g_xmlPath, L"vmd");
  CopyDirToDir(szResDir, szDestDir);

  wsprintf(szResDir, L"%s\\%s", g_xmlPath, L"media");
  CopyDirToDir(szResDir, szDestDir);
 }
 else
 {
  int slen = wcslen(g_xmlPath);
  for(int i=0; i
  {
   if(i >= 3)
    xmlPath[i] = g_xmlPath[i+1];
   else
    xmlPath[i] = g_xmlPath[i];
  }

  wsprintf(m_szSavePath, L"%s", strSaveFileName);
  wsprintf(szResFile, L"%s\%s", xmlPath, g_lpszXmlName);

  if(wcscmp(szDesFile, szResFile) != 0)
    {CopyFile(szResFile,szDesFile,FALSE);}

  wsprintf(szExDestFile, L"%s\\%s", szDestDir, L"vmd");
  wsprintf(szResDir, L"%s\%s", xmlPath, L"vmd");
  if(wcscmp(szExDestFile, szResDir) != 0)
    {CopyDirToDir(szResDir, szDestDir);}

  wsprintf(szExDestFile, L"%s\\%s", szDestDir, L"media");
  wsprintf(szResDir, L"%s\%s", xmlPath, L"media");
  if(wcscmp(szExDestFile, szResDir) != 0)
    {CopyDirToDir(szResDir, szDestDir);}
 }

 wsprintf(g_lpszExePath, L"%s",strSaveFileName);
 wsprintf(g_xmlExecutorPath, L"%s", szDesFile);
 wsprintf(g_lpszXmlName, L"%s%s",fname, strExtName);

 return TRUE;
}

 

BOOL CopyDirToDir(wchar_t   *pszSrcDir,wchar_t   *pszDesDir)
{ 

 SHFILEOPSTRUCT   FileOp = {0};  

 //if(!PathIsDirectory(pszSrcDir) || !PathIsDirectory(pszDesDir))  
 //{  
 //    return   true;  
 //}

 FileOp.fFlags              =   FOF_NOCONFIRMATION;  
 FileOp.lpszProgressTitle   =   NULL;  
 FileOp.hNameMappings       =   NULL;  
 FileOp.hwnd                =   NULL;  
 FileOp.pTo                 =   pszDesDir;  
 FileOp.wFunc               =   FO_COPY;  
 FileOp.pFrom               =   pszSrcDir; 

 //Copies, moves, renames, or deletes a file system object. 

 return   SHFileOperation(&FileOp)   ==   0;  


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -