r4409 - in developers/alphaone/u-blox: . libubx libubx/include libubx/src

alphaone at docs.openmoko.org alphaone at docs.openmoko.org
Tue Apr 29 22:52:56 CEST 2008


Author: alphaone
Date: 2008-04-29 22:52:55 +0200 (Tue, 29 Apr 2008)
New Revision: 4409

Added:
   developers/alphaone/u-blox/libubx/
   developers/alphaone/u-blox/libubx/AUTHORS
   developers/alphaone/u-blox/libubx/ChangeLog
   developers/alphaone/u-blox/libubx/Makefile.am
   developers/alphaone/u-blox/libubx/NEWS
   developers/alphaone/u-blox/libubx/README
   developers/alphaone/u-blox/libubx/autogen.sh
   developers/alphaone/u-blox/libubx/configure.in
   developers/alphaone/u-blox/libubx/include/
   developers/alphaone/u-blox/libubx/include/Makefile.am
   developers/alphaone/u-blox/libubx/include/libubx.h
   developers/alphaone/u-blox/libubx/libubx.pc.in
   developers/alphaone/u-blox/libubx/src/
   developers/alphaone/u-blox/libubx/src/Makefile.am
   developers/alphaone/u-blox/libubx/src/libubx.c
   developers/alphaone/u-blox/libubx/src/ubx-parse.c
   developers/alphaone/u-blox/libubx/src/ubx-parse.h
Log:
* Started working on libubx, a library to generate and parse UBX packets


Added: developers/alphaone/u-blox/libubx/AUTHORS
===================================================================
--- developers/alphaone/u-blox/libubx/AUTHORS	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/AUTHORS	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1 @@
+Daniel Willmann <daniel at openmoko.org>

Added: developers/alphaone/u-blox/libubx/ChangeLog
===================================================================
--- developers/alphaone/u-blox/libubx/ChangeLog	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/ChangeLog	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1,3 @@
+2008-04-29	Daniel Willmann <daniel at openmoko.org>
+
+	* *: Start libubx, a library to generate and parse UBX packets

Added: developers/alphaone/u-blox/libubx/Makefile.am
===================================================================
--- developers/alphaone/u-blox/libubx/Makefile.am	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/Makefile.am	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1,7 @@
+SUBDIRS =				\
+	include				\
+	src
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libubx.pc
+

Added: developers/alphaone/u-blox/libubx/NEWS
===================================================================

Added: developers/alphaone/u-blox/libubx/README
===================================================================

Added: developers/alphaone/u-blox/libubx/autogen.sh
===================================================================
--- developers/alphaone/u-blox/libubx/autogen.sh	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/autogen.sh	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1,9 @@
+#!/bin/sh
+set -x
+
+aclocal
+libtoolize --force
+autoheader
+automake --add-missing
+autoconf configure.in > configure
+chmod +x configure


Property changes on: developers/alphaone/u-blox/libubx/autogen.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: developers/alphaone/u-blox/libubx/configure.in
===================================================================
--- developers/alphaone/u-blox/libubx/configure.in	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/configure.in	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1,43 @@
+AC_PREREQ(2.52)
+
+AC_INIT(libubx, 0.1, daniel at openmoko.org)
+AM_INIT_AUTOMAKE([subdir-objects])
+AM_MAINTAINER_MODE
+
+AM_CONFIG_HEADER(config.h)
+
+dnl
+dnl Require programs
+dnl
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_PROG_INSTALL
+AC_PROG_LIBTOOL
+
+dnl
+dnl Required headers
+dnl
+AC_HEADER_STDC
+
+dnl
+dnl Checks for typedefs, structures, and compiler characteristics.
+dnl
+AC_HEADER_TIME
+
+dnl
+dnl Checks for library functions.
+dnl
+
+dnl
+dnl Make sha1.c happy on big endian systems
+dnl
+AC_C_BIGENDIAN
+
+CFLAGS="-Wall $CFLAGS"
+
+AC_OUTPUT([
+Makefile
+libubx.pc
+include/Makefile
+src/Makefile
+])

Added: developers/alphaone/u-blox/libubx/include/Makefile.am
===================================================================
--- developers/alphaone/u-blox/libubx/include/Makefile.am	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/include/Makefile.am	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1,5 @@
+libubxinclude_HEADERS = \
+												libubx.h
+libubxincludedir = $(includedir)/libubx
+
+#libdiversity_xmpp_backend_la_LIBADD =

Added: developers/alphaone/u-blox/libubx/include/libubx.h
===================================================================
--- developers/alphaone/u-blox/libubx/include/libubx.h	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/include/libubx.h	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1,97 @@
+#ifndef _LIBUBX_H_
+#define _LIBUBX_H_
+
+#include <stdint.h>
+
+#define UBX_SYNC1 0xb5
+#define UBX_SYNC2 0x62
+
+typedef enum {
+	UBX_CL_NAV = 0x01,
+	UBX_CL_RXM = 0x02,
+	UBX_CL_INF = 0x04,
+	UBX_CL_ACK = 0x05,
+	UBX_CL_CFG = 0x06,
+	UBX_CL_UPD = 0x09,
+	UBX_CL_MON = 0x0a,
+	UBX_CL_AID = 0x0b,
+	UBX_CL_TIM = 0x0d,
+	UBX_CL_USR = 0x40
+} ubx_class;
+
+typedef enum {
+	UBX_ID_ACK = 0x01,
+	UBX_ID_NACK = 0x00,
+	UBX_ID_ALM = 0x30,
+	UBX_ID_DATA = 0x10,
+	UBX_ID_EPH = 0x31,
+	UBX_ID_HUI = 0x02,
+	UBX_ID_INI = 0x01,
+	UBX_ID_REQ = 0x00,
+	UBX_ID_ANT = 0x13,
+	UBX_ID_CFG = 0x09
+} ubx_id;
+
+typedef struct {
+	uint8_t cls;
+	uint8_t id;
+	uint16_t length;
+	uint8_t ck_a;
+	uint8_t ck_b;
+} ubx_hdr;
+
+typedef struct {
+	ubx_hdr *header;
+	void *payload;
+} ubx_msg;
+
+typedef struct {
+	uint32_t svid;
+	uint32_t week;
+	uint32_t dwrd0;
+	uint32_t dwrd1;
+	uint32_t dwrd2;
+	uint32_t dwrd3;
+	uint32_t dwrd4;
+	uint32_t dwrd5;
+	uint32_t dwrd6;
+	uint32_t dwrd7;
+} ubx_msg_aid_alm;
+
+typedef struct {
+	uint32_t svid;
+	uint32_t how;
+	uint32_t sf1d0;
+	uint32_t sf1d1;
+	uint32_t sf1d2;
+	uint32_t sf1d3;
+	uint32_t sf1d4;
+	uint32_t sf1d5;
+	uint32_t sf1d6;
+	uint32_t sf1d7;
+	uint32_t sf2d0;
+	uint32_t sf2d1;
+	uint32_t sf2d2;
+	uint32_t sf2d3;
+	uint32_t sf2d4;
+	uint32_t sf2d5;
+	uint32_t sf2d6;
+	uint32_t sf2d7;
+	uint32_t sf3d0;
+	uint32_t sf3d1;
+	uint32_t sf3d2;
+	uint32_t sf3d3;
+	uint32_t sf3d4;
+	uint32_t sf3d5;
+	uint32_t sf3d6;
+	uint32_t sf3d7;
+} ubx_msg_aid_eph;
+
+/*m Returns 1 if the checksum matches, otherwise zero
+ * If the checksum fields are both zero calculates it */
+uint8_t checksum(ubx_hdr *header, uint8_t *msg);
+
+uint16_t ubx_msg_encode(ubx_hdr *header, uint8_t *msg, uint8_t **data);
+ubx_msg *ubx_msg_decode(uint16_t length, uint8_t *data);
+
+#endif /* _LIBUBX_H_ */

Added: developers/alphaone/u-blox/libubx/libubx.pc.in
===================================================================
--- developers/alphaone/u-blox/libubx/libubx.pc.in	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/libubx.pc.in	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libubx
+Description: libubx
+Requires:
+Version: @VERSION@
+Libs: -L${libdir} -lubx
+Cflags: -I${includedir}/libubx

Added: developers/alphaone/u-blox/libubx/src/Makefile.am
===================================================================
--- developers/alphaone/u-blox/libubx/src/Makefile.am	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/src/Makefile.am	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1,9 @@
+INCLUDES = -I${top_srcdir}/include
+
+lib_LTLIBRARIES = libubx.la
+
+libubx_la_SOURCES =	\
+	libubx.c \
+	ubx-parse.c
+
+#libdiversity_xmpp_backend_la_LIBADD =

Added: developers/alphaone/u-blox/libubx/src/libubx.c
===================================================================
--- developers/alphaone/u-blox/libubx/src/libubx.c	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/src/libubx.c	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1,90 @@
+#include <libubx.h>
+#include "ubx-parse.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/* Returns 1 if the checksum matches, otherwise zero
+ * If the checksum fields are both zero calculates it */
+uint8_t checksum(ubx_hdr *header, uint8_t *msg)
+{
+	uint8_t ck_a = 0, ck_b = 0;
+	uint16_t *len = &header->length;
+
+	ck_a += header->cls;
+	ck_b += ck_a;
+	ck_a += header->id;
+	ck_b += ck_a;
+	ck_a += ((uint8_t *)len)[0];
+	ck_b += ck_a;
+	ck_a += ((uint8_t *)len)[1];
+	ck_b += ck_a;
+
+	if ((ck_a == header->ck_a)&&(ck_b == header->ck_b)) {
+		return 1;
+	}
+	else if ((header->ck_a == 0)&&(header->ck_b == 0)) {
+		header->ck_a = ck_a;
+		header->ck_b = ck_b;
+	}
+	return 0;
+}
+
+uint16_t ubx_msg_encode(ubx_hdr *header, uint8_t *msg, uint8_t **data)
+{
+	uint8_t *temp;
+	*data = malloc(header->length + 8);
+	if (!*data)
+		return 0;
+
+	checksum(header, *data);
+	temp = *data;
+	*temp++ = UBX_SYNC1;
+	*temp++ = UBX_SYNC2;
+	// Copy the header
+	// XXX: Handle Endianess
+	memcpy(temp, header, 4);
+	temp += 4;
+	// And the message
+	memcpy(temp, msg, header->length);
+	temp += header->length;
+	*temp++ = header->ck_a;
+	*temp++ = header->ck_b;
+	return header->length + 8;
+}
+
+ubx_msg *ubx_msg_decode(uint16_t length, uint8_t *data)
+{
+	ubx_hdr *header;
+	ubx_msg *msg;
+
+	if ((data[0] != UBX_SYNC1) || (data[1] != UBX_SYNC2)
+			|| (length < 8))
+		return 0;
+
+	data += 2;
+	header = malloc(sizeof(ubx_hdr));
+	header->cls = *data++;
+	header->id = *data++;
+	header->length = (uint16_t)*data;
+	data += 2;
+
+	if (length < header->length + 8)
+		return 0;
+
+	header->ck_a = data[header->length];
+	header->ck_b = data[header->length+1];
+
+	if (!checksum(header, data)) {
+		free (header);
+		return 0;
+	}
+
+	/* Now we know the packet is valid and complete */
+	msg = malloc(sizeof(ubx_msg));
+	msg->header = header;
+
+	msg->payload = ubx_parse_msg(header->cls, header->id, header->length, data);
+
+	return msg;
+}

Added: developers/alphaone/u-blox/libubx/src/ubx-parse.c
===================================================================
--- developers/alphaone/u-blox/libubx/src/ubx-parse.c	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/src/ubx-parse.c	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1,147 @@
+#include <libubx.h>
+#include <ubx-parse.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void *ubx_parse_aid_msg(uint8_t id, uint16_t length, uint8_t *data)
+{
+	switch (id) {
+		case UBX_ID_ALM:
+			if (length == 0) {
+				return 0;
+			} else if (length == 1) {
+				ubx_msg_aid_alm *msg;
+				msg = malloc(sizeof(ubx_msg_aid_alm));
+				msg->svid = data[0];
+				return msg;
+				} else {
+				ubx_msg_aid_alm *msg;
+				if (length >= 8) {
+					msg = malloc(sizeof(ubx_msg_aid_alm));
+					msg->svid = (uint32_t)*data;
+					data += 4;
+					msg->week = (uint32_t)*data;
+					data += 4;
+				}
+				if (length == 40) {
+					msg->dwrd0 = (uint32_t)*data;
+					data += 4;
+					msg->dwrd1 = (uint32_t)*data;
+					data += 4;
+					msg->dwrd2 = (uint32_t)*data;
+					data += 4;
+					msg->dwrd3 = (uint32_t)*data;
+					data += 4;
+					msg->dwrd4 = (uint32_t)*data;
+					data += 4;
+					msg->dwrd5 = (uint32_t)*data;
+					data += 4;
+					msg->dwrd6 = (uint32_t)*data;
+					data += 4;
+					msg->dwrd7 = (uint32_t)*data;
+				}
+				return msg;
+			}
+			break;
+		case UBX_ID_EPH:
+			if (length == 0) {
+				return 0;
+			} else if (length == 1) {
+				ubx_msg_aid_eph *msg;
+				msg = malloc(sizeof(ubx_msg_aid_eph));
+				msg->svid = data[0];
+				return msg;
+				} else {
+				ubx_msg_aid_eph *msg;
+				if (length >= 8) {
+					msg = malloc(sizeof(ubx_msg_aid_eph));
+					msg->svid = (uint32_t)*data;
+					data += 4;
+					msg->how = (uint32_t)*data;
+					data += 4;
+				}
+				if (length == 104) {
+					msg->sf1d0 = (uint32_t)*data;
+					data += 4;
+					msg->sf1d1 = (uint32_t)*data;
+					data += 4;
+					msg->sf1d2 = (uint32_t)*data;
+					data += 4;
+					msg->sf1d3 = (uint32_t)*data;
+					data += 4;
+					msg->sf1d4 = (uint32_t)*data;
+					data += 4;
+					msg->sf1d5 = (uint32_t)*data;
+					data += 4;
+					msg->sf1d6 = (uint32_t)*data;
+					data += 4;
+					msg->sf1d7 = (uint32_t)*data;
+					data += 4;
+					msg->sf2d0 = (uint32_t)*data;
+					data += 4;
+					msg->sf2d1 = (uint32_t)*data;
+					data += 4;
+					msg->sf2d2 = (uint32_t)*data;
+					data += 4;
+					msg->sf2d3 = (uint32_t)*data;
+					data += 4;
+					msg->sf2d4 = (uint32_t)*data;
+					data += 4;
+					msg->sf2d5 = (uint32_t)*data;
+					data += 4;
+					msg->sf2d6 = (uint32_t)*data;
+					data += 4;
+					msg->sf2d7 = (uint32_t)*data;
+					data += 4;
+					msg->sf3d0 = (uint32_t)*data;
+					data += 4;
+					msg->sf3d1 = (uint32_t)*data;
+					data += 4;
+					msg->sf3d2 = (uint32_t)*data;
+					data += 4;
+					msg->sf3d3 = (uint32_t)*data;
+					data += 4;
+					msg->sf3d4 = (uint32_t)*data;
+					data += 4;
+					msg->sf3d5 = (uint32_t)*data;
+					data += 4;
+					msg->sf3d6 = (uint32_t)*data;
+					data += 4;
+					msg->sf3d7 = (uint32_t)*data;
+				}
+				return msg;
+			}
+			break;
+		default:
+			printf("Unknown AID message (0x%x), length %d", id, length);
+			break;
+	}
+	return 0;
+}
+
+
+void *ubx_parse_msg(uint8_t cls, uint8_t id, uint16_t length,
+		uint8_t *data)
+{
+	switch (cls) {
+		case UBX_CL_NAV:
+//			return ubx_parse_nav_msg(id, length, data);
+			break;
+		case UBX_CL_AID:
+			return ubx_parse_aid_msg(id, length, data);
+			break;
+			/* Fall through */
+		case UBX_CL_RXM:
+		case UBX_CL_INF:
+		case UBX_CL_ACK:
+		case UBX_CL_CFG:
+		case UBX_CL_UPD:
+		case UBX_CL_MON:
+		case UBX_CL_TIM:
+		case UBX_CL_USR:
+		default:
+			printf("Unknown UBX message class (0x%x, 0x%x), length %d", cls, id, length);
+			break;
+	}
+	return 0;
+}

Added: developers/alphaone/u-blox/libubx/src/ubx-parse.h
===================================================================
--- developers/alphaone/u-blox/libubx/src/ubx-parse.h	                        (rev 0)
+++ developers/alphaone/u-blox/libubx/src/ubx-parse.h	2008-04-29 20:52:55 UTC (rev 4409)
@@ -0,0 +1,10 @@
+#ifndef _UBX_PARSE_H_
+#define _UBX_PARSE_H_
+
+#include <libubx.h>
+
+void *ubx_parse_aid_msg(uint8_t id, uint16_t length, uint8_t *data);
+void *ubx_parse_msg(uint8_t cls, uint8_t id, uint16_t length,
+		uint8_t *data);
+
+#endif /* _UBX_PARSE_H_ */





More information about the commitlog mailing list