summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJames Maki <jmaki@multitech.com>2010-04-23 12:32:53 -0500
committerJames Maki <jmaki@multitech.com>2010-04-23 12:32:53 -0500
commit5450acde53db80f453a658f59ab887212680ca34 (patch)
treec67ba88c2d9e5a4fcf84919ea607214618614bd5 /src
downloadvenus-gps-5450acde53db80f453a658f59ab887212680ca34.tar.gz
venus-gps-5450acde53db80f453a658f59ab887212680ca34.tar.bz2
venus-gps-5450acde53db80f453a658f59ab887212680ca34.zip
initial commit
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am8
-rw-r--r--src/Makefile.in417
-rw-r--r--src/cbuffer.c107
-rw-r--r--src/cbuffer.h22
-rwxr-xr-xsrc/gps_test.rb43
-rw-r--r--src/log.h32
-rw-r--r--src/utils.c217
-rw-r--r--src/utils.h27
-rw-r--r--src/venus_api.c487
-rw-r--r--src/venus_api.h98
-rw-r--r--src/venus_gps.c631
-rw-r--r--src/venus_gps.h6
12 files changed, 2095 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..b9e40b1
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,8 @@
+AUTOMAKE_OPTIONS = gnu
+AM_CFLAGS = -Wall
+bin_PROGRAMS = venus-gps
+venus_gps_SOURCES = venus_gps.c cbuffer.c utils.c venus_api.c
+noinst_HEADERS = venus_gps.h cbuffer.h log.h utils.h venus_api.h
+
+EXTRA_DIST =
+
diff --git a/src/Makefile.in b/src/Makefile.in
new file mode 100644
index 0000000..599b96a
--- /dev/null
+++ b/src/Makefile.in
@@ -0,0 +1,417 @@
+# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+bin_PROGRAMS = venus-gps$(EXEEXT)
+subdir = src
+DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
+ $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+am__installdirs = "$(DESTDIR)$(bindir)"
+binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
+PROGRAMS = $(bin_PROGRAMS)
+am_venus_gps_OBJECTS = venus_gps.$(OBJEXT) cbuffer.$(OBJEXT) \
+ utils.$(OBJEXT) venus_api.$(OBJEXT)
+venus_gps_OBJECTS = $(am_venus_gps_OBJECTS)
+venus_gps_LDADD = $(LDADD)
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(venus_gps_SOURCES)
+DIST_SOURCES = $(venus_gps_SOURCES)
+HEADERS = $(noinst_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build_alias = @build_alias@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host_alias = @host_alias@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AUTOMAKE_OPTIONS = gnu
+AM_CFLAGS = -Wall
+venus_gps_SOURCES = venus_gps.c cbuffer.c utils.c venus_api.c
+noinst_HEADERS = venus_gps.h cbuffer.h log.h utils.h venus_api.h
+EXTRA_DIST =
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu src/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+install-binPROGRAMS: $(bin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
+ if test -f $$p \
+ ; then \
+ f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
+ echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
+ $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
+ else :; fi; \
+ done
+
+uninstall-binPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
+ echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
+ rm -f "$(DESTDIR)$(bindir)/$$f"; \
+ done
+
+clean-binPROGRAMS:
+ -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
+venus-gps$(EXEEXT): $(venus_gps_OBJECTS) $(venus_gps_DEPENDENCIES)
+ @rm -f venus-gps$(EXEEXT)
+ $(LINK) $(venus_gps_OBJECTS) $(venus_gps_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cbuffer.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/venus_api.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/venus_gps.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS) $(HEADERS)
+installdirs:
+ for dir in "$(DESTDIR)$(bindir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-binPROGRAMS clean-generic mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-exec-am: install-binPROGRAMS
+
+install-html: install-html-am
+
+install-info: install-info-am
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-ps: install-ps-am
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-binPROGRAMS
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
+ clean-generic ctags distclean distclean-compile \
+ distclean-generic distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-binPROGRAMS \
+ install-data install-data-am install-dvi install-dvi-am \
+ install-exec install-exec-am install-html install-html-am \
+ install-info install-info-am install-man install-pdf \
+ install-pdf-am install-ps install-ps-am install-strip \
+ installcheck installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \
+ uninstall-am uninstall-binPROGRAMS
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/cbuffer.c b/src/cbuffer.c
new file mode 100644
index 0000000..1242496
--- /dev/null
+++ b/src/cbuffer.c
@@ -0,0 +1,107 @@
+/*
+ * Venus GPS Server
+ *
+ * Copyright (C) 2010 by Multi-Tech Systems
+ *
+ * Author: James Maki <jmaki@multitech.com>
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#include "log.h"
+#include "cbuffer.h"
+#include "utils.h"
+#include <errno.h>
+
+int buffered_write(int fd, struct cbuffer *buf) {
+ int i;
+ int len;
+ int count = buffer_used(buf);
+ int total = 0;
+
+ i = buf->read_index;
+ if(i + count > buffer_size(buf)) {
+ len = full_write(fd, buf->buffer + i, buffer_size(buf) - i);
+ if(len <= 0) {
+ log_error("full_write failed errno: %d", errno);
+ return len;
+ }
+
+ total += len;
+ count -= len;
+
+ if(len < buffer_size(buf) - i) {
+ buf->read_index = i + len;
+ return total;
+ }
+
+ i = 0;
+ }
+
+ len = full_write(fd, buf->buffer + i, count);
+ if(len <= 0) {
+ if(total) {
+ return total;
+ } else {
+ log_error("full_write failed errno: %d", errno);
+ return len;
+ }
+ }
+ buf->read_index = i + len;
+ total += len;
+
+ return total;
+}
+
+int buffered_read(int fd, struct cbuffer *buf) {
+ int i;
+ int len;
+ int count = buffer_free(buf);
+ int total = 0;
+
+ i = buf->write_index;
+ if(i + count > buffer_size(buf)) {
+ len = safe_read(fd, buf->buffer + i, buffer_size(buf) - i);
+ if(len <= 0) {
+ log_warning("safe_read failed errno: %d", errno);
+ return len;
+ }
+
+ total += len;
+ count -= len;
+
+ if(len < buffer_size(buf) - i) {
+ buf->write_index = i + len;
+ return total;
+ }
+
+ i = 0;
+ }
+
+ len = safe_read(fd, buf->buffer + i, count);
+ if(len <= 0) {
+ if(total) {
+ return total;
+ } else {
+ log_warning("safe_read failed errno: %d", errno);
+ return len;
+ }
+ }
+ buf->write_index = i + len;
+ total += len;
+
+ return total;
+}
+
diff --git a/src/cbuffer.h b/src/cbuffer.h
new file mode 100644
index 0000000..5fc2de0
--- /dev/null
+++ b/src/cbuffer.h
@@ -0,0 +1,22 @@
+#include <stdint.h>
+
+#ifndef __CBUFFER_H
+#define __CBUFFER_H
+
+struct cbuffer {
+ uint8_t buffer[1 << 10];
+ int read_index;
+ int write_index;
+};
+
+#define buffer_size(buf) (sizeof((buf)->buffer))
+#define buffer_used(buf) (((buf)->write_index - (buf)->read_index) & (buffer_size(buf) - 1))
+#define buffer_free(buf) (buffer_size(buf) - 1 - buffer_used(buf))
+
+int buffered_write(int fd, struct cbuffer *buf);
+int buffered_read(int fd, struct cbuffer *buf);
+
+#define DIR_REV(i) ((i == 1) ? 0 : 1)
+
+#endif /* ~__CBUFFER_H */
+
diff --git a/src/gps_test.rb b/src/gps_test.rb
new file mode 100755
index 0000000..4f35ec5
--- /dev/null
+++ b/src/gps_test.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby1.8
+
+require 'socket'
+
+GPS_SERVER_IP = "192.168.2.1"
+GPS_SERVER_PORT = 5445
+MODE = :client
+PROTOCOL = :tcp
+
+def tcp_read(sock)
+ loop {
+ data = sock.readline()
+ puts data.inspect
+ }
+end
+
+if PROTOCOL == :tcp
+ if MODE == :client
+ sock = TCPSocket.new(GPS_SERVER_IP, GPS_SERVER_PORT)
+ tcp_read(sock)
+ sock.close
+ else
+ serv = TCPServer.new(GPS_SERVER_PORT)
+ sock = serv.accept
+ tcp_read(sock)
+ sock.close
+ end
+elsif PROTOCOL == :udp
+ sock = UDPSocket.new
+ sock.bind('0.0.0.0', GPS_SERVER_PORT)
+
+ loop {
+ begin
+ msg, sender = sock.recvfrom(1024)
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK => e
+ puts "recvfrom error: #{e.class}: #{e}"
+ next
+ end
+ puts msg.inspect
+ }
+end
+
+
diff --git a/src/log.h b/src/log.h
new file mode 100644
index 0000000..5f0eceb
--- /dev/null
+++ b/src/log.h
@@ -0,0 +1,32 @@
+#ifndef __LOG_H
+#define __LOG_H
+
+#include "config.h"
+
+#if CONFIG_USE_SYSLOG
+# include <syslog.h>
+# define LOG_FACILITY LOG_USER
+
+# define __log(level, name, format, args...) \
+ syslog(LOG_FACILITY | level, "[" name "] %s:%s:%d: " format "\n" , \
+ __FILE__ , __func__ , __LINE__ , ## args)
+#else
+# define __log(level, name, format, args...) \
+ fprintf(stderr, "[" name "] %s:%s:%d: " format "\n" , \
+ __FILE__ , __func__ , __LINE__ , ## args)
+#endif
+
+#define log_emerg(format, args...) __log(LOG_EMERG, "EMERG", format , ## args)
+#define log_alert(format, args...) __log(LOG_ALERT, "ALERT", format , ## args)
+#define log_crit(format, args...) __log(LOG_CRIT, "CRIT", format , ## args)
+#define log_error(format, args...) __log(LOG_ERR, "ERROR", format , ## args)
+#define log_warning(format, args...) __log(LOG_WARNING, "WARNING", format , ## args)
+#define log_notice(format, args...) __log(LOG_NOTICE, "NOTICE", format , ## args)
+#define log_info(format, args...) __log(LOG_INFO, "INFO", format , ## args)
+#if DEBUG
+# define log_debug(format, args...) __log(LOG_DEBUG, "DEBUG", format , ## args)
+#else
+# define log_debug(format, args...) do {} while (0)
+#endif
+
+#endif /* ~__LOG_H */
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..6f98ab0
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,217 @@
+/*
+ * Venus GPS Server
+ *
+ * Copyright (C) 2010 by Multi-Tech Systems
+ * Copyright (C) 2004-2009 by James Maki
+ *
+ * Author: James Maki <jmaki@multitech.com>
+ *
+ * safe_read, safe_write, full_write are from Busybox
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#define _GNU_SOURCE
+
+#include <string.h>
+#include <netdb.h>
+#include <fcntl.h>
+
+#include "log.h"
+#include "utils.h"
+
+int systemf(const char *fmt, ...) {
+ int err;
+ va_list ap;
+ char *buf;
+
+ va_start(ap, fmt);
+ err = vasprintf(&buf, fmt, ap);
+ va_end(ap);
+ if(err == -1) {
+ log_error("out of memory");
+ return -1;
+ }
+
+ log_debug("%s", buf);
+
+ err = system(buf);
+ free(buf);
+
+ return err;
+}
+
+ssize_t safe_read(int fd, void *buf, size_t count) {
+ ssize_t n;
+
+ do {
+ n = read(fd, buf, count);
+ } while(n < 0 && errno == EINTR);
+
+ return n;
+}
+
+ssize_t safe_readn(int fd, void *buf, size_t len) {
+ ssize_t cc;
+ ssize_t total;
+
+ total = 0;
+
+ while(len) {
+ cc = safe_read(fd, buf, len);
+
+ if(cc < 0) {
+ if(total) {
+ return total;
+ }
+ return cc;
+ }
+
+ total += cc;
+ buf = buf + cc;
+ len -= cc;
+ }
+
+ return total;
+}
+
+ssize_t safe_write(int fd, const void *buf, size_t count) {
+ ssize_t n;
+
+ do {
+ n = write(fd, buf, count);
+ } while(n < 0 && errno == EINTR);
+
+ return n;
+}
+
+ssize_t full_write(int fd, const void *buf, size_t len) {
+ ssize_t cc;
+ ssize_t total;
+
+ total = 0;
+
+ while(len) {
+ cc = safe_write(fd, buf, len);
+
+ if(cc < 0) {
+ if(total) {
+ return total;
+ }
+ return cc;
+ }
+
+ total += cc;
+ buf = ((const char *)buf) + cc;
+ len -= cc;
+ }
+
+ return total;
+}
+
+int set_nonblocking(int fd) {
+ int err;
+
+ err = fcntl(fd, F_GETFL, 0);
+ if(err < 0) {
+ log_warning("fcntl(fd, F_GETFL, 0) failed: errno %d", errno);
+ return err;
+ }
+ err = fcntl(fd, F_SETFL, err | O_NONBLOCK);
+ if(err < 0) {
+ log_warning("fcntl(fd, F_SETFL, opts | O_NONBLOCK) failed: errno %d", errno);
+ return err;
+ }
+
+ return err;
+}
+
+int host_to_inet(const char *host, struct in_addr *in) {
+ struct hostent h;
+ struct hostent *hp;
+ char buf[1024];
+ int herrno;
+ int err;
+
+ err = gethostbyname_r(host, &h, buf, sizeof(buf), &hp, &herrno);
+ if(hp == NULL) {
+ log_error("gethostbyname_r: %d", herrno);
+ return -1;
+ }
+
+ memcpy(&in->s_addr, h.h_addr_list[0], 4);
+
+ return 0;
+}
+
+int inet_conn_str(char *host, int port, int type) {
+ struct hostent h;
+ struct hostent *hp;
+ char buf[1024];
+ int herrno;
+ int err;
+
+ err = gethostbyname_r(host, &h, buf, sizeof(buf), &hp, &herrno);
+ if(hp == NULL) {
+ log_error("gethostbyname_r: %d", herrno);
+ return -1;
+ }
+
+ int sd = socket(PF_INET, type, 0);
+ if(sd == -1) {
+ log_error("socket: %d", errno);
+ return -1;
+ }
+
+ struct sockaddr_in serv_addr;
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_port = htons(port);
+ memcpy(&serv_addr.sin_addr.s_addr, h.h_addr_list[0], 4);
+
+ err = connect(sd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
+ if(err == -1) {
+ log_error("connect: %d", errno);
+ close(sd);
+ return -1;
+ }
+
+ return sd;
+}
+
+int inet_conn_ia(struct in_addr *host, int port, int type) {
+ int err;
+
+ int sd = socket(PF_INET, type, 0);
+ if(sd == -1) {
+ log_error("socket: %d", errno);
+ return -1;
+ }
+
+ struct sockaddr_in serv_addr;
+ memset(&serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_port = htons(port);
+ serv_addr.sin_addr.s_addr = host->s_addr;
+
+ err = connect(sd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
+ if(err == -1) {
+ log_error("connect: %d", errno);
+ close(sd);
+ return -1;
+ }
+
+ return sd;
+}
+
diff --git a/src/utils.h b/src/utils.h
new file mode 100644
index 0000000..71d3e9c
--- /dev/null
+++ b/src/utils.h
@@ -0,0 +1,27 @@
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <errno.h>
+#include <arpa/inet.h>
+
+#ifndef __UTILS_H
+#define __UTILS_H
+
+#define match(a, b) (!strcmp(a, b))
+#define matchn(a, b, n) (!strncmp(a, b, n))
+
+int host_to_inet(const char *host, struct in_addr *in);
+int systemf(const char *fmt, ...);
+ssize_t safe_read(int fd, void *buf, size_t count);
+ssize_t safe_readn(int fd, void *buf, size_t len);
+ssize_t safe_write(int fd, const void *buf, size_t count);
+ssize_t full_write(int fd, const void *buf, size_t len);
+int set_nonblocking(int fd);
+int inet_conn_str(char *host, int port, int type);
+int inet_conn_ia(struct in_addr *host, int port, int type);
+
+#endif /* ~__UTILS_H */
diff --git a/src/venus_api.c b/src/venus_api.c
new file mode 100644
index 0000000..52a4a96
--- /dev/null
+++ b/src/venus_api.c
@@ -0,0 +1,487 @@
+/*
+ * SkyTraq Venus 5 GPS API
+ *
+ * Copyright (C) 2010 by Multi-Tech Systems
+ *
+ * Author: James Maki <jmaki@multitech.com>
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <time.h>
+#include <asm/byteorder.h>
+#include <netdb.h>
+
+#include "log.h"
+#include "cbuffer.h"
+#include "utils.h"
+#include "venus_api.h"
+
+static const struct baud_map __baud_map[] = {
+ {B4800, 4800},
+ {B9600, 9600},
+ {B19200, 19200},
+ {B38400, 38400},
+ {B57600, 57600},
+ {B115200, 115200},
+};
+
+static const struct baud_map __venus_baud_map[] = {
+ {B4800, VENUS_4800},
+ {B9600, VENUS_9600},
+ {B19200, VENUS_19200},
+ {B38400, VENUS_38400},
+ {B57600, VENUS_57600},
+ {B115200, VENUS_115200},
+};
+
+speed_t value_to_baud(speed_t value) {
+ int n = sizeof(__baud_map) / sizeof(struct baud_map);
+ int i;
+
+ for(i = 0; i < n; ++i) {
+ if(__baud_map[i].value == value) {
+ return __baud_map[i].baud;
+ }
+ }
+
+ log_warning("baud rate not valid: %lu", (unsigned long) value);
+
+ return (speed_t) -1;
+}
+
+speed_t baud_to_venus(speed_t baud) {
+ int n = sizeof(__venus_baud_map) / sizeof(struct baud_map);
+ int i;
+
+ for(i = 0; i < n; ++i) {
+ if(__venus_baud_map[i].baud == baud) {
+ return __venus_baud_map[i].value;
+ }
+ }
+
+ log_warning("baud rate not valid: %lu", (unsigned long) baud);
+
+ return (speed_t) -1;
+}
+
+static uint8_t seq_start[] = {0xA0, 0xA1};
+static uint8_t seq_end[] = {0x0D, 0x0A};
+
+void free_venus_msg_data(struct venus_msg *msg) {
+ if(!msg) {
+ return;
+ }
+
+ if(msg->data) {
+ free(msg->data);
+ }
+ msg->data = NULL;
+}
+
+uint8_t checksum(void *data, uint16_t len) {
+ int i;
+ uint8_t cs = 0;
+
+ for(i = 0; i < len; i++) {
+ cs ^= ((char *) data)[i];
+ }
+
+ return cs;
+}
+
+int venus_write_msg(int fd, struct venus_msg *msg) {
+ int err;
+ uint8_t cs = 0;
+
+ log_debug("id: %d", msg->data[0]);
+
+ err = full_write(fd, seq_start, sizeof(seq_start));
+ if(err != sizeof(seq_start)) {
+ log_error("failed to write seq_start: %d %d", err, errno);
+ }
+ msg->len = __cpu_to_be16(msg->len);
+ err = full_write(fd, &msg->len, 2);
+ if(err != 2) {
+ log_error("failed to write len: %d %d", err, errno);
+ }
+ msg->len = __be16_to_cpu(msg->len);
+ err = full_write(fd, msg->data, msg->len);
+ if(err != msg->len) {
+ log_error("failed to write data: %d %d", err, errno);
+ }
+ cs = checksum(msg->data, msg->len);
+ err = full_write(fd, &cs, 1);
+ if(err != 1) {
+ log_error("failed to write checksum: %d %d", err, errno);
+ }
+ err = full_write(fd, seq_end, sizeof(seq_end));
+ if(err != sizeof(seq_end)) {
+ log_error("failed to write seq_end: %d %d", err, errno);
+ }
+
+ return 0;
+}
+
+int venus_read_msg(int fd, struct venus_msg *msg) {
+ uint8_t cs;
+ uint8_t *data;
+ uint16_t len;
+ uint8_t seq[2];
+ int attempts = 0;
+
+again:
+ while(1) {
+ safe_readn(fd, seq, 2);
+ //log_error("start seq %c %c", seq[0], seq[1]);
+ if(!memcmp(seq, seq_start, 2)) {
+ break;
+ }
+ attempts++;
+ if(attempts > 1024) {
+ log_error("max attempts reached");
+ return -1;
+ }
+ }
+
+ safe_readn(fd, &len, 2);
+ len = __be16_to_cpu(len);
+ data = malloc(len);
+ safe_readn(fd, data, len);
+ safe_readn(fd, &cs, 1);
+ if(checksum(data, len) != cs) {
+ log_error("checksum mismatch");
+ return -1;
+ }
+ safe_readn(fd, seq, 2);
+ if(memcmp(seq, seq_end, 2)) {
+ log_error("expected seq end");
+ return -1;
+ }
+
+ if(len == 2 && data[0] == ID_ACK && data[1] == ID_NONE) {
+ log_debug("read ACK ID_NONE");
+ free(data);
+ goto again;
+ }
+
+ msg->data = data;
+ msg->len = len;