<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>cli</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/39417/cli</link><description>Hi, 
 I am using cli and made my own command like bellow, as you see i have a command with 3 sub commands. But i think my idea is primitive because if i have 1000 sub command so i have to write many functions!!!! 
 Another problem of using this method</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 16 Oct 2018 12:44:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/39417/cli" /><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/153060?ContentTypeID=1</link><pubDate>Tue, 16 Oct 2018 12:44:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0dc167b-e61f-4e91-80b9-19a8a947b653</guid><dc:creator>D</dc:creator><description>&lt;p&gt;Im afraid i cant share it Jakub.&amp;nbsp;My problem solved. Thank u so much for helpfull advices.&lt;/p&gt;
&lt;p&gt;i used this structure and it worked.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void cmd_send(nrf_cli_t const * p_cli, size_t argc, char **argv)
{
    if ((argc == 1) || nrf_cli_help_requested(p_cli))
    {
    
    
    }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/153055?ContentTypeID=1</link><pubDate>Tue, 16 Oct 2018 12:30:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3131fb4-dddf-4842-aa31-c278fe8972c1</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;First things first. Inside a command context you should not use NRF_LOG because order of displayed text may be not according to your intention. Use nrf_cli_fprintf instead.&lt;/p&gt;
&lt;p&gt;May you please share complete project?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/153052?ContentTypeID=1</link><pubDate>Tue, 16 Oct 2018 12:11:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8fc0f33d-93c1-49a5-868b-db0e75accf76</guid><dc:creator>D</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**
 * Copyright (c) 2018 - 2018, Nordic Semiconductor ASA
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 * 
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 * 
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 * 
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 * 
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 */
#include  &amp;quot;nrf_cli.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;

#include &amp;lt;ctype.h&amp;gt;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;

#include &amp;quot;nrf_esb.h&amp;quot;


/* commands counter */
static uint8_t m_dynamic_cmd_cnt;

uint8_t     m_pyload_active = 0;

// INDIVIDUAL ADDRESSES SUBS

//@ Choose Board_1 function
static void b1(nrf_cli_t const * p_cli, size_t argc, char **argv)
      { 
           m_pyload_active = 1;    
      }
     
static char m_dynamic_cmd_buffer[][20] = {&amp;quot;b1&amp;quot;};
static void cmd_send(nrf_cli_t const * p_cli, size_t argc, char **argv)
{
    for (size_t i = 1; i &amp;lt; argc; i++)
    {
    	if (!strcmp(argv[i], m_dynamic_cmd_buffer[i]))
    		{
    		 
                  // NRF_LOG_DEBUG(&amp;quot;Transmitting packet %02x&amp;quot;,&amp;#39;payload.data[1]&amp;#39;);
                  payload.noack=false;

               if(m_pyload_active == 1){
                           data[0] = 0x19;
                 }           
             
                  if (nrf_esb_write_payload(&amp;amp;payload) == NRF_SUCCESS){
                    NRF_LOG_DEBUG(&amp;quot;Transmiting Successful!&amp;quot;);
                   }
                   else {
                    NRF_LOG_WARNING(&amp;quot;Sending packet failed&amp;quot;);
                   }

                    NRF_LOG_FLUSH();

    }
}


static void dynamic_cmd_get(size_t idx, nrf_cli_static_entry_t * p_static)
{
    ASSERT(p_static);

    if (idx &amp;lt; m_dynamic_cmd_cnt)
    {
        /* m_dynamic_cmd_buffer must be sorted alphabetically to ensure correct CLI completion */
        p_static-&amp;gt;p_syntax = m_dynamic_cmd_buffer[idx];
        p_static-&amp;gt;handler  = NULL;
        p_static-&amp;gt;p_subcmd = NULL;
        p_static-&amp;gt;p_help = NULL;
    }
    else
    {
        /* if there are no more dynamic commands available p_syntax must be set to NULL */
        p_static-&amp;gt;p_syntax = NULL;
    }
}
NRF_CLI_CREATE_DYNAMIC_CMD(m_sub_dynamic_set, dynamic_cmd_get);



NRF_CLI_CMD_REGISTER(send,
                     &amp;amp;m_sub_dynamic_set,
                     &amp;quot;Demonstrate dynamic command usage.&amp;quot;,
                     cmd_send);

NRF_CLI_CREATE_STATIC_SUBCMD_SET(m_sub_send)
{
    
    NRF_CLI_CMD(b1, &amp;amp;m_sub_dynamic_set, &amp;quot;Execute a command.&amp;quot;, b1),
};

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/153042?ContentTypeID=1</link><pubDate>Tue, 16 Oct 2018 11:33:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e97d5fb0-4f2c-4c00-8c80-cb73514993e7</guid><dc:creator>D</dc:creator><description>&lt;p&gt;The error resolved. Now i have another error:&lt;/p&gt;
&lt;p&gt;&lt;img alt="errors" src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/45711.Capture.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/153029?ContentTypeID=1</link><pubDate>Tue, 16 Oct 2018 10:44:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45586c80-7559-4774-870d-690f7a58358b</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;Please share an error message you have. Line no. 18 compiles on my side fine.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152967?ContentTypeID=1</link><pubDate>Tue, 16 Oct 2018 07:15:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fc70ed6-307b-4e82-9c14-2ef32302558b</guid><dc:creator>D</dc:creator><description>&lt;p&gt;Dear Jakub&lt;/p&gt;
&lt;p&gt;Thank you for answering. The code which i sent u to visit was just an example because of my better understanding of using commands and subcommands. in fact in the command i am using pipe (i prefer to use only one pipe not more!) and by the help of the payload data, i am sending data to another two boards. This is the reason that i want to use subcommands because without that i cant choose which board im going to send data. Moreover, i am using SEEGER Embedded Studio. The &amp;#39;&amp;#39;data&amp;#39;&amp;#39; in the code which i sent u is payload.data[0] also. Im eagerly waiting for ur answer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regatds&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152766?ContentTypeID=1</link><pubDate>Sat, 13 Oct 2018 18:49:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4b1e2ec-f308-4a0c-b5b3-dc5bd071b59c</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;post the full text of the error message&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152762?ContentTypeID=1</link><pubDate>Sat, 13 Oct 2018 15:43:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0065e4b9-adb4-420a-bf94-ee3edaeadd42</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;When I think a bit more about your use case I wonder why you need subcommands at all?&lt;/p&gt;
&lt;p&gt;You can have only 1 command and implement it like that:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void cmd_Do(nrf_cli_t const * p_cli, size_t argc, char **argv)
{
    data[0] = atoi(argv[i]);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and you can simply call it like that:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Do&amp;nbsp;10&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152759?ContentTypeID=1</link><pubDate>Sat, 13 Oct 2018 14:48:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9725603e-6c8f-4cae-ae54-1b938dee24ef</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;This code is not complete. What is &lt;strong&gt;data&lt;/strong&gt;?&lt;/p&gt;
&lt;p&gt;May you please let me know what is exact error message and what compiler you are using? May you share complete project?&lt;/p&gt;
&lt;p&gt;btw.&lt;/p&gt;
&lt;p&gt;Are you aware that functions:&amp;nbsp;DO_A,&amp;nbsp;DO_B, DO_C will not be called so variable&amp;nbsp;&lt;strong&gt;A&lt;/strong&gt; will not be updated?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152756?ContentTypeID=1</link><pubDate>Sat, 13 Oct 2018 12:03:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93055476-aa8d-4c86-ab16-5a670e1b7e5a</guid><dc:creator>D</dc:creator><description>&lt;p&gt;please see this code, im using the same concept which jacub said but i have an error for&amp;nbsp;&lt;span&gt;conflicting types&amp;nbsp;&lt;/span&gt;for &amp;#39;m_dynamic_cmd_buffer&amp;#39;. what is the problem?&lt;pre class="ui-code" data-mode="text"&gt;uint8_t     A= 0;

//sub commands
static void DO_A (nrf_cli_t const * p_cli, size_t argc, char **argv)
      { 
          A = 1;    
      }

static void DO_B (nrf_cli_t const * p_cli, size_t argc, char **argv)
      { 
          A = 2;
      }

static void DO_C (nrf_cli_t const * p_cli, size_t argc, char **argv)
      { 
          A = 3;
      }
static char m_dynamic_cmd_buffer[][20] = {&amp;quot;Do_A&amp;quot;, &amp;quot;Do_B&amp;quot;, &amp;quot;Do_C&amp;quot;};

// Command
static void cmd_send(nrf_cli_t const * p_cli, size_t argc, char **argv)
{
    for (size_t i = 1; i &amp;lt; argc; i++)
    {
    	if (!strcmp(argv[i], m_dynamic_cmd_buffer[i]))
    		{
    		//
    		//
    		//
              switch(A)
               {
                case 1:
                    data[0] = 0x19;
                        
                        break;
                 case 2:
                        data[0] = 0x20;
                        
                        break;
                }
            }    
    }                    
}

static void dynamic_cmd_get(size_t idx, nrf_cli_static_entry_t * p_static)
{
    ASSERT(p_static);

    if (idx &amp;lt; m_dynamic_cmd_cnt)
    {
        /* m_dynamic_cmd_buffer must be sorted alphabetically to ensure correct CLI completion */
        p_static-&amp;gt;p_syntax = m_dynamic_cmd_buffer[idx];
        p_static-&amp;gt;handler  = NULL;
        p_static-&amp;gt;p_subcmd = NULL;
        p_static-&amp;gt;p_help = NULL;
    }
    else
    {
        /* if there are no more dynamic commands available p_syntax must be set to NULL */
        p_static-&amp;gt;p_syntax = NULL;
    }
}


NRF_CLI_CREATE_DYNAMIC_CMD(m_sub_dynamic_set, dynamic_cmd_get);
NRF_CLI_CMD_REGISTER(Do,
                     &amp;amp;m_sub_dynamic_set,
                     &amp;quot;Demonstrate dynamic command usage.&amp;quot;,
                     cmd_Do);      &lt;/pre&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152755?ContentTypeID=1</link><pubDate>Sat, 13 Oct 2018 11:53:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d9ea984d-7ae3-43bd-a440-ed73f7063fec</guid><dc:creator>awneil</dc:creator><description>[quote userid="73588" url="~/f/nordic-q-a/39417/cli/152754"]error in line18[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have no idea what you&amp;#39;re talking about!&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see that mentioned anywhere else in this thread!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152754?ContentTypeID=1</link><pubDate>Sat, 13 Oct 2018 11:31:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43003a96-e127-4b50-a16e-c8b9bbe135d8</guid><dc:creator>D</dc:creator><description>&lt;p&gt;Thank for answering awneil. But could plz let me know about error in line18?&lt;/p&gt;
&lt;p&gt;&lt;span&gt;conflicting types for &amp;#39;m_dynamic_cmd_buffer&amp;#39;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152753?ContentTypeID=1</link><pubDate>Sat, 13 Oct 2018 11:25:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e53382d0-c405-4f59-9715-2f8a1844338b</guid><dc:creator>awneil</dc:creator><description>[quote userid="73588" url="~/f/nordic-q-a/39417/cli"]if i have 1000 sub command so i have to write&amp;nbsp;many functions!!!! [/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Obviously, if you have lots of commands, you are going to have to write lots of code to handle them all! There&amp;#39;s no escaping that!&lt;/p&gt;
&lt;p&gt;I think the Nordic CLI is really just for the purpose of simple demos.&lt;/p&gt;
&lt;p&gt;If you really do need a complex, extensive UI, then you are going to have to do a proper, full design yourself.&lt;/p&gt;
&lt;p&gt;This is a common task, not specific to Nordic - so you should be able to find plenty of general solutions, libraries, etc ...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152747?ContentTypeID=1</link><pubDate>Sat, 13 Oct 2018 06:51:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64390b58-4f46-4e5f-a925-20081f93c16f</guid><dc:creator>D</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please see the bellow code. this is what i mean. Because i think the problem is in Sub commands definitions.I will appreciate if you give me more guidance.&lt;/p&gt;
&lt;p&gt;Kind regards&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint8_t     A= 0;

//sub commands
static void DO_A (nrf_cli_t const * p_cli, size_t argc, char **argv)
      { 
          A = 1;    
      }

static void DO_B (nrf_cli_t const * p_cli, size_t argc, char **argv)
      { 
          A = 2;
      }

static void DO_C (nrf_cli_t const * p_cli, size_t argc, char **argv)
      { 
          A = 3;
      }
static char m_dynamic_cmd_buffer[][20] = {&amp;quot;Do_A&amp;quot;, &amp;quot;Do_B&amp;quot;, &amp;quot;Do_C&amp;quot;};

// Command
static void cmd_send(nrf_cli_t const * p_cli, size_t argc, char **argv)
{
    for (size_t i = 1; i &amp;lt; argc; i++)
    {
    	if (!strcmp(argv[i], m_dynamic_cmd_buffer[i]))
    		{
    		//
    		//
    		//
              switch(A)
               {
                case 1:
                    data[0] = 0x19;
                        
                        break;
                 case 2:
                        data[0] = 0x20;
                        
                        break;
                }
            }    
    }                    
}

static void dynamic_cmd_get(size_t idx, nrf_cli_static_entry_t * p_static)
{
    ASSERT(p_static);

    if (idx &amp;lt; m_dynamic_cmd_cnt)
    {
        /* m_dynamic_cmd_buffer must be sorted alphabetically to ensure correct CLI completion */
        p_static-&amp;gt;p_syntax = m_dynamic_cmd_buffer[idx];
        p_static-&amp;gt;handler  = NULL;
        p_static-&amp;gt;p_subcmd = NULL;
        p_static-&amp;gt;p_help = NULL;
    }
    else
    {
        /* if there are no more dynamic commands available p_syntax must be set to NULL */
        p_static-&amp;gt;p_syntax = NULL;
    }
}


NRF_CLI_CREATE_DYNAMIC_CMD(m_sub_dynamic_set, dynamic_cmd_get);
NRF_CLI_CMD_REGISTER(Do,
                     &amp;amp;m_sub_dynamic_set,
                     &amp;quot;Demonstrate dynamic command usage.&amp;quot;,
                     cmd_Do);      &lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152728?ContentTypeID=1</link><pubDate>Fri, 12 Oct 2018 15:00:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:365c8fdd-643e-451e-bcf2-d36aaaa000fa</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I do not understand why it is impossible and you will have a conflict types? Please let me know what problems you are facing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152722?ContentTypeID=1</link><pubDate>Fri, 12 Oct 2018 14:24:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:199a5dd1-1340-486a-a269-de4df0f77279</guid><dc:creator>D</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Thank you for answering and explanation&lt;span&gt;:).&lt;/span&gt; But putting char inside of array by this way is impossible and i will face issue with the&amp;nbsp;conflicting types for &amp;#39;m_dynamic_cmd_buffer&amp;#39;. Any other way?&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152701?ContentTypeID=1</link><pubDate>Fri, 12 Oct 2018 13:06:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8ee3cec-014e-4c88-9930-e8da38520508</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;This is syntax of your subcommands :). It only means that you can autocomplete commands A, B, c, z, d&lt;/p&gt;
&lt;p&gt;This table could look like that&lt;/p&gt;
&lt;p&gt;&lt;span&gt;static char m_dynamic_cmd_buffer[][20] = {&amp;quot;A_subcommand&amp;quot;, &amp;quot;B_subcommand&amp;quot;, &amp;quot;c_subcommand&amp;quot;};&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Next you can type in the CLI:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;em&gt;DO A &amp;lt;TAB&amp;gt;&lt;/em&gt; and CLI will autocompleate it to:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;em&gt;DO A_subcommand&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Next you can tab other (or the same) command.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;DO A_subcommand c &amp;lt;tab&amp;gt;&lt;/em&gt; will result in:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;DO A_subcommand c_subcommand&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152694?ContentTypeID=1</link><pubDate>Fri, 12 Oct 2018 12:42:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08fe9254-d12c-4e62-af8e-b0ed517fd273</guid><dc:creator>D</dc:creator><description>&lt;p&gt;Thank you for helpful advises. Could you please let me know about A,B,c,z,d?&lt;/p&gt;
&lt;p&gt;I mean this line:&lt;/p&gt;
&lt;p&gt;static char m_dynamic_cmd_buffer[10][20] = {&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;z&amp;quot;, &amp;quot;d&amp;quot;};&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cli</title><link>https://devzone.nordicsemi.com/thread/152683?ContentTypeID=1</link><pubDate>Fri, 12 Oct 2018 12:11:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47d7920e-eb28-49e0-babc-10cf7712ec13</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;What you can do is to implement handler for DO command only which will be checking what subcommands were passed to it using argc and argv.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To achieve that you need to use dynamic commands concept. It can look more less like that:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
static char m_dynamic_cmd_buffer[10][20] = {&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;z&amp;quot;, &amp;quot;d&amp;quot;};

static void cmd_DO(nrf_cli_t const * p_cli, size_t argc, char **argv)
{
    for (size_t i = 1; i &amp;lt; argc; i++)
    {
    	if (!strcmp(argv[i], m_dynamic_cmd_buffer[i])
    		{
    		 // do something
    		}
    }
}


static void dynamic_cmd_get(size_t idx, nrf_cli_static_entry_t * p_static)
{
    ASSERT(p_static);

    if (idx &amp;lt; m_dynamic_cmd_cnt)
    {
        /* m_dynamic_cmd_buffer must be sorted alphabetically to ensure correct CLI completion */
        p_static-&amp;gt;p_syntax = m_dynamic_cmd_buffer[idx];
        p_static-&amp;gt;handler  = NULL;
        p_static-&amp;gt;p_subcmd = NULL;
        p_static-&amp;gt;p_help = NULl;
    }
    else
    {
        /* if there are no more dynamic commands available p_syntax must be set to NULL */
        p_static-&amp;gt;p_syntax = NULL;
    }
}

NRF_CLI_CREATE_DYNAMIC_CMD(m_sub_dynamic_set, dynamic_cmd_get);
NRF_CLI_CMD_REGISTER(DO,
                     &amp;amp;m_sub_dynamic_set,
                     &amp;quot;Demonstrate dynamic command usage.&amp;quot;,
                     cmd_DO);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I did not compile it, it&amp;#39;s only a concept.&lt;/p&gt;
&lt;p&gt;Using this approach you will be able to autocomplete all subcommands.&lt;/p&gt;
&lt;p&gt;CLI is not capable to execute more than 1 handler at a time so you do not have much choice here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>