Main class of the Vrekrer_SCPI_Parser library. More...
#include <Vrekrer_scpi_parser.h>
Public Types | |
enum class | ErrorCode { NoError , UnknownCommand , Timeout , BufferOverflow } |
SCPI Error codes. More... | |
Public Member Functions | |
SCPI_Parser () | |
SCPI_Parser constructor. More... | |
void | SetCommandTreeBase (char *tree_base) |
Change the TreeBase for the next RegisterCommand calls. More... | |
void | SetCommandTreeBase (const char *tree_base) |
SetCommandTreeBase version with RAM string support. More... | |
void | SetCommandTreeBase (const __FlashStringHelper *tree_base) |
SetCommandTreeBase version with Flash strings (F() macro) support. More... | |
void | RegisterCommand (char *command, SCPI_caller_t caller) |
Registers a new valid command and associate a procedure to it. More... | |
void | RegisterCommand (const char *command, SCPI_caller_t caller) |
RegisterCommand version with RAM string support. More... | |
void | RegisterCommand (const __FlashStringHelper *command, SCPI_caller_t caller) |
RegisterCommand version with Flash strings (F() macro) support. More... | |
void | SetErrorHandler (SCPI_caller_t caller) |
Set the function to be used by the error handler. More... | |
void | Execute (char *message, Stream &interface) |
Process a message and execute it a valid command is found. More... | |
void | ProcessInput (Stream &interface, const char *term_chars) |
Gets a message from a Stream interface and execute it. More... | |
char * | GetMessage (Stream &interface, const char *term_chars) |
Gets a message from a Stream interface. More... | |
void | PrintDebugInfo () |
Prints registered tokens and command hashes to the serial interface. | |
Data Fields | |
ErrorCode | last_error = ErrorCode::NoError |
Variable that holds the last error code. | |
Protected Member Functions | |
void | AddToken_ (char *token) |
Add a token to the tokens' storage. | |
SCPI_HASH_TYPE | GetCommandCode_ (SCPI_Commands &commands) |
Get a hash from a valid command. More... | |
Protected Attributes | |
uint8_t | tokens_size_ = 0 |
char * | tokens_ [SCPI_MAX_TOKENS] |
uint8_t | codes_size_ = 0 |
SCPI_HASH_TYPE | valid_codes_ [SCPI_MAX_COMMANDS] |
SCPI_caller_t | callers_ [SCPI_MAX_COMMANDS+1] |
SCPI_HASH_TYPE | tree_code_ = 0 |
char | msg_buffer_ [SCPI_BUFFER_LENGTH] |
uint8_t | message_length_ = 0 |
unsigned long | time_checker_ |
Main class of the Vrekrer_SCPI_Parser library.
|
strong |
SCPI_Parser::SCPI_Parser | ( | ) |
SCPI_Parser constructor.
Example:
SCPI_Parser my_instrument
;
void SCPI_Parser::Execute | ( | char * | message, |
Stream & | interface | ||
) |
Process a message and execute it a valid command is found.
message | Message to be processed. |
interface | The source of the message. |
Commands and parameters are extracted from the message,
if a valid command is found, its associated procedure is executed.
The command' tokens and parameters, and the interface is passed to the executed procedure.
|
protected |
Get a hash from a valid command.
commands | Keywords of a command |
Returnn 0 if the command contains keywords not registered as tokens.
The hash is calculated including the TreeBase hash.
char * SCPI_Parser::GetMessage | ( | Stream & | interface, |
const char * | term_chars | ||
) |
Gets a message from a Stream interface.
interface | A Stream interface like Serial or Ethernet. |
term_chars | Termination chars e.g. "\r\n" . |
term_chars
are found, otherwise NULL
.Reads the available chars in the interface, if the term_chars are found the message is returned, otherwise the return is NULL
.
Subsequent calls to this function continues the message reading.
The message is discarded, and the error handler is called if:
A timeout occurs (10 ms without new chars)
The message buffer overflows
void SCPI_Parser::ProcessInput | ( | Stream & | interface, |
const char * | term_chars | ||
) |
Gets a message from a Stream interface and execute it.
void SCPI_Parser::RegisterCommand | ( | char * | command, |
SCPI_caller_t | caller | ||
) |
Registers a new valid command and associate a procedure to it.
command | New valid command. |
caller | Procedure associated to the valid command. |
void SCPI_Parser::RegisterCommand | ( | const __FlashStringHelper * | command, |
SCPI_caller_t | caller | ||
) |
RegisterCommand version with Flash strings (F() macro) support.
Example:
my_instrument.RegisterCommand(F("*IDN?"), &Identify);
void SCPI_Parser::RegisterCommand | ( | const char * | command, |
SCPI_caller_t | caller | ||
) |
RegisterCommand version with RAM string support.
Example:
my_instrument.RegisterCommand("*IDN?", &Identify);
For lower RAM usage use the Flash strings version.
void SCPI_Parser::SetCommandTreeBase | ( | char * | tree_base | ) |
Change the TreeBase for the next RegisterCommand calls.
tree_base | TreeBase to be used. An empty string "" sets the TreeBase to root. |
void SCPI_Parser::SetCommandTreeBase | ( | const __FlashStringHelper * | tree_base | ) |
SetCommandTreeBase version with Flash strings (F() macro) support.
Example:
my_instrument.SetCommandTreeBase(F("SYSTem:LED"));
void SCPI_Parser::SetCommandTreeBase | ( | const char * | tree_base | ) |
SetCommandTreeBase version with RAM string support.
Example:
my_instrument.SetCommandTreeBase("SYSTem:LED");
For lower RAM usage use the Flash strings version.
void SCPI_Parser::SetErrorHandler | ( | SCPI_caller_t | caller | ) |
Set the function to be used by the error handler.
Example:
my_instrument.SetErrorHandler(&myErrorHandler);