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_helper.h File Reference

SCPI helper header file. More...

#include "config.h"
#include "scpi_parser.h"
Include dependency graph for scpi_helper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SCPI_choice_def_t
 Defines a structure for SCPI choice options. More...
 

Typedefs

typedef struct _SCPI_choice_def_t SCPI_choice_def_t
 

Functions

uint8_t ScpiParamString (SCPI_P &parameters, String &param)
 Extracts a string parameter from the SCPI parameter list.
 
uint8_t ScpiParamUInt8 (SCPI_P &parameters, uint8_t &param)
 Extracts an unsigned 8-bit integer parameter from the SCPI parameter list.
 
uint8_t ScpiParamUInt32 (SCPI_P &parameters, uint32_t &param)
 Extracts an unsigned 32-bit integer parameter from the SCPI parameter list.
 
uint8_t ScpiParamDouble (SCPI_P &parameters, double &param)
 Extracts a double-precision floating-point parameter from the SCPI parameter list.
 
uint8_t ScpiParamBool (SCPI_P &parameters, bool &param)
 Extracts a boolean parameter ('ON', '1', 'OFF', or '0') from the SCPI parameter list.
 
uint8_t ScpiParamInt8 (SCPI_P &parameters, int8_t &param)
 
uint8_t ScpiParamChoice (SCPI_P &parameters, const SCPI_choice_def_t *options, size_t optionsSize, uint8_t &param)
 Extracts a choice parameter from the SCPI parameter list and maps it to a numerical tag.
 
uint8_t ScpiChoiceToName (const SCPI_choice_def_t *options, size_t optionsSize, int8_t value, String &name)
 Converts a numerical choice tag back to its string representation.
 

Detailed Description

SCPI helper header file.

This header file declares a set of helper functions designed to simplify the process of extracting and converting parameters from the SCPI parser and mapping choice values to their string representations. These functions are intended to be used in the implementation of SCPI commands.

Author
Nexperia: http://www.nexperia.com
Support Page
For additional support, visit: https://www.nexperia.com/support
Author
Aanas Sayed
Date
2025/04/21


Definition in file scpi_helper.h.

Function Documentation

◆ ScpiChoiceToName()

uint8_t ScpiChoiceToName ( const SCPI_choice_def_t * options,
size_t optionsSize,
int8_t value,
String & name )

Converts a numerical choice tag back to its string representation.

This function iterates through the provided list of valid choices and compares the input numerical tag with the tag of each choice. If a match is found, the stem and suffix of the corresponding choice are concatenated and stored in the output string.

Parameters
optionsA pointer to an array of SCPI_choice_def_t structures defining the valid choices.
optionsSizeThe number of elements in the options array.
valueThe numerical tag to convert to a string.
nameA reference to a String variable where the string representation of the tag will be stored.
Returns
1 if a matching choice was found and its name was stored in name, 0 otherwise (if no matching tag is found).

Definition at line 172 of file scpi_helper.cpp.

173{
174 for (size_t i = 0; i < optionsSize; i++)
175 {
176 if (options[i].tag == value)
177 {
178 name = options[i].stem + options[i].suffix;
179 return TRUE;
180 }
181 }
182 return FALSE;
183}
#define TRUE
TRUE constant value, defined to be compatible with comparisons.
Definition config.h:598
#define FALSE
FALSE constant value.
Definition config.h:596
Here is the caller graph for this function:

◆ ScpiParamBool()

uint8_t ScpiParamBool ( SCPI_P & parameters,
bool & param )

Extracts a boolean parameter ('ON', '1', 'OFF', or '0') from the SCPI parameter list.

This function checks if there are any parameters available. If so, it pops the last parameter from the list, converts it to uppercase, and checks if it matches "ON", "1" (for true) or "OFF", "0" (for false).

Parameters
parametersA reference to the SCPI parameter list.
paramA reference to a bool variable where the extracted parameter will be stored.
Returns
1 if a valid boolean parameter was successfully extracted, 0 otherwise (if no parameters are available or the parameter is invalid).

Definition at line 109 of file scpi_helper.cpp.

110{
111 if (parameters.Size() == 0)
112 return FALSE;
113 String rawParam = String(parameters.Pop());
114 rawParam.toUpperCase();
115
116 if (rawParam == "ON" || rawParam == "1")
117 param = TRUE;
118 else if (rawParam == "OFF" || rawParam == "0")
119 param = FALSE;
120 else
121 return FALSE;
122 return TRUE;
123}
uint8_t Size() const
Get the number of stored strings.
char * Pop()
Remove and return the last string (LIFO pop).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScpiParamChoice()

uint8_t ScpiParamChoice ( SCPI_P & parameters,
const SCPI_choice_def_t * options,
size_t optionsSize,
uint8_t & param )

Extracts a choice parameter from the SCPI parameter list and maps it to a numerical tag.

This function first extracts a string parameter. If successful, it iterates through the provided list of valid choices and compares the extracted string (case-insensitively) with the stem or the full stem and suffix of each choice. If a match is found, the corresponding numerical tag is stored in the output parameter.

Parameters
parametersA reference to the SCPI parameter list.
optionsA pointer to an array of SCPI_choice_def_t structures defining the valid choices.
optionsSizeThe number of elements in the options array.
paramA reference to a uint8_t variable where the numerical tag of the matched choice will be stored.
Returns
1 if a valid choice parameter was found and its tag was extracted, 0 otherwise (if no parameters are available or no match is found).

Definition at line 139 of file scpi_helper.cpp.

140{
141 String paramStr;
142 uint8_t result = ScpiParamString(parameters, paramStr);
143 if (result)
144 {
145 // Check if the parsed string matches any of the valid choices
146 for (size_t i = 0; i < optionsSize; i++)
147 {
148 if (paramStr.equalsIgnoreCase(options[i].stem) || paramStr.equalsIgnoreCase(options[i].stem + options[i].suffix))
149 {
150 param = options[i].tag;
151 return TRUE;
152 }
153 }
154 }
155 return FALSE;
156}
uint8_t ScpiParamString(SCPI_P &parameters, String &param)
Extracts a string parameter from the SCPI parameter list.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScpiParamDouble()

uint8_t ScpiParamDouble ( SCPI_P & parameters,
double & param )

Extracts a double-precision floating-point parameter from the SCPI parameter list.

This function checks if there are any parameters available. If so, it pops the last parameter from the list and converts it to a double.

Parameters
parametersA reference to the SCPI parameter list.
paramA reference to a double variable where the extracted parameter will be stored.
Returns
1 if a double-precision floating-point parameter was successfully extracted, 0 otherwise (if no parameters are available).

Definition at line 90 of file scpi_helper.cpp.

91{
92 if (parameters.Size() == 0)
93 return FALSE;
94 param = String(parameters.Pop()).toDouble();
95 return TRUE;
96}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScpiParamString()

uint8_t ScpiParamString ( SCPI_P & parameters,
String & param )

Extracts a string parameter from the SCPI parameter list.

This function checks if there are any parameters available. If so, it pops the last parameter from the list and converts it to a String.

Parameters
parametersA reference to the SCPI parameter list.
paramA reference to a String variable where the extracted parameter will be stored.
Returns
1 if a string parameter was successfully extracted, 0 otherwise (if no parameters are available).

Definition at line 36 of file scpi_helper.cpp.

37{
38 if (parameters.Size() == 0)
39 return FALSE;
40 param = String(parameters.Pop());
41 return TRUE;
42}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScpiParamUInt32()

uint8_t ScpiParamUInt32 ( SCPI_P & parameters,
uint32_t & param )

Extracts an unsigned 32-bit integer parameter from the SCPI parameter list.

This function checks if there are any parameters available. If so, it pops the last parameter from the list and converts it to an unsigned 32-bit integer.

Parameters
parametersA reference to the SCPI parameter list.
paramA reference to a uint32_t variable where the extracted parameter will be stored.
Returns
1 if an unsigned 32-bit integer parameter was successfully extracted, 0 otherwise (if no parameters are available).

Definition at line 72 of file scpi_helper.cpp.

73{
74 if (parameters.Size() == 0)
75 return FALSE;
76 param = String(parameters.Pop()).toInt();
77 return TRUE;
78}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScpiParamUInt8()

uint8_t ScpiParamUInt8 ( SCPI_P & parameters,
uint8_t & param )

Extracts an unsigned 8-bit integer parameter from the SCPI parameter list.

This function checks if there are any parameters available. If so, it pops the last parameter from the list and converts it to an unsigned 8-bit integer.

Parameters
parametersA reference to the SCPI parameter list.
paramA reference to a uint8_t variable where the extracted parameter will be stored.
Returns
1 if an unsigned 8-bit integer parameter was successfully extracted, 0 otherwise (if no parameters are available).

Definition at line 54 of file scpi_helper.cpp.

55{
56 if (parameters.Size() == 0)
57 return FALSE;
58 param = String(parameters.Pop()).toInt();
59 return TRUE;
60}
Here is the call graph for this function: