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.cpp
Go to the documentation of this file.
1/* This file has been prepared for Doxygen automatic documentation generation.*/
23
24#include "scpi_helper.h"
25
36uint8_t ScpiParamString(SCPI_P &parameters, String &param)
37{
38 if (parameters.Size() == 0)
39 return FALSE;
40 param = String(parameters.Pop());
41 return TRUE;
42}
43
54uint8_t ScpiParamUInt8(SCPI_P &parameters, uint8_t &param)
55{
56 if (parameters.Size() == 0)
57 return FALSE;
58 param = String(parameters.Pop()).toInt();
59 return TRUE;
60}
61
72uint8_t ScpiParamUInt32(SCPI_P &parameters, uint32_t &param)
73{
74 if (parameters.Size() == 0)
75 return FALSE;
76 param = String(parameters.Pop()).toInt();
77 return TRUE;
78}
79
90uint8_t ScpiParamDouble(SCPI_P &parameters, double &param)
91{
92 if (parameters.Size() == 0)
93 return FALSE;
94 param = String(parameters.Pop()).toDouble();
95 return TRUE;
96}
97
109uint8_t ScpiParamBool(SCPI_P &parameters, bool &param)
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}
124
139uint8_t ScpiParamChoice(SCPI_P &parameters, const SCPI_choice_def_t *options, size_t optionsSize, uint8_t &param)
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}
157
172uint8_t ScpiChoiceToName(const SCPI_choice_def_t *options, size_t optionsSize, int8_t value, String &name)
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}
uint8_t Size() const
Get the number of stored strings.
char * Pop()
Remove and return the last string (LIFO pop).
#define TRUE
TRUE constant value, defined to be compatible with comparisons.
Definition config.h:598
#define FALSE
FALSE constant value.
Definition config.h:596
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 ScpiParamBool(SCPI_P &parameters, bool &param)
Extracts a boolean parameter ('ON', '1', 'OFF', or '0') 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 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.
uint8_t ScpiParamString(SCPI_P &parameters, String &param)
Extracts a string parameter from the SCPI parameter list.
SCPI helper header file.
SCPI_Parameters SCPI_P
Alias for SCPI_Parameters.
Definition scpi_types.h:106