📄 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 + -