*
* Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
- * Genie Kim <daejins.kim@samsung.com>
- *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
typedef struct {
FILE *fd;
- FILE *batch_fd;
int interval;
int replay_mode;
- int lcd_mode;
int batch_mode;
int batch_client_count;
int batch_interval;
int batch_period;
int num_of_batch;
+ int batch_buf_size;
time_t batch_start_time;
gboolean is_flush;
batch_data_t *batch_data;
sv_data_t *sv_data;
nmea_data_t *nmea_data;
+ pos_data_t *batch_buf;
GSource *timeout_src;
GMainContext *default_context;
g_gps_event_cb(&gps_event, g_user_data);
}
+void add_batch_data(pos_data_t *data, replay_timeout *timer, int idx, time_t timestamp)
+{
+ timer->batch_buf[idx].timestamp = timestamp;
+ timer->batch_buf[idx].latitude = data->latitude;
+ timer->batch_buf[idx].longitude = data->longitude;
+ timer->batch_buf[idx].altitude = data->altitude;
+ timer->batch_buf[idx].speed = data->speed;
+ timer->batch_buf[idx].bearing = data->bearing;
+ timer->batch_buf[idx].hor_accuracy = data->hor_accuracy;
+ timer->batch_buf[idx].ver_accuracy = data->ver_accuracy;
+}
+
void gps_plugin_replay_batch_event(pos_data_t *data, replay_timeout *timer)
{
- char buf[256] = {0, };
time_t timestamp;
time(×tamp);
- const char *batch_path = tzplatform_mkpath(TZ_SYS_MEDIA, "lbs-server/location_batch.log");
- if (timer->batch_fd == NULL) {
-
- struct stat st = {0};
- const char *lbs_server_path = tzplatform_mkpath(TZ_SYS_MEDIA, "lbs-server");
- if (stat(lbs_server_path, &st) == -1) {
- if (mkdir(lbs_server_path, 0777) == -1) {
- LOG_PLUGIN(DBG_ERR, "Fail to create lbs-server folder");
- return ;
- }
+ if (timer->num_of_batch < 1) {
+ if (timer->batch_buf) {
+ free(timer->batch_buf);
+ timer->batch_buf = NULL;
}
- timer->batch_fd = fopen(batch_path, "w+");
- if (timer->batch_fd == NULL) {
- LOG_PLUGIN(DBG_ERR, "Fail to open file [Not available batch_fd]");
- return ;
- }
+ int size = timer->batch_period / timer->batch_interval;
+ timer->batch_buf = (pos_data_t *) malloc(sizeof(pos_data_t) * size);
+ LOG_PLUGIN(DBG_LOW, "--> set batch_buf[size : %d]", size);
+ timer->batch_buf_size = size;
}
- if (data != NULL) {
-
- g_snprintf(buf, 256, "%ld;%.6lf;%.6lf;%.2lf;%.2lf;%.2lf;%.2lf;%.2lf;\n",
- timestamp, data->latitude, data->longitude, data->altitude,
- data->speed, data->bearing, data->hor_accuracy, data->ver_accuracy);
- LOG_PLUGIN(DBG_LOW, "Add location info to batch file [%s]", buf);
- }
-
- if (timer->lcd_mode == VCONFKEY_PM_STATE_NORMAL) {
- fwrite(buf, 1, strlen(buf), timer->batch_fd);
-
- (timer->num_of_batch)++ ;
- timer->is_flush = TRUE;
- } else {
if ((timestamp - timer->batch_start_time) % timer->batch_interval == 0) {
- fwrite(buf, 1, strlen(buf), timer->batch_fd);
- (timer->num_of_batch)++ ;
+
+ if (timer->num_of_batch < timer->batch_buf_size) {
+ add_batch_data(data, timer, timer->num_of_batch, timestamp);
+ (timer->num_of_batch)++ ;
+ }
}
+
if ((timestamp - timer->batch_start_time) >= timer->batch_period)
timer->is_flush = TRUE;
- }
+ /**
+ * invoke collected postion infomations in every batch period.
+ */
if (timer->is_flush) {
LOG_PLUGIN(DBG_LOW, "Batch invoked, Batch interval is expired or Batch stopped");
gps_event_info_t gps_event;
memset(&gps_event, 0, sizeof(gps_event_info_t));
- if (timer->batch_fd != NULL) {
- if (fclose(timer->batch_fd) != 0)
- LOG_PLUGIN(DBG_ERR, "Fail to close file");
- timer->batch_fd = NULL;
- }
-
gps_event.event_id = GPS_EVENT_REPORT_BATCH;
timer->batch_start_time = timestamp;
timer->is_flush = FALSE;
} else {
gps_event.event_data.batch_ind.error = GPS_ERR_NONE;
gps_event.event_data.batch_ind.batch.num_of_location = timer->num_of_batch;
+ gps_event.event_data.batch_ind.batch.data = timer->batch_buf;
}
if (g_gps_event_cb != NULL) {
}
while (fgets(buf, REPLAY_NMEA_SENTENCE_SIZE, timer->fd) != NULL) {
+ size_t buf_len = strlen(buf);
if (strncmp(buf, "$GPGGA", 6) == 0) {
ref++;
if (ref > 1) {
- fseek(timer->fd, -strlen(buf), SEEK_CUR);
+ fseek(timer->fd, -buf_len, SEEK_CUR);
/* LOG_PLUGIN(DBG_LOW, "2nd GPGGA : stop to read nmea data"); */
ret = TRUE;
break;
} else if (ref == 1) {
/* LOG_PLUGIN(DBG_LOW, "1st GPGGA : start to read nmea data"); */
- strncpy(nmea_data, buf, strlen(buf) - 1);
+ strncpy(nmea_data, buf, MIN(buf_len, REPLAY_NMEA_SET_SIZE - 1));
}
} else {
- if (strlen(nmea_data) + strlen(buf) > REPLAY_NMEA_SET_SIZE) {
+ size_t nmea_data_len = strlen(nmea_data);
+ if ((nmea_data_len + buf_len) > (REPLAY_NMEA_SET_SIZE - 1)) {
LOG_PLUGIN(DBG_ERR, "read nmea data size is too long");
break;
} else {
- strncpy(nmea_data + strlen(nmea_data), buf, strlen(buf) - 1);
+ strncat(nmea_data, buf, REPLAY_NMEA_SET_SIZE - nmea_data_len - 1);
}
}
- timer->nmea_data->len = strlen(buf);
+ timer->nmea_data->len = buf_len;
timer->nmea_data->data = buf;
gps_plugin_replay_nmea_event(timer->nmea_data);
}
memset(timer->batch_data, 0, sizeof(batch_data_t));
memset(timer->sv_data, 0, sizeof(sv_data_t));
- if (timer->replay_mode == REPLAY_NMEA) {
+ if (timer->replay_mode == MODE_REAL_GPS) {
if (gps_plugin_read_uart(timer, nmea_data) == FALSE) {
LOG_PLUGIN(DBG_ERR, "Fail to read nmea data from peripheral uart");
return FALSE;
timer->sv_data->pos_valid = FALSE;
}
}
- } else if (timer->replay_mode == REPLAY_MANUAL) {
+ } else if (timer->replay_mode == MODE_EMULATOR) {
if (gps_plugin_replay_read_manual(timer->pos_data) == FALSE) {
LOG_PLUGIN(DBG_ERR, "Fail to read manual data");
err = READ_ERROR;
timer->sv_data->pos_valid = TRUE;
err = READ_SUCCESS;
}
- } else if (timer->replay_mode == REPLAY_OFF) {
+ } else if (timer->replay_mode == MODE_DUMMY_GPS) {
if (gps_plugin_replay_read_nmea(timer, nmea_data) == FALSE) {
LOG_PLUGIN(DBG_ERR, "Fail to read nmea data from file");
return FALSE;
void gps_plugin_stop_replay_mode(replay_timeout *timer)
{
- if (timer->replay_mode == REPLAY_NMEA && gps_uart_close() == FALSE)
+ if (timer->replay_mode == MODE_REAL_GPS && gps_uart_close() == FALSE)
LOG_PLUGIN(DBG_ERR, "peripheral_uart_close failed");
- else if (timer->replay_mode == REPLAY_OFF && fclose(timer->fd) != 0)
+ else if (timer->replay_mode == MODE_DUMMY_GPS && fclose(timer->fd) != 0)
LOG_PLUGIN(DBG_ERR, "fclose failed");
timer->fd = NULL;
if (str == NULL)
return FALSE;
- const char *nmea_file_path = tzplatform_mkpath(TZ_SYS_MEDIA, "lbs-server/replay/");
+ const char *nmea_file_path = tzplatform_mkpath(TZ_SYS_SHARE, "location/replay/");
snprintf(replay_file_path, sizeof(replay_file_path), "%s%s", nmea_file_path, str);
- SECLOG_PLUGIN(DBG_ERR, "replay file name : %s", replay_file_path);
+ SECLOG_PLUGIN(DBG_ERR, "check custom replay : %s", replay_file_path);
free(str);
timer->fd = fopen(replay_file_path, "r");
if (timer->fd == NULL) {
- SECLOG_PLUGIN(DBG_ERR, "fopen(%s) failed", replay_file_path);
- const char *default_nmea_log = tzplatform_mkpath(TZ_SYS_RO_ETC, "lbs-server/replay/nmea_replay.log");
+ const char *default_nmea_log = tzplatform_mkpath(TZ_SYS_RO_ETC, "location/nmea_replay.log");
+ SECLOG_PLUGIN(DBG_ERR, "fopen failed(%s). loading default(%s) ", replay_file_path, default_nmea_log);
timer->fd = fopen(default_nmea_log, "r");
if (timer->fd == NULL) {
SECLOG_PLUGIN(DBG_ERR, "fopen(%s) failed", default_nmea_log);
LOG_PLUGIN(DBG_LOW, "gps_plugin_start replay mode");
gboolean ret = FALSE;
- if (timer->replay_mode == REPLAY_NMEA) {
+ if (timer->replay_mode == MODE_REAL_GPS) {
if (gps_uart_open() == FALSE)
return FALSE;
- } else if (timer->replay_mode == REPLAY_OFF) {
+ } else if (timer->replay_mode == MODE_DUMMY_GPS) {
if (gps_plugin_get_nmea_fd(timer) == FALSE)
return FALSE;
}
timer->batch_interval = 0;
timer->batch_period = 0;
- if (timer->batch_fd != NULL) {
- fclose(timer->batch_fd);
- timer->batch_fd = NULL;
- timer->num_of_batch = 0;
+ if (timer->batch_buf) {
+ free(timer->batch_buf);
+ timer->batch_buf = NULL;
}
+ timer->num_of_batch = 0;
+ timer->batch_buf_size = 0;
+
} else {
timer->batch_interval = batch_interval;
timer->batch_period = batch_period;
static void replay_mode_changed_cb(keynode_t *key, void *data)
{
if (setting_get_int(VCONFKEY_LOCATION_REPLAY_MODE, &g_replay_timer->replay_mode) == FALSE)
- g_replay_timer->replay_mode = REPLAY_OFF;
+ g_replay_timer->replay_mode = MODE_DUMMY_GPS;
- if (g_replay_timer->replay_mode == REPLAY_NMEA) {
+ if (g_replay_timer->replay_mode == MODE_DUMMY_GPS) {
if (gps_plugin_get_nmea_fd(g_replay_timer) == FALSE)
LOG_PLUGIN(DBG_ERR, "Fail to get nmea fd.");
return;
}
-static void display_mode_changed_cb(keynode_t * key, void *data)
-{
- if (setting_get_int(VCONFKEY_PM_STATE, &g_replay_timer->lcd_mode) == FALSE) {
- LOG_PLUGIN(DBG_ERR, "Fail to get lcd state");
- g_replay_timer->lcd_mode = VCONFKEY_PM_STATE_LCDOFF;
- }
-
- if (g_replay_timer->lcd_mode == VCONFKEY_PM_STATE_NORMAL)
- g_replay_timer->is_flush = TRUE;
-
- return;
-}
-
replay_timeout *gps_plugin_replay_timer_init()
{
replay_timeout *timer = NULL;
timer->fd = NULL;
timer->interval = 1;
- timer->batch_fd = NULL;
timer->num_of_batch = 0;
timer->batch_client_count = 0;
timer->batch_mode = BATCH_MODE_OFF;
timer->batch_interval = 0;
timer->batch_period = 0;
+ timer->batch_buf_size = 0;
timer->is_flush = FALSE;
if (setting_get_int(VCONFKEY_LOCATION_REPLAY_MODE, &timer->replay_mode) == FALSE)
- timer->replay_mode = REPLAY_OFF;
+ timer->replay_mode = MODE_DUMMY_GPS;
setting_notify_key_changed(VCONFKEY_LOCATION_REPLAY_MODE, replay_mode_changed_cb);
- if (setting_get_int(VCONFKEY_PM_STATE, &timer->lcd_mode) == FALSE)
- timer->lcd_mode = VCONFKEY_PM_STATE_LCDOFF;
-
- setting_notify_key_changed(VCONFKEY_PM_STATE, display_mode_changed_cb);
-
timer->pos_data = (pos_data_t *) malloc(sizeof(pos_data_t));
if (timer->pos_data == NULL) {
LOG_PLUGIN(DBG_ERR, "pos_data allocation is failed.");
timer->timeout_src = NULL;
timer->default_context = NULL;
+ timer->batch_buf = NULL;
return timer;
}