4 * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
7 * Genie Kim <daejins.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
31 #include <gps_plugin_intf.h>
32 #include <tzplatform_config.h>
34 #include "gps_plugin_debug.h"
35 #include "nmea_parser.h"
38 #include "peripheral_io.h"
39 #include "peripheral_gdbus_i2c.h"
40 #include "peripheral_common.h"
41 #include "peripheral_internal.h"
43 #define REPLAY_NMEA_SET_SIZE 4096
44 #define REPLAY_NMEA_SENTENCE_SIZE 128
47 * NMEA PACKET CMD for BerryGPS-IMU
49 #define PMK_CMD_WAKEUP_MODE "$PMTK161,1*28\r\n"
50 #define PMK_CMD_STANDBY_MODE "$PMTK161,0*28\r\n"
53 * ARTIK7 UART PORT has only one.
55 #define GPS_UART_PORT 4
56 #define GPS_UART_BUFF_SIZE 1024
58 gps_event_cb g_gps_event_cb = NULL;
59 void *g_user_data = NULL;
61 peripheral_uart_h uart_hndl = NULL;
71 int batch_client_count;
75 time_t batch_start_time;
79 batch_data_t *batch_data;
81 nmea_data_t *nmea_data;
84 GMainContext *default_context;
87 replay_timeout *g_replay_timer = NULL;
89 int gps_plugin_replay_gps_init(gps_event_cb gps_event_cb, void *user_data);
90 int gps_plugin_replay_gps_deinit(gps_failure_reason_t *reason_code);
91 int gps_plugin_replay_gps_request(gps_action_t gps_action, void *gps_action_data, gps_failure_reason_t *reason_code);
93 static const gps_plugin_interface g_gps_plugin_replay_interface = {
94 gps_plugin_replay_gps_init,
95 gps_plugin_replay_gps_deinit,
96 gps_plugin_replay_gps_request
99 static int gps_uart_close()
103 ret = peripheral_uart_close(uart_hndl);
105 _E("GPS Uart Port Close failed !!");
109 _D("GPS Uart Port Close Successful !!");
113 static int gps_uart_open()
117 ret = peripheral_uart_open(GPS_UART_PORT, &uart_hndl);
119 _E("GPS Uart Port Open failed !!");
122 _D("GPS Uart Port Open Successful !!");
123 ret = peripheral_uart_set_baud_rate(uart_hndl, PERIPHERAL_UART_BAUD_RATE_9600);
125 _E("GPS Uart Port Open failed !!");
128 ret = peripheral_uart_set_byte_size(uart_hndl, PERIPHERAL_UART_BYTE_SIZE_8BIT);
130 _E("GPS Uart Set Mode failed !!");
133 ret = peripheral_uart_set_parity(uart_hndl, PERIPHERAL_UART_PARITY_NONE);
135 _E("GPS Uart Set Mode failed !!");
138 ret = peripheral_uart_set_stop_bits(uart_hndl, PERIPHERAL_UART_STOP_BITS_1BIT);
140 _E("GPS Uart Set Mode failed !!");
143 ret = peripheral_uart_set_flow_control(uart_hndl,
144 PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS,
145 PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE);
147 _E("GPS Uart Set Flow Control Open failed !!");
156 static int gps_uart_read(char *buf, int len)
160 /* ERROR if the length is less than 0 */
161 if ((length = peripheral_uart_read(uart_hndl, (uint8_t *)buf, len)) < PERIPHERAL_ERROR_NONE)
162 _E("GPS Uart Read failed !!");
167 void gps_plugin_replay_pos_event(pos_data_t *data)
169 gps_event_info_t gps_event;
172 memset(&gps_event, 0, sizeof(gps_event_info_t));
175 gps_event.event_id = GPS_EVENT_REPORT_POSITION;
178 LOG_PLUGIN(DBG_ERR, "NULL POS data.");
179 gps_event.event_data.pos_ind.error = GPS_ERR_COMMUNICATION;
181 gps_event.event_data.pos_ind.error = GPS_ERR_NONE;
182 gps_event.event_data.pos_ind.pos.timestamp = timestamp;
183 gps_event.event_data.pos_ind.pos.latitude = data->latitude;
184 gps_event.event_data.pos_ind.pos.longitude = data->longitude;
185 gps_event.event_data.pos_ind.pos.altitude = data->altitude;
186 gps_event.event_data.pos_ind.pos.speed = data->speed;
187 gps_event.event_data.pos_ind.pos.bearing = data->bearing;
188 gps_event.event_data.pos_ind.pos.hor_accuracy = data->hor_accuracy;
189 gps_event.event_data.pos_ind.pos.ver_accuracy = data->ver_accuracy;
192 if (g_gps_event_cb != NULL)
193 g_gps_event_cb(&gps_event, g_user_data);
196 void gps_plugin_replay_batch_event(pos_data_t *data, replay_timeout *timer)
198 char buf[256] = {0, };
202 const char *batch_path = tzplatform_mkpath(TZ_SYS_MEDIA, "lbs-server/location_batch.log");
203 if (timer->batch_fd == NULL) {
205 struct stat st = {0};
206 const char *lbs_server_path = tzplatform_mkpath(TZ_SYS_MEDIA, "lbs-server");
207 if (stat(lbs_server_path, &st) == -1) {
208 if (mkdir(lbs_server_path, 0777) == -1) {
209 LOG_PLUGIN(DBG_ERR, "Fail to create lbs-server folder");
214 timer->batch_fd = fopen(batch_path, "w+");
215 if (timer->batch_fd == NULL) {
216 LOG_PLUGIN(DBG_ERR, "Fail to open file [Not available batch_fd]");
223 g_snprintf(buf, 256, "%ld;%.6lf;%.6lf;%.2lf;%.2lf;%.2lf;%.2lf;%.2lf;\n",
224 timestamp, data->latitude, data->longitude, data->altitude,
225 data->speed, data->bearing, data->hor_accuracy, data->ver_accuracy);
226 LOG_PLUGIN(DBG_LOW, "Add location info to batch file [%s]", buf);
229 if (timer->lcd_mode == VCONFKEY_PM_STATE_NORMAL) {
230 fwrite(buf, 1, strlen(buf), timer->batch_fd);
232 (timer->num_of_batch)++ ;
233 timer->is_flush = TRUE;
235 if ((timestamp - timer->batch_start_time) % timer->batch_interval == 0) {
236 fwrite(buf, 1, strlen(buf), timer->batch_fd);
237 (timer->num_of_batch)++ ;
239 if ((timestamp - timer->batch_start_time) >= timer->batch_period)
240 timer->is_flush = TRUE;
243 if (timer->is_flush) {
244 LOG_PLUGIN(DBG_LOW, "Batch invoked, Batch interval is expired or Batch stopped");
245 gps_event_info_t gps_event;
246 memset(&gps_event, 0, sizeof(gps_event_info_t));
248 if (timer->batch_fd != NULL) {
249 if (fclose(timer->batch_fd) != 0)
250 LOG_PLUGIN(DBG_ERR, "Fail to close file");
251 timer->batch_fd = NULL;
254 gps_event.event_id = GPS_EVENT_REPORT_BATCH;
255 timer->batch_start_time = timestamp;
256 timer->is_flush = FALSE;
258 if (timer->num_of_batch < 1) {
259 LOG_PLUGIN(DBG_ERR, "There is no Batch data");
260 gps_event.event_data.batch_ind.error = GPS_ERR_COMMUNICATION;
262 gps_event.event_data.batch_ind.error = GPS_ERR_NONE;
263 gps_event.event_data.batch_ind.batch.num_of_location = timer->num_of_batch;
266 if (g_gps_event_cb != NULL) {
267 g_gps_event_cb(&gps_event, g_user_data);
268 timer->num_of_batch = 0;
273 void gps_plugin_replay_sv_event(sv_data_t *data)
276 gps_event_info_t gps_event;
279 memset(&gps_event, 0, sizeof(gps_event_info_t));
281 gps_event.event_id = GPS_EVENT_REPORT_SATELLITE;
284 LOG_PLUGIN(DBG_ERR, "NULL SV data.");
285 gps_event.event_data.sv_ind.error = GPS_ERR_COMMUNICATION;
287 gps_event.event_data.sv_ind.error = GPS_ERR_NONE;
288 gps_event.event_data.sv_ind.sv.timestamp = timestamp;
289 gps_event.event_data.sv_ind.sv.pos_valid = data->pos_valid;
290 gps_event.event_data.sv_ind.sv.num_of_sat = data->num_of_sat;
291 for (i = 0; i < data->num_of_sat; i++) {
292 gps_event.event_data.sv_ind.sv.sat[i].used = data->sat[i].used;
293 gps_event.event_data.sv_ind.sv.sat[i].prn = data->sat[i].prn;
294 gps_event.event_data.sv_ind.sv.sat[i].snr = data->sat[i].snr;
295 gps_event.event_data.sv_ind.sv.sat[i].elevation = data->sat[i].elevation;
296 gps_event.event_data.sv_ind.sv.sat[i].azimuth = data->sat[i].azimuth;
300 if (g_gps_event_cb != NULL)
301 g_gps_event_cb(&gps_event, g_user_data);
304 void gps_plugin_replay_nmea_event(nmea_data_t *data)
306 gps_event_info_t gps_event;
309 memset(&gps_event, 0, sizeof(gps_event_info_t));
312 gps_event.event_id = GPS_EVENT_REPORT_NMEA;
315 LOG_PLUGIN(DBG_ERR, "NULL NMEA data.");
316 gps_event.event_data.nmea_ind.error = GPS_ERR_COMMUNICATION;
318 if (data->len > REPLAY_NMEA_SENTENCE_SIZE) {
319 LOG_PLUGIN(DBG_WARN, "The Size of NMEA[ %d ] is larger then max ", data->len);
320 data->len = REPLAY_NMEA_SENTENCE_SIZE;
321 gps_event.event_data.nmea_ind.error = GPS_ERR_COMMUNICATION;
323 gps_event.event_data.nmea_ind.error = GPS_ERR_NONE;
325 gps_event.event_data.nmea_ind.nmea.timestamp = timestamp;
326 gps_event.event_data.nmea_ind.nmea.len = data->len;
327 gps_event.event_data.nmea_ind.nmea.data = (char *)malloc(data->len);
328 g_return_if_fail(gps_event.event_data.nmea_ind.nmea.data);
330 memset(gps_event.event_data.nmea_ind.nmea.data, 0x00, data->len);
331 memcpy(gps_event.event_data.nmea_ind.nmea.data, data->data, data->len);
334 if (g_gps_event_cb != NULL)
335 g_gps_event_cb(&gps_event, g_user_data);
337 if (gps_event.event_data.nmea_ind.nmea.data != NULL) {
338 free(gps_event.event_data.nmea_ind.nmea.data);
339 gps_event.event_data.nmea_ind.nmea.data = NULL;
343 void gps_plugin_respond_start_session(gboolean ret)
345 gps_event_info_t gps_event;
346 gps_event.event_id = GPS_EVENT_START_SESSION;
349 gps_event.event_data.start_session_rsp.error = GPS_ERR_NONE;
351 gps_event.event_data.start_session_rsp.error = GPS_ERR_COMMUNICATION;
353 if (g_gps_event_cb != NULL)
354 g_gps_event_cb(&gps_event, g_user_data);
357 void gps_plugin_respond_stop_session(void)
359 gps_event_info_t gps_event;
361 gps_event.event_id = GPS_EVENT_STOP_SESSION;
362 gps_event.event_data.stop_session_rsp.error = GPS_ERR_NONE;
364 if (g_gps_event_cb != NULL)
365 g_gps_event_cb(&gps_event, g_user_data);
368 gboolean gps_plugin_read_uart(replay_timeout *timer, char *nmea_data)
370 char buf[GPS_UART_BUFF_SIZE] = { 0, };
375 if (uart_hndl == NULL) {
376 LOG_PLUGIN(DBG_ERR, "uart handle is NULL");
380 if (nmea_data == NULL) {
381 LOG_PLUGIN(DBG_ERR, "nmea_data is NULL");
387 if ((len = gps_uart_read(buf, GPS_UART_BUFF_SIZE)) < 0) {
388 LOG_PLUGIN(DBG_ERR, "gps_uart_read ERROR");
392 /* remove uncompleted sentences */
393 endstr = rindex(buf, '\n');
399 str = (char *)strtok(buf, "\n");
400 while (str != NULL) {
401 if (strncmp(str, "$GP", 3) == 0) {
402 if (strlen(nmea_data) + strlen(str) > REPLAY_NMEA_SET_SIZE) {
403 LOG_PLUGIN(DBG_ERR, "read nmea data size is too long");
406 strncpy(nmea_data + strlen(nmea_data), str, strlen(str) - 1);
408 timer->nmea_data->len = strlen(str);
409 timer->nmea_data->data = str;
410 gps_plugin_replay_nmea_event(timer->nmea_data);
412 str = (char *)strtok(NULL, "\n");
417 gboolean gps_plugin_replay_read_nmea(replay_timeout *timer, char *nmea_data)
419 gboolean ret = FALSE;
421 char buf[REPLAY_NMEA_SENTENCE_SIZE] = { 0, };
423 if (timer->fd == NULL) {
424 LOG_PLUGIN(DBG_ERR, "nmea fd is NULL");
428 if (nmea_data == NULL) {
429 LOG_PLUGIN(DBG_ERR, "nmea_data is NULL");
435 while (fgets(buf, REPLAY_NMEA_SENTENCE_SIZE, timer->fd) != NULL) {
436 if (strncmp(buf, "$GPGGA", 6) == 0) {
439 fseek(timer->fd, -strlen(buf), SEEK_CUR);
440 /* LOG_PLUGIN(DBG_LOW, "2nd GPGGA : stop to read nmea data"); */
443 } else if (ref == 1) {
444 /* LOG_PLUGIN(DBG_LOW, "1st GPGGA : start to read nmea data"); */
445 strncpy(nmea_data, buf, strlen(buf) - 1);
448 if (strlen(nmea_data) + strlen(buf) > REPLAY_NMEA_SET_SIZE) {
449 LOG_PLUGIN(DBG_ERR, "read nmea data size is too long");
452 strncpy(nmea_data + strlen(nmea_data), buf, strlen(buf) - 1);
455 timer->nmea_data->len = strlen(buf);
456 timer->nmea_data->data = buf;
457 gps_plugin_replay_nmea_event(timer->nmea_data);
460 if (feof(timer->fd)) {
461 LOG_PLUGIN(DBG_ERR, "end of file");
465 /* LOG_PLUGIN(DBG_LOW, "read nmea data [%s]", nmea_data); */
470 gboolean gps_plugin_replay_read_manual(pos_data_t *pos_data)
474 if (setting_get_double(VCONFKEY_LOCATION_MANUAL_LATITUDE, &pos_data->latitude) == FALSE) {
475 LOG_PLUGIN(DBG_ERR, "Fail to get latitude");
478 if (setting_get_double(VCONFKEY_LOCATION_MANUAL_LONGITUDE, &pos_data->longitude) == FALSE) {
479 LOG_PLUGIN(DBG_ERR, "Fail to get longitude");
482 if (setting_get_double(VCONFKEY_LOCATION_MANUAL_ALTITUDE, &pos_data->altitude) == FALSE) {
483 LOG_PLUGIN(DBG_ERR, "Fail to get altitude");
490 gboolean gps_plugin_replay_timeout_cb(gpointer data)
492 gboolean ret = FALSE;
493 read_error_t err = READ_SUCCESS;
494 char nmea_data[REPLAY_NMEA_SET_SIZE] = { 0, };
495 replay_timeout *timer = (replay_timeout *) data;
498 LOG_PLUGIN(DBG_ERR, "replay handel[timer] is NULL");
502 memset(timer->pos_data, 0, sizeof(pos_data_t));
503 memset(timer->batch_data, 0, sizeof(batch_data_t));
504 memset(timer->sv_data, 0, sizeof(sv_data_t));
506 if (timer->replay_mode == REPLAY_NMEA) {
507 if (gps_plugin_read_uart(timer, nmea_data) == FALSE) {
508 LOG_PLUGIN(DBG_ERR, "Fail to read nmea data from peripheral uart");
511 err = nmea_parser(nmea_data, timer->pos_data, timer->sv_data);
512 if (err == READ_ERROR) {
513 LOG_PLUGIN(DBG_ERR, "Fail to parser nmea data from peripheral uart");
515 } else if (err == READ_NOT_FIXED) {
516 LOG_PLUGIN(DBG_LOW, "GPS position is not fixed");
517 timer->sv_data->pos_valid = FALSE;
520 } else if (timer->replay_mode == REPLAY_MANUAL) {
521 if (gps_plugin_replay_read_manual(timer->pos_data) == FALSE) {
522 LOG_PLUGIN(DBG_ERR, "Fail to read manual data");
526 timer->sv_data->pos_valid = TRUE;
529 } else if (timer->replay_mode == REPLAY_OFF) {
530 if (gps_plugin_replay_read_nmea(timer, nmea_data) == FALSE) {
531 LOG_PLUGIN(DBG_ERR, "Fail to read nmea data from file");
534 err = nmea_parser(nmea_data, timer->pos_data, timer->sv_data);
535 if (err == READ_ERROR) {
536 LOG_PLUGIN(DBG_ERR, "Fail to parser nmea data from file");
538 } else if (err == READ_NOT_FIXED) {
539 LOG_PLUGIN(DBG_LOW, "GPS position is not fixed");
540 timer->sv_data->pos_valid = FALSE;
545 if (g_gps_event_cb != NULL) {
546 if (err != READ_NOT_FIXED) {
547 if (timer->batch_mode == BATCH_MODE_ON) {
548 gps_plugin_replay_batch_event(timer->pos_data, timer);
551 gps_plugin_replay_pos_event(timer->pos_data);
554 gps_plugin_replay_sv_event(timer->sv_data);
560 void gps_plugin_stop_replay_mode(replay_timeout *timer)
562 if (timer->replay_mode == REPLAY_NMEA && gps_uart_close() == FALSE)
563 LOG_PLUGIN(DBG_ERR, "peripheral_uart_close failed");
564 else if (timer->replay_mode == REPLAY_OFF && fclose(timer->fd) != 0)
565 LOG_PLUGIN(DBG_ERR, "fclose failed");
569 if (timer->timeout_src != NULL && timer->default_context != NULL && !g_source_is_destroyed(timer->timeout_src)) {
570 if (timer->default_context == g_source_get_context(timer->timeout_src)) {
571 g_source_destroy(timer->timeout_src);
572 LOG_PLUGIN(DBG_LOW, "g_source_destroy timeout_src");
574 LOG_PLUGIN(DBG_WARN, "timer->timeout_src is attatched to 0x%x (actual 0x%x)",
575 g_source_get_context(timer->timeout_src), timer->default_context);
577 timer->timeout_src = NULL;
578 timer->default_context = NULL;
580 LOG_PLUGIN(DBG_WARN, "timeout_src or default_context is NULL or timeout_src is already destroyed");
582 gps_plugin_respond_stop_session();
585 gboolean gps_plugin_get_nmea_fd(replay_timeout *timer)
587 char replay_file_path[256];
590 str = setting_get_string(VCONFKEY_LOCATION_NMEA_FILE_NAME);
594 const char *nmea_file_path = tzplatform_mkpath(TZ_SYS_MEDIA, "lbs-server/replay/");
595 snprintf(replay_file_path, sizeof(replay_file_path), "%s%s", nmea_file_path, str);
596 SECLOG_PLUGIN(DBG_ERR, "replay file name : %s", replay_file_path);
599 timer->fd = fopen(replay_file_path, "r");
600 if (timer->fd == NULL) {
601 SECLOG_PLUGIN(DBG_ERR, "fopen(%s) failed", replay_file_path);
602 const char *default_nmea_log = tzplatform_mkpath(TZ_SYS_RO_ETC, "lbs-server/replay/nmea_replay.log");
603 timer->fd = fopen(default_nmea_log, "r");
604 if (timer->fd == NULL) {
605 SECLOG_PLUGIN(DBG_ERR, "fopen(%s) failed", default_nmea_log);
612 gboolean gps_plugin_start_replay_mode(replay_timeout *timer)
614 LOG_PLUGIN(DBG_LOW, "gps_plugin_start replay mode");
615 gboolean ret = FALSE;
617 if (timer->replay_mode == REPLAY_NMEA) {
618 if (gps_uart_open() == FALSE)
620 } else if (timer->replay_mode == REPLAY_OFF) {
621 if (gps_plugin_get_nmea_fd(timer) == FALSE)
625 if (timer->default_context == NULL) {
626 timer->default_context = g_main_context_default();
628 if (timer->default_context == NULL)
632 if (timer->timeout_src != NULL) {
633 LOG_PLUGIN(DBG_ERR, "timeout_src is already existed");
636 timer->timeout_src = g_timeout_source_new_seconds(timer->interval);
637 if (timer->timeout_src != NULL) {
638 g_source_set_callback(timer->timeout_src, &gps_plugin_replay_timeout_cb, timer, NULL);
639 if (g_source_attach(timer->timeout_src, timer->default_context) > 0) {
640 LOG_PLUGIN(DBG_LOW, "timeout_src(0x%x) is created & attatched to 0x%x", timer->timeout_src, timer->default_context);
643 gps_plugin_stop_replay_mode(timer);
649 gps_plugin_respond_start_session(ret);
654 gboolean gps_plugin_update_batch_mode(replay_timeout *timer, int batch_interval, int batch_period)
656 gboolean ret = FALSE;
660 if (timer->batch_mode == BATCH_MODE_OFF) {
661 timer->batch_mode = BATCH_MODE_ON;
662 timer->batch_client_count = 0;
664 timer->batch_client_count++;
666 timer->batch_interval = batch_interval;
667 timer->batch_period = batch_period;
668 timer->batch_start_time = timestamp;
670 LOG_PLUGIN(DBG_LOW, "batch_client_count = %d", timer->batch_client_count);
674 void gps_plugin_stop_batch_mode(replay_timeout *timer, int batch_interval, int batch_period)
676 if (timer->batch_client_count > 0)
677 timer->batch_client_count--;
679 LOG_PLUGIN(DBG_ERR, "batch_client_count = %d", timer->batch_client_count);
680 if (timer->batch_client_count <= 0) {
681 timer->batch_mode = BATCH_MODE_OFF;
682 timer->batch_interval = 0;
683 timer->batch_period = 0;
685 if (timer->batch_fd != NULL) {
686 fclose(timer->batch_fd);
687 timer->batch_fd = NULL;
688 timer->num_of_batch = 0;
691 timer->batch_interval = batch_interval;
692 timer->batch_period = batch_period;
695 timer->batch_start_time = timestamp;
699 static void replay_mode_changed_cb(keynode_t *key, void *data)
701 if (setting_get_int(VCONFKEY_LOCATION_REPLAY_MODE, &g_replay_timer->replay_mode) == FALSE)
702 g_replay_timer->replay_mode = REPLAY_OFF;
704 if (g_replay_timer->replay_mode == REPLAY_NMEA) {
705 if (gps_plugin_get_nmea_fd(g_replay_timer) == FALSE)
706 LOG_PLUGIN(DBG_ERR, "Fail to get nmea fd.");
709 if (g_replay_timer->fd != NULL) {
710 fclose(g_replay_timer->fd);
711 g_replay_timer->fd = NULL;
717 static void display_mode_changed_cb(keynode_t * key, void *data)
719 if (setting_get_int(VCONFKEY_PM_STATE, &g_replay_timer->lcd_mode) == FALSE) {
720 LOG_PLUGIN(DBG_ERR, "Fail to get lcd state");
721 g_replay_timer->lcd_mode = VCONFKEY_PM_STATE_LCDOFF;
724 if (g_replay_timer->lcd_mode == VCONFKEY_PM_STATE_NORMAL)
725 g_replay_timer->is_flush = TRUE;
730 replay_timeout *gps_plugin_replay_timer_init()
732 replay_timeout *timer = NULL;
734 timer = (replay_timeout *) malloc(sizeof(replay_timeout));
736 LOG_PLUGIN(DBG_ERR, "replay_timeout allocation is failed.");
743 timer->batch_fd = NULL;
744 timer->num_of_batch = 0;
745 timer->batch_client_count = 0;
746 timer->batch_mode = BATCH_MODE_OFF;
747 timer->batch_interval = 0;
748 timer->batch_period = 0;
749 timer->is_flush = FALSE;
751 if (setting_get_int(VCONFKEY_LOCATION_REPLAY_MODE, &timer->replay_mode) == FALSE)
752 timer->replay_mode = REPLAY_OFF;
754 setting_notify_key_changed(VCONFKEY_LOCATION_REPLAY_MODE, replay_mode_changed_cb);
756 if (setting_get_int(VCONFKEY_PM_STATE, &timer->lcd_mode) == FALSE)
757 timer->lcd_mode = VCONFKEY_PM_STATE_LCDOFF;
759 setting_notify_key_changed(VCONFKEY_PM_STATE, display_mode_changed_cb);
761 timer->pos_data = (pos_data_t *) malloc(sizeof(pos_data_t));
762 if (timer->pos_data == NULL) {
763 LOG_PLUGIN(DBG_ERR, "pos_data allocation is failed.");
768 timer->batch_data = (batch_data_t *) malloc(sizeof(batch_data_t));
769 if (timer->batch_data == NULL) {
770 LOG_PLUGIN(DBG_ERR, "batch_data allocation is failed.");
771 free(timer->pos_data);
776 timer->sv_data = (sv_data_t *) malloc(sizeof(sv_data_t));
777 if (timer->sv_data == NULL) {
778 LOG_PLUGIN(DBG_ERR, "sv_data allocation is failed.");
779 free(timer->pos_data);
780 free(timer->batch_data);
785 timer->nmea_data = (nmea_data_t *) malloc(sizeof(nmea_data_t));
786 if (timer->nmea_data == NULL) {
787 LOG_PLUGIN(DBG_ERR, "nmea_data allocation is failed.");
788 free(timer->pos_data);
789 free(timer->batch_data);
790 free(timer->sv_data);
795 timer->timeout_src = NULL;
796 timer->default_context = NULL;
801 void gps_plugin_replay_timer_deinit(replay_timeout *timer)
806 if (timer->pos_data != NULL) {
807 free(timer->pos_data);
808 timer->pos_data = NULL;
810 if (timer->sv_data != NULL) {
811 free(timer->sv_data);
812 timer->sv_data = NULL;
814 if (timer->nmea_data != NULL) {
815 free(timer->nmea_data);
816 timer->nmea_data = NULL;
819 setting_ignore_key_changed(VCONFKEY_LOCATION_REPLAY_MODE, replay_mode_changed_cb);
825 int gps_plugin_replay_gps_init(gps_event_cb gps_event_cb, void *user_data)
827 g_gps_event_cb = gps_event_cb;
828 g_replay_timer = gps_plugin_replay_timer_init();
829 g_user_data = user_data;
834 int gps_plugin_replay_gps_deinit(gps_failure_reason_t *reason_code)
836 gps_plugin_replay_timer_deinit(g_replay_timer);
837 g_gps_event_cb = NULL;
840 peripheral_uart_close(uart_hndl);
841 _D("GPS Uart Port Close Successful !!");
846 int gps_plugin_replay_gps_request(gps_action_t gps_action, void *gps_action_data, gps_failure_reason_t *reason_code)
848 gps_action_start_data_t *gps_start_data = gps_action_data;
850 switch (gps_action) {
851 case GPS_ACTION_SEND_PARAMS:
853 case GPS_ACTION_START_SESSION:
854 gps_plugin_start_replay_mode(g_replay_timer);
856 case GPS_ACTION_STOP_SESSION:
857 gps_plugin_stop_replay_mode(g_replay_timer);
859 case GPS_ACTION_START_BATCH:
860 if (!gps_start_data->session_status) /* need to start */
861 gps_plugin_start_replay_mode(g_replay_timer);
863 gps_plugin_update_batch_mode(g_replay_timer, gps_start_data->interval, gps_start_data->period);
865 case GPS_ACTION_STOP_BATCH:
866 if (!gps_start_data->session_status) /* need to stop */
867 gps_plugin_stop_replay_mode(g_replay_timer);
869 gps_plugin_stop_batch_mode(g_replay_timer, gps_start_data->interval, gps_start_data->period);
871 case GPS_INDI_SUPL_VERIFICATION:
872 case GPS_INDI_SUPL_DNSQUERY:
873 case GPS_ACTION_START_FACTTEST:
874 case GPS_ACTION_STOP_FACTTEST:
875 case GPS_ACTION_REQUEST_SUPL_NI:
876 LOG_PLUGIN(DBG_LOW, "Don't use action type : [ %d ]", gps_action);
885 EXPORT_API const gps_plugin_interface *get_gps_plugin_interface()
887 return &g_gps_plugin_replay_interface;