Versions Compared

Key

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

Table of Contents

Terminal Reporter on the

...

Target

If your target board has a serial interface, you should use the Terminal Reporter. You must create a function which will transmit a string buffer via the serial interface. The NDIT module must be able to use this function to send back the menu or any command errors. The listing below shows an example.

Code Block
languagecpp
firstline1
titleListing - Terminal reporter output function
linenumberstrue
/*
***********************************************************************************************
*                                           NDIT_OutputFnct()
*
* Description : Output a string on the display.
*
* Argument(s) : p_buf       Pointer to buffer to output.
*
*               p_param     Pointer to IPerf output parameters. (unused)
*
* Return(s)   : none.
*
* Caller(s)   : various.
*
* Note(s)     : (1) The string pointed to by p_buf has to be NUL ('\0') terminated.
***********************************************************************************************
*/
#if (NDIT_COM == NDIT_SERIAL_COM)
void  NDIT_OutputFnct (CPU_CHAR         *p_buf,
                       IPERF_OUT_PARAM  *p_param)
{
   (void)&p_param;                                                                         (1)
  
    if (p_buf == (CPU_CHAR *)0) {                                                          (2)
        return;
    }
    APP_TRACE_INFO((p_buf));                                                               (3)
}
#endif



Panel
bgColor#f0f0f0

(1)  Prevent “variable unused” compiler warning.

(2) Validate that the pointer to the string is not null.

(3) Display the string on the serial port of the board. BSP_Ser_WrStr() is a BSP-specific function that outputs each character of the string passed in the parameter until it reaches the NULL character (“\0”). It terminates the string with the Carriage Return symbol (“\r”) followed by the Line Feed symbol (“\n”). The null is not transmitted.


You will also need to implement the task NDIT_TaskTerminal() which performs Terminal I/O. It must be able to:

...

The listing below shows a Terminal I/O task example.

Code Block
languagecpp
firstline1
titleListing - Terminal I/O task
linenumberstrue
/*
**********************************************************************************************
*                                           NDIT_TaskTerminal()
*
* Description : Task that reads the serial port input, processes the commands and verifies 
*               that the cmd has been correctly executed.
*
* Argument(s) : p_arg           Pointer to task input parameter (unused). 
*
* Return(s)   : none.
*
* Caller(s)   : AppTaskCreateTerminal().
*
* Note(s)     : none.
**********************************************************************************************
*/
#if (NDIT_COM == NDIT_SERIAL_COM)
void  NDIT_TaskTerminal (void  *p_arg)
{
    CPU_CHAR       cmd_str[TASK_TERMINAL_CMD_STR_MAX_LEN];
    CPU_SIZE_T     cmd_len;
    NDIT_ERR       err;
    
#if (IPERF_REPORTER == DEF_ENABLED)
    APP_TRACE_INFO(("\r\nTerminal I/O\r\n\r\n"));
    while (DEF_ON) {
        APP_TRACE(("\r\n>  "));
        BSP_Ser_RdStr((CPU_CHAR *)&cmd_str[0],                                                (1)
                      (CPU_INT16U) TASK_TERMINAL_CMD_STR_MAX_LEN);
        cmd_len = Str_Len(&cmd_str[0]);
        
        NDIT_ProcessCommand((CPU_CHAR     *)&cmd_str[0],                                      (2)
                            (CPU_INT16U    ) cmd_len,
                            (NDIT_OUT_FNCT )&NDIT_Output,
                            (IPERF_OUT_FNCT)&NDIT_OutputFnct,
                            (NDIT_ERR     *)&err);
        switch(err) {                                                                         (3)
            case NDIT_NO_ERR:
            case NDIT_ERR_NO_CMD:  
                break;
            case NDIT_ERR_IPERF:                                                              (4)
                NDIT_Output(("Error in IPerf Test\r\n\r\n"));
                break;
            case NDIT_ERR_MCAST:                                                              (5)
                NDIT_Output(("Error in Mcast Test\r\n\r\n"));
                break;
            case NDIT_ERR_IFSS:                                                               (6)
                NDIT_Output(("Error in IFSS Test\r\n\r\n"));
                break;
            case NDIT_ERR_NO_MATCH:                                                           (7)
                NDIT_Output(("Command not recognized\r\n\r\n"));
                break;    
        }
    }
#endif 
}
#endif


Panel
bgColor#f0f0f0

(1) Read string command from serial port.

(2) The command read from the serial port is processed and executed by the NDIT_ProcessCommand() function.

(3) Verify test executed correctly based on the return error from the NDIT_ProcessCommand() function.

(4) An error occurred during an IPerf test.

(5) An error occurred during a Multicast test.

(6) An error occurred during an Interface Start/Stop test.

(7) The provided command was neither recognized by the IPerf, Multicast or Interface Start/Stop test modules.

Note that you must initialize µC/IPerf before using the “Terminal Reporter.”



Server Reporter on the

...

Target

You can also use the network interface of your device to send commands to the NDIT. This way, if you don't have a Serial Port on your device, you can still send commands and receive results through the NDIT_TaskServer() task and NDIT_NetOutputFnct() display function.

The source of NDIT_NetOutputFnct() is displayed in the listing below:

Code Block
languagecpp
firstline1
titleListing - NDIT_NetOutputFnct display function
linenumberstrue
/*
**********************************************************************************************
*                                           NDIT_NetOutputFnct()
*
* Description : Outputs a string to the test host application.
*
* Argument(s) : p_buf       Pointer to buffer to output.
*
*               p_param     Pointer to IPERF_OUT_PARAM object.
*
* Return(s)   : none.
*
* Caller(s)   : various.
*
* Note(s)     : (1) The string pointed to by p_buf has to be NUL ('\0') terminated.
**********************************************************************************************
*/
#if (NDIT_COM == NDIT_NETWORK_COM)
void  NDIT_NetOutputFnct (CPU_CHAR         *p_buf,
                          IPERF_OUT_PARAM  *p_param)
{
    CPU_INT16U  tx_len;
    NET_ERR     net_err;
  
   (void)&p_param;                                                                        (1)
   
    if (p_buf == (CPU_CHAR *)0) {                                                         (2)
        return;
    }
    if (NDIT_TS_SockInfo.NetSockID != NET_SOCK_BSD_ERR_OPEN) {
        
        tx_len = (CPU_INT16U)Str_Len(p_buf);                                              (3)
        
        (void)NetApp_SockTx ((NET_SOCK_ID      ) NDIT_TS_SockInfo.NetSockID,              (4)
                             (void            *) p_buf,
                             (CPU_INT16U       ) tx_len,
                             (CPU_INT16S       ) NET_SOCK_FLAG_NONE,
                             (NET_SOCK_ADDR   *)&NDIT_TS_SockInfo.NetSockAddr,
                             (NET_SOCK_ADDR_LEN) NDIT_TS_SockInfo.NetSockAddrLen,
                             (CPU_INT16U       ) NDIT_SERVER_RETRY_MAX,
                             (CPU_INT32U       ) NDIT_SERVER_DELAY_MS,
                             (CPU_INT32U       ) NDIT_SERVER_DELAY_MS,
                             (NET_ERR         *)&net_err);    }
    }
}
#endif


Panel
bgColor#f0f0f0

(1)  Prevent “variable unused” compiler warning.

(2) Verify that the pointer is not null.

(3) Calculate buffer length.

(4) Send the buffer to the test station host using the test station host information found in the DIS_TS_SockInfo global variable.


The listing below shows the NDIT_TaskServer() function, which reads the commands from the test station host, processes them, and gives back the results to the test station host.

Code Block
languagecpp
firstline1
titleListing - NDIT_TaskServer() task
linenumberstrue
typedef  struct  host_sock_info {                                                           (1)
    NET_SOCK_ID        NetSockID;
    NET_SOCK_ADDR      NetSockAddr;
    NET_SOCK_ADDR_LEN  NetSockAddrLen;
} HOST_SOCK_INFO;
static  HOST_SOCK_INFO    NDIT_TS_SockInfo;                                                 (2)
/*
**********************************************************************************************
*                                              NDIT_TaskServer()
*
* Description:  This function creates a input/output ethernet communication link to use iPerf.
*
* Argument(s) : p_arg       Pointer to arg. (unused)
*
* Return(s)   : none.
*
* Caller(s)   : NDIT_TaskCreateServer().
*
* Note(s)     : (1) NDIT_COM must be defined to NDIT_NETWORK_COM in app_cfg.h for this function to be used.
*
**********************************************************************************************
*/
#if (NDIT_COM == NDIT_NETWORK_COM)
void  NDIT_TaskServer (void  *p_arg)
{
    NET_SOCK_ID        net_sock_id;
    NET_SOCK_ADDR_IP   server_addr_port;
    NET_SOCK_ADDR      client_addr_port;
    NET_SOCK_ADDR_LEN  client_addr_port_len;
    CPU_CHAR           buf[TASK_TERMINAL_CMD_STR_MAX_LEN];
    CPU_INT16S         rx_len;
    CPU_BOOLEAN        socket_connected;
    NET_ERR            net_err;
    NDIT_ERR           test_err;
    
    (void)&p_arg;                                                                           (3)
    Mem_Clr((void     *)&server_addr_port,                                                  (4)
            (CPU_SIZE_T) sizeof(server_addr_port));
    
    server_addr_port.AddrFamily = NET_SOCK_ADDR_FAMILY_IP_V4;
    server_addr_port.Port       = NET_UTIL_HOST_TO_NET_16(NDIT_PORT);
    server_addr_port.Addr       = NET_SOCK_ADDR_IP_WILDCARD;
    while (DEF_TRUE){
        socket_connected = DEF_YES;
        
        net_sock_id = NetApp_SockOpen((NET_SOCK_PROTOCOL_FAMILY) NET_SOCK_FAMILY_IP_V4,     (5)
                                      (NET_SOCK_TYPE           ) NET_SOCK_TYPE_DATAGRAM,
                                      (NET_SOCK_PROTOCOL       ) NET_SOCK_PROTOCOL_UDP,
                                      (CPU_INT16U              ) NDIT_SERVER_RETRY_MAX,
                                      (CPU_INT32U              ) NDIT_SERVER_DELAY_MS,
                                      (NET_ERR                *)&net_err);
        
        if (net_err != NET_APP_ERR_NONE) {
            APP_TRACE_INFO(("\r\nFail to open socket.\r\n\r\n"));                           (6)
            socket_connected = DEF_NO;
        } else {
            
            (void)NetApp_SockBind((NET_SOCK_ID      ) net_sock_id,                          (7)
                                  (NET_SOCK_ADDR   *)&server_addr_port,
                                  (NET_SOCK_ADDR_LEN) NET_SOCK_ADDR_SIZE,
                                  (CPU_INT16U       ) NDIT_SERVER_RETRY_MAX,
                                  (CPU_INT32U       ) NDIT_SERVER_DELAY_MS,
                                  (NET_ERR         *)&net_err);
            
            if (net_err != NET_APP_ERR_NONE) {
                                                                
                (void)NetApp_SockClose((NET_SOCK_ID) net_sock_id,                           (8)
                                       (CPU_INT32U ) 0u,
                                       (NET_ERR   *)&net_err);
                 
                 socket_connected = DEF_NO; 
            }
        }
        while(socket_connected == DEF_YES) {                                                (9)
            
            rx_len = NetApp_SockRx ((NET_SOCK_ID        ) net_sock_id,                     (10)
                                    (void              *)&buf[0],
                                    (CPU_INT16U         ) TASK_TERMINAL_CMD_STR_MAX_LEN,
                                    (CPU_INT16U         ) 0,
                                    (CPU_INT16S         ) NET_SOCK_FLAG_NONE,
                                    (NET_SOCK_ADDR     *)&client_addr_port,
                                    (NET_SOCK_ADDR_LEN *)&client_addr_port_len,
                                    (CPU_INT16U         ) 1,
                                    (CPU_INT32U         ) 0,
                                    (CPU_INT32U         ) 0,
                                    (NET_ERR           *)&net_err);
            switch (net_err) {
                case NET_APP_ERR_CONN_CLOSED:                                              (11)
                    socket_connected = DEF_NO; 
                    break;
                case NET_APP_ERR_NONE: 
                default:
                    break;
            }
            
            NDIT_TS_SockInfo.NetSockID      = net_sock_id;                                 (12)
            NDIT_TS_SockInfo.NetSockAddr    = client_addr_port; 
            NDIT_TS_SockInfo.NetSockAddrLen = client_addr_port_len;
            
            buf[rx_len] = '\0'; 
            NDIT_NetOutput(&buf[0]);                                                       (13)
            NDIT_NetOutput(NEW_LINE);
            
            NDIT_ProcessCommand((CPU_CHAR     *)&buf[0],                                   (14)
                                (CPU_INT16U    ) rx_len,
                                (NDIT_OUT_FNCT  )&NDIT_NetOutput,
                                (IPERF_OUT_FNCT)&NDIT_NetOutputFnct,
                                (NDIT_ERR      *)&test_err);
            switch(test_err) {                                                             (15)
                case NDIT_NO_ERR:
                case NDIT_ERR_NO_CMD:  
                    break;
                case NDIT_ERR_IPERF:
                    NDIT_NetOutput("\r\nError in IPerf Test\r\n\r\n");                     (16)
                    break;
                case NDIT_ERR_MCAST:
                    NDIT_NetOutput("\r\nError in Mcast Test\r\n\r\n");                     (17)
                    break;
                case NDIT_ERR_IFSS:
                    NDIT_NetOutput("\r\nError in IFSS Test\r\n\r\n");                      (18)
                    break;
                case NDIT_ERR_NO_MATCH:
                default:    
                    NDIT_NetOutput("\r\nCommand not recognized\r\n\r\n");                  (19)
                    break; 
            }
             
            NDIT_Delay (0, 0, 0, 100); 
        }
    }
}
#endif


Panel
bgColor#f0f0f0

(1) Structure that contains the test station host socket id, socket address and socket address length.

(2) The global variable that hold the necessary information for the NDIT display function to return the test results and information messages to the test station host.

(3) Prevent the “variable unused” warning from the compiler.

(4) Initialize NDIT Server Address and Port.

(5) Open socket for receiving host commands and publish results.

(6) An error has occurred during the opening of the socket.

(7) Bind the socket to a local port.

(8) If binding fails, close the socket.

(9) Server reading and command processing loop.

(10) Read the incoming command from the test station host.

(11) If socket is closed, then exit the while loop and restart connection process.

(12) Update remote host socket information for displaying test results and messages to the test station host.

(13) Reply to test station for acknowledgement.

(14) The command read from the serial port is processed and executed by the NDIT_ProcessCommand() function.

(15) Verify test executed correctly based on the return error from the NDIT_ProcessCommand() function.

(16) An error occurred during an IPerf test.

(17) An error occurred during a Multicast test.

(18) An error occurred during an Interface Start/Stop test.

(19) The provided command was neither recognized by the IPerf, Multicast or Interface Start/Stop test modules.