This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Calling CLI lists without console

Hi,

In the Thread API under the Command Line Interface section, there are the following functions:

void otCliConsoleInit(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext)

void otCliConsoleInputLine(char *aBuf, uint16_t aBufLength)	

I'm assuming these functions can be used to manually input in main() an OpenThread command from the list shown here and log the output response without using the CLI console?

I hope someone can shed some light on this.

Parents
  • Hello Roger!

    Yes you are right! What is more, there is no requirement to run otCliUartInit simultanously (but it is possible).

    I have just run following code:

    otCliConsoleInit(m_app.p_ot_instance, console_output, NULL);
    
    char command[] = "help\n";
    otCliConsoleInputLine(command, strlen(command));
    

    The result (whole list of commands) is passed then to console_output function as a non-null terminated string and its size.

    Give me know if you need more details on this feature.

  • Hello,

    I have just modified CLI example from our nRF5 SDK for Thread v0.10.

    You can modify main section of the main.c to print CLI output on RTT:

    int console_output(const char *p_buf, uint16_t buf_length, void *p_context)
    {
    	(void)p_context;
    
    	// We need to ensure that p_buf is null terminated string in order to use NRF_LOG_INFO
    	// macro to print it.
    	// Currently OT always return p_buf as null-terminated string so below lines could
    	// be removed. But there is possibility that this will change over time.
    	char str[512];
    	memcpy(str, p_buf, buf_length);
    	str[buf_length] = 0;
    	
    	NRF_LOG_INFO("CLI Output: %s\r\n", (uint32_t)str);
    	
    	return buf_length;
    }
     
    int main(int argc, char *argv[])
    {
        NRF_LOG_INIT(NULL);
    
        thread_init();
    
        timer_init();
        thread_bsp_init();
        leds_init();
    
    	otCliConsoleInit(m_app.p_ot_instance, console_output, NULL);
    
    	char command[] = "state\n";
    	otCliConsoleInputLine(command, strlen(command));
    
        while (true)
        {
            otTaskletsProcess(m_app.p_ot_instance);
            PlatformProcessDrivers(m_app.p_ot_instance);
        }
    }
    
Reply
  • Hello,

    I have just modified CLI example from our nRF5 SDK for Thread v0.10.

    You can modify main section of the main.c to print CLI output on RTT:

    int console_output(const char *p_buf, uint16_t buf_length, void *p_context)
    {
    	(void)p_context;
    
    	// We need to ensure that p_buf is null terminated string in order to use NRF_LOG_INFO
    	// macro to print it.
    	// Currently OT always return p_buf as null-terminated string so below lines could
    	// be removed. But there is possibility that this will change over time.
    	char str[512];
    	memcpy(str, p_buf, buf_length);
    	str[buf_length] = 0;
    	
    	NRF_LOG_INFO("CLI Output: %s\r\n", (uint32_t)str);
    	
    	return buf_length;
    }
     
    int main(int argc, char *argv[])
    {
        NRF_LOG_INIT(NULL);
    
        thread_init();
    
        timer_init();
        thread_bsp_init();
        leds_init();
    
    	otCliConsoleInit(m_app.p_ot_instance, console_output, NULL);
    
    	char command[] = "state\n";
    	otCliConsoleInputLine(command, strlen(command));
    
        while (true)
        {
            otTaskletsProcess(m_app.p_ot_instance);
            PlatformProcessDrivers(m_app.p_ot_instance);
        }
    }
    
Children
No Data
Related