PS_Fgen_FW  4da88f4073c1cc65ea45c3a652a2751e495e50db
Firmware for an Power Supply and Function Generator build from an ATX power supply
Loading...
Searching...
No Matches
utils_private.h
1/*-
2 * BSD 2-Clause License
3 *
4 * Copyright (c) 2012-2018, Jan Breuer
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
37
38#ifndef SCPI_UTILS_PRIVATE_H
39#define SCPI_UTILS_PRIVATE_H
40
41#include <stdint.h>
43#include "../../../libraries/scpi-parser/inc/scpi/types.h"
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49#if defined(__GNUC__) && (__GNUC__ >= 4)
50#define LOCAL __attribute__((visibility ("hidden")))
51#else
52#define LOCAL
53#endif
54
55 char * strnpbrk(const char *str, size_t size, const char *set) LOCAL;
56 scpi_bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) LOCAL;
57 scpi_bool_t compareStrAndNum(const char * str1, size_t len1, const char * str2, size_t len2, int32_t * num) LOCAL;
58 size_t UInt32ToStrBaseSign(uint32_t val, char * str, size_t len, int8_t base, scpi_bool_t sign) LOCAL;
59 size_t UInt64ToStrBaseSign(uint64_t val, char * str, size_t len, int8_t base, scpi_bool_t sign) LOCAL;
60 size_t strBaseToInt32(const char * str, int32_t * val, int8_t base) LOCAL;
61 size_t strBaseToUInt32(const char * str, uint32_t * val, int8_t base) LOCAL;
62 size_t strBaseToInt64(const char * str, int64_t * val, int8_t base) LOCAL;
63 size_t strBaseToUInt64(const char * str, uint64_t * val, int8_t base) LOCAL;
64 size_t strToFloat(const char * str, float * val) LOCAL;
65 size_t strToDouble(const char * str, double * val) LOCAL;
66 scpi_bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL;
67 scpi_bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL;
68 size_t skipWhitespace(const char * cmd, size_t len) LOCAL;
69 scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len, int32_t * num) LOCAL;
70 scpi_bool_t matchCommand(const char * pattern, const char * cmd, size_t len, int32_t *numbers, size_t numbers_len, int32_t default_value) LOCAL;
71 scpi_bool_t composeCompoundCommand(const scpi_token_t * prev, scpi_token_t * current) LOCAL;
72
73#define SCPI_DTOSTRE_UPPERCASE 1
74#define SCPI_DTOSTRE_ALWAYS_SIGN 2
75#define SCPI_DTOSTRE_PLUS_SIGN 4
76 char * SCPI_dtostre(double __val, char * __s, size_t __ssize, unsigned char __prec, unsigned char __flags);
77
78 scpi_array_format_t SCPI_GetNativeFormat(void);
79 uint16_t SCPI_Swap16(uint16_t val);
80 uint32_t SCPI_Swap32(uint32_t val);
81 uint64_t SCPI_Swap64(uint64_t val);
82
83#if !HAVE_STRNLEN
84 size_t BSD_strnlen(const char *s, size_t maxlen) LOCAL;
85#endif
86
87#if !HAVE_STRNCASECMP && !HAVE_STRNICMP
88 int OUR_strncasecmp(const char *s1, const char *s2, size_t n) LOCAL;
89#endif
90
91#if USE_DEVICE_DEPENDENT_ERROR_INFORMATION && !USE_MEMORY_ALLOCATION_FREE
92 void scpiheap_init(scpi_error_info_heap_t * heap, char * error_info_heap, size_t error_info_heap_length);
93 char * scpiheap_strndup(scpi_error_info_heap_t * heap, const char *s, size_t n) LOCAL;
94 void scpiheap_free(scpi_error_info_heap_t * heap, char *s, scpi_bool_t rollback) LOCAL;
95 scpi_bool_t scpiheap_get_parts(scpi_error_info_heap_t * heap, const char *s1, size_t * len1, const char ** s2, size_t * len2) LOCAL;
96#endif
97
98#if !HAVE_STRNDUP
99 char *OUR_strndup(const char *s, size_t n);
100#endif
101
102#ifndef min
103#define min(a, b) (((a) < (b)) ? (a) : (b))
104#endif
105
106#ifndef max
107#define max(a, b) (((a) > (b)) ? (a) : (b))
108#endif
109
110#if 0
111#define max(a,b) \
112 ({ __typeof__ (a) _a = (a); \
113 __typeof__ (b) _b = (b); \
114 _a > _b ? _a : _b; })
115
116#define min(a,b) \
117 ({ __typeof__ (a) _a = (a); \
118 __typeof__ (b) _b = (b); \
119 _a < _b ? _a : _b; })
120
121#endif
122
123#ifdef __cplusplus
124}
125#endif
126
127#endif /* SCPI_UTILS_PRIVATE_H */
128
SCPI Configuration.