The VxWorks Shell

来源:互联网 发布:淘宝管控记录异常订单 编辑:程序博客网 时间:2024/04/30 09:39
 

The VxWorks shell is the command-line interface which allows you to interact directly with VxWorks. You may use commands to load programs, run various utilities, perform simple debugging, etc. VxWorks is single-user, so only one shell is active at any time. You use the shell when you type at the system's console, or when you login remotely using rlogin or telnet. When you issue a shell command, the shell executes it, and then prints a value (generally the command's result).

Differences from UNIX Shells

The VxWorks shell is VERY different from any of the UNIX shells. To describe the VxWorks shell in a single term, it is "interpreted C". It uses C syntax, with a couple of differences:

  • I/O redirection is supported using < and >
  • the types of variables cannot be declared (although casting is supported);
  • omitted trailing arguments default to 0 (zero);
  • parentheses are not required;
  • semicolons are not required at the end of a line.
So, it is much more similar to C than to any shell you've probably ever encountered.

What Can the Shell Do?

Function Invocation

From the shell, you can directly invoke any VxWorks system call (or any other global function in any module you have loaded) just by typing its name and providing arguments (separated by commas). For example, the UNIX time() function takes an optional pointer argument and returns the number of seconds elapsed since January 1, 1970. To find out what "time" your VxWorks target thinks it is, use:

timeIt will respond with something like:

value = 341193 = 0x534c9 = _trcStack + 0x185Notice that it prints the value in decimal and hexidecimal, along with something else mysterious. You will find out about this one in the symbol table tutorial. Note also that it didn't complain that you omitted the parentheses, or the argument (it defaulted the argument to 0, which works fine for this particular function).

Variables

You can examine and set the values of global variables just by typing their names (and the equals sign and new value if you wish to set a value). For example, to see the value of "shellTaskId" (in which VxWorks keeps the shell's task ID):

-> shellTaskId _shellTaskId = 0x7b760: value = 3488644 = 0x353b84To set the shell task's priority to 5, one would use:

-> shellTaskPriority=5 _shellTaskPriority = 0x6c864: value = 5 = 0x5You can create new variables by assigning a value to a name which is not already defined. To create a new variable called "myNewVar", use:

-> myNewVar=0 new symbol "myNewVar" added to symbol table. myNewVar = 0x3fdd3c: value = 0 = 0x0

"Built-in" Functions

Since direct calling of system services is not the most friendly thing, VxWorks also provides some "user-friendly" commands in "usrLib". You could consider these to be the shell's "built-in" functions. Some of the more useful ones are:

Command Description------- -----------i Show information on all running taskscd Change Directory; just like UNIX cdpwd Print Working Directory; just like UNIX pwdls List directory contentsll Long listing of directory contents; like UNIX "ls -l"ld Load a module (for whatever reason, it uses stdin, so redirecting input from a file is most useful)sp( FUNCPTR func, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9 ) Spawns a new task with the entrypoint given by func, passing the given arguments to the function (arg1..arg9 optional)devs List all devicesinetstatShow Show network connections (like netstat on UNIX)memShow( int type ) Show free memory summary; additional details if argument is non-zero

Important Notes

Normally, you must quote string literals as in C (with ""), except when they are file/device names which are targets of I/O redirection. For example, hostAdd() takes string arguments:

hostAdd( "b0sgh", "131.225.206.49" )but to redirect input to ld(), use something like:

ld < test.o

Scripting

The VxWorks shell is scriptable, meaning that you can tell it to run a set of commands you have previously saved in a file. The commands in the file have exactly the same syntax as if you were entering them interactively. Also, any lines starting with "#" are treated as comments (they are ignored). To run a script stored in a file, simply redirect the shell's input from that file. For example, to run a script in /home/myaccount/mytest:

</home/myaccount/mytest

The Startup Script

The most immediate use of the shell's scripting ability is the provision of a startup script. The startup script runs at boot time. This is where you can put the commands you always want to run, like loading your application's code, spawning tasks, etc. You specify the startup script in one of the boot parameters, which you can change using "bootChange". Be careful changing boot parameters!

原创粉丝点击