4 * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7 * Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.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.
26 #include <sys/types.h>
30 #include "nmea_logger.h"
31 #include "debug_util.h"
33 #define MAX_NMEA_RAW_DATA_LOG_FILE_CNT (999)
34 #define MAX_NMEA_LOG_FILE_PATH (100)
36 #define PHONE_FOLDER "/opt/media"
37 #define GPSMANAGER_FOLDER PHONE_FOLDER"/gps-manager"
38 #define NMEA_FOLDER GPSMANAGER_FOLDER"/NMEA"
39 #define NMEA_LOGGING_FILE_PATH NMEA_FOLDER"/nmea_data"
43 static int generate_nmea_log_file(char *);
47 char filepath[MAX_NMEA_LOG_FILE_PATH];
52 if (stat(GPSMANAGER_FOLDER, &st) == -1) {
53 mkdir(GPSMANAGER_FOLDER, 0777);
56 if(stat(NMEA_FOLDER, &st) == -1)
57 mkdir(NMEA_FOLDER, 0777);
60 if (generate_nmea_log_file(filepath) == -1) {
61 LOG_GPS(DBG_ERR, "Starting LBS Logging for RAW NMEA data FAILED!");
66 raw_nmea_fd = open(filepath, O_RDWR | O_APPEND | O_CREAT, 0644);
68 if (raw_nmea_fd < 0) {
69 LOG_GPS(DBG_ERR, "FAILED to open [%s], error[%d]", filepath, errno);
71 LOG_GPS(DBG_LOW, "Success :: %s raw_nmea_fd [%d]", filepath, raw_nmea_fd);
79 int close_ret_val = 0;
81 LOG_GPS(DBG_LOW, "raw_nmea_fd [%d]", raw_nmea_fd);
83 if (raw_nmea_fd != -1) {
84 close_ret_val = close(raw_nmea_fd);
85 if (close_ret_val < 0) {
86 LOG_GPS(DBG_ERR, "FAILED to close raw_nmea_fd[%d], error[%d]", raw_nmea_fd, errno);
93 void write_nmea_log(char *data, int len)
95 int write_ret_val = 0;
97 if (raw_nmea_fd != -1) {
98 write_ret_val = write(raw_nmea_fd, data, len);
99 if (write_ret_val < 0) {
100 LOG_GPS(DBG_ERR, "FAILED to write[%d], error[%d]", raw_nmea_fd, errno);
108 static int generate_nmea_log_file(char *filepath)
112 char fn[MAX_NMEA_LOG_FILE_PATH];
114 for (idx = 0; idx < MAX_NMEA_RAW_DATA_LOG_FILE_CNT; idx++) {
115 snprintf(fn, MAX_NMEA_LOG_FILE_PATH, "%s%03d.txt", NMEA_LOGGING_FILE_PATH, idx);
116 if ((fd = access(fn, R_OK)) == -1) {
117 LOG_GPS(DBG_LOW, "Next log file [%s]", fn);
118 strcpy(filepath, fn);
122 LOG_GPS(DBG_LOW, "All NMEA RAW Data logging files are used. New log file can not be created");