Shell - Whereis?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Shell - Whereis?

跳至解决方案
3,278 次查看
CarlFST60L
Senior Contributor II

Where do I find information on the shell library used in the demo?

I cannot find the source code, documents etc

1 解答
1,685 次查看
PetrL
NXP Employee
NXP Employee

Hi,

 

you will find shell sources in:

<MQX_INSTALL_DIR>\shell\source\..

 

Using shell is quite easy: 

 

  • 1)Include shell header into your application:
#include <shell.h>
  • 2)Prepare shell command structure:

 

const SHELL_COMMAND_STRUCT Shell_commands[] = {

    { "command_name", command_ptr},   
    { "?",         Shell_command_list },   
    { NULL,        NULL }
};

 if "command_name" is typed into shell console (IO_STDIN, IO_STDOUT), command_ptr function is called. You can implement your own command function. There are also prepared functions for working with mfs, rtcs, and mqx (sh_tad) - see sh_mfs.h, sh_rtcs.h in"\shell\source\include" directory.

 

  • 3) Start Shell in your program:
Shell(Shell_commands, NULL);

 

For example of usage see web_hvac demo, especially files - Shell_Task.c and Command_Lists.c. Do not forgot to enable DEMOCFG_ENABLE_SERIAL_SHELL in HVAC.h.

 

Message Edited by PetrL on 2009-11-22 03:01 PM

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,686 次查看
PetrL
NXP Employee
NXP Employee

Hi,

 

you will find shell sources in:

<MQX_INSTALL_DIR>\shell\source\..

 

Using shell is quite easy: 

 

  • 1)Include shell header into your application:
#include <shell.h>
  • 2)Prepare shell command structure:

 

const SHELL_COMMAND_STRUCT Shell_commands[] = {

    { "command_name", command_ptr},   
    { "?",         Shell_command_list },   
    { NULL,        NULL }
};

 if "command_name" is typed into shell console (IO_STDIN, IO_STDOUT), command_ptr function is called. You can implement your own command function. There are also prepared functions for working with mfs, rtcs, and mqx (sh_tad) - see sh_mfs.h, sh_rtcs.h in"\shell\source\include" directory.

 

  • 3) Start Shell in your program:
Shell(Shell_commands, NULL);

 

For example of usage see web_hvac demo, especially files - Shell_Task.c and Command_Lists.c. Do not forgot to enable DEMOCFG_ENABLE_SERIAL_SHELL in HVAC.h.

 

Message Edited by PetrL on 2009-11-22 03:01 PM
0 项奖励
回复
1,685 次查看
alfredogualdron
Contributor III

Hi,

I'm trying to make my own shell commands, but I can not figure out how to build the files I've created.

I wrote sh_myowncmd.c and sh_myowncmd.h, but I always get the errors:

undefined identifier 'Shell_mycmd'

the file 'sh_myowncmd.h' cannot be opened

I've tried to put the files into the "/Shell" source path but nothing happens

I also tried to edit and rebuild the "Shell source/.project" file, adding my files into it, but didn't work...

where I should put my source files?

Are there some document which explain how the mqx libraries work, and how I can add new ones?

I've checked the hvac example but i do not understand how it works...

best regards

0 项奖励
回复
1,685 次查看
Martin_
NXP Employee
NXP Employee

When building an MQX application, compiler searches into /lib directory for the MQX include header files and libraries. For your own shell functions, just simply add them into your application project, not to the MQX library project.

If you used Freescale CodeWarrior for MCU, I would recommend to create a new application using the CW New Project Wizard for MQX. In a new empty workspace, go to File->New->MQX 4.0 Project and then in next steps

-enter the name of your new application

-select the board you will be using

-select New Application

-select Freescale compiler in case of Kinetis (GCC use only with MQX 4.0.1)

-check "Add Shell Support"

-select "Basic Application"

-check "Create shell command structure"

In the generated project, see main.c. There is the following structure defined:

const SHELL_COMMAND_STRUCT Shell_commands[] = {

/*    Add your custom shell commands here    */

/* { "command_name",        Your_function }, */

   { "sh",        Shell_sh },

   { "help",      Shell_help },

   { "?",         Shell_command_list },  

   { "exit",      Shell_exit },

   { NULL,        NULL },

};

and you can start adding your commands, for example:

const SHELL_COMMAND_STRUCT Shell_commands[] = {

/*    Add your custom shell commands here    */

/* { "command_name",        Your_function }, */

   { "mycmd", Shell_mycmd }

   { "sh",        Shell_sh },

   { "help",      Shell_help },

   { "?",         Shell_command_list },  

   { "exit",      Shell_exit },

   { NULL,        NULL },

};

Then you need to define your "Shell_mycmd" function. In may look like this:

int_32 Shell_mycmd (int_32 argc, char_ptr argv[])

{

  boolean              print_usage, shorthelp = FALSE;

print_usage = Shell_check_help_request(argc, argv, &shorthelp );

if(!print_usage)

{

    MyFunc0();

}

if (print_usage)

{

    if (shorthelp)

    {

        printf("%s\n", argv[0]);

    }

    else

    {

        printf("Usage: %s\n", argv[0]);

    }

}

return SHELL_EXIT_SUCCESS;

}

where "MyFunc0" is the user function to be called and implementataon of "print_usage" conditions you can put your own help text.

1,685 次查看
alfredogualdron
Contributor III

Thank you so much...

I tried and it works fine...

0 项奖励
回复