ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / VP_SDK / ATcodec / ATcodec.h
1 /**
2  * @file ATcodec_Buffer.h
3  * @author aurelien.morelle@parrot.fr
4  * @date 2006/12/06
5  */
6
7 #ifndef _AT_CODEC_INCLUDE_
8 #define _AT_CODEC_INCLUDE_
9
10 #include <stdarg.h>
11
12 #include <VP_Os/vp_os_types.h>
13 #include <ATcodec/ATcodec_Memory.h>
14
15
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
20
21
22 // For *_sprintf and *_sscanf debug
23 //#define AT_CODEC_DEBUG
24 // For common debug
25 //#define ATCODEC_DEBUG
26
27
28 // Return values
29 typedef enum _ATCODEC_Return_Values
30 {
31   ATCODEC_TRUE,
32   ATCODEC_FALSE
33 }
34 ATCODEC_RET;
35
36
37 #ifdef AT_CODEC_DEBUG
38 # define ATCODEC_DEBUG
39 #endif // <- AT_CODEC_DEBUG
40
41 #ifdef ATCODEC_DEBUG
42
43 # define ATCODEC_PRINT(...) \
44          PRINT(__VA_ARGS__)
45 # define ATCODEC_ZERO_MEMSET(DEST, VALUE, SIZE) \
46          vp_os_memset((DEST),(VALUE),(SIZE))
47
48 #else // ! ATCODEC_DEBUG
49
50 # define ATCODEC_PRINT(...) \
51          do { } while(0)
52 # define ATCODEC_ZERO_MEMSET(DEST, VALUE, SIZE) \
53          do { } while(0)
54
55 #endif // <- ATCODEC_DEBUG
56
57
58 /**
59  * Inspired of the "Very complex scanf" from the CK5000 software, but again a little bit more complicated.
60  *
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".
63  *
64  * It recognizes "%d", "%s", "%c", "%l". To match a '%' character, "\\%" can be used in <fmt>.
65  *
66  * To formulate a list pattern, "%l" must be followed by a '{' character, then the part which can be repeated, and finally a closing '}'.
67  *
68  * Parameters are saved in a memory area given in parameter.
69  *
70  * CHANGES :
71  *
72  *      - Shared memory saving of the parameters has been changed (no allocation for new parameters).
73  *
74  *      - Facultative pattern management has been enhanced (not compatible with the old : closing character present, and opening character different).
75  *
76  *      - List management has been added.
77  *
78  *      - Spaces have to match exactly between <str> and <fmt> strings.
79  *
80  *      - Access to characters has been optmized by using a pointer instead of accessing them with an index
81  *
82  * RULES :
83  *
84  *      %s - The character which follows a "%s" in <fmt> cannot be the '[' or '%' characters.
85  *
86  *         - For "%s", the following character in <fmt> determines the closing of the string.
87  *           An empty string does not match the "%s" pattern.
88  *
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.
91  *
92  *      %c - "%c" can represent any character, excepted <str_lastchar>.
93  *
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.
98  *
99  *         - Characters that are between a '[' and a ']' character cannot contain other '[' or ']', excepted if they are escaped by a '\\' in <fmt>.
100  *
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 '\\'.
103  *
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.
106  *
107  *         - Between the '{' and '}' characters, all special controls can be used. Imbricated "%l" are also supported.
108  *
109  * @param str                   The source string to recognize
110  *
111  * @param fmt                   The model string to match
112  *
113  * @param memory                The memory where to save parameters
114  *
115  * @param len_dec               Used to get length decoded in str
116  *
117  * @retVal ATCODEC_TRUE         If the strings match
118  * @retVal ATCODEC_FALSE        If the strings do not match
119  */
120 ATCODEC_RET
121 vp_atcodec_sscanf
122         (
123                 ATcodec_Memory_t *str,
124
125                 ATcodec_Memory_t *fmt,
126
127                 ATcodec_Memory_t *memory,
128
129                 int *len_dec
130         );
131
132 /**
133  * Common private function, see below
134  *
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
137  */
138 ATCODEC_RET
139 ATCodec_common_sprintf
140         (
141                 ATcodec_Memory_t *dest,
142                 int32_t *len,
143
144                 ATcodec_Memory_t *fmt,
145
146                 int params_from_memory,
147                 ATcodec_Memory_t *params,
148                 va_list *va
149         );
150
151 /**
152  * Symmetrical function of the other one.
153  *
154  * The difficulty is to know to which pattern the arguments correspond. To resolve this,
155  * we provide additionnal informations between parameters when necessary :
156  *
157  *      - for "%l" : before the parameters of the "%l" pattern must be expressed the size of the list
158  *
159  *      - for facultative patterns : a boolean is used to know if we follow the facultative pattern or if we skip it
160  *
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.
163  *
164  * @param dest                  The buffer to receive the result. It has to be allocated before ...
165  * @param len                   The length of the produced string
166  *
167  * @param fmt                   The model string to match
168  *
169  * @param ...                   Optional parameters used to fill patterns
170  *
171  * @retVal ATCODEC_TRUE                 If no error occured
172  * @retVal ATCODEC_FALSE                If the model string is incorrect
173  */
174 ATCODEC_RET
175 vp_atcodec_sprintf_valist
176         (
177                 ATcodec_Memory_t *dest,
178                 int32_t *len,
179
180                 ATcodec_Memory_t *fmt,
181
182                 va_list *va
183         );
184
185 /**
186  * Same function as the previous, but with parameters passed through a memory area.
187  *
188  * The difficulty is to know to which pattern the arguments correspond. To resolve this,
189  * we provide additionnal informations between parameters when necessary :
190  *
191  *      - for "%l" : before the parameters of the "%l" pattern must be expressed the size of the list
192  *
193  *      - for facultative patterns : a boolean is used to know if we follow the facultative pattern or if we skip it
194  *
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.
197  *
198  * @param dest                  The buffer to receive the result. It has to be allocated before ...
199  * @param len                   The length of the produced string
200  *
201  * @param fmt                   The model string to match
202  *
203  * @param params                Optional parameters used to fill patterns
204  *
205  * @retVal ATCODEC_TRUE                 If no error occured
206  * @retVal ATCODEC_FALSE                If the model string is incorrect
207  */
208 ATCODEC_RET
209 vp_atcodec_sprintf_params
210         (
211                 ATcodec_Memory_t *dest,
212                 int32_t *len,
213
214                 ATcodec_Memory_t *fmt,
215
216                 ATcodec_Memory_t *params
217         );
218
219
220 #endif // ! _AT_CODEC_INCLUDE_