https://github.com/j123b567/scpi-parser
Dependents: scpi_sx127x scpi_sx127x_firstTest MLX90418_I2C_master
types.h
00001 /*- 00002 * Copyright (c) 2013 Jan Breuer 00003 * Richard.hmm 00004 * Copyright (c) 2012 Jan Breuer 00005 * 00006 * All Rights Reserved 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are 00010 * met: 00011 * 1. Redistributions of source code must retain the above copyright notice, 00012 * this list of conditions and the following disclaimer. 00013 * 2. Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the distribution. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00019 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00020 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 00024 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00025 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00026 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 00027 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 /** 00031 * @file scpi_types.h 00032 * @date Thu Nov 15 10:58:45 UTC 2012 00033 * 00034 * @brief SCPI data types 00035 * 00036 * 00037 */ 00038 00039 #ifndef SCPI_TYPES_H 00040 #define SCPI_TYPES_H 00041 00042 #include <stddef.h> 00043 #include <stdint.h> 00044 #include "scpi/config.h" 00045 00046 #if HAVE_STDBOOL 00047 #include <stdbool.h> 00048 #endif 00049 00050 #ifdef __cplusplus 00051 extern "C" { 00052 #endif 00053 00054 #if !HAVE_STDBOOL 00055 typedef unsigned char bool; 00056 #endif 00057 00058 #ifndef FALSE 00059 #define FALSE 0 00060 #endif 00061 #ifndef TRUE 00062 #define TRUE (!FALSE) 00063 #endif 00064 00065 /* basic data types */ 00066 typedef bool scpi_bool_t; 00067 /* typedef enum { FALSE = 0, TRUE } scpi_bool_t; */ 00068 00069 /* IEEE 488.2 registers */ 00070 enum _scpi_reg_name_t { 00071 SCPI_REG_STB = 0, /* Status Byte */ 00072 SCPI_REG_SRE, /* Service Request Enable Register */ 00073 SCPI_REG_ESR, /* Standard Event Status Register (ESR, SESR) */ 00074 SCPI_REG_ESE, /* Event Status Enable Register */ 00075 SCPI_REG_OPER, /* OPERation Status Register */ 00076 SCPI_REG_OPERE, /* OPERation Status Enable Register */ 00077 SCPI_REG_QUES, /* QUEStionable status register */ 00078 SCPI_REG_QUESE, /* QUEStionable status Enable Register */ 00079 00080 /* last definition - number of registers */ 00081 SCPI_REG_COUNT 00082 }; 00083 typedef enum _scpi_reg_name_t scpi_reg_name_t; 00084 00085 enum _scpi_ctrl_name_t { 00086 SCPI_CTRL_SRQ = 1, /* service request */ 00087 SCPI_CTRL_GTL, /* Go to local */ 00088 SCPI_CTRL_SDC, /* Selected device clear */ 00089 SCPI_CTRL_PPC, /* Parallel poll configure */ 00090 SCPI_CTRL_GET, /* Group execute trigger */ 00091 SCPI_CTRL_TCT, /* Take control */ 00092 SCPI_CTRL_LLO, /* Device clear */ 00093 SCPI_CTRL_DCL, /* Local lockout */ 00094 SCPI_CTRL_PPU, /* Parallel poll unconfigure */ 00095 SCPI_CTRL_SPE, /* Serial poll enable */ 00096 SCPI_CTRL_SPD, /* Serial poll disable */ 00097 SCPI_CTRL_MLA, /* My local address */ 00098 SCPI_CTRL_UNL, /* Unlisten */ 00099 SCPI_CTRL_MTA, /* My talk address */ 00100 SCPI_CTRL_UNT, /* Untalk */ 00101 SCPI_CTRL_MSA /* My secondary address */ 00102 }; 00103 typedef enum _scpi_ctrl_name_t scpi_ctrl_name_t; 00104 00105 typedef uint16_t scpi_reg_val_t; 00106 00107 /* scpi commands */ 00108 enum _scpi_result_t { 00109 SCPI_RES_OK = 1, 00110 SCPI_RES_ERR = -1 00111 }; 00112 typedef enum _scpi_result_t scpi_result_t; 00113 00114 typedef struct _scpi_command_t scpi_command_t; 00115 00116 #define SCPI_CMD_LIST_END {NULL, NULL, 0} 00117 00118 /* scpi interface */ 00119 typedef struct _scpi_t scpi_t; 00120 typedef struct _scpi_interface_t scpi_interface_t; 00121 00122 struct _scpi_buffer_t { 00123 size_t length; 00124 size_t position; 00125 char * data; 00126 }; 00127 typedef struct _scpi_buffer_t scpi_buffer_t; 00128 00129 struct _scpi_const_buffer_t { 00130 size_t length; 00131 size_t position; 00132 const char * data; 00133 }; 00134 typedef struct _scpi_const_buffer_t scpi_const_buffer_t; 00135 00136 typedef size_t(*scpi_write_t)(scpi_t * context, const char * data, size_t len); 00137 typedef scpi_result_t(*scpi_write_control_t)(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val); 00138 typedef int (*scpi_error_callback_t)(scpi_t * context, int_fast16_t error); 00139 00140 /* scpi lexer */ 00141 enum _scpi_token_type_t { 00142 SCPI_TOKEN_COMMA, 00143 SCPI_TOKEN_SEMICOLON, 00144 SCPI_TOKEN_QUESTION, 00145 SCPI_TOKEN_NL, 00146 SCPI_TOKEN_HEXNUM, 00147 SCPI_TOKEN_OCTNUM, 00148 SCPI_TOKEN_BINNUM, 00149 SCPI_TOKEN_PROGRAM_MNEMONIC, 00150 SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA, 00151 SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX, 00152 SCPI_TOKEN_SUFFIX_PROGRAM_DATA, 00153 SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA, 00154 SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA, 00155 SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA, 00156 SCPI_TOKEN_PROGRAM_EXPRESSION, 00157 SCPI_TOKEN_COMPOUND_PROGRAM_HEADER, 00158 SCPI_TOKEN_INCOMPLETE_COMPOUND_PROGRAM_HEADER, 00159 SCPI_TOKEN_COMMON_PROGRAM_HEADER, 00160 SCPI_TOKEN_INCOMPLETE_COMMON_PROGRAM_HEADER, 00161 SCPI_TOKEN_COMPOUND_QUERY_PROGRAM_HEADER, 00162 SCPI_TOKEN_COMMON_QUERY_PROGRAM_HEADER, 00163 SCPI_TOKEN_WS, 00164 SCPI_TOKEN_ALL_PROGRAM_DATA, 00165 SCPI_TOKEN_INVALID, 00166 SCPI_TOKEN_UNKNOWN, 00167 }; 00168 typedef enum _scpi_token_type_t scpi_token_type_t; 00169 00170 struct _scpi_token_t { 00171 scpi_token_type_t type; 00172 char * ptr; 00173 int len; 00174 }; 00175 typedef struct _scpi_token_t scpi_token_t; 00176 00177 struct _lex_state_t { 00178 char * buffer; 00179 char * pos; 00180 int len; 00181 }; 00182 typedef struct _lex_state_t lex_state_t; 00183 00184 /* scpi parser */ 00185 enum _message_termination_t { 00186 SCPI_MESSAGE_TERMINATION_NONE, 00187 SCPI_MESSAGE_TERMINATION_NL, 00188 SCPI_MESSAGE_TERMINATION_SEMICOLON, 00189 }; 00190 typedef enum _message_termination_t message_termination_t; 00191 00192 struct _scpi_parser_state_t { 00193 scpi_token_t programHeader; 00194 scpi_token_t programData; 00195 int numberOfParameters; 00196 message_termination_t termination; 00197 }; 00198 typedef struct _scpi_parser_state_t scpi_parser_state_t; 00199 00200 typedef scpi_result_t(*scpi_command_callback_t)(scpi_t *); 00201 00202 /* scpi error queue */ 00203 typedef void * scpi_error_queue_t; 00204 00205 /* scpi units */ 00206 enum _scpi_unit_t { 00207 SCPI_UNIT_NONE, 00208 SCPI_UNIT_VOLT, 00209 SCPI_UNIT_AMPER, 00210 SCPI_UNIT_OHM, 00211 SCPI_UNIT_HERTZ, 00212 SCPI_UNIT_CELSIUS, 00213 SCPI_UNIT_SECONDS, 00214 SCPI_UNIT_DISTANCE 00215 }; 00216 typedef enum _scpi_unit_t scpi_unit_t; 00217 00218 struct _scpi_unit_def_t { 00219 const char * name; 00220 scpi_unit_t unit; 00221 double mult; 00222 }; 00223 #define SCPI_UNITS_LIST_END {NULL, SCPI_UNIT_NONE, 0} 00224 typedef struct _scpi_unit_def_t scpi_unit_def_t; 00225 00226 enum _scpi_special_number_t { 00227 SCPI_NUM_NUMBER, 00228 SCPI_NUM_MIN, 00229 SCPI_NUM_MAX, 00230 SCPI_NUM_DEF, 00231 SCPI_NUM_UP, 00232 SCPI_NUM_DOWN, 00233 SCPI_NUM_NAN, 00234 SCPI_NUM_INF, 00235 SCPI_NUM_NINF, 00236 SCPI_NUM_AUTO 00237 }; 00238 typedef enum _scpi_special_number_t scpi_special_number_t; 00239 00240 struct _scpi_choice_def_t { 00241 const char * name; 00242 int32_t tag; 00243 }; 00244 #define SCPI_CHOICE_LIST_END {NULL, -1} 00245 typedef struct _scpi_choice_def_t scpi_choice_def_t; 00246 00247 struct _scpi_param_list_t { 00248 const scpi_command_t * cmd; 00249 lex_state_t lex_state; 00250 scpi_const_buffer_t cmd_raw; 00251 }; 00252 typedef struct _scpi_param_list_t scpi_param_list_t; 00253 00254 struct _scpi_number_parameter_t { 00255 scpi_bool_t special; 00256 union { 00257 double value; 00258 int32_t tag; 00259 }; 00260 scpi_unit_t unit; 00261 int8_t base; 00262 }; 00263 typedef struct _scpi_number_parameter_t scpi_number_t; 00264 00265 struct _scpi_data_parameter_t { 00266 const char * ptr; 00267 int32_t len; 00268 }; 00269 typedef struct _scpi_data_parameter_t scpi_data_parameter_t; 00270 00271 typedef scpi_token_t scpi_parameter_t; 00272 00273 struct _scpi_command_t { 00274 const char * pattern; 00275 scpi_command_callback_t callback; 00276 int32_t tag; 00277 }; 00278 00279 struct _scpi_interface_t { 00280 scpi_error_callback_t error; 00281 scpi_write_t write; 00282 scpi_write_control_t control; 00283 scpi_command_callback_t flush; 00284 scpi_command_callback_t reset; 00285 }; 00286 00287 struct _scpi_t { 00288 const scpi_command_t * cmdlist; 00289 scpi_buffer_t buffer; 00290 scpi_param_list_t param_list; 00291 scpi_interface_t * interface; 00292 int_fast16_t output_count; 00293 int_fast16_t input_count; 00294 scpi_bool_t cmd_error; 00295 scpi_error_queue_t error_queue; 00296 scpi_reg_val_t * registers; 00297 const scpi_unit_def_t * units; 00298 void * user_context; 00299 scpi_parser_state_t parser_state; 00300 const char * idn[4]; 00301 }; 00302 00303 #ifdef __cplusplus 00304 } 00305 #endif 00306 00307 #endif /* SCPI_TYPES_H */
Generated on Tue Jul 12 2022 19:30:15 by 1.7.2