34#ifndef _SCPI_PARSER_H_
35#define _SCPI_PARSER_H_
77 void Execute(
char *message, Stream &interface);
79 void ProcessInput(Stream &interface,
const char *term_chars);
81 char *
GetMessage(Stream &interface,
const char *term_chars);
91#if SCPI_MAX_SPECIAL_COMMANDS
95 void RegisterSpecialCommand(
const char *command,
98 void RegisterSpecialCommand(
const __FlashStringHelper *command,
156#if SCPI_MAX_SPECIAL_COMMANDS
160 uint8_t special_codes_size_ = 0;
Stores parsed command tokens.
Stores parsed command parameters.
void PrintDebugInfo(Stream &interface)
Prints debug information about the SCPI parser configuration and status to a Stream interface.
ErrorCode last_error
Variable that holds the last error code.
scpi_hash_t GetCommandCode_(SCPI_Commands &commands)
Get a hash from a command.
unsigned long timeout
Timeout, in miliseconds, for GetMessage and ProcessInput.
void SetErrorHandler(SCPI_caller_t caller)
Sets the function to be used as the error handler.
const uint8_t buffer_length
Length of the message buffer.
uint8_t tokens_size_
Number of stored tokens.
void RegisterCommand(char *command, SCPI_caller_t caller)
Registers a new valid SCPI command and associates a callback function with it.
scpi_hash_t hash_magic_number
Magic number used for hashing the commands.
uint8_t tree_length_
TreeBase branch's length (0 for root)
unsigned long time_checker_
Varible used for checking timeout errors.
scpi_hash_t valid_codes_[20]
Registered commands' hash storage.
SCPI_Parser()
SCPI_Parser class constructor.
char msg_buffer_[64]
Message buffer.
const uint8_t max_commands
Max number of registered commands.
void AddToken_(char *token)
Add a token to the tokens' storage.
void SetCommandTreeBase(char *tree_base)
Changes the base of the command tree for subsequent RegisterCommand calls.
const scpi_hash_t invalid_hash
Hash reserved for invalid commands.
const scpi_hash_t unknown_hash
Hash result for unknown commands.
void ProcessInput(Stream &interface, const char *term_chars)
Reads a message from a Stream interface and executes it.
char * GetMessage(Stream &interface, const char *term_chars)
Reads a message from a Stream interface until termination characters are found.
scpi_hash_t hash_magic_offset
Magic offset used for hashing the commands.
SCPI_caller_t callers_[20+1]
Pointers to the functions to be called when a valid command is received.
uint8_t codes_size_
Number of registered commands.
scpi_hash_t tree_code_
TreeBase branch's hash used when calculating hashes (0 for root)
const uint8_t max_tokens
Max number of valid tokens.
char * tokens_[20]
Storage for tokens.
void Execute(char *message, Stream &interface)
Processes an incoming SCPI message and executes the associated command if found.
uint8_t message_length_
Length of the readed message.
SCPI parser configuration header file.
#define SCPI_MAX_TOKENS
Maximum number of valid SCPI tokens (keywords) that the parser can recognize.
#define SCPI_BUFFER_LENGTH
Length of the buffer used to store incoming SCPI messages from the communication interface.
#define SCPI_MAX_COMMANDS
Maximum number of distinct SCPI commands that can be registered with the parser.
#define SCPI_MAX_SPECIAL_COMMANDS
Maximum number of special SCPI commands (without parameters) that can be registered.
void(*)(SCPI_Commands, SCPI_Parameters, Stream &) SCPI_caller_t
Void template used with SCPI_Parser::RegisterCommand.
void(*)(SCPI_Commands, Stream &) SCPI_special_caller_t
Void template used with SCPI_Parser::RegisterSpecialCommand.
uint8_t scpi_hash_t
Alias for SCPI integer hash type defined in SCPI_HASH_TYPE.
ErrorCode
SCPI Error codes.
@ NoError
No error occurred.
Internal errors container.
bool branch_overflow
Branch (SCPI_Commands) storage overflow error.
bool command_overflow
Command storage overflow error.
bool token_overflow
Token storage overflow error.
bool special_command_overflow
Special command storage overflow error.