/src/open5gs/lib/sbi/openapi/model/velocity_estimate.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "velocity_estimate.h" |
6 | | |
7 | | OpenAPI_velocity_estimate_t *OpenAPI_velocity_estimate_create( |
8 | | float h_speed, |
9 | | int bearing, |
10 | | float v_speed, |
11 | | OpenAPI_vertical_direction_e v_direction, |
12 | | float h_uncertainty, |
13 | | float v_uncertainty, |
14 | | OpenAPI_radial_velocity_t *r_velocity, |
15 | | OpenAPI_angular_velocity_t *a_transverse_velocity, |
16 | | OpenAPI_angular_velocity_t *e_transverse_velocity |
17 | | ) |
18 | 0 | { |
19 | 0 | OpenAPI_velocity_estimate_t *velocity_estimate_local_var = ogs_malloc(sizeof(OpenAPI_velocity_estimate_t)); |
20 | 0 | ogs_assert(velocity_estimate_local_var); |
21 | | |
22 | 0 | velocity_estimate_local_var->h_speed = h_speed; |
23 | 0 | velocity_estimate_local_var->bearing = bearing; |
24 | 0 | velocity_estimate_local_var->v_speed = v_speed; |
25 | 0 | velocity_estimate_local_var->v_direction = v_direction; |
26 | 0 | velocity_estimate_local_var->h_uncertainty = h_uncertainty; |
27 | 0 | velocity_estimate_local_var->v_uncertainty = v_uncertainty; |
28 | 0 | velocity_estimate_local_var->r_velocity = r_velocity; |
29 | 0 | velocity_estimate_local_var->a_transverse_velocity = a_transverse_velocity; |
30 | 0 | velocity_estimate_local_var->e_transverse_velocity = e_transverse_velocity; |
31 | |
|
32 | 0 | return velocity_estimate_local_var; |
33 | 0 | } |
34 | | |
35 | | void OpenAPI_velocity_estimate_free(OpenAPI_velocity_estimate_t *velocity_estimate) |
36 | 0 | { |
37 | 0 | OpenAPI_lnode_t *node = NULL; |
38 | |
|
39 | 0 | if (NULL == velocity_estimate) { |
40 | 0 | return; |
41 | 0 | } |
42 | 0 | if (velocity_estimate->r_velocity) { |
43 | 0 | OpenAPI_radial_velocity_free(velocity_estimate->r_velocity); |
44 | 0 | velocity_estimate->r_velocity = NULL; |
45 | 0 | } |
46 | 0 | if (velocity_estimate->a_transverse_velocity) { |
47 | 0 | OpenAPI_angular_velocity_free(velocity_estimate->a_transverse_velocity); |
48 | 0 | velocity_estimate->a_transverse_velocity = NULL; |
49 | 0 | } |
50 | 0 | if (velocity_estimate->e_transverse_velocity) { |
51 | 0 | OpenAPI_angular_velocity_free(velocity_estimate->e_transverse_velocity); |
52 | 0 | velocity_estimate->e_transverse_velocity = NULL; |
53 | 0 | } |
54 | 0 | ogs_free(velocity_estimate); |
55 | 0 | } |
56 | | |
57 | | cJSON *OpenAPI_velocity_estimate_convertToJSON(OpenAPI_velocity_estimate_t *velocity_estimate) |
58 | 0 | { |
59 | 0 | cJSON *item = NULL; |
60 | 0 | OpenAPI_lnode_t *node = NULL; |
61 | |
|
62 | 0 | if (velocity_estimate == NULL) { |
63 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [VelocityEstimate]"); |
64 | 0 | return NULL; |
65 | 0 | } |
66 | | |
67 | 0 | item = cJSON_CreateObject(); |
68 | 0 | if (cJSON_AddNumberToObject(item, "hSpeed", velocity_estimate->h_speed) == NULL) { |
69 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [h_speed]"); |
70 | 0 | goto end; |
71 | 0 | } |
72 | | |
73 | 0 | if (cJSON_AddNumberToObject(item, "bearing", velocity_estimate->bearing) == NULL) { |
74 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [bearing]"); |
75 | 0 | goto end; |
76 | 0 | } |
77 | | |
78 | 0 | if (cJSON_AddNumberToObject(item, "vSpeed", velocity_estimate->v_speed) == NULL) { |
79 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [v_speed]"); |
80 | 0 | goto end; |
81 | 0 | } |
82 | | |
83 | 0 | if (velocity_estimate->v_direction == OpenAPI_vertical_direction_NULL) { |
84 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [v_direction]"); |
85 | 0 | return NULL; |
86 | 0 | } |
87 | 0 | if (cJSON_AddStringToObject(item, "vDirection", OpenAPI_vertical_direction_ToString(velocity_estimate->v_direction)) == NULL) { |
88 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [v_direction]"); |
89 | 0 | goto end; |
90 | 0 | } |
91 | | |
92 | 0 | if (cJSON_AddNumberToObject(item, "hUncertainty", velocity_estimate->h_uncertainty) == NULL) { |
93 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [h_uncertainty]"); |
94 | 0 | goto end; |
95 | 0 | } |
96 | | |
97 | 0 | if (cJSON_AddNumberToObject(item, "vUncertainty", velocity_estimate->v_uncertainty) == NULL) { |
98 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [v_uncertainty]"); |
99 | 0 | goto end; |
100 | 0 | } |
101 | | |
102 | 0 | if (velocity_estimate->r_velocity) { |
103 | 0 | cJSON *r_velocity_local_JSON = OpenAPI_radial_velocity_convertToJSON(velocity_estimate->r_velocity); |
104 | 0 | if (r_velocity_local_JSON == NULL) { |
105 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [r_velocity]"); |
106 | 0 | goto end; |
107 | 0 | } |
108 | 0 | cJSON_AddItemToObject(item, "rVelocity", r_velocity_local_JSON); |
109 | 0 | if (item->child == NULL) { |
110 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [r_velocity]"); |
111 | 0 | goto end; |
112 | 0 | } |
113 | 0 | } |
114 | | |
115 | 0 | if (velocity_estimate->a_transverse_velocity) { |
116 | 0 | cJSON *a_transverse_velocity_local_JSON = OpenAPI_angular_velocity_convertToJSON(velocity_estimate->a_transverse_velocity); |
117 | 0 | if (a_transverse_velocity_local_JSON == NULL) { |
118 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [a_transverse_velocity]"); |
119 | 0 | goto end; |
120 | 0 | } |
121 | 0 | cJSON_AddItemToObject(item, "aTransverseVelocity", a_transverse_velocity_local_JSON); |
122 | 0 | if (item->child == NULL) { |
123 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [a_transverse_velocity]"); |
124 | 0 | goto end; |
125 | 0 | } |
126 | 0 | } |
127 | | |
128 | 0 | if (velocity_estimate->e_transverse_velocity) { |
129 | 0 | cJSON *e_transverse_velocity_local_JSON = OpenAPI_angular_velocity_convertToJSON(velocity_estimate->e_transverse_velocity); |
130 | 0 | if (e_transverse_velocity_local_JSON == NULL) { |
131 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [e_transverse_velocity]"); |
132 | 0 | goto end; |
133 | 0 | } |
134 | 0 | cJSON_AddItemToObject(item, "eTransverseVelocity", e_transverse_velocity_local_JSON); |
135 | 0 | if (item->child == NULL) { |
136 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed [e_transverse_velocity]"); |
137 | 0 | goto end; |
138 | 0 | } |
139 | 0 | } |
140 | | |
141 | 0 | end: |
142 | 0 | return item; |
143 | 0 | } |
144 | | |
145 | | OpenAPI_velocity_estimate_t *OpenAPI_velocity_estimate_parseFromJSON(cJSON *velocity_estimateJSON) |
146 | 0 | { |
147 | 0 | OpenAPI_velocity_estimate_t *velocity_estimate_local_var = NULL; |
148 | 0 | OpenAPI_lnode_t *node = NULL; |
149 | 0 | cJSON *h_speed = NULL; |
150 | 0 | cJSON *bearing = NULL; |
151 | 0 | cJSON *v_speed = NULL; |
152 | 0 | cJSON *v_direction = NULL; |
153 | 0 | OpenAPI_vertical_direction_e v_directionVariable = 0; |
154 | 0 | cJSON *h_uncertainty = NULL; |
155 | 0 | cJSON *v_uncertainty = NULL; |
156 | 0 | cJSON *r_velocity = NULL; |
157 | 0 | OpenAPI_radial_velocity_t *r_velocity_local_nonprim = NULL; |
158 | 0 | cJSON *a_transverse_velocity = NULL; |
159 | 0 | OpenAPI_angular_velocity_t *a_transverse_velocity_local_nonprim = NULL; |
160 | 0 | cJSON *e_transverse_velocity = NULL; |
161 | 0 | OpenAPI_angular_velocity_t *e_transverse_velocity_local_nonprim = NULL; |
162 | 0 | h_speed = cJSON_GetObjectItemCaseSensitive(velocity_estimateJSON, "hSpeed"); |
163 | 0 | if (!h_speed) { |
164 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [h_speed]"); |
165 | 0 | goto end; |
166 | 0 | } |
167 | 0 | if (!cJSON_IsNumber(h_speed)) { |
168 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [h_speed]"); |
169 | 0 | goto end; |
170 | 0 | } |
171 | | |
172 | 0 | bearing = cJSON_GetObjectItemCaseSensitive(velocity_estimateJSON, "bearing"); |
173 | 0 | if (!bearing) { |
174 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [bearing]"); |
175 | 0 | goto end; |
176 | 0 | } |
177 | 0 | if (!cJSON_IsNumber(bearing)) { |
178 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [bearing]"); |
179 | 0 | goto end; |
180 | 0 | } |
181 | | |
182 | 0 | v_speed = cJSON_GetObjectItemCaseSensitive(velocity_estimateJSON, "vSpeed"); |
183 | 0 | if (!v_speed) { |
184 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [v_speed]"); |
185 | 0 | goto end; |
186 | 0 | } |
187 | 0 | if (!cJSON_IsNumber(v_speed)) { |
188 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [v_speed]"); |
189 | 0 | goto end; |
190 | 0 | } |
191 | | |
192 | 0 | v_direction = cJSON_GetObjectItemCaseSensitive(velocity_estimateJSON, "vDirection"); |
193 | 0 | if (!v_direction) { |
194 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [v_direction]"); |
195 | 0 | goto end; |
196 | 0 | } |
197 | 0 | if (!cJSON_IsString(v_direction)) { |
198 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [v_direction]"); |
199 | 0 | goto end; |
200 | 0 | } |
201 | 0 | v_directionVariable = OpenAPI_vertical_direction_FromString(v_direction->valuestring); |
202 | |
|
203 | 0 | h_uncertainty = cJSON_GetObjectItemCaseSensitive(velocity_estimateJSON, "hUncertainty"); |
204 | 0 | if (!h_uncertainty) { |
205 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [h_uncertainty]"); |
206 | 0 | goto end; |
207 | 0 | } |
208 | 0 | if (!cJSON_IsNumber(h_uncertainty)) { |
209 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [h_uncertainty]"); |
210 | 0 | goto end; |
211 | 0 | } |
212 | | |
213 | 0 | v_uncertainty = cJSON_GetObjectItemCaseSensitive(velocity_estimateJSON, "vUncertainty"); |
214 | 0 | if (!v_uncertainty) { |
215 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [v_uncertainty]"); |
216 | 0 | goto end; |
217 | 0 | } |
218 | 0 | if (!cJSON_IsNumber(v_uncertainty)) { |
219 | 0 | ogs_error("OpenAPI_velocity_estimate_parseFromJSON() failed [v_uncertainty]"); |
220 | 0 | goto end; |
221 | 0 | } |
222 | | |
223 | 0 | r_velocity = cJSON_GetObjectItemCaseSensitive(velocity_estimateJSON, "rVelocity"); |
224 | 0 | if (r_velocity) { |
225 | 0 | r_velocity_local_nonprim = OpenAPI_radial_velocity_parseFromJSON(r_velocity); |
226 | 0 | if (!r_velocity_local_nonprim) { |
227 | 0 | ogs_error("OpenAPI_radial_velocity_parseFromJSON failed [r_velocity]"); |
228 | 0 | goto end; |
229 | 0 | } |
230 | 0 | } |
231 | | |
232 | 0 | a_transverse_velocity = cJSON_GetObjectItemCaseSensitive(velocity_estimateJSON, "aTransverseVelocity"); |
233 | 0 | if (a_transverse_velocity) { |
234 | 0 | a_transverse_velocity_local_nonprim = OpenAPI_angular_velocity_parseFromJSON(a_transverse_velocity); |
235 | 0 | if (!a_transverse_velocity_local_nonprim) { |
236 | 0 | ogs_error("OpenAPI_angular_velocity_parseFromJSON failed [a_transverse_velocity]"); |
237 | 0 | goto end; |
238 | 0 | } |
239 | 0 | } |
240 | | |
241 | 0 | e_transverse_velocity = cJSON_GetObjectItemCaseSensitive(velocity_estimateJSON, "eTransverseVelocity"); |
242 | 0 | if (e_transverse_velocity) { |
243 | 0 | e_transverse_velocity_local_nonprim = OpenAPI_angular_velocity_parseFromJSON(e_transverse_velocity); |
244 | 0 | if (!e_transverse_velocity_local_nonprim) { |
245 | 0 | ogs_error("OpenAPI_angular_velocity_parseFromJSON failed [e_transverse_velocity]"); |
246 | 0 | goto end; |
247 | 0 | } |
248 | 0 | } |
249 | | |
250 | 0 | velocity_estimate_local_var = OpenAPI_velocity_estimate_create ( |
251 | | |
252 | 0 | h_speed->valuedouble, |
253 | | |
254 | 0 | bearing->valuedouble, |
255 | | |
256 | 0 | v_speed->valuedouble, |
257 | 0 | v_directionVariable, |
258 | | |
259 | 0 | h_uncertainty->valuedouble, |
260 | | |
261 | 0 | v_uncertainty->valuedouble, |
262 | 0 | r_velocity ? r_velocity_local_nonprim : NULL, |
263 | 0 | a_transverse_velocity ? a_transverse_velocity_local_nonprim : NULL, |
264 | 0 | e_transverse_velocity ? e_transverse_velocity_local_nonprim : NULL |
265 | 0 | ); |
266 | |
|
267 | 0 | return velocity_estimate_local_var; |
268 | 0 | end: |
269 | 0 | if (r_velocity_local_nonprim) { |
270 | 0 | OpenAPI_radial_velocity_free(r_velocity_local_nonprim); |
271 | 0 | r_velocity_local_nonprim = NULL; |
272 | 0 | } |
273 | 0 | if (a_transverse_velocity_local_nonprim) { |
274 | 0 | OpenAPI_angular_velocity_free(a_transverse_velocity_local_nonprim); |
275 | 0 | a_transverse_velocity_local_nonprim = NULL; |
276 | 0 | } |
277 | 0 | if (e_transverse_velocity_local_nonprim) { |
278 | 0 | OpenAPI_angular_velocity_free(e_transverse_velocity_local_nonprim); |
279 | 0 | e_transverse_velocity_local_nonprim = NULL; |
280 | 0 | } |
281 | 0 | return NULL; |
282 | 0 | } |
283 | | |
284 | | OpenAPI_velocity_estimate_t *OpenAPI_velocity_estimate_copy(OpenAPI_velocity_estimate_t *dst, OpenAPI_velocity_estimate_t *src) |
285 | 0 | { |
286 | 0 | cJSON *item = NULL; |
287 | 0 | char *content = NULL; |
288 | |
|
289 | 0 | ogs_assert(src); |
290 | 0 | item = OpenAPI_velocity_estimate_convertToJSON(src); |
291 | 0 | if (!item) { |
292 | 0 | ogs_error("OpenAPI_velocity_estimate_convertToJSON() failed"); |
293 | 0 | return NULL; |
294 | 0 | } |
295 | | |
296 | 0 | content = cJSON_Print(item); |
297 | 0 | cJSON_Delete(item); |
298 | |
|
299 | 0 | if (!content) { |
300 | 0 | ogs_error("cJSON_Print() failed"); |
301 | 0 | return NULL; |
302 | 0 | } |
303 | | |
304 | 0 | item = cJSON_Parse(content); |
305 | 0 | ogs_free(content); |
306 | 0 | if (!item) { |
307 | 0 | ogs_error("cJSON_Parse() failed"); |
308 | 0 | return NULL; |
309 | 0 | } |
310 | | |
311 | 0 | OpenAPI_velocity_estimate_free(dst); |
312 | 0 | dst = OpenAPI_velocity_estimate_parseFromJSON(item); |
313 | 0 | cJSON_Delete(item); |
314 | |
|
315 | 0 | return dst; |
316 | 0 | } |
317 | | |