/*****************************************************************

Name:				AddCRCToCommand

Input Values:		
				char
					*pszCommandString - the message to have a CRC added
					remeber, we substitute the space with a :
								
Output Values:
				char *

Return Value:
				int - 1 if succesful, 0 otherwise

Description:		
					This function adds a CRC to the end of a command
					and replaces the space with a :.  The CRC is calc'd
					using the CRC functionality found in the API			
*****************************************************************/
int CCommandHandling::nAddCRCToCommand( char * pszCommandString )
{
	int 
		m,n;
	unsigned int 
		uCrc;
	bool
		bFirstSpace = FALSE;

	if(strlen(pszCommandString) >= (MAX_COMMAND_MSG-6))
		return 0;

	n=strlen(pszCommandString);
	/*
	 * determine 16 bit CRC
	 */
	uCrc = 0;
	for(m=0;m<n;m++)
	{
		/*
		 * replace space character with : if sending CRC
		 * since parameter names can have spaces we need to 
		 * replace only the first space with the :
		 */
		if(pszCommandString[m]==' ' && !bFirstSpace )
		{
			pszCommandString[m]=':';
			bFirstSpace = TRUE;
		}
		uCrc = CalcCrc16(uCrc,pszCommandString[m]);
	} /* for */
	sprintf(&pszCommandString[n],"%04X",uCrc);
	n+=4;

	/*
	 *Add the carriage return to the end
	 */
	return 1;
} /* nAddCRCToCommand */
예제 #2
0
파일: banner.cpp 프로젝트: 0871087123/rtems
/*
 * CalcBannerCRC
 */
unsigned short CalcBannerCRC(Banner &banner)
{
	return CalcCrc16((unsigned char *)&banner + 32, 0x840 - 32);
}