Motor Driver Evaluation Kit NEVB-MTR1-t01-1.0.0
Firmware for NEVB-MTR1-KIT1 for trapezoidal control of BLDC motors using Hall-effect sensors
Loading...
Searching...
No Matches
scpi_parser.h
Go to the documentation of this file.
1/* This file has been prepared for Doxygen automatic documentation generation.*/
33
34#ifndef _SCPI_PARSER_H_
35#define _SCPI_PARSER_H_
36
37#include "scpi_config.h"
38#include "scpi_types.h"
39
41using SCPI_caller_t = void (*)(SCPI_Commands, SCPI_Parameters, Stream &);
43using SCPI_special_caller_t = void (*)(SCPI_Commands, Stream &);
44
55{
56public:
57 // Constructor
59 // Change the TreeBase for the next RegisterCommand calls
60 void SetCommandTreeBase(char *tree_base);
61 // SetCommandTreeBase version with RAM string support
62 void SetCommandTreeBase(const char *tree_base);
63 // SetCommandTreeBase version with Flash strings (F() macro) support
64 void SetCommandTreeBase(const __FlashStringHelper *tree_base);
65 // Registers a new valid command and associate a procedure to it
66 void RegisterCommand(char *command, SCPI_caller_t caller);
67 // RegisterCommand version with RAM string support.
68 void RegisterCommand(const char *command, SCPI_caller_t caller);
69 // RegisterCommand version with Flash strings (F() macro) support
70 void RegisterCommand(const __FlashStringHelper *command,
71 SCPI_caller_t caller);
72 // Set the function to be used by the error handler.
73 void SetErrorHandler(SCPI_caller_t caller);
76 // Process a message and execute it a valid command is found
77 void Execute(char *message, Stream &interface);
78 // Gets a message from a Stream interface and execute it
79 void ProcessInput(Stream &interface, const char *term_chars);
80 // Gets a message from a Stream interface
81 char *GetMessage(Stream &interface, const char *term_chars);
82 // Prints registered tokens and command hashes to the serial interface
83 void PrintDebugInfo(Stream &interface);
89 unsigned long timeout = 10;
90
91#if SCPI_MAX_SPECIAL_COMMANDS
92 // Registers a new valid special command and associate a procedure to it
93 void RegisterSpecialCommand(char *command, SCPI_special_caller_t caller);
94 // RegisterSpecialCommand version with RAM string support.
95 void RegisterSpecialCommand(const char *command,
97 // RegisterSpecialCommand version with Flash strings (F() macro) support
98 void RegisterSpecialCommand(const __FlashStringHelper *command,
100#endif
101
102protected:
116 {
118 bool command_overflow = false;
120 bool token_overflow = false;
122 bool branch_overflow = false;
125 } setup_errors;
126
130
132 void AddToken_(char *token);
136 uint8_t tokens_size_ = 0;
140 uint8_t codes_size_ = 0;
148 uint8_t tree_length_ = 0;
152 uint8_t message_length_ = 0;
154 unsigned long time_checker_;
155
156#if SCPI_MAX_SPECIAL_COMMANDS
158 const uint8_t max_special_commands = SCPI_MAX_SPECIAL_COMMANDS;
160 uint8_t special_codes_size_ = 0;
162 scpi_hash_t valid_special_codes_[SCPI_MAX_SPECIAL_COMMANDS];
165#endif
166};
167
168#endif
Stores parsed command tokens.
Definition scpi_types.h:75
Stores parsed command parameters.
Definition scpi_types.h:93
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.
Definition scpi_parser.h:75
scpi_hash_t GetCommandCode_(SCPI_Commands &commands)
Get a hash from a command.
unsigned long timeout
Timeout, in miliseconds, for GetMessage and ProcessInput.
Definition scpi_parser.h:89
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.
Definition scpi_parser.h:85
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.
Definition scpi_parser.h:87
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.
Definition scpi_config.h:49
#define SCPI_BUFFER_LENGTH
Length of the buffer used to store incoming SCPI messages from the communication interface.
Definition scpi_config.h:83
#define SCPI_MAX_COMMANDS
Maximum number of distinct SCPI commands that can be registered with the parser.
Definition scpi_config.h:60
#define SCPI_MAX_SPECIAL_COMMANDS
Maximum number of special SCPI commands (without parameters) that can be registered.
Definition scpi_config.h:72
void(*)(SCPI_Commands, SCPI_Parameters, Stream &) SCPI_caller_t
Void template used with SCPI_Parser::RegisterCommand.
Definition scpi_parser.h:41
void(*)(SCPI_Commands, Stream &) SCPI_special_caller_t
Void template used with SCPI_Parser::RegisterSpecialCommand.
Definition scpi_parser.h:43
SCPI types header file.
uint8_t scpi_hash_t
Alias for SCPI integer hash type defined in SCPI_HASH_TYPE.
Definition scpi_types.h:110
ErrorCode
SCPI Error codes.
Definition scpi_types.h:118
@ NoError
No error occurred.
Definition scpi_types.h:120
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.