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.
28 #include "nmea_logger.h"
29 #include "debug_util.h"
31 #define MAX_NMEA_RAW_DATA_LOG_FILE_CNT (999)
32 #define MAX_NMEA_LOG_FILE_PATH (100)
33 #define NMEA_LOGGING_FILE_PATH "/opt/data/gps-manager/res/nmea_data"
37 static int open_nmea_log_file(const char *);
41 char filepath[MAX_NMEA_LOG_FILE_PATH];
43 if (open_nmea_log_file(filepath) == -1) {
44 LOG_GPS(DBG_ERR, "Starting LBS Logging for RAW NMEA data FAILED!");
49 raw_nmea_fd = open(filepath, O_RDWR | O_APPEND | O_CREAT, 0644);
51 if (raw_nmea_fd < -1) {
52 LOG_GPS(DBG_ERR, "FAILED to open [%s], error[%d]", filepath, errno);
54 LOG_GPS(DBG_LOW, "%s raw_nmea_fd [%d]", filepath, raw_nmea_fd);
62 int close_ret_val = 0;
64 LOG_GPS(DBG_LOW, "raw_nmea_fd [%d]", raw_nmea_fd);
66 if (raw_nmea_fd != -1) {
67 close_ret_val = close(raw_nmea_fd);
68 if (close_ret_val < 0) {
69 LOG_GPS(DBG_ERR, "FAILED to close raw_nmea_fd[%d], error[%d]", raw_nmea_fd, errno);
76 void write_nmea_log(char *data, int len)
78 int write_ret_val = 0;
80 if (raw_nmea_fd != -1) {
81 write_ret_val = write(raw_nmea_fd, data, len);
82 if (write_ret_val < 0) {
83 LOG_GPS(DBG_ERR, "FAILED to write[%d], error[%d]", raw_nmea_fd, errno);
91 static int open_nmea_log_file(const char *filepath)
95 char fn[MAX_NMEA_LOG_FILE_PATH];
97 for (idx = 0; idx < MAX_NMEA_RAW_DATA_LOG_FILE_CNT; idx++) {
98 snprintf(fn, MAX_NMEA_LOG_FILE_PATH, "%s%03d.log", NMEA_LOGGING_FILE_PATH, idx);
99 fd = open(fn, O_RDONLY);
101 LOG_GPS(DBG_LOW, "next log file [%s]", fn);
107 LOG_GPS(DBG_LOW, "All NMEA RAW Data logging files are used. New log file can not be created");