4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: sharanayya mathapati <sharan.m@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
25 #include <sys/types.h>
32 #include <core_object.h>
36 #include <user_request.h>
40 #include <libxml/xmlreader.h>
41 #include <libxml/parser.h>
42 #include <libxml/tree.h>
44 #include "imc_common.h"
48 #define FILE_NAME "/opt/home/root/sample.xml"
49 #define POSITION_NODE "pos"
50 #define POSITION_NODE_ATTR_XSI "xsi:noNamespaceSchemaLocation"
51 #define POSITION_NODE_ATTR_VAL_XSI "pos.xsd"
52 #define POSITION_NODE_ATTR_XMLNS "xmlns:xsi"
53 #define POSITION_NODE_ATTR_VAL_XMLNS "http://www.w3.org/2001/XMLSchema-instance"
55 #define MAX_NUM_OF_GPS_REF_TIME_ELEMENT 12 /* max number of gps satalite */
56 #define MAX_NUM_OF_GPS_NAV_ELEMENT 16 /* max num of navigation gps element. */
57 #define MAX_NUM_OF_GPS_ALMANC_ELEMENTS 64 /* Max num of almanc elements. */
59 #define NUM_OF_ELEMENTS(array) (sizeof(array) / sizeof(*(array)))
63 static char node_name[128]; /* max len of xml node */
64 static char node_value[128]; /* max len of xml node value. */
66 /* node type of gps assist data */
67 enum gps_assist_element_type {
81 unsigned short bcchCarrier;
83 unsigned long int frameNumber;
84 unsigned short timeSlot;
85 unsigned short bitNumber;
86 } __attribute__((packed)) gps_gsm_time_t;
90 unsigned long int gpsTimeUncertainty;
91 } __attribute__((packed)) gps_utran_gps_unc_t;
95 signed long int driftRate;
96 } __attribute__((packed)) gps_drift_rate_t;
100 unsigned long int cellFrames;
101 unsigned char choice_mode;
102 unsigned long int UtranFdd; /* FDD Primary Scrambling Code */
103 unsigned long int UtranTdd; /* TDD Cell Parameter ID */
104 unsigned long int sfn; /* SFN */
105 } __attribute__((packed)) gps_utran_gps_ref_time_t;
108 gps_utran_gps_ref_time_t UtranGpsRefTime;
109 gps_utran_gps_unc_t UtranGpsUncertainty;
110 unsigned char UtranSfnUncertainty;
111 gps_drift_rate_t UtranDriftRate;
112 } __attribute__((packed)) gps_utran_time_t;
115 unsigned short satID;
116 unsigned short tlmWord;
117 unsigned char antiSpoofFlag;
118 unsigned char alertFlag;
119 unsigned char tmlReservedBits;
120 } __attribute__((packed)) gps_gps_tow_assist_t;
123 unsigned long int gpsTow;
124 unsigned long int gpsWeek;
125 unsigned char nrOfSats;
126 union { /* Not supported. */
127 gps_gsm_time_t gsm_time;
128 gps_utran_time_t UtranTime;
130 gps_gps_tow_assist_t GpsTowAssist[12];
131 } __attribute__((packed)) gps_ref_time_t;
134 /* Ref - Location. */
136 unsigned char shapeType;
137 unsigned char hemisphere;
138 unsigned short altitude;
139 unsigned long int latitude;
140 signed long int longitude;
141 unsigned char directionOfAlt;
142 unsigned char semiMajorUncert;
143 unsigned char semiMinorUncert;
144 unsigned char majorAxis;
145 unsigned char altUncert;
146 unsigned char confidence;
147 } __attribute__((packed)) gps_ref_loc_t;
149 /* DGPS corrections */
152 GPS_DGPS_UDRE_SCALE_1_0,
153 GPS_DGPS_UDRE_SCALE_0_75,
154 GPS_DGPS_UDRE_SCALE_0_5,
155 GPS_DGPS_UDRE_SCALE_0_3,
156 GPS_DGPS_UDRE_SCALE_0_2,
157 GPS_DGPS_UDRE_SCALE_0_1,
159 } __attribute__((packed)) gps_dgps_status_e_type;
162 unsigned char satId; /* Satellite ID */
165 signed short pseudoRangeCor;
166 signed short rangeRateCor;
167 } gps_dgps_sat_list_t;
170 unsigned long int gpsTow;
171 gps_dgps_status_e_type status;
172 unsigned long int numberOfSat;
173 gps_dgps_sat_list_t seqOfSatElement[16];
174 } __attribute__((packed)) gps_dgps_correction_t;
178 unsigned long int rsv1; /* 0~838860 */
179 unsigned long int rsv2; /* 0~16777215 */
180 unsigned long int rsv3; /* 0~16777215 */
181 unsigned long int rsv4; /* 0~65535 */
182 } __attribute__((packed)) gps_navi_subframe_rsv_t;
185 unsigned char ephemCodeOnL2; /* 0~3 */
186 unsigned char ephemUra; /* 0~15 */
187 unsigned char ephemSvHealth; /* 0~63 */
188 unsigned short ephemIodc; /* 0~1023 */
189 unsigned char ephemL2PFlag; /* 0~1 */
190 gps_navi_subframe_rsv_t NavigationSubFrameRsv;
191 signed char ephemTgd; /* -128~127 */
192 unsigned short ephemToc; /* 0~37799 */
193 signed char ephemAf2; /* -128~12 */
194 signed short ephemAf1; /* -32768~32767 */
195 signed long int ephemAf0; /* -2097152~2097151 */
196 signed short ephemCrs; /* -32768~32767 */
197 signed short ephemDeltaN; /* -32768~32767 */
198 signed long int ephemM0; /* -2147483648~2147483647 */
199 signed short ephemCuc; /* -32768~32767 */
200 unsigned long int ephemE; /* 0~4294967295 */
201 signed short ephemCus; /* -32768~32767 */
202 unsigned long int ephemAPowrHalf; /* 0~4294967295 */
203 unsigned short ephemToe; /* 0~37799 */
204 signed char ephemFitFlag; /* 0~1 */
205 unsigned char ephemAoda; /* 0~31 */
206 signed short ephemCic; /* -32768~32767 */
207 signed long int ephemOmegaA0; /* -2147483648~2147483647 */
208 signed short ephemCis; /* -32768~32767 */
209 signed long int ephemI0; /* -2147483648~2147483647 */
210 signed short ephemCrc; /* -32768~32767 */
211 signed long int ephemW; /* -2147483648~2147483647 */
212 signed long int ephemOmegaADot; /* -8388608~8388607 */
213 signed short ephemIDot; /* -8192~8191 */
214 } __attribute__((packed)) gps_navi_ephe_t;
217 GPS_NAVIGATION_MODEL_NEW_SATELLITE_NEW_NAVIGATION,
218 GPS_NAVIGATION_MODEL_EXIST_SATELLITE_EXIST_NAVIGATION,
219 GPS_NAVIGATION_MODEL_EXIST_SATELLITE_NEW_NAVIGATION,
220 GPS_NAVIGATION_MODEL_RESERVED
221 } gps_navigation_sat_status_e_type;
225 gps_navigation_sat_status_e_type NavigationSatStatus;
226 gps_navi_ephe_t NavigationEphemeris;
227 } __attribute__((packed)) gps_navi_sat_info_t;
230 unsigned long int numberOfSat;
231 gps_navi_sat_info_t NavigationSatInfo[16];
232 } __attribute__((packed)) gps_navi_model_t;
236 signed char alfa0; /* -128~127 */
237 signed char alfa1; /* -128~127 */
238 signed char alfa2; /* -128~127 */
239 signed char alfa3; /* -128~127 */
240 signed char beta0; /* -128~127 */
241 signed char beta1; /* -128~127 */
242 signed char beta2; /* -128~127 */
243 signed char beta3; /* -128~127 */
244 } __attribute__((packed)) gps_iono_model_t;
248 signed long int utcA1; /* -8388608~8388607 */
249 signed long int utcA0; /* -2147483648~2147483647 */
250 unsigned char utcTot; /* 0~255 */
251 unsigned char utcWNt; /* 0~255 */
252 signed char utcDeltaTls; /* -128~127 */
253 unsigned char utcWNlsf; /* 0~255 */
254 signed char utcDN; /* -128~127 */
255 signed char utcDeltaTlsf; /* -128~127 */
256 } __attribute__((packed)) gps_utc_model_t;
260 signed char dataId; /* only for 3G, 0~3, if this value is -1, it means this value is invalid */
262 unsigned short almanacE; /* 0~65536 */
263 unsigned char almanacToa; /* 0~255 */
264 signed short almanacKsii; /* -32768~3276 */
265 signed short almanacOmegaDot; /* -32768~3276 */
266 unsigned char almanacSvHealth; /* 0~255 */
267 unsigned long int almanacAPowerHalf; /* 0~16777215 */
268 signed long int almanacOmega0; /* -8388608~8388607 */
269 signed long int almanacW; /* -8388608~8388607 */
270 signed long int almanacM0; /* -8388608~8388607 */
271 signed short almanacAf0; /* -1024~1023 */
272 signed short almanacAf1; /* -1024~1023 */
273 } __attribute__((packed)) gps_almanac_sat_info_t;
276 unsigned char almanacWNa; /* 0~255 */
277 unsigned long int numberOfSat;
278 gps_almanac_sat_info_t AlmanacSatInfo[64];
279 } __attribute__((packed)) gps_almanac_model_t;
284 signed short doppler0; /* -2048~2047 (real value is from -5120 to 5117.5 by step of 2.5) */
285 unsigned char doppler1; /* 0~63 (real value is from -0.966 to 0.483 by step of 0.023) */
286 unsigned char dopplerUncertainty; /* 0~7 (12.5, 25, 50, 100, 200) */
287 unsigned short codePhase; /* 0~1022 */
288 unsigned char intCodePhase; /* 0~19 */
289 unsigned char gpsBitNumber; /* 0~3 */
290 unsigned char codePhaseSearchWindow; /* 0~15 (1023, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192) */
291 unsigned char azimuth; /* 0~31, 11.25 degree resolution */
292 unsigned char elevation; /* 0~7, 11.25 degree resolution */
293 } __attribute__((packed)) gps_acq_sat_info_t;
296 gps_utran_gps_ref_time_t AcqUtranGpsRefTime;
297 gps_utran_gps_unc_t AcqUtranGpsUncertainty;
298 } __attribute__((packed)) gps_acq_utran_time_t;
301 unsigned long int gpsTow;
303 gps_gsm_time_t gsm_time;
304 gps_acq_utran_time_t AcqUtranTime;
305 } acquisitionTimeInfo; /* --- not supported. */
306 unsigned long int numberOfSat;
307 gps_acq_sat_info_t lcsAcquisitionSatInfo[16];
308 } __attribute__((packed)) gps_acq_assist_t;
311 unsigned char satId[16];
312 unsigned char numOfSat;
313 } __attribute__((packed)) gps_r_time_int_t;
318 unsigned long int flag;
319 gps_ref_time_t ref_time;
320 gps_ref_loc_t ref_loc;
321 gps_dgps_correction_t dgps_corrections;
322 gps_navi_model_t navi_model;
323 gps_iono_model_t iono_model;
324 gps_utc_model_t utc_model;
325 gps_almanac_model_t almanac;
326 gps_acq_assist_t acq_assist;
327 gps_r_time_int_t r_time_int; /* not supported */
328 } __attribute__((packed)) gps_assist_data_noti_t; /* APGPS - GPS Assist Data Message - Notification */
333 } __attribute__((packed)) sat_status_info_t;
335 const sat_status_info_t sat_status_info_table[] = {
336 { "NS_NN-U", 0}, {"NS_NN", 0}, {"ES_NN-U", 1}, {"ES_SN", 2},
341 char *pdoppler_status;
343 } __attribute__((packed)) doppler_status_info_t;
345 const doppler_status_info_t doppler_status_info_table[] = {
346 { "hz12-5", 12.5}, {"hz25", 25}, {"hz50", 50}, {"hz100", 100},
350 /* postion measurement data structure. */
351 /* gps_method_e_type */
353 GPS_METHODTYPE_INVALID,
354 GPS_METHODTYPE_MS_ASSISTED,
355 GPS_METHODTYPE_MS_BASED,
356 GPS_METHODTYPE_MS_BASED_PREF,
357 GPS_METHODTYPE_MS_ASSISTED_PREF
363 unsigned char horizontalAccuracy;
364 unsigned char vertcalAccuracy;
365 } __attribute__((packed)) gps_accuracy_t;
367 /* gps_use_multi_sets_e_type */
369 GPS_MULTIPLESETS_INVALID,
370 GPS_MULTIPLESETS_MULTIPLESETS,
371 GPS_MULTIPLESETS_ONESET
372 } gps_use_multi_sets_e_type;
374 /* gps_env_char_e_type */
376 GPS_ENVIRONMENT_INVALID,
377 GPS_ENVIRONMENT_BAD_AREA,
378 GPS_ENVIRONMENT_NOT_BAD_AREA,
379 GPS_ENVIRONMENT_MIXED_AREA
380 } gps_env_char_e_type;
382 /* gps_cell_timing_wnt_e_type */
384 GPS_CELLTIMING_INVALID,
385 GPS_CELLTIMING_WANTED,
386 GPS_CELLTIMING_NOT_WANTED
387 } gps_cell_timing_wnt_e_type;
389 /* gps_add_assit_req_e_type */
391 GPS_ADDITIONAL_ASSISREQ_INVALID,
392 GPS_ADDITIONAL_ASSISREQ_REQ,
393 GPS_ADDITIONAL_ASSISREQ_NOT_REQ
394 } gps_add_assit_req_e_type;
396 /* gps measure position. */
398 gps_method_e_type method_type;
399 gps_accuracy_t accuracy;
400 unsigned char rsp_time;
401 gps_use_multi_sets_e_type use_multi_sets;
402 gps_env_char_e_type environment_char;
403 gps_cell_timing_wnt_e_type cell_timing_wnt;
404 gps_add_assit_req_e_type add_assist_req;
405 } __attribute__((packed)) gps_measure_position_indi_t;
408 /* APGPS - Measure Position message - confirm */
410 GPS_MSR_POS_RES_LOCATION,
411 GPS_MSR_POS_RES_GPS_MEASUREMENTS,
412 GPS_MSR_POS_RES_AID_REQ,
413 GPS_MSR_POS_RES_ERROR
414 } gps_msr_pos_res_e_type;
417 unsigned char sat_id;
419 } __attribute__((packed)) gps_sat_info_t;
422 unsigned char beginWeek;
423 unsigned char endWeek;
424 unsigned char beginTow;
425 unsigned char endTow;
426 } __attribute__((packed)) gps_ext_ephe_chk_t;
429 unsigned long int assistanceFlag;
430 unsigned short gpsWeek;
431 unsigned char gpsToe;
433 unsigned char toeLimit;
434 gps_sat_info_t satInfo[15];
435 unsigned char gpsExtendedEphemeris;
436 gps_ext_ephe_chk_t extEphemerisChk;
437 } __attribute__((packed)) gps_assistance_data_t;
439 /* Measure Position message */
441 unsigned char satId; /* Satellite ID */
442 unsigned char cno; /* 0~63, unit of dB-Hz */
443 signed short doppler; /* -32768~32767, Hz and scale factor 0.2 */
444 unsigned short wholeChips; /* 0~1022 */
445 unsigned short fracChips; /* 0~1024 */
446 unsigned char lcsMultiPath;
447 unsigned char pseuRangeRmsErr; /* 0~63 */
448 } __attribute__((packed)) gps_measuremet_element_t;
451 unsigned long int gpsTow; /* /< GPS time of week [msec] */
452 unsigned short gpsWeek; /* /< GPS week [0 .. 1023] */
453 unsigned char nrOfSats; /* /< number of satellites [1 .. 16] */
454 gps_measuremet_element_t GpsMeasure[16];
455 } __attribute__((packed)) gps_measure_t;
458 signed long int latitude;
459 signed long int longitude;
460 } __attribute__((packed)) gps_ellipsoid_po_t;
463 gps_ellipsoid_po_t point;
464 unsigned char uncertainRadius;
465 } __attribute__((packed)) gps_po_unc_circle_t;
468 gps_ellipsoid_po_t point;
469 unsigned char semiMajorAxis;
470 unsigned char semiMinorAxis;
471 unsigned char orientationAngle;
472 unsigned char confidence;
473 } __attribute__((packed)) gps_po_unc_ellipse_t;
476 gps_ellipsoid_po_t point;
477 signed short altitude;
478 unsigned char semiMajorAxis;
479 unsigned char semiMinorAxis;
480 unsigned char orientationAngle;
481 unsigned char uncertainAltitude;
482 unsigned char confidence;
483 } __attribute__((packed)) gps_po_alt_unc_ellipse_t;
486 gps_ellipsoid_po_t point;
487 unsigned short innerRadius;
488 unsigned char uncertainRadius;
489 unsigned char offsetAngle;
490 unsigned char includedAngle;
491 unsigned char confidence;
492 } __attribute__((packed)) gps_ellipsoid_arc_t;
495 gps_ellipsoid_po_t point;
496 signed short altitude;
497 } __attribute__((packed)) gps_ellipsoid_alt_t;
500 unsigned char noOfPoints;
501 gps_ellipsoid_po_t points[15];
502 } __attribute__((packed)) gps_polygon_t;
506 unsigned char shape_type;
507 gps_po_unc_circle_t p_unc_clrcle;
508 gps_po_unc_ellipse_t p_unc_ellipse;
509 gps_po_alt_unc_ellipse_t p_alt_unc_ellipse;
510 gps_ellipsoid_arc_t ellipsoid_arc;
511 gps_ellipsoid_po_t ellipsoid_po;
512 gps_ellipsoid_alt_t ellipsoid_alt;
513 gps_polygon_t polygon;
514 } __attribute__((packed)) gps_loc_info_t;
518 unsigned long int gpsTow; /* /< GPS time of week [msec] */
519 unsigned short gpsWeek; /* /< GPS week [0 .. 1023] */
520 unsigned char fixType; /* /< Fix type. 2D(0x01) or 3D(0x02) */
521 gps_loc_info_t measured_loc_info;
522 } __attribute__((packed)) gps_measure_loc_info_t;
526 unsigned long int cellFrames;
527 unsigned char choice_mode;
528 unsigned long int UtranFdd; /* FDD Primary Scrambling Code */
529 unsigned long int UtranTdd; /* TDD Cell Parameter ID */
530 unsigned long int sfn; /* SFN */
531 } __attribute__((packed)) gps_utrangps_ref_time_t;
534 unsigned char result; /* 0x00 : SUCCESS, 0x01 : Fail */
535 gps_msr_pos_res_e_type response_type; /* should be 4 byte */
536 gps_measure_t gps_measure;
537 gps_measure_loc_info_t loc_info;
538 gps_assistance_data_t measured_assit_data;
539 gps_utrangps_ref_time_t UtranGpsRefTime; /* only for 3G */
540 } __attribute__((packed)) gps_measure_position_confirm_t; /* APGPS - Measure Position message - confirm */
547 static t_element elements[] = {
548 {"ref_time", REF_TIME},
549 {"location_parameters", LOCATION_PARM},
550 {"DGPS_corrections", DGPS_CORRECTION},
551 {"nav_model_elem", NAV_MODEL_ELEM},
552 {"ionospheric_model", IONOSPHERIC_MODEL},
553 {"UTC_model", UTC_MODEL},
554 {"almanac", ALMANAC},
555 {"acqu_assist", ACQU_ASSIST},
559 /**************************************************************************
560 * Local Function Prototypes
561 **************************************************************************/
563 static inline int _modem_sat_status_info_2_tel_sat_info(char *sat_info);
565 static inline int _modem_acqa_assit_doppler_2_tel_doppler(char *doppler_info);
567 static int _gps_element_compare(char *element[], char *element_str, int nelem);
569 static enum gps_assist_element_type _get_element_type(char *element_str);
571 static void _parse_ref_time_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist, gboolean GPS_TOW_assist, int count);
573 static void _parse_location_parameters(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist);
575 static void _parse_dgps_correction_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist);
577 static void _parse_ionospheric_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist);
579 static void _parse_utc_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist);
581 static void _parse_almanc_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist, gboolean alm_elem, int count);
583 static void _parse_acqu_assist_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist);
585 static void _parse_nav_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist, gboolean ephem_and_clock, int element_count);
587 static void _set_coordinate(xmlNodePtr node, gps_ellipsoid_po_t *point, int isalt, int altitude);
589 static void _set_loc_info_ellipse_elements(xmlNodePtr node, void *elliplse, int is_unc_ellipse);
591 static xmlChar *_generate_confirm_measure_pos_xml_text(gps_measure_position_confirm_t *gps_measure_position_confirm);
593 static gboolean on_notification_gps_measure_position_from_modem(CoreObject *o, char *file_name, void *user_data);
595 /**************************************************************************
596 * Local Function Definitions
597 **************************************************************************/
599 static inline int _modem_sat_status_info_2_tel_sat_info(char *sat_info)
603 for (count = 0; count < (int) (sizeof(sat_status_info_table) / sizeof(sat_status_info_t)); count++)
604 if (strcmp(sat_status_info_table[count].psat_status, sat_info) == 0)
605 return (sat_status_info_table[count].stat_status);
610 static inline int _modem_acqa_assit_doppler_2_tel_doppler(char *doppler_info)
614 for (count = 0; count < (int) (sizeof(doppler_status_info_table) / sizeof(doppler_status_info_t)); count++)
615 if (strcmp(doppler_status_info_table[count].pdoppler_status, doppler_info) == 0)
616 return (doppler_status_info_table[count].doppler_status);
621 static int _gps_element_compare(char *element[], char *element_str, int nelem)
625 for (count = 0; count < nelem; count++)
626 if (strcmp(element[count], element_str) == 0)
633 static enum gps_assist_element_type _get_element_type(char *element_str)
637 for (index = 0; index < sizeof(elements) / sizeof(t_element); index++)
638 if (strcmp(elements[index].name, element_str) == 0)
639 return elements[index].type;
644 static void _parse_ref_time_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist, gboolean GPS_TOW_assist, int count)
648 static char *element[] = {"GPS_TOW_msec", "GPS_week", "sat_id", "tlm_word", "anti_sp", "alert", "tlm_res"};
651 if (count < 0 || count >= MAX_NUM_OF_GPS_REF_TIME_ELEMENT) {
652 dbg("invalid count");
655 nelem = (int) NUM_OF_ELEMENTS(element);
656 node_count = _gps_element_compare(element, element_str, nelem);
658 if (node_count == 0) {
659 gpsdata_assist->ref_time.gpsTow = atoi(element_value);
660 dbg("gpsTow - %d\n", gpsdata_assist->ref_time.gpsTow);
661 gpsdata_assist->dgps_corrections.gpsTow = gpsdata_assist->ref_time.gpsTow;
663 } else if (node_count == 1) {
664 gpsdata_assist->ref_time.gpsWeek = atoi(element_value);
665 dbg("gpsWeek - %d\n", gpsdata_assist->ref_time.gpsWeek);
669 if (GPS_TOW_assist) {
670 switch (node_count) {
672 gpsdata_assist->ref_time.GpsTowAssist[count].satID = atoi(element_value);
673 dbg("GpsTowAssist[%d].satID = %d\n", count, gpsdata_assist->ref_time.GpsTowAssist[count].satID);
674 gpsdata_assist->ref_time.nrOfSats = count + 1;
678 gpsdata_assist->ref_time.GpsTowAssist[count].tlmWord = atoi(element_value);
679 dbg("GpsTowAssist[%d]-tlmWord = %d\n", count, gpsdata_assist->ref_time.GpsTowAssist[count].tlmWord);
680 gpsdata_assist->ref_time.nrOfSats = count + 1;
684 gpsdata_assist->ref_time.GpsTowAssist[count].antiSpoofFlag = *element_value;
685 dbg("GpsTowAssist[%d]-antiSpoofFlag = 0x%X\n", count, gpsdata_assist->ref_time.GpsTowAssist[count].antiSpoofFlag);
686 gpsdata_assist->ref_time.nrOfSats = count + 1;
690 gpsdata_assist->ref_time.GpsTowAssist[count].alertFlag = *element_value;
691 dbg("GpsTowAssist[%d]-alertFlag = 0x%X\n", count, gpsdata_assist->ref_time.GpsTowAssist[count].alertFlag);
692 gpsdata_assist->ref_time.nrOfSats = count + 1;
696 gpsdata_assist->ref_time.GpsTowAssist[count].tmlReservedBits = *element_value;
697 dbg("GpsTowAssist[%d]-tmlReservedBits = 0x%X\n", count, gpsdata_assist->ref_time.GpsTowAssist[count].tmlReservedBits);
698 gpsdata_assist->ref_time.nrOfSats = count + 1;
702 dbg("Invalid gps element");
708 static void _parse_location_parameters(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist)
710 /* unsigned char shapeType; and unsigned char hemisphere not supported. */
712 static char *element[] = {
713 "north", "degrees", "height_above_surface", "height", "longitude", "uncert_semi_major", "uncert_semi_minor",
714 "orient_major", "confidence", "uncert_alt"
717 int nelem = (int) NUM_OF_ELEMENTS(element);
720 count = _gps_element_compare(element, element_str, nelem);
726 /* gpsdata_assist.ref_loc.latitude_data.north = atoi(element_str_text); */
727 /* dbg("gpsdata_assist.ref_loc.latitude_data.north - %d\n",gpsdata_assist.ref_loc.latitude_data.north); */
731 gpsdata_assist->ref_loc.latitude = atoi(element_value);
732 dbg("latitude_data.degrees - %d\n", gpsdata_assist->ref_loc.latitude);
736 /* gpsdata_assist.ref_loc.altitude_data.height_above_surface = atoi(element_str_text); */
737 /* dbg("altitude_data.height_above_surface - %d\n",gpsdata_assist.ref_loc.altitude_data.height_above_surface); */
741 gpsdata_assist->ref_loc.altitude = atoi(element_value); /* todo- need to confirm */
742 dbg("altitude_data.height - %d\n", gpsdata_assist->ref_loc.altitude);
746 gpsdata_assist->ref_loc.longitude = atoi(element_value);
747 dbg("longitude - %d\n", gpsdata_assist->ref_loc.longitude);
751 gpsdata_assist->ref_loc.semiMajorUncert = *element_value;
752 dbg("semiMajorUncert - 0x%X\n", gpsdata_assist->ref_loc.semiMajorUncert);
756 gpsdata_assist->ref_loc.semiMinorUncert = *element_value;
757 dbg("uncert_semi_minor - 0x%X\n", gpsdata_assist->ref_loc.semiMinorUncert);
761 gpsdata_assist->ref_loc.majorAxis = *element_value;
762 dbg("orient_major - 0x%X\n", gpsdata_assist->ref_loc.majorAxis);
766 gpsdata_assist->ref_loc.confidence = *element_value;
767 dbg("confidence - 0x%X\n", gpsdata_assist->ref_loc.confidence);
771 gpsdata_assist->ref_loc.altUncert = *element_value;
772 dbg("altUncert - 0x%X\n", gpsdata_assist->ref_loc.altUncert);
776 dbg("invalid element");
781 static void _parse_dgps_correction_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist)
785 if (strcmp(element_str, "sat_id") == 0) {
786 gpsdata_assist->dgps_corrections.seqOfSatElement[0].satId = *element_value;
787 dbg("seqOfSatElement[0].satId - %d\n",
788 gpsdata_assist->dgps_corrections.seqOfSatElement[0].satId);
789 } else if (strcmp(element_str, "IODE") == 0) {
790 gpsdata_assist->dgps_corrections.seqOfSatElement[0].iode = atoi(element_value);
791 dbg("seqOfSatElement[0].iode - %d\n",
792 gpsdata_assist->dgps_corrections.seqOfSatElement[0].iode);
793 } else if (strcmp(element_str, "UDRE") == 0) {
794 gpsdata_assist->dgps_corrections.seqOfSatElement[0].udre = *element_value;
795 dbg("seqOfSatElement[0].udre- %d\n",
796 gpsdata_assist->dgps_corrections.seqOfSatElement[0].udre);
797 } else if (strcmp(element_str, "PRC") == 0) {
798 gpsdata_assist->dgps_corrections.seqOfSatElement[0].pseudoRangeCor = atoi(element_value);
799 dbg("seqOfSatElement[0].pseudoRangeCor - %d\n",
800 gpsdata_assist->dgps_corrections.seqOfSatElement[0].pseudoRangeCor);
801 } else if (strcmp(element_str, "RRC") == 0) {
802 gpsdata_assist->dgps_corrections.seqOfSatElement[0].rangeRateCor = atoi(element_value);
803 dbg("seqOfSatElement[0].rangeRateCor - %d\n",
804 gpsdata_assist->dgps_corrections.seqOfSatElement[0].rangeRateCor);
808 static void _parse_ionospheric_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist)
810 static char *element[] = {"alfa0", "alfa1", "alfa2", "alfa3", "beta0", "beta1", "beta2", "beta3" };
811 int nelem = (int) NUM_OF_ELEMENTS(element);
814 count = _gps_element_compare(element, element_str, nelem);
818 gpsdata_assist->iono_model.alfa0 = *element_value;
819 dbg("alfa0 - 0x%X\n", gpsdata_assist->iono_model.alfa0);
823 gpsdata_assist->iono_model.alfa1 = *element_value;
824 dbg("alfa1 - 0x%X\n", gpsdata_assist->iono_model.alfa1);
828 gpsdata_assist->iono_model.alfa2 = *element_value;
829 dbg("alfa2 - 0x%X\n", gpsdata_assist->iono_model.alfa2);
833 gpsdata_assist->iono_model.alfa3 = *element_value;
834 dbg("alfa3 - 0x%X\n", gpsdata_assist->iono_model.alfa3);
838 gpsdata_assist->iono_model.beta0 = *element_value;
839 dbg("beta0 - 0x%X\n", gpsdata_assist->iono_model.beta0);
843 gpsdata_assist->iono_model.beta1 = *element_value;
844 dbg("beta1 -0x%X\n", gpsdata_assist->iono_model.beta1);
848 gpsdata_assist->iono_model.beta2 = *element_value;
849 dbg("beta2 - 0x%X\n", gpsdata_assist->iono_model.beta2);
853 gpsdata_assist->iono_model.beta3 = *element_value;
854 dbg("beta3 - 0x%X\n", gpsdata_assist->iono_model.beta3);
858 dbg("invalid gps element");
863 void _parse_utc_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist)
865 static char *element[] = {"a1", "a0", "tot", "wnt", "dtls", "wnlsf", "dn", "dtlsf"};
866 int nelem = (int) NUM_OF_ELEMENTS(element);
869 count = _gps_element_compare(element, element_str, nelem);
874 gpsdata_assist->utc_model.utcA1 = atoi(element_value);
875 dbg("utcA1 - %d\n", gpsdata_assist->utc_model.utcA1);
879 gpsdata_assist->utc_model.utcA0 = atoi(element_value);
880 dbg("utcA0 - %d\n", gpsdata_assist->utc_model.utcA0);
884 gpsdata_assist->utc_model.utcTot = *element_value;
885 dbg("utcTot - 0x%X\n", gpsdata_assist->utc_model.utcTot);
889 gpsdata_assist->utc_model.utcWNt = *element_value;
890 dbg("utcWNt - 0x%X\n", gpsdata_assist->utc_model.utcWNt);
894 gpsdata_assist->utc_model.utcDeltaTls = *element_value;
895 dbg("utcDeltaTls -0x%X\n", gpsdata_assist->utc_model.utcDeltaTls);
899 gpsdata_assist->utc_model.utcWNlsf = *element_value;
900 dbg("utcWNlsf - 0x%X\n", gpsdata_assist->utc_model.utcWNlsf);
904 gpsdata_assist->utc_model.utcDN = *element_value;
905 dbg("utcDN - 0x%X\n", gpsdata_assist->utc_model.utcDN);
909 gpsdata_assist->utc_model.utcDeltaTlsf = *element_value;
910 dbg("utcDeltaTlsf - 0x%X\n", gpsdata_assist->utc_model.utcDeltaTlsf);
914 dbg("invalid gps element");
919 static void _parse_almanc_model_gps_elements(char *element_str,
920 char *element_value, gps_assist_data_noti_t *gpsdata_assist,
921 gboolean alm_elem, int count)
925 static char *element[] = {
926 "wna", "data_id", "sat_id", "alm_ecc", "alm_toa", "alm_ksii", "alm_omega_dot", "alm_sv_health", "alm_power_half",
927 "alm_omega0", "alm_omega", "alm_m0", "alm_af0", "alm_af1"
931 if (count < 0 || count >= MAX_NUM_OF_GPS_ALMANC_ELEMENTS) {
932 dbg("invalid count");
935 nelem = (int) NUM_OF_ELEMENTS(element);
937 node_count = _gps_element_compare(element, element_str, nelem);
938 if (node_count == 0) {
939 gpsdata_assist->almanac.almanacWNa = *element_value;
940 dbg("almanacWNa - %d\n", gpsdata_assist->almanac.almanacWNa);
945 switch (node_count) {
947 gpsdata_assist->almanac.AlmanacSatInfo[count].dataId = *element_value;
948 dbg("AlmanacSatInfo[%d].data_id - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].dataId);
952 gpsdata_assist->almanac.AlmanacSatInfo[count].satId = *element_value;
953 dbg("AlmanacSatInfo[%d].sat_id - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].satId);
957 gpsdata_assist->almanac.AlmanacSatInfo[count].almanacE = atoi(element_value);
958 dbg("AlmanacSatInfo[%d].almanacE - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacE);
962 gpsdata_assist->almanac.AlmanacSatInfo[count].almanacToa = *element_value;
963 dbg("AlmanacSatInfo[%d].almanacToa - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacToa);
967 gpsdata_assist->almanac.AlmanacSatInfo[count].almanacKsii = *element_value;
968 dbg("AlmanacSatInfo[%d].almanacKsii - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacKsii);
972 gpsdata_assist->almanac.AlmanacSatInfo[count].almanacOmegaDot = *element_value;
973 dbg("AlmanacSatInfo[%d].almanacOmegaDot - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacOmegaDot);
977 gpsdata_assist->almanac.AlmanacSatInfo[count].almanacSvHealth = *element_value;
978 dbg("AlmanacSatInfo[%d].almanacSvHealth - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacSvHealth);
982 gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAPowerHalf = atoi(element_value);
983 dbg("AlmanacSatInfo[%d].almanacAPowerHalf - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAPowerHalf);
987 gpsdata_assist->almanac.AlmanacSatInfo[count].almanacOmega0 = atoi(element_value);
988 dbg("AlmanacSatInfo[%d].almanacOmega0 - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacOmega0);
992 gpsdata_assist->almanac.AlmanacSatInfo[count].almanacW = atoi(element_value);
993 dbg("AlmanacSatInfo[%d].almanacW - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacW);
997 gpsdata_assist->almanac.AlmanacSatInfo[count].almanacM0 = atoi(element_value);
998 dbg("AlmanacSatInfo[%d].almanacM0 - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacM0);
1002 gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAf0 = atoi(element_value);
1003 dbg("AlmanacSatInfo[%d].almanacAf0 - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAf0);
1007 gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAf1 = atoi(element_value);
1008 dbg("AlmanacSatInfo[%d].almanacAf1 - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAf1);
1012 dbg("invalid gps element");
1018 static void _parse_acqu_assist_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist)
1020 static char *element[] = {"tow_msec", "sat_id", "dopl0", "dopl1", "code_ph", "code_ph_int", "GPS_bitno", "srch_w", "az", "elev"};
1021 int nelem = (int) NUM_OF_ELEMENTS(element);
1024 count = _gps_element_compare(element, element_str, nelem);
1029 gpsdata_assist->acq_assist.gpsTow = atoi(element_value);
1030 dbg("acq_assist.gpsTow - %d\n", gpsdata_assist->acq_assist.gpsTow);
1034 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].satId = *element_value;
1035 dbg("lcsAcquisitionSatInfo[0].satId - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].satId);
1039 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].doppler0 = atoi(element_value);
1040 dbg("lcsAcquisitionSatInfo[0].dopl0 - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].doppler0);
1044 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].doppler1 = *element_value;
1045 dbg("lcsAcquisitionSatInfo[0].doppler1 - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].doppler1);
1049 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].codePhase = atoi(element_value);
1050 dbg("lcsAcquisitionSatInfo[0].codePhase - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].codePhase);
1054 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].intCodePhase = *element_value;
1055 dbg("lcsAcquisitionSatInfo[0].intCodePhase - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].intCodePhase);
1059 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].gpsBitNumber = *element_value;
1060 dbg("lcsAcquisitionSatInfo[0].GPS_bitno - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].gpsBitNumber);
1064 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].codePhaseSearchWindow = *element_value;
1065 dbg("lcsAcquisitionSatInfo[0].codePhaseSearchWindow - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].codePhaseSearchWindow);
1069 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].azimuth = *element_value;
1070 dbg("lcsAcquisitionSatInfo[0].azimuth - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].azimuth);
1074 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].elevation = *element_value;
1075 dbg("lcsAcquisitionSatInfo[0].elevation - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].elevation);
1079 dbg("invalid gps element");
1084 static void _parse_nav_model_gps_elements(char *element_str, char *element_value,
1085 gps_assist_data_noti_t *gpsdata_assist, gboolean ephem_and_clock, int element_count)
1087 static char *element[] = {
1088 "sat_id", "l2_code", "ura", "sv_health", "iodc", "l2p_flag", "esr1", "esr2", "esr3", "esr4", "tgd", "toc", "af2", "af0",
1089 "crs", "delta_n", "m0", "cuc", "ecc", "cus", "power_half", "toe", "fit_flag", "aoda", "cic", "omega0", "cis", "i0", "crc", "omega", "idot", "omega_dot"
1092 int nelem = (int) NUM_OF_ELEMENTS(element);
1095 if (element_count < 0 || element_count >= MAX_NUM_OF_GPS_NAV_ELEMENT) {
1096 dbg("invalid count");
1099 count = _gps_element_compare(element, element_str, nelem);
1103 gpsdata_assist->navi_model.NavigationSatInfo[element_count].satId = *element_value;
1104 dbg("NavigationSatInfo[%d].satId - 0x%X\n", element_count, gpsdata_assist->navi_model.NavigationSatInfo[element_count].satId);
1108 if (ephem_and_clock) {
1111 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCodeOnL2 = *element_value;
1115 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemUra = *element_value;
1119 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemSvHealth = *element_value;
1123 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemIodc = atoi(element_value);
1127 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemL2PFlag = *element_value;
1131 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.NavigationSubFrameRsv.rsv1 = atoi(element_value);
1135 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.NavigationSubFrameRsv.rsv2 = atoi(element_value);
1139 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.NavigationSubFrameRsv.rsv3 = atoi(element_value);
1143 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.NavigationSubFrameRsv.rsv4 = atoi(element_value);
1147 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemTgd = *element_value;
1151 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemToc = atoi(element_value);
1155 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemAf2 = *element_value;
1159 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemAf1 = atoi(element_value);
1163 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemAf0 = atoi(element_value);
1167 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCrs = atoi(element_value);
1171 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemDeltaN = atoi(element_value);
1175 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemM0 = atoi(element_value);
1179 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCuc = atoi(element_value);
1183 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemE = atoi(element_value);
1187 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCus = atoi(element_value);
1191 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemAPowrHalf = atoi(element_value);
1195 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemToe = atoi(element_value);
1199 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemFitFlag = *element_value;
1203 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemAoda = *element_value;
1207 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCic = atoi(element_value);
1211 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemI0 = atoi(element_value);
1215 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCrc = atoi(element_value);
1219 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemW = atoi(element_value);
1223 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemIDot = atoi(element_value);
1227 gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemOmegaADot = atoi(element_value);
1228 dbg("NavigationSatInfo[%d].NavigationEphemeris.ephemOmegaADot - 0x%X\n",
1229 element_count, gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemOmegaADot);
1233 dbg("invalid gps element");
1240 /* Set coordinate elements : <latitude> <longitude> <altitude> */
1241 static void _set_coordinate(xmlNodePtr node, gps_ellipsoid_po_t *point, int isalt, int altitude)
1243 /* <parent_node> .. .. (xmlNodePtr node) */
1244 /* <coordinate> <latitude> <north>0</north> <degrees>0</degrees> </latitude> <longitude>0</longitude> </coordinate> */
1245 /* <altitude> <height_above_surface>0</height_above_surface> <height>0</height> </altitude> */
1246 /* .. .. <\parent_node> */
1248 xmlNodePtr coordinate_node = NULL, temp_node = NULL;
1250 memset(node_name, 0x00, sizeof(node_name));
1251 memset(node_value, 0x00, sizeof(node_value));
1253 snprintf(node_name, NODE_SIZE, "%s", "coordinate");
1254 coordinate_node = xmlNewChild(node, NULL, BAD_CAST node_name, NULL);
1256 snprintf(node_name, NODE_SIZE, "%s", "latitude");
1257 temp_node = xmlNewChild(coordinate_node, NULL, BAD_CAST node_name, NULL);
1259 snprintf(node_name, NODE_SIZE, "%s", "north");
1260 snprintf(node_value, NODE_SIZE, "%d", 0);
1261 xmlNewChild(temp_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1263 snprintf(node_name, NODE_SIZE, "%s", "degrees");
1264 snprintf(node_value, NODE_SIZE, "%d", (int) point->latitude);
1265 xmlNewChild(temp_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1267 snprintf(node_name, NODE_SIZE, "%s", "longitude");
1268 snprintf(node_value, NODE_SIZE, "%d", (int) point->longitude);
1269 xmlNewChild(coordinate_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1272 snprintf(node_name, NODE_SIZE, "%s", "altitude");
1273 temp_node = xmlNewChild(node, NULL, BAD_CAST node_name, NULL);
1274 snprintf(node_name, NODE_SIZE, "%s", "height_above_surface");
1275 snprintf(node_value, NODE_SIZE, "%d", 0);
1276 xmlNewChild(temp_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1277 snprintf(node_name, NODE_SIZE, "%s", "height");
1278 snprintf(node_value, NODE_SIZE, "%d", altitude);
1279 xmlNewChild(temp_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1284 static void _set_loc_info_ellipse_elements(xmlNodePtr node, void *elliplse, int is_unc_ellipse)
1286 gps_po_unc_ellipse_t *p_unc_ellipse;
1287 gps_po_alt_unc_ellipse_t *p_alt_unc_ellipse;
1288 unsigned char semiMajorAxis, semiMinorAxis, orientationAngle, confidence;
1290 memset(node_name, 0x00, sizeof(node_name));
1291 memset(node_value, 0x00, sizeof(node_value));
1293 if (is_unc_ellipse) {
1294 p_unc_ellipse = (gps_po_unc_ellipse_t *) elliplse;
1295 semiMajorAxis = p_unc_ellipse->semiMajorAxis;
1296 semiMinorAxis = p_unc_ellipse->semiMinorAxis;
1297 orientationAngle = p_unc_ellipse->orientationAngle;
1298 confidence = p_unc_ellipse->confidence;
1300 p_alt_unc_ellipse = (gps_po_alt_unc_ellipse_t *) elliplse;
1301 semiMajorAxis = p_alt_unc_ellipse->semiMajorAxis;
1302 semiMinorAxis = p_alt_unc_ellipse->semiMinorAxis;
1303 orientationAngle = p_alt_unc_ellipse->orientationAngle;
1304 confidence = p_alt_unc_ellipse->confidence;
1307 snprintf(node_name, NODE_SIZE, "%s", "uncert_semi_major");
1308 snprintf(node_value, NODE_SIZE, "%d", semiMajorAxis);
1309 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1311 snprintf(node_name, NODE_SIZE, "%s", "uncert_semi_minor");
1312 snprintf(node_value, NODE_SIZE, "%d", semiMinorAxis);
1313 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1315 snprintf(node_name, NODE_SIZE, "%s", "orient_major");
1316 snprintf(node_value, NODE_SIZE, "%d", orientationAngle);
1317 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1319 snprintf(node_name, NODE_SIZE, "%s", "confidence");
1320 snprintf(node_value, NODE_SIZE, "%d", confidence);
1321 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1324 static xmlChar *_generate_confirm_measure_pos_xml_text(gps_measure_position_confirm_t *gps_measure_position_confirm)
1326 xmlDocPtr doc = NULL;
1327 xmlNodePtr root_node = NULL, node = NULL;
1328 xmlNodePtr gps_msr_node = NULL, shape_data_node = NULL, loc_child_node = NULL;
1329 xmlChar *xml = NULL;
1330 int count = 0, altitude, size;
1333 Creates a new XML document
1334 ================================================================================================================================
1335 <?xml version="1.0"?>
1336 <pos xsi:noNamespaceSchemaLocation="pos.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1339 <tow_msec></tow_msec>
1342 <sat_id></sat_id><carr2_noise></carr2_noise><dopl></dopl><whole_chips></whole_chips><fract_chips></fract_chips>
1343 <multi_path literal="xx"></multi_path> <psr_rms_err></psr_rms_err>
1348 <time_of_fix></time_of_fix><
1349 <location_parameters>
1354 <latitude><north></north><degrees></degrees></latitude><longitude></longitude>
1358 <ellipsoid_point_uncert_circle>
1359 <uncert_circle></uncert_circle>
1361 <latitude> <> <\> ...</latitude> <longitude></longitude>
1363 </ellipsoid_point_uncert_circle>
1365 <ellipsoid_point_uncert_ellipse>
1367 <latitude><> <\>..<longitude></longitude>
1369 <uncert_ellipse><uncert_semi_major></uncert_semi_major><uncert_semi_minor></uncert_semi_minor>
1370 <orient_major></orient_major><confidence></confidence></uncert_ellipse>
1371 </ellipsoid_point_uncert_ellipse>
1375 <latitude><> <\>...</latitude><longitude></longitude>
1379 <ellipsoid_point_alt>
1381 <latitude><> <\>..</latitude><longitude></longitude>
1384 <height_above_surface></height_above_surface><height></height>
1386 </ellipsoid_point_alt>
1388 <ellipsoid_point_alt_uncertellipse>
1390 <latitude> <> <\>.. ..</latitude><longitude></longitude>
1393 <height_above_surface></height_above_surface><height></height>
1395 <uncert_semi_major></uncert_semi_major><uncert_semi_minor></uncert_semi_minor><orient_major></orient_major>
1396 <confidence></confidence><uncert_alt></uncert_alt>
1397 </ellipsoid_point_alt_uncertellipse>
1401 <latitude><> <\> .. </latitude><longitude></longitude>
1403 <inner_rad></inner_rad>
1404 <uncert_rad></uncert_rad><offset_angle></offset_angle><included_angle></included_angle>
1405 <confidence></confidence>
1408 </location_parameters>
1414 ================================================================================================================================
1417 doc = xmlNewDoc(BAD_CAST "1.0");
1420 memset(node_name, 0x00, sizeof(node_name));
1421 memset(node_value, 0x00, sizeof(node_value));
1423 snprintf(node_name, NODE_SIZE, "%s", POSITION_NODE);
1424 /* Creation of a new node element */
1425 root_node = xmlNewNode(NULL, BAD_CAST node_name);
1426 /* Set the root element of the document */
1427 xmlDocSetRootElement(doc, root_node);
1428 snprintf(node_name, NODE_SIZE, "%s", POSITION_NODE_ATTR_XSI);
1429 snprintf(node_value, NODE_SIZE, "%s", POSITION_NODE_ATTR_VAL_XSI);
1430 /* Create a new property carried by a node */
1431 xmlNewProp(root_node, BAD_CAST node_name, BAD_CAST node_value);
1433 snprintf(node_name, NODE_SIZE, "%s", POSITION_NODE_ATTR_XMLNS);
1434 snprintf(node_value, NODE_SIZE, "%s", POSITION_NODE_ATTR_VAL_XMLNS);
1435 xmlNewProp(root_node, BAD_CAST node_name, BAD_CAST node_value);
1437 /* 1.GPS measure. */
1438 /* Creation of a new child element, added at the end of @parent children list */
1439 snprintf(node_name, NODE_SIZE, "%s", "GPS_meas");
1440 gps_msr_node = xmlNewChild(root_node, NULL, BAD_CAST node_name, NULL);
1442 snprintf(node_name, NODE_SIZE, "%s", "ref_time_only");
1443 node = xmlNewChild(gps_msr_node, NULL, BAD_CAST node_name, NULL);
1445 snprintf(node_name, NODE_SIZE, "%s", "tow_msec");
1446 snprintf(node_value, NODE_SIZE, "%d", (int) gps_measure_position_confirm->gps_measure.gpsTow);
1447 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1449 /* creatation of <meas_params> elements. */
1450 for (count = 0; count < gps_measure_position_confirm->gps_measure.nrOfSats; count++) {
1451 xmlNodePtr multipath_node = NULL;
1452 snprintf(node_name, NODE_SIZE, "%s", "meas_params");
1453 node = xmlNewChild(gps_msr_node, NULL, BAD_CAST node_name, NULL);
1455 snprintf(node_name, NODE_SIZE, "%s", "sat_id");
1456 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].satId);
1457 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1459 snprintf(node_name, NODE_SIZE, "%s", "carr2_noise");
1460 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].cno);
1461 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1463 snprintf(node_name, NODE_SIZE, "%s", "dopl");
1464 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].doppler);
1465 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1467 snprintf(node_name, NODE_SIZE, "%s", "whole_chips");
1468 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].wholeChips);
1469 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1471 snprintf(node_name, NODE_SIZE, "%s", "fract_chips");
1472 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].fracChips);
1473 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1475 snprintf(node_name, NODE_SIZE, "%s", "multi_path");
1476 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].lcsMultiPath);
1477 multipath_node = xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1478 xmlNewProp(multipath_node, BAD_CAST "literal", BAD_CAST "not_measured");
1480 snprintf(node_name, NODE_SIZE, "%s", "psr_rms_err");
1481 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].pseuRangeRmsErr);
1482 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1486 snprintf(node_name, NODE_SIZE, "%s", "location");
1487 node = xmlNewChild(root_node, NULL, BAD_CAST node_name, NULL);
1489 snprintf(node_name, NODE_SIZE, "%s", "time_of_fix");
1490 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.fixType);
1491 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1493 /* location_parameters */
1494 snprintf(node_name, NODE_SIZE, "%s", "location_parameters");
1495 node = xmlNewChild(node, NULL, BAD_CAST node_name, NULL);
1498 snprintf(node_name, NODE_SIZE, "%s", "shape_data");
1499 shape_data_node = xmlNewChild(node, NULL, BAD_CAST node_name, NULL);
1501 /* ellipsoid_point */
1502 snprintf(node_name, NODE_SIZE, "%s", "ellipsoid_point");
1503 node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1504 /* set coordinate. */
1505 _set_coordinate(node, &(gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_po), 0, 0);
1507 /* ellipsoid_point_uncert_circle */
1508 snprintf(node_name, NODE_SIZE, "%s", "ellipsoid_point_uncert_circle");
1509 node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1510 snprintf(node_name, NODE_SIZE, "%s", "uncert_circle");
1511 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.p_unc_clrcle.uncertainRadius);
1512 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1513 /* set coordinate parameters. */
1514 _set_coordinate(node, &(gps_measure_position_confirm->loc_info.measured_loc_info.p_unc_clrcle.point), 0, 0);
1516 /* ellipsoid_point_uncert_ellipse */
1517 snprintf(node_name, NODE_SIZE, "%s", "ellipsoid_point_uncert_ellipse");
1518 loc_child_node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1519 /* set coordinate parameters. */
1520 _set_coordinate(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.p_unc_clrcle.point), 0, 0);
1522 snprintf(node_name, NODE_SIZE, "%s", "uncert_ellipse");
1523 node = xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, NULL);
1524 /* set location ellipse parametes. */
1525 _set_loc_info_ellipse_elements(node, &(gps_measure_position_confirm->loc_info.measured_loc_info.p_unc_ellipse), 1);
1527 snprintf(node_name, NODE_SIZE, "%s", "polygon");
1528 loc_child_node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1529 for (count = 0; count < gps_measure_position_confirm->loc_info.measured_loc_info.polygon.noOfPoints; count++) {
1530 /* set coordinate parameters. */
1531 _set_coordinate(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.polygon.points[count]), 0, 0);
1534 /* ellipsoid_point_alt */
1535 snprintf(node_name, NODE_SIZE, "%s", "ellipsoid_point_alt");
1536 loc_child_node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1537 altitude = gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_alt.altitude;
1538 /* set coordinate parameters. */
1539 _set_coordinate(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_alt.point), 1, altitude);
1541 /* ellipsoid_point_alt_uncertellipse */
1542 snprintf(node_name, NODE_SIZE, "%s", "ellipsoid_point_alt_uncertellipse");
1543 loc_child_node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1544 altitude = gps_measure_position_confirm->loc_info.measured_loc_info.p_alt_unc_ellipse.altitude;
1545 /* set coordinate parameters. */
1546 _set_coordinate(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.p_alt_unc_ellipse.point), 1, altitude);
1547 /* set location ellipse parametes. */
1548 _set_loc_info_ellipse_elements(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.p_alt_unc_ellipse), 0);
1550 snprintf(node_name, NODE_SIZE, "%s", "uncert_alt");
1551 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.p_alt_unc_ellipse.uncertainAltitude);
1552 xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1554 /* ellipsoid_point_alt_uncertellipse */
1555 snprintf(node_name, NODE_SIZE, "%s", "ellips_arc");
1556 loc_child_node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1557 _set_coordinate(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.point), 0, 0);
1559 snprintf(node_name, NODE_SIZE, "%s", "inner_rad");
1560 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.innerRadius);
1561 xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1563 snprintf(node_name, NODE_SIZE, "%s", "uncert_rad");
1564 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.uncertainRadius);
1565 xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1567 snprintf(node_name, NODE_SIZE, "%s", "offset_angle");
1568 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.offsetAngle);
1569 xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1571 snprintf(node_name, NODE_SIZE, "%s", "included_angle");
1572 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.includedAngle);
1573 xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1575 snprintf(node_name, NODE_SIZE, "%s", "confidence");
1576 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.confidence);
1577 xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1579 /* 3. assist data /msr_assist_data */
1580 snprintf(node_name, NODE_SIZE, "%s", "assist_data");
1581 node = xmlNewChild(root_node, NULL, BAD_CAST node_name, NULL);
1582 snprintf(node_name, NODE_SIZE, "%s", "msr_assist_data");
1583 xmlNewChild(node, NULL, BAD_CAST node_name, NULL);
1585 /* Dump an XML document in memory and return the #xmlChar * and it's size in bytes */
1586 xmlDocDumpMemory(doc, &xml, &size);
1587 dbg("xmlcontetnt:\n");
1588 dbg("%s", (char *) xml);
1589 /* Free up all the structures used by a document, tree included. */
1595 static gboolean on_notification_gps_assist_data(CoreObject *o, const void *event_info, void *user_data)
1598 gps_assist_data_noti_t gps_data_assist;
1599 char *node = NULL, *node_value = NULL;
1600 char *attribute = NULL, *attr_value = NULL;
1601 enum gps_assist_element_type node_type = -1, set_element_type = -1;
1602 int nav_model_node_count = 0;
1603 int alm_node_count = -1;
1604 int gps_tow_assist_count = -1;
1605 char *line = NULL, *pos = NULL;
1606 char *xml_line = NULL;
1608 xmlTextReaderPtr reader;
1609 gboolean _gps_assist_data = FALSE, gps_tow_assist = FALSE;
1610 gboolean ephem_and_clock = FALSE, alm_elem = FALSE;
1615 Example:GPS assist XML data will be in below format.
1616 ================================================================================================================================
1617 +CPOSR:<?xml version="1.0" encoding="UTF-8"?>
1618 <pos xsi:noNamespaceSchemaLocation="pos.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1622 <GPS_time> <> <\>..<\GPS_time> <GPS_TOW_assist*> <> <\> ..<\GPS_TOW_assist>
1625 <location_parameters>
1626 <shape_data> <ellipsoid_point_alt_uncertellipse> </coordinate> <> <\>...</coordinate> <altitude> <\altitude>
1627 <uncert_semi_major> </uncert_semi_major> <uncert_semi_minor> </uncert_semi_minor> <orient_major> </orient_major> <confidence> </confidence>
1628 <uncert_alt> </uncert_alt> </ellipsoid_point_alt_uncertellipse> </shape_data>
1629 </location_parameters>
1632 <sat_id> </sat_id> <IODE> </IODE> <UDRE></UDRE> <PRC></PRC> <RRC></RRC>
1636 <sat_id> </sat_id> <sat_status literal="xx"></sat_status>
1637 <ephem_and_clock?> <l2_code></l2_code> <> <\> .. .. <\ephem_and_clock>
1640 <ionospheric_model> <alfa0> </alfa0> <alfa1> </alfa1> <alfa2> </alfa2> <alfa3></alfa3>
1641 <beta0></beta0> <beta1></beta1> <beta2></beta2> <beta3> </beta3>
1642 </ionospheric_model>
1645 <a1></a1><a0></a0><tot></tot><wnt></wnt> <dtls></dtls> <wnlsf></wnlsf> <dn></dn><dtlsf></dtlsf>
1648 <wna>0</wna> <alm_elem*> <> <\> ...<\alm_elem>
1652 <tow_msec></tow_msec> <sat_info> <> <\> ... <\sat_info>
1658 ================================================================================================================================
1661 memset((void *) &gps_data_assist, 0x00, sizeof(gps_data_assist));
1662 xml_line = (char *) ((GSList *) event_info)->data;
1664 if (g_str_has_prefix((char *) xml_line, "+CPOSR:")) {
1665 dbg("notification line with prefix");
1666 pos = (char *) xml_line + strlen("+CPOSR:");
1668 pos = (char *) xml_line;
1670 line = g_strdup((char *) pos);
1673 if ((fd = open(FILE_NAME, O_WRONLY | O_CREAT | O_TRUNC | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, S_IRWXU)) == -1) {
1674 dbg("Cannot open file\n");
1679 /* write gps xml data into file. */
1680 if (write(fd, (const void *) line, strlen(line)) == -1) {
1681 dbg("Cannot write into file\n");
1687 /* free the memory pointed to by line. */
1690 dbg("read xml file");
1691 reader = xmlReaderForFile(FILE_NAME, NULL, 0);
1693 while (xmlTextReaderRead(reader)) {
1694 /* Get the node type of the current node */
1695 switch (xmlTextReaderNodeType(reader)) {
1696 case XML_READER_TYPE_ELEMENT: {
1697 /* Read the qualified name of the node. */
1698 node = (char *) xmlTextReaderConstName(reader);
1699 dbg("Element: %s\n ", node);
1701 /* check type of sub element of <GPS_assist> */
1702 set_element_type = _get_element_type(node);
1703 if ((int) set_element_type != -1) /* ignore negative value as excepted element type not set. */
1704 node_type = set_element_type;
1706 dbg("xml node type : %d", node_type);
1708 /* Check for position measurement data. */
1709 if (strcmp(node, "pos_meas") == 0) {
1710 /* Deallocate all the resources associated to the reader */
1711 xmlFreeTextReader(reader);
1713 dbg("gps postion measurement notification ");
1714 /* GPS position measurement notification. */
1715 ret = on_notification_gps_measure_position_from_modem(o, FILE_NAME, user_data);
1718 if (access(FILE_NAME, F_OK) == 0) {
1719 if (remove(FILE_NAME))
1720 dbg("file removed");
1725 /* Moves the position of the current instance to the next attribute associated with the current node. */
1726 while (xmlTextReaderMoveToNextAttribute(reader)) {
1727 /* Read the qualified name of the node */
1728 attribute = (char *) xmlTextReaderConstName(reader);
1729 dbg("attribute value - %s\n", attribute);
1731 /* Provides the text value of the node if present. */
1732 attr_value = (char *) xmlTextReaderConstValue(reader);
1733 dbg("=\"%s\"\n", attr_value);
1735 /* Read attribute value of <nav_model_elem> */
1736 if (node_type == NAV_MODEL_ELEM) {
1737 if (strcmp(node, "sat_status") == 0 && strcmp(attribute, "literal") == 0) {
1738 gps_data_assist.navi_model.NavigationSatInfo[nav_model_node_count].NavigationSatStatus = _modem_sat_status_info_2_tel_sat_info(attr_value);
1739 dbg("navigation sat status of nav model element - %d\n", gps_data_assist.navi_model.NavigationSatInfo[nav_model_node_count].NavigationSatStatus);
1742 /* Read attribute value of <acqu_assist> */
1743 else if (node_type == ACQU_ASSIST) {
1744 if (strcmp(node, "dopl1_uncert") == 0 && strcmp(attribute, "literal") == 0) {
1745 gps_data_assist.acq_assist.lcsAcquisitionSatInfo[0].dopplerUncertainty = _modem_acqa_assit_doppler_2_tel_doppler(attr_value);
1746 dbg("doppler uncertainty of acqu assist data- %d", gps_data_assist.acq_assist.lcsAcquisitionSatInfo[0].dopplerUncertainty);
1749 } /* end of attribute check. */
1751 /* check GPS data is having GPS_assist data. */
1752 if (strcmp(node, "GPS_assist") == 0)
1753 _gps_assist_data = TRUE;
1755 if (_gps_assist_data == TRUE) {
1756 /* number of GPS_TOW_assist elements. */
1757 if (strcmp(node, "GPS_TOW_assist") == 0) {
1758 gps_tow_assist_count++;
1759 gps_tow_assist = TRUE;
1760 } else if (strcmp(node, "nav_model_elem") == 0) {
1761 /* number of nav_model_elem. */
1762 nav_model_node_count++;
1763 } else if (strcmp(node, "alm_elem") == 0) {
1764 /* number of alm_elem elements. */
1766 dbg("alm_elem_count - %d", alm_node_count);
1767 if (node_type == ALMANAC)
1769 } else if (strcmp(node, "ephem_and_clock") == 0 && node_type == NAV_MODEL_ELEM) {
1770 ephem_and_clock = TRUE;
1774 xmlTextReaderMoveToElement(reader);
1775 } /* end of reading node type. */
1778 case XML_READER_TYPE_TEXT: {
1779 /* Provides the text value of the node if present */
1780 node_value = (char *) xmlTextReaderConstValue(reader);
1781 dbg("node_value: %s\n", node_value);
1783 if (node_value != NULL) {
1784 switch (node_type) {
1786 _parse_ref_time_gps_elements(node, node_value, &gps_data_assist, gps_tow_assist, gps_tow_assist_count);
1790 _parse_location_parameters(node, node_value, &gps_data_assist);
1793 case DGPS_CORRECTION:
1794 _parse_dgps_correction_gps_elements(node, node_value, &gps_data_assist);
1797 case NAV_MODEL_ELEM:
1798 _parse_nav_model_gps_elements(node, node_value, &gps_data_assist, ephem_and_clock, nav_model_node_count);
1801 case IONOSPHERIC_MODEL:
1802 _parse_ionospheric_model_gps_elements(node, node_value, &gps_data_assist);
1806 _parse_utc_model_gps_elements(node, node_value, &gps_data_assist);
1810 _parse_almanc_model_gps_elements(node, node_value, &gps_data_assist, alm_elem, alm_node_count);
1814 _parse_acqu_assist_gps_elements(node, node_value, &gps_data_assist);
1818 dbg("invalid element");
1821 } /* end of reading node value. */
1824 } /* end of parsing. */
1826 /* Deallocate all the resources associated to the reader */
1827 xmlFreeTextReader(reader);
1830 /* remove xml file. */
1832 if (access(FILE_NAME, F_OK) == 0) {
1833 if (remove(FILE_NAME))
1834 dbg("file removed");
1837 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)),
1839 TNOTI_GPS_ASSIST_DATA,
1840 sizeof(gps_data_assist), &gps_data_assist);
1844 static gboolean on_notification_gps_measure_position_from_modem(CoreObject *o, char *file_name, void *user_data)
1846 char *node = NULL, *node_value = NULL;
1847 char *attribute = NULL;
1848 char *attr_value = NULL;
1849 gps_measure_position_indi_t gps_measure_position_indi;
1850 gboolean rep_quant = FALSE;
1851 xmlTextReaderPtr reader;
1853 memset(&gps_measure_position_indi, 0x00, sizeof(gps_measure_position_indi));
1854 reader = xmlReaderForFile(file_name, NULL, 0);
1856 while (xmlTextReaderRead(reader)) {
1857 switch (xmlTextReaderNodeType(reader)) {
1858 case XML_READER_TYPE_ELEMENT: {
1859 node = (char *) xmlTextReaderConstName(reader);
1863 dbg("Element: %s", node);
1865 /* Read attribute value. */
1866 while (xmlTextReaderMoveToNextAttribute(reader)) {
1867 attribute = (char *) xmlTextReaderConstName(reader);
1868 dbg("Attribute value - %s\n", attribute);
1869 attr_value = (char *) xmlTextReaderConstValue(reader);
1870 dbg("=\"%s\"\n", attr_value);
1872 if (strcmp(node, "mult_sets") == 0) {
1873 if (strcmp(attribute, "literal") == 0) {
1874 if (strcmp(attr_value, "one") == 0)
1875 gps_measure_position_indi.use_multi_sets = GPS_MULTIPLESETS_ONESET;
1876 else if (strcmp(attr_value, "multiple") == 0)
1877 gps_measure_position_indi.use_multi_sets = GPS_MULTIPLESETS_MULTIPLESETS;
1879 dbg("gps_measure_position_indi.use_multi_sets - 0x%x\n", gps_measure_position_indi.use_multi_sets);
1880 } else if (strcmp(node, "rep_quant") == 0) {
1882 if (strcmp(attribute, "addl_assist_data_req") == 0) {
1883 if (strcmp(attr_value, "true") == 0)
1884 gps_measure_position_indi.add_assist_req = GPS_ADDITIONAL_ASSISREQ_REQ;
1886 gps_measure_position_indi.add_assist_req = GPS_ADDITIONAL_ASSISREQ_NOT_REQ;
1887 } else if (strcmp(attribute, "gps_timing_of_cell_wanted") == 0) {
1888 if (strcmp(attr_value, "true") == 0)
1889 gps_measure_position_indi.cell_timing_wnt = GPS_CELLTIMING_WANTED;
1891 gps_measure_position_indi.cell_timing_wnt = GPS_CELLTIMING_NOT_WANTED;
1894 } /* end of attribute check */
1896 if (strcmp(node, "ms_assisted") == 0)
1897 gps_measure_position_indi.method_type = GPS_METHODTYPE_MS_ASSISTED;
1898 else if (strcmp(node, "ms_assisted_no_accuracy") == 0)
1899 gps_measure_position_indi.method_type = GPS_METHODTYPE_MS_ASSISTED;
1900 else if (strcmp(node, "ms_based") == 0)
1901 gps_measure_position_indi.method_type = GPS_METHODTYPE_MS_BASED;
1902 else if (strcmp(node, "ms_based_pref") == 0)
1903 gps_measure_position_indi.method_type = GPS_METHODTYPE_MS_BASED_PREF;
1904 else if (strcmp(node, "ms_assisted_pref") == 0)
1905 gps_measure_position_indi.method_type = GPS_METHODTYPE_MS_ASSISTED_PREF;
1907 xmlTextReaderMoveToElement(reader);
1911 case XML_READER_TYPE_TEXT: {
1912 node_value = (char *) xmlTextReaderConstValue(reader);
1913 dbg("element-value: %s", node_value);
1914 if (node_value != NULL) {
1915 if (strcmp(node_value, "resp_time_seconds") == 0) {
1916 gps_measure_position_indi.rsp_time = *node_value;
1917 dbg("gps_measure_position_indi.rsp_time - 0x%x", gps_measure_position_indi.rsp_time);
1919 if (rep_quant == TRUE) {
1920 if (strcmp(node_value, "hor_acc") == 0)
1921 gps_measure_position_indi.accuracy.horizontalAccuracy = *node_value;
1922 else if (strcmp(node_value, "vert_acc") == 0)
1923 gps_measure_position_indi.accuracy.vertcalAccuracy = *node_value;
1930 xmlFreeTextReader(reader);
1933 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)),
1934 o, TNOTI_GPS_MEASURE_POSITION, sizeof(gps_measure_position_indi), &gps_measure_position_indi);
1940 static void on_confirmation_gps_message_send(TcorePending *p, gboolean result, void *user_data)
1944 if (result == FALSE) /* Fail */
1952 static gboolean on_notification_reset_assist_data(CoreObject *o, const void *event_info, void *user_data)
1955 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)),
1956 o, TNOTI_GPS_RESET_ASSIST_DATA, 0, NULL);
1960 static void on_confirmation_gps_measure_position(TcorePending *p, int data_len, const void *data, void *user_data)
1962 /* GPS server does not except confirmation for GPS measure position request. */
1968 static TReturn gps_confirm_measure_pos(CoreObject *o, UserRequest *ur)
1970 char *raw_str = NULL;
1971 char *cmd_str = NULL;
1972 TcorePending *pending = NULL;
1973 TcoreATRequest *req = NULL;
1974 TcoreHal *hal = NULL;
1975 gboolean ret = FALSE;
1976 xmlChar *xml = NULL;
1977 unsigned char *data = NULL;
1978 unsigned int data_len;
1979 gps_measure_position_confirm_t gps_measure_pos_confirm;
1983 return TCORE_RETURN_EINVAL;
1985 data = (unsigned char *) tcore_user_request_ref_data(ur, &data_len);
1986 memcpy(&gps_measure_pos_confirm, data, data_len);
1988 /* make confirm measure postion request in xml format. */
1989 xml = _generate_confirm_measure_pos_xml_text(&gps_measure_pos_confirm);
1991 err("xml text generation failed");
1992 return TCORE_RETURN_EINVAL;
1995 /* AT+CPOS<cr>text is entered<ctrl-z/esc> */
1996 raw_str = g_strdup_printf("AT+CPOS%s", "\r");
1997 cmd_str = g_strdup_printf("%s%s\x1A", raw_str, xml);
1999 dbg("command string : %s", cmd_str);
2000 pending = tcore_pending_new(o, 0);
2001 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
2003 tcore_pending_free(pending);
2006 return TCORE_RETURN_EINVAL;
2008 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2009 tcore_pending_set_request_data(pending, strlen(cmd_str), req);
2010 tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT);
2011 tcore_pending_set_send_callback(pending, on_confirmation_gps_message_send, NULL);
2012 tcore_pending_set_response_callback(pending, on_confirmation_gps_measure_position, NULL);
2013 tcore_pending_link_user_request(pending, ur);
2016 hal = tcore_object_get_hal(o);
2017 /* Send request to HAL */
2018 ret = tcore_hal_send_request(hal, pending);
2019 if (TCORE_RETURN_SUCCESS != ret) {
2020 err("Request send failed");
2031 static struct tcore_gps_operations gps_ops = {
2032 .confirm_measure_pos = gps_confirm_measure_pos,
2035 gboolean imc_gps_init(TcorePlugin *cp, CoreObject *co_gps)
2039 /* Set operations */
2040 tcore_gps_set_ops(co_gps, &gps_ops, TCORE_OPS_TYPE_CP);
2042 tcore_object_add_callback(co_gps, "+CPOSR", on_notification_gps_assist_data, NULL);
2043 tcore_object_add_callback(co_gps, "+XCPOSR", on_notification_reset_assist_data, NULL);
2050 void imc_gps_exit(TcorePlugin *cp, CoreObject *co_gps)