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

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 */
Ejemplo n.º 2
0
/*
 * CalcBannerCRC
 */
unsigned short CalcBannerCRC(Banner &banner)
{
	return CalcCrc16((unsigned char *)&banner + 32, 0x840 - 32);
}