void CCommThread::SetReadData(BYTE *pBuff, DWORD nData)
{
	int length;
	int packetType;

	int i, j;	
	memset(mTempData,0,sizeof(BYTE)*BUFF_SIZE);
	memcpy(mTempData,pBuff,nData);
	for(i=0; i<nData; i++)
	{
		if(CmdParser(&RxPacket, pBuff[i]))
		{
			length = RxPacket.LEN;
			
			//broadcast data
			if(RxPacket.BUF[0] == 0x30 && RxPacket.BUF[1] == 0x0C && RxPacket.BUF[2] == 0x12)
			{
				packetType = 1;
			}

			//receive data
			else if(RxPacket.BUF[0] == 0x80 && RxPacket.BUF[1] == 0x80 && RxPacket.BUF[2] == 0x11)
			{
				packetType = 2;
			}
			else 
			{
				packetType = 256;
			}
			for(j=0; j< length; j++)
			{
				m_usData[j] = RxPacket.BUF[j];
			}

			makeRcvData(m_usData[30]);						

		}
	}	
}
Пример #2
0
//******************************************************************************
//
// FUNCTION:        DebugHandler
//
// USAGE:             Handles debug commands from the UART
//				
//
// INPUT:              N/A
//
// OUTPUT:           N/A
//
// GLOBALS:         TopDebugCmdList
//
//******************************************************************************
void DebugHandler(void)
{
	//
	// Fill Input Stack
	// Design decision: only one command can be executed each iteration, TomW
	//
	if ( UartRcvDebugCommandRdy() )
	{
		SetLEDStatus(LED_DEBUG_BUSY);

		if (!CmdParser(UartRcvStack, &TopDebugCmdList))
		{
			DebugMsg("unrecognized command, try 'help'\n\r");
		}

		DisplayPrompt();
		SetLEDStatus(LED_DEBUG_NOT_BUSY);
		
	}


	
}
Пример #3
0
//******************************************************************************
//
// FUNCTION:        CmdParser
//
// USAGE:             Parses commands to find debug actions
//				
//
// INPUT:              cmdBuffer - buffer containing input string
//
// OUTPUT:           N/A
//
// GLOBALS:         debugParameters, globalCurrentCmdListPtr
//
//******************************************************************************
static BOOL CmdParser(BYTE *cmdBuffer, ROM CMD_LIST_STRUCT *cmdListToUse)
{
	BYTE cmdSearchCounter = 0;
	BOOL cmdStringMatchFound = FALSE; 
	
	BYTE *cmdBufferPtr;
	char *cmdString;
	ROM DEBUG_CMD_STRUCT *debugCmdStructPtr;
	BYTE sizeOfDebugList;
	
	globalCurrentCmdListPtr = cmdListToUse;
	sizeOfDebugList = cmdListToUse->numOfCmdsInList;
	

	//Look for help command
	cmdBufferPtr = cmdBuffer;
	if (*cmdBufferPtr++ == 'h' &&
		*cmdBufferPtr++ == 'e' &&
		*cmdBufferPtr++ == 'l' &&
		*cmdBufferPtr++ == 'p' )
	{
		HelpCmd();
		return TRUE;
	}


	while (cmdSearchCounter < sizeOfDebugList && !cmdStringMatchFound)
	{
		BOOL byteMatchContinue = TRUE;

		cmdBufferPtr = cmdBuffer;
		debugCmdStructPtr = &(cmdListToUse->debugCmdList[cmdSearchCounter]);

		
		cmdString = debugCmdStructPtr->cmdString;
/*
		DebugMsg("Matching Command: ");
		DebugMsg(cmdString);
		DebugMsg("\n\r");
*/
		do 
		{
			if (*cmdString != ASCII_NULL)
			{
				//Case sensitivity is not matched
				if (( (*cmdBufferPtr >= 'a' && *cmdBufferPtr <= 'z') ||
					(*cmdBufferPtr >= 'A' && *cmdBufferPtr <= 'Z')  ) &&

					( (*cmdString >= 'a' && *cmdString <= 'z') ||
					(*cmdString >= 'A' && *cmdString <= 'Z')  ) )
					
				{
					if ( (*cmdString & 0x1F) != (*cmdBufferPtr & 0x1F) )
					{
						byteMatchContinue = FALSE;
					}
				}			
				else if ( *cmdString != *cmdBufferPtr )
					byteMatchContinue = FALSE;
				
				cmdString++;
				cmdBufferPtr++;
			}
			//
			//CmdString Terminated with all matching
			//
			else 
			{
				byteMatchContinue = FALSE;

				//CmdBuffer Terminated with all matching
				if (*cmdBufferPtr == ASCII_SPACE || *cmdBufferPtr == NULL)
				{
					//
					// MATCH FOUND
					//
					cmdStringMatchFound = TRUE;
					cmdBuffer = cmdBufferPtr;
				}
					
			}
		} while ( byteMatchContinue && cmdBufferPtr != NULL);

		cmdSearchCounter++;		
	}

	//Skip Spaces, look for space after command
	while (*cmdBuffer == ASCII_SPACE)
		cmdBuffer++;


	//
	// Match found
	//
	if (cmdStringMatchFound)
	{
		BYTE numOfCmdParameters = debugCmdStructPtr->numOfCmdParameters;
		BYTE numOfCmdParametersFound = 0;
		SWORD parsedParameter;
		BOOL invalidNumeralFound = FALSE;


		//
		// Recursive parsing of subcommands
		//
		if (debugCmdStructPtr->subCmdList != NULL)
		{
			if (CmdParser(cmdBuffer, (CMD_LIST_STRUCT*)debugCmdStructPtr->subCmdList) == TRUE)
			{
				return TRUE;
			}
			else
			{
				DebugMsg("the command is not complete, please type 'cmd help' for list \n\r");
			}
		}

		//
		// Now Parse Numerical Arguments
		//			
		while ( (numOfCmdParametersFound < MAX_NUM_DEBUG_PARAMETERS) && (*cmdBuffer != NULL) && !invalidNumeralFound )
		{
			parsedParameter = 0;
			
			//parse hex
			if ( *cmdBuffer == '0'  && *(cmdBuffer + 1) == 'x')
			{
				cmdBuffer += 2;

				while (*cmdBuffer != NULL && *cmdBuffer != ASCII_SPACE)
				{
					parsedParameter *= 16;
					
					if (*cmdBuffer >= '0' && *cmdBuffer <= '9')
					{
						parsedParameter += (*cmdBuffer & 0xF);
					}
					else if ( (*cmdBuffer >= 'a'  && *cmdBuffer <= 'f') ||
							(*cmdBuffer >= 'A' && *cmdBuffer <= 'F') )
					{
						parsedParameter += (*cmdBuffer & 0xF) + 9;
					}
					// Invalid Hex Numeral Found, Let Parameter Parser Terminate
					else
					{						
						invalidNumeralFound = TRUE;
					}
					cmdBuffer++;
				}
			}
			else if  (*cmdBuffer =='b')
			{
				cmdBuffer++;
				while (*cmdBuffer != NULL && *cmdBuffer != ASCII_SPACE)
				{
					parsedParameter = parsedParameter << 1;
					if (*cmdBuffer == '0' || *cmdBuffer == '1')
					{
						parsedParameter += *cmdBuffer & 0x1;
					}
					// Invalid Binary Numeral Found, Let Parameter Parser Terminate
					else
					{
						invalidNumeralFound = TRUE;
					}
					cmdBuffer++;
				}
			}
			else 
			{
				BOOL isNegative = FALSE;
				
				if (*cmdBuffer == '-')
				{
					cmdBuffer++;
					isNegative = TRUE;
				}
				
				while (*cmdBuffer != NULL && *cmdBuffer != ASCII_SPACE)
				{
					parsedParameter = parsedParameter * 10;
					if (*cmdBuffer >= '0' && *cmdBuffer <= '9')
					{
						parsedParameter += *cmdBuffer & 0xF;
					}
					// Invalid Decimall Found, Let Parameter Parser Terminate
					else
					{
						invalidNumeralFound = TRUE;
					}
					cmdBuffer++;
				}

				if (isNegative)
				{
					parsedParameter *= -1;
				}
			}
			

			debugParameters[numOfCmdParametersFound++] = parsedParameter;

			//Skip Spaces, look for space after command
			while (*cmdBuffer == ASCII_SPACE)
				cmdBuffer++;
 		}
		

		//
		// Now Command Function
		//
		if ( ( (numOfCmdParameters == numOfCmdParametersFound)  ||
				( numOfCmdParameters == NUMOFCMDPARAMETERS_CANBEANYSIZE))
				&& !invalidNumeralFound)
		{
			numOfDebugParametersFound = numOfCmdParametersFound;
			if (debugCmdStructPtr->CmdFunctionPtr != NULL)
				debugCmdStructPtr->CmdFunctionPtr(debugParameters);
			return (TRUE);
		}
	}
	return (FALSE);

}