AMU Library 3.0
C/C++ library for communicating with AMU (Aerospace Measurement Unit) devices
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1/*-
2 * Copyright (c) 2012-2013 Jan Breuer,
3 *
4 * All Rights Reserved
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
36
37#ifndef __SCPI_CONFIG_H_
38#define __SCPI_CONFIG_H_
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44#include "cc.h"
45
46#define SCPI_MAX_CMD_PATTERN_SIZE 32
47
48/* set the termination character(s) */
49#define LINE_ENDING_CR "\r" /* use a <CR> carriage return as termination charcter */
50#define LINE_ENDING_LF "\n" /* use a <LF> line feed as termination charcter */
51#define LINE_ENDING_CRLF "\r\n" /* use <CR><LF> carriage return + line feed as termination charcters */
52
53#ifndef SCPI_LINE_ENDING
54#define SCPI_LINE_ENDING LINE_ENDING_LF
55#endif
56
61#define SYSTEM_BARE_METAL 0
62#define SYSTEM_FULL_BLOWN 1
63
64/* This should cover all windows compilers (msvc, mingw, cvi) and all Linux/OSX/BSD and other UNIX compatible systems (gcc, clang) */
65#if defined(_WIN32) || defined(_WIN64) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
66#define SYSTEM_TYPE SYSTEM_FULL_BLOWN
67#else
68#define SYSTEM_TYPE SYSTEM_BARE_METAL
69#endif
70
79#ifndef USE_FULL_ERROR_LIST
80#define USE_FULL_ERROR_LIST SYSTEM_TYPE
81#endif
82
88#ifndef USE_USER_ERROR_LIST
89#define USE_USER_ERROR_LIST SYSTEM_TYPE
90#endif
91
92#ifndef USE_DEVICE_DEPENDENT_ERROR_INFORMATION
93#define USE_DEVICE_DEPENDENT_ERROR_INFORMATION SYSTEM_TYPE
94#endif
95
96#if USE_DEVICE_DEPENDENT_ERROR_INFORMATION
97#ifndef USE_MEMORY_ALLOCATION_FREE
98#define USE_MEMORY_ALLOCATION_FREE 1
99#endif
100#endif
101
102#ifndef USE_COMMAND_TAGS
103#define USE_COMMAND_TAGS 1
104#endif
105
106#ifndef USE_DEPRECATED_FUNCTIONS
107#define USE_DEPRECATED_FUNCTIONS 1
108#endif
109
110#ifndef USE_CUSTOM_DTOSTR
111#define USE_CUSTOM_DTOSTR 0
112#endif
113
114#ifndef USE_UNITS_IMPERIAL
115#define USE_UNITS_IMPERIAL 0
116#endif
117
118#ifndef USE_UNITS_ANGLE
119#define USE_UNITS_ANGLE SYSTEM_TYPE
120#endif
121
122#ifndef USE_UNITS_PARTICLES
123#define USE_UNITS_PARTICLES SYSTEM_TYPE
124#endif
125
126#ifndef USE_UNITS_DISTANCE
127#define USE_UNITS_DISTANCE SYSTEM_TYPE
128#endif
129
130#ifndef USE_UNITS_MAGNETIC
131#define USE_UNITS_MAGNETIC SYSTEM_TYPE
132#endif
133
134#ifndef USE_UNITS_LIGHT
135#define USE_UNITS_LIGHT SYSTEM_TYPE
136#endif
137
138#ifndef USE_UNITS_ENERGY_FORCE_MASS
139#define USE_UNITS_ENERGY_FORCE_MASS SYSTEM_TYPE
140#endif
141
142#ifndef USE_UNITS_TIME
143#define USE_UNITS_TIME SYSTEM_TYPE
144#endif
145
146#ifndef USE_UNITS_TEMPERATURE
147#define USE_UNITS_TEMPERATURE SYSTEM_TYPE
148#endif
149
150#ifndef USE_UNITS_RATIO
151#define USE_UNITS_RATIO SYSTEM_TYPE
152#endif
153
154#ifndef USE_UNITS_POWER
155#define USE_UNITS_POWER 1
156#endif
157
158#ifndef USE_UNITS_FREQUENCY
159#define USE_UNITS_FREQUENCY 1
160#endif
161
162#ifndef USE_UNITS_ELECTRIC
163#define USE_UNITS_ELECTRIC 1
164#endif
165
166#ifndef USE_UNITS_ELECTRIC_CHARGE_CONDUCTANCE
167#define USE_UNITS_ELECTRIC_CHARGE_CONDUCTANCE SYSTEM_TYPE
168#endif
169
170/* define local macros depending on existance of strnlen */
171#if HAVE_STRNLEN
172#define SCPIDEFINE_strnlen(s, l) strnlen((s), (l))
173#else
174#define SCPIDEFINE_strnlen(s, l) BSD_strnlen((s), (l))
175#endif
176
177/* define local macros depending on existance of strncasecmp and strnicmp */
178#if HAVE_STRNCASECMP
179#define SCPIDEFINE_strncasecmp(s1, s2, l) strncasecmp((s1), (s2), (l))
180#elif HAVE_STRNICMP
181#define SCPIDEFINE_strncasecmp(s1, s2, l) strnicmp((s1), (s2), (l))
182#else
183#define SCPIDEFINE_strncasecmp(s1, s2, l) OUR_strncasecmp((s1), (s2), (l))
184#endif
185
186#if HAVE_DTOSTRE
187#define SCPIDEFINE_floatToStr(v, s, l) dtostre((double)(v), (s), 6, DTOSTR_PLUS_SIGN | DTOSTR_ALWAYS_SIGN | DTOSTR_UPPERCASE)
188#elif USE_CUSTOM_DTOSTRE
189#define SCPIDEFINE_floatToStr(v, s, l) SCPI_dtostre((v), (s), (l), 6, 0)
190#elif HAVE_SNPRINTF
191#define SCPIDEFINE_floatToStr(v, s, l) snprintf((s), (l), "%g", (v))
192#else
193#define SCPIDEFINE_floatToStr(v, s, l) SCPI_dtostre((v), (s), (l), 6, 0)
194#endif
195
196#if HAVE_DTOSTRE
197#define SCPIDEFINE_doubleToStr(v, s, l) dtostre((v), (s), 15, DTOSTR_PLUS_SIGN | DTOSTR_ALWAYS_SIGN | DTOSTR_UPPERCASE)
198#elif USE_CUSTOM_DTOSTRE
199#define SCPIDEFINE_doubleToStr(v, s, l) SCPI_dtostre((v), (s), (l), 15, 0)
200#elif HAVE_SNPRINTF
201#define SCPIDEFINE_doubleToStr(v, s, l) snprintf((s), (l), "%.15lg", (v))
202#else
203#define SCPIDEFINE_doubleToStr(v, s, l) SCPI_dtostre((v), (s), (l), 15, 0)
204#endif
205
206#if USE_DEVICE_DEPENDENT_ERROR_INFORMATION
207
208 #if USE_MEMORY_ALLOCATION_FREE
209 #include <stdlib.h>
210 #include <string.h>
211 #define SCPIDEFINE_DESCRIPTION_MAX_PARTS 2
212 #if HAVE_STRNDUP
213 #define SCPIDEFINE_strndup(h, s, l) strndup((s), (l))
214 #else
215 #define SCPIDEFINE_strndup(h, s, l) OUR_strndup((s), (l))
216 #endif
217 #define SCPIDEFINE_free(h, s, r) free((s))
218 #else
219 #define SCPIDEFINE_DESCRIPTION_MAX_PARTS 3
220 #define SCPIDEFINE_strndup(h, s, l) scpiheap_strndup((h), (s), (l))
221 #define SCPIDEFINE_free(h, s, r) scpiheap_free((h), (s), (r))
222 #define SCPIDEFINE_get_parts(h, s, l1, s2, l2) scpiheap_get_parts((h), (s), (l1), (s2), (l2))
223 #endif
224#else
225 #define SCPIDEFINE_DESCRIPTION_MAX_PARTS 1
226 #define SCPIDEFINE_strndup(h, s, l) NULL
227 #define SCPIDEFINE_free(h, s, r)
228#endif
229
230#if HAVE_SIGNBIT
231 #define SCPIDEFINE_signbit(n) signbit(n)
232#else
233 #define SCPIDEFINE_signbit(n) ((n)<0)
234#endif
235
236#if HAVE_FINITE
237 #define SCPIDEFINE_isfinite(n) finite(n)
238#elif HAVE_ISFINITE
239 #define SCPIDEFINE_isfinite(n) isfinite(n)
240#else
241 #define SCPIDEFINE_isfinite(n) (!SCPIDEFINE_isnan((n)) && ((n) < INFINITY) && ((n) > -INFINITY))
242#endif
243
244#if HAVE_STRTOF
245 #define SCPIDEFINE_strtof(n, p) strtof((n), (p))
246#else
247 #define SCPIDEFINE_strtof(n, p) strtod((n), (p))
248#endif
249
250#if HAVE_STRTOLL
251 #define SCPIDEFINE_strtoll(n, p, b) strtoll((n), (p), (b))
252 #define SCPIDEFINE_strtoull(n, p, b) strtoull((n), (p), (b))
253#else
254 #define SCPIDEFINE_strtoll(n, p, b) strtoll((n), (p), (b))
255 #define SCPIDEFINE_strtoull(n, p, b) strtoull((n), (p), (b))
256 extern long long int strtoll(const char *nptr, char **endptr, int base);
257 extern unsigned long long int strtoull(const char *nptr, char **endptr, int base);
258 /* TODO: implement OUR_strtoll and OUR_strtoull */
259 /* #warning "64bit string to int conversion not implemented" */
260#endif
261
262#if HAVE_ISNAN
263 #define SCPIDEFINE_isnan(n) isnan((n))
264#else
265 #define SCPIDEFINE_isnan(n) ((n) != (n))
266#endif
267
268#ifndef NAN
269 #define NAN (0.0 / 0.0)
270#endif
271
272#ifndef INFINITY
273 #define INFINITY (1.0 / 0.0)
274#endif
275
276#ifdef __cplusplus
277}
278#endif
279
280#endif
compiler detection
long long int strtoll(const char *nptr, char **endptr, int base)
unsigned long long int strtoull(const char *nptr, char **endptr, int base)