LibRTOSConsole-C-Library 1.0
Library Code documentation
Loading...
Searching...
No Matches
FreeRTOS Console Library

Introduction

The following code documentation is a set of tipps and diagramms as well as function and structure descriptions which help when using the library. It is used to increase the implementation speed. Some examples are attached in this documentation as well

static compile flags of the library

CONSOLE_USERNAME: The username in the console which is printed at least on power up before changing the username
CONSOLE_USE_DYNAMIC_USERNAME: The username can be changed on runtime which is enabled with this DEFINE
CONSOLE_LINE_HISTORY: specifies the maximum number of entries of the "last commands" buffer
CONSOLE_LINE_SIZE: Specifies the number of chars per line. When exceeding this number without a newline,
the console prints a buffer overflow and clears the input. All inputs are then invalidated within
this line
CONSOLE_COMMAND_MAX_LENGTH: Specifies the maximum number of chars per command
CONSOLE_HELP_MAX_LENGTH: Specifies the maximum number of chars per command help text

Examples

The following example shows how to create a instance of the console library and how to attach a function for console usage. This is called registering a command

static int CapabilityFunc( int argc, char** argv, void* ctx )
{
printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\nOK",
1, // has spindle
1, // has spindle status
1, // has stepper
1, // has stepper move relative
1, // has stepper move speed
1, // has stepper move async
1, // has stepper status
1, // has stepper refrun
1, // has stepper refrun timeout
1, // has stepper refrun skip
1, // has stepper refrun stay enabled
1, // has stepper reset
1, // has stepper position
1, // has stepper config
1, // has stepper config torque
1, // has stepper config throvercurr
1, // has stepper config powerena
1, // has stepper config stepmode
1, // has stepper config timeoff
1, // has stepper config timeon
1, // has stepper config timefast
1, // has stepper config mmperturn
1, // has stepper config posmax
1, // has stepper config posmin
1, // has stepper config posref
1, // has stepper config stepsperturn
1 // has stepper cancel
);
return 0;
}
...
// create the console processor. There are no additional arguments required because it uses stdin, stderr and
// stdout of the stdlib of the platform
ConsoleHandle_t c = CONSOLE_CreateInstance( 4*configMINIMAL_STACK_SIZE, configMAX_PRIORITIES - 5 );
// register the function, there is always a help text required, an empty string or null is not allowed!
CONSOLE_RegisterCommand(c, "capability", "prints a specified string of capability bits",
CapabilityFunc, NULL);
...
ConsoleHandle_t CONSOLE_CreateInstance(unsigned int uxStackDepth, int xPrio)
Definition Console.c:1397
int CONSOLE_RegisterCommand(ConsoleHandle_t h, char *cmd, char *help, CONSOLE_CommandFunc func, void *context)
Definition Console.c:1442

The following example shows a really simple console function and how it is used to work with the console and arguments passed by the user

static int ConsoleFunction( int argc, char** argv, void* ctx )
{
//possible commands are
//(command) start
//(command) stop
// first decode the subcommand and all arguments
if ( argc == 0 )
{
printf("invalid number of arguments\r\nFAIL");
return -1;
}
if ( strcmp(argv[0], "stop") == 0 )
{
// do something
}
else if ( strcmp(argv[0], "start") == 0 )
{
// do something else
}
else
{
printf("invalid subcommand was given as argument\r\nFAIL");
}
}