]> git.webhop.me Git - lcd4linux.git/commitdiff
gps plugin, code by michu / www.neophob.com
authormichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 19 May 2007 11:43:32 +0000 (11:43 +0000)
committermichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 19 May 2007 11:43:32 +0000 (11:43 +0000)
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@801 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

Makefile.am
Makefile.in
config.h.in
configure
plugin.c
plugin_gps.c [new file with mode: 0644]
plugins.m4

index 8463dbd9c7ff28966d3bb5f38ae5032ea27526c5..d860904d2fb45421d8f6bc25ded09f651ed0ac8d 100644 (file)
@@ -111,6 +111,7 @@ plugin_diskstats.c            \
 plugin_dvb.c                  \
 plugin_exec.c                 \
 plugin_file.c                 \
+plugin_gps.c                  \
 plugin_i2c_sensors.c          \
 plugin_iconv.c                \
 plugin_imon.c                 \
index 4a084f727161577a567fa4e54bc4cc4f2a02cec9..5c8b3ef227351f1c1420d109e0d1bc5c883d40cb 100644 (file)
@@ -306,6 +306,7 @@ plugin_diskstats.c            \
 plugin_dvb.c                  \
 plugin_exec.c                 \
 plugin_file.c                 \
+plugin_gps.c                  \
 plugin_i2c_sensors.c          \
 plugin_iconv.c                \
 plugin_imon.c                 \
@@ -489,6 +490,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_dvb.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_exec.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_file.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_gps.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_i2c_sensors.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_iconv.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_imon.Po@am__quote@
index ed264ef4a86ecd49013bd72f24c58cd06dc9d26b..fb06ab4aaf478fb448a043f5ff8e36e9c49635fc 100644 (file)
 /* Define to 1 if you have the <net/if_ppp.h> header file. */
 #undef HAVE_NET_IF_PPP_H
 
+/* Define to 1 if you have the <nmeap.h> header file. */
+#undef HAVE_NMEAP_H
+
 /* Define to 1 if you have the `pow' function. */
 #undef HAVE_POW
 
 /* file plugin */
 #undef PLUGIN_FILE
 
+/* gps plugin */
+#undef PLUGIN_GPS
+
 /* i2c sensors plugin */
 #undef PLUGIN_I2C_SENSORS
 
index 4f14f50f5077629a6146e72ce2f853df7ed3ec2b..eadd0292aa352eb38c16ac3c8e006e0cc1086f2e 100755 (executable)
--- a/configure
+++ b/configure
@@ -8112,6 +8112,7 @@ echo "$as_me: error: run ./configure --with-plugins=..." >&2;}
          PLUGIN_DVB="yes"
          PLUGIN_EXEC="yes"
          PLUGIN_FILE="yes"
+         PLUGIN_GPS="yes"
          PLUGIN_I2C_SENSORS="yes"
          PLUGIN_ICONV="yes"
          PLUGIN_IMON="yes"
@@ -8152,6 +8153,9 @@ echo "$as_me: error: run ./configure --with-plugins=..." >&2;}
       file)
          PLUGIN_FILE=$val
          ;;
+      gps)
+         PLUGIN_GPS=$val
+         ;;
       i2c_sensors)
          PLUGIN_I2C_SENSORS=$val
         ;;
@@ -8425,6 +8429,239 @@ cat >>confdefs.h <<\_ACEOF
 #define PLUGIN_FILE 1
 _ACEOF
 
+fi
+if test "$PLUGIN_GPS" = "yes"; then
+
+for ac_header in nmeap.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  { echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+              { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <$ac_header>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+        test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+    ( cat <<\_ASBOX
+## ---------------------------------------------------- ##
+## Report this to lcd4linux-users@lists.sourceforge.net ##
+## ---------------------------------------------------- ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+{ echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
+fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+              { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+ has_nmeap_header="true"
+else
+  has_nmeap_header="false"
+fi
+
+done
+
+   if test "$has_nmeap_header" = "true"; then
+      { echo "$as_me:$LINENO: checking for nmeap_init in -lnmeap" >&5
+echo $ECHO_N "checking for nmeap_init in -lnmeap... $ECHO_C" >&6; }
+if test "${ac_cv_lib_nmeap_nmeap_init+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lnmeap  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char nmeap_init ();
+int
+main ()
+{
+return nmeap_init ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_lib_nmeap_nmeap_init=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_cv_lib_nmeap_nmeap_init=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_nmeap_nmeap_init" >&5
+echo "${ECHO_T}$ac_cv_lib_nmeap_nmeap_init" >&6; }
+if test $ac_cv_lib_nmeap_nmeap_init = yes; then
+  has_libnmeap_lib="true"
+else
+  has_libnmeap_lib="false"
+fi
+
+      if test "$has_libnmeap_lib" = "true"; then
+        PLUGINS="$PLUGINS plugin_gps.o"
+        PLUGINLIBS="$PLUGINLIBS -lnmeap"
+
+cat >>confdefs.h <<\_ACEOF
+#define PLUGIN_GPS 1
+_ACEOF
+
+      else
+        { echo "$as_me:$LINENO: WARNING: libnmeap lib not found: gps plugin disabled" >&5
+echo "$as_me: WARNING: libnmeap lib not found: gps plugin disabled" >&2;}
+      fi
+   else
+      { echo "$as_me:$LINENO: WARNING: nmeap.h header not found: gps plugin disabled" >&5
+echo "$as_me: WARNING: nmeap.h header not found: gps plugin disabled" >&2;}
+   fi
 fi
 if test "$PLUGIN_I2C_SENSORS" = "yes"; then
    PLUGINS="$PLUGINS plugin_i2c_sensors.o"
index a1b4ac480e1808635037d928913077388578dcc9..f4579e1871d2a59e3ad4f0b4de92fe0db691e12d 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -68,6 +68,8 @@ int plugin_init_exec(void);
 void plugin_exit_exec(void);
 int plugin_init_file(void);
 void plugin_exit_file(void);
+int plugin_init_gps(void);
+void plugin_exit_gps(void);
 int plugin_init_i2c_sensors(void);
 void plugin_exit_i2c_sensors(void);
 int plugin_init_imon(void);
@@ -138,6 +140,9 @@ int plugin_init(void)
 #ifdef PLUGIN_FILE
     plugin_init_file();
 #endif
+#ifdef PLUGIN_GPS
+    plugin_init_gps();
+#endif
 #ifdef PLUGIN_I2C_SENSORS
     plugin_init_i2c_sensors();
 #endif
@@ -227,6 +232,9 @@ void plugin_exit(void)
 #ifdef PLUGIN_FILE
     plugin_exit_file();
 #endif
+#ifdef PLUGIN_GPS
+    plugin_exit_gps();
+#endif
 #ifdef PLUGIN_I2C_SENSORS
     plugin_exit_i2c_sensors();
 #endif
diff --git a/plugin_gps.c b/plugin_gps.c
new file mode 100644 (file)
index 0000000..d5b2349
--- /dev/null
@@ -0,0 +1,307 @@
+/* $Id$
+ * $URL$
+ *
+ * gps plugin, code by michu / www.neophob.com, based on nmeap, http://sourceforge.net/projects/nmeap/
+ *
+ * Copyright (C) 2007 michu
+ * Copyright (C) 2004, 2005, 2006, 2007 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
+ *
+ * This file is part of LCD4Linux.
+ *
+ * LCD4Linux is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * LCD4Linux is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/* 
+ * exported functions:
+ *
+ * int plugin_init_gps (void)
+ *  adds various functions
+ *
+ */
+
+
+/* define the include files you need */
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/io.h>
+
+/* these should always be included */
+#include "debug.h"
+#include "plugin.h"
+
+#ifdef WITH_DMALLOC
+#include <dmalloc.h>
+#endif
+
+#include "nmeap.h"
+
+
+#define SHOW_ALTITUDE  0x0000001
+#define SHOW_SPEED     0x0000010
+#define SHOW_COURSE    0x0000100
+#define SHOW_SATELLITES 0x0001000
+#define SHOW_QUALITY   0x0010000
+#define SHOW_WARN      0x0100000
+
+nmeap_gga_t g_gga;
+
+
+/* ---------------------------------------------------------------------------------------*/
+/* STEP 1 : allocate the data structures. be careful if you put them on the stack because */
+/*          they need to be live for the duration of the parser                           */
+/* ---------------------------------------------------------------------------------------*/
+
+static nmeap_context_t nmea;   /* parser context */
+static nmeap_gga_t gga;                /* this is where the data from GGA messages will show up */
+static nmeap_rmc_t rmc;                /* this is where the data from RMC messages will show up */
+static int user_data;          /* user can pass in anything. typically it will be a pointer to some user data */
+static int fd;
+
+
+
+/*************************************************************************
+ * LINUX IO
+ */
+
+/*
+ * open the specified serial port for read/write
+ * @return port file descriptor or -1
+ */
+
+static int openPort(const char *tty, int baud)
+{
+    int status;
+    int fd;
+    struct termios newtio;
+
+    /* open the tty */
+    fd = open(tty, O_RDWR | O_NOCTTY);
+    if (fd < 0) {
+       error("open");
+       return fd;
+    }
+
+    /* flush serial port */
+    status = tcflush(fd, TCIFLUSH);
+    if (status < 0) {
+       error("tcflush");
+       close(fd);
+       return -1;
+    }
+
+    /* get current terminal state */
+    tcgetattr(fd, &newtio);
+
+    /* set to raw terminal type */
+    newtio.c_cflag = baud | CS8 | CLOCAL | CREAD;
+    newtio.c_iflag = IGNBRK | IGNPAR;
+    newtio.c_oflag = 0;
+
+    /* control parameters */
+    newtio.c_cc[VMIN] = 1;     /* block for at least one charater */
+
+    /* set its new attrigutes */
+    status = tcsetattr(fd, TCSANOW, &newtio);
+    if (status < 0) {
+       error("tcsetattr() failed: %s", strerror(errno));
+       close(fd);
+       fd = -1;
+       return fd;
+    }
+    return fd;
+}
+
+
+
+static void printGps(nmeap_gga_t * gga, nmeap_rmc_t * rmc)
+{
+    float myCourse = rmc->course;      /* I assume 0 degree = North */
+
+    char courses[8][3] = { "N ", "NO", "O ", "SO", "S ", "SW", "W ", "NW" };
+    float degrees[8] = { 22.5f, 67.5f, 112.5f, 157.5f, 202.5f, 247.5f, 292.5f, 337.5f };
+    int selectedDegree = 0;
+    int n;
+
+    for (n = 0; n < 8; n++) {
+       if (myCourse < degrees[n]) {
+           selectedDegree = n;
+           break;
+       }
+    }
+
+    debug("alt:%.0f speed:%.0f course:%s sat:%d quali:%d, warn:%c\n", gga->altitude, rmc->speed * 1.852f,      /* knots -> km/h */
+         courses[selectedDegree], gga->satellites, gga->quality, rmc->warn     /* A=active or V=Void */
+       );
+
+}
+
+
+/*
+#define SHOW_ALTITUDE  0x0000001
+#define SHOW_SPEED     0x0000010
+#define SHOW_COURSE    0x0000100
+#define SHOW_SATELLITES 0x0001000
+#define SHOW_QUALITY   0x0010000
+#define SHOW_WARN      0x0100000
+*/
+
+static void parse(RESULT * result, RESULT * theOptions)
+{
+    char *value = " ";
+    int finito = 0;
+
+    int rem;
+    int offset;
+    int status;
+    int len;
+    int lame;
+    long options;
+    char buffer[32];
+
+    options = R2N(theOptions);
+    if (options & SHOW_ALTITUDE)
+
+       while (finito == 0) {
+
+           /* ---------------------------------------- */
+           /* STEP 6 : get a buffer of input          */
+           /* --------------------------------------- */
+           len = rem = read(fd, buffer, sizeof(buffer));
+           if (len <= 0) {
+               error("GPS Plugin, Error read from port");
+               break;
+           }
+
+           /* ---------------------------------------------- */
+           /* STEP 7 : process input until buffer is used up */
+           /* ---------------------------------------------- */
+
+           offset = 0;
+           lame = 0;
+
+           while (rem > 0) {
+               status = nmeap_parseBuffer(&nmea, &buffer[offset], &rem);
+               offset += (len - rem);
+
+               switch (status) {
+               case NMEAP_GPGGA:
+                   /* GOT A GPGGA MESSAGE */
+                   lame++;
+                   break;
+               case NMEAP_GPRMC:
+                   /* GOT A GPRMC MESSAGE */
+                   lame++;
+                   break;
+               default:
+                   debug("unhandled status: %d", status);
+                   break;
+               }
+               if (lame > 1) {
+                   finito = 1;
+                   printGps(&gga, &rmc);
+               }
+           }
+
+       }
+
+
+    /* store result */
+    SetResult(&result, R_STRING, value);
+
+    free(value);
+}
+
+
+
+/* plugin initialization */
+/* MUST NOT be declared 'static'! */
+int plugin_init_gps(void)
+{
+    int fd;
+    int status;
+    char *port = "/dev/usb/tty/1";
+    char *test;
+
+    if ((test = getenv("GPS_PORT"))) { /* define your port via env variable */
+       port = test;
+    }
+
+
+    /* --------------------------------------- */
+    /* open the serial port device             */
+    /* using default 4800 baud for most GPS    */
+    /* --------------------------------------- */
+    fd = openPort(port, B4800);
+    if (fd < 0) {
+       /* open failed */
+       error("GPS PLUGIN, Error: openPort %d", fd);
+       return fd;
+    }
+
+    /* --------------------------------------- */
+    /*STEP 2 : initialize the nmea context    */
+    /* --------------------------------------- */
+    status = nmeap_init(&nmea, (void *) &user_data);
+    if (status != 0) {
+       error("GPS PLUGIN, Error: nmeap_init %d", status);
+       exit(1);
+    }
+
+    /* --------------------------------------- */
+    /*STEP 3 : add standard GPGGA parser      */
+    /* -------------------------------------- */
+    status = nmeap_addParser(&nmea, "GPGGA", nmeap_gpgga, 0, &gga);
+    if (status != 0) {
+       error("GPS PLUGIN, Error: nmeap_add GPGGA parser, error:%d", status);
+       return -1;
+    }
+
+    /* --------------------------------------- */
+    /*STEP 4 : add standard GPRMC parser      */
+    /* -------------------------------------- */
+    /* status = nmeap_addParser(&nmea,"GPRMC",nmeap_gprmc,gprmc_callout,&rmc); */
+    status = nmeap_addParser(&nmea, "GPRMC", nmeap_gprmc, 0, &rmc);
+    if (status != 0) {
+       error("GPS PLUGIN, Error: nmeap_add GPRMC parser, error:%d", status);
+       return -1;
+    }
+
+
+    /* register all our cool functions */
+    /* the second parameter is the number of arguments */
+    /* -1 stands for variable argument list */
+    AddFunction("gps::parse", 0, parse);
+
+    return 0;
+}
+
+void plugin_exit_gps(void)
+{
+    /* close the serial port */
+    close(fd);
+
+}
index f1d157f54026a428f70123ff880d4ae015877b54..c6a3bfa020cd8b9ad637420f6c34c0cd5789eed6 100644 (file)
@@ -59,6 +59,7 @@ for plugin in $plugins; do
          PLUGIN_DVB="yes"
          PLUGIN_EXEC="yes"
          PLUGIN_FILE="yes"
+         PLUGIN_GPS="yes"
          PLUGIN_I2C_SENSORS="yes"
          PLUGIN_ICONV="yes"
          PLUGIN_IMON="yes"
@@ -99,6 +100,9 @@ for plugin in $plugins; do
       file)
          PLUGIN_FILE=$val
          ;;
+      gps)
+         PLUGIN_GPS=$val
+         ;;
       i2c_sensors)
          PLUGIN_I2C_SENSORS=$val
         ;;
@@ -199,6 +203,21 @@ if test "$PLUGIN_FILE" = "yes"; then
    PLUGINS="$PLUGINS plugin_file.o"
    AC_DEFINE(PLUGIN_FILE,1,[file plugin])
 fi
+if test "$PLUGIN_GPS" = "yes"; then
+   AC_CHECK_HEADERS(nmeap.h, [has_nmeap_header="true"], [has_nmeap_header="false"])
+   if test "$has_nmeap_header" = "true"; then  
+      AC_CHECK_LIB(nmeap, nmeap_init, [has_libnmeap_lib="true"], [has_libnmeap_lib="false"])
+      if test "$has_libnmeap_lib" = "true"; then
+        PLUGINS="$PLUGINS plugin_gps.o"
+        PLUGINLIBS="$PLUGINLIBS -lnmeap"
+        AC_DEFINE(PLUGIN_GPS,1,[gps plugin])
+      else
+        AC_MSG_WARN(libnmeap lib not found: gps plugin disabled)
+      fi
+   else
+      AC_MSG_WARN(nmeap.h header not found: gps plugin disabled)
+   fi 
+fi
 if test "$PLUGIN_I2C_SENSORS" = "yes"; then
    PLUGINS="$PLUGINS plugin_i2c_sensors.o"
    AC_DEFINE(PLUGIN_I2C_SENSORS,1,[i2c sensors plugin])