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

📄 crc.cpp

📁 键盘测试,数据系统操作键盘测试, 键盘测试,数据系统操作键盘测试,
💻 CPP
字号:
// Crc.cpp: implementation of the CCrc class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "OptKeyTest.h"
#include "Crc.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

/********************************************************
//功能描述:构造函数
//函数入口:无
//函数出口:无
//操    作:无
//版	本:V1.0
//作	者:周登勇
//时	间:2004.12.14 09:04
*********************************************************/
CCrc8::CCrc8()
{

}

/********************************************************
//功能描述:析构函数
//函数入口:无
//函数出口:无
//操    作:无
//版	本:V1.0
//作	者:周登勇
//时	间:2004.12.14 09:05
*********************************************************/
CCrc8::~CCrc8()
{

}

/********************************************************
//功能描述:8位CRC校验程序
//函数入口:buf=数据缓冲区
//函数出口:无
//操    作:在数据缓冲区末尾加上CRC校验数据
//版	本:V1.0
//作	者:周登勇
//时	间:2004.12.14 09:05
*********************************************************/
void CCrc8::AddCrc(U8* buf)
{
	U32 i;
	U16 crcword=0xffff;
	U16 table;

	U32 count;
	count = (U32)buf[0];
	count -= 2;
	for( i=0; i<count; i++ )
	{
		table = (crcword>>8)^buf[i];
		crcword = (crcword<<8)^(CrcTable8[table]);
	}
	crcword ^= 0xffff;
	buf[i++] = (U8)( crcword >> 8 );
	buf[i]= (U8)( crcword & 0xff );
}

/********************************************************
//功能描述:检查CRC校验码
//函数入口:buf=数据缓冲区
//函数出口:校验成功返回TRUE,失败返回FALSE
//操    作:对数据进行校验
//版	本:V1.0
//作	者:周登勇
//时	间:2004.12.14 09:29
*********************************************************/
BOOL CCrc8::CheckCrc(U8* buf)
{
	U32 i;
	U16 crcword=0xffff;
	U16 table;

	U32 count;
	count = (U32)buf[0];

	for( i=0; i<count; i++ )
	{
		table = (crcword>>8)^buf[i];
		crcword = (crcword<<8)^(CrcTable8[table]);
	}
	crcword ^= 0xffff;
	if( crcword == 0xe2f0 )
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

/********************************************************
//功能描述:8位CRC校验程序
//函数入口:buf=数据缓冲区,count=数据长度
//函数出口:无
//操    作:在数据缓冲区末尾加上CRC校验数据
//版	本:V1.0
//作	者:周登勇
//时	间:2004.12.14 09:30
*********************************************************/
void CCrc8::AddCrc(U8* buf,U32 count)
{
	
	U32 i;
	U16 crcword=0xffff;
	U16 table;

	count -= 2;

	for( i=0; i<count; i++ )
	{
		table = (crcword>>8)^buf[i];
		crcword = (crcword<<8)^(CrcTable8[table]);
	}
	
	//crcword ^= 0xffff;
	
	buf[i++] = (U8)( crcword >> 8 );
	buf[i]= (U8)( crcword & 0xff );
}

/********************************************************
//功能描述:检查CRC校验码
//函数入口:buf=数据缓冲区,count=数据长度
//函数出口:校验成功返回TRUE,失败返回FALSE
//操    作:对数据进行校验
//版	本:V1.0
//作	者:周登勇
//时	间:2004.12.14 09:31
*********************************************************/
BOOL CCrc8::CheckCrc(U8* buf,U32 count)
{
	U32 i;
	U16 crcword=0xffff;
	U16 table;

	for( i=0; i<count; i++ )
	{
		table = (crcword>>8)^buf[i];
		crcword = (crcword<<8)^(CrcTable8[table]);
	}
	return !crcword;

	crcword ^= 0xffff;
	if( crcword == 0xe2f0 )
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

⌨️ 快捷键说明

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