AMU Library 3.0
C/C++ library for communicating with AMU (Aerospace Measurement Unit) devices
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1/*-
2 * Copyright (c) 2013 Jan Breuer
3 * Richard.hmm
4 * Copyright (c) 2012 Jan Breuer
5 *
6 * All Rights Reserved
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
38
39#ifndef SCPI_TYPES_H
40#define SCPI_TYPES_H
41
42#include <stddef.h>
43#include <stdint.h>
44#include "config.h"
45
46
47#if HAVE_STDBOOL
48#include <stdbool.h>
49#endif
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55#if !HAVE_STDBOOL
56 typedef unsigned char bool;
57#endif
58
59#ifndef FALSE
60#define FALSE 0
61#endif
62#ifndef TRUE
63#define TRUE (!FALSE)
64#endif
65
66 /* basic data types */
67 typedef bool scpi_bool_t;
68 /* typedef enum { FALSE = 0, TRUE } scpi_bool_t; */
69
70 /* IEEE 488.2 registers */
72 SCPI_REG_STB = 0, /* Status Byte */
73 SCPI_REG_SRE, /* Service Request Enable Register */
74 SCPI_REG_ESR, /* Standard Event Status Register (ESR, SESR) */
75 SCPI_REG_ESE, /* Event Status Enable Register */
76 SCPI_REG_OPER, /* OPERation Status Register */
77 SCPI_REG_OPERE, /* OPERation Status Enable Register */
78 SCPI_REG_QUES, /* QUEStionable status register */
79 SCPI_REG_QUESE, /* QUEStionable status Enable Register */
80
81 /* last definition - number of registers */
83 };
85
87 SCPI_CTRL_SRQ = 1, /* service request */
88 SCPI_CTRL_GTL, /* Go to local */
89 SCPI_CTRL_SDC, /* Selected device clear */
90 SCPI_CTRL_PPC, /* Parallel poll configure */
91 SCPI_CTRL_GET, /* Group execute trigger */
92 SCPI_CTRL_TCT, /* Take control */
93 SCPI_CTRL_LLO, /* Device clear */
94 SCPI_CTRL_DCL, /* Local lockout */
95 SCPI_CTRL_PPU, /* Parallel poll unconfigure */
96 SCPI_CTRL_SPE, /* Serial poll enable */
97 SCPI_CTRL_SPD, /* Serial poll disable */
98 SCPI_CTRL_MLA, /* My local address */
99 SCPI_CTRL_UNL, /* Unlisten */
100 SCPI_CTRL_MTA, /* My talk address */
101 SCPI_CTRL_UNT, /* Untalk */
102 SCPI_CTRL_MSA /* My secondary address */
103 };
105
106 typedef uint16_t scpi_reg_val_t;
107
108 /* scpi commands */
114
115
116#if USE_COMMAND_TAGS
117 #define SCPI_CMD_LIST_END {NULL, NULL, 0}
118#else
119 #define SCPI_CMD_LIST_END {NULL, NULL}
120#endif
121
122
123 /* scpi interface */
124 typedef struct _scpi_t scpi_t;
125 typedef struct _scpi_interface_t scpi_interface_t;
126
128 size_t length;
129 size_t position;
130 char * data;
131 };
132 typedef struct _scpi_buffer_t scpi_buffer_t;
133
135 size_t length;
136 size_t position;
137 const char * data;
138 };
139 typedef struct _scpi_const_buffer_t scpi_const_buffer_t;
140
141 typedef size_t(*scpi_write_t)(scpi_t * context, const char * data, size_t len);
143 typedef int (*scpi_error_callback_t)(scpi_t * context, int_fast16_t error);
144
145 /* scpi lexer */
176
182 typedef struct _scpi_token_t scpi_token_t;
183
185 char * buffer;
186 char * pos;
187 int len;
188 };
189 typedef struct _lex_state_t lex_state_t;
190
191 /* scpi parser */
198
205 typedef struct _scpi_parser_state_t scpi_parser_state_t;
206
208
210 size_t wr;
211 /* size_t rd; */
212 size_t count;
213 size_t size;
214 char * data;
215 };
216 typedef struct _scpi_error_info_heap_t scpi_error_info_heap_t;
217
219 int16_t error_code;
220#if USE_DEVICE_DEPENDENT_ERROR_INFORMATION
221 char * device_dependent_info;
222#endif
223 };
224 typedef struct _scpi_error_t scpi_error_t;
225
227 int16_t wr;
228 int16_t rd;
229 int16_t count;
230 int16_t size;
231 scpi_error_t * data;
232 };
233 typedef struct _scpi_fifo_t scpi_fifo_t;
234
235 /* scpi units */
293
295 const char * name;
297 double mult;
298 };
299#define SCPI_UNITS_LIST_END {NULL, SCPI_UNIT_NONE, 0}
300 typedef struct _scpi_unit_def_t scpi_unit_def_t;
301
315
317 const char * name;
318 int32_t tag;
319 };
320#define SCPI_CHOICE_LIST_END {NULL, -1}
321 typedef struct _scpi_choice_def_t scpi_choice_def_t;
322
324 const char * pattern;
326 #if USE_COMMAND_TAGS
327 uint16_t tag;
328 #endif /* USE_COMMAND_TAGS */
329 };
330 typedef struct _scpi_command_t scpi_command_t;
331
332
334 const scpi_command_t * cmd;
335 lex_state_t lex_state;
336 scpi_const_buffer_t cmd_raw;
337#ifdef __AMU_SCPI_USE_PROGMEM__
338 scpi_command_t cmd_s;
339 char cmd_pattern_s[SCPI_MAX_CMD_PATTERN_SIZE + 1];
340#endif
341 };
342 typedef struct _scpi_param_list_t scpi_param_list_t;
343
346
347 union {
348 double value;
349 int32_t tag;
352 int8_t base;
353 };
354 typedef struct _scpi_number_parameter_t scpi_number_t;
355
357 const char * ptr;
358 int32_t len;
359 };
360 typedef struct _scpi_data_parameter_t scpi_data_parameter_t;
361
362 typedef scpi_token_t scpi_parameter_t;
363
364
365
366
374
375 struct _scpi_t {
376 const scpi_command_t * def_cmdlist;
377 const scpi_command_t * aux_cmdlist;
378 scpi_buffer_t buffer;
379 scpi_param_list_t param_list;
380 scpi_interface_t * interface;
381 int_fast16_t output_count;
382 int_fast16_t input_count;
384 scpi_fifo_t error_queue;
385#if USE_DEVICE_DEPENDENT_ERROR_INFORMATION && !USE_MEMORY_ALLOCATION_FREE
386 scpi_error_info_heap_t error_info_heap;
387#endif
389 const scpi_unit_def_t * units;
391 scpi_parser_state_t parser_state;
392 const char * idn[4];
394
395 bool query;
397
398 };
399
408
409#ifdef __cplusplus
410}
411#endif
412
413#endif /* SCPI_TYPES_H */
414
SCPI Configuration.
#define SCPI_MAX_CMD_PATTERN_SIZE
Definition config.h:46
char * pos
Definition types.h:186
char * buffer
Definition types.h:185
char * data
Definition types.h:130
size_t position
Definition types.h:129
size_t length
Definition types.h:128
const char * name
Definition types.h:317
const char * pattern
Definition types.h:324
scpi_command_callback_t callback
Definition types.h:325
uint16_t tag
Definition types.h:327
const char * data
Definition types.h:137
const char * ptr
Definition types.h:357
int16_t error_code
Definition types.h:219
int16_t rd
Definition types.h:228
int16_t size
Definition types.h:230
int16_t wr
Definition types.h:227
scpi_error_t * data
Definition types.h:231
int16_t count
Definition types.h:229
scpi_error_callback_t error
Definition types.h:368
scpi_write_control_t control
Definition types.h:370
scpi_command_callback_t flush
Definition types.h:371
scpi_command_callback_t reset
Definition types.h:372
scpi_write_t write
Definition types.h:369
union _scpi_number_parameter_t::@111343061222217161234252247320002055250221266016 content
scpi_bool_t special
Definition types.h:345
scpi_const_buffer_t cmd_raw
Definition types.h:336
lex_state_t lex_state
Definition types.h:335
const scpi_command_t * cmd
Definition types.h:334
scpi_token_t programHeader
Definition types.h:200
scpi_token_t programData
Definition types.h:201
message_termination_t termination
Definition types.h:203
scpi_buffer_t buffer
Definition types.h:378
size_t arbitrary_reminding
Definition types.h:393
scpi_bool_t cmd_error
Definition types.h:383
bool query
Definition types.h:395
int_fast16_t output_count
Definition types.h:381
scpi_interface_t * interface
Definition types.h:380
void * user_context
Definition types.h:390
scpi_reg_val_t registers[SCPI_REG_COUNT]
Definition types.h:388
const scpi_unit_def_t * units
Definition types.h:389
int_fast16_t input_count
Definition types.h:382
bool has_param
Definition types.h:396
const scpi_command_t * aux_cmdlist
Definition types.h:377
const char * idn[4]
Definition types.h:392
scpi_fifo_t error_queue
Definition types.h:384
scpi_param_list_t param_list
Definition types.h:379
scpi_parser_state_t parser_state
Definition types.h:391
const scpi_command_t * def_cmdlist
Definition types.h:376
char * ptr
Definition types.h:179
scpi_token_type_t type
Definition types.h:178
double mult
Definition types.h:297
const char * name
Definition types.h:295
scpi_unit_t unit
Definition types.h:296
_message_termination_t
Definition types.h:192
@ SCPI_MESSAGE_TERMINATION_NONE
Definition types.h:193
@ SCPI_MESSAGE_TERMINATION_NL
Definition types.h:194
@ SCPI_MESSAGE_TERMINATION_SEMICOLON
Definition types.h:195
enum _scpi_array_format_t scpi_array_format_t
Definition types.h:407
bool scpi_bool_t
Definition types.h:67
enum _scpi_special_number_t scpi_special_number_t
Definition types.h:314
_scpi_result_t
Definition types.h:109
@ SCPI_RES_ERR
Definition types.h:111
@ SCPI_RES_OK
Definition types.h:110
_scpi_reg_name_t
Definition types.h:71
@ SCPI_REG_ESE
Definition types.h:75
@ SCPI_REG_SRE
Definition types.h:73
@ SCPI_REG_COUNT
Definition types.h:82
@ SCPI_REG_OPERE
Definition types.h:77
@ SCPI_REG_QUES
Definition types.h:78
@ SCPI_REG_STB
Definition types.h:72
@ SCPI_REG_ESR
Definition types.h:74
@ SCPI_REG_OPER
Definition types.h:76
@ SCPI_REG_QUESE
Definition types.h:79
enum _scpi_unit_t scpi_unit_t
Definition types.h:292
uint16_t scpi_reg_val_t
Definition types.h:106
enum _scpi_reg_name_t scpi_reg_name_t
Definition types.h:84
_scpi_unit_t
Definition types.h:236
@ SCPI_UNIT_YEAR
Definition types.h:287
@ SCPI_UNIT_CANDELA
Definition types.h:269
@ SCPI_UNIT_UNITLESS
Definition types.h:283
@ SCPI_UNIT_COULOMB
Definition types.h:255
@ SCPI_UNIT_BECQUEREL
Definition types.h:246
@ SCPI_UNIT_NEWTON
Definition types.h:259
@ SCPI_UNIT_FARAD
Definition types.h:254
@ SCPI_UNIT_INCH_OF_MERCURY
Definition types.h:277
@ SCPI_UNIT_HERTZ
Definition types.h:241
@ SCPI_UNIT_ATMOSPHERE
Definition types.h:276
@ SCPI_UNIT_FAGRENHEIT
Definition types.h:284
@ SCPI_UNIT_JOULE
Definition types.h:258
@ SCPI_UNIT_ATOMIC_MASS
Definition types.h:272
@ SCPI_UNIT_MILE
Definition types.h:266
@ SCPI_UNIT_STERADIAN
Definition types.h:252
@ SCPI_UNIT_TORT
Definition types.h:280
@ SCPI_UNIT_DBM
Definition types.h:275
@ SCPI_UNIT_FOOT
Definition types.h:264
@ SCPI_UNIT_BAR
Definition types.h:281
@ SCPI_UNIT_DECIBEL
Definition types.h:282
@ SCPI_UNIT_SIEVERT
Definition types.h:253
@ SCPI_UNIT_KELVIN
Definition types.h:285
@ SCPI_UNIT_GRAY
Definition types.h:245
@ SCPI_UNIT_RADIAN
Definition types.h:250
@ SCPI_UNIT_CELSIUS
Definition types.h:242
@ SCPI_UNIT_INCH
Definition types.h:263
@ SCPI_UNIT_OHM
Definition types.h:240
@ SCPI_UNIT_REVOLUTION
Definition types.h:251
@ SCPI_UNIT_LUX
Definition types.h:260
@ SCPI_UNIT_NAUTICAL_MILE
Definition types.h:267
@ SCPI_UNIT_ASTRONOMIC_UNIT
Definition types.h:262
@ SCPI_UNIT_MOLE
Definition types.h:247
@ SCPI_UNIT_DEGREE
Definition types.h:248
@ SCPI_UNIT_VOLT
Definition types.h:238
@ SCPI_UNIT_DAY
Definition types.h:286
@ SCPI_UNIT_POISE
Definition types.h:289
@ SCPI_UNIT_HENRY
Definition types.h:261
@ SCPI_UNIT_SIEMENS
Definition types.h:256
@ SCPI_UNIT_KILOGRAM
Definition types.h:273
@ SCPI_UNIT_GRADE
Definition types.h:249
@ SCPI_UNIT_TESLA
Definition types.h:271
@ SCPI_UNIT_ELECTRONVOLT
Definition types.h:257
@ SCPI_UNIT_AMPER
Definition types.h:239
@ SCPI_UNIT_LUMEN
Definition types.h:268
@ SCPI_UNIT_SECOND
Definition types.h:243
@ SCPI_UNIT_PARSEC
Definition types.h:265
@ SCPI_UNIT_MM_OF_MERCURY
Definition types.h:278
@ SCPI_UNIT_WEBER
Definition types.h:270
@ SCPI_UNIT_WATT
Definition types.h:274
@ SCPI_UNIT_PASCAL
Definition types.h:279
@ SCPI_UNIT_LITER
Definition types.h:290
@ SCPI_UNIT_STROKES
Definition types.h:288
@ SCPI_UNIT_METER
Definition types.h:244
@ SCPI_UNIT_NONE
Definition types.h:237
enum _message_termination_t message_termination_t
Definition types.h:197
unsigned char bool
Definition types.h:56
scpi_result_t(* scpi_command_callback_t)(scpi_t *)
Definition types.h:207
int(* scpi_error_callback_t)(scpi_t *context, int_fast16_t error)
Definition types.h:143
_scpi_ctrl_name_t
Definition types.h:86
@ SCPI_CTRL_SRQ
Definition types.h:87
@ SCPI_CTRL_SPE
Definition types.h:96
@ SCPI_CTRL_MSA
Definition types.h:102
@ SCPI_CTRL_DCL
Definition types.h:94
@ SCPI_CTRL_MTA
Definition types.h:100
@ SCPI_CTRL_SDC
Definition types.h:89
@ SCPI_CTRL_GTL
Definition types.h:88
@ SCPI_CTRL_UNT
Definition types.h:101
@ SCPI_CTRL_TCT
Definition types.h:92
@ SCPI_CTRL_LLO
Definition types.h:93
@ SCPI_CTRL_GET
Definition types.h:91
@ SCPI_CTRL_PPC
Definition types.h:90
@ SCPI_CTRL_PPU
Definition types.h:95
@ SCPI_CTRL_UNL
Definition types.h:99
@ SCPI_CTRL_SPD
Definition types.h:97
@ SCPI_CTRL_MLA
Definition types.h:98
scpi_result_t(* scpi_write_control_t)(scpi_t *context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val)
Definition types.h:142
enum _scpi_token_type_t scpi_token_type_t
Definition types.h:175
enum _scpi_result_t scpi_result_t
Definition types.h:113
_scpi_special_number_t
Definition types.h:302
@ SCPI_NUM_NINF
Definition types.h:311
@ SCPI_NUM_INF
Definition types.h:310
@ SCPI_NUM_MIN
Definition types.h:304
@ SCPI_NUM_DEF
Definition types.h:306
@ SCPI_NUM_NAN
Definition types.h:309
@ SCPI_NUM_UP
Definition types.h:307
@ SCPI_NUM_NUMBER
Definition types.h:303
@ SCPI_NUM_DOWN
Definition types.h:308
@ SCPI_NUM_AUTO
Definition types.h:312
@ SCPI_NUM_MAX
Definition types.h:305
_scpi_token_type_t
Definition types.h:146
@ SCPI_TOKEN_PROGRAM_MNEMONIC
Definition types.h:156
@ SCPI_TOKEN_BINNUM
Definition types.h:155
@ SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA
Definition types.h:162
@ SCPI_TOKEN_SEMICOLON
Definition types.h:148
@ SCPI_TOKEN_COMMON_QUERY_PROGRAM_HEADER
Definition types.h:169
@ SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX
Definition types.h:158
@ SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA
Definition types.h:161
@ SCPI_TOKEN_COMPOUND_QUERY_PROGRAM_HEADER
Definition types.h:168
@ SCPI_TOKEN_INCOMPLETE_COMMON_PROGRAM_HEADER
Definition types.h:167
@ SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA
Definition types.h:157
@ SCPI_TOKEN_SPECIFIC_CHARACTER
Definition types.h:150
@ SCPI_TOKEN_COMMA
Definition types.h:147
@ SCPI_TOKEN_OCTNUM
Definition types.h:154
@ SCPI_TOKEN_NL
Definition types.h:152
@ SCPI_TOKEN_HEXNUM
Definition types.h:153
@ SCPI_TOKEN_QUESTION
Definition types.h:151
@ SCPI_TOKEN_COLON
Definition types.h:149
@ SCPI_TOKEN_ALL_PROGRAM_DATA
Definition types.h:171
@ SCPI_TOKEN_COMMON_PROGRAM_HEADER
Definition types.h:166
@ SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA
Definition types.h:160
@ SCPI_TOKEN_INVALID
Definition types.h:172
@ SCPI_TOKEN_WS
Definition types.h:170
@ SCPI_TOKEN_PROGRAM_EXPRESSION
Definition types.h:163
@ SCPI_TOKEN_INCOMPLETE_COMPOUND_PROGRAM_HEADER
Definition types.h:165
@ SCPI_TOKEN_COMPOUND_PROGRAM_HEADER
Definition types.h:164
@ SCPI_TOKEN_SUFFIX_PROGRAM_DATA
Definition types.h:159
@ SCPI_TOKEN_UNKNOWN
Definition types.h:173
enum _scpi_ctrl_name_t scpi_ctrl_name_t
Definition types.h:104
_scpi_array_format_t
Definition types.h:400
@ SCPI_FORMAT_SWAPPED
Definition types.h:403
@ SCPI_FORMAT_NORMAL
Definition types.h:402
@ SCPI_FORMAT_ASCII
Definition types.h:401
@ SCPI_FORMAT_BIGENDIAN
Definition types.h:404
@ SCPI_FORMAT_LITTLEENDIAN
Definition types.h:405
size_t(* scpi_write_t)(scpi_t *context, const char *data, size_t len)
Definition types.h:141
scpi_token_t scpi_parameter_t
Definition types.h:362