2 * @file ATcodec_Buffer.h
3 * @author aurelien.morelle@parrot.fr
7 #ifndef _AT_CODEC_INCLUDE_
8 #define _AT_CODEC_INCLUDE_
12 #include <VP_Os/vp_os_types.h>
13 #include <ATcodec/ATcodec_Memory.h>
16 #define INIT_CHAR_COUNT 128
17 #define INIT_SON_COUNT 1
18 #define INTERNAL_BUFFER_SIZE 1024
19 #define ATCODEC_SERVER_YIELD_DELAY 5
22 // For *_sprintf and *_sscanf debug
23 //#define AT_CODEC_DEBUG
25 //#define ATCODEC_DEBUG
29 typedef enum _ATCODEC_Return_Values
38 # define ATCODEC_DEBUG
39 #endif // <- AT_CODEC_DEBUG
43 # define ATCODEC_PRINT(...) \
45 # define ATCODEC_ZERO_MEMSET(DEST, VALUE, SIZE) \
46 vp_os_memset((DEST),(VALUE),(SIZE))
48 #else // ! ATCODEC_DEBUG
50 # define ATCODEC_PRINT(...) \
52 # define ATCODEC_ZERO_MEMSET(DEST, VALUE, SIZE) \
55 #endif // <- ATCODEC_DEBUG
59 * Inspired of the "Very complex scanf" from the CK5000 software, but again a little bit more complicated.
61 * This function allows the source string matching multiple model strings by using the '[' and ']' characters.
62 * For example, if the model string is "AT*PAVI=[%d],[%d],[%d],[%d]", successful matching source strings can be "AT*PAVI=76,,," or "AT*PAVI=76,,,87".
64 * It recognizes "%d", "%s", "%c", "%l". To match a '%' character, "\\%" can be used in <fmt>.
66 * To formulate a list pattern, "%l" must be followed by a '{' character, then the part which can be repeated, and finally a closing '}'.
68 * Parameters are saved in a memory area given in parameter.
72 * - Shared memory saving of the parameters has been changed (no allocation for new parameters).
74 * - Facultative pattern management has been enhanced (not compatible with the old : closing character present, and opening character different).
76 * - List management has been added.
78 * - Spaces have to match exactly between <str> and <fmt> strings.
80 * - Access to characters has been optmized by using a pointer instead of accessing them with an index
84 * %s - The character which follows a "%s" in <fmt> cannot be the '[' or '%' characters.
86 * - For "%s", the following character in <fmt> determines the closing of the string.
87 * An empty string does not match the "%s" pattern.
89 * %d - For "%d", the following character in <fmt> must be different from characters '0' to '9'.
90 * A matching "%d" pattern can begin with the '-' character.
92 * %c - "%c" can represent any character, excepted <str_lastchar>.
94 * [] - The character which follows a ']' closing character in <fmt> must not be a '%' or '[' character.
95 * The character which follows an '[' opening character in <fmt> must not be a '[' character but could be a '%' control character
96 * if the character which follows the respective ']' closing character make us able to determine if we try to match the facultative
97 * pattern or not. If this character does not correspond, we try to match the facultative pattern which begins with the '%' control character.
99 * - Characters that are between a '[' and a ']' character cannot contain other '[' or ']', excepted if they are escaped by a '\\' in <fmt>.
101 * %l - Elements of the list are considered to be separated by the ',' character. So to use a ',' character in the format of a list
102 * element, you have to escape it by a '\\'.
104 * - The character in <fmt> which follows the '}' character determines the closing of the list. Be careful not to have
105 * this character used in <str> for the elements of the list.
107 * - Between the '{' and '}' characters, all special controls can be used. Imbricated "%l" are also supported.
109 * @param str The source string to recognize
111 * @param fmt The model string to match
113 * @param memory The memory where to save parameters
115 * @param len_dec Used to get length decoded in str
117 * @retVal ATCODEC_TRUE If the strings match
118 * @retVal ATCODEC_FALSE If the strings do not match
123 ATcodec_Memory_t *str,
125 ATcodec_Memory_t *fmt,
127 ATcodec_Memory_t *memory,
133 * Common private function, see below
135 * @param params_from_memory 1 : params are passed from a memory area / 0 : params are accessed using va_list
136 * @param ... Optional parameters used to fill patterns
139 ATCodec_common_sprintf
141 ATcodec_Memory_t *dest,
144 ATcodec_Memory_t *fmt,
146 int params_from_memory,
147 ATcodec_Memory_t *params,
152 * Symmetrical function of the other one.
154 * The difficulty is to know to which pattern the arguments correspond. To resolve this,
155 * we provide additionnal informations between parameters when necessary :
157 * - for "%l" : before the parameters of the "%l" pattern must be expressed the size of the list
159 * - for facultative patterns : a boolean is used to know if we follow the facultative pattern or if we skip it
161 * Of course, rules that must be respected for the other symmetrical function must also be respected when formulating
162 * parameters. Otherwise, when decoded with the other, it will not work.
164 * @param dest The buffer to receive the result. It has to be allocated before ...
165 * @param len The length of the produced string
167 * @param fmt The model string to match
169 * @param ... Optional parameters used to fill patterns
171 * @retVal ATCODEC_TRUE If no error occured
172 * @retVal ATCODEC_FALSE If the model string is incorrect
175 vp_atcodec_sprintf_valist
177 ATcodec_Memory_t *dest,
180 ATcodec_Memory_t *fmt,
186 * Same function as the previous, but with parameters passed through a memory area.
188 * The difficulty is to know to which pattern the arguments correspond. To resolve this,
189 * we provide additionnal informations between parameters when necessary :
191 * - for "%l" : before the parameters of the "%l" pattern must be expressed the size of the list
193 * - for facultative patterns : a boolean is used to know if we follow the facultative pattern or if we skip it
195 * Of course, rules that must be respected for the other symmetrical function must also be respected when formulating
196 * parameters. Otherwise, when decoded with the other, it will not work.
198 * @param dest The buffer to receive the result. It has to be allocated before ...
199 * @param len The length of the produced string
201 * @param fmt The model string to match
203 * @param params Optional parameters used to fill patterns
205 * @retVal ATCODEC_TRUE If no error occured
206 * @retVal ATCODEC_FALSE If the model string is incorrect
209 vp_atcodec_sprintf_params
211 ATcodec_Memory_t *dest,
214 ATcodec_Memory_t *fmt,
216 ATcodec_Memory_t *params
220 #endif // ! _AT_CODEC_INCLUDE_