Fernando Cosentino / uTerminal

Dependencies:   USBDevice

Dependents:   uTerminal_Example

Embed: (wiki syntax)

« Back to documentation index

uTerminal Class Reference

uTerminal Class Reference

uTerminal processes messages from a serial port, parsing as a "COMMAND=value" pair, or "COMMAND=value1,value2,value3,..." set. More...

#include <uTerminal.h>

Public Member Functions

 uTerminal (PinName PinTX, PinName PinRX)
 Instances an uTerminal object.
 uTerminal (Serial *serial_object)
 Instances an uTerminal object.
 uTerminal (USBSerial *usbserial_object)
 Instances an uTerminal object.
void attach (void(*callback)())
 Attaches an external function to be called whenever a new command is received.
int Process ()
 Process the internal buffer and check for complete messages.
void ModeAuto ()
 Sets automatic mode: whenever a message is ready, Process() is automatically called.
void ModeManual ()
 Sets manual mode: whenever a message is ready, you have to call Process() to prepare the message before acting on it.
char * GetParam ()
 Retrieves the first or next parameter from the received message.
void print (char *str)
 Prints a string to serial port.

Data Fields

int NumParams
 When a new message is received, NumParams contains the number of parameters available to be read.
char Command [UTERMINAL_BUF_SIZE+1]
 String buffer (array of char) containing the received command (in a message like "BAUD=9600,1" the command would be "BAUD")
char Value [UTERMINAL_BUF_SIZE+1]
 String buffer (array of char) containing the received value (in a message like "BAUD=9600,1" the value would be "9600,1")
char Param [UTERMINAL_BUF_SIZE+1]
 String buffer (array of char) containing the current parameter taken from the value.
int ParamLen
 Length of useful data in Param.

Detailed Description

uTerminal processes messages from a serial port, parsing as a "COMMAND=value" pair, or "COMMAND=value1,value2,value3,..." set.

Definition at line 27 of file uTerminal.h.


Constructor & Destructor Documentation

uTerminal ( PinName  PinTX,
PinName  PinRX 
)

Instances an uTerminal object.

Parameters:
PinTXTX pin for the serial port.
PinRXRX pin for the serial port.

Definition at line 3 of file uTerminal.cpp.

uTerminal ( Serial *  serial_object )

Instances an uTerminal object.

Parameters:
serial_objectAn instance of a Serial object

Definition at line 10 of file uTerminal.cpp.

uTerminal ( USBSerial *  usbserial_object )

Instances an uTerminal object.

Parameters:
usbserial_objectAn instance of a USBSerial object

Definition at line 17 of file uTerminal.cpp.


Member Function Documentation

void attach ( void(*)()  callback )

Attaches an external function to be called whenever a new command is received.

Format for the callback is: void function_name()

Parameters:
callbackThe callback function to attach to

Definition at line 59 of file uTerminal.cpp.

char * GetParam (  )

Retrieves the first or next parameter from the received message.

In the first call, fetches the first parameter. All subsequent calls will return the next parameter.

Returns:
pointer to first char (that is, a C string)

Definition at line 142 of file uTerminal.cpp.

void ModeAuto (  )

Sets automatic mode: whenever a message is ready, Process() is automatically called.

Use in conjunction with your own interrupt service routine, attached as callback via attach().

Definition at line 51 of file uTerminal.cpp.

void ModeManual (  )

Sets manual mode: whenever a message is ready, you have to call Process() to prepare the message before acting on it.

This way you can decide the best time to poll Process() (useful in time-consuming code). This is the default mode.

Definition at line 55 of file uTerminal.cpp.

void print ( char *  str )

Prints a string to serial port.

If you want to use printf formatting functionalities, use sprintf to output your formatted data into a string buffer and then call this method passing your buffer as parameter.

Parameters:
strString to be sent to serial port

Definition at line 183 of file uTerminal.cpp.

int Process (  )

Process the internal buffer and check for complete messages.

Invokes the callback as appropriate.

Returns:
0 if command not yet present 1 if a command is present ended by a new line 2 if there is content filling the entire buffer

Definition at line 171 of file uTerminal.cpp.


Field Documentation

char Command[UTERMINAL_BUF_SIZE+1]

String buffer (array of char) containing the received command (in a message like "BAUD=9600,1" the command would be "BAUD")

Definition at line 90 of file uTerminal.h.

int NumParams

When a new message is received, NumParams contains the number of parameters available to be read.

If it is zero, the received message is just a command

Definition at line 85 of file uTerminal.h.

char Param[UTERMINAL_BUF_SIZE+1]

String buffer (array of char) containing the current parameter taken from the value.

(In a message like "BAUD=9600,1", after the first call to GetParam() Param would be "9600", and after the second call Param would be "1".)

Definition at line 102 of file uTerminal.h.

int ParamLen

Length of useful data in Param.

Param is actually safe to be used as a null-terminated string, but if the length of actual data in it is required this is it.

Definition at line 108 of file uTerminal.h.

char Value[UTERMINAL_BUF_SIZE+1]

String buffer (array of char) containing the received value (in a message like "BAUD=9600,1" the value would be "9600,1")

Definition at line 95 of file uTerminal.h.