?? dataframe.cpp
字號:
// DataFrame.cpp: implementation of the CDataFrame class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DataFrame.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDataFrame::CDataFrame()
{
nFrameFlag='#';
}
CDataFrame::~CDataFrame()
{
}
void CDataFrame::WriteFrame(CString &fStr)
{
if(fStr.GetLength()==0)//空幀,直接返回
return;
int index=0;
bool state=false;
while(index<fStr.GetLength())
{
index=fStr.Find(nFrameFlag,index); //從串頭開始找標志位
if(!state)
{
fStr.Insert(index,nFrameFlag);//如果含有標志位,在標志位之前插入一個標志位
index=index+2;
}
if(index==fStr.Find(nFrameFlag,index))//如果含有連續若干個標志位,跳過
{
state=true;
index++;
}
if(fStr.Find(nFrameFlag,index)!=-1&&
index!=fStr.Find(nFrameFlag,index))//如果含有不連續,再在標志位之前插入一個標志位
{
state=false;
index++;
}
if(fStr.Find(nFrameFlag,index)==-1)//如果不含,退出循環
{
break;
}
}
int len=fStr.GetLength();//串長度轉化為字符,作為校驗位
CString str;
str.Format("%c",len);
fStr=nFrameFlag+fStr+str+nFrameFlag;
return;
}
bool CDataFrame::ReadFrame(CString &fStr)
{
if(fStr.GetLength()<=3)
return false;
if(fStr.Mid(0,1)!=nFrameFlag||
fStr.Mid(fStr.GetLength()-1,1)!=nFrameFlag)
return false;
fStr.Delete(fStr.GetLength()-1,1);
fStr.Delete(0,1);
if((fStr.GetLength()-1)!=(int)fStr.GetAt(fStr.GetLength()-1))
return false;
fStr.Delete(fStr.GetLength()-1);
int index=0;
bool state=false;
while(index<fStr.GetLength())
{
index=fStr.Find(nFrameFlag,index);//如果含有標志位,在標志位之前刪除一個標志位
if(!state)
{
fStr.Delete(index);
}
if(index==fStr.Find(nFrameFlag,index))
{
state=true;
index++;
}
if(fStr.Find(nFrameFlag,index)!=-1&&
index!=fStr.Find(nFrameFlag,index))
{
state=false;
index++;
}
if(fStr.Find(nFrameFlag,index)==-1)
{
return true;
}
}
return true;
}
void CDataFrame::SetFrameFlag(char nFrameFlag)
{
this->nFrameFlag=nFrameFlag;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -