#include "nmea_parser.h"
#include "setting.h"
+#include "peripheral_io.h"
+#include "peripheral_gdbus_i2c.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+
#define REPLAY_NMEA_SET_SIZE 4096
#define REPLAY_NMEA_SENTENCE_SIZE 128
+/*
+ * NMEA PACKET CMD for BerryGPS-IMU
+ */
+#define PMK_CMD_WAKEUP_MODE "$PMTK161,1*28\r\n"
+#define PMK_CMD_STANDBY_MODE "$PMTK161,0*28\r\n"
+
+/*
+ * RPI3 UART PORT has only one.
+ */
+#define GPS_UART_PORT 0
+#define GPS_UART_BUFF_SIZE 1024
gps_event_cb g_gps_event_cb = NULL;
void *g_user_data = NULL;
+peripheral_uart_h uart_hndl = NULL;
+
typedef struct {
FILE *fd;
FILE *batch_fd;
gps_plugin_replay_gps_request
};
+static int gps_uart_close()
+{
+ int ret;
+
+ ret = peripheral_uart_close(uart_hndl);
+ if (ret < 0 ) {
+ _E("GPS Uart Port Close failed !!");
+ return FALSE;
+ }
+ uart_hndl = NULL;
+ _D("GPS Uart Port Close Successful !!");
+ return TRUE;
+}
+
+static int gps_uart_open()
+{
+ int ret;
+
+ ret = peripheral_uart_open(GPS_UART_PORT, &uart_hndl);
+ if (ret < 0 ) {
+ _E("GPS Uart Port Open failed !!");
+ return FALSE;
+ }
+ _D("GPS Uart Port Open Successful !!");
+ ret = peripheral_uart_set_baudrate(uart_hndl, PERIPHERAL_UART_BAUDRATE_9600);
+ if (ret < 0) {
+ _E("GPS Uart Port Open failed !!");
+ goto ERROR;
+ }
+ ret = peripheral_uart_set_mode(uart_hndl,
+ PERIPHERAL_UART_BYTESIZE_8BIT,
+ PERIPHERAL_UART_PARITY_NONE,
+ PERIPHERAL_UART_STOPBITS_1BIT);
+ if (ret < 0) {
+ _E("GPS Uart Set Mode failed !!");
+ goto ERROR;
+ }
+ ret = peripheral_uart_set_flowcontrol(uart_hndl, true, false);
+ if (ret < 0) {
+ _E("GPS Uart Set Flow Control Open failed !!");
+ goto ERROR;
+ }
+ ret = peripheral_uart_flush(uart_hndl);
+ if (ret < 0) {
+ _E("GPS Uart Flush failed !!");
+ goto ERROR;
+ }
+ return TRUE;
+ERROR:
+ gps_uart_close();
+ return FALSE;
+}
+
+static int gps_uart_read(char *buf, int len)
+{
+ int length;
+
+ /* ERROR if the length is less than 0 */
+ if ((length = peripheral_uart_read(uart_hndl, (uint8_t *)buf, len)) < PERIPHERAL_ERROR_NONE)
+ _E("GPS Uart Read failed !!");
+
+ return length;
+}
+
void gps_plugin_replay_pos_event(pos_data_t *data)
{
gps_event_info_t gps_event;
g_gps_event_cb(&gps_event, g_user_data);
}
+gboolean gps_plugin_read_uart(replay_timeout *timer, char *nmea_data)
+{
+ char buf[GPS_UART_BUFF_SIZE] = { 0, };
+ char *endstr = NULL;
+ int len = 0;
+ char *str = NULL;
+
+ if (uart_hndl == NULL) {
+ LOG_PLUGIN(DBG_ERR, "uart handle is NULL");
+ return FALSE;
+ }
+
+ if (nmea_data == NULL) {
+ LOG_PLUGIN(DBG_ERR, "nmea_data is NULL");
+ gps_uart_close();
+ timer->fd = NULL;
+ return FALSE;
+ }
+
+ if ((len = gps_uart_read(buf, GPS_UART_BUFF_SIZE)) < 0) {
+ LOG_PLUGIN(DBG_ERR, "gps_uart_read ERROR");
+ return TRUE;
+ }
+
+ /* remove uncompleted sentences */
+ endstr = rindex(buf, '\n');
+ if (endstr != NULL)
+ *endstr = '\0';
+ else
+ return TRUE;
+
+ str = (char *)strtok(buf, "\n");
+ while (str != NULL) {
+ if (strncmp(str, "$GP", 3) == 0) {
+ if (strlen(nmea_data) + strlen(str) > REPLAY_NMEA_SET_SIZE) {
+ LOG_PLUGIN(DBG_ERR, "read nmea data size is too long");
+ break;
+ } else {
+ strncpy(nmea_data + strlen(nmea_data), str, strlen(str) - 1);
+ }
+ timer->nmea_data->len = strlen(str);
+ timer->nmea_data->data = str;
+ gps_plugin_replay_nmea_event(timer->nmea_data);
+ }
+ str = (char *)strtok(NULL, "\n");
+ }
+ return TRUE;
+}
+
gboolean gps_plugin_replay_read_nmea(replay_timeout *timer, char *nmea_data)
{
gboolean ret = FALSE;
LOG_PLUGIN(DBG_ERR, "read nmea data size is too long");
break;
} else {
- strncat(nmea_data, buf, strlen(buf));
- }
+ strncpy(nmea_data + strlen(nmea_data), buf, strlen(buf) - 1);
+ }
}
timer->nmea_data->len = strlen(buf);
timer->nmea_data->data = buf;
memset(timer->sv_data, 0, sizeof(sv_data_t));
if (timer->replay_mode == REPLAY_NMEA) {
- if (gps_plugin_replay_read_nmea(timer, nmea_data) == FALSE) {
- LOG_PLUGIN(DBG_ERR, "Fail to read nmea data from file");
+ if (gps_plugin_read_uart(timer, nmea_data) == FALSE) {
+ LOG_PLUGIN(DBG_ERR, "Fail to read nmea data from peripheral uart");
return FALSE;
} else {
err = nmea_parser(nmea_data, timer->pos_data, timer->sv_data);
if (err == READ_ERROR) {
- LOG_PLUGIN(DBG_ERR, "Fail to parser nmea data from file");
+ LOG_PLUGIN(DBG_ERR, "Fail to parser nmea data from peripheral uart");
/*return FALSE; */
} else if (err == READ_NOT_FIXED) {
LOG_PLUGIN(DBG_LOW, "GPS position is not fixed");
err = READ_SUCCESS;
}
} else if (timer->replay_mode == REPLAY_OFF) {
- LOG_PLUGIN(DBG_WARN, "replay_mode is OFF");
- err = READ_NOT_FIXED;
- timer->sv_data->pos_valid = FALSE;
+ if (gps_plugin_replay_read_nmea(timer, nmea_data) == FALSE) {
+ LOG_PLUGIN(DBG_ERR, "Fail to read nmea data from file");
+ return FALSE;
+ } else {
+ err = nmea_parser(nmea_data, timer->pos_data, timer->sv_data);
+ if (err == READ_ERROR) {
+ LOG_PLUGIN(DBG_ERR, "Fail to parser nmea data from file");
+ /*return FALSE; */
+ } else if (err == READ_NOT_FIXED) {
+ LOG_PLUGIN(DBG_LOW, "GPS position is not fixed");
+ timer->sv_data->pos_valid = FALSE;
+ }
+ }
}
if (g_gps_event_cb != NULL) {
void gps_plugin_stop_replay_mode(replay_timeout *timer)
{
- if (timer->replay_mode == REPLAY_NMEA && fclose(timer->fd) != 0)
+ if (timer->replay_mode == REPLAY_NMEA && gps_uart_close() == FALSE)
+ LOG_PLUGIN(DBG_ERR, "peripheral_uart_close failed");
+ else if (timer->replay_mode == REPLAY_OFF && fclose(timer->fd) != 0)
LOG_PLUGIN(DBG_ERR, "fclose failed");
timer->fd = NULL;
gboolean ret = FALSE;
if (timer->replay_mode == REPLAY_NMEA) {
+ if (gps_uart_open() == FALSE)
+ return FALSE;
+ } else if (timer->replay_mode == REPLAY_OFF) {
if (gps_plugin_get_nmea_fd(timer) == FALSE)
return FALSE;
}
g_gps_event_cb = NULL;
g_user_data = NULL;
+ peripheral_uart_close(uart_hndl);
+ _D("GPS Uart Port Close Successful !!");
+
return TRUE;
}
-Name: lbs-server-plugin-replay
+Name: lbs-plugin-gps-rpi3
Summary: LBS Server plugin library for replay mode
-Version: 0.2.5
+Version: 0.1.0
Release: 1
Group: Location/Libraries
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
-Source1: lbs-server-plugin-replay.manifest
+Source1: lbs-plugin-gps-rpi3.manifest
BuildRequires: cmake
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(lbs-server-plugin)
BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(capi-system-peripheral-io)
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
%post
rm -rf %{_libdir}/liblbs-server-plugin.so
-ln -sf %{_libdir}/liblbs-server-plugin-replay.so %{_libdir}/liblbs-server-plugin.so
+ln -sf %{_libdir}/liblbs-plugin-gps-rpi3.so %{_libdir}/liblbs-server-plugin.so
#for compatible with old version
-ln -sf %{_libdir}/liblbs-server-plugin-replay.so %{_libdir}/libSLP-lbs-plugin-replay.so
-ln -sf %{_libdir}/liblbs-server-plugin-replay.so %{_libdir}/libSLP-lbs-plugin.so
+ln -sf %{_libdir}/liblbs-plugin-gps-rpi3.so %{_libdir}/libSLP-lbs-plugin-replay.so
+ln -sf %{_libdir}/liblbs-plugin-gps-rpi3.so %{_libdir}/libSLP-lbs-plugin.so
/sbin/ldconfig
%postun -p /sbin/ldconfig
%files
-%manifest lbs-server-plugin-replay.manifest
+%manifest lbs-plugin-gps-rpi3.manifest
%license LICENSE
%defattr(-,root,root,-)
-%{_libdir}/liblbs-server-plugin-replay.so*
+%{_libdir}/liblbs-plugin-gps-rpi3.so*
%{DATADIR}/replay/*