From fdcfd776b9a6166d88c28a68de9b5fdb26de5782 Mon Sep 17 00:00:00 2001 From: "kj7.sung" Date: Fri, 24 Nov 2017 15:57:12 +0900 Subject: [PATCH] Plugin updated Change-Id: Ib78bd08523ed6040c384fe731b07d52a58735017 Signed-off-by: kj7.sung --- gps-plugin/include/gps_plugin_debug.h | 5 +- gps-plugin/include/nmea_parser.h | 3 - gps-plugin/include/setting.h | 10 +-- gps-plugin/src/gps_plugin_replay.c | 147 ++++++++++++++-------------------- gps-plugin/src/setting.c | 3 - packaging/lbs-plugin-gps-artik7.spec | 11 +-- 6 files changed, 69 insertions(+), 110 deletions(-) diff --git a/gps-plugin/include/gps_plugin_debug.h b/gps-plugin/include/gps_plugin_debug.h index e74a02d..7fad694 100644 --- a/gps-plugin/include/gps_plugin_debug.h +++ b/gps-plugin/include/gps_plugin_debug.h @@ -3,9 +3,6 @@ * * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. * - * Contact: Youngae Kang , Minjune Kim - * Genie Kim - * * 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 @@ -31,7 +28,7 @@ extern "C" { #ifdef GPS_DLOG #include -#define TAG_GPS_PLUGIN "LBS_REPLAY" +#define TAG_GPS_PLUGIN "LBS_GPS_PLUGIN" #define DBG_LOW LOG_DEBUG #define DBG_INFO LOG_INFO diff --git a/gps-plugin/include/nmea_parser.h b/gps-plugin/include/nmea_parser.h index dd2b2c8..73d5bef 100644 --- a/gps-plugin/include/nmea_parser.h +++ b/gps-plugin/include/nmea_parser.h @@ -3,9 +3,6 @@ * * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. * - * Contact: Youngae Kang , Minjune Kim - * Genie Kim - * * 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 diff --git a/gps-plugin/include/setting.h b/gps-plugin/include/setting.h index 4436c31..119fa35 100644 --- a/gps-plugin/include/setting.h +++ b/gps-plugin/include/setting.h @@ -3,9 +3,6 @@ * * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. * - * Contact: Youngae Kang , Minjune Kim - * Genie Kim - * * 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 @@ -27,10 +24,9 @@ typedef enum { - REPLAY_OFF = 0, - REPLAY_NMEA, - REPLAY_MANUAL, - REPLAY_MODE_MAX + MODE_DUMMY_GPS = 0, + MODE_REAL_GPS, + MODE_EMULATOR, } replay_mode_t; typedef enum { diff --git a/gps-plugin/src/gps_plugin_replay.c b/gps-plugin/src/gps_plugin_replay.c index 23e6450..765e2c5 100644 --- a/gps-plugin/src/gps_plugin_replay.c +++ b/gps-plugin/src/gps_plugin_replay.c @@ -3,9 +3,6 @@ * * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. * - * Contact: Youngae Kang , Minjune Kim - * Genie Kim - * * 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 @@ -62,16 +59,15 @@ peripheral_uart_h uart_hndl = NULL; 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; @@ -79,6 +75,7 @@ typedef struct { 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; @@ -193,64 +190,54 @@ void gps_plugin_replay_pos_event(pos_data_t *data) 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; @@ -261,6 +248,7 @@ void gps_plugin_replay_batch_event(pos_data_t *data, replay_timeout *timer) } 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) { @@ -433,26 +421,28 @@ gboolean gps_plugin_replay_read_nmea(replay_timeout *timer, char *nmea_data) } 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); } @@ -503,7 +493,7 @@ gboolean gps_plugin_replay_timeout_cb(gpointer 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; @@ -517,7 +507,7 @@ gboolean gps_plugin_replay_timeout_cb(gpointer data) 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; @@ -526,7 +516,7 @@ gboolean gps_plugin_replay_timeout_cb(gpointer data) 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; @@ -559,9 +549,9 @@ gboolean gps_plugin_replay_timeout_cb(gpointer data) 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; @@ -591,15 +581,15 @@ gboolean gps_plugin_get_nmea_fd(replay_timeout *timer) 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); @@ -614,10 +604,10 @@ gboolean gps_plugin_start_replay_mode(replay_timeout *timer) 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; } @@ -682,11 +672,13 @@ void gps_plugin_stop_batch_mode(replay_timeout *timer, int batch_interval, int b 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; @@ -699,9 +691,9 @@ void gps_plugin_stop_batch_mode(replay_timeout *timer, int batch_interval, int b 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."); @@ -714,19 +706,6 @@ static void replay_mode_changed_cb(keynode_t *key, void *data) 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; @@ -740,24 +719,19 @@ replay_timeout *gps_plugin_replay_timer_init() 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."); @@ -794,6 +768,7 @@ replay_timeout *gps_plugin_replay_timer_init() timer->timeout_src = NULL; timer->default_context = NULL; + timer->batch_buf = NULL; return timer; } diff --git a/gps-plugin/src/setting.c b/gps-plugin/src/setting.c index 135fa57..7726a03 100644 --- a/gps-plugin/src/setting.c +++ b/gps-plugin/src/setting.c @@ -3,9 +3,6 @@ * * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved. * - * Contact: Youngae Kang , Minjune Kim - * Genie Kim - * * 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 diff --git a/packaging/lbs-plugin-gps-artik7.spec b/packaging/lbs-plugin-gps-artik7.spec index 88a312c..8cf7adc 100644 --- a/packaging/lbs-plugin-gps-artik7.spec +++ b/packaging/lbs-plugin-gps-artik7.spec @@ -1,6 +1,6 @@ Name: lbs-plugin-gps-artik7 Summary: LBS Server plugin library for replay mode -Version: 0.1.0 +Version: 0.1.1 Release: 1 Group: Location/Libraries License: Apache-2.0 @@ -30,9 +30,6 @@ export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" -#./autogen.sh -#./configure --prefix=%{_prefix} --datadir=%{DATADIR} - MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \ -DLIB_DIR=%{_libdir} \ @@ -43,8 +40,8 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install -mkdir -p %{buildroot}%{DATADIR}/replay -cp -a nmea-log/*.log %{buildroot}%{DATADIR}/replay +mkdir -p %{buildroot}%{TZ_SYS_RO_ETC}/location +cp -a nmea-log/*.log %{buildroot}%{TZ_SYS_RO_ETC}/location %post rm -rf %{_libdir}/liblbs-server-plugin.so @@ -61,4 +58,4 @@ ln -sf %{_libdir}/liblbs-plugin-gps-artik7.so %{_libdir}/libSLP-lbs-plugin.so %license LICENSE %defattr(-,root,root,-) %{_libdir}/liblbs-plugin-gps-artik7.so* -%{DATADIR}/replay/* +%{TZ_SYS_RO_ETC}/location/* -- 2.7.4