Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagemicrium
static void App_TaskTerminal (void *p_arg)
{
	CPU_CHAR 		cmd_str[TASK_TERMINAL_CMD_STR_MAX_LEN];
	CPU_INT16S 		cmp_str;
	CPU_SIZE_T 		cmd_len;
	IPERF_TEST_ID 	test_id_iperf;
	IPERF_ERR 		err_iperf;
	
 
	IPerf_Init(&err_iperf); 														(1)
	APP_TEST_FAULT(err_iperf, IPERF_ERR_NONE); 										(2)
	printf("\n\rTerminal I/O\n\r\n\r");
	
	while (DEF_ON) {
		printf("\n\r> ");
		BSP_Ser_RdStr(&cmd_str[0],TASK_TERMINAL_CMD_STR_MAX_LEN);    				(3)
				       
		cmp_str = Str_Cmp_N(&cmd_str[0], "iperf", 5);								(4)					
							 
		cmd_len = Str_Len(&cmd_str[0]);
		if (cmp_str == 0) {
			printf("\n\r\n\r");
			test_id_iperf = IPerf_TestStart( &cmd_str[0], 							(5)
											 &App_OutputFnct,
										      0,
											 &err_iperf);
			if ((err_iperf     == IPERF_ERR_NONE    ) &&
				(test_id_iperf != IPERF_TEST_ID_NONE)) {
				 IPerf_Reporter((IPERF_TEST_ID    ) test_id_iperf, 					(6)
								(IPERF_OUT_FNCT   )&App_OutputFnct,
							    (IPERF_OUT_PARAM *) 0);
				 printf("\n\r");
			}
		} else if (cmd_len > 1u) {
				printf("Command is not recognized.");
		}
	}
}
  1. Initialize the μC/IPerf. If the process is successful, the μC/IPerf task is started, and its various data structures are initialized.
  2. For this example, if an error occurs with the initialization, the terminal task is delayed infinitely.

  3. Wait to receive a string command.
  4. Verify if string command start with the word “iperf”. Note that the first word of the string command is not verified by μC/IPerf and start to read the arguments after a first space. That give the opportunity to the user to set the name of his choose to start μC/IPerf.

  5. Once the string command is validated locally, the test can be queued. μC/IPerf use App_OutputFnct() to return a string for the menu, version and/or command error.

  6. If μC/IPerf has queued the test, we got a test id. With this test id, we can query status and result from μC/IPerf. The basic reporter takes this test id and a pointer to an output function to print the data.

The following example show an App_OutputFnct() function example. This function receives a pointer to a string and simply prints the string. It is used by the IPerf_Reporter() function to output the formatted data. 

Code Block
languagemicrium
void App_OutputFnct (CPU_CHAR        *p_buf,
					 IPERF_OUT_PARAM *p_param)
{
	if (p_buf == (CPU_CHAR *)0) {
		return;
	}
	printf(p_buf);
}