示例#1
0
portBASE_TYPE prvSendFloorCommand(int8_t *pcWriteBuffer,
								  size_t xWriteBufferLen,
								  const int8_t *pcCommandString)
{
	portBASE_TYPE xParameter1StringLength;
	int8_t *pcParameter1;

	pcParameter1 = (uint8_t *) FreeRTOS_CLIGetParameter( pcCommandString, 1 , &xParameter1StringLength);

	switch( atoi(pcParameter1) )
	{
		case 1:
			DnCalls |= 1;
			break;

		case 2:
			UpCalls |= 2;
			DnCalls |= 2;
			break;

		case 3:
			UpCalls |= 4;
			break;
	}

	return pdFALSE;
}
示例#2
0
/***********************************
			TRACKING CMD
 ***********************************/
static portBASE_TYPE prvTrackingCommand(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) {

	long lParam_len;
	const char *cCmd_string;

	//Get parameters from command string
	cCmd_string = FreeRTOS_CLIGetParameter(pcCommandString, 1, &lParam_len);

	// check and turn servo control task on/off
	if (strcmp(cCmd_string, "on") == 0 || strcmp(cCmd_string, "On") == 0 || strcmp(cCmd_string, "ON") == 0) {
		vTaskResume(xPanTiltTask);
		vTaskResume(xDistanceTask);
		debug_printf("Tracking and Distance Estimation On!\n\r");
	}
	else if (strcmp(cCmd_string, "off") == 0 || strcmp(cCmd_string, "Off") == 0 || strcmp(cCmd_string, "OFF") == 0) {
		vTaskSuspend(xPanTiltTask);
		vTaskSuspend(xDistanceTask);
		debug_printf("Tracking and Distance Estimation Off\n\r");
	}
	else {
		debug_printf("Invalid argument. Use only on/On/ON or off/Off/OFF.\n\r");
	}

	xWriteBufferLen = sprintf(pcWriteBuffer, "\n\r");

	return pdFALSE;
}
示例#3
0
/***********************************
			LASER CMD
 ***********************************/
static portBASE_TYPE prvLaserCommand(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) {

	long lParam_len;
	const char *cCmd_string;

	//Get parameters from command string
	cCmd_string = FreeRTOS_CLIGetParameter(pcCommandString, 1, &lParam_len);

	// check and turn laser on/off
	if (strcmp(cCmd_string, "on") == 0 || strcmp(cCmd_string, "On") == 0 || strcmp(cCmd_string, "ON") == 0) {
		GPIO_WriteBit(NP2_D1_GPIO_PORT, NP2_D1_PIN, 0x01);
		debug_printf("Laser On!\n\r");
	}
	else if (strcmp(cCmd_string, "off") == 0 || strcmp(cCmd_string, "Off") == 0 || strcmp(cCmd_string, "OFF") == 0) {
		GPIO_WriteBit(NP2_D1_GPIO_PORT, NP2_D1_PIN, 0x00);
		debug_printf("Laser Off\n\r");
	}
	else {
		debug_printf("Invalid argument. Use only on/On/ON or off/Off/OFF.\n\r");
	}

	xWriteBufferLen = sprintf(pcWriteBuffer, "\n\r");

	return pdFALSE;
}
示例#4
0
/**
 * @brief	Switch LCD backlight LED
 * @param	pcWriteBuffer
 * @param	xWriteBufferLen
 * @param	pcCommandString
 * @return
 */
static BaseType_t LCD_SleepCommand(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString)
{
	const char *parameterPtr;
	int32_t paramterLen;

	parameterPtr = FreeRTOS_CLIGetParameter(pcCommandString, 1, &paramterLen);

	if (paramterLen == 1)
	{
		if (parameterPtr[0] == '0')
			LCD_Sleep(ENABLE);
		else if (parameterPtr[0] == '1')
			LCD_Sleep(DISABLE);
	}
	else if (paramterLen == 2)
	{
		if (parameterPtr[0] == 'o' && parameterPtr[1] == 'n')
			LCD_Sleep(DISABLE);
	}
	else if (paramterLen == 3)
	{
		if (parameterPtr[0] == 'o' && parameterPtr[1] == 'f'
				&& parameterPtr[2] == 'f')
			LCD_Sleep(ENABLE);
	}

	sprintf(pcWriteBuffer, "\n"); // Clean Message

	return pdFALSE;

}
示例#5
0
/**
 * @param	pcWriteBuffer
 * @param	xWriteBufferLen
 * @param	pcCommandString
 * @return
 */
static BaseType_t LCD_LocCommand(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString)
{
	const char *parameterPtr;
	int32_t paramterLen;
	uint32_t x, y;

	parameterPtr = FreeRTOS_CLIGetParameter(pcCommandString, 1, &paramterLen);
	x = DecToInt((char *) parameterPtr, paramterLen);

	parameterPtr = FreeRTOS_CLIGetParameter(pcCommandString, 2, &paramterLen);
	y = DecToInt((char *) parameterPtr, paramterLen);

	LCD_SetLoc(x, y);

	sprintf(pcWriteBuffer, "\n");

	return pdFALSE;

}
示例#6
0
portBASE_TYPE prvAccelCommand(int8_t *pcWriteBuffer,
								  size_t xWriteBufferLen,
								  const int8_t *pcCommandString)
{
	portBASE_TYPE xParameter1StringLength;
	int8_t *pcParameter1;

	pcParameter1 = (uint8_t *) FreeRTOS_CLIGetParameter( pcCommandString, 1 , &xParameter1StringLength);

	MaxAccel = atoi(pcParameter1);

	return pdFALSE;
}
示例#7
0
static portBASE_TYPE prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
portBASE_TYPE lParameterStringLength;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	/* Obtain the parameter string. */
	pcParameter = FreeRTOS_CLIGetParameter
					(
						pcCommandString,		/* The command string itself. */
						1,						/* Return the first parameter. */
						&lParameterStringLength	/* Store the parameter string length. */
					);

	/* Sanity check something was returned. */
	configASSERT( pcParameter );

	/* There are only two valid parameter values. */
	if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
	{
		/* Start or restart the trace. */
		vTraceStop();
		vTraceClear();
		uiTraceStart();

		sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
	}
	else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
	{
		/* End the trace, if one is running. */
		vTraceStop();
		sprintf( pcWriteBuffer, "Stopping trace recording and dumping log to disk.\r\n" );
		prvSaveTraceFile();
	}
	else
	{
		sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
	}

	/* There is no more data to return after this single string, so return
	pdFALSE. */
	return pdFALSE;
}
示例#8
0
static portBASE_TYPE create_task_command(int8_t *pcWriteBuffer,
		size_t xWriteBufferLen,
		const int8_t *pcCommandString)
{
	int8_t *parameter_string;
	portBASE_TYPE parameter_string_length;
	static const int8_t *success_message = (int8_t *) "Task created\r\n";
	static const int8_t *failure_message = (int8_t *) "Task not created\r\n";
	static const int8_t *task_already_created_message = (int8_t *) "The task has already been created. Execute the delete-task command first.\r\n";
	int32_t parameter_value;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	(void) xWriteBufferLen;
	configASSERT(pcWriteBuffer);

	/* Obtain the parameter string. */
	parameter_string = (int8_t *) FreeRTOS_CLIGetParameter(
									pcCommandString,		/* The command string itself. */
									1,						/* Return the first parameter. */
									&parameter_string_length	/* Store the parameter string length. */
								);

	/* Turn the parameter into a number. */
	parameter_value = (int32_t) atol((const char *) parameter_string);

	/* Attempt to create the task. */
	if (created_task_handle != NULL) {
		strcpy((char *) pcWriteBuffer,
				(const char *) task_already_created_message);
	} else {
		if (xTaskCreate(created_task, (const signed char *) "Created",
				configMINIMAL_STACK_SIZE,
				(void *) parameter_value, tskIDLE_PRIORITY,
				&created_task_handle) == pdPASS) {
			strcpy((char *) pcWriteBuffer,
					(const char *) success_message);
		} else {
			strcpy((char *) pcWriteBuffer,
					(const char *) failure_message);
		}
	}

	/* There is no more data to return after this single string, so return
	pdFALSE. */
	return pdFALSE;
}
示例#9
0
/**
 * @param	pcWriteBuffer
 * @param	xWriteBufferLen
 * @param	pcCommandString
 * @return
 */
static BaseType_t LCD_CursorCommand(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString)
{
	const char *parameterPtr;
	int32_t paramterLen;
	uint32_t mode;

	parameterPtr = FreeRTOS_CLIGetParameter(pcCommandString, 1, &paramterLen);
	mode = DecToInt((char *) parameterPtr, paramterLen);

	LCD_Cursor(mode & BIT0);
	LCD_Blink(mode & BIT1);

	sprintf(pcWriteBuffer, "Cursor set to mode: %d\n", (uint16_t)(mode & 0x03));

	return pdFALSE;

}
示例#10
0
/**
 * @param	pcWriteBuffer
 * @param	xWriteBufferLen
 * @param	pcCommandString
 * @return
 */
static BaseType_t LCD_PrintCommand(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString)
{
	const char *parameterPtr;
	int32_t paramterLen;
	uint8_t i = 0;

	parameterPtr = FreeRTOS_CLIGetParameter(pcCommandString, 1, &paramterLen);
	while(i < paramterLen)
	{
		LCD_WriteData(parameterPtr[i]);
		i++;
	}
	sprintf(pcWriteBuffer, "\n");

	return pdFALSE;

}
示例#11
0
static portBASE_TYPE prvDelCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
{
int8_t *pcParameter;
portBASE_TYPE xParameterStringLength;
const unsigned portBASE_TYPE uxFirstParameter = 1U;

	/* This assumes pcWriteBuffer is long enough. */
	( void ) xWriteBufferLen;

	/* Obtain the name of the file being deleted. */
	pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter( pcCommandString, uxFirstParameter, &xParameterStringLength );

	/* Terminate the parameter string. */
	pcParameter[ xParameterStringLength ] = 0x00;

	if( f_unlink( ( const TCHAR * ) pcParameter ) != FR_OK )
	{
		snprintf( ( char * ) pcWriteBuffer, xWriteBufferLen, "Could not delete %s\r\n\r\n", pcParameter );
	}

	/* There is only ever one string to return. */
	return pdFALSE;
}
示例#12
0
static portBASE_TYPE prvDELCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
portBASE_TYPE xParameterStringLength;
unsigned char ucReturned;

	/* This function assumes xWriteBufferLen is large enough! */
	( void ) xWriteBufferLen;

	/* Obtain the parameter string. */
	pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							1,						/* Return the first parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

	/* Sanity check something was returned. */
	configASSERT( pcParameter );

	/* Attempt to delete the file. */
	ucReturned = f_delete( pcParameter );

	if( ucReturned == F_NO_ERROR )
	{
		sprintf( pcWriteBuffer, "%s was deleted", pcParameter );
	}
	else
	{
		sprintf( pcWriteBuffer, "Error" );
	}

	strcat( pcWriteBuffer, cliNEW_LINE );

	return pdFALSE;
}
示例#13
0
static portBASE_TYPE prvCDCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
portBASE_TYPE xParameterStringLength;
unsigned char ucReturned;
size_t xStringLength;

	/* Obtain the parameter string. */
	pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							1,						/* Return the first parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

	/* Sanity check something was returned. */
	configASSERT( pcParameter );

	/* Attempt to move to the requested directory. */
	ucReturned = f_chdir( pcParameter );

	if( ucReturned == F_NO_ERROR )
	{
		sprintf( pcWriteBuffer, "In: " );
		xStringLength = strlen( pcWriteBuffer );
		f_getcwd( &( pcWriteBuffer[ xStringLength ] ), ( unsigned char ) ( xWriteBufferLen - xStringLength ) );
	}
	else
	{
		sprintf( pcWriteBuffer, "Error" );
	}

	strcat( pcWriteBuffer, cliNEW_LINE );

	return pdFALSE;
}
示例#14
0
/**
 * @param	pcWriteBuffer
 * @param	xWriteBufferLen
 * @param	pcCommandString
 * @return
 */
static BaseType_t LCD_MoveCommand(char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString)
{
	const char *parameterPtr;
	int32_t paramterLen;
	uint32_t mode;

	parameterPtr = FreeRTOS_CLIGetParameter(pcCommandString, 1, &paramterLen);
	mode = DecToInt((char *) parameterPtr, paramterLen);

	switch(mode)
	{
		case 3:
			LCD_ScrollRight();
			break;

		case 2:
			LCD_ScrollLeft();
			break;

		case 1:
			LCD_CursorMoveRight();
			break;

		case 0:
			LCD_CursorMoveLeft();
			break;

		default:
			break;
	}

	sprintf(pcWriteBuffer, "\n");

	return pdFALSE;

}
示例#15
0
static portBASE_TYPE prvCOPYCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcDestinationFile;
char *pcSourceFile;
portBASE_TYPE xParameterStringLength;
long lSourceLength, lDestinationLength = 0;

	/* Obtain the name of the destination file. */
	pcDestinationFile = FreeRTOS_CLIGetParameter
							(
								pcCommandString,		/* The command string itself. */
								2,						/* Return the second parameter. */
								&xParameterStringLength	/* Store the parameter string length. */
							);

	/* Sanity check something was returned. */
	configASSERT( pcDestinationFile );

	/* Obtain the name of the source file. */
	pcSourceFile = ( char * ) FreeRTOS_CLIGetParameter
								(
									pcCommandString,		/* The command string itself. */
									1,						/* Return the first parameter. */
									&xParameterStringLength	/* Store the parameter string length. */
								);

	/* Sanity check something was returned. */
	configASSERT( pcSourceFile );

	/* Terminate the string. */
	pcSourceFile[ xParameterStringLength ] = 0x00;

	/* See if the source file exists, obtain its length if it does. */
	lSourceLength = f_filelength( pcSourceFile );

	if( lSourceLength == 0 )
	{
		sprintf( pcWriteBuffer, "Source file does not exist" );
	}
	else
	{
		/* See if the destination file exists. */
		lDestinationLength = f_filelength( pcDestinationFile );

		if( lDestinationLength != 0 )
		{
			sprintf( pcWriteBuffer, "Error: Destination file already exists" );
		}
	}

	/* Continue only if the source file exists and the destination file does
	not exist. */
	if( ( lSourceLength != 0 ) && ( lDestinationLength == 0 ) )
	{
		if( prvPerformCopy( pcSourceFile, lSourceLength, pcDestinationFile, pcWriteBuffer, xWriteBufferLen ) == pdPASS )
		{
			sprintf( pcWriteBuffer, "Copy made" );
		}
		else
		{
			sprintf( pcWriteBuffer, "Error during copy" );
		}
	}

	strcat( pcWriteBuffer, cliNEW_LINE );

	return pdFALSE;
}
示例#16
0
static portBASE_TYPE prvTYPECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
portBASE_TYPE xParameterStringLength, xReturn = pdTRUE;
static F_FILE *pxFile = NULL;
int iChar;
size_t xByte;
size_t xColumns = 50U;

	/* Ensure there is always a null terminator after each character written. */
	memset( pcWriteBuffer, 0x00, xWriteBufferLen );

	/* Ensure the buffer leaves space for the \r\n. */
	configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
	xWriteBufferLen -= strlen( cliNEW_LINE );

	if( xWriteBufferLen < xColumns )
	{
		/* Ensure the loop that uses xColumns as an end condition does not
		write off the end of the buffer. */
		xColumns = xWriteBufferLen;
	}

	if( pxFile == NULL )
	{
		/* The file has not been opened yet.  Find the file name. */
		pcParameter = FreeRTOS_CLIGetParameter
							(
								pcCommandString,		/* The command string itself. */
								1,						/* Return the first parameter. */
								&xParameterStringLength	/* Store the parameter string length. */
							);

		/* Sanity check something was returned. */
		configASSERT( pcParameter );

		/* Attempt to open the requested file. */
		pxFile = f_open( pcParameter, "r" );
	}

	if( pxFile != NULL )
	{
		/* Read the next chunk of data from the file. */
		for( xByte = 0; xByte < xColumns; xByte++ )
		{
			iChar = f_getc( pxFile );

			if( iChar == -1 )
			{
				/* No more characters to return. */
				f_close( pxFile );
				pxFile = NULL;
				break;
			}
			else
			{
				pcWriteBuffer[ xByte ] = ( char ) iChar;
			}
		}
	}

	if( pxFile == NULL )
	{
		/* Either the file was not opened, or all the data from the file has
		been returned and the file is now closed. */
		xReturn = pdFALSE;
	}

	strcat( pcWriteBuffer, cliNEW_LINE );

	return xReturn;
}
示例#17
0
文件: aos_cli.c 项目: OUWECAD/MOWE
static portBASE_TYPE motorCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
{
	int8_t *pcParameterString1, *pcParameterString2, *pcParameterString3; 
	portBASE_TYPE xParameterStringLength1 = 0, xParameterStringLength2 = 0, xParameterStringLength3 = 0;
	
	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );
	
	/* Obtain the 1st parameter string. */
	pcParameterString1 = ( int8_t * ) FreeRTOS_CLIGetParameter
								(
									pcCommandString,		/* The command string itself. */
									1,						/* Return the first parameter. */
									&xParameterStringLength1	/* Store the parameter string length. */
								);

	/* Obtain the 2nd parameter string. */
	pcParameterString2 = ( int8_t * ) FreeRTOS_CLIGetParameter (pcCommandString, 2, &xParameterStringLength2);

	/* Obtain the 3rd parameter string. */
	pcParameterString3 = ( int8_t * ) FreeRTOS_CLIGetParameter (pcCommandString, 3, &xParameterStringLength3);

	/* Read the motor port */
	if( pcParameterString1 != NULL )
	{	
		if (pcParameterString1[0] == 'P' || pcParameterString1[0] == 'p') 
		{
			motor = ( uint8_t ) atol( ( char * ) (pcParameterString1+1) );	
		}
	}	
	
	strcpy( (char *) pcWriteBuffer, "\r\n" );
	
	/* Read the motor command */
	if( pcParameterString2 != NULL )
	{
		if (!strncmp(( char * ) pcParameterString2, "start", (size_t) xParameterStringLength2)) {
			mode = 1;	
		}	else if (!strncmp(( char * ) pcParameterString2, "stop", (size_t) xParameterStringLength2)) {
			mode = 2;	
		}	else if (!strncmp(( char * ) pcParameterString2, "min", (size_t) xParameterStringLength2)) {
			mode = 5;	
		}	else if (!strncmp(( char * ) pcParameterString2, "maxCW", (size_t) xParameterStringLength2)) {
			mode = 6;	
		}	else if (!strncmp(( char * ) pcParameterString2, "maxCCW", (size_t) xParameterStringLength2)) {
			mode = 7;	
//		}	else if (!strncmp(( char * ) pcParameterString2, "middle", (size_t) xParameterStringLength2)) {
//			mode = 4;	
//		}	else if (!strncmp(( char * ) pcParameterString2, "sweep", (size_t) xParameterStringLength2)) {
//			mode = 7;	
//		}	else if (!strncmp(( char * ) pcParameterString2, "angle", (size_t) xParameterStringLength2)) {
//			mode = 3;	
//			if( pcParameterString3 != NULL ) {
//				angle = atoi( ( char * ) (pcParameterString3) );
//			}
		}	else if (!strncmp(( char * ) pcParameterString2, "speed", (size_t) xParameterStringLength2)) {	
			mode = 8;			
			if( pcParameterString3 != NULL ) {
				rate = atof( ( char * ) (pcParameterString3) );
			}
		}
		
	}
	
	

	/* There is no more data to return after this single string, so return
	pdFALSE. */
	return pdFALSE;
}
示例#18
0
static portBASE_TYPE prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
portBASE_TYPE lParameterStringLength, xReturn;
static portBASE_TYPE lParameterNumber = 0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	if( lParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf( pcWriteBuffer, "The three parameters were:\r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		lParameterNumber = 1L;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = pdPASS;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							lParameterNumber,		/* Return the next parameter. */
							&lParameterStringLength	/* Store the parameter string length. */
						);

		/* Sanity check something was returned. */
		configASSERT( pcParameter );

		/* Return the parameter string. */
		memset( pcWriteBuffer, 0x00, xWriteBufferLen );
		sprintf( pcWriteBuffer, "%d: ", lParameterNumber );
		strncat( pcWriteBuffer, pcParameter, lParameterStringLength );
		strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );

		/* If this is the last of the three parameters then there are no more
		strings to return after this one. */
		if( lParameterNumber == 3L )
		{
			/* If this is the last of the three parameters then there are no more
			strings to return after this one. */
			xReturn = pdFALSE;
			lParameterNumber = 0L;
		}
		else
		{
			/* There are more parameters to return after this one. */
			xReturn = pdTRUE;
			lParameterNumber++;
		}
	}

	return xReturn;
}
示例#19
0
static portBASE_TYPE prvCopyCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
{
int8_t *pcParameter1, *pcParameter2;
portBASE_TYPE xParameter1StringLength, xParameter2StringLength, xFinished = pdFALSE;
const unsigned portBASE_TYPE uxFirstParameter = 1U, uxSecondParameter = 2U;
UINT xBytesRead, xBytesWritten;
const portTickType xMaxDelay = 500UL / portTICK_RATE_MS;

	( void ) xWriteBufferLen;

	/* Obtain the name of the source file, and the length of its name. */
	pcParameter1 = ( int8_t * ) FreeRTOS_CLIGetParameter( pcCommandString, uxFirstParameter, &xParameter1StringLength );

	/* Obtain the name of the destination file, and the length of its name. */
	pcParameter2 = ( int8_t * ) FreeRTOS_CLIGetParameter( pcCommandString, uxSecondParameter, &xParameter2StringLength );

	/* Terminate both file names. */
	pcParameter1[ xParameter1StringLength ] = 0x00;
	pcParameter2[ xParameter2StringLength ] = 0x00;

	/* Open the source file. */
	if( f_open( &xCommandLineFile1, ( const TCHAR * ) pcParameter1, ( FA_OPEN_EXISTING | FA_READ ) ) == FR_OK )
	{
		/* Open the destination file. */
		if( f_open( &xCommandLineFile2, ( const TCHAR * ) pcParameter2, ( FA_CREATE_ALWAYS | FA_WRITE ) ) == FR_OK )
		{
			while( xFinished == pdFALSE )
			{
				/* About to use the RAM buffer, ensure this task has exclusive access
				to it while it is in use. */
				if( xSemaphoreTake( xRamBufferMutex, xMaxDelay ) == pdPASS )
				{
					if( f_read( &xCommandLineFile1, cRAMBuffer, sizeof( cRAMBuffer ), &xBytesRead ) == FR_OK )
					{
						if( xBytesRead != 0U )
						{
							if( f_write( &xCommandLineFile2, cRAMBuffer, xBytesRead, &xBytesWritten ) == FR_OK )
							{
								if( xBytesWritten < xBytesRead )
								{
									snprintf( ( char * ) pcWriteBuffer, xWriteBufferLen, "Error writing to %s, disk full?\r\n\r\n", pcParameter2 );
									xFinished = pdTRUE;
								}
							}
							else
							{
								snprintf( ( char * ) pcWriteBuffer, xWriteBufferLen, "Error during copy\r\n\r\n" );
								xFinished = pdTRUE;
							}
						}
						else
						{
							/* EOF. */
							xFinished = pdTRUE;
						}
					}
					else
					{
						snprintf( ( char * ) pcWriteBuffer, xWriteBufferLen, "Error during copy\r\n\r\n" );
						xFinished = pdTRUE;
					}
					
					/* Must give the mutex back! */
					xSemaphoreGive( xRamBufferMutex );
				}				
			}

			/* Close both files. */
			f_close( &xCommandLineFile1 );
			f_close( &xCommandLineFile2 );
		}
		else
		{
			snprintf( ( char * ) pcWriteBuffer, xWriteBufferLen, "Could not open or create %s\r\n\r\n", pcParameter2 );

			/* Close the source file. */
			f_close( &xCommandLineFile1 );
		}
	}
	else
	{
		snprintf( ( char * ) pcWriteBuffer, xWriteBufferLen, "Could not open %s\r\n\r\n", pcParameter1 );
	}

	return pdFALSE;
}
示例#20
0
portBASE_TYPE prvCanCmd( int8_t *pcWriteBuffer,
						size_t xWriteBufferLen,
						const int8_t *pcCommandString )
{
portCHAR *pcParameter;
portBASE_TYPE lParameterStringLength;
static portSHORT xArgL1;
static portSHORT xArgL2;
static portSHORT xArgL3;
static portUCHAR xArgMsg[8];
static portUCHAR xMsgIdx;
static xCanCmdStates_t xState;
static portBASE_TYPE lParameterNumber = 0;
static xCanCmdElement_t xCanCmdElement;

	(void) xWriteBufferLen;
	pcWriteBuffer[ 0 ] = 0x00;
	portBASE_TYPE xReturn = pdPASS;
	
    if( lParameterNumber == 0 )
    {
		//entering can command parser
        xState = STATE_Z;
		lParameterNumber = 1L;
	} else 
	{
		pcParameter = ( portCHAR * ) FreeRTOS_CLIGetParameter ( pcCommandString,
														lParameterNumber,
														&lParameterStringLength
		);	
		
		if (pcParameter) 
		{
			lParameterNumber++;
			switch (xState) 
			{
			case STATE_Z: //first arg ena dis open close baud mob 
				if (!strncmp(pcParameter, CCC_RESET, CCC_RESET_L)) 
				{
					xState = STATE_RESET;
				} else 
				if (!strncmp(pcParameter, CCC_ENA, CCC_ENA_L)) 
				{
					xState = STATE_ENA;
				} else 
				if (!strncmp(pcParameter, CCC_DIS, CCC_DIS_L)) 
				{
					xState = STATE_DIS;
				} else
				if (!strncmp(pcParameter, CCC_CONF, CCC_CONF_L)) 
				{
					xState = STATE_CONF1;
				} else 
				if (!strncmp(pcParameter, CCC_CLOSE, CCC_CLOSE_L)) 
				{
					xState = STATE_CLOSE;
				} else
				if (!strncmp(pcParameter, CCC_BAUD, CCC_BAUD_L)) 
				{
					xState = STATE_BAUD1;
				} else
				if (!strncmp(pcParameter, CCC_MOB, CCC_MOB_L)) 
				{
					xState = STATE_MOB1;
				} else
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_ENA: //arg: listen
				if (!strncmp(pcParameter, CCC_LISTEN, CCC_LISTEN_L)) 
				{
					xState = STATE_ENALISTEN;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_CONF1: //arg: #conf
				xArgL1 = strtol(pcParameter,NULL,16);
				xState = STATE_CONFVALUE;
			break;
			case STATE_BAUD1: //arg: auto set get
				if (!strncmp(pcParameter, CCC_AUTO, CCC_AUTO_L)) 
				{
					xState = STATE_BAUDAUTO;
				} else 				
				if (!strncmp(pcParameter, CCC_GET, CCC_GET_L)) 
				{
					xState = STATE_BAUDGET;
				} else 				
				if (!strncmp(pcParameter, CCC_SET, CCC_SET_L)) 
				{
					xState = STATE_BAUDSET1;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_BAUDSET1: //arg: 0<=val<0xFFF
				xArgL1 = strtol(pcParameter,NULL,16);
				if ((xArgL1<=0xFFF) && (xArgL1>=0x000)) 
				{
					xState = STATE_BAUDSETVAL1;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_BAUDSETVAL1: //arg: 0<=val<0xFFF
				xArgL2 = strtol(pcParameter,NULL,16);
				if ((xArgL2<=0xFFF) && (xArgL2>=0x000)) 
				{
					xState = STATE_BAUDSETVAL2;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_BAUDSETVAL2: //arg: 0<=val<0xFFF
				xArgL3 = strtol(pcParameter,NULL,16);
				if ((xArgL3<=0xFFF) && (xArgL3>=0x000))
				{
					xState = STATE_BAUDSETVALS;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOB1: //arg: 0<=val<15
				xArgL1 = strtol(pcParameter,NULL,16);
				if ((xArgL1<15) && (xArgL1>=0)) 
				{
					xState = STATE_MOB2;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOB2: //arg: rd, wr, dump, undump
				if (!strncmp(pcParameter, CCC_RD, CCC_RD_L)) 
				{
					xState = STATE_MOBRD1;
				} else 				
				if (!strncmp(pcParameter, CCC_WR, CCC_WR_L)) 
				{
					xState = STATE_MOBWR1;
				} else 				
				if (!strncmp(pcParameter, CCC_DUMP, CCC_DUMP_L)) 
				{
					xState = STATE_MOBDUMP;
				} else 				
				if (!strncmp(pcParameter, CCC_UNDUMP, CCC_UNDUMP_L)) 
				{
					xState = STATE_MOBUNDUMP;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOBRD1: //arg: 0x000<=tag<0xFFF
				xArgL2 = strtol(pcParameter,NULL,16);
				if ((xArgL2<=0xFFF) && (xArgL2>=0x000)) 
				{
					xState = STATE_MOBRDTAG1;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOBWR1: //arg: 0x000<=tag<0xFFF
				xArgL2 = strtol(pcParameter,NULL,16);
				if ((xArgL2<=0xFFF) && (xArgL2>=0x000)) 
				{
					xMsgIdx = 0;
					xState = STATE_MOBWRTAG1;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOBRDTAG1: //arg: 0x000<=msk<0xFFF
				xArgL3 = strtol(pcParameter,NULL,16);
				if ((xArgL3<=0xFFF) && (xArgL3>=0x000)) 
				{
					xState = STATE_MOBRDTAGMASK;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOBWRTAG1: //arg: 0x0<=len<0x08
				xArgL3 = strtol(pcParameter,NULL,16);
				if ((xArgL3<=0x1F) && (xArgL3>=0))
				{ 
					xState = STATE_MOBWRTAGLEN1;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOBWRTAGLEN1: //arg: 0x00<=data<=0xFF
				xArgMsg[xMsgIdx] = strtol(pcParameter,NULL,16);
				{
					++xMsgIdx;
					if (xMsgIdx == xArgL3)
					{
						xState = STATE_MOBWRTAGLENMSG;
					}
				}
			break;
			//...
			default:
				xState = STATE_FAIL;
				xReturn = pdFAIL;
			}
		} else //no more params
		{
			xReturn = pdFALSE;
			lParameterNumber = 0;
			pcWriteBuffer[ 0 ] = 0x00;
			
			switch (xState) 
			{
			case STATE_RESET:
				xCanCmdElement.xCanCmd = CMD_CAN_RESET;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			/*case STATE_CLOSE:
				xCanCmdElement.xCanCmd = CMD_CAN_OPEN;
				xCanCmdElement.ucCloseOpen = 0;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;*/
			case STATE_CONFVALUE:
				xCanCmdElement.xCanCmd = CMD_CAN_CONF;
				xCanCmdElement.ucDefaultConfig = xArgL1;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_DIS:
				xCanCmdElement.xCanCmd = CMD_CAN_ENA;
				xCanCmdElement.ucDisEnaListen = CMD_CAN_DIS_VAL;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_ENA:
				xCanCmdElement.xCanCmd = CMD_CAN_ENA;
				xCanCmdElement.ucDisEnaListen = CMD_CAN_ENA_VAL;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_ENALISTEN:
				xCanCmdElement.xCanCmd = CMD_CAN_ENA;
				xCanCmdElement.ucDisEnaListen = CMD_CAN_ENA_LISTEN_VAL;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_BAUDAUTO:
				xCanCmdElement.xCanCmd = CMD_CAN_BAUD;
				xCanCmdElement.ucGetSetAuto = CMD_CAN_BAUD_AUTO_VAL;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_BAUDGET:
				xCanCmdElement.xCanCmd = CMD_CAN_BAUD;
				xCanCmdElement.ucGetSetAuto = CMD_CAN_BAUD_GET_VAL;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_BAUDSETVALS:
				xCanCmdElement.xCanCmd = CMD_CAN_BAUD;
				xCanCmdElement.ucGetSetAuto = CMD_CAN_BAUD_SET_VAL;
				xCanCmdElement.xArgMsg[0] = xArgL1;
				xCanCmdElement.xArgMsg[1] = xArgL2;
				xCanCmdElement.xArgMsg[2] = xArgL3;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_MOBDUMP:
				xCanCmdElement.xCanCmd = CMD_CAN_MOB_DUMP;
				xCanCmdElement.ucUndumpDump = CMD_CAN_DUMP;
				xCanCmdElement.cMobNum = xArgL1;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_MOBUNDUMP:
				xCanCmdElement.xCanCmd = CMD_CAN_MOB_DUMP;
				xCanCmdElement.ucUndumpDump = CMD_CAN_UNDUMP;
				xCanCmdElement.cMobNum = xArgL1;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_MOBRDTAGMASK:
				xCanCmdElement.xCanCmd = CMD_CAN_MOB_RDWR;
				xCanCmdElement.ucReadWrite = CMD_CAN_RD_VAL;
				xCanCmdElement.cMobNum = xArgL1;
				xCanCmdElement.sTag = xArgL2;
				xCanCmdElement.sMask = xArgL3;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_MOBWRTAGLENMSG:
				xCanCmdElement.xCanCmd = CMD_CAN_MOB_RDWR;
				xCanCmdElement.ucReadWrite = CMD_CAN_WR_VAL;
				xCanCmdElement.cMobNum = xArgL1;
				xCanCmdElement.sTag = xArgL2;
				xCanCmdElement.sLen = xArgL3&0x0F;
				xCanCmdElement.cRtr = xArgL3&0x10;
				memcpy(xCanCmdElement.xArgMsg,xArgMsg,8);
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_FAIL:
			default:
			{}
			}
		}
	}
	if ( STATE_FAIL == xState ) 
	{
		lParameterNumber = 0;
		strcpy_P((portCHAR*)pcWriteBuffer, pm_cstr_INVALID );
		
	}
	return xReturn;
}
示例#21
0
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static BaseType_t lParameterNumber = 0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	if( lParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf( pcWriteBuffer, "The parameters were:\r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		lParameterNumber = 1L;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = pdPASS;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							lParameterNumber,		/* Return the next parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

		if( pcParameter != NULL )
		{
			/* Return the parameter string. */
			memset( pcWriteBuffer, 0x00, xWriteBufferLen );
			sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
			strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
			strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );

			/* There might be more parameters to return after this one. */
			xReturn = pdTRUE;
			lParameterNumber++;
		}
		else
		{
			/* No more parameters were found.  Make sure the write buffer does
			not contain a valid string. */
			pcWriteBuffer[ 0 ] = 0x00;

			/* No more data to return. */
			xReturn = pdFALSE;

			/* Start over the next time this command is executed. */
			lParameterNumber = 0;
		}
	}

	return xReturn;
}
示例#22
0
	static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
	{
	char * pcParameter;
	BaseType_t lParameterStringLength, xReturn = pdFALSE;
	uint32_t ulIPAddress, ulBytesToPing;
	const uint32_t ulDefaultBytesToPing = 8UL;
	char cBuffer[ 16 ];

		/* Remove compile time warnings about unused parameters, and check the
		write buffer is not NULL.  NOTE - for simplicity, this example assumes the
		write buffer length is adequate, so does not check for buffer overflows. */
		( void ) pcCommandString;
		( void ) xWriteBufferLen;
		configASSERT( pcWriteBuffer );

		/* Start with an empty string. */
		pcWriteBuffer[ 0 ] = 0x00;

		/* Obtain the number of bytes to ping. */
		pcParameter = ( char * ) FreeRTOS_CLIGetParameter
								(
									pcCommandString,		/* The command string itself. */
									2,						/* Return the second parameter. */
									&lParameterStringLength	/* Store the parameter string length. */
								);

		if( pcParameter == NULL )
		{
			/* The number of bytes was not specified, so default it. */
			ulBytesToPing = ulDefaultBytesToPing;
		}
		else
		{
			ulBytesToPing = atol( pcParameter );
		}

		/* Obtain the IP address string. */
		pcParameter = ( char * ) FreeRTOS_CLIGetParameter
								(
									pcCommandString,		/* The command string itself. */
									1,						/* Return the first parameter. */
									&lParameterStringLength	/* Store the parameter string length. */
								);

		if( pcParameter != NULL )
		{
			/* Terminate the host name or IP address string. */
			pcParameter[ lParameterStringLength ] = 0x00;

			/* Attempt to obtain the IP address.   If the first character is not a
			digit, assume the host name has been passed in. */
			if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )
			{
				ulIPAddress = FreeRTOS_inet_addr( pcParameter );
			}
			else
			{
				/* Attempt to resolve host. */
				ulIPAddress = FreeRTOS_gethostbyname( pcParameter );
			}

			/* Convert IP address, which may have come from a DNS lookup, to string. */
			FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );

			if( ulIPAddress != 0 )
			{
				xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );
			}
		}

		if( xReturn == pdFALSE )
		{
			sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );
		}
		else
		{
			sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, ( int ) xReturn );
		}

		return pdFALSE;
	}
示例#23
0
static portBASE_TYPE multi_parameter_echo_command(int8_t *pcWriteBuffer,
		size_t xWriteBufferLen,
		const int8_t *pcCommandString)
{
	int8_t *parameter_string;
	portBASE_TYPE parameter_string_length, return_value;
	static portBASE_TYPE parameter_number = 0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	(void) pcCommandString;
	(void) xWriteBufferLen;
	configASSERT(pcWriteBuffer);

	if (parameter_number == 0) {
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf((char *) pcWriteBuffer, "The parameters were:\r\n");

		/* Next time the function is called the first parameter will be echoed
		back. */
		parameter_number = 1L;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		return_value = pdPASS;
	} else {
		/* Obtain the parameter string. */
		parameter_string = (int8_t *) FreeRTOS_CLIGetParameter
									(
										pcCommandString,		/* The command string itself. */
										parameter_number,		/* Return the next parameter. */
										&parameter_string_length	/* Store the parameter string length. */
									);

		if (parameter_string != NULL) {
			/* Return the parameter string. */
			memset(pcWriteBuffer, 0x00, xWriteBufferLen);
			sprintf((char *) pcWriteBuffer, "%ld: ", parameter_number);
			strncat((char *) pcWriteBuffer, (const char *) parameter_string, parameter_string_length);
			strncat((char *) pcWriteBuffer, "\r\n", strlen("\r\n"));

			/* There might be more parameters to return after this one. */
			return_value = pdTRUE;
			parameter_number++;
		} else {
			/* No more parameters were found.  Make sure the write buffer does
			not contain a valid string. */
			pcWriteBuffer[0] = 0x00;

			/* No more data to return. */
			return_value = pdFALSE;

			/* Start over the next time this command is executed. */
			parameter_number = 0;
		}
	}

	return return_value;
}